Commit 6711c5df by 董文博
parents d6f6f97f 64c2972a
...@@ -56,15 +56,9 @@ ...@@ -56,15 +56,9 @@
@chatStore.State(ChatStore.STATE_CHAT_CURRENT_CHAT_ID) @chatStore.State(ChatStore.STATE_CHAT_CURRENT_CHAT_ID)
private readonly chatId!: ChatStore.STATE_CHAT_CURRENT_CHAT_ID; private readonly chatId!: ChatStore.STATE_CHAT_CURRENT_CHAT_ID;
@chatStore.Mutation(ChatStore.MUTATION_CLEAR_CURRENT_CHAT_MEMBERS)
private readonly clearChatMembers!: ChatStore.MUTATION_CLEAR_CURRENT_CHAT_MEMBERS;
@chatStore.State(ChatStore.STATE_CURRENT_CHAT_INPUTING) @chatStore.State(ChatStore.STATE_CURRENT_CHAT_INPUTING)
private readonly currentInputPeople!: ChatStore.STATE_CURRENT_CHAT_INPUTING; private readonly currentInputPeople!: ChatStore.STATE_CURRENT_CHAT_INPUTING;
@chatStore.State(ChatStore.STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID)
private readonly currentChatUniplatId!: ChatStore.STATE_CHAT_CURRENT_CHAT_UNIPLAT_ID;
@chatStore.State(ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER) @chatStore.State(ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER)
private readonly isChatMember!: ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER; private readonly isChatMember!: ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER;
...@@ -82,12 +76,6 @@ ...@@ -82,12 +76,6 @@
@Provide() showReadSummary = true; @Provide() showReadSummary = true;
@Watch("currentChatUniplatId")
private whenCurrentChatIdChanged(newValue: string, oldValue: string) {
if (Number(oldValue) === Number(newValue)) return;
this.clearChatMembers();
}
private get getCurrentInputingPeople() { private get getCurrentInputingPeople() {
return this.currentInputPeople return this.currentInputPeople
.map(() => "" /* this.userInfo[k].name */) .map(() => "" /* this.userInfo[k].name */)
...@@ -174,6 +162,7 @@ ...@@ -174,6 +162,7 @@
), ),
300 300
); );
this.$emit("send");
} }
} }
</script> </script>
...@@ -184,7 +173,7 @@ ...@@ -184,7 +173,7 @@
width: 46px; width: 46px;
height: 20px; height: 20px;
line-height: 20px; line-height: 20px;
background: #22bd7a; background-color: #22bd7a;
font-size: 13px; font-size: 13px;
border-radius: 2px; border-radius: 2px;
color: #ffffff; color: #ffffff;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
width="90%" width="90%"
> >
<div class="d-flex flex-column"> <div class="d-flex flex-column">
<div class="d-flex justify-content-center"> <div class="d-flex justify-content-center align-items-start">
<img v-if="file" :src="file.url" /> <img v-if="file" :src="file.url" />
<i class="el-icon-close" @click="close"></i> <i class="el-icon-close" @click="close"></i>
</div> </div>
......
...@@ -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}`
); );
...@@ -163,11 +163,11 @@ class ChatCacheDatabaseController { ...@@ -163,11 +163,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;
...@@ -191,11 +191,11 @@ class ChatCacheDatabaseController { ...@@ -191,11 +191,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;
...@@ -214,11 +214,11 @@ class ChatCacheDatabaseController { ...@@ -214,11 +214,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;
...@@ -253,7 +253,7 @@ class ChatCacheDatabaseController { ...@@ -253,7 +253,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) {
...@@ -267,7 +267,7 @@ class ChatCacheDatabaseController { ...@@ -267,7 +267,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) {
...@@ -284,7 +284,7 @@ class ChatCacheDatabaseController { ...@@ -284,7 +284,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) {
...@@ -306,7 +306,7 @@ class ChatCacheDatabaseController { ...@@ -306,7 +306,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);
...@@ -319,27 +319,27 @@ class ChatCacheDatabaseController { ...@@ -319,27 +319,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);
}); });
...@@ -364,21 +364,21 @@ class ChatCacheDatabaseController { ...@@ -364,21 +364,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 || !items.length) { if (!this.db || !items || !items.length) {
return resolve(); return resolve();
} }
...@@ -413,7 +413,7 @@ class ChatCacheDatabaseController { ...@@ -413,7 +413,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,
...@@ -445,14 +445,14 @@ class ChatCacheDatabaseController { ...@@ -445,14 +445,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);
......
...@@ -82,6 +82,11 @@ export interface ChatOption { ...@@ -82,6 +82,11 @@ export interface ChatOption {
message?: ChatMessageController; message?: ChatMessageController;
avatar?: string; avatar?: string;
/**
* 禁用IndexDb
*/
disabledIndexDb?:boolean;
} }
export interface ChatMessageController { export interface ChatMessageController {
......
import Axios, { AxiosResponse } from "axios"; import Axios, { AxiosResponse, AxiosAdapter } from "axios";
import { UniplatSdk } from "uniplat-sdk"; import { UniplatSdk } from "uniplat-sdk";
import { ImEnvironment } from "../model"; import { ImEnvironment } from "../model";
...@@ -26,6 +26,7 @@ export interface SdkMonitorOption { ...@@ -26,6 +26,7 @@ export interface SdkMonitorOption {
userAgent?: boolean; userAgent?: boolean;
envir: ImEnvironment; envir: ImEnvironment;
product: Product; product: Product;
call?: (r: any) => void;
} }
class WebMonitor { class WebMonitor {
...@@ -33,6 +34,7 @@ class WebMonitor { ...@@ -33,6 +34,7 @@ class WebMonitor {
private envir = ImEnvironment.Dev; private envir = ImEnvironment.Dev;
private product = Product.Default; private product = Product.Default;
private readonly url = "https://pre-hrs-monitor.hrs100.com"; private readonly url = "https://pre-hrs-monitor.hrs100.com";
private adapter: AxiosAdapter | undefined;
public updateKey(key: string) { public updateKey(key: string) {
this.key = key; this.key = key;
...@@ -42,6 +44,7 @@ class WebMonitor { ...@@ -42,6 +44,7 @@ class WebMonitor {
private buildHeaders() { private buildHeaders() {
return { return {
headers: { authorization: "cdd0a34e-f537-4e5b-808e-2ba06af21845" }, headers: { authorization: "cdd0a34e-f537-4e5b-808e-2ba06af21845" },
adapter: this.adapter,
}; };
} }
...@@ -85,11 +88,17 @@ class WebMonitor { ...@@ -85,11 +88,17 @@ class WebMonitor {
); );
} }
public useSdk(sdk: UniplatSdk, options: SdkMonitorOption) { public useSdk(
sdk: UniplatSdk,
options: SdkMonitorOption,
adapter?: AxiosAdapter
) {
this.envir = options.envir; this.envir = options.envir;
this.product = options.product; this.product = options.product;
this.adapter = adapter;
sdk.events.addUniversalErrorResponseCallback( sdk.events.addUniversalErrorResponseCallback(
(r: AxiosResponse<any>) => { (r: AxiosResponse<any>) => {
options.call && options.call(r);
if (this.enable()) { if (this.enable()) {
const msg: string[] = []; const msg: string[] = [];
msg.push( msg.push(
...@@ -111,12 +120,14 @@ class WebMonitor { ...@@ -111,12 +120,14 @@ class WebMonitor {
if (r.config && r.config.data) { if (r.config && r.config.data) {
const form = r.config.data as FormData; const form = r.config.data as FormData;
if (form.getAll) { if (form.getAll) {
const p = form.getAll('parameters'); const p = form.getAll("parameters");
for (const item of p) { for (const item of p) {
msg.push(`Payload: ${item}`); msg.push(`Payload: ${item}`);
} }
} else { } else {
msg.push(`Payload: ${JSON.stringify(r.config.data)}`); msg.push(
`Payload: ${JSON.stringify(r.config.data)}`
);
} }
} }
......
...@@ -56,8 +56,8 @@ async function preCacheImgs(msgs?: any[]) { ...@@ -56,8 +56,8 @@ async function preCacheImgs(msgs?: any[]) {
} }
await Promise.all( await Promise.all(
msgs msgs
.filter((i) => i.id > 0) .filter(i => i.id > 0)
.map((k) => { .map(k => {
return new Promise((resolve: (p: void) => void) => { return new Promise((resolve: (p: void) => void) => {
if (k.type === "image") { if (k.type === "image") {
const msg = JSON.parse(k.msg); const msg = JSON.parse(k.msg);
...@@ -108,14 +108,16 @@ const chatType = "group"; ...@@ -108,14 +108,16 @@ const chatType = "group";
const allowedChatTypes = [chatType, "notify"]; const allowedChatTypes = [chatType, "notify"];
export const filterActiveChats = (items: RawChatItem[]) => { export const filterActiveChats = (items: RawChatItem[]) => {
return items.filter( return items
(i) => .filter(
i =>
!i.is_finish && !i.is_finish &&
!i.is_exited && !i.is_exited &&
!i.is_remove && !i.is_remove &&
!i.is_deleted && !i.is_deleted &&
allowedChatTypes.includes(i.type) allowedChatTypes.includes(i.type)
); )
.sort((x, y) => y.last_msg_ts - x.last_msg_ts);
}; };
export function getLastMessageId(msgs: Message[] | any) { export function getLastMessageId(msgs: Message[] | any) {
...@@ -226,15 +228,15 @@ export default { ...@@ -226,15 +228,15 @@ export default {
// 移除撤回的消息 // 移除撤回的消息
const newItems = data || []; const newItems = data || [];
const hasWithdraw = newItems.find( const hasWithdraw = newItems.find(
(i) => i.type === MessageType.Withdraw i => i.type === MessageType.Withdraw
); );
const withdraw = hasWithdraw const withdraw = hasWithdraw
? newItems ? newItems
.filter((i) => i.type === MessageType.Withdraw) .filter(i => i.type === MessageType.Withdraw)
.map((i) => +i.msg) .map(i => +i.msg)
: []; : [];
const filterout = withdraw.length const filterout = withdraw.length
? newItems.filter((i) => !withdraw.includes(i.id)) ? newItems.filter(i => !withdraw.includes(i.id))
: newItems; : newItems;
state[ChatStore.STATE_CHAT_MSG_HISTORY] = Object.freeze( state[ChatStore.STATE_CHAT_MSG_HISTORY] = Object.freeze(
combineMessages(old, filterout, chatid) combineMessages(old, filterout, chatid)
...@@ -243,10 +245,11 @@ export default { ...@@ -243,10 +245,11 @@ export default {
}, },
[ChatStore.MUTATION_SAVE_MYSELF_ID](state) { [ChatStore.MUTATION_SAVE_MYSELF_ID](state) {
if (!state[ChatStore.STATE_CHAT_MY_ID]) { if (!state[ChatStore.STATE_CHAT_MY_ID]) {
Chat.getToken().then((token) => { Chat.getToken().then(token => {
if (token) { if (token) {
const eid = const eid = decodeJwt<{ user_id: string; sub: string }>(
decodeJwt<{ user_id: string; sub: string }>(token); token
);
state[ChatStore.STATE_CHAT_MY_ID] = String(eid.user_id); state[ChatStore.STATE_CHAT_MY_ID] = String(eid.user_id);
state[ChatStore.STATE_CHAT_MY_UID] = eid.sub; state[ChatStore.STATE_CHAT_MY_UID] = eid.sub;
} }
...@@ -351,7 +354,7 @@ export default { ...@@ -351,7 +354,7 @@ export default {
ChatStore.STATE_CHAT_SENDING_MESSAGES ChatStore.STATE_CHAT_SENDING_MESSAGES
] as ChatStore.STATE_CHAT_SENDING_MESSAGE[]; ] as ChatStore.STATE_CHAT_SENDING_MESSAGE[];
if (current) { if (current) {
const target = current.find((i) => i.id === payload); const target = current.find(i => i.id === payload);
if (target) { if (target) {
const index = current.indexOf(target); const index = current.indexOf(target);
current.splice(index, 1); current.splice(index, 1);
...@@ -366,7 +369,7 @@ export default { ...@@ -366,7 +369,7 @@ export default {
ChatStore.STATE_CHAT_SENDING_MESSAGES ChatStore.STATE_CHAT_SENDING_MESSAGES
] as ChatStore.STATE_CHAT_SENDING_MESSAGE[]; ] as ChatStore.STATE_CHAT_SENDING_MESSAGE[];
if (current) { if (current) {
const target = current.find((i) => i.id === payload); const target = current.find(i => i.id === payload);
if (target) { if (target) {
target.status = -1; target.status = -1;
} }
...@@ -374,11 +377,13 @@ export default { ...@@ -374,11 +377,13 @@ export default {
state[ChatStore.STATE_CHAT_SENDING_MESSAGES] = [...current]; state[ChatStore.STATE_CHAT_SENDING_MESSAGES] = [...current];
} }
}, },
[ChatStore.MUTATION_SAVE_CURRENT_CHAT_INPUTING]: (function () { [ChatStore.MUTATION_SAVE_CURRENT_CHAT_INPUTING]: (function() {
const setTimeoutId: { [key: string]: number } = {}; const setTimeoutId: { [key: string]: number } = {};
return ( return (
state: ChatStoreState, state: ChatStoreState,
payload: Parameters<ChatStore.MUTATION_SAVE_CURRENT_CHAT_INPUTING>[0] payload: Parameters<
ChatStore.MUTATION_SAVE_CURRENT_CHAT_INPUTING
>[0]
) => { ) => {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]; const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (!chatId) return; if (!chatId) return;
...@@ -397,13 +402,13 @@ export default { ...@@ -397,13 +402,13 @@ export default {
); );
}; };
})(), })(),
[ChatStore.MUTATION_CLEAR_CURRENT_CHAT_INPUTING]: (state) => { [ChatStore.MUTATION_CLEAR_CURRENT_CHAT_INPUTING]: state => {
state[ChatStore.STATE_CURRENT_CHAT_INPUTING] = []; state[ChatStore.STATE_CURRENT_CHAT_INPUTING] = [];
}, },
[ChatStore.MUTATION_INITING_CHAT]: (state) => { [ChatStore.MUTATION_INITING_CHAT]: state => {
state[ChatStore.STATE_CURRENT_CHAT_INITING] = true; state[ChatStore.STATE_CURRENT_CHAT_INITING] = true;
}, },
[ChatStore.MUTATION_INITING_CHAT_DONE]: (state) => { [ChatStore.MUTATION_INITING_CHAT_DONE]: state => {
state[ChatStore.STATE_CURRENT_CHAT_INITING] = false; state[ChatStore.STATE_CURRENT_CHAT_INITING] = false;
}, },
[ChatStore.MUTATION_CHAT_UPDATE_IS_MEMBER]: (state, v: boolean) => { [ChatStore.MUTATION_CHAT_UPDATE_IS_MEMBER]: (state, v: boolean) => {
...@@ -426,16 +431,16 @@ export default { ...@@ -426,16 +431,16 @@ export default {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]; const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (!chatId) return; if (!chatId) return;
state[ChatStore.STATE_CHAT_MSG_HISTORY] = old.filter( state[ChatStore.STATE_CHAT_MSG_HISTORY] = old.filter(
(i) => !ids.includes(i.id) i => !ids.includes(i.id)
); );
}, },
}, },
actions: { actions: {
async [ChatStore.ACTION_GET_MY_CHAT_LIST]({ commit, dispatch }) { async [ChatStore.ACTION_GET_MY_CHAT_LIST]({ commit, dispatch, state }) {
commit(ChatStore.MUTATION_SAVE_MYSELF_ID); commit(ChatStore.MUTATION_SAVE_MYSELF_ID);
if (loadingChatList) { if (loadingChatList) {
return new Promise<ChatType[]>((resolve) => return new Promise<ChatType[]>(resolve =>
cachedLoadingChatListAction.push(resolve) cachedLoadingChatListAction.push(resolve)
); );
} }
...@@ -446,14 +451,14 @@ export default { ...@@ -446,14 +451,14 @@ export default {
new Promise<ChatType[]>((resolve, reject) => { new Promise<ChatType[]>((resolve, reject) => {
Chat.onReady(() => { Chat.onReady(() => {
xim.fetchChatList() xim.fetchChatList()
.then((data) => { .then(data => {
if (!data) { if (!data) {
return resolve([]); return resolve([]);
} }
const chatList = filterActiveChats( const chatList = filterActiveChats(
data.args[0] as RawChatItem[] data.args[0] as RawChatItem[]
); );
const items = chatList.map((chat) => const items = chatList.map(chat =>
buildChatItem(chat) buildChatItem(chat)
); );
dbController.saveChatList(items); dbController.saveChatList(items);
...@@ -463,46 +468,29 @@ export default { ...@@ -463,46 +468,29 @@ export default {
); );
dispatch( dispatch(
ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT
).finally(resolve); );
resolve(items);
}) })
.catch(reject); .catch(reject);
}); });
}).finally(() => (loadingChatList = false)); }).finally(() => (loadingChatList = false));
return await execute().then((d) => clearAction(d)); return await execute().then(d => clearAction(d));
}, },
async [ChatStore.ACTION_FORCE_RELOAD_CHAT_LIST]({ commit }) { [ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT]({ state }) {
return new Promise<ChatType[]>((resolve) => { const items = state[ChatStore.STATE_MY_CHAT_ROOM_LIST];
Chat.onReady(() => { if (items) {
xim.fetchChatList().then((data) => {
if (!data) {
return resolve([]);
}
const chatList = filterActiveChats(
data.args[0] as RawChatItem[]
);
const items = chatList.map((chat) =>
buildChatItem(chat)
);
dbController.saveChatList(items);
commit(ChatStore.MUTATION_SAVE_CHAT_LIST, items);
resolve(items);
});
});
});
},
async [ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT]({ state }) {
let items = await dbController.getChatList();
let sum = 0; let sum = 0;
items.forEach((i) => (sum += i.unread_msg_count)); items.forEach(i => (sum += i.unread_msg_count));
state[ChatStore.STATE_CURRENT_UNREAD_MESSAGE_COUNT] = sum; state[ChatStore.STATE_CURRENT_UNREAD_MESSAGE_COUNT] = sum;
}
}, },
async [ChatStore.ACTION_UPDATE_CHAT_UNREAD_MESSAGE_COUNT]( async [ChatStore.ACTION_UPDATE_CHAT_UNREAD_MESSAGE_COUNT](
{ dispatch, state }, { dispatch, state },
p: { chat: number; unread: number } p: { chat: number; unread: number }
) { ) {
const list = state[ChatStore.STATE_MY_CHAT_ROOM_LIST] as ChatType[]; const list = state[ChatStore.STATE_MY_CHAT_ROOM_LIST] as ChatType[];
const t = list.find((i) => i.id === p.chat); const t = list.find(i => i.id === p.chat);
t && (t.unread_msg_count = p.unread); t && (t.unread_msg_count = p.unread);
return dbController return dbController
.updateChat4UnreadCount(p.chat, p.unread) .updateChat4UnreadCount(p.chat, p.unread)
...@@ -556,7 +544,9 @@ export default { ...@@ -556,7 +544,9 @@ export default {
}, },
async [ChatStore.ACTION_GET_CHAT_MESSAGES_BEFORE_SPECIFIC_ID]( async [ChatStore.ACTION_GET_CHAT_MESSAGES_BEFORE_SPECIFIC_ID](
{ state, commit, getters }, { state, commit, getters },
msgId: Parameters<ChatStore.ACTION_GET_CHAT_MESSAGES_BEFORE_SPECIFIC_ID>[0] msgId: Parameters<
ChatStore.ACTION_GET_CHAT_MESSAGES_BEFORE_SPECIFIC_ID
>[0]
) { ) {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]; const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (!chatId) return; if (!chatId) return;
...@@ -581,7 +571,9 @@ export default { ...@@ -581,7 +571,9 @@ export default {
}, },
async [ChatStore.ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID]( async [ChatStore.ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID](
{ state, commit, getters }, { state, commit, getters },
msgId: Parameters<ChatStore.ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID>[0] msgId: Parameters<
ChatStore.ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID
>[0]
) { ) {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]; const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (!chatId) return; if (!chatId) return;
...@@ -654,7 +646,9 @@ export default { ...@@ -654,7 +646,9 @@ export default {
}, },
async [ChatStore.ACTION_CREATE_NEW_CHAT_BY_SERVICE_MAN]( async [ChatStore.ACTION_CREATE_NEW_CHAT_BY_SERVICE_MAN](
{ commit, dispatch }, { commit, dispatch },
params: Parameters<ChatStore.ACTION_CREATE_NEW_CHAT_BY_SERVICE_MAN>[0] params: Parameters<
ChatStore.ACTION_CREATE_NEW_CHAT_BY_SERVICE_MAN
>[0]
) { ) {
const { imChatId, catalog } = await Chat.getSdk() const { imChatId, catalog } = await Chat.getSdk()
.model(params.modelName) .model(params.modelName)
...@@ -710,9 +704,9 @@ export default { ...@@ -710,9 +704,9 @@ export default {
const scroll = () => const scroll = () =>
state[ChatStore.STATE_FUNC_ON_NEW_MSG](e); state[ChatStore.STATE_FUNC_ON_NEW_MSG](e);
if (e.chat_id === chatId) { if (e.chat_id === chatId) {
dispatch(ChatStore.ACTION_GET_FRESH_MESSAGE).finally( dispatch(
() => scroll() ChatStore.ACTION_GET_FRESH_MESSAGE
); ).finally(() => scroll());
} else { } else {
scroll(); scroll();
} }
...@@ -730,7 +724,7 @@ export default { ...@@ -730,7 +724,7 @@ export default {
xim.on("msg", onNewMsg); xim.on("msg", onNewMsg);
return; return;
} }
const onMsgRead: ChatNotifyListener = async (e) => { const onMsgRead: ChatNotifyListener = async e => {
if (chatId !== e.chat_id) return; if (chatId !== e.chat_id) return;
const msgs = state[ChatStore.STATE_CHAT_MSG_HISTORY]; const msgs = state[ChatStore.STATE_CHAT_MSG_HISTORY];
if (msgs == null) return; if (msgs == null) return;
...@@ -762,10 +756,10 @@ export default { ...@@ -762,10 +756,10 @@ export default {
commit(ChatStore.MUTATION_CLEAR_CHAT_MSG_HISTORY); commit(ChatStore.MUTATION_CLEAR_CHAT_MSG_HISTORY);
commit( commit(
ChatStore.MUTATION_PUSH_CHAT_MSG_HISTORY, ChatStore.MUTATION_PUSH_CHAT_MSG_HISTORY,
msgs.map((msg) => { msgs.map(msg => {
msg = { ...msg }; msg = { ...msg };
const newMsg = freshMsgs.find( const newMsg = freshMsgs.find(
(freshMsg) => freshMsg.id === msg.id freshMsg => freshMsg.id === msg.id
); );
if (newMsg != null) { if (newMsg != null) {
msg.read_count = newMsg.read_count; msg.read_count = newMsg.read_count;
...@@ -774,7 +768,7 @@ export default { ...@@ -774,7 +768,7 @@ export default {
}) })
); );
}; };
const onInputing: ChatNotifyListener = (e) => { const onInputing: ChatNotifyListener = e => {
commit(ChatStore.MUTATION_SAVE_CURRENT_CHAT_INPUTING, e); commit(ChatStore.MUTATION_SAVE_CURRENT_CHAT_INPUTING, e);
}; };
removeRegisterChatEvents.push(() => { removeRegisterChatEvents.push(() => {
...@@ -793,10 +787,8 @@ export default { ...@@ -793,10 +787,8 @@ export default {
if (!chatId) { if (!chatId) {
return; return;
} }
const chatList = state[ const chatList = state[ChatStore.STATE_MY_CHAT_ROOM_LIST];
ChatStore.STATE_MY_CHAT_ROOM_LIST let wantedChatRoom = chatList.find(k => k.chat_id === chatId);
] as ChatType[];
let wantedChatRoom = chatList.find((k) => k.chat_id === chatId);
if (!wantedChatRoom) { if (!wantedChatRoom) {
const data = await xim.fetchChat(chatId); const data = await xim.fetchChat(chatId);
...@@ -825,7 +817,7 @@ export default { ...@@ -825,7 +817,7 @@ export default {
wantedChatRoom.obj_id, wantedChatRoom.obj_id,
wantedChatRoom.detail_name wantedChatRoom.detail_name
) )
.then((info) => { .then(info => {
commit( commit(
ChatStore.MUTATION_SAVE_CURRENT_CHAT_VERSION, ChatStore.MUTATION_SAVE_CURRENT_CHAT_VERSION,
info.uniplat_version info.uniplat_version
...@@ -834,12 +826,12 @@ export default { ...@@ -834,12 +826,12 @@ export default {
ChatStore.MUTATION_SAVE_CURRENT_CHAT_UNIPLAT_ID, ChatStore.MUTATION_SAVE_CURRENT_CHAT_UNIPLAT_ID,
info.uniplatId info.uniplatId
); );
dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS);
}) })
.catch(console.error); .catch(console.error);
commit(ChatStore.MUTATION_INITING_CHAT); commit(ChatStore.MUTATION_INITING_CHAT);
removeRegisterChatEvents.forEach((k) => k()); removeRegisterChatEvents.forEach(k => k());
removeRegisterChatEvents = []; removeRegisterChatEvents = [];
await dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS);
try { try {
await Promise.all([ await Promise.all([
dispatch(ChatStore.ACTION_REGISTER_EVENT), dispatch(ChatStore.ACTION_REGISTER_EVENT),
...@@ -877,8 +869,10 @@ export default { ...@@ -877,8 +869,10 @@ export default {
if (!getChatMembersResult) return; if (!getChatMembersResult) return;
const chatMembers = getChatMembersResult.args[0] as ChatMember[]; const chatMembers = getChatMembersResult.args[0] as ChatMember[];
const all = await Promise.all( const all = await Promise.all(
chatMembers.map(async (member) => { chatMembers.map(async member => {
let result: NonNullable<ChatStore.STATE_CURRENT_CHAT_MEMBERS>[number]; let result: NonNullable<
ChatStore.STATE_CURRENT_CHAT_MEMBERS
>[number];
try { try {
const data = await ChatUserInfoService.getUserInfo( const data = await ChatUserInfoService.getUserInfo(
member.eid member.eid
...@@ -896,9 +890,9 @@ export default { ...@@ -896,9 +890,9 @@ export default {
}) })
); );
(<any>state)[ChatStore.STATE_ALL_HISTORY_CHAT_MEMBERS] = all; (<any>state)[ChatStore.STATE_ALL_HISTORY_CHAT_MEMBERS] = all;
const newChatMembers = all.filter((it) => !it.is_exited); const newChatMembers = all.filter(it => !it.is_exited);
const member = newChatMembers.find( const member = newChatMembers.find(
(it) => it =>
it.eid === it.eid ===
String(state[ChatStore.STATE_CHAT_CURRENT_USER_UID]) String(state[ChatStore.STATE_CHAT_CURRENT_USER_UID])
); );
...@@ -912,8 +906,8 @@ export default { ...@@ -912,8 +906,8 @@ export default {
commit( commit(
ChatStore.MUTATION_SAVE_CURRENT_CHAT_MEMBERS, ChatStore.MUTATION_SAVE_CURRENT_CHAT_MEMBERS,
unique(newChatMembers, function (item, all) { unique(newChatMembers, function(item, all) {
return all.findIndex((k) => k.eid === item.eid); return all.findIndex(k => k.eid === item.eid);
}) })
); );
}, },
...@@ -1039,7 +1033,7 @@ export default { ...@@ -1039,7 +1033,7 @@ export default {
return await Chat.getSdk() return await Chat.getSdk()
.model(currentChat.model_name) .model(currentChat.model_name)
.chat(currentChat.obj_id, orgId()) .chat(currentChat.obj_id, orgId())
.addMember(uids.map((id) => +id)) .addMember(uids.map(id => +id))
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS)); .finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
}, },
async [ChatStore.ACTION_CHAT_REMOVE_MEMBER]( async [ChatStore.ACTION_CHAT_REMOVE_MEMBER](
...@@ -1059,7 +1053,7 @@ export default { ...@@ -1059,7 +1053,7 @@ export default {
return await Chat.getSdk() return await Chat.getSdk()
.model(currentChat.model_name) .model(currentChat.model_name)
.chat(currentChat.obj_id, currentChat.org_id) .chat(currentChat.obj_id, currentChat.org_id)
.removeMember(uids.map((id) => +id)) .removeMember(uids.map(id => +id))
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS)); .finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
}, },
async [ChatStore.ACTION_CHAT_ADD_CS]( async [ChatStore.ACTION_CHAT_ADD_CS](
...@@ -1079,7 +1073,7 @@ export default { ...@@ -1079,7 +1073,7 @@ export default {
return await Chat.getSdk() return await Chat.getSdk()
.model(currentChat.model_name) .model(currentChat.model_name)
.chat(currentChat.obj_id, orgId()) .chat(currentChat.obj_id, orgId())
.addCs(uids.map((id) => Number(id))) .addCs(uids.map(id => Number(id)))
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS)); .finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
}, },
async [ChatStore.ACTION_CHAT_REMOVE_CS]( async [ChatStore.ACTION_CHAT_REMOVE_CS](
...@@ -1099,7 +1093,7 @@ export default { ...@@ -1099,7 +1093,7 @@ export default {
return await Chat.getSdk() return await Chat.getSdk()
.model(currentChat.model_name) .model(currentChat.model_name)
.chat(currentChat.obj_id, orgId()) .chat(currentChat.obj_id, orgId())
.removeCs(uids.map((id) => Number(id))) .removeCs(uids.map(id => Number(id)))
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS)); .finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
}, },
[ChatStore.ACTION_SET_HANDLED]( [ChatStore.ACTION_SET_HANDLED](
...@@ -1111,7 +1105,7 @@ export default { ...@@ -1111,7 +1105,7 @@ export default {
) { ) {
const msgs = state[ChatStore.STATE_CHAT_MSG_HISTORY]; const msgs = state[ChatStore.STATE_CHAT_MSG_HISTORY];
if (msgs) { if (msgs) {
const t = msgs.find((i) => i.id === p.id); const t = msgs.find(i => i.id === p.id);
if (t) { if (t) {
t.handled = p.value; t.handled = p.value;
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]; const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
...@@ -1139,7 +1133,7 @@ export default { ...@@ -1139,7 +1133,7 @@ export default {
return new Promise<{ id: string; name: string }>( return new Promise<{ id: string; name: string }>(
(resolve, reject) => (resolve, reject) =>
ChatUserInfoService.getUserInfo(id) ChatUserInfoService.getUserInfo(id)
.then((d) => { .then(d => {
Vue.set( Vue.set(
state[ChatStore.STATE_CHAT_USERNAME], state[ChatStore.STATE_CHAT_USERNAME],
id, id,
...@@ -1164,7 +1158,7 @@ export default { ...@@ -1164,7 +1158,7 @@ export default {
if (items) { if (items) {
if (option.end && option.end > option.start) { if (option.end && option.end > option.start) {
for (let i = option.start; i <= option.end; i++) { for (let i = option.start; i <= option.end; i++) {
const p = items.find((m) => m.id === i); const p = items.find(m => m.id === i);
if (p) { if (p) {
p.read_count = option.all p.read_count = option.all
? p.total_read_count ? p.total_read_count
...@@ -1174,7 +1168,7 @@ export default { ...@@ -1174,7 +1168,7 @@ export default {
} }
} }
} else { } else {
const p = items.find((i) => i.id === option.start); const p = items.find(i => i.id === option.start);
if (p) { if (p) {
p.read_count = option.all p.read_count = option.all
? p.total_read_count ? p.total_read_count
...@@ -1204,7 +1198,7 @@ export default { ...@@ -1204,7 +1198,7 @@ export default {
}, },
[ChatStore.GETTER_CURRENT_CHAT_PRESENT_MEMBERS](state) { [ChatStore.GETTER_CURRENT_CHAT_PRESENT_MEMBERS](state) {
return (state[ChatStore.STATE_CURRENT_CHAT_MEMBERS] ?? []).filter( return (state[ChatStore.STATE_CURRENT_CHAT_MEMBERS] ?? []).filter(
(member) => !member.is_exited member => !member.is_exited
); );
}, },
[ChatStore.STATE_CURRENT_CHAT_TITLE](state) { [ChatStore.STATE_CURRENT_CHAT_TITLE](state) {
...@@ -1220,7 +1214,7 @@ export default { ...@@ -1220,7 +1214,7 @@ export default {
return singleChat; return singleChat;
} }
const chatList = state[ChatStore.STATE_MY_CHAT_ROOM_LIST]; const chatList = state[ChatStore.STATE_MY_CHAT_ROOM_LIST];
return chatList.find((chat) => chat.chat_id === chatId); return chatList.find(chat => chat.chat_id === chatId);
}, },
}, },
} as Module<ChatStoreState, RootStoreState>; } as Module<ChatStoreState, RootStoreState>;
...@@ -252,9 +252,6 @@ export namespace ChatStore { ...@@ -252,9 +252,6 @@ export namespace ChatStore {
keyword?: string keyword?: string
) => Promise<ChatType[]>; ) => Promise<ChatType[]>;
export const ACTION_FORCE_RELOAD_CHAT_LIST = "重新获取我的会话列表";
export type ACTION_FORCE_RELOAD_CHAT_LIST = () => Promise<ChatType[]>;
export const ACTION_REBUILD_UNREAD_MESSAGE_COUNT = "重新计算未读消息数"; export const ACTION_REBUILD_UNREAD_MESSAGE_COUNT = "重新计算未读消息数";
export type ACTION_REBUILD_UNREAD_MESSAGE_COUNT = () => void; export type ACTION_REBUILD_UNREAD_MESSAGE_COUNT = () => void;
......
...@@ -58,7 +58,12 @@ class Chat { ...@@ -58,7 +58,12 @@ class Chat {
option.message && (this.messageController = option.message); option.message && (this.messageController = option.message);
option.avatar !== undefined && (this.defaultAvatar = option.avatar); option.avatar !== undefined && (this.defaultAvatar = option.avatar);
await this.setupIndexDb(option.orgId()); if(!option.disabledIndexDb){
await this.setupIndexDb(option.orgId()).catch(err => {
// 必须catch error不然小程序不会向后运行
console.error("setupIndexDb Error")
});
}
this.token = async () => option.sdk().global.jwtToken; this.token = async () => option.sdk().global.jwtToken;
tokenManager.save(this.token); tokenManager.save(this.token);
...@@ -151,7 +156,7 @@ class Chat { ...@@ -151,7 +156,7 @@ class Chat {
.finally(() => { .finally(() => {
this.registerXimEvent(); this.registerXimEvent();
if (xim.isConnected()) { if (xim.isConnected()) {
resolve(); setTimeout(resolve, 200);
} else { } else {
reject(new Error(`xim is not connected`)); reject(new Error(`xim is not connected`));
} }
......
...@@ -8,7 +8,7 @@ import { Message, NotifyMessage } from "./models/chat"; ...@@ -8,7 +8,7 @@ import { Message, NotifyMessage } from "./models/chat";
import chat from "./index"; import chat from "./index";
import { STATUS } from "xchat-client/dist/xchat"; import { STATUS } from "xchat-client/dist/xchat";
wampDebug(true); wampDebug(false);
const DefaultMsgPageSize = 20; const DefaultMsgPageSize = 20;
......
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