forked from mystiq/hydrogen-web
clean up rejoin storage logic somewhat
This commit is contained in:
parent
f16c08f13e
commit
8c2ae863fd
2 changed files with 11 additions and 12 deletions
|
@ -249,12 +249,12 @@ export class Room extends EventEmitter {
|
|||
/** @package */
|
||||
async writeSync(roomResponse, isInitialSync, {summaryChanges, decryptChanges, roomEncryption, retryEntries}, txn, log) {
|
||||
log.set("id", this.id);
|
||||
const isRejoin = summaryChanges.membership === "join" && this.membership !== "join";
|
||||
const isRejoin = summaryChanges.isNewJoin(this._summary.data);
|
||||
if (isRejoin) {
|
||||
// remove all room state before calling syncWriter,
|
||||
// so no old state sticks around
|
||||
txn.roomState.removeAllForRoom(this.id);
|
||||
this._summary.tryRemoveArchive(txn);
|
||||
txn.archivedRoomSummary.remove(this.id);
|
||||
}
|
||||
const {entries: newEntries, newLiveKey, memberChanges} =
|
||||
await log.wrap("syncWriter", log => this._syncWriter.writeSync(roomResponse, isRejoin, txn, log), log.level.Detail);
|
||||
|
@ -282,9 +282,11 @@ export class Room extends EventEmitter {
|
|||
// also apply (decrypted) timeline entries to the summary changes
|
||||
summaryChanges = summaryChanges.applyTimelineEntries(
|
||||
allEntries, isInitialSync, !this._isTimelineOpen, this._user.id);
|
||||
|
||||
// only archive a room if we had previously joined it
|
||||
if (summaryChanges.membership === "leave" && this.membership === "join") {
|
||||
summaryChanges = this._summary.removeAndWriteArchive(summaryChanges, txn);
|
||||
txn.roomSummary.remove(this.id);
|
||||
summaryChanges = this._summary.writeArchivedData(summaryChanges, txn);
|
||||
} else {
|
||||
// write summary changes, and unset if nothing was actually changed
|
||||
summaryChanges = this._summary.writeData(summaryChanges, txn);
|
||||
|
@ -356,8 +358,7 @@ export class Room extends EventEmitter {
|
|||
}
|
||||
let emitChange = false;
|
||||
if (summaryChanges) {
|
||||
// if we joined the room, we can't have an invite anymore
|
||||
if (summaryChanges.membership === "join" && this.membership !== "join") {
|
||||
if (summaryChanges.isNewJoin(this._summary.data)) {
|
||||
this._invite = null;
|
||||
}
|
||||
this._summary.applyChanges(summaryChanges);
|
||||
|
|
|
@ -261,6 +261,10 @@ export class SummaryData {
|
|||
get needsHeroes() {
|
||||
return !this.name && !this.canonicalAlias && this.heroes && this.heroes.length > 0;
|
||||
}
|
||||
|
||||
isNewJoin(oldData) {
|
||||
return this.membership === "join" && oldData.membership !== "join";
|
||||
}
|
||||
}
|
||||
|
||||
export class RoomSummary {
|
||||
|
@ -304,19 +308,13 @@ export class RoomSummary {
|
|||
}
|
||||
|
||||
/** move summary to archived store when leaving the room */
|
||||
removeAndWriteArchive(data, txn) {
|
||||
txn.roomSummary.remove(data.roomId);
|
||||
writeArchivedData(data, txn) {
|
||||
if (data !== this._data) {
|
||||
txn.archivedRoomSummary.set(data.serialize());
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
/** delete archived summary when rejoining the room */
|
||||
tryRemoveArchive(txn) {
|
||||
txn.archivedRoomSummary.remove(this._data.roomId);
|
||||
}
|
||||
|
||||
async writeAndApplyData(data, storage) {
|
||||
if (data === this._data) {
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue