forked from mystiq/hydrogen-web
don't continue messages from more than 5min ago
This commit is contained in:
parent
fad728069a
commit
614a00b741
3 changed files with 17 additions and 6 deletions
|
@ -33,14 +33,17 @@ when loading, it just reads events from a sortkey backwards or forwards...
|
||||||
*/
|
*/
|
||||||
import {TilesCollection} from "./TilesCollection.js";
|
import {TilesCollection} from "./TilesCollection.js";
|
||||||
import {tilesCreator} from "./tilesCreator.js";
|
import {tilesCreator} from "./tilesCreator.js";
|
||||||
|
import {ViewModel} from "../../../ViewModel.js";
|
||||||
|
|
||||||
export class TimelineViewModel {
|
export class TimelineViewModel extends ViewModel {
|
||||||
constructor({room, timeline, ownUserId}) {
|
constructor(options) {
|
||||||
|
super(options);
|
||||||
|
const {room, timeline, ownUserId} = options;
|
||||||
this._timeline = timeline;
|
this._timeline = timeline;
|
||||||
// once we support sending messages we could do
|
// once we support sending messages we could do
|
||||||
// timeline.entries.concat(timeline.pendingEvents)
|
// timeline.entries.concat(timeline.pendingEvents)
|
||||||
// for an ObservableList that also contains local echos
|
// 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}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -20,6 +20,7 @@ import {getIdentifierColorNumber} from "../../../../avatar.js";
|
||||||
export class MessageTile extends SimpleTile {
|
export class MessageTile extends SimpleTile {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
|
this._clock = options.clock;
|
||||||
this._isOwn = this._entry.sender === options.ownUserId;
|
this._isOwn = this._entry.sender === options.ownUserId;
|
||||||
this._date = this._entry.timestamp ? new Date(this._entry.timestamp) : null;
|
this._date = this._entry.timestamp ? new Date(this._entry.timestamp) : null;
|
||||||
this._isContinuation = false;
|
this._isContinuation = false;
|
||||||
|
@ -59,7 +60,14 @@ export class MessageTile extends SimpleTile {
|
||||||
|
|
||||||
updatePreviousSibling(prev) {
|
updatePreviousSibling(prev) {
|
||||||
super.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) {
|
if (isContinuation !== this._isContinuation) {
|
||||||
this._isContinuation = isContinuation;
|
this._isContinuation = isContinuation;
|
||||||
this.emitChange("isContinuation");
|
this.emitChange("isContinuation");
|
||||||
|
|
|
@ -22,9 +22,9 @@ import {RoomNameTile} from "./tiles/RoomNameTile.js";
|
||||||
import {RoomMemberTile} from "./tiles/RoomMemberTile.js";
|
import {RoomMemberTile} from "./tiles/RoomMemberTile.js";
|
||||||
import {EncryptedEventTile} from "./tiles/EncryptedEventTile.js";
|
import {EncryptedEventTile} from "./tiles/EncryptedEventTile.js";
|
||||||
|
|
||||||
export function tilesCreator({room, ownUserId}) {
|
export function tilesCreator({room, ownUserId, clock}) {
|
||||||
return function tilesCreator(entry, emitUpdate) {
|
return function tilesCreator(entry, emitUpdate) {
|
||||||
const options = {entry, emitUpdate, ownUserId};
|
const options = {entry, emitUpdate, ownUserId, clock};
|
||||||
if (entry.isGap) {
|
if (entry.isGap) {
|
||||||
return new GapTile(options, room);
|
return new GapTile(options, room);
|
||||||
} else if (entry.eventType) {
|
} else if (entry.eventType) {
|
||||||
|
|
Loading…
Reference in a new issue