diff --git a/packages/web/src/stores/chatStore.ts b/packages/web/src/stores/chatStore.ts index d95cb43a..3d75cb9a 100644 --- a/packages/web/src/stores/chatStore.ts +++ b/packages/web/src/stores/chatStore.ts @@ -64,6 +64,7 @@ interface ChatState { onMarkUnread: (channelId: string, messageId: string) => void; removeChannelStates: (channelIds: Set) => void; updateUserInMessages: (user: { id: string; [key: string]: any }) => void; + clearTypingForUser: (userId: string) => void; } /** Find which channel a message belongs to by scanning the message cache. */ @@ -727,4 +728,19 @@ export const useChatStore = create((set, get) => ({ return changed ? { messages: newMessages } : {}; }); }, + + clearTypingForUser: (userId: string) => { + set((state) => { + const newTyping = new Map(state.typingUsers); + let changed = false; + for (const [channelId, users] of newTyping) { + const filtered = users.filter(t => t.userId !== userId); + if (filtered.length !== users.length) { + newTyping.set(channelId, filtered); + changed = true; + } + } + return changed ? { typingUsers: newTyping } : state; + }); + }, })); diff --git a/packages/web/src/stores/discoverStore.ts b/packages/web/src/stores/discoverStore.ts index 958d4d0e..e8893d4e 100644 --- a/packages/web/src/stores/discoverStore.ts +++ b/packages/web/src/stores/discoverStore.ts @@ -20,6 +20,7 @@ interface DiscoverState { fetchUsers: (query?: string) => Promise; setSearchQuery: (q: string) => void; updateRelationship: (userId: string, origin: string, relationship: DiscoverUser['relationship'], requestId?: string) => void; + removeUser: (userId: string) => void; reset: () => void; } @@ -111,6 +112,13 @@ export const useDiscoverStore = create((set) => ({ })); }, + removeUser: (userId: string) => { + set((state) => ({ + users: state.users.filter(u => u.id !== userId), + total: Math.max(0, state.total - state.users.filter(u => u.id === userId).length), + })); + }, + reset: () => set({ users: [], searchQuery: '', diff --git a/packages/web/src/stores/socialStore.ts b/packages/web/src/stores/socialStore.ts index 491653d1..fcdd33e9 100644 --- a/packages/web/src/stores/socialStore.ts +++ b/packages/web/src/stores/socialStore.ts @@ -56,6 +56,7 @@ interface SocialState { updateFriendProfile: (user: User) => void; removeFriendLocally: (userId: string, origin: string) => void; removeRequestById: (requestId: string, origin: string) => void; + removeRequestsForUser: (userId: string) => void; reset: () => void; } @@ -326,6 +327,13 @@ export const useSocialStore = create((set, get) => ({ })); }, + // Called when a user is deleted — remove all pending requests involving them + removeRequestsForUser: (userId: string) => { + set((state) => ({ + requests: state.requests.filter(r => r.fromId !== userId && r.toId !== userId), + })); + }, + // Called from WS handler on presence_update to keep friend status live updateFriendPresence: (userId: string, status: string) => { set((state) => ({