feat(client): dm_channel_updated WS handler + updateDmMetadata store action
This commit is contained in:
@@ -1117,6 +1117,13 @@ function handleEvent(origin: string, event: ServerEvent): void {
|
||||
break;
|
||||
}
|
||||
|
||||
case 'dm_channel_updated': {
|
||||
if (!isHome && !activePeerOrigins.has(origin)) break;
|
||||
const { dmChannelId, name, icon } = event;
|
||||
useSpaceStore.getState().updateDmMetadata(dmChannelId, { name, icon });
|
||||
break;
|
||||
}
|
||||
|
||||
// ─── Channel/space events (all origins) ─────────────────────────────────
|
||||
|
||||
case 'channel_created': {
|
||||
|
||||
@@ -130,6 +130,7 @@ interface SpaceState {
|
||||
addDmMember: (dmChannelId: string, user: User) => void;
|
||||
removeDmMember: (dmChannelId: string, userId: string) => void;
|
||||
updateDmOwner: (dmChannelId: string, newOwnerId: string) => void;
|
||||
updateDmMetadata: (dmChannelId: string, patch: { name?: string | null; icon?: string | null }) => void;
|
||||
closeDm: (id: string) => Promise<void>;
|
||||
leaveDm: (id: string) => Promise<void>;
|
||||
loadSpaces: () => Promise<void>;
|
||||
@@ -326,6 +327,20 @@ export const useSpaceStore = create<SpaceState>((set, get) => ({
|
||||
),
|
||||
})),
|
||||
|
||||
// Patches the group DM's display metadata (name + icon). Idempotent: a
|
||||
// payload with only one of `name`/`icon` leaves the other field untouched.
|
||||
// Mirrors `updateDmOwner` shape; called by the `dm_channel_updated` WS
|
||||
// handler after a remote rename / icon change.
|
||||
updateDmMetadata: (dmChannelId, patch) => set((state) => ({
|
||||
dmChannels: state.dmChannels.map(dm => {
|
||||
if (dm.id !== dmChannelId) return dm;
|
||||
const next = { ...dm };
|
||||
if ('name' in patch) next.name = patch.name ?? null;
|
||||
if ('icon' in patch) next.icon = patch.icon ?? null;
|
||||
return next;
|
||||
}),
|
||||
})),
|
||||
|
||||
closeDm: async (id) => {
|
||||
const origin = get().channelOriginMap.get(id) || '';
|
||||
const targetApi = getApiForOrigin(origin);
|
||||
|
||||
Reference in New Issue
Block a user