Commit be0ef3af by 吴云建
parents bd4fedae 95cd3bba
Showing with 23 additions and 13 deletions
......@@ -25,7 +25,7 @@ function uniqueMessages(
messages: NonNullable<ChatStore.STATE_CHAT_MSG_HISTORY>
) {
const arr = [...messages];
return unique(arr, function (item, all) {
return unique(arr, function(item, all) {
return all.findIndex((k) => k.id === item.id);
});
}
......@@ -256,7 +256,7 @@ export default {
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 } = {};
return (
state: ChatStoreState,
......@@ -296,9 +296,10 @@ export default {
},
actions: {
async [ChatStore.ACTION_GET_MY_CHAT_LIST]({
state,
commit,
}) /* ...params: Parameters<ChatStore.ACTION_GET_MY_CHAT_LIST> */ {
if (!this.state[ChatStore.STATE_CHAT_CURRENT_USER_UID]) {
}) /* ...params: Parameters<ChatStore.ACTION_GET_MY_CHAT_LIST> */ {
if (!state[ChatStore.STATE_CHAT_CURRENT_USER_UID]) {
const userInfo = await sdk().getUserInfo();
commit(ChatStore.MUTATION_SET_CURRENT_USER_UID, userInfo.id);
}
......@@ -334,7 +335,7 @@ export default {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (chatId == null) return;
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);
await preCacheImgs(data);
commit(ChatStore.MUTATION_SCROLL_TO_BOTTOM);
......@@ -355,7 +356,7 @@ export default {
chatId,
msgId,
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);
return data;
......@@ -371,7 +372,7 @@ export default {
chatId,
msgId,
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);
return data;
......@@ -492,15 +493,21 @@ export default {
},
async [ChatStore.ACTION_SAVE_CURRENT_CHAT_ID_VERSION](
{ 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 ?? [];
let wantedChatRoom = chatList.find(
(k) => k.chat_id === chatId
);
if (wantedChatRoom == null || wantedChatRoom.business_data == null) {
const data = await xim.fetchChat(chatId);
if (!data) {
return;
}
let chat = data.args[0];
let business_data;
if (chat.business_data) {
......@@ -573,14 +580,14 @@ export default {
})
);
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);
} else {
commit(ChatStore.MUTATION_CHAT_UPDATE_IS_MEMBER, false);
}
commit(
ChatStore.MUTATION_SAVE_CURRENT_CHAT_MEMBERS,
unique(newChatMembers, function (item, all) {
unique(newChatMembers, function(item, all) {
return all.findIndex((k) => k.eid === item.eid);
})
);
......
......@@ -201,7 +201,7 @@ export namespace ChatStore {
) => void
export const MUTATION_CLEAR_CURRENT_CHAT_INPUTING = "清空正在输入";
export type MUTATION_CLEAR_CURRENT_CHAT_INPUTING = () => void
export const MUTATION_CHAT_UPDATE_IS_MEMBER = "更新是否是当前成员";
export type MUTATION_CHAT_UPDATE_IS_MEMBER = (v: boolean) => Promise<void>
......@@ -272,7 +272,6 @@ export namespace ChatStore {
}
export interface ChatStoreState {
[ChatStore.STATE_CHAT_MSG_HISTORY]: ChatStore.STATE_CHAT_MSG_HISTORY;
[ChatStore.STATE_CHAT_SENDING_MESSAGES]: ChatStore.STATE_CHAT_SENDING_MESSAGES;
[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]: ChatStore.STATE_CHAT_CURRENT_CHAT_ID;
......@@ -288,6 +287,10 @@ export interface ChatStoreState {
[ChatStore.STATE_CURRENT_CHAT_INITING]: ChatStore.STATE_CURRENT_CHAT_INITING;
[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_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);
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