restore invites when loading the session

This commit is contained in:
Bruno Windels 2021-04-20 18:09:48 +02:00
parent 5876e5200b
commit ee98eaa640
2 changed files with 16 additions and 2 deletions

View File

@ -258,6 +258,7 @@ export class Session {
const txn = await this._storage.readTxn([ const txn = await this._storage.readTxn([
this._storage.storeNames.session, this._storage.storeNames.session,
this._storage.storeNames.roomSummary, this._storage.storeNames.roomSummary,
this._storage.storeNames.invites,
this._storage.storeNames.roomMembers, this._storage.storeNames.roomMembers,
this._storage.storeNames.timelineEvents, this._storage.storeNames.timelineEvents,
this._storage.storeNames.timelineFragments, this._storage.storeNames.timelineFragments,
@ -289,6 +290,13 @@ export class Session {
await log.wrap("room", log => room.load(summary, txn, log)); await log.wrap("room", log => room.load(summary, txn, log));
this._rooms.add(room.id, room); this._rooms.add(room.id, room);
})); }));
// load invites
const invites = await txn.invites.getAll();
await Promise.all(invites.map(async inviteData => {
const invite = this.createInvite(inviteData.roomId);
log.wrap("invite", log => invite.load(inviteData, log));
this._invites.add(invite.id, invite);
}));
} }
dispose() { dispose() {
@ -583,6 +591,11 @@ export function tests() {
getAll() { getAll() {
return Promise.resolve([]); return Promise.resolve([]);
} }
},
invites: {
getAll() {
return Promise.resolve([]);
}
} }
}; };
}, },

View File

@ -70,7 +70,8 @@ export class Invite extends EventEmitter {
} }
load(inviteData) { load(inviteData, log) {
log.set("id", this.id);
this._inviteData = inviteData; this._inviteData = inviteData;
this._inviter = inviteData.inviter ? new RoomMember(inviteData.inviter) : null; this._inviter = inviteData.inviter ? new RoomMember(inviteData.inviter) : null;
} }
@ -257,7 +258,7 @@ export function tests() {
const txn = createStorage(); const txn = createStorage();
await writeInvite.writeSync("invite", dmInviteFixture, txn, new NullLogItem()); await writeInvite.writeSync("invite", dmInviteFixture, txn, new NullLogItem());
const invite = new Invite({roomId}); const invite = new Invite({roomId});
invite.load(txn.invitesMap.get(roomId)); invite.load(txn.invitesMap.get(roomId), new NullLogItem());
assert.equal(invite.name, "Alice"); assert.equal(invite.name, "Alice");
assert.equal(invite.avatarUrl, aliceAvatarUrl); assert.equal(invite.avatarUrl, aliceAvatarUrl);
assert.equal(invite.timestamp, 1003); assert.equal(invite.timestamp, 1003);