| | |
| | | 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 }[] = []; |
| | |
| | | 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); |
| | |
| | | updateLoadIndex(unSyncedHistoryIds.length); |
| | | scrollToBottom(); |
| | | } |
| | | |
| | | }; |
| | | |
| | | onActivated(() => { |