Commit f129063c by Sixong.Zhu

update

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