Commit b3433377 by Sixong.Zhu

update

parent 540f3673
Showing with 25 additions and 7 deletions
......@@ -7,6 +7,7 @@ import {
MessageHandled,
RawChatItem,
BaseChatItemBusinessData,
MessageType,
} from "../model";
import { isAccessibleUrl } from "../service/tools";
import { unique } from "../utils";
......@@ -199,10 +200,15 @@ export default {
) {
const old = state[ChatStore.STATE_CHAT_MSG_HISTORY] || [];
const chatid = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (chatid == null) return;
state[ChatStore.STATE_CHAT_MSG_HISTORY] = Object.freeze(
filterMessages([...old, ...(data || [])], chatid)
);
if (chatid) {
// 移除撤回的消息
const newItems = data || [];
const withdraw = newItems.filter(i => i.type === MessageType.Withdraw).map(i => +i.msg);
const filterout = newItems.filter(i => !withdraw.includes(i.id));
state[ChatStore.STATE_CHAT_MSG_HISTORY] = Object.freeze(
filterMessages([...old, ...filterout], chatid)
);
}
},
[ChatStore.MUTATION_SAVE_MYSELF_ID](state) {
if (!state[ChatStore.STATE_CHAT_MY_ID]) {
......@@ -667,10 +673,22 @@ export default {
}) {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
const onNewMsg = (e: Message) => {
if (e.chat_id === chatId) {
dispatch(ChatStore.ACTION_GET_FRESH_MESSAGE);
const thenAction = () => {
if (e.type === MessageType.Withdraw) {
commit(ChatStore.MUTATION_WITHDRAW, +e.msg);
}
const scroll = () => state[ChatStore.STATE_FUNC_ON_NEW_MSG](e);
if (e.chat_id === chatId) {
dispatch(ChatStore.ACTION_GET_FRESH_MESSAGE).finally(() => scroll());
} else {
scroll();
}
};
if (e.type === MessageType.Withdraw) {
dbController.removeMessage(e.chat_id, +e.msg).finally(() => thenAction());
} else {
thenAction();
}
state[ChatStore.STATE_FUNC_ON_NEW_MSG](e);
};
if (!chatId) {
xim.off("msg", onNewMsg);
......
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