Commit f24ba7b7 by panjiangyi

优化打开会话的逻辑

parent 0fa8de52
......@@ -175,19 +175,8 @@ export default class ChatList extends Vue {
private async selectFirstChat() {
if (this.chatId != null) return;
if (!this.chatRooms.length) return;
const { chat_id, business_data } = this.chatRooms[0];
if (business_data == null) {
return;
}
const data = await getChatModelInfo(
business_data.model_name,
business_data.obj_id
);
this.saveChatId({
chatId: chat_id,
v: data.uniplat_version,
uniplatId: data.uniplatId,
});
const { chat_id } = this.chatRooms[0];
this.saveChatId(chat_id);
}
@buttonThrottle()
......@@ -217,11 +206,7 @@ export default class ChatList extends Vue {
wantedChatRoom.business_data.obj_id,
wantedChatRoom.business_data.detail_name
);
await this.saveChatId({
chatId: wantedChatRoom.chat_id,
v: info.uniplat_version,
uniplatId: info.uniplatId,
}).finally(this.raiseChatIdChanged);
await this.saveChatId(wantedChatRoom.chat_id).finally(this.raiseChatIdChanged);
this.showChat();
this.close();
......
......@@ -473,14 +473,31 @@ export default {
xim.on("chat_notify", "user.input", onInputing);
},
async [ChatStore.ACTION_SAVE_CURRENT_CHAT_ID_VERSION](
{ commit, dispatch },
params: Parameters<ChatStore.ACTION_SAVE_CURRENT_CHAT_ID_VERSION>[0]
{ state, commit, dispatch },
chatId: Parameters<ChatStore.ACTION_SAVE_CURRENT_CHAT_ID_VERSION>[0]
) {
const { chatId, v, uniplatId } = params;
const chatList = state[ChatStore.STATE_MY_CHAT_ROOM_LIST]?.list ?? [];
if (chatList.length === 0) return;
const wantedChatRoom = chatList.find(
(k) => k.chat_id === chatId
);
if (wantedChatRoom == null) return;
if (wantedChatRoom.business_data == null) {
return;
}
const info = await getChatModelInfo(
wantedChatRoom.business_data.model_name,
wantedChatRoom.business_data.obj_id,
wantedChatRoom.business_data.detail_name
);
commit(ChatStore.MUTATION_CLEAR_CHAT_MSG_HISTORY);
commit(ChatStore.MUTATION_SAVE_CURRENT_CHAT_ID, chatId);
commit(ChatStore.MUTATION_SAVE_CURRENT_CHAT_VERSION, v);
commit(ChatStore.MUTATION_SAVE_CURRENT_CHAT_UNIPLAT_ID, uniplatId);
commit(ChatStore.MUTATION_SAVE_CURRENT_CHAT_VERSION, info.uniplat_version);
commit(ChatStore.MUTATION_SAVE_CURRENT_CHAT_UNIPLAT_ID, info.uniplatId);
commit(ChatStore.MUTATION_INITING_CHAT);
removeRegisterChatEvents.forEach((k) => k());
await Promise.all([
......
......@@ -227,11 +227,7 @@ export namespace ChatStore {
}) => Promise<number>
export const ACTION_SAVE_CURRENT_CHAT_ID_VERSION = "action:保存当前chat-id";
export type ACTION_SAVE_CURRENT_CHAT_ID_VERSION = (params: {
chatId: ChatStore.STATE_CHAT_CURRENT_CHAT_ID;
v: number;
uniplatId: STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID;
}) => Promise<void>
export type ACTION_SAVE_CURRENT_CHAT_ID_VERSION = (chatId: ChatStore.STATE_CHAT_CURRENT_CHAT_ID) => Promise<void>
export const ACTION_CLEAR_CURRENT_CHAT_DATA = "action:清空当前会话数据";
export type ACTION_CLEAR_CURRENT_CHAT_DATA = () => Promise<void>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment