Commit be0ef3af by 吴云建
parents bd4fedae 95cd3bba
Showing with 20 additions and 10 deletions
...@@ -25,7 +25,7 @@ function uniqueMessages( ...@@ -25,7 +25,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);
}); });
} }
...@@ -256,7 +256,7 @@ export default { ...@@ -256,7 +256,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,
...@@ -296,9 +296,10 @@ export default { ...@@ -296,9 +296,10 @@ export default {
}, },
actions: { actions: {
async [ChatStore.ACTION_GET_MY_CHAT_LIST]({ async [ChatStore.ACTION_GET_MY_CHAT_LIST]({
state,
commit, commit,
}) /* ...params: Parameters<ChatStore.ACTION_GET_MY_CHAT_LIST> */ { }) /* ...params: Parameters<ChatStore.ACTION_GET_MY_CHAT_LIST> */ {
if (!this.state[ChatStore.STATE_CHAT_CURRENT_USER_UID]) { if (!state[ChatStore.STATE_CHAT_CURRENT_USER_UID]) {
const userInfo = await sdk().getUserInfo(); const userInfo = await sdk().getUserInfo();
commit(ChatStore.MUTATION_SET_CURRENT_USER_UID, userInfo.id); commit(ChatStore.MUTATION_SET_CURRENT_USER_UID, userInfo.id);
} }
...@@ -334,7 +335,7 @@ export default { ...@@ -334,7 +335,7 @@ export default {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]; const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (chatId == null) return; if (chatId == null) return;
try { try {
const data = await xim.queryLastPageMsg(chatType, chatId, 20, !this.state[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER]); const data = await xim.queryLastPageMsg(chatType, chatId, 20, !state[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER]);
commit(ChatStore.MUTATION_PUSH_CHAT_MSG_HISTORY, data); commit(ChatStore.MUTATION_PUSH_CHAT_MSG_HISTORY, data);
await preCacheImgs(data); await preCacheImgs(data);
commit(ChatStore.MUTATION_SCROLL_TO_BOTTOM); commit(ChatStore.MUTATION_SCROLL_TO_BOTTOM);
...@@ -355,7 +356,7 @@ export default { ...@@ -355,7 +356,7 @@ export default {
chatId, chatId,
msgId, msgId,
10, 10,
!this.state[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER] !state[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER]
); );
commit(ChatStore.MUTATION_UNSHIFT_CHAT_MSG_HISTORY, data); commit(ChatStore.MUTATION_UNSHIFT_CHAT_MSG_HISTORY, data);
return data; return data;
...@@ -371,7 +372,7 @@ export default { ...@@ -371,7 +372,7 @@ export default {
chatId, chatId,
msgId, msgId,
10, 10,
!this.state[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER] !state[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER]
); );
commit(ChatStore.MUTATION_PUSH_CHAT_MSG_HISTORY, data); commit(ChatStore.MUTATION_PUSH_CHAT_MSG_HISTORY, data);
return data; return data;
...@@ -492,8 +493,11 @@ export default { ...@@ -492,8 +493,11 @@ export default {
}, },
async [ChatStore.ACTION_SAVE_CURRENT_CHAT_ID_VERSION]( async [ChatStore.ACTION_SAVE_CURRENT_CHAT_ID_VERSION](
{ state, commit, dispatch }, { state, commit, dispatch },
chatId: Parameters<ChatStore.ACTION_SAVE_CURRENT_CHAT_ID_VERSION>[0] chatId: ChatStore.STATE_CHAT_CURRENT_CHAT_ID
) { ) {
if (!chatId) {
return;
}
const chatList = state[ChatStore.STATE_MY_CHAT_ROOM_LIST]?.list ?? []; const chatList = state[ChatStore.STATE_MY_CHAT_ROOM_LIST]?.list ?? [];
let wantedChatRoom = chatList.find( let wantedChatRoom = chatList.find(
(k) => k.chat_id === chatId (k) => k.chat_id === chatId
...@@ -501,6 +505,9 @@ export default { ...@@ -501,6 +505,9 @@ export default {
if (wantedChatRoom == null || wantedChatRoom.business_data == null) { if (wantedChatRoom == null || wantedChatRoom.business_data == null) {
const data = await xim.fetchChat(chatId); const data = await xim.fetchChat(chatId);
if (!data) {
return;
}
let chat = data.args[0]; let chat = data.args[0];
let business_data; let business_data;
if (chat.business_data) { if (chat.business_data) {
...@@ -573,14 +580,14 @@ export default { ...@@ -573,14 +580,14 @@ export default {
}) })
); );
newChatMembers = newChatMembers.filter(it => !it.is_exited) newChatMembers = newChatMembers.filter(it => !it.is_exited)
if (newChatMembers.findIndex(it => it.eid == state[ChatStore.STATE_CHAT_CURRENT_USER_UID]) > -1) { if (newChatMembers.findIndex(it => it.eid === String(state[ChatStore.STATE_CHAT_CURRENT_USER_UID])) > -1) {
commit(ChatStore.MUTATION_CHAT_UPDATE_IS_MEMBER, true); commit(ChatStore.MUTATION_CHAT_UPDATE_IS_MEMBER, true);
} else { } else {
commit(ChatStore.MUTATION_CHAT_UPDATE_IS_MEMBER, false); commit(ChatStore.MUTATION_CHAT_UPDATE_IS_MEMBER, false);
} }
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);
}) })
); );
......
...@@ -272,7 +272,6 @@ export namespace ChatStore { ...@@ -272,7 +272,6 @@ export namespace ChatStore {
} }
export interface ChatStoreState { export interface ChatStoreState {
[ChatStore.STATE_CHAT_MSG_HISTORY]: ChatStore.STATE_CHAT_MSG_HISTORY; [ChatStore.STATE_CHAT_MSG_HISTORY]: ChatStore.STATE_CHAT_MSG_HISTORY;
[ChatStore.STATE_CHAT_SENDING_MESSAGES]: ChatStore.STATE_CHAT_SENDING_MESSAGES; [ChatStore.STATE_CHAT_SENDING_MESSAGES]: ChatStore.STATE_CHAT_SENDING_MESSAGES;
[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]: ChatStore.STATE_CHAT_CURRENT_CHAT_ID; [ChatStore.STATE_CHAT_CURRENT_CHAT_ID]: ChatStore.STATE_CHAT_CURRENT_CHAT_ID;
...@@ -288,6 +287,10 @@ export interface ChatStoreState { ...@@ -288,6 +287,10 @@ export interface ChatStoreState {
[ChatStore.STATE_CURRENT_CHAT_INITING]: ChatStore.STATE_CURRENT_CHAT_INITING; [ChatStore.STATE_CURRENT_CHAT_INITING]: ChatStore.STATE_CURRENT_CHAT_INITING;
[ChatStore.STATE_MY_CHAT_ROOM_LIST]: ChatStore.STATE_MY_CHAT_ROOM_LIST; [ChatStore.STATE_MY_CHAT_ROOM_LIST]: ChatStore.STATE_MY_CHAT_ROOM_LIST;
[ChatStore.STATE_CHAT_DIALOG_VISIBLE]: ChatStore.STATE_CHAT_DIALOG_VISIBLE; [ChatStore.STATE_CHAT_DIALOG_VISIBLE]: ChatStore.STATE_CHAT_DIALOG_VISIBLE;
[ChatStore.STATE_CHAT_DIALOG_IS_SINGLE]: ChatStore.STATE_CHAT_DIALOG_IS_SINGLE
[ChatStore.STATE_SINGLE_CHAT]: ChatStore.STATE_SINGLE_CHAT
[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER]: ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER
[ChatStore.STATE_CHAT_CURRENT_USER_UID]: ChatStore.STATE_CHAT_CURRENT_USER_UID
} }
export const chatStore = namespace(ChatStore.ns); export const chatStore = namespace(ChatStore.ns);
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