Commit cf9c45b6 by Sixong.Zhu

update

parent 483d728f
Showing with 30 additions and 6 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}`
); );
...@@ -173,6 +173,29 @@ class ChatCacheDatabaseController { ...@@ -173,6 +173,29 @@ class ChatCacheDatabaseController {
}); });
} }
public updateChat4UnreadCount(chat: number, unread: number) {
return new Promise<void>((resolve) => {
if (this.db) {
const store = this.buildStore(this.chatListKey);
const t = store.get(chat);
t.onsuccess = (r) => {
const chat = (r.target as any).result as Chat;
if (chat) {
chat.unread_msg_count = unread;
const u = store.put(chat, chat.id);
u.onsuccess = () => resolve();
u.onerror = () => resolve();
} else {
resolve();
}
};
t.onerror = () => resolve();
} else {
resolve();
}
});
}
public setRead(chat: number) { public setRead(chat: number) {
return new Promise<void>((resolve) => { return new Promise<void>((resolve) => {
if (this.db) { if (this.db) {
...@@ -351,6 +374,7 @@ class ChatCacheDatabaseController { ...@@ -351,6 +374,7 @@ class ChatCacheDatabaseController {
for (const item of source2) { for (const item of source2) {
const t = source1.find((i) => i.id === item.id); const t = source1.find((i) => i.id === item.id);
if (t) { if (t) {
item.unread_msg_count = Math.max(item.unread_msg_count, t.unread_msg_count);
const index = source1.indexOf(t); const index = source1.indexOf(t);
source1[index] = item; source1[index] = item;
} else { } else {
......
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