RoomListStore: Unread filter should match rooms that were marked as unread (#29580)

* Unread filter should match rooms marked as unread

* Re-insert room into skip list on account data

So that filters are re-calculated when rooms are marked as unread.

* Write test
This commit is contained in:
R Midhun Suresh
2025-03-24 22:21:42 +05:30
committed by GitHub
parent f3653abe92
commit 3f1e56b715
3 changed files with 43 additions and 1 deletions

View File

@@ -26,6 +26,7 @@ import { RoomNotificationStateStore } from "../../../../src/stores/notifications
import DMRoomMap from "../../../../src/utils/DMRoomMap";
import { SortingAlgorithm } from "../../../../src/stores/room-list-v3/skip-list/sorters";
import SettingsStore from "../../../../src/settings/SettingsStore";
import * as utils from "../../../../src/utils/notifications";
describe("RoomListStoreV3", () => {
async function getRoomListStore() {
@@ -474,6 +475,36 @@ describe("RoomListStoreV3", () => {
}
});
it("unread filter matches rooms that are marked as unread", async () => {
const { client, rooms } = getClientAndRooms();
// Let's choose 5 rooms to put in space
const { spaceRoom, roomIds } = createSpace(rooms, [6, 8, 13, 27, 75], client);
setupMocks(spaceRoom, roomIds);
const store = new RoomListStoreV3Class(dispatcher);
await store.start();
// Since there's no unread yet, we expect zero results
let result = store.getSortedRoomsInActiveSpace([FilterKey.UnreadFilter]);
expect(result).toHaveLength(0);
// Mock so that room at index 8 is marked as unread
jest.spyOn(utils, "getMarkedUnreadState").mockImplementation((room) => room.roomId === rooms[8].roomId);
dispatcher.dispatch(
{
action: "MatrixActions.Room.accountData",
room: rooms[8],
event_type: utils.MARKED_UNREAD_TYPE_STABLE,
},
true,
);
// Now we expect room at index 8 to show as unread
result = store.getSortedRoomsInActiveSpace([FilterKey.UnreadFilter]);
expect(result).toHaveLength(1);
expect(result).toContain(rooms[8]);
});
it("supports filtering by people and rooms", async () => {
const { client, rooms } = getClientAndRooms();
// Let's choose 5 rooms to put in space