fix(sidebar): favourite / low-priority changes move the room immediately

Home's categorisation memo keyed only on the room list, and nothing
observed m.tag changes. The SDK emits RoomEvent.Tags on the room and
re-emits it on the client (room.js addTags, sync.js reEmit); a small
client-level hook bumps a version that the memo depends on.

Fixes #20

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
2026-09-13 00:56:22 -04:00
co-authored by Claude Opus 5
parent 31b3cf63c6
commit 4d7a510e06
2 changed files with 41 additions and 1 deletions
+31
View File
@@ -0,0 +1,31 @@
import { useEffect } from 'react';
import { MatrixClient, RoomEvent } from 'matrix-js-sdk';
import { useForceUpdate } from './useForceUpdate';
/**
* Bumps a counter whenever any room's `m.tag` account data changes
* (favourite/low-priority add or remove via `mx.setRoomTag`/`deleteRoomTag`).
*
* `RoomEvent.Tags` is emitted on the individual `Room` by `Room.addTags()`
* (matrix-js-sdk `lib/models/room.js`) and re-emitted onto the `MatrixClient`
* itself by the sync loop (`lib/sync.js`, the `client.reEmitter.reEmit(room, [...
* RoomEvent.Tags ...])` call), so a single client-level listener here sees the
* change for every room without needing to attach/detach a per-room listener.
*
* Consumers should add the returned counter to the deps of any memo that
* derives favourite/low-priority categorisation from `room.tags`, so toggling
* a tag moves the room immediately instead of waiting for an unrelated
* re-render to pick up the mutated (but stale-looking) `Room` object.
*/
export const useRoomTagsVersion = (mx: MatrixClient): number => {
const [version, bumpVersion] = useForceUpdate();
useEffect(() => {
mx.on(RoomEvent.Tags, bumpVersion);
return () => {
mx.removeListener(RoomEvent.Tags, bumpVersion);
};
}, [mx, bumpVersion]);
return version;
};