forked from mystiq/hydrogen-web
attempt to load sync writer position when joining a room during sync
since fragments and events are not archived, just the summary, attempt to load the room and sync writer during sync, so we write the timeline correctly and don't cause ConstraintErrors because unaware of fragments and events already there.
This commit is contained in:
parent
07535eedca
commit
9546b13821
2 changed files with 17 additions and 5 deletions
|
@ -223,7 +223,11 @@ export class Sync {
|
||||||
return this._storage.readTxn([
|
return this._storage.readTxn([
|
||||||
storeNames.olmSessions,
|
storeNames.olmSessions,
|
||||||
storeNames.inboundGroupSessions,
|
storeNames.inboundGroupSessions,
|
||||||
storeNames.timelineEvents // to read events that can now be decrypted
|
// to read fragments when loading sync writer when rejoining archived room
|
||||||
|
storeNames.timelineFragments,
|
||||||
|
// to read fragments when loading sync writer when rejoining archived room
|
||||||
|
// to read events that can now be decrypted
|
||||||
|
storeNames.timelineEvents,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,8 +254,13 @@ export class Sync {
|
||||||
|
|
||||||
await Promise.all(roomStates.map(async rs => {
|
await Promise.all(roomStates.map(async rs => {
|
||||||
const newKeys = newKeysByRoom?.get(rs.room.id);
|
const newKeys = newKeysByRoom?.get(rs.room.id);
|
||||||
rs.preparation = await log.wrap("room", log => rs.room.prepareSync(
|
rs.preparation = await log.wrap("room", async log => {
|
||||||
rs.roomResponse, rs.membership, rs.invite, newKeys, prepareTxn, log), log.level.Detail);
|
if (rs.isNewRoom) {
|
||||||
|
await rs.room.load(null, prepareTxn, log);
|
||||||
|
}
|
||||||
|
return rs.room.prepareSync(
|
||||||
|
rs.roomResponse, rs.membership, rs.invite, newKeys, prepareTxn, log)
|
||||||
|
}, log.level.Detail);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// This is needed for safari to not throw TransactionInactiveErrors on the syncTxn. See docs/INDEXEDDB.md
|
// This is needed for safari to not throw TransactionInactiveErrors on the syncTxn. See docs/INDEXEDDB.md
|
||||||
|
|
|
@ -423,7 +423,10 @@ export class Room extends EventEmitter {
|
||||||
async load(summary, txn, log) {
|
async load(summary, txn, log) {
|
||||||
log.set("id", this.id);
|
log.set("id", this.id);
|
||||||
try {
|
try {
|
||||||
|
// if called from sync, there is no summary yet
|
||||||
|
if (summary) {
|
||||||
this._summary.load(summary);
|
this._summary.load(summary);
|
||||||
|
}
|
||||||
if (this._summary.data.encryption) {
|
if (this._summary.data.encryption) {
|
||||||
const roomEncryption = this._createRoomEncryption(this, this._summary.data.encryption);
|
const roomEncryption = this._createRoomEncryption(this, this._summary.data.encryption);
|
||||||
this._setEncryption(roomEncryption);
|
this._setEncryption(roomEncryption);
|
||||||
|
@ -714,7 +717,7 @@ export class Room extends EventEmitter {
|
||||||
if (this._roomEncryption) {
|
if (this._roomEncryption) {
|
||||||
this._timeline.enableEncryption(this._decryptEntries.bind(this, DecryptionSource.Timeline));
|
this._timeline.enableEncryption(this._decryptEntries.bind(this, DecryptionSource.Timeline));
|
||||||
}
|
}
|
||||||
await this._timeline.load(this._user, this._summary.data.membership, log);
|
await this._timeline.load(this._user, this.membership, log);
|
||||||
return this._timeline;
|
return this._timeline;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue