Commit fe6e470e by Sixong.Zhu

Merge branch 'master' into pre

parents 89e76ac1 3e2c1309
...@@ -207,7 +207,7 @@ ...@@ -207,7 +207,7 @@
QuestionAnswerMessage, QuestionAnswerMessage,
ActionMessage, ActionMessage,
PayMessage, PayMessage,
NotifyMessage NotifyMessage,
}, },
}) })
export default class Message extends Vue { export default class Message extends Vue {
...@@ -326,8 +326,13 @@ ...@@ -326,8 +326,13 @@
return true; return true;
} }
const senderEid = this.messageBody.eid; const senderEid = +this.messageBody.eid;
return senderEid!.toString() === this.chatMyId!.toString(); const m1 = senderEid === +this.chatMyId;
if (m1 && this.chatMembers) {
const m2 = _.find(this.chatMembers, (i) => +i.eid === senderEid);
return m2 && +m2.oid === +this.messageBody.oid;
}
return false;
} }
private get userName() { private get userName() {
......
...@@ -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: () => ({
...@@ -222,10 +232,12 @@ export default { ...@@ -222,10 +232,12 @@ export default {
[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]) {
Chat.getToken().then((token) => { Chat.getToken().then((token) => {
const eid = if (token) {
decodeJwt<{ user_id: string; sub: string }>(token); const eid =
state[ChatStore.STATE_CHAT_MY_ID] = String(eid.user_id); decodeJwt<{ user_id: string; sub: string }>(token);
state[ChatStore.STATE_CHAT_MY_UID] = eid.sub; state[ChatStore.STATE_CHAT_MY_ID] = String(eid.user_id);
state[ChatStore.STATE_CHAT_MY_UID] = eid.sub;
}
}); });
} }
}, },
...@@ -410,6 +422,14 @@ export default { ...@@ -410,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));
...@@ -465,9 +485,9 @@ export default { ...@@ -465,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 = () =>
...@@ -488,9 +508,9 @@ export default { ...@@ -488,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) => {
......
...@@ -56,8 +56,7 @@ class Chat { ...@@ -56,8 +56,7 @@ class Chat {
this.eventHub = option.eventHub || null; this.eventHub = option.eventHub || null;
option.message && (this.messageController = option.message); option.message && (this.messageController = option.message);
option.avatar !== undefined && option.avatar !== undefined && (this.defaultAvatar = option.avatar);
(this.defaultAvatar = option.avatar);
await this.setupIndexDb(option.orgId()); await this.setupIndexDb(option.orgId());
this.token = async () => option.sdk().global.jwtToken; this.token = async () => option.sdk().global.jwtToken;
...@@ -73,7 +72,9 @@ class Chat { ...@@ -73,7 +72,9 @@ class Chat {
// this.keywords = ["社保"]; // this.keywords = ["社保"];
const path = socketMapping.get(option.connection as ImEnvironment) as string || option.connection as string; const path =
(socketMapping.get(option.connection as ImEnvironment) as string) ||
(option.connection as string);
return this.initChatSdk((this.ws = path)).finally(() => { return this.initChatSdk((this.ws = path)).finally(() => {
this.connected = true; this.connected = true;
...@@ -86,7 +87,7 @@ class Chat { ...@@ -86,7 +87,7 @@ class Chat {
private setupIndexDb(orgId: number | string) { private setupIndexDb(orgId: number | string) {
if (this._sdk) { if (this._sdk) {
const s = this._sdk(); const s = this._sdk();
const key = `${s.global.uid}-${orgId || 0}` const key = `${s.global.uid}-${orgId || 0}`;
return dbController.setup(key); return dbController.setup(key);
} }
return Promise.reject(); return Promise.reject();
...@@ -134,7 +135,10 @@ class Chat { ...@@ -134,7 +135,10 @@ class Chat {
} }
public async getToken() { public async getToken() {
return this.trimToken(await this.token()); if (this.token) {
return this.trimToken(await this.token());
}
return Promise.resolve("");
} }
private async initChatSdk(uri: string) { private async initChatSdk(uri: string) {
......
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