Skip to content

Commit 3f1e56b

Browse files
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
1 parent f3653ab commit 3f1e56b

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

src/stores/room-list-v3/RoomListStoreV3.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { MentionsFilter } from "./skip-list/filters/MentionsFilter";
3333
import { LowPriorityFilter } from "./skip-list/filters/LowPriorityFilter";
3434
import { type Sorter, SortingAlgorithm } from "./skip-list/sorters";
3535
import { SettingLevel } from "../../settings/SettingLevel";
36+
import { MARKED_UNREAD_TYPE_STABLE, MARKED_UNREAD_TYPE_UNSTABLE } from "../../utils/notifications";
3637

3738
/**
3839
* These are the filters passed to the room skip list.
@@ -156,6 +157,15 @@ export class RoomListStoreV3Class extends AsyncStoreWithClient<EmptyObject> {
156157
break;
157158
}
158159

160+
case "MatrixActions.Room.accountData": {
161+
const eventType = payload.event_type;
162+
if (eventType === MARKED_UNREAD_TYPE_STABLE || eventType === MARKED_UNREAD_TYPE_UNSTABLE) {
163+
const room = payload.room;
164+
this.addRoomAndEmit(room);
165+
}
166+
break;
167+
}
168+
159169
case "MatrixActions.Event.decrypted": {
160170
const roomId = payload.event.getRoomId();
161171
if (!roomId) return;

src/stores/room-list-v3/skip-list/filters/UnreadFilter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import type { Room } from "matrix-js-sdk/src/matrix";
88
import type { Filter } from ".";
99
import { FilterKey } from ".";
1010
import { RoomNotificationStateStore } from "../../../notifications/RoomNotificationStateStore";
11+
import { getMarkedUnreadState } from "../../../../utils/notifications";
1112

1213
export class UnreadFilter implements Filter {
1314
public matches(room: Room): boolean {
14-
return RoomNotificationStateStore.instance.getRoomState(room).hasUnreadCount;
15+
return RoomNotificationStateStore.instance.getRoomState(room).hasUnreadCount || !!getMarkedUnreadState(room);
1516
}
1617

1718
public get key(): FilterKey.UnreadFilter {

test/unit-tests/stores/room-list-v3/RoomListStoreV3-test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { RoomNotificationStateStore } from "../../../../src/stores/notifications
2626
import DMRoomMap from "../../../../src/utils/DMRoomMap";
2727
import { SortingAlgorithm } from "../../../../src/stores/room-list-v3/skip-list/sorters";
2828
import SettingsStore from "../../../../src/settings/SettingsStore";
29+
import * as utils from "../../../../src/utils/notifications";
2930

3031
describe("RoomListStoreV3", () => {
3132
async function getRoomListStore() {
@@ -474,6 +475,36 @@ describe("RoomListStoreV3", () => {
474475
}
475476
});
476477

478+
it("unread filter matches rooms that are marked as unread", async () => {
479+
const { client, rooms } = getClientAndRooms();
480+
// Let's choose 5 rooms to put in space
481+
const { spaceRoom, roomIds } = createSpace(rooms, [6, 8, 13, 27, 75], client);
482+
483+
setupMocks(spaceRoom, roomIds);
484+
const store = new RoomListStoreV3Class(dispatcher);
485+
await store.start();
486+
487+
// Since there's no unread yet, we expect zero results
488+
let result = store.getSortedRoomsInActiveSpace([FilterKey.UnreadFilter]);
489+
expect(result).toHaveLength(0);
490+
491+
// Mock so that room at index 8 is marked as unread
492+
jest.spyOn(utils, "getMarkedUnreadState").mockImplementation((room) => room.roomId === rooms[8].roomId);
493+
dispatcher.dispatch(
494+
{
495+
action: "MatrixActions.Room.accountData",
496+
room: rooms[8],
497+
event_type: utils.MARKED_UNREAD_TYPE_STABLE,
498+
},
499+
true,
500+
);
501+
502+
// Now we expect room at index 8 to show as unread
503+
result = store.getSortedRoomsInActiveSpace([FilterKey.UnreadFilter]);
504+
expect(result).toHaveLength(1);
505+
expect(result).toContain(rooms[8]);
506+
});
507+
477508
it("supports filtering by people and rooms", async () => {
478509
const { client, rooms } = getClientAndRooms();
479510
// Let's choose 5 rooms to put in space

0 commit comments

Comments
 (0)