Commit b3433377 by Sixong.Zhu

update

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