gerson
2025-01-21 c9b6d9a10160ca1d18237a0728bac87ec8ff16da
src/components/chat/hooks/useSyncMsg.ts
@@ -14,10 +14,11 @@
   checkCanSync: (data: any) => boolean;
   loadReplyData: (data: any) => Promise<ChatMessage[]>;
   scrollToBottom: () => void;
   showTip: (data: any) => void;
};
export const useSyncMsg = (options: UseSyncMsgOptions) => {
   const { updateLoadIndex, msgList, historyGroupId, checkCanSync, loadReplyData, scrollToBottom } = options;
   const { updateLoadIndex, msgList, historyGroupId, checkCanSync, loadReplyData, scrollToBottom, showTip } = options;
   const insertSyncMsg = (replayData: any[]) => {
      const insertResult: { index: number; item: any }[] = [];
@@ -41,19 +42,18 @@
         msgList.value.splice(resultItem.index, 0, ...resultItem.item);
      });
   };
   const historyUpdate = async (data: any) => {
      if (!checkCanSync(data)) return;
      if (!data) return;
      Logger.info('sync message notification:\n\n' + JSON.stringify(data));
      if (data?.type === 'chat_start') {
         const fromTitle = data?.from || '未知端';
         ElNotification({
            title: fromTitle,
            message: `正在处理新的提问,请耐心等待,对话完成后会自动同步`,
            type: 'info',
            duration: 4000,
         });
         const groupId = unref(historyGroupId);
         const startGroupId = data?.history_group_id;
         if (groupId !== startGroupId) return;
         showTip(data);
      }
      if (data?.type === 'chat_history_id') {
         const groupId = unref(historyGroupId);
@@ -86,6 +86,7 @@
         updateLoadIndex(unSyncedHistoryIds.length);
         scrollToBottom();
      }
   };
   onActivated(() => {