Commit f129063c by Sixong.Zhu

update

parent c1153f8d
Showing with 30 additions and 28 deletions
......@@ -124,7 +124,12 @@ export interface Message {
export type MessageRequestResult = readonly Message[];
export interface BaseChatItem {
export interface BaseChatItemBusinessData {
model_name: string;
obj_id: string;
}
export interface BaseChatItem extends BaseChatItemBusinessData {
id: number;
org_id: string;
uid: string;
......@@ -160,8 +165,6 @@ export interface BaseChatItem {
last_msg_ts: number;
members_updated: number;
user_updated: number;
model_name: string;
obj_id: string;
}
export interface RawChatItem extends BaseChatItem {
......
import Vue from "vue";
import { Module } from "vuex";
import { dbController } from "../database";
import { ChatMember, MessageType,ServiceType, MessageHandled, RawChatItem } from "../model";
import {
ChatMember,
MessageType,
ServiceType,
MessageHandled,
RawChatItem,
BaseChatItemBusinessData,
} from "../model";
import { isAccessibleUrl } from "../service/tools";
import { unique } from "../utils";
import { getChatModelInfo } from "../utils/chat-info";
......@@ -77,10 +84,7 @@ async function preCacheImgs(msgs?: any[]) {
function buildChatItem(chat: RawChatItem) {
if (!chat.model_name && chat.business_data) {
const b = JSON.parse(chat.business_data) as {
model_name: string;
obj_id: string;
};
const b = JSON.parse(chat.business_data) as BaseChatItemBusinessData;
chat.model_name = b.model_name;
b.obj_id && (chat.obj_id = b.obj_id);
}
......@@ -550,7 +554,10 @@ export default {
.createChat(true);
const chatId = Number(imChatId);
await commit(ChatStore.MUTATION_SHOW_CHAT, true);
await dispatch(ChatStore.ACTION_SAVE_CURRENT_CHAT_ID_VERSION, chatId);
await dispatch(
ChatStore.ACTION_SAVE_CURRENT_CHAT_ID_VERSION,
chatId
);
// 打开会话后获取一下会话列表,刷新未读消息
dispatch(ChatStore.ACTION_GET_MY_CHAT_LIST);
},
......@@ -623,19 +630,10 @@ export default {
return;
}
const chat = data.args[0] as RawChatItem;
if (!chat.model_name && chat.business_data) {
const b = JSON.parse(chat.business_data) as {
model_name: string;
obj_id: string;
};
chat.model_name = b.model_name;
chat.obj_id = b.obj_id;
}
wantedChatRoom = {
...chat,
chat_id: chat.id,
} as ChatType;
commit(ChatStore.MUTATION_SAVE_SINGLE_CHAT, wantedChatRoom);
commit(
ChatStore.MUTATION_SAVE_SINGLE_CHAT,
(wantedChatRoom = buildChatItem(chat))
);
} else {
commit(ChatStore.MUTATION_CLEAR_SINGLE_CHAT);
}
......@@ -663,7 +661,6 @@ export default {
);
})
.catch(console.error);
commit(ChatStore.MUTATION_INITING_CHAT);
removeRegisterChatEvents.forEach((k) => k());
removeRegisterChatEvents = [];
......@@ -674,7 +671,7 @@ export default {
]);
commit(
ChatStore.MUTATION_SAVE_CHAT_TITLE,
wantedChatRoom.title || chatId
wantedChatRoom.title || `会话${chatId}`
);
commit(ChatStore.MUTATION_INITING_CHAT_DONE);
commit(ChatStore.MUTATION_SCROLL_TO_BOTTOM);
......@@ -688,9 +685,9 @@ export default {
},
async [ChatStore.ACTION_GET_CHAT_MEMBERS]({ commit, state }) {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (chatId == null) return;
if (!chatId) return;
const getChatMembersResult = await xim.fetchChatMembers(chatId);
if (getChatMembersResult == null) return;
if (!getChatMembersResult) return;
const chatMembers = getChatMembersResult.args[0] as ChatMember[];
let newChatMembers = await Promise.all(
chatMembers.map(async (member) => {
......@@ -888,8 +885,10 @@ export default {
[ChatStore.STATE_CHAT_MSG_HISTORY](state) {
// 过滤消息撤回
const msgList = state[ChatStore.STATE_CHAT_MSG_HISTORY] ?? [];
const drawList = msgList.filter(i => i.type === MessageType.Withdraw).map(i => +i.msg);
return msgList.filter(i => !drawList.includes(i.id));
const drawList = msgList
.filter((i) => i.type === MessageType.Withdraw)
.map((i) => +i.msg);
return msgList.filter((i) => !drawList.includes(i.id));
},
[ChatStore.STATE_CHAT_SENDING_MESSAGES](state) {
return state[ChatStore.STATE_CHAT_SENDING_MESSAGES] || [];
......
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