Commit 77f708a6 by 杨铁龙

indexdb orgid 使用传入的orgid

parent d940313d
Showing with 11 additions and 12 deletions
...@@ -57,17 +57,17 @@ class ChatCacheDatabaseController { ...@@ -57,17 +57,17 @@ class ChatCacheDatabaseController {
} }
resolve(); resolve();
}; };
r.onsuccess = function (e) { r.onsuccess = function(e) {
that.db = (e.target as any).result; that.db = (e.target as any).result;
console.log(`index database init comepleted`); console.log(`index database init comepleted`);
setupDb(); setupDb();
}; };
r.onupgradeneeded = function (e) { r.onupgradeneeded = function(e) {
that.db = (e.target as any).result; that.db = (e.target as any).result;
console.log(`upgrade database comepleted`); console.log(`upgrade database comepleted`);
setupDb(); setupDb();
}; };
r.onerror = function (e) { r.onerror = function(e) {
console.log(`index database init failed, ${e}`); console.log(`index database init failed, ${e}`);
}; };
} else { } else {
...@@ -94,17 +94,17 @@ class ChatCacheDatabaseController { ...@@ -94,17 +94,17 @@ class ChatCacheDatabaseController {
} }
setTimeout(() => resolve(), 200); setTimeout(() => resolve(), 200);
}; };
r.onsuccess = function (e) { r.onsuccess = function(e) {
const db = (e.target as any).result; const db = (e.target as any).result;
that.messageDatabases.set(k, db); that.messageDatabases.set(k, db);
setupDb(); setupDb();
}; };
r.onupgradeneeded = function (e) { r.onupgradeneeded = function(e) {
const db = (e.target as any).result; const db = (e.target as any).result;
that.messageDatabases.set(k, db); that.messageDatabases.set(k, db);
setupDb(); setupDb();
}; };
r.onerror = function (e) { r.onerror = function(e) {
console.log( console.log(
`chat message index database init failed, ${e}` `chat message index database init failed, ${e}`
); );
......
...@@ -59,7 +59,7 @@ class Chat implements ChatMessageController { ...@@ -59,7 +59,7 @@ class Chat implements ChatMessageController {
option.avatar !== undefined && option.avatar !== undefined &&
(this.defaultAvatar = option.avatar); (this.defaultAvatar = option.avatar);
await this.setupIndexDb(); await this.setupIndexDb(option.orgId());
this.token = async () => option.sdk().global.jwtToken; this.token = async () => option.sdk().global.jwtToken;
tokenManager.save(this.token); tokenManager.save(this.token);
...@@ -83,12 +83,11 @@ class Chat implements ChatMessageController { ...@@ -83,12 +83,11 @@ class Chat implements ChatMessageController {
}); });
} }
private setupIndexDb() { private setupIndexDb(orgId: number | string) {
if (this._sdk) { if (this._sdk) {
const s = this._sdk(); const s = this._sdk();
return dbController.setup( const key = `${s.global.uid}-${orgId || 0}`
s.global.uid + "-" + (s.global.initData.orgId || 0) return dbController.setup(key);
);
} }
return Promise.reject(new Error("Sdk is not defined")); return Promise.reject(new Error("Sdk is not defined"));
} }
...@@ -96,7 +95,7 @@ class Chat implements ChatMessageController { ...@@ -96,7 +95,7 @@ class Chat implements ChatMessageController {
public resetup(org: () => string | number) { public resetup(org: () => string | number) {
this._orgId = org; this._orgId = org;
xim.onConnected(); xim.onConnected();
return this.setupIndexDb(); return this.setupIndexDb(org());
} }
public unSetup() { public unSetup() {
......
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