Commit eb6ee908 by Sixong.Zhu

Merge branch 'master' into pre

parents 4386b8a1 f9d281a8
...@@ -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;
......
...@@ -152,9 +152,13 @@ class ChatCacheDatabaseController { ...@@ -152,9 +152,13 @@ class ChatCacheDatabaseController {
public saveChatList(items: Chat[]) { public saveChatList(items: Chat[]) {
if (this.db) { if (this.db) {
const store = this.buildStore(this.chatListKey); const store = this.buildStore(this.chatListKey);
if (items && items.length) {
for (const item of items) { for (const item of items) {
store.add(item, item.id); store.add(item, item.id);
} }
} else {
store.clear();
}
} }
} }
...@@ -459,47 +463,6 @@ class ChatCacheDatabaseController { ...@@ -459,47 +463,6 @@ class ChatCacheDatabaseController {
}); });
}); });
} }
public syncChats(chats: number[]) {
return new Promise<void>((resolve) => {
if (this.db) {
this.getChatList().then((r) => {
const set = new Set<number>(chats);
let finished = 0;
let removing = [];
for (const item of r) {
if (!set.has(item.id)) {
removing.push(item.id);
}
}
for (const item of removing) {
this.removeChatAndMessages(item).finally(() => {
finished++;
if (finished === removing.length) {
resolve();
}
});
}
!removing.length && resolve();
});
}
});
}
private removeChatAndMessages(chat: number) {
this.setupChatMessageDatabase(chat).finally(() => {
const store = this.buildChatMessageStore(chat);
const r = store.clear();
r.onsuccess = () => {
indexedDB.deleteDatabase(this.buildChatMessageKey(chat));
};
});
return this.removeChatFromList(chat);
}
} }
export const dbController = new ChatCacheDatabaseController(); export const dbController = new ChatCacheDatabaseController();
...@@ -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
.filter(
(i) => (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) => (x.update_time - y.update_time ? 1 : -1));
}; };
export function getLastMessageId(msgs: Message[] | any) { export function getLastMessageId(msgs: Message[] | any) {
...@@ -140,8 +142,6 @@ function clearAction(value: ChatType[]) { ...@@ -140,8 +142,6 @@ function clearAction(value: ChatType[]) {
return value; return value;
} }
let synced = false;
export default { export default {
namespaced: true, namespaced: true,
state: () => ({ state: () => ({
...@@ -436,8 +436,6 @@ export default { ...@@ -436,8 +436,6 @@ export default {
async [ChatStore.ACTION_GET_MY_CHAT_LIST]({ commit, dispatch }) { async [ChatStore.ACTION_GET_MY_CHAT_LIST]({ commit, dispatch }) {
commit(ChatStore.MUTATION_SAVE_MYSELF_ID); commit(ChatStore.MUTATION_SAVE_MYSELF_ID);
await dispatch(ChatStore.ACTION_SYNC_MY_CHAT_LIST);
if (loadingChatList) { if (loadingChatList) {
return new Promise<ChatType[]>((resolve) => return new Promise<ChatType[]>((resolve) =>
cachedLoadingChatListAction.push(resolve) cachedLoadingChatListAction.push(resolve)
...@@ -446,62 +444,6 @@ export default { ...@@ -446,62 +444,6 @@ export default {
loadingChatList = true; loadingChatList = true;
let cache = await dbController.getChatList();
cache.sort((x, y) => (x.last_msg_ts < y.last_msg_ts ? 1 : -1));
for (const item of cache) {
if (item.business_data && !item.detail_name) {
const d = JSON.parse(
item.business_data
) as BaseChatItemBusinessData;
if (d) {
if (d.detail_name) {
item.detail_name = d.detail_name;
}
if (!item.obj_id && d.obj_id) {
item.obj_id = d.obj_id;
}
if (!item.model_name && d.model_name) {
item.model_name = d.model_name;
}
}
}
}
if (cache && cache.length) {
const execute = () =>
new Promise<ChatType[]>((resolve, reject) => {
Chat.onReady(() => {
xim.fetchChatListAfter(0)
.then((r) => {
const list = filterActiveChats(
r.args[0] as RawChatItem[]
);
const items = list.map((i) =>
buildChatItem(i)
);
if (items && items.length) {
cache = dbController.mergeChatList(
cache,
items
);
}
commit(
ChatStore.MUTATION_SAVE_CHAT_LIST,
cache
);
dispatch(
ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT
).finally(resolve);
})
.catch(reject);
});
}).finally(() => (loadingChatList = false));
return await execute().then((d) => clearAction(d));
}
const execute = () => const execute = () =>
new Promise<ChatType[]>((resolve, reject) => { new Promise<ChatType[]>((resolve, reject) => {
Chat.onReady(() => { Chat.onReady(() => {
...@@ -531,47 +473,6 @@ export default { ...@@ -531,47 +473,6 @@ export default {
return await execute().then((d) => clearAction(d)); return await execute().then((d) => clearAction(d));
}, },
async [ChatStore.ACTION_SYNC_MY_CHAT_LIST]() {
if (synced) {
return Promise.resolve();
}
return new Promise<void>((resolve) =>
Chat.onReady(() => {
synced = true;
xim.fetchChatList()
.then((data) => {
dbController
.syncChats(
(data.args[0] as RawChatItem[]).map(
(i) => i.id
)
)
.finally(resolve);
})
.catch(resolve);
})
);
},
async [ChatStore.ACTION_FORCE_RELOAD_CHAT_LIST]({ commit }) {
return new Promise<ChatType[]>((resolve) => {
Chat.onReady(() => {
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 }) { async [ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT]({ state }) {
let items = await dbController.getChatList(); let items = await dbController.getChatList();
let sum = 0; let sum = 0;
......
...@@ -252,12 +252,6 @@ export namespace ChatStore { ...@@ -252,12 +252,6 @@ export namespace ChatStore {
keyword?: string keyword?: string
) => Promise<ChatType[]>; ) => Promise<ChatType[]>;
export const ACTION_SYNC_MY_CHAT_LIST = "同步我的会话列表";
export type ACTION_SYNC_MY_CHAT_LIST = () => void;
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;
......
...@@ -151,7 +151,7 @@ class Chat { ...@@ -151,7 +151,7 @@ class Chat {
.finally(() => { .finally(() => {
this.registerXimEvent(); this.registerXimEvent();
if (xim.isConnected()) { if (xim.isConnected()) {
resolve(); setTimeout(resolve, 0);
} else { } else {
reject(new Error(`xim is not connected`)); reject(new Error(`xim is not connected`));
} }
......
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