fall back to bare userid for local echo profile

This commit is contained in:
Bruno Windels 2021-04-08 16:30:46 +02:00
parent 521894f401
commit 863f659774
3 changed files with 14 additions and 3 deletions

View file

@ -678,7 +678,7 @@ export class Room extends EventEmitter {
if (this._roomEncryption) {
this._timeline.enableEncryption(this._decryptEntries.bind(this, DecryptionSource.Timeline));
}
await this._timeline.load(this._user, log);
await this._timeline.load(this._user, this._summary.data.membership, log);
return this._timeline;
});
}

View file

@ -23,6 +23,10 @@ export class RoomMember {
this._data = data;
}
static fromUserId(roomId, userId, membership) {
return new RoomMember({roomId, userId, membership});
}
static fromMemberEvent(roomId, memberEvent) {
const userId = memberEvent?.state_key;
if (typeof userId !== "string") {

View file

@ -45,10 +45,17 @@ export class Timeline {
}
/** @package */
async load(user, log) {
async load(user, membership, log) {
const txn = await this._storage.readTxn(this._timelineReader.readTxnStores.concat(this._storage.storeNames.roomMembers));
const memberData = await txn.roomMembers.get(this._roomId, user.id);
this._ownMember = new RoomMember(memberData);
if (memberData) {
this._ownMember = new RoomMember(memberData);
} else {
// this should never happen, as our own join into the room would have
// made us receive our own member event, but just to be on the safe side and not crash,
// fall back to bare user id
this._ownMember = RoomMember.fromUserId(this._roomId, user.id, membership);
}
// it should be fine to not update the local entries,
// as they should only populate once the view subscribes to it
// if they are populated already, the sender profile would be empty