From 614a00b7417049bf6342f2d14c346d88831fb5ea Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 19 Aug 2020 10:28:09 +0200 Subject: [PATCH] don't continue messages from more than 5min ago --- src/domain/session/room/timeline/TimelineViewModel.js | 9 ++++++--- src/domain/session/room/timeline/tiles/MessageTile.js | 10 +++++++++- src/domain/session/room/timeline/tilesCreator.js | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/domain/session/room/timeline/TimelineViewModel.js b/src/domain/session/room/timeline/TimelineViewModel.js index faf93609..1527d3ae 100644 --- a/src/domain/session/room/timeline/TimelineViewModel.js +++ b/src/domain/session/room/timeline/TimelineViewModel.js @@ -33,14 +33,17 @@ when loading, it just reads events from a sortkey backwards or forwards... */ import {TilesCollection} from "./TilesCollection.js"; import {tilesCreator} from "./tilesCreator.js"; +import {ViewModel} from "../../../ViewModel.js"; -export class TimelineViewModel { - constructor({room, timeline, ownUserId}) { +export class TimelineViewModel extends ViewModel { + constructor(options) { + super(options); + const {room, timeline, ownUserId} = options; this._timeline = timeline; // once we support sending messages we could do // timeline.entries.concat(timeline.pendingEvents) // for an ObservableList that also contains local echos - this._tiles = new TilesCollection(timeline.entries, tilesCreator({room, ownUserId})); + this._tiles = new TilesCollection(timeline.entries, tilesCreator({room, ownUserId, clock: this.clock})); } /** diff --git a/src/domain/session/room/timeline/tiles/MessageTile.js b/src/domain/session/room/timeline/tiles/MessageTile.js index f7c47030..8ad0b22e 100644 --- a/src/domain/session/room/timeline/tiles/MessageTile.js +++ b/src/domain/session/room/timeline/tiles/MessageTile.js @@ -20,6 +20,7 @@ import {getIdentifierColorNumber} from "../../../../avatar.js"; export class MessageTile extends SimpleTile { constructor(options) { super(options); + this._clock = options.clock; this._isOwn = this._entry.sender === options.ownUserId; this._date = this._entry.timestamp ? new Date(this._entry.timestamp) : null; this._isContinuation = false; @@ -59,7 +60,14 @@ export class MessageTile extends SimpleTile { updatePreviousSibling(prev) { super.updatePreviousSibling(prev); - const isContinuation = prev && prev instanceof MessageTile && prev.sender === this.sender; + let isContinuation = false; + if (prev && prev instanceof MessageTile && prev.sender === this.sender) { + // timestamp is null for pending events + const myTimestamp = this._entry.timestamp || this._clock.now(); + const otherTimestamp = prev._entry.timestamp || this._clock.now(); + // other message was sent less than 5min ago + isContinuation = (myTimestamp - otherTimestamp) < (5 * 60 * 1000); + } if (isContinuation !== this._isContinuation) { this._isContinuation = isContinuation; this.emitChange("isContinuation"); diff --git a/src/domain/session/room/timeline/tilesCreator.js b/src/domain/session/room/timeline/tilesCreator.js index 2e294467..1ae17bdc 100644 --- a/src/domain/session/room/timeline/tilesCreator.js +++ b/src/domain/session/room/timeline/tilesCreator.js @@ -22,9 +22,9 @@ import {RoomNameTile} from "./tiles/RoomNameTile.js"; import {RoomMemberTile} from "./tiles/RoomMemberTile.js"; import {EncryptedEventTile} from "./tiles/EncryptedEventTile.js"; -export function tilesCreator({room, ownUserId}) { +export function tilesCreator({room, ownUserId, clock}) { return function tilesCreator(entry, emitUpdate) { - const options = {entry, emitUpdate, ownUserId}; + const options = {entry, emitUpdate, ownUserId, clock}; if (entry.isGap) { return new GapTile(options, room); } else if (entry.eventType) {