Skip to content

Commit f66687e

Browse files
loganjLarry
andcommitted
fix(desktop): refresh mention directory from background membership rows
The app-wide background receiver merged kind 40099 channel-event rows into the timeline cache but never refreshed the mention directory, so a third-party member add/remove in a subscribed background channel left mention candidates stale until the next focused directory poll. Parse the member_joined/member_left/member_removed payload in handleIncomingMessage and call the existing refreshDirectoryAfterMembershipChange with the row's event id, mirroring the mounted-channel path; the helper's coalesce, cancel and event-id dedup semantics are unchanged. A mounted-caller regression drives the real hook with relay-wire 40099 rows and asserts that non-membership rows do not refresh. Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Signed-off-by: Logan Johnson <[email protected]>
1 parent ff2b68c commit f66687e

2 files changed

Lines changed: 546 additions & 0 deletions

File tree

‎desktop/src/features/channels/useLiveChannelUpdates.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { relayClient } from "@/shared/api/relayClient";
1414
import {
1515
CHANNEL_EVENT_KINDS,
1616
CHANNEL_MESSAGE_EVENT_KINDS,
17+
KIND_SYSTEM_MESSAGE,
1718
} from "@/shared/constants/kinds";
1819
import type { Channel, RelayEvent } from "@/shared/api/types";
1920
import {
@@ -22,6 +23,7 @@ import {
2223
} from "@/shared/lib/trailingDebounce";
2324

2425
import { isDmNotifiableKind } from "./isDmNotifiableKind";
26+
import { refreshDirectoryAfterMembershipChange } from "./membershipDirectorySync";
2527
import { refreshChannelsWhenIdle } from "./refreshChannelsWhenIdle";
2628

2729
export type UseLiveChannelUpdatesOptions = {
@@ -322,6 +324,27 @@ export function useLiveChannelUpdates(
322324
}
323325
}
324326

327+
// A membership change in any subscribed channel must refresh the mention
328+
// directory. The mounted-channel refresh only covers the active channel
329+
// and the global membership hook only covers viewer-addressed 44100/44101
330+
// rows, so background third-party changes would otherwise stay stale
331+
// until the focused directory poll. The helper coalesces bursts and
332+
// dedupes by event id.
333+
if (event.kind === KIND_SYSTEM_MESSAGE) {
334+
try {
335+
const payload = JSON.parse(event.content) as { type?: string };
336+
if (
337+
payload.type === "member_joined" ||
338+
payload.type === "member_left" ||
339+
payload.type === "member_removed"
340+
) {
341+
refreshDirectoryAfterMembershipChange(queryClient, event.id);
342+
}
343+
} catch {
344+
// Non-JSON system message — ignore.
345+
}
346+
}
347+
325348
// Merge into the timeline cache for the active channel.
326349
// useChannelSubscription also writes to this cache, but there's a
327350
// race window where it hasn't connected yet. Writes are idempotent

0 commit comments

Comments
 (0)