make continuation logic work well with pending events

- don't use display name to compare but user id
   (pending doesn't have display name yet)
 - use current time as timestamp
This commit is contained in:
Bruno Windels 2020-09-11 11:43:40 +02:00
parent 2c186554a1
commit 0dece5b04f
6 changed files with 17 additions and 9 deletions

View File

@ -31,8 +31,12 @@ export class MessageTile extends SimpleTile {
return "message"; return "message";
} }
get displayName() {
return this._entry.displayName || this.sender;
}
get sender() { get sender() {
return this._entry.displayName || this._entry.sender; return this._entry.sender;
} }
// Avatar view model contract // Avatar view model contract
@ -52,7 +56,7 @@ export class MessageTile extends SimpleTile {
} }
get avatarTitle() { get avatarTitle() {
return this.sender; return this.displayName;
} }
get date() { get date() {

View File

@ -245,7 +245,8 @@ export class Session {
sendScheduler: this._sendScheduler, sendScheduler: this._sendScheduler,
pendingEvents, pendingEvents,
user: this._user, user: this._user,
createRoomEncryption: this._createRoomEncryption createRoomEncryption: this._createRoomEncryption,
clock: this._clock
}); });
this._rooms.add(roomId, room); this._rooms.add(roomId, room);
return room; return room;

View File

@ -31,7 +31,7 @@ import {DecryptionSource} from "../e2ee/common.js";
const EVENT_ENCRYPTED_TYPE = "m.room.encrypted"; const EVENT_ENCRYPTED_TYPE = "m.room.encrypted";
export class Room extends EventEmitter { export class Room extends EventEmitter {
constructor({roomId, storage, hsApi, emitCollectionChange, sendScheduler, pendingEvents, user, createRoomEncryption, getSyncToken}) { constructor({roomId, storage, hsApi, emitCollectionChange, sendScheduler, pendingEvents, user, createRoomEncryption, getSyncToken, clock}) {
super(); super();
this._roomId = roomId; this._roomId = roomId;
this._storage = storage; this._storage = storage;
@ -48,6 +48,7 @@ export class Room extends EventEmitter {
this._createRoomEncryption = createRoomEncryption; this._createRoomEncryption = createRoomEncryption;
this._roomEncryption = null; this._roomEncryption = null;
this._getSyncToken = getSyncToken; this._getSyncToken = getSyncToken;
this._clock = clock;
} }
async notifyRoomKeys(roomKeys) { async notifyRoomKeys(roomKeys) {
@ -488,6 +489,7 @@ export class Room extends EventEmitter {
} }
}, },
user: this._user, user: this._user,
clock: this._clock
}); });
if (this._roomEncryption) { if (this._roomEncryption) {
this._timeline.enableEncryption(this._decryptEntries.bind(this, DecryptionSource.Timeline)); this._timeline.enableEncryption(this._decryptEntries.bind(this, DecryptionSource.Timeline));

View File

@ -21,7 +21,7 @@ import {TimelineReader} from "./persistence/TimelineReader.js";
import {PendingEventEntry} from "./entries/PendingEventEntry.js"; import {PendingEventEntry} from "./entries/PendingEventEntry.js";
export class Timeline { export class Timeline {
constructor({roomId, storage, closeCallback, fragmentIdComparer, pendingEvents, user}) { constructor({roomId, storage, closeCallback, fragmentIdComparer, pendingEvents, user, clock}) {
this._roomId = roomId; this._roomId = roomId;
this._storage = storage; this._storage = storage;
this._closeCallback = closeCallback; this._closeCallback = closeCallback;
@ -35,7 +35,7 @@ export class Timeline {
}); });
this._readerRequest = null; this._readerRequest = null;
const localEntries = new MappedList(pendingEvents, pe => { const localEntries = new MappedList(pendingEvents, pe => {
return new PendingEventEntry({pendingEvent: pe, user}); return new PendingEventEntry({pendingEvent: pe, user, clock});
}, (pee, params) => { }, (pee, params) => {
pee.notifyUpdate(params); pee.notifyUpdate(params);
}); });

View File

@ -17,10 +17,11 @@ limitations under the License.
import {BaseEntry, PENDING_FRAGMENT_ID} from "./BaseEntry.js"; import {BaseEntry, PENDING_FRAGMENT_ID} from "./BaseEntry.js";
export class PendingEventEntry extends BaseEntry { export class PendingEventEntry extends BaseEntry {
constructor({pendingEvent, user}) { constructor({pendingEvent, user, clock}) {
super(null); super(null);
this._pendingEvent = pendingEvent; this._pendingEvent = pendingEvent;
this._user = user; this._user = user;
this._clock = clock;
} }
get fragmentId() { get fragmentId() {
@ -52,7 +53,7 @@ export class PendingEventEntry extends BaseEntry {
} }
get timestamp() { get timestamp() {
return null; return this._clock.now();
} }
get isPending() { get isPending() {

View File

@ -28,7 +28,7 @@ export function renderMessage(t, vm, children) {
const profile = t.div({className: "profile"}, [ const profile = t.div({className: "profile"}, [
renderAvatar(t, vm, 30), renderAvatar(t, vm, 30),
t.div({className: `sender usercolor${vm.avatarColorNumber}`}, vm.sender) t.div({className: `sender usercolor${vm.avatarColorNumber}`}, vm.displayName)
]); ]);
children = [profile].concat(children); children = [profile].concat(children);
return t.li( return t.li(