Commit 9861a612 by Sixong.Zhu

u

parent e25d4958
Showing with 27 additions and 5 deletions
...@@ -164,6 +164,7 @@ ...@@ -164,6 +164,7 @@
private emoji: EmojiItem[] = []; private emoji: EmojiItem[] = [];
private percentage = 0; private percentage = 0;
private reloadTimer = 0;
@Watch("chatId") @Watch("chatId")
private onChatIdChanged(v: number, old: number) { private onChatIdChanged(v: number, old: number) {
...@@ -344,7 +345,10 @@ ...@@ -344,7 +345,10 @@
if (this.chatId) { if (this.chatId) {
chatCache[this.chatId] = []; chatCache[this.chatId] = [];
} }
setTimeout(() => this.getMyChatList(), 120); if (this.reloadTimer) {
clearTimeout(this.reloadTimer);
}
this.reloadTimer = setTimeout(() => this.getMyChatList(), 120);
} }
/** /**
......
...@@ -124,6 +124,16 @@ export function getLastMessageId(msgs: Message[] | any) { ...@@ -124,6 +124,16 @@ export function getLastMessageId(msgs: Message[] | any) {
return 0; return 0;
} }
let loadingChatList = false;
let cachedLoadingChatListAction: ((value: ChatType[]) => void)[] = [];
function clearAction(value: ChatType[]) {
for (const item of cachedLoadingChatListAction) {
item(value);
}
cachedLoadingChatListAction = [];
return value;
}
export default { export default {
namespaced: true, namespaced: true,
state: () => ({ state: () => ({
...@@ -412,6 +422,14 @@ export default { ...@@ -412,6 +422,14 @@ export default {
async [ChatStore.ACTION_GET_MY_CHAT_LIST]({ commit, state }) { async [ChatStore.ACTION_GET_MY_CHAT_LIST]({ commit, state }) {
commit(ChatStore.MUTATION_SAVE_MYSELF_ID); commit(ChatStore.MUTATION_SAVE_MYSELF_ID);
if (loadingChatList) {
return new Promise<ChatType[]>((resolve) =>
cachedLoadingChatListAction.push(resolve)
);
}
loadingChatList = true;
let cache = await dbController.getChatList(); let cache = await dbController.getChatList();
cache.sort((x, y) => (x.last_msg_ts < y.last_msg_ts ? 1 : -1)); cache.sort((x, y) => (x.last_msg_ts < y.last_msg_ts ? 1 : -1));
...@@ -467,9 +485,9 @@ export default { ...@@ -467,9 +485,9 @@ export default {
resolve(buildUnreadMessage(cache)); resolve(buildUnreadMessage(cache));
}); });
}); });
}); }).finally(() => (loadingChatList = false));
return await execute().then((d) => d); return await execute().then((d) => clearAction(d));
} }
const execute = () => const execute = () =>
...@@ -490,9 +508,9 @@ export default { ...@@ -490,9 +508,9 @@ export default {
resolve(buildUnreadMessage(items)); resolve(buildUnreadMessage(items));
}); });
}); });
}); }).finally(() => (loadingChatList = false));
return await execute().then((d) => d); return await execute().then((d) => clearAction(d));
}, },
async [ChatStore.ACTION_FORCE_RELOAD_CHAT_LIST]({ commit }) { async [ChatStore.ACTION_FORCE_RELOAD_CHAT_LIST]({ commit }) {
return new Promise<ChatType[]>((resolve) => { return new Promise<ChatType[]>((resolve) => {
......
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