feat: real-time sync, notification & social system overhaul
- Add WS events: dm_channel_created, dm_channel_closed, friend_removed, channel_created/updated/deleted, server_updated - Fix first-ever DM: broadcast dm_channel_created to recipient - Add DELETE /api/dm/:id for closing DMs with re-open support - Wire Close DM button in sidebar - Fix dm_message_created for unknown channels (safety net) - Broadcast friend_removed on friend deletion - Sound system: track realtimeMessageEvents separately from API loads, play notification for messages in all channels, not just current - Optimistic updates: send/edit/delete messages appear instantly with rollback on failure, temp message deduplication on WS echo - Channel CRUD broadcasts to all server members - Server update broadcast on PATCH - Server join registers user in connectionManager immediately - Reconnect: only reload current channel, preserve other channel caches - Activity panel, right panel, member list toggle components
This commit is contained in:
@@ -16,6 +16,8 @@ interface SocialState {
|
||||
searchUsers: (query: string) => Promise<User[]>;
|
||||
addIncomingRequest: (request: FriendRequest) => void;
|
||||
addFriendFromAccepted: (friend: Friend, requestId: string) => void;
|
||||
updateFriendPresence: (userId: string, status: string) => void;
|
||||
removeFriendLocally: (userId: string) => void;
|
||||
}
|
||||
|
||||
export const useSocialStore = create<SocialState>((set, get) => ({
|
||||
@@ -121,4 +123,20 @@ export const useSocialStore = create<SocialState>((set, get) => ({
|
||||
requests: state.requests.filter(r => r.id !== requestId),
|
||||
}));
|
||||
},
|
||||
|
||||
// Called from WS handler when the other user removes us as a friend
|
||||
removeFriendLocally: (userId: string) => {
|
||||
set((state) => ({
|
||||
friends: state.friends.filter(f => f.id !== userId),
|
||||
}));
|
||||
},
|
||||
|
||||
// Called from WS handler on presence_update to keep friend status live
|
||||
updateFriendPresence: (userId: string, status: string) => {
|
||||
set((state) => ({
|
||||
friends: state.friends.map(f =>
|
||||
f.id === userId ? { ...f, status: status as Friend['status'] } : f
|
||||
),
|
||||
}));
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user