Commit baa3d07f by 杨铁龙

格式化

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