fix(state): correct invite re-notify, status clear sync, soundboard resync (DP2/DP3/DP5)
- Invites: seed the notify baseline with the invite count at mount instead of 0, so a warm reload (allInvitesAtom populates synchronously from cache while SYNCING) no longer re-fires the toast+sound for pre-existing invites. Only a genuine increase notifies. - Status: the cross-device sync effect gated on a truthy presence.status, so a remote CLEAR never reset the input or localStorage[STATUS_MSG_KEY] and usePresenceUpdater.readStatus() re-sent the stale status. Now mirror an empty status as a clear (skipping offline/invisible, which carries an empty status_msg by design). - Soundboard: useState initializers ran once and never recomputed when the room/rooms arg changed. Add a resync effect keyed on the arg while keeping the live state-event update path. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Room } from 'matrix-js-sdk';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { AccountDataEvent } from '../../types/matrix/accountData';
|
||||
import { StateEvent } from '../../types/matrix/room';
|
||||
import {
|
||||
@@ -79,6 +79,13 @@ export const useRoomSoundboardPack = (room: Room, stateKey: string): SoundboardP
|
||||
const mx = useMatrixClient();
|
||||
const [roomPack, setRoomPack] = useState(() => getRoomSoundboardPack(room, stateKey));
|
||||
|
||||
// Resync when the room/stateKey arg changes — the useState initializer only
|
||||
// runs on mount, so without this a re-target (e.g. a different room) kept
|
||||
// showing the first room's pack.
|
||||
useEffect(() => {
|
||||
setRoomPack(getRoomSoundboardPack(room, stateKey));
|
||||
}, [room, stateKey]);
|
||||
|
||||
useStateEventCallback(
|
||||
mx,
|
||||
useCallback(
|
||||
@@ -102,6 +109,11 @@ export const useRoomSoundboardPacks = (room: Room): SoundboardPack[] => {
|
||||
const mx = useMatrixClient();
|
||||
const [roomPacks, setRoomPacks] = useState(() => getRoomSoundboardPacks(room));
|
||||
|
||||
// Resync on room change (see useRoomSoundboardPack).
|
||||
useEffect(() => {
|
||||
setRoomPacks(getRoomSoundboardPacks(room));
|
||||
}, [room]);
|
||||
|
||||
useStateEventCallback(
|
||||
mx,
|
||||
useCallback(
|
||||
@@ -124,6 +136,12 @@ export const useRoomsSoundboardPacks = (rooms: Room[]): SoundboardPack[] => {
|
||||
const mx = useMatrixClient();
|
||||
const [roomPacks, setRoomPacks] = useState(() => rooms.flatMap(getRoomSoundboardPacks));
|
||||
|
||||
// Resync when the room list changes (callers pass a memoized array, so this
|
||||
// fires only on an actual change — see useRoomSoundboardPack).
|
||||
useEffect(() => {
|
||||
setRoomPacks(rooms.flatMap(getRoomSoundboardPacks));
|
||||
}, [rooms]);
|
||||
|
||||
useStateEventCallback(
|
||||
mx,
|
||||
useCallback(
|
||||
|
||||
Reference in New Issue
Block a user