-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Room List - Update the room list store on actions from the dispatcher #29397
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e4a7b6c
Update the store on action
MidhunSureshR fbab49d
Add more tests
MidhunSureshR 7257660
Add newlines between case blocks
MidhunSureshR 5f6aa6c
Make code more readable
MidhunSureshR c9a715e
Add more tests
MidhunSureshR 39087a0
Remove redundant code
MidhunSureshR ec05fff
Fix test
MidhunSureshR 86bcaa9
Remove more redundant code
MidhunSureshR 2f7f16e
Add more tests
MidhunSureshR 9465811
Explain intention in comment
MidhunSureshR bab8d93
Emit only once even when adding multiple rooms
MidhunSureshR 3e32e2d
Add missing tsdoc
MidhunSureshR File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,10 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com | |
Please see LICENSE files in the repository root for full details. | ||
*/ | ||
|
||
import type { EmptyObject, Room } from "matrix-js-sdk/src/matrix"; | ||
import { logger } from "matrix-js-sdk/src/logger"; | ||
import { EventType } from "matrix-js-sdk/src/matrix"; | ||
|
||
import type { EmptyObject, Room, RoomState } from "matrix-js-sdk/src/matrix"; | ||
import type { MatrixDispatcher } from "../../dispatcher/dispatcher"; | ||
import type { ActionPayload } from "../../dispatcher/payloads"; | ||
import { AsyncStoreWithClient } from "../AsyncStoreWithClient"; | ||
|
@@ -16,6 +19,8 @@ import { LISTS_UPDATE_EVENT } from "../room-list/RoomListStore"; | |
import { RoomSkipList } from "./skip-list/RoomSkipList"; | ||
import { RecencySorter } from "./skip-list/sorters/RecencySorter"; | ||
import { AlphabeticSorter } from "./skip-list/sorters/AlphabeticSorter"; | ||
import { readReceiptChangeIsFor } from "../../utils/read-receipts"; | ||
import { EffectiveMembership, getEffectiveMembership, getEffectiveMembershipTag } from "../../utils/membership"; | ||
|
||
/** | ||
* This store allows for fast retrieval of the room list in a sorted and filtered manner. | ||
|
@@ -78,7 +83,93 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> { | |
} | ||
|
||
protected async onAction(payload: ActionPayload): Promise<void> { | ||
return; | ||
if (!this.matrixClient || !this.roomSkipList?.initialized) return; | ||
|
||
/** | ||
* For the kind of updates that we care about (represented by the cases below), | ||
* we try to find the associated room and simply re-insert it into the | ||
* skiplist. If the position of said room in the sorted list changed, re-inserting | ||
* would put it in the correct place. | ||
*/ | ||
switch (payload.action) { | ||
case "MatrixActions.Room.receipt": { | ||
if (readReceiptChangeIsFor(payload.event, this.matrixClient)) { | ||
const room = payload.room; | ||
if (!room) { | ||
logger.warn(`Own read receipt was in unknown room ${room.roomId}`); | ||
return; | ||
} | ||
this.addRoomAndEmit(room); | ||
} | ||
break; | ||
} | ||
|
||
case "MatrixActions.Room.tags": { | ||
const room = payload.room; | ||
this.addRoomAndEmit(room); | ||
break; | ||
} | ||
|
||
case "MatrixActions.Event.decrypted": { | ||
const roomId = payload.event.getRoomId(); | ||
if (!roomId) return; | ||
const room = this.matrixClient.getRoom(roomId); | ||
if (!room) { | ||
logger.warn(`Event ${payload.event.getId()} was decrypted in an unknown room ${roomId}`); | ||
return; | ||
} | ||
this.addRoomAndEmit(room); | ||
break; | ||
} | ||
|
||
case "MatrixActions.accountData": { | ||
if (payload.event_type !== EventType.Direct) return; | ||
const dmMap = payload.event.getContent(); | ||
for (const userId of Object.keys(dmMap)) { | ||
const roomIds = dmMap[userId]; | ||
for (const roomId of roomIds) { | ||
const room = this.matrixClient.getRoom(roomId); | ||
if (!room) { | ||
logger.warn(`${roomId} was found in DMs but the room is not in the store`); | ||
continue; | ||
} | ||
this.addRoomAndEmit(room); | ||
} | ||
} | ||
break; | ||
} | ||
|
||
case "MatrixActions.Room.timeline": { | ||
// Ignore non-live events (backfill) and notification timeline set events (without a room) | ||
if (!payload.isLiveEvent || !payload.isLiveUnfilteredRoomTimelineEvent || !payload.room) return; | ||
this.addRoomAndEmit(payload.room); | ||
break; | ||
} | ||
|
||
case "MatrixActions.Room.myMembership": { | ||
const oldMembership = getEffectiveMembership(payload.oldMembership); | ||
const newMembership = getEffectiveMembershipTag(payload.room, payload.membership); | ||
if (oldMembership !== EffectiveMembership.Join && newMembership === EffectiveMembership.Join) { | ||
// If we're joining an upgraded room, we'll want to make sure we don't proliferate | ||
// the dead room in the list. | ||
const roomState: RoomState = payload.room.currentState; | ||
const predecessor = roomState.findPredecessor(this.msc3946ProcessDynamicPredecessor); | ||
if (predecessor) { | ||
const prevRoom = this.matrixClient?.getRoom(predecessor.roomId); | ||
if (prevRoom) this.roomSkipList.removeRoom(prevRoom); | ||
else logger.warn(`Unable to find predecessor room with id ${predecessor.roomId}`); | ||
} | ||
} | ||
this.addRoomAndEmit(payload.room); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
private addRoomAndEmit(room: Room): void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing tsdoc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 3e32e2d |
||
if (!this.roomSkipList) throw new Error("roomSkipList hasn't been created yet!"); | ||
this.roomSkipList.addRoom(room); | ||
this.emit(LISTS_UPDATE_EVENT); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fire
LISTS_UPDATE_EVENT
multiple times. Can we add the rooms to the skip list and after fire once the event?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in bab8d93