Skip to content

Commit 9de4251

Browse files
committed
Handle sticky rooms when regenerating lists
`setKnownRooms` is called to regenerate the room list, and if we don't take the sticky room out of the equation we end up with the room being duplicated. So, to make this easy, we simply remove the sticky room and handle it after the fact.
1 parent da2fd35 commit 9de4251

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/stores/room-list/algorithms/Algorithm.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,13 @@ export class Algorithm extends EventEmitter {
441441
if (isNullOrUndefined(rooms)) throw new Error(`Array of rooms cannot be null`);
442442
if (!this.sortAlgorithms) throw new Error(`Cannot set known rooms without a tag sorting map`);
443443

444+
console.warn("Resetting known rooms, initiating regeneration");
445+
446+
// Before we go any further we need to clear (but remember) the sticky room to
447+
// avoid accidentally duplicating it in the list.
448+
const oldStickyRoom = this._stickyRoom;
449+
await this.updateStickyRoom(null);
450+
444451
this.rooms = rooms;
445452

446453
const newTags: ITagMap = {};
@@ -500,6 +507,21 @@ export class Algorithm extends EventEmitter {
500507

501508
this.cachedRooms = newTags;
502509
this.updateTagsFromCache();
510+
this.recalculateFilteredRooms();
511+
512+
// Now that we've finished generation, we need to update the sticky room to what
513+
// it was. It's entirely possible that it changed lists though, so if it did then
514+
// we also have to update the position of it.
515+
if (oldStickyRoom && oldStickyRoom.room) {
516+
await this.updateStickyRoom(oldStickyRoom.room);
517+
if (this._stickyRoom && this._stickyRoom.room) { // just in case the update doesn't go according to plan
518+
if (this._stickyRoom.tag !== oldStickyRoom.tag) {
519+
// We put the sticky room at the top of the list to treat it as an obvious tag change.
520+
this._stickyRoom.position = 0;
521+
this.recalculateStickyRoom(this._stickyRoom.tag);
522+
}
523+
}
524+
}
503525
}
504526

505527
private getTagsForRoom(room: Room): TagID[] {

0 commit comments

Comments
 (0)