Commit 73050731 by Sixong.Zhu

store

parent cf9c45b6
Showing with 15 additions and 7 deletions
...@@ -31,7 +31,7 @@ function uniqueMessages( ...@@ -31,7 +31,7 @@ function uniqueMessages(
messages: NonNullable<ChatStore.STATE_CHAT_MSG_HISTORY> messages: NonNullable<ChatStore.STATE_CHAT_MSG_HISTORY>
) { ) {
const arr = [...messages]; const arr = [...messages];
return unique(arr, function (item, all) { return unique(arr, function(item, all) {
return all.findIndex((k) => k.id === item.id); return all.findIndex((k) => k.id === item.id);
}); });
} }
...@@ -335,7 +335,7 @@ export default { ...@@ -335,7 +335,7 @@ export default {
state[ChatStore.STATE_CHAT_SENDING_MESSAGES] = [...current]; state[ChatStore.STATE_CHAT_SENDING_MESSAGES] = [...current];
} }
}, },
[ChatStore.MUTATION_SAVE_CURRENT_CHAT_INPUTING]: (function () { [ChatStore.MUTATION_SAVE_CURRENT_CHAT_INPUTING]: (function() {
const setTimeoutId: { [key: string]: number } = {}; const setTimeoutId: { [key: string]: number } = {};
return ( return (
state: ChatStoreState, state: ChatStoreState,
...@@ -483,6 +483,11 @@ export default { ...@@ -483,6 +483,11 @@ export default {
items.forEach((i) => (sum += i.unread_msg_count)); items.forEach((i) => (sum += i.unread_msg_count));
state[ChatStore.STATE_CURRENT_UNREAD_MESSAGE_COUNT] = sum; state[ChatStore.STATE_CURRENT_UNREAD_MESSAGE_COUNT] = sum;
}, },
async [ChatStore.ACTION_UPDATE_CHAT_UNREAD_MESSAGE_COUNT]({ dispatch }, p: { chat: number; unread: number }) {
dbController
.updateChat4UnreadCount(p.chat, p.unread)
.then(() => dispatch(ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT))
},
async [ChatStore.ACTION_GET_CHAT_MESSAGES]({ state, commit, getters }) { async [ChatStore.ACTION_GET_CHAT_MESSAGES]({ state, commit, getters }) {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]; const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
const chat = getters[ const chat = getters[
...@@ -840,7 +845,7 @@ export default { ...@@ -840,7 +845,7 @@ export default {
} }
commit( commit(
ChatStore.MUTATION_SAVE_CURRENT_CHAT_MEMBERS, ChatStore.MUTATION_SAVE_CURRENT_CHAT_MEMBERS,
unique(newChatMembers, function (item, all) { unique(newChatMembers, function(item, all) {
return all.findIndex((k) => k.eid === item.eid); return all.findIndex((k) => k.eid === item.eid);
}) })
); );
...@@ -1089,8 +1094,8 @@ export default { ...@@ -1089,8 +1094,8 @@ export default {
p.read_count = option.all p.read_count = option.all
? p.total_read_count ? p.total_read_count
: option.readed : option.readed
? option.readed ? option.readed
: p.read_count + 1; : p.read_count + 1;
} }
} }
} else { } else {
...@@ -1099,8 +1104,8 @@ export default { ...@@ -1099,8 +1104,8 @@ export default {
p.read_count = option.all p.read_count = option.all
? p.total_read_count ? p.total_read_count
: option.readed : option.readed
? option.readed ? option.readed
: p.read_count + 1; : p.read_count + 1;
} }
} }
} }
......
...@@ -378,6 +378,9 @@ export namespace ChatStore { ...@@ -378,6 +378,9 @@ export namespace ChatStore {
export const ACTION_UPDATE_CHAT = "更新会话信息"; export const ACTION_UPDATE_CHAT = "更新会话信息";
export type ACTION_UPDATE_CHAT = (p: ChatUpdateParameter) => void; export type ACTION_UPDATE_CHAT = (p: ChatUpdateParameter) => void;
export const ACTION_UPDATE_CHAT_UNREAD_MESSAGE_COUNT = "更新Chat会话未读消息并重新计数总数";
export type ACTION_UPDATE_CHAT_UNREAD_MESSAGE_COUNT = (p: { chat: number; unread: number }) => void;
} }
export interface ChatStoreState { export interface ChatStoreState {
......
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