Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Fix people space notification badge not updating for new DM invites (#…
Browse files Browse the repository at this point in the history
…10849)

* Add regression test

* Fix people space notification state not updating for new DM invites
  • Loading branch information
t3chguy authored May 12, 2023
1 parent cb779fe commit 9611cbf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/stores/spaces/SpaceStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {

const hiddenChildren = new EnhancedMap<string, Set<string>>();
visibleRooms.forEach((room) => {
if (room.getMyMembership() !== "join") return;
if (!["join", "invite"].includes(room.getMyMembership())) return;
this.getParents(room.roomId).forEach((parent) => {
hiddenChildren.getOrCreate(parent.roomId, new Set()).add(room.roomId);
});
Expand Down Expand Up @@ -872,10 +872,9 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
}

const notificationStatesToUpdate = [...changeSet];
if (
this.enabledMetaSpaces.includes(MetaSpace.People) &&
userDiff.added.length + userDiff.removed.length + usersChanged.length > 0
) {
// We update the People metaspace even if we didn't detect any changes
// as roomIdsBySpace does not pre-calculate it so we have to assume it could have changed
if (this.enabledMetaSpaces.includes(MetaSpace.People)) {
notificationStatesToUpdate.push(MetaSpace.People);
}
this.updateNotificationStates(notificationStatesToUpdate);
Expand Down
23 changes: 23 additions & 0 deletions test/stores/SpaceStore-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,29 @@ describe("SpaceStore", () => {
});
});

it("should add new DM Invites to the People Space Notification State", async () => {
mkRoom(dm1);
mocked(client.getRoom(dm1)!).getMyMembership.mockReturnValue("join");
mocked(client).getRoom.mockImplementation((roomId) => rooms.find((room) => room.roomId === roomId) || null);

await run();

mkRoom(dm2);
const cliDm2 = client.getRoom(dm2)!;
mocked(cliDm2).getMyMembership.mockReturnValue("invite");
mocked(client).getRoom.mockImplementation((roomId) => rooms.find((room) => room.roomId === roomId) || null);
client.emit(RoomEvent.MyMembership, cliDm2, "invite");

[dm1, dm2].forEach((d) => {
expect(
store
.getNotificationState(MetaSpace.People)
.rooms.map((r) => r.roomId)
.includes(d),
).toBeTruthy();
});
});

describe("hierarchy resolution update tests", () => {
it("updates state when spaces are joined", async () => {
await run();
Expand Down

0 comments on commit 9611cbf

Please sign in to comment.