From 928b2bb9a7fe85195f24f4811004f06ffbc0bbcc Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 10 Mar 2016 14:16:31 +0000 Subject: [PATCH] Use 'today' for the date separator for unsent messages Fixes https://github.com/vector-im/vector-web/issues/1087, though we'll still have problems if the unsent messages get out of order. --- src/components/structures/MessagePanel.js | 24 ++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/components/structures/MessagePanel.js b/src/components/structures/MessagePanel.js index 4d52ee3d42..503d069e48 100644 --- a/src/components/structures/MessagePanel.js +++ b/src/components/structures/MessagePanel.js @@ -259,12 +259,15 @@ module.exports = React.createClass({ continuation = true; } - // do we need a date separator since the last event? + // local echoes have a fake date, which could even be yesterday. Treat them + // as 'today' for the date separators. var ts1 = mxEv.getTs(); - if ((prevEvent == null && !this.props.suppressFirstDateSeparator) || - (prevEvent != null && - new Date(prevEvent.getTs()).toDateString() - !== new Date(ts1).toDateString())) { + if (mxEv.status) { + ts1 = new Date(); + } + + // do we need a date separator since the last event? + if (this._wantsDateSeparator(prevEvent, ts1)) { var dateSeparator =
  • ; ret.push(dateSeparator); continuation = false; @@ -290,6 +293,17 @@ module.exports = React.createClass({ return ret; }, + _wantsDateSeparator: function(prevEvent, nextEventTs) { + if (prevEvent == null) { + // first event in the panel: depends if we could back-paginate from + // here. + return !this.props.suppressFirstDateSeparator; + } + + return (new Date(prevEvent.getTs()).toDateString() + !== new Date(nextEventTs).toDateString()); + }, + _getReadMarkerTile: function(visible) { var hr; if (visible) {