diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 7326e32f..91cc3ceb 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -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; }); } diff --git a/src/matrix/room/members/RoomMember.js b/src/matrix/room/members/RoomMember.js index 4013f556..f810a9fe 100644 --- a/src/matrix/room/members/RoomMember.js +++ b/src/matrix/room/members/RoomMember.js @@ -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") { diff --git a/src/matrix/room/timeline/Timeline.js b/src/matrix/room/timeline/Timeline.js index 2cccdf83..7743ddb8 100644 --- a/src/matrix/room/timeline/Timeline.js +++ b/src/matrix/room/timeline/Timeline.js @@ -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