Multi-Agent Collaboration for Team and Friends
TypeScript agent-automationagent-orchestrationagent-workflowai-agentsai-collaborationai-memoryai-workforceautonomous-agentsclaude-codeclaude-code-skillscodexcoding-agentmulti-agentmultiple-agentone-person-businessone-person-companyone-person-teamopencodesolopreneur
fix(community): show the real name in 'X is typing', not 'Unknown member'
Shelly8b41a4a1601a
diff --git a/src/web/src/app/c/channels/[serverId]/[channelId]/page.tsx b/src/web/src/app/c/channels/[serverId]/[channelId]/page.tsxindex 89accbe07..690ae0fb6 100644--- a/src/web/src/app/c/channels/[serverId]/[channelId]/page.tsx+++ b/src/web/src/app/c/channels/[serverId]/[channelId]/page.tsx@@ -28,6 +28,7 @@ import {useCurrentChannelMeta,useUiHandlers,useTypingUsersForScope,+ useTypingNamesForScope,} from "@/stores/community"import { useCurrentUser } from "@/contexts/community/current-user"import { useServer } from "@/hooks/community/use-servers"@@ -428,6 +429,7 @@ function ChannelView() {const notifs = useNotificationSettings()const channelNotif = notifs.channelconst typingUsers = useTypingUsersForScope(`ch:${channelId}`)+ const typingNames = useTypingNamesForScope(`ch:${channelId}`)// Mutationsconst sendMessageMut = useSendMessage()@@ -976,7 +978,7 @@ function ChannelView() {loading={messagesLoading}pinnedIds={pinnedIds}newDividerBefore={newDividerBefore}- typingUsers={typingUsers.map((id) => resolveUserName(id))}+ typingUsers={typingUsers.map((id) => typingNames[id] ?? resolveUserName(id))}onOpenThread={() => { }}{...threadActions}onOpenProfile={openProfile}@@ -1126,7 +1128,7 @@ function ChannelView() {loading={messagesLoading}pinnedIds={pinnedIds}newDividerBefore={newDividerBefore}- typingUsers={typingUsers.map((id) => resolveUserName(id))}+ typingUsers={typingUsers.map((id) => typingNames[id] ?? resolveUserName(id))}onOpenThread={enterThread}{...messageActions}onOpenProfile={openProfile}diff --git a/src/web/src/app/c/me/[dmId]/page.tsx b/src/web/src/app/c/me/[dmId]/page.tsxindex 1a799b460..15f11ef6e 100644--- a/src/web/src/app/c/me/[dmId]/page.tsx+++ b/src/web/src/app/c/me/[dmId]/page.tsx@@ -16,6 +16,7 @@ import {useCurrentChannelId,useUiHandlers,useTypingUsersForScope,+ useTypingNamesForScope,} from "@/stores/community"import { useOnlineUserIds, useCommunityWsStore } from "@/stores/community/ws"import { tid } from "@/lib/community/testids"@@ -177,6 +178,7 @@ function DmView() {const typingUsers = useTypingUsersForScope(`dm:${dmId}`)+ const typingNames = useTypingNamesForScope(`dm:${dmId}`)const sendDmMessage = useSendDmMessage()const toggleReaction = useToggleReactionApi()const uploadFile = useUploadFile()@@ -345,7 +347,7 @@ function DmView() {messages={messages}loading={messagesLoading}newDividerBefore={newDividerBefore}- typingUsers={typingUsers.map((id) => resolveUserName(id))}+ typingUsers={typingUsers.map((id) => typingNames[id] ?? resolveUserName(id))}onOpenThread={() => { }}onToggleReaction={dmBlocked ? undefined : messageActions.onToggleReaction}onReact={dmBlocked ? undefined : messageActions.onReact}diff --git a/src/web/src/hooks/community/use-community-ws.test.ts b/src/web/src/hooks/community/use-community-ws.test.tsindex 13d873029..f20f01ade 100644--- a/src/web/src/hooks/community/use-community-ws.test.ts+++ b/src/web/src/hooks/community/use-community-ws.test.ts@@ -1189,10 +1189,51 @@ describe("useCommunityWs — typing.start honours focus (no DM leak)", () => {}capturedOnMessage!(event)- expect([...(useCommunityStore.getState().typingByScope.get("ch:ch_1") ?? [])]).toEqual([+ expect([...(useCommunityStore.getState().typingByScope.get("ch:ch_1")?.keys() ?? [])]).toEqual(["u_other",])})++ it("stores the name the typing event carries (fixes 'Unknown member' when the typer isn't in the loaded roster)", async () => {+ await mountHook()+ const { useCommunityStore } = await import("@/stores/community")+ useCommunityStore.getState().subscribe({ channelId: "ch_1" })+ refCounter = 0+ stateCounter = 0+ callbackCounter = 0+ await mountHook()++ const event: CommunityTypingStart = {+ type: "community:typing.start",+ channelId: "ch_1",+ userId: "u_other",+ name: "Alice",+ discriminator: "0001",+ }+ capturedOnMessage!(event)++ // The name rides the event → the consumer renders it directly, no roster+ // lookup, so a typer outside the loaded roster page is no longer "Unknown".+ expect(useCommunityStore.getState().typingByScope.get("ch:ch_1")?.get("u_other")).toBe("Alice")+ })++ it("stores null when the typing event carries no name (older server → consumer falls back to roster)", async () => {+ await mountHook()+ const { useCommunityStore } = await import("@/stores/community")+ useCommunityStore.getState().subscribe({ channelId: "ch_1" })+ refCounter = 0+ stateCounter = 0+ callbackCounter = 0+ await mountHook()++ capturedOnMessage!({+ type: "community:typing.start",+ channelId: "ch_1",+ userId: "u_other",+ } as CommunityTypingStart)++ expect(useCommunityStore.getState().typingByScope.get("ch:ch_1")?.get("u_other")).toBeNull()+ })})// ── Typing scope isolation (per-conversation, no cross-leak) ────────────────@@ -1218,7 +1259,7 @@ describe("useCommunityWs — typing state is scoped per conversation", () => {const state = useCommunityStore.getState()// The typer is confined to dm:dm_1 — a channel view reading ch:* sees nothing.- expect([...(state.typingByScope.get("dm:dm_1") ?? [])]).toEqual(["u_peer"])+ expect([...(state.typingByScope.get("dm:dm_1")?.keys() ?? [])]).toEqual(["u_peer"])expect(state.typingByScope.get("ch:dm_1")).toBeUndefined()// The 8s timer is keyed by (scope, user), not user alone.expect(state.typingTimers.has("dm:dm_1|u_peer")).toBe(true)@@ -1239,7 +1280,7 @@ describe("useCommunityWs — typing state is scoped per conversation", () => {channelId: "dm_bot",userId: "u_bot",})- expect([...(useCommunityStore.getState().typingByScope.get("dm:dm_bot") ?? [])]).toEqual([+ expect([...(useCommunityStore.getState().typingByScope.get("dm:dm_bot")?.keys() ?? [])]).toEqual(["u_bot",])diff --git a/src/web/src/hooks/community/use-community-ws.ts b/src/web/src/hooks/community/use-community-ws.tsindex f755d4276..795cf48bf 100644--- a/src/web/src/hooks/community/use-community-ws.ts+++ b/src/web/src/hooks/community/use-community-ws.ts@@ -550,7 +550,7 @@ export function useCommunityWs(options?: UseCommunityWsOptions) {if (viewerId && userId === viewerId) return// Focus check: only surface typing for the currently-viewed target.if (!matchesFocus(event)) return- applyTypingIndicator(typingScopeKey(event, sub), userId)+ applyTypingIndicator(typingScopeKey(event, sub), userId, event.name ?? null)cbs.onTyping?.(event)return}@@ -1175,7 +1175,7 @@ const timerKey = (scopeKey: string, userId: string) => `${scopeKey}|${userId}`* No-ops the set write when the user is already typing in the scope (rule 2 —* typing.start re-fires every ~3s).*/-function applyTypingIndicator(scopeKey: string, userId: string) {+function applyTypingIndicator(scopeKey: string, userId: string, name: string | null) {useCommunityStore.setState((state) => {const tKey = timerKey(scopeKey, userId)const existing = state.typingTimers.get(tKey)@@ -1187,12 +1187,14 @@ function applyTypingIndicator(scopeKey: string, userId: string) {nextTimers.set(tKey, timer)const current = state.typingByScope.get(scopeKey)- if (current?.has(userId)) {- // Already typing here — only the timer refreshed; leave the set alone.+ // Already typing here with the same known name — only the timer refreshed,+ // leave the name map alone (avoids a needless re-render). Otherwise (new+ // typer, or a name we didn't have before) write the entry.+ if (current?.has(userId) && current.get(userId) === name) {return { typingTimers: nextTimers }}const nextByScope = new Map(state.typingByScope)- nextByScope.set(scopeKey, new Set(current ?? []).add(userId))+ nextByScope.set(scopeKey, new Map(current ?? []).set(userId, name))return { typingByScope: nextByScope, typingTimers: nextTimers }})}@@ -1214,24 +1216,24 @@ function clearTypingIndicator(scopeKey: string, userId: string) {}/**- * Pure state patch: drop userId from `scopeKey`'s set (deleting the scope key- * when it empties, to avoid unbounded Map growth) and its `(scope, user)`- * timer. Shared by the auto-expire timer and the explicit clear.+ * Pure state patch: drop userId from `scopeKey`'s typing map (deleting the+ * scope key when it empties, to avoid unbounded Map growth) and its+ * `(scope, user)` timer. Shared by the auto-expire timer and the explicit clear.*/function removeTypingUser(- state: { typingByScope: Map<string, Set<string>>; typingTimers: Map<string, ReturnType<typeof setTimeout>> },+ state: { typingByScope: Map<string, Map<string, string | null>>; typingTimers: Map<string, ReturnType<typeof setTimeout>> },scopeKey: string,userId: string,-): Partial<{ typingByScope: Map<string, Set<string>>; typingTimers: Map<string, ReturnType<typeof setTimeout>> }> {+): Partial<{ typingByScope: Map<string, Map<string, string | null>>; typingTimers: Map<string, ReturnType<typeof setTimeout>> }> {const nextTimers = new Map(state.typingTimers)nextTimers.delete(timerKey(scopeKey, userId))const current = state.typingByScope.get(scopeKey)if (!current?.has(userId)) return { typingTimers: nextTimers }- const nextSet = new Set(current)- nextSet.delete(userId)+ const nextMap = new Map(current)+ nextMap.delete(userId)const nextByScope = new Map(state.typingByScope)- if (nextSet.size === 0) nextByScope.delete(scopeKey)- else nextByScope.set(scopeKey, nextSet)+ if (nextMap.size === 0) nextByScope.delete(scopeKey)+ else nextByScope.set(scopeKey, nextMap)return { typingByScope: nextByScope, typingTimers: nextTimers }}diff --git a/src/web/src/stores/community/index.ts b/src/web/src/stores/community/index.tsindex f7080b13d..da10ad844 100644--- a/src/web/src/stores/community/index.ts+++ b/src/web/src/stores/community/index.ts@@ -87,9 +87,11 @@ export type CommunityStoreState = {// Typing indicators, keyed by conversation scope so a DM typer never leaks// into a channel view (and vice versa). `scopeKey` is `dm:<id>` / `ch:<id>`- // (see `use-community-ws.ts`). Each scope maps to the set of userIds typing- // there right now; `typingTimers` auto-expires each `(scope, user)` pair.- typingByScope: Map<string, Set<string>>+ // (see `use-community-ws.ts`). Each scope maps its typing userIds to the+ // display name the typing event carried (`null` when the event didn't+ // include one — an older server — so the consumer falls back to roster+ // resolution). `typingTimers` auto-expires each `(scope, user)` pair.+ typingByScope: Map<string, Map<string, string | null>>typingTimers: Map<string, Timer>// Rate-limit for typing.start emissions the viewer sends outbound; keyed// by channelId/dmId so switching contexts doesn't cross-throttle.@@ -238,6 +240,8 @@ export const usePendingMachineTokenId = () =>// Module-scoped stable empty array — avoids allocating a fresh `[]` on every// selector run for the common no-typing case.const EMPTY_TYPING: string[] = []+// Stable empty object for the no-typing case, so `useShallow` doesn't churn.+const EMPTY_TYPING_NAMES: Record<string, string | null> = {}/*** The userIds currently typing in a given conversation scope (`dm:<id>` /@@ -248,7 +252,25 @@ const EMPTY_TYPING: string[] = []export const useTypingUsersForScope = (scopeKey: string) =>useCommunityStore(useShallow((s) => {- const set = s.typingByScope.get(scopeKey)- return set ? Array.from(set) : EMPTY_TYPING+ const map = s.typingByScope.get(scopeKey)+ return map ? Array.from(map.keys()) : EMPTY_TYPING+ }),+ )++/**+ * The display names the typing events carried for a scope, keyed by userId+ * (`null` when the event didn't include one). Consumers prefer this name and+ * fall back to roster resolution only when it's absent — the fix for+ * "Unknown member is typing" when the typer isn't in the loaded roster page.+ * Returned as a plain object so `useShallow` can compare it entry-wise.+ */+export const useTypingNamesForScope = (scopeKey: string) =>+ useCommunityStore(+ useShallow((s) => {+ const map = s.typingByScope.get(scopeKey)+ if (!map) return EMPTY_TYPING_NAMES+ const out: Record<string, string | null> = {}+ for (const [id, name] of map) out[id] = name+ return out}),)