feat: real-time user profile updates and propagate avatarColor to all Avatar callsites
Broadcast user_updated events over WebSocket when profile fields change, updating members, DM participants, friends, and cached messages in real time. Widen useVoiceParticipantMeta to return the full user object and add a standalone avatarColor prop to Avatar so all ~16 callsites now resolve the user's chosen gradient color instead of falling back to hash-based colors.
This commit is contained in:
@@ -57,6 +57,7 @@ interface ChatState {
|
||||
markChannelUnread: (channelId: string) => void;
|
||||
ackChannel: (channelId: string) => void;
|
||||
onChannelAck: (channelId: string, messageId: string) => void;
|
||||
updateUserInMessages: (user: { id: string; [key: string]: any }) => void;
|
||||
}
|
||||
|
||||
/** Find which channel a message belongs to by scanning the message cache. */
|
||||
@@ -593,4 +594,23 @@ export const useChatStore = create<ChatState>((set, get) => ({
|
||||
return { readStates: newReadStates, unreadChannels: newUnread };
|
||||
});
|
||||
},
|
||||
|
||||
updateUserInMessages: (user: { id: string; [key: string]: any }) => {
|
||||
set((state) => {
|
||||
const newMessages = new Map(state.messages);
|
||||
let changed = false;
|
||||
for (const [channelId, msgs] of newMessages) {
|
||||
let channelChanged = false;
|
||||
const updated = msgs.map(m => {
|
||||
if (m.userId === user.id) {
|
||||
channelChanged = true;
|
||||
return { ...m, user: { ...m.user, ...user } };
|
||||
}
|
||||
return m;
|
||||
});
|
||||
if (channelChanged) { newMessages.set(channelId, updated); changed = true; }
|
||||
}
|
||||
return changed ? { messages: newMessages } : {};
|
||||
});
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user