diff --git a/src/components/structures/MessagePanel.js b/src/components/structures/MessagePanel.js
index c681f5105d..affa33a3e8 100644
--- a/src/components/structures/MessagePanel.js
+++ b/src/components/structures/MessagePanel.js
@@ -21,6 +21,8 @@ var sdk = require('../../index');
var MatrixClientPeg = require('../../MatrixClientPeg')
+const MILLIS_IN_DAY = 86400000;
+
/* (almost) stateless UI component which builds the event tiles in the room timeline.
*/
module.exports = React.createClass({
@@ -306,7 +308,7 @@ module.exports = React.createClass({
// membership event, which will not change during forward pagination.
const key = "membereventlistsummary-" + (prevEvent ? mxEv.getId() : "initial");
- if (this._wantsDateSeparator(prevEvent, ts1)) {
+ if (this._wantsDateSeparator(prevEvent, mxEv.getDate())) {
let dateSeparator =
;
ret.push(dateSeparator);
}
@@ -316,7 +318,7 @@ module.exports = React.createClass({
let collapsedMxEv = this.props.events[i + 1];
if (!isMembershipChange(collapsedMxEv) ||
- this._wantsDateSeparator(this.props.events[i], collapsedMxEv.getTs())) {
+ this._wantsDateSeparator(this.props.events[i], collapsedMxEv.getDate())) {
break;
}
summarisedEvents.push(collapsedMxEv);
@@ -427,12 +429,14 @@ module.exports = React.createClass({
// local echoes have a fake date, which could even be yesterday. Treat them
// as 'today' for the date separators.
var ts1 = mxEv.getTs();
+ var eventDate = mxEv.getDate();
if (mxEv.status) {
- ts1 = new Date();
+ eventDate = new Date();
+ ts1 = eventDate.getTime();
}
// do we need a date separator since the last event?
- if (this._wantsDateSeparator(prevEvent, ts1)) {
+ if (this._wantsDateSeparator(prevEvent, eventDate)) {
var dateSeparator = ;
ret.push(dateSeparator);
continuation = false;
@@ -469,15 +473,19 @@ module.exports = React.createClass({
return ret;
},
- _wantsDateSeparator: function(prevEvent, nextEventTs) {
+ _wantsDateSeparator: function(prevEvent, nextEventDate) {
if (prevEvent == null) {
// first event in the panel: depends if we could back-paginate from
// here.
return !this.props.suppressFirstDateSeparator;
}
+ // Return early for events that are > 24h apart
+ if (Math.abs(prevEvent.getTs() - nextEventDate.getTime()) > MILLIS_IN_DAY) {
+ return true;
+ }
- return (new Date(prevEvent.getTs()).toDateString()
- !== new Date(nextEventTs).toDateString());
+ // Compare weekdays
+ return prevEvent.getDate().getDay() !== nextEventDate.getDay();
},
// get a list of read receipts that should be shown next to this event