Commit e25d4958 by Sixong.Zhu

u

parent 959d9b39
Showing with 10 additions and 4 deletions
......@@ -222,10 +222,12 @@ export default {
[ChatStore.MUTATION_SAVE_MYSELF_ID](state) {
if (!state[ChatStore.STATE_CHAT_MY_ID]) {
Chat.getToken().then((token) => {
if (token) {
const eid =
decodeJwt<{ user_id: string; sub: string }>(token);
state[ChatStore.STATE_CHAT_MY_ID] = String(eid.user_id);
state[ChatStore.STATE_CHAT_MY_UID] = eid.sub;
}
});
}
},
......
......@@ -56,8 +56,7 @@ class Chat {
this.eventHub = option.eventHub || null;
option.message && (this.messageController = option.message);
option.avatar !== undefined &&
(this.defaultAvatar = option.avatar);
option.avatar !== undefined && (this.defaultAvatar = option.avatar);
await this.setupIndexDb(option.orgId());
this.token = async () => option.sdk().global.jwtToken;
......@@ -73,7 +72,9 @@ class Chat {
// 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(() => {
this.connected = true;
......@@ -86,7 +87,7 @@ class Chat {
private setupIndexDb(orgId: number | string) {
if (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 Promise.reject();
......@@ -134,8 +135,11 @@ class Chat {
}
public async getToken() {
if (this.token) {
return this.trimToken(await this.token());
}
return Promise.resolve("");
}
private async initChatSdk(uri: string) {
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