Commit e25d4958 by Sixong.Zhu

u

parent 959d9b39
Showing with 10 additions and 4 deletions
...@@ -222,10 +222,12 @@ export default { ...@@ -222,10 +222,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) => {
if (token) {
const eid = const eid =
decodeJwt<{ user_id: string; sub: string }>(token); decodeJwt<{ user_id: string; sub: string }>(token);
state[ChatStore.STATE_CHAT_MY_ID] = String(eid.user_id); state[ChatStore.STATE_CHAT_MY_ID] = String(eid.user_id);
state[ChatStore.STATE_CHAT_MY_UID] = eid.sub; state[ChatStore.STATE_CHAT_MY_UID] = eid.sub;
}
}); });
} }
}, },
......
...@@ -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,8 +135,11 @@ class Chat { ...@@ -134,8 +135,11 @@ class Chat {
} }
public async getToken() { public async getToken() {
if (this.token) {
return this.trimToken(await this.token()); return this.trimToken(await this.token());
} }
return Promise.resolve("");
}
private async initChatSdk(uri: string) { private async initChatSdk(uri: string) {
if (xim.isConnected()) { if (xim.isConnected()) {
......
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