diff --git a/src/hooks/useStreaming/index.ts b/src/hooks/useStreaming/index.ts index a1f83167..64aa080d 100644 --- a/src/hooks/useStreaming/index.ts +++ b/src/hooks/useStreaming/index.ts @@ -28,7 +28,12 @@ import { setReady } from "@/app/slices/ui"; import { updateContactStatus, updateUsersByLogs, updateUsersStatus } from "@/app/slices/users"; import { updateCallInfo } from "@/app/slices/voice"; import { useAppDispatch, useAppSelector } from "@/app/store"; -import { ServerEvent, UserSettingsChangedEvent, UsersStateEvent } from "@/types/sse"; +import { + ServerEvent, + UserSettingsChangedEvent, + UserSettingsEvent, + UsersStateEvent +} from "@/types/sse"; import { getLocalAuthData } from "@/utils"; import chatMessageHandler from "./chat.handler"; @@ -157,11 +162,7 @@ export default function useStreaming() { dispatch(updateCallInfo({ from: uid, to: target, calling: true })); break; } - case "pinned_chats": { - const { chats } = data; - dispatch(upsertPinChats({ pins: chats, override: true })); - break; - } + case "users_snapshot": { const { version } = data; dispatch(updateUsersVersion(version)); @@ -205,6 +206,11 @@ export default function useStreaming() { case "read_index_users": dispatch(updateReadUsers(data[key])); break; + case "pinned_chats": { + const chats = (data as UserSettingsEvent)[key] ?? []; + dispatch(upsertPinChats({ pins: chats, override: true })); + break; + } case "add_pin_chats": { const pins = (data as UserSettingsChangedEvent).add_pin_chats ?? []; diff --git a/src/types/sse.ts b/src/types/sse.ts index 6cb885e4..c53cf908 100644 --- a/src/types/sse.ts +++ b/src/types/sse.ts @@ -62,6 +62,7 @@ export type UserSettingsEvent = { read_index_groups?: { gid: number; mid: number }[]; burn_after_reading_users?: AutoDeleteMsgForUser[]; burn_after_reading_groups?: AutoDeleteMsgForGroup[]; + pinned_chats?: PinChat[]; }; export type AutoDeleteSettingForUsers = { burn_after_reading_users: AutoDeleteMsgForUser[]; @@ -99,10 +100,6 @@ export type PinChatTargetChannel = { }; export type PinChatTarget = PinChatTargetUser | PinChatTargetChannel; export type PinChat = { target: PinChatTarget[]; updated_at: number }; -export interface PinnedChatsEvent { - type: "pinned_chats"; - chats: PinChat[]; -} export interface NormalMessage { mid: number; @@ -238,5 +235,4 @@ export type ServerEvent = | PinnedMessageUpdatedEvent | HeartbeatEvent | GroupClearEvent - | PinnedChatsEvent | UserCallEvent;