Commit eb6ee908 by Sixong.Zhu

Merge branch 'master' into pre

parents 4386b8a1 f9d281a8
......@@ -56,15 +56,9 @@
@chatStore.State(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)
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)
private readonly isChatMember!: ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER;
......@@ -82,12 +76,6 @@
@Provide() showReadSummary = true;
@Watch("currentChatUniplatId")
private whenCurrentChatIdChanged(newValue: string, oldValue: string) {
if (Number(oldValue) === Number(newValue)) return;
this.clearChatMembers();
}
private get getCurrentInputingPeople() {
return this.currentInputPeople
.map(() => "" /* this.userInfo[k].name */)
......@@ -174,6 +162,7 @@
),
300
);
this.$emit("send");
}
}
</script>
......@@ -184,7 +173,7 @@
width: 46px;
height: 20px;
line-height: 20px;
background: #22bd7a;
background-color: #22bd7a;
font-size: 13px;
border-radius: 2px;
color: #ffffff;
......
......@@ -152,9 +152,13 @@ class ChatCacheDatabaseController {
public saveChatList(items: Chat[]) {
if (this.db) {
const store = this.buildStore(this.chatListKey);
if (items && items.length) {
for (const item of items) {
store.add(item, item.id);
}
} else {
store.clear();
}
}
}
......@@ -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();
......@@ -108,14 +108,16 @@ const chatType = "group";
const allowedChatTypes = [chatType, "notify"];
export const filterActiveChats = (items: RawChatItem[]) => {
return items.filter(
return items
.filter(
(i) =>
!i.is_finish &&
!i.is_exited &&
!i.is_remove &&
!i.is_deleted &&
allowedChatTypes.includes(i.type)
);
)
.sort((x, y) => (x.update_time - y.update_time ? 1 : -1));
};
export function getLastMessageId(msgs: Message[] | any) {
......@@ -140,8 +142,6 @@ function clearAction(value: ChatType[]) {
return value;
}
let synced = false;
export default {
namespaced: true,
state: () => ({
......@@ -436,8 +436,6 @@ export default {
async [ChatStore.ACTION_GET_MY_CHAT_LIST]({ commit, dispatch }) {
commit(ChatStore.MUTATION_SAVE_MYSELF_ID);
await dispatch(ChatStore.ACTION_SYNC_MY_CHAT_LIST);
if (loadingChatList) {
return new Promise<ChatType[]>((resolve) =>
cachedLoadingChatListAction.push(resolve)
......@@ -446,62 +444,6 @@ export default {
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 = () =>
new Promise<ChatType[]>((resolve, reject) => {
Chat.onReady(() => {
......@@ -531,47 +473,6 @@ export default {
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 }) {
let items = await dbController.getChatList();
let sum = 0;
......
......@@ -252,12 +252,6 @@ export namespace ChatStore {
keyword?: string
) => 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 type ACTION_REBUILD_UNREAD_MESSAGE_COUNT = () => void;
......
......@@ -151,7 +151,7 @@ class Chat {
.finally(() => {
this.registerXimEvent();
if (xim.isConnected()) {
resolve();
setTimeout(resolve, 0);
} else {
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