Commit cf9c45b6 by Sixong.Zhu

update

parent 483d728f
Showing with 30 additions and 6 deletions
......@@ -57,17 +57,17 @@ class ChatCacheDatabaseController {
}
resolve();
};
r.onsuccess = function (e) {
r.onsuccess = function(e) {
that.db = (e.target as any).result;
console.log(`index database init comepleted`);
setupDb();
};
r.onupgradeneeded = function (e) {
r.onupgradeneeded = function(e) {
that.db = (e.target as any).result;
console.log(`upgrade database comepleted`);
setupDb();
};
r.onerror = function (e) {
r.onerror = function(e) {
console.log(`index database init failed, ${e}`);
};
} else {
......@@ -94,17 +94,17 @@ class ChatCacheDatabaseController {
}
setTimeout(() => resolve(), 200);
};
r.onsuccess = function (e) {
r.onsuccess = function(e) {
const db = (e.target as any).result;
that.messageDatabases.set(k, db);
setupDb();
};
r.onupgradeneeded = function (e) {
r.onupgradeneeded = function(e) {
const db = (e.target as any).result;
that.messageDatabases.set(k, db);
setupDb();
};
r.onerror = function (e) {
r.onerror = function(e) {
console.log(
`chat message index database init failed, ${e}`
);
......@@ -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) {
return new Promise<void>((resolve) => {
if (this.db) {
......@@ -351,6 +374,7 @@ class ChatCacheDatabaseController {
for (const item of source2) {
const t = source1.find((i) => i.id === item.id);
if (t) {
item.unread_msg_count = Math.max(item.unread_msg_count, t.unread_msg_count);
const index = source1.indexOf(t);
source1[index] = item;
} 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