Commit baa3d07f by 杨铁龙

格式化

parent 05c87287
Showing with 30 additions and 30 deletions
......@@ -63,17 +63,17 @@ class ChatCacheDatabaseController {
}
resolve();
};
r.onsuccess = (e) => {
r.onsuccess = e => {
this.db = (e.target as any).result;
console.log(`index database init comepleted`);
setupDb();
};
r.onupgradeneeded = (e) => {
r.onupgradeneeded = e => {
this.db = (e.target as any).result;
console.log(`upgrade database comepleted`);
setupDb();
};
r.onerror = (e) => {
r.onerror = e => {
console.log(`index database init failed, ${e}`);
this.setupError = true;
reject();
......@@ -88,7 +88,7 @@ class ChatCacheDatabaseController {
const k = this.buildChatMessageKey(chat);
const t = this.messageDatabases.get(k);
if (!t) {
return new Promise<void>((resolve) => {
return new Promise<void>(resolve => {
if (this.uid && indexedDB) {
const r = indexedDB.open(k, this.msgVersion);
// eslint-disable-next-line @typescript-eslint/no-this-alias
......@@ -102,17 +102,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}`
);
......@@ -159,11 +159,11 @@ class ChatCacheDatabaseController {
}
public updateChat(p: ChatStore.ChatUpdateParameter) {
return new Promise<void>((resolve) => {
return new Promise<void>(resolve => {
if (this.db) {
const store = this.buildStore(this.chatListKey);
const t = store.get(p.chat);
t.onsuccess = (r) => {
t.onsuccess = r => {
const chat = (r.target as any).result as Chat;
if (chat) {
chat.eid = p.eid as string;
......@@ -187,11 +187,11 @@ class ChatCacheDatabaseController {
}
public updateChat4UnreadCount(chat: number, unread: number) {
return new Promise<void>((resolve) => {
return new Promise<void>(resolve => {
if (this.db) {
const store = this.buildStore(this.chatListKey);
const t = store.get(chat);
t.onsuccess = (r) => {
t.onsuccess = r => {
const chat = (r.target as any).result as Chat;
if (chat) {
chat.unread_msg_count = unread;
......@@ -210,11 +210,11 @@ class ChatCacheDatabaseController {
}
public setRead(chat: number) {
return new Promise<void>((resolve) => {
return new Promise<void>(resolve => {
if (this.db) {
const store = this.buildStore(this.chatListKey);
const t = store.get(chat);
t.onsuccess = (r) => {
t.onsuccess = r => {
const chat = (r.target as any).result as Chat;
if (chat) {
chat.unread_msg_count = 0;
......@@ -249,7 +249,7 @@ class ChatCacheDatabaseController {
allRead?: boolean;
}
) {
return new Promise<void>((resolve) => {
return new Promise<void>(resolve => {
if (this.db) {
const store = this.buildChatMessageStore(chat);
if (option.end && option.end > option.start) {
......@@ -263,7 +263,7 @@ class ChatCacheDatabaseController {
};
for (let i = option.start; i <= option.end; i++) {
const r = store.get(i);
r.onsuccess = (m) => {
r.onsuccess = m => {
const p = (m.target as any).result as Message;
if (p) {
if (option.allRead) {
......@@ -280,7 +280,7 @@ class ChatCacheDatabaseController {
}
} else {
const r = store.get(option.start);
r.onsuccess = (m) => {
r.onsuccess = m => {
const p = (m.target as any).result as Message;
if (p) {
if (option.allRead) {
......@@ -302,7 +302,7 @@ class ChatCacheDatabaseController {
}
public removeChatFromList(chat: number) {
return new Promise<void>((resolve) => {
return new Promise<void>(resolve => {
if (this.db) {
const store = this.buildStore(this.chatListKey);
const t = store.delete(chat);
......@@ -315,27 +315,27 @@ class ChatCacheDatabaseController {
}
public getChatList() {
return new Promise<Chat[]>((resolve) => {
return new Promise<Chat[]>(resolve => {
if (!this.db) {
return resolve([]);
}
const store = this.buildStore(this.chatListKey);
const r = store.getAll();
r.onsuccess = (o) => resolve((o.target as any).result);
r.onsuccess = o => resolve((o.target as any).result);
r.onerror = () => resolve([]);
});
}
public getChatByCode(code: string) {
return new Promise<Chat | null>((resolve) => {
return new Promise<Chat | null>(resolve => {
if (!this.db) {
return resolve(null);
}
const store = this.buildStore(this.chatListKey);
const r = store.getAll();
r.onsuccess = (o) => {
r.onsuccess = o => {
const items = (o.target as any).result as Chat[];
resolve(items.find((i) => i.biz_type_code === code) as Chat);
resolve(items.find(i => i.biz_type_code === code) as Chat);
};
r.onerror = () => resolve(null);
});
......@@ -360,21 +360,21 @@ class ChatCacheDatabaseController {
}
public getChatMessages(chat: number) {
return new Promise<Message[]>((resolve) => {
return new Promise<Message[]>(resolve => {
if (!this.db) {
return resolve([]);
}
this.setupChatMessageDatabase(chat).finally(() => {
const store = this.buildChatMessageStore(chat);
const r = store.getAll();
r.onsuccess = (o) => resolve((o.target as any).result);
r.onsuccess = o => resolve((o.target as any).result);
r.onerror = () => resolve([]);
});
});
}
public appendMessages(chat: number, items: Message[]) {
return new Promise<void>((resolve) => {
return new Promise<void>(resolve => {
if (!this.db || !items.length) {
return resolve();
}
......@@ -409,7 +409,7 @@ class ChatCacheDatabaseController {
public mergeChatList(source1: Chat[], source2: Chat[]) {
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) {
item.unread_msg_count = Math.max(
item.unread_msg_count,
......@@ -441,14 +441,14 @@ class ChatCacheDatabaseController {
msg: number,
status: MessageHandled
) {
return new Promise<void>((resolve) => {
return new Promise<void>(resolve => {
if (!this.db) {
return resolve();
}
this.setupChatMessageDatabase(chat).finally(() => {
const store = this.buildChatMessageStore(chat);
const r = store.get(msg);
r.onsuccess = (o) => {
r.onsuccess = o => {
const p = (o.target as any).result as Message;
p.handled = status;
const u = store.put(p);
......@@ -461,9 +461,9 @@ class ChatCacheDatabaseController {
}
public syncChats(chats: number[]) {
return new Promise<void>((resolve) => {
return new Promise<void>(resolve => {
if (this.db) {
this.getChatList().then((r) => {
this.getChatList().then(r => {
const set = new Set<number>(chats);
let finished = 0;
......
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