balibabu commited on
Commit
7c07000
·
1 Parent(s): 8bdf2db

fix: historical chats appear in the new user's chat box #256 (#282)

Browse files

### What problem does this PR solve?

historical chats appear in the new user's chat box

Issue link:#256

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

web/src/hooks/chatHooks.ts ADDED
@@ -0,0 +1,166 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { IConversation, IDialog } from '@/interfaces/database/chat';
2
+ import { useCallback } from 'react';
3
+ import { useDispatch, useSelector } from 'umi';
4
+
5
+ export const useFetchDialogList = () => {
6
+ const dispatch = useDispatch();
7
+
8
+ const fetchDialogList = useCallback(() => {
9
+ return dispatch<any>({ type: 'chatModel/listDialog' });
10
+ }, [dispatch]);
11
+
12
+ return fetchDialogList;
13
+ };
14
+
15
+ export const useSelectDialogList = () => {
16
+ const dialogList: IDialog[] = useSelector(
17
+ (state: any) => state.chatModel.dialogList,
18
+ );
19
+
20
+ return dialogList;
21
+ };
22
+
23
+ export const useFetchConversationList = () => {
24
+ const dispatch = useDispatch();
25
+
26
+ const fetchConversationList = useCallback(
27
+ async (dialogId: string) => {
28
+ if (dialogId) {
29
+ dispatch({
30
+ type: 'chatModel/listConversation',
31
+ payload: { dialog_id: dialogId },
32
+ });
33
+ }
34
+ },
35
+ [dispatch],
36
+ );
37
+
38
+ return fetchConversationList;
39
+ };
40
+
41
+ export const useSelectConversationList = () => {
42
+ const conversationList: IConversation[] = useSelector(
43
+ (state: any) => state.chatModel.conversationList,
44
+ );
45
+
46
+ return conversationList;
47
+ };
48
+
49
+ export const useFetchConversation = () => {
50
+ const dispatch = useDispatch();
51
+
52
+ const fetchConversation = useCallback(
53
+ (conversationId: string, needToBeSaved = true) => {
54
+ return dispatch<any>({
55
+ type: 'chatModel/getConversation',
56
+ payload: {
57
+ needToBeSaved,
58
+ conversation_id: conversationId,
59
+ },
60
+ });
61
+ },
62
+ [dispatch],
63
+ );
64
+
65
+ return fetchConversation;
66
+ };
67
+
68
+ export const useFetchDialog = () => {
69
+ const dispatch = useDispatch();
70
+
71
+ const fetchDialog = useCallback(
72
+ (dialogId: string, needToBeSaved = true) => {
73
+ if (dialogId) {
74
+ return dispatch<any>({
75
+ type: 'chatModel/getDialog',
76
+ payload: { dialog_id: dialogId, needToBeSaved },
77
+ });
78
+ }
79
+ },
80
+ [dispatch],
81
+ );
82
+
83
+ return fetchDialog;
84
+ };
85
+
86
+ export const useRemoveDialog = () => {
87
+ const dispatch = useDispatch();
88
+
89
+ const removeDocument = useCallback(
90
+ (dialogIds: Array<string>) => {
91
+ return dispatch({
92
+ type: 'chatModel/removeDialog',
93
+ payload: {
94
+ dialog_ids: dialogIds,
95
+ },
96
+ });
97
+ },
98
+ [dispatch],
99
+ );
100
+
101
+ return removeDocument;
102
+ };
103
+
104
+ export const useUpdateConversation = () => {
105
+ const dispatch = useDispatch();
106
+
107
+ const updateConversation = useCallback(
108
+ (payload: any) => {
109
+ return dispatch<any>({
110
+ type: 'chatModel/setConversation',
111
+ payload,
112
+ });
113
+ },
114
+ [dispatch],
115
+ );
116
+
117
+ return updateConversation;
118
+ };
119
+
120
+ export const useSetDialog = () => {
121
+ const dispatch = useDispatch();
122
+
123
+ const setDialog = useCallback(
124
+ (payload: IDialog) => {
125
+ return dispatch<any>({ type: 'chatModel/setDialog', payload });
126
+ },
127
+ [dispatch],
128
+ );
129
+
130
+ return setDialog;
131
+ };
132
+
133
+ export const useRemoveConversation = () => {
134
+ const dispatch = useDispatch();
135
+
136
+ const removeConversation = useCallback(
137
+ (conversationIds: Array<string>, dialogId: string) => {
138
+ return dispatch<any>({
139
+ type: 'chatModel/removeConversation',
140
+ payload: {
141
+ dialog_id: dialogId,
142
+ conversation_ids: conversationIds,
143
+ },
144
+ });
145
+ },
146
+ [dispatch],
147
+ );
148
+
149
+ return removeConversation;
150
+ };
151
+
152
+ export const useCompleteConversation = () => {
153
+ const dispatch = useDispatch();
154
+
155
+ const completeConversation = useCallback(
156
+ (payload: any) => {
157
+ return dispatch<any>({
158
+ type: 'chatModel/completeConversation',
159
+ payload,
160
+ });
161
+ },
162
+ [dispatch],
163
+ );
164
+
165
+ return completeConversation;
166
+ };
web/src/locales/en.ts CHANGED
@@ -269,6 +269,7 @@ export default {
269
  chatConfigurationDescription:
270
  ' Here, dress up a dedicated assistant for your special knowledge bases! 💕',
271
  assistantName: 'Assistant name',
 
272
  namePlaceholder: 'e.g. Resume Jarvis',
273
  assistantAvatar: 'Assistant avatar',
274
  language: 'Language',
 
269
  chatConfigurationDescription:
270
  ' Here, dress up a dedicated assistant for your special knowledge bases! 💕',
271
  assistantName: 'Assistant name',
272
+ assistantNameMessage: 'Assistant name is required',
273
  namePlaceholder: 'e.g. Resume Jarvis',
274
  assistantAvatar: 'Assistant avatar',
275
  language: 'Language',
web/src/locales/zh.ts CHANGED
@@ -260,6 +260,7 @@ export default {
260
  chatConfiguration: '聊天配置',
261
  chatConfigurationDescription: '在这里,为你的专业知识库装扮专属助手! 💕',
262
  assistantName: '助理姓名',
 
263
  namePlaceholder: '例如 贾维斯简历',
264
  assistantAvatar: '助理头像',
265
  language: '语言',
 
260
  chatConfiguration: '聊天配置',
261
  chatConfigurationDescription: '在这里,为你的专业知识库装扮专属助手! 💕',
262
  assistantName: '助理姓名',
263
+ assistantNameMessage: '助理姓名是必填项',
264
  namePlaceholder: '例如 贾维斯简历',
265
  assistantAvatar: '助理头像',
266
  language: '语言',
web/src/pages/chat/chat-configuration-modal/assistant-setting.tsx CHANGED
@@ -31,9 +31,9 @@ const AssistantSetting = ({ show }: ISegmentedContentProps) => {
31
  <Form.Item
32
  name={'name'}
33
  label={t('assistantName')}
34
- rules={[{ required: true }]}
35
  >
36
- <Input placeholder="e.g. Resume Jarvis" />
37
  </Form.Item>
38
  <Form.Item
39
  name="icon"
@@ -90,7 +90,7 @@ const AssistantSetting = ({ show }: ISegmentedContentProps) => {
90
  rules={[
91
  {
92
  required: true,
93
- message: 'Please select!',
94
  type: 'array',
95
  },
96
  ]}
 
31
  <Form.Item
32
  name={'name'}
33
  label={t('assistantName')}
34
+ rules={[{ required: true, message: t('assistantNameMessage') }]}
35
  >
36
+ <Input placeholder={t('namePlaceholder')} />
37
  </Form.Item>
38
  <Form.Item
39
  name="icon"
 
90
  rules={[
91
  {
92
  required: true,
93
+ message: t('knowledgeBasesMessage'),
94
  type: 'array',
95
  },
96
  ]}
web/src/pages/chat/hooks.ts CHANGED
@@ -1,5 +1,18 @@
1
  import { MessageType } from '@/constants/chat';
2
  import { fileIconMap } from '@/constants/common';
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  import { useSetModalState, useShowDeleteConfirm } from '@/hooks/commonHooks';
4
  import { useOneNamespaceEffectsLoading } from '@/hooks/storeHooks';
5
  import { IConversation, IDialog } from '@/interfaces/database/chat';
@@ -25,32 +38,6 @@ import {
25
  import { ChatModelState } from './model';
26
  import { isConversationIdExist } from './utils';
27
 
28
- export const useFetchDialogList = () => {
29
- const dispatch = useDispatch();
30
- const dialogList: IDialog[] = useSelector(
31
- (state: any) => state.chatModel.dialogList,
32
- );
33
-
34
- useEffect(() => {
35
- dispatch({ type: 'chatModel/listDialog' });
36
- }, [dispatch]);
37
-
38
- return dialogList;
39
- };
40
-
41
- export const useSetDialog = () => {
42
- const dispatch = useDispatch();
43
-
44
- const setDialog = useCallback(
45
- (payload: IDialog) => {
46
- return dispatch<any>({ type: 'chatModel/setDialog', payload });
47
- },
48
- [dispatch],
49
- );
50
-
51
- return setDialog;
52
- };
53
-
54
  export const useSelectCurrentDialog = () => {
55
  const currentDialog: IDialog = useSelector(
56
  (state: any) => state.chatModel.currentDialog,
@@ -59,24 +46,6 @@ export const useSelectCurrentDialog = () => {
59
  return currentDialog;
60
  };
61
 
62
- export const useFetchDialog = () => {
63
- const dispatch = useDispatch();
64
-
65
- const fetchDialog = useCallback(
66
- (dialogId: string, needToBeSaved = true) => {
67
- if (dialogId) {
68
- return dispatch<any>({
69
- type: 'chatModel/getDialog',
70
- payload: { dialog_id: dialogId, needToBeSaved },
71
- });
72
- }
73
- },
74
- [dispatch],
75
- );
76
-
77
- return fetchDialog;
78
- };
79
-
80
  export const useFetchDialogOnMount = (
81
  dialogId: string,
82
  visible: boolean,
@@ -147,21 +116,13 @@ export const useSelectPromptConfigParameters = (): VariableTableDataType[] => {
147
  return finalParameters;
148
  };
149
 
150
- export const useRemoveDialog = () => {
151
- const dispatch = useDispatch();
152
  const showDeleteConfirm = useShowDeleteConfirm();
153
 
154
- const removeDocument = (dialogIds: Array<string>) => () => {
155
- return dispatch({
156
- type: 'chatModel/removeDialog',
157
- payload: {
158
- dialog_ids: dialogIds,
159
- },
160
- });
161
- };
162
 
163
  const onRemoveDialog = (dialogIds: Array<string>) => {
164
- showDeleteConfirm({ onOk: removeDocument(dialogIds) });
165
  };
166
 
167
  return { onRemoveDialog };
@@ -216,16 +177,21 @@ export const useClickDialogCard = () => {
216
  };
217
 
218
  export const useSelectFirstDialogOnMount = () => {
219
- const dialogList = useFetchDialogList();
220
- const { dialogId } = useGetChatSearchParams();
221
 
222
  const { handleClickDialog } = useClickDialogCard();
223
 
224
- useEffect(() => {
225
- if (dialogList.length > 0 && !dialogId) {
226
- handleClickDialog(dialogList[0].id);
 
227
  }
228
- }, [dialogList, handleClickDialog, dialogId]);
 
 
 
 
229
 
230
  return dialogList;
231
  };
@@ -301,30 +267,19 @@ export const useEditDialog = () => {
301
 
302
  //#region conversation
303
 
304
- export const useFetchConversationList = () => {
305
- const dispatch = useDispatch();
306
- const conversationList: any[] = useSelector(
307
- (state: any) => state.chatModel.conversationList,
308
- );
309
  const { dialogId } = useGetChatSearchParams();
310
-
311
- const fetchConversationList = useCallback(async () => {
312
- if (dialogId) {
313
- dispatch({
314
- type: 'chatModel/listConversation',
315
- payload: { dialog_id: dialogId },
316
- });
317
- }
318
- }, [dispatch, dialogId]);
319
 
320
  useEffect(() => {
321
- fetchConversationList();
322
- }, [fetchConversationList]);
323
 
324
  return conversationList;
325
  };
326
 
327
- export const useSelectConversationList = () => {
328
  const [list, setList] = useState<Array<IConversation>>([]);
329
  let chatModel: ChatModelState = useSelector((state: any) => state.chatModel);
330
  const { conversationList, currentDialog } = chatModel;
@@ -381,27 +336,23 @@ export const useClickConversationCard = () => {
381
  };
382
 
383
  export const useSetConversation = () => {
384
- const dispatch = useDispatch();
385
  const { dialogId } = useGetChatSearchParams();
 
386
 
387
  const setConversation = useCallback(
388
  (message: string) => {
389
- return dispatch<any>({
390
- type: 'chatModel/setConversation',
391
- payload: {
392
- // conversation_id: '',
393
- dialog_id: dialogId,
394
- name: message,
395
- message: [
396
- {
397
- role: MessageType.Assistant,
398
- content: message,
399
- },
400
- ],
401
- },
402
  });
403
  },
404
- [dispatch, dialogId],
405
  );
406
 
407
  return { setConversation };
@@ -473,31 +424,14 @@ export const useSelectCurrentConversation = () => {
473
  }, [addPrologue]);
474
 
475
  useEffect(() => {
476
- setCurrentConversation(conversation);
477
- }, [conversation]);
 
 
478
 
479
  return { currentConversation, addNewestConversation, removeLatestMessage };
480
  };
481
 
482
- export const useFetchConversation = () => {
483
- const dispatch = useDispatch();
484
-
485
- const fetchConversation = useCallback(
486
- (conversationId: string, needToBeSaved = true) => {
487
- return dispatch<any>({
488
- type: 'chatModel/getConversation',
489
- payload: {
490
- needToBeSaved,
491
- conversation_id: conversationId,
492
- },
493
- });
494
- },
495
- [dispatch],
496
- );
497
-
498
- return fetchConversation;
499
- };
500
-
501
  export const useScrollToBottom = (currentConversation: IClientConversation) => {
502
  const ref = useRef<HTMLDivElement>(null);
503
 
@@ -564,33 +498,26 @@ export const useSendMessage = (
564
  const loading = useOneNamespaceEffectsLoading('chatModel', [
565
  'completeConversation',
566
  ]);
567
- const dispatch = useDispatch();
568
  const { setConversation } = useSetConversation();
569
  const { conversationId } = useGetChatSearchParams();
570
  const { handleInputChange, value, setValue } = useHandleMessageInputChange();
571
- // const conversation: IClientConversation = useSelector(
572
- // (state: any) => state.chatModel.currentConversation,
573
- // );
574
  const fetchConversation = useFetchConversation();
 
575
 
576
  const { handleClickConversation } = useClickConversationCard();
577
 
578
  const sendMessage = useCallback(
579
  async (message: string, id?: string) => {
580
- const retcode = await dispatch<any>({
581
- type: 'chatModel/completeConversation',
582
- payload: {
583
- conversation_id: id ?? conversationId,
584
- messages: [
585
- ...(conversation?.message ?? []).map((x: IMessage) =>
586
- omit(x, 'id'),
587
- ),
588
- {
589
- role: MessageType.User,
590
- content: message,
591
- },
592
- ],
593
- },
594
  });
595
 
596
  if (retcode === 0) {
@@ -607,13 +534,13 @@ export const useSendMessage = (
607
  }
608
  },
609
  [
610
- dispatch,
611
  conversation?.message,
612
  conversationId,
613
  fetchConversation,
614
  handleClickConversation,
615
  removeLatestMessage,
616
  setValue,
 
617
  ],
618
  );
619
 
@@ -664,37 +591,28 @@ export const useGetFileIcon = () => {
664
  return getFileIcon;
665
  };
666
 
667
- export const useRemoveConversation = () => {
668
- const dispatch = useDispatch();
669
  const { dialogId } = useGetChatSearchParams();
670
  const { handleClickConversation } = useClickConversationCard();
671
  const showDeleteConfirm = useShowDeleteConfirm();
 
672
 
673
- const removeConversation = (conversationIds: Array<string>) => async () => {
674
- const ret = await dispatch<any>({
675
- type: 'chatModel/removeConversation',
676
- payload: {
677
- dialog_id: dialogId,
678
- conversation_ids: conversationIds,
679
- },
680
- });
681
-
682
  if (ret === 0) {
683
  handleClickConversation('');
684
  }
685
-
686
  return ret;
687
  };
688
 
689
  const onRemoveConversation = (conversationIds: Array<string>) => {
690
- showDeleteConfirm({ onOk: removeConversation(conversationIds) });
691
  };
692
 
693
  return { onRemoveConversation };
694
  };
695
 
696
  export const useRenameConversation = () => {
697
- const dispatch = useDispatch();
698
  const [conversation, setConversation] = useState<IClientConversation>(
699
  {} as IClientConversation,
700
  );
@@ -704,19 +622,21 @@ export const useRenameConversation = () => {
704
  hideModal: hideConversationRenameModal,
705
  showModal: showConversationRenameModal,
706
  } = useSetModalState();
 
707
 
708
  const onConversationRenameOk = useCallback(
709
  async (name: string) => {
710
- const ret = await dispatch<any>({
711
- type: 'chatModel/setConversation',
712
- payload: { ...conversation, conversation_id: conversation.id, name },
 
713
  });
714
 
715
  if (ret.retcode === 0) {
716
  hideConversationRenameModal();
717
  }
718
  },
719
- [dispatch, conversation, hideConversationRenameModal],
720
  );
721
 
722
  const loading = useOneNamespaceEffectsLoading('chatModel', [
 
1
  import { MessageType } from '@/constants/chat';
2
  import { fileIconMap } from '@/constants/common';
3
+ import {
4
+ useCompleteConversation,
5
+ useFetchConversation,
6
+ useFetchConversationList,
7
+ useFetchDialog,
8
+ useFetchDialogList,
9
+ useRemoveConversation,
10
+ useRemoveDialog,
11
+ useSelectConversationList,
12
+ useSelectDialogList,
13
+ useSetDialog,
14
+ useUpdateConversation,
15
+ } from '@/hooks/chatHooks';
16
  import { useSetModalState, useShowDeleteConfirm } from '@/hooks/commonHooks';
17
  import { useOneNamespaceEffectsLoading } from '@/hooks/storeHooks';
18
  import { IConversation, IDialog } from '@/interfaces/database/chat';
 
38
  import { ChatModelState } from './model';
39
  import { isConversationIdExist } from './utils';
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  export const useSelectCurrentDialog = () => {
42
  const currentDialog: IDialog = useSelector(
43
  (state: any) => state.chatModel.currentDialog,
 
46
  return currentDialog;
47
  };
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  export const useFetchDialogOnMount = (
50
  dialogId: string,
51
  visible: boolean,
 
116
  return finalParameters;
117
  };
118
 
119
+ export const useDeleteDialog = () => {
 
120
  const showDeleteConfirm = useShowDeleteConfirm();
121
 
122
+ const removeDocument = useRemoveDialog();
 
 
 
 
 
 
 
123
 
124
  const onRemoveDialog = (dialogIds: Array<string>) => {
125
+ showDeleteConfirm({ onOk: () => removeDocument(dialogIds) });
126
  };
127
 
128
  return { onRemoveDialog };
 
177
  };
178
 
179
  export const useSelectFirstDialogOnMount = () => {
180
+ const fetchDialogList = useFetchDialogList();
181
+ const dialogList = useSelectDialogList();
182
 
183
  const { handleClickDialog } = useClickDialogCard();
184
 
185
+ const fetchList = useCallback(async () => {
186
+ const data = await fetchDialogList();
187
+ if (data.retcode === 0 && data.data.length > 0) {
188
+ handleClickDialog(data.data[0].id);
189
  }
190
+ }, [fetchDialogList, handleClickDialog]);
191
+
192
+ useEffect(() => {
193
+ fetchList();
194
+ }, [fetchList]);
195
 
196
  return dialogList;
197
  };
 
267
 
268
  //#region conversation
269
 
270
+ export const useFetchConversationListOnMount = () => {
271
+ const conversationList = useSelectConversationList();
 
 
 
272
  const { dialogId } = useGetChatSearchParams();
273
+ const fetchConversationList = useFetchConversationList();
 
 
 
 
 
 
 
 
274
 
275
  useEffect(() => {
276
+ fetchConversationList(dialogId);
277
+ }, [fetchConversationList, dialogId]);
278
 
279
  return conversationList;
280
  };
281
 
282
+ export const useSelectDerivedConversationList = () => {
283
  const [list, setList] = useState<Array<IConversation>>([]);
284
  let chatModel: ChatModelState = useSelector((state: any) => state.chatModel);
285
  const { conversationList, currentDialog } = chatModel;
 
336
  };
337
 
338
  export const useSetConversation = () => {
 
339
  const { dialogId } = useGetChatSearchParams();
340
+ const updateConversation = useUpdateConversation();
341
 
342
  const setConversation = useCallback(
343
  (message: string) => {
344
+ return updateConversation({
345
+ dialog_id: dialogId,
346
+ name: message,
347
+ message: [
348
+ {
349
+ role: MessageType.Assistant,
350
+ content: message,
351
+ },
352
+ ],
 
 
 
 
353
  });
354
  },
355
+ [updateConversation, dialogId],
356
  );
357
 
358
  return { setConversation };
 
424
  }, [addPrologue]);
425
 
426
  useEffect(() => {
427
+ if (conversationId) {
428
+ setCurrentConversation(conversation);
429
+ }
430
+ }, [conversation, conversationId]);
431
 
432
  return { currentConversation, addNewestConversation, removeLatestMessage };
433
  };
434
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
435
  export const useScrollToBottom = (currentConversation: IClientConversation) => {
436
  const ref = useRef<HTMLDivElement>(null);
437
 
 
498
  const loading = useOneNamespaceEffectsLoading('chatModel', [
499
  'completeConversation',
500
  ]);
 
501
  const { setConversation } = useSetConversation();
502
  const { conversationId } = useGetChatSearchParams();
503
  const { handleInputChange, value, setValue } = useHandleMessageInputChange();
504
+
 
 
505
  const fetchConversation = useFetchConversation();
506
+ const completeConversation = useCompleteConversation();
507
 
508
  const { handleClickConversation } = useClickConversationCard();
509
 
510
  const sendMessage = useCallback(
511
  async (message: string, id?: string) => {
512
+ const retcode = await completeConversation({
513
+ conversation_id: id ?? conversationId,
514
+ messages: [
515
+ ...(conversation?.message ?? []).map((x: IMessage) => omit(x, 'id')),
516
+ {
517
+ role: MessageType.User,
518
+ content: message,
519
+ },
520
+ ],
 
 
 
 
 
521
  });
522
 
523
  if (retcode === 0) {
 
534
  }
535
  },
536
  [
 
537
  conversation?.message,
538
  conversationId,
539
  fetchConversation,
540
  handleClickConversation,
541
  removeLatestMessage,
542
  setValue,
543
+ completeConversation,
544
  ],
545
  );
546
 
 
591
  return getFileIcon;
592
  };
593
 
594
+ export const useDeleteConversation = () => {
 
595
  const { dialogId } = useGetChatSearchParams();
596
  const { handleClickConversation } = useClickConversationCard();
597
  const showDeleteConfirm = useShowDeleteConfirm();
598
+ const removeConversation = useRemoveConversation();
599
 
600
+ const deleteConversation = (conversationIds: Array<string>) => async () => {
601
+ const ret = await removeConversation(conversationIds, dialogId);
 
 
 
 
 
 
 
602
  if (ret === 0) {
603
  handleClickConversation('');
604
  }
 
605
  return ret;
606
  };
607
 
608
  const onRemoveConversation = (conversationIds: Array<string>) => {
609
+ showDeleteConfirm({ onOk: deleteConversation(conversationIds) });
610
  };
611
 
612
  return { onRemoveConversation };
613
  };
614
 
615
  export const useRenameConversation = () => {
 
616
  const [conversation, setConversation] = useState<IClientConversation>(
617
  {} as IClientConversation,
618
  );
 
622
  hideModal: hideConversationRenameModal,
623
  showModal: showConversationRenameModal,
624
  } = useSetModalState();
625
+ const updateConversation = useUpdateConversation();
626
 
627
  const onConversationRenameOk = useCallback(
628
  async (name: string) => {
629
+ const ret = await updateConversation({
630
+ ...conversation,
631
+ conversation_id: conversation.id,
632
+ name,
633
  });
634
 
635
  if (ret.retcode === 0) {
636
  hideConversationRenameModal();
637
  }
638
  },
639
+ [updateConversation, conversation, hideConversationRenameModal],
640
  );
641
 
642
  const loading = useOneNamespaceEffectsLoading('chatModel', [
web/src/pages/chat/index.tsx CHANGED
@@ -21,16 +21,16 @@ import ChatContainer from './chat-container';
21
  import {
22
  useClickConversationCard,
23
  useClickDialogCard,
 
 
24
  useEditDialog,
25
- useFetchConversationList,
26
  useFetchDialogOnMount,
27
  useGetChatSearchParams,
28
  useHandleItemHover,
29
- useRemoveConversation,
30
- useRemoveDialog,
31
  useRenameConversation,
32
- useSelectConversationList,
33
  useSelectConversationListLoading,
 
34
  useSelectDialogListLoading,
35
  useSelectFirstDialogOnMount,
36
  } from './hooks';
@@ -40,13 +40,13 @@ import styles from './index.less';
40
 
41
  const Chat = () => {
42
  const dialogList = useSelectFirstDialogOnMount();
43
- const { onRemoveDialog } = useRemoveDialog();
44
- const { onRemoveConversation } = useRemoveConversation();
45
  const { handleClickDialog } = useClickDialogCard();
46
  const { handleClickConversation } = useClickConversationCard();
47
  const { dialogId, conversationId } = useGetChatSearchParams();
48
  const { list: conversationList, addTemporaryConversation } =
49
- useSelectConversationList();
50
  const { activated, handleItemEnter, handleItemLeave } = useHandleItemHover();
51
  const {
52
  activated: conversationActivated,
@@ -197,7 +197,7 @@ const Chat = () => {
197
  return appItems;
198
  };
199
 
200
- useFetchConversationList();
201
 
202
  return (
203
  <Flex className={styles.chatWrapper}>
 
21
  import {
22
  useClickConversationCard,
23
  useClickDialogCard,
24
+ useDeleteConversation,
25
+ useDeleteDialog,
26
  useEditDialog,
27
+ useFetchConversationListOnMount,
28
  useFetchDialogOnMount,
29
  useGetChatSearchParams,
30
  useHandleItemHover,
 
 
31
  useRenameConversation,
 
32
  useSelectConversationListLoading,
33
+ useSelectDerivedConversationList,
34
  useSelectDialogListLoading,
35
  useSelectFirstDialogOnMount,
36
  } from './hooks';
 
40
 
41
  const Chat = () => {
42
  const dialogList = useSelectFirstDialogOnMount();
43
+ const { onRemoveDialog } = useDeleteDialog();
44
+ const { onRemoveConversation } = useDeleteConversation();
45
  const { handleClickDialog } = useClickDialogCard();
46
  const { handleClickConversation } = useClickConversationCard();
47
  const { dialogId, conversationId } = useGetChatSearchParams();
48
  const { list: conversationList, addTemporaryConversation } =
49
+ useSelectDerivedConversationList();
50
  const { activated, handleItemEnter, handleItemLeave } = useHandleItemHover();
51
  const {
52
  activated: conversationActivated,
 
197
  return appItems;
198
  };
199
 
200
+ useFetchConversationListOnMount();
201
 
202
  return (
203
  <Flex className={styles.chatWrapper}>
web/src/pages/chat/model.ts CHANGED
@@ -97,6 +97,7 @@ const model: DvaModel<ChatModelState> = {
97
  if (data.retcode === 0) {
98
  yield put({ type: 'setDialogList', payload: data.data });
99
  }
 
100
  },
101
  *listConversation({ payload }, { call, put }) {
102
  const { data } = yield call(chatService.listConversation, payload);
 
97
  if (data.retcode === 0) {
98
  yield put({ type: 'setDialogList', payload: data.data });
99
  }
100
+ return data;
101
  },
102
  *listConversation({ payload }, { call, put }) {
103
  const { data } = yield call(chatService.listConversation, payload);