Account for timezone in date separator calculation (#595)

* Account for timezone in date separator calculation

Decide on date separators using MatrixEvent.getDate(). This requires matrix-org/matrix-js-sdk#311
This commit is contained in:
Luke Barnard 2016-12-22 17:54:30 +00:00 committed by GitHub
parent fd44d9f4d6
commit 2a63017372

View file

@ -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 = <li key={ts1+'~'}><DateSeparator key={ts1+'~'} ts={ts1}/></li>;
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 = <li key={ts1}><DateSeparator key={ts1} ts={ts1}/></li>;
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