Commit 7abbf4ee by Sixong.Zhu

Merge branch 'master' into pre

parents 257f730d 8b24464a
...@@ -191,9 +191,10 @@ ...@@ -191,9 +191,10 @@
this.handleScrollWrapper(); this.handleScrollWrapper();
this.onNewMessage((e) => { this.onNewMessage((e) => {
if (e.type === MessageType.Withdraw) { if (e.type === MessageType.Withdraw) {
this.executeWithDraw(e.ref_id); const ids = e.ref_id ? [e.ref_id] : JSON.parse(e.msg);
this.executeWithDraw(ids);
dbController dbController
.removeMessage(e.chat_id, e.ref_id) .removeMessage(e.chat_id, ids)
.finally(() => this.refresh()); .finally(() => this.refresh());
} }
}); });
...@@ -339,6 +340,23 @@ ...@@ -339,6 +340,23 @@
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.log("没有更多新消息了"); console.log("没有更多新消息了");
} }
const removingIds: number[] = [];
for (const item of data) {
if (item.type === MessageType.Withdraw) {
item.msg && removingIds.push(...JSON.parse(item.msg));
}
}
if (removingIds.length) {
dbController
.removeMessage(this.chatId, removingIds)
.then(() => {
this.refresh();
this.executeWithDraw(removingIds);
});
}
this.$emit("next-page", msgId); this.$emit("next-page", msgId);
this.endLoadingNew(); this.endLoadingNew();
}) })
......
...@@ -486,15 +486,14 @@ ...@@ -486,15 +486,14 @@
} }
private withdraw() { private withdraw() {
if (new Date().valueOf() - this.data.ts * 1000 > twoMinutes) { if (!this.hoverWithdraw()) {
Xim.error("超过两分钟的消息不能撤回"); return Xim.error("不能撤回");
return;
} }
ximInstance.withdraw(this.chatId!, this.data.id).finally(() => { ximInstance.withdraw(this.chatId, this.data.id).finally(() => {
dbController dbController
.removeMessage(this.chatId!, this.data.id) .removeMessage(this.chatId, [this.data.id])
.finally(() => { .finally(() => {
this.executeWithDraw(this.data.id); this.executeWithDraw([this.data.id]);
this.$emit("withdraw", this.data.id); this.$emit("withdraw", this.data.id);
}); });
}); });
...@@ -502,11 +501,11 @@ ...@@ -502,11 +501,11 @@
private hoverWithdraw() { private hoverWithdraw() {
if (!this.isWithdraw || !this.isMyMessage) { if (!this.isWithdraw || !this.isMyMessage) {
return; return false;
} }
this.isWithdraw = this.needReadTip return (this.isWithdraw = this.needReadTip
? new Date().valueOf() - this.data.ts * 1000 < twoMinutes ? new Date().valueOf() - this.data.ts * 1000 < twoMinutes
: new Date().valueOf() - this.data.ts * 1000 < twoHours; : new Date().valueOf() - this.data.ts * 1000 < twoHours);
} }
private openReaderList(e: MouseEvent) { private openReaderList(e: MouseEvent) {
......
...@@ -20,7 +20,9 @@ class ChatCacheDatabaseController { ...@@ -20,7 +20,9 @@ class ChatCacheDatabaseController {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
const checker = () => { const checker = () => {
if (!this.setuping) { if (!this.setuping) {
this.setupError ? reject(new Error(`IM index database setup failed`)) : resolve(); this.setupError
? reject(new Error(`IM index database setup failed`))
: resolve();
} else { } else {
setTimeout(() => checker(), 200); setTimeout(() => checker(), 200);
} }
...@@ -30,16 +32,17 @@ class ChatCacheDatabaseController { ...@@ -30,16 +32,17 @@ class ChatCacheDatabaseController {
} }
public setup(uid: string) { public setup(uid: string) {
if (this.db) {
return Promise.resolve();
}
if (this.setuping) { if (this.setuping) {
return this.waitSetupCompleted(); return this.waitSetupCompleted();
} }
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
if (uid && indexedDB) { if (uid && indexedDB) {
this.setuping = true; this.setuping = true;
const r = indexedDB.open( const key = "u-" + (this.uid = uid);
"u-" + (this.uid = uid), const r = indexedDB.open(key, this.listVersion);
this.listVersion
);
const setupDb = () => { const setupDb = () => {
if (this.setuping) { if (this.setuping) {
if (this.db) { if (this.db) {
...@@ -131,8 +134,9 @@ class ChatCacheDatabaseController { ...@@ -131,8 +134,9 @@ class ChatCacheDatabaseController {
} }
private buildTransaction(key: string) { private buildTransaction(key: string) {
try { return this.db.transaction(key, "readwrite"); } try {
catch{ return this.db.transaction(key, "readwrite");
} catch {
window.location.reload(); window.location.reload();
throw new Error(`transition failed`); throw new Error(`transition failed`);
} }
...@@ -329,7 +333,7 @@ class ChatCacheDatabaseController { ...@@ -329,7 +333,7 @@ class ChatCacheDatabaseController {
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);
}); });
...@@ -379,13 +383,22 @@ class ChatCacheDatabaseController { ...@@ -379,13 +383,22 @@ class ChatCacheDatabaseController {
}); });
} }
public removeMessage(chat: number, msg: number) { public removeMessage(chat: number, msgs: number[]) {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
if (this.db) { if (this.db) {
const store = this.buildChatMessageStore(chat); const store = this.buildChatMessageStore(chat);
const d = store.delete(msg); let count = 0;
d.onsuccess = () => setTimeout(() => resolve(), 100); const action = () => {
d.onerror = () => reject(); count++;
if (count === msgs.length) {
resolve();
}
};
for (const item of msgs) {
const d = store.delete(item);
d.onsuccess = () => action();
d.onerror = () => action();
}
} else { } else {
resolve(); resolve();
} }
...@@ -396,7 +409,10 @@ class ChatCacheDatabaseController { ...@@ -396,7 +409,10 @@ class ChatCacheDatabaseController {
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, t.unread_msg_count); item.unread_msg_count = Math.max(
item.unread_msg_count,
t.unread_msg_count
);
const index = source1.indexOf(t); const index = source1.indexOf(t);
source1[index] = item; source1[index] = item;
} else { } else {
......
import type { UniplatSdk } from "uniplat-sdk"; import type { UniplatSdk } from "uniplat-sdk";
export * from "./order"; export * from "./order";
export * from "./order-product" export * from "./order-product";
export const enum ChatRole { export const enum ChatRole {
Default = 25, Default = 25,
...@@ -115,12 +115,12 @@ export const enum MessageType { ...@@ -115,12 +115,12 @@ export const enum MessageType {
Action = "action", Action = "action",
Notify = "notify", Notify = "notify",
MpNavigate = "mp-navigate", MpNavigate = "mp-navigate",
PayV1 = 'gpay', PayV1 = "gpay",
Pay = "gpay2", Pay = "gpay2",
PayResult = "gresult", PayResult = "gresult",
RefundV1 = 'grefund', RefundV1 = "grefund",
Refund = "grefund2", Refund = "grefund2",
Card = 'card' Card = "card",
} }
export const enum MessageHandled { export const enum MessageHandled {
...@@ -195,6 +195,7 @@ export interface BaseChatItem extends BaseChatItemBusinessData { ...@@ -195,6 +195,7 @@ export interface BaseChatItem extends BaseChatItemBusinessData {
create_time: number; create_time: number;
update_time: number; update_time: number;
last_msg_ts: number; last_msg_ts: number;
last_msg_sender: string;
members_updated: number; members_updated: number;
user_updated: number; user_updated: number;
} }
......
...@@ -94,6 +94,10 @@ function buildChatItem(chat: RawChatItem) { ...@@ -94,6 +94,10 @@ function buildChatItem(chat: RawChatItem) {
const b = JSON.parse(chat.business_data) as BaseChatItemBusinessData; const b = JSON.parse(chat.business_data) as BaseChatItemBusinessData;
b.detail_name && (chat.detail_name = b.detail_name); b.detail_name && (chat.detail_name = b.detail_name);
} }
// 系统发的自动消息,重新校准未读消息数为0
if (!+chat.last_msg_sender && chat.msg_id === 1) {
chat.unread_msg_count = 0;
}
return { ...chat, chat_id: chat.id } as ChatType; return { ...chat, chat_id: chat.id } as ChatType;
} }
...@@ -148,7 +152,7 @@ export default { ...@@ -148,7 +152,7 @@ export default {
[ChatStore.STATE_MY_CHAT_ROOM_LIST]: [], [ChatStore.STATE_MY_CHAT_ROOM_LIST]: [],
[ChatStore.STATE_SINGLE_CHAT]: null, [ChatStore.STATE_SINGLE_CHAT]: null,
[ChatStore.STATE_CHAT_CURRENT_CHAT_VERSION]: null, [ChatStore.STATE_CHAT_CURRENT_CHAT_VERSION]: null,
[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]: null, [ChatStore.STATE_CHAT_CURRENT_CHAT_ID]: 0,
[ChatStore.STATE_CHAT_MY_ID]: null, [ChatStore.STATE_CHAT_MY_ID]: null,
[ChatStore.STATE_CHAT_MY_UID]: null, [ChatStore.STATE_CHAT_MY_UID]: null,
[ChatStore.STATE_CHAT_SOURCE]: ServiceType.Frontend, [ChatStore.STATE_CHAT_SOURCE]: ServiceType.Frontend,
...@@ -183,7 +187,7 @@ export default { ...@@ -183,7 +187,7 @@ export default {
state[ChatStore.STATE_CHAT_MSG_HISTORY] = null; state[ChatStore.STATE_CHAT_MSG_HISTORY] = null;
}, },
[ChatStore.MUTATION_CLEAR_CURRENT_CHAT_ID](state) { [ChatStore.MUTATION_CLEAR_CURRENT_CHAT_ID](state) {
state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID] = null; state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID] = 0;
}, },
[ChatStore.MUTATION_SAVE_CURRENT_CHAT_ID]( [ChatStore.MUTATION_SAVE_CURRENT_CHAT_ID](
state, state,
...@@ -259,10 +263,10 @@ export default { ...@@ -259,10 +263,10 @@ export default {
data: ChatStore.STATE_CHAT_MSG_HISTORY data: ChatStore.STATE_CHAT_MSG_HISTORY
) { ) {
const old = state[ChatStore.STATE_CHAT_MSG_HISTORY] || []; const old = state[ChatStore.STATE_CHAT_MSG_HISTORY] || [];
const chatid = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]; const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (chatid == null) return; if (!chatId) return;
state[ChatStore.STATE_CHAT_MSG_HISTORY] = Object.freeze( state[ChatStore.STATE_CHAT_MSG_HISTORY] = Object.freeze(
filterMessages([...(data || []), ...old], chatid) filterMessages([...(data || []), ...old], chatId)
); );
}, },
[ChatStore.MUTATION_SAVE_CURRENT_CHAT_MEMBERS]( [ChatStore.MUTATION_SAVE_CURRENT_CHAT_MEMBERS](
...@@ -369,7 +373,7 @@ export default { ...@@ -369,7 +373,7 @@ export default {
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 == null) return; if (!chatId) return;
if (payload.chat_id !== chatId) return; if (payload.chat_id !== chatId) return;
const arr = state[ChatStore.STATE_CURRENT_CHAT_INPUTING]; const arr = state[ChatStore.STATE_CURRENT_CHAT_INPUTING];
const eid = payload.eid; const eid = payload.eid;
...@@ -409,17 +413,17 @@ export default { ...@@ -409,17 +413,17 @@ export default {
) => { ) => {
Vue.set(state[ChatStore.STATE_CHAT_USERNAME], param.id, param.name); Vue.set(state[ChatStore.STATE_CHAT_USERNAME], param.id, param.name);
}, },
[ChatStore.MUTATION_WITHDRAW]: (state, id: number) => { [ChatStore.MUTATION_WITHDRAW]: (state, ids: number[]) => {
const old = state[ChatStore.STATE_CHAT_MSG_HISTORY] || []; const old = state[ChatStore.STATE_CHAT_MSG_HISTORY] || [];
const chatid = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]; const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (chatid == null) return; if (!chatId) return;
state[ChatStore.STATE_CHAT_MSG_HISTORY] = old.filter( state[ChatStore.STATE_CHAT_MSG_HISTORY] = old.filter(
(i) => i.id !== id (i) => !ids.includes(i.id)
); );
}, },
}, },
actions: { actions: {
async [ChatStore.ACTION_GET_MY_CHAT_LIST]({ commit, state }) { async [ChatStore.ACTION_GET_MY_CHAT_LIST]({ commit, dispatch }) {
commit(ChatStore.MUTATION_SAVE_MYSELF_ID); commit(ChatStore.MUTATION_SAVE_MYSELF_ID);
if (loadingChatList) { if (loadingChatList) {
...@@ -453,15 +457,6 @@ export default { ...@@ -453,15 +457,6 @@ export default {
} }
} }
const buildUnreadMessage = (items: ChatType[]) => {
let sum = 0;
items.forEach((i) => (sum += i.unread_msg_count));
state[ChatStore.STATE_CURRENT_UNREAD_MESSAGE_COUNT] = sum;
return items.sort((x, y) =>
x.last_msg_ts < y.last_msg_ts ? 1 : -1
);
};
if (cache && cache.length) { if (cache && cache.length) {
commit(ChatStore.MUTATION_SAVE_CHAT_LIST, cache); commit(ChatStore.MUTATION_SAVE_CHAT_LIST, cache);
const ts = cache const ts = cache
...@@ -471,19 +466,23 @@ export default { ...@@ -471,19 +466,23 @@ export default {
const execute = () => const execute = () =>
new Promise<ChatType[]>((resolve, reject) => { new Promise<ChatType[]>((resolve, reject) => {
Chat.onReady(() => { Chat.onReady(() => {
xim.fetchChatListAfter(last)!.then((r) => { xim.fetchChatListAfter(last)!
.then((r) => {
const list = filterActiveChats( const list = filterActiveChats(
r.args[0] as RawChatItem[] r.args[0] as RawChatItem[]
); );
const items = list.map((i) => buildChatItem(i)); const items = list.map((i) =>
buildChatItem(i)
);
if (items && items.length) { if (items && items.length) {
cache = dbController.mergeChatList( cache = dbController.mergeChatList(
cache, cache,
items items
); );
} }
resolve(buildUnreadMessage(cache)); dispatch(ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT).finally(resolve);
}).catch(reject); })
.catch(reject);
}); });
}).finally(() => (loadingChatList = false)); }).finally(() => (loadingChatList = false));
...@@ -493,7 +492,8 @@ export default { ...@@ -493,7 +492,8 @@ export default {
const execute = () => const execute = () =>
new Promise<ChatType[]>((resolve, reject) => { new Promise<ChatType[]>((resolve, reject) => {
Chat.onReady(() => { Chat.onReady(() => {
xim.fetchChatList().then((data) => { xim.fetchChatList()
.then((data) => {
if (!data) { if (!data) {
return resolve([]); return resolve([]);
} }
...@@ -504,9 +504,13 @@ export default { ...@@ -504,9 +504,13 @@ export default {
buildChatItem(chat) buildChatItem(chat)
); );
dbController.saveChatList(items); dbController.saveChatList(items);
commit(ChatStore.MUTATION_SAVE_CHAT_LIST, items); commit(
resolve(buildUnreadMessage(items)); ChatStore.MUTATION_SAVE_CHAT_LIST,
}).catch(reject); items
);
dispatch(ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT).finally(resolve);
})
.catch(reject);
}); });
}).finally(() => (loadingChatList = false)); }).finally(() => (loadingChatList = false));
...@@ -539,9 +543,12 @@ export default { ...@@ -539,9 +543,12 @@ export default {
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 }, { dispatch, state },
p: { chat: number; unread: number } p: { chat: number; unread: number }
) { ) {
const list = state[ChatStore.STATE_MY_CHAT_ROOM_LIST] as ChatType[];
const t = list.find(i => i.id === p.chat)
t && (t.unread_msg_count = p.unread)
return dbController return dbController
.updateChat4UnreadCount(p.chat, p.unread) .updateChat4UnreadCount(p.chat, p.unread)
.then(() => .then(() =>
...@@ -550,29 +557,25 @@ export default { ...@@ -550,29 +557,25 @@ export default {
}, },
async [ChatStore.ACTION_GET_CHAT_MESSAGES]({ state, commit, getters }) { async [ChatStore.ACTION_GET_CHAT_MESSAGES]({ state, commit, getters }) {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]; const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
const chat = getters[ const chat = getters[ChatStore.GETTER_CURRENT_CURRENT_CHAT] as ChatType;
ChatStore.GETTER_CURRENT_CURRENT_CHAT
] as ChatType;
const isMember = state[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER]; const isMember = state[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER];
if (chatId == null) return; if (!chatId) return;
let data: Message[] = []; let data: Message[] = [];
const getMessages = async () => { const getMessages = async () =>
const o = { await xim.queryLastPageMsg(chatType, chatId, 20, {
model: chat.model_name, model: chat.model_name,
obj: chat.obj_id, obj: chat.obj_id,
isMember, isMember,
}; });
data = await xim.queryLastPageMsg(chatType, chatId, 20, o);
};
if (isMember) { if (isMember) {
const cache = await dbController.getChatMessages(chatId); const cache = await dbController.getChatMessages(chatId);
if (cache && cache.length) { if (cache && cache.length) {
data = cache; data = cache;
} else { } else {
await getMessages(); data = await getMessages();
} }
} else { } else {
await getMessages(); data = await getMessages();
} }
try { try {
...@@ -591,7 +594,7 @@ export default { ...@@ -591,7 +594,7 @@ export default {
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 == null) return; if (!chatId) return;
const chat = getters[ const chat = getters[
ChatStore.GETTER_CURRENT_CURRENT_CHAT ChatStore.GETTER_CURRENT_CURRENT_CHAT
] as ChatType; ] as ChatType;
...@@ -611,12 +614,12 @@ export default { ...@@ -611,12 +614,12 @@ export default {
dbController.appendMessages(chatId, data); dbController.appendMessages(chatId, data);
return data; return data;
}, },
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 == null) return; if (!chatId) return;
const chat = getters[ const chat = getters[
ChatStore.GETTER_CURRENT_CURRENT_CHAT ChatStore.GETTER_CURRENT_CURRENT_CHAT
] as ChatType; ] as ChatType;
...@@ -636,7 +639,7 @@ export default { ...@@ -636,7 +639,7 @@ export default {
dbController.appendMessages(chatId, data); dbController.appendMessages(chatId, data);
return data; return data;
}, },
async [ChatStore.ACTION_SEND_MESSAGE]( async[ChatStore.ACTION_SEND_MESSAGE](
{ state, dispatch, getters, commit }, { state, dispatch, getters, commit },
params: Parameters<ChatStore.ACTION_SEND_MESSAGE>[0] params: Parameters<ChatStore.ACTION_SEND_MESSAGE>[0]
) { ) {
...@@ -664,7 +667,7 @@ export default { ...@@ -664,7 +667,7 @@ export default {
return Promise.reject(error); return Promise.reject(error);
} }
}, },
async [ChatStore.ACTION_GET_FRESH_MESSAGE]({ async[ChatStore.ACTION_GET_FRESH_MESSAGE]({
state, state,
dispatch, dispatch,
commit, commit,
...@@ -684,7 +687,7 @@ export default { ...@@ -684,7 +687,7 @@ export default {
await preCacheImgs(newMsgsArr); await preCacheImgs(newMsgsArr);
commit(ChatStore.MUTATION_SCROLL_TO_BOTTOM); commit(ChatStore.MUTATION_SCROLL_TO_BOTTOM);
}, },
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]
) { ) {
...@@ -701,7 +704,7 @@ export default { ...@@ -701,7 +704,7 @@ export default {
); );
return { chatId, catalog }; return { chatId, catalog };
}, },
async [ChatStore.ACTION_CREATE_NEW_CHAT_BY_CLIENT]( async[ChatStore.ACTION_CREATE_NEW_CHAT_BY_CLIENT](
{ commit, dispatch }, { commit, dispatch },
params: Parameters<ChatStore.ACTION_CREATE_NEW_CHAT_BY_CLIENT>[0] params: Parameters<ChatStore.ACTION_CREATE_NEW_CHAT_BY_CLIENT>[0]
) { ) {
...@@ -719,7 +722,7 @@ export default { ...@@ -719,7 +722,7 @@ export default {
dispatch(ChatStore.ACTION_GET_MY_CHAT_LIST); dispatch(ChatStore.ACTION_GET_MY_CHAT_LIST);
return chatId; return chatId;
}, },
async [ChatStore.ACTION_REGISTER_EVENT]({ async[ChatStore.ACTION_REGISTER_EVENT]({
dispatch, dispatch,
commit, commit,
state, state,
...@@ -729,7 +732,7 @@ export default { ...@@ -729,7 +732,7 @@ export default {
const onNewMsg = (e: Message) => { const onNewMsg = (e: Message) => {
const thenAction = () => { const thenAction = () => {
if (e.type === MessageType.Withdraw) { if (e.type === MessageType.Withdraw) {
commit(ChatStore.MUTATION_WITHDRAW, +e.msg); commit(ChatStore.MUTATION_WITHDRAW, e.msg.startsWith('[') ? JSON.parse(e.msg) : [+e.msg]);
} }
const scroll = () => const scroll = () =>
state[ChatStore.STATE_FUNC_ON_NEW_MSG](e); state[ChatStore.STATE_FUNC_ON_NEW_MSG](e);
...@@ -743,7 +746,7 @@ export default { ...@@ -743,7 +746,7 @@ export default {
}; };
if (e.type === MessageType.Withdraw) { if (e.type === MessageType.Withdraw) {
dbController dbController
.removeMessage(e.chat_id, +e.msg) .removeMessage(e.chat_id, e.msg.startsWith('[') ? JSON.parse(e.msg) : [+e.msg])
.finally(() => thenAction()); .finally(() => thenAction());
} else { } else {
thenAction(); thenAction();
...@@ -810,7 +813,7 @@ export default { ...@@ -810,7 +813,7 @@ export default {
xim.on("chat_notify", "read", onMsgRead); xim.on("chat_notify", "read", onMsgRead);
xim.on("chat_notify", "user.input", onInputing); xim.on("chat_notify", "user.input", onInputing);
}, },
async [ChatStore.ACTION_SAVE_CURRENT_CHAT_ID_VERSION]( async[ChatStore.ACTION_SAVE_CURRENT_CHAT_ID_VERSION](
{ state, commit, dispatch }, { state, commit, dispatch },
chatId: ChatStore.STATE_CHAT_CURRENT_CHAT_ID chatId: ChatStore.STATE_CHAT_CURRENT_CHAT_ID
) { ) {
...@@ -876,7 +879,7 @@ export default { ...@@ -876,7 +879,7 @@ export default {
commit(ChatStore.MUTATION_SCROLL_TO_BOTTOM); commit(ChatStore.MUTATION_SCROLL_TO_BOTTOM);
(<any>state)[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_ERROR] = null; (<any>state)[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_ERROR] = null;
}, },
async [ChatStore.ACTION_CLEAR_CURRENT_CHAT_DATA]({ commit, state }) { async[ChatStore.ACTION_CLEAR_CURRENT_CHAT_DATA]({ commit, state }) {
commit(ChatStore.MUTATION_CLEAR_CURRENT_CHAT_ID); commit(ChatStore.MUTATION_CLEAR_CURRENT_CHAT_ID);
commit(ChatStore.MUTATION_CLEAR_MYSELF_ID); commit(ChatStore.MUTATION_CLEAR_MYSELF_ID);
commit(ChatStore.MUTATION_CLEAR_CHAT_MSG_HISTORY); commit(ChatStore.MUTATION_CLEAR_CHAT_MSG_HISTORY);
...@@ -884,7 +887,7 @@ export default { ...@@ -884,7 +887,7 @@ export default {
commit(ChatStore.MUTATION_CLEAR_CURRENT_CHAT_MEMBERS); commit(ChatStore.MUTATION_CLEAR_CURRENT_CHAT_MEMBERS);
(<any>state)[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_ERROR] = null; (<any>state)[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_ERROR] = null;
}, },
async [ChatStore.ACTION_GET_CHAT_MEMBERS]({ commit, state }) { async[ChatStore.ACTION_GET_CHAT_MEMBERS]({ commit, state }) {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID]; const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (!chatId) return; if (!chatId) return;
const getChatMembersResult = await xim.fetchChatMembers(chatId); const getChatMembersResult = await xim.fetchChatMembers(chatId);
...@@ -927,7 +930,7 @@ export default { ...@@ -927,7 +930,7 @@ export default {
}) })
); );
}, },
async [ChatStore.ACTION_TERINATE_CHAT]({ state, dispatch }) { async[ChatStore.ACTION_TERINATE_CHAT]({ state, dispatch }) {
const v = state[ChatStore.STATE_CHAT_CURRENT_CHAT_VERSION]; const v = state[ChatStore.STATE_CHAT_CURRENT_CHAT_VERSION];
if (v == null) return; if (v == null) return;
const id = Number( const id = Number(
...@@ -955,7 +958,7 @@ export default { ...@@ -955,7 +958,7 @@ export default {
firstChat.chat_id firstChat.chat_id
); );
}, },
async [ChatStore.ACTION_CHAT_START_RECEPTION]({ getters, dispatch }) { async[ChatStore.ACTION_CHAT_START_RECEPTION]({ getters, dispatch }) {
const currentChat = getters[ const currentChat = getters[
ChatStore.GETTER_CURRENT_CURRENT_CHAT ChatStore.GETTER_CURRENT_CURRENT_CHAT
] as ChatType; ] as ChatType;
...@@ -979,7 +982,7 @@ export default { ...@@ -979,7 +982,7 @@ export default {
); );
}); });
}, },
async [ChatStore.ACTION_CHAT_FINISH_RECEPTION]({ getters, dispatch }) { async[ChatStore.ACTION_CHAT_FINISH_RECEPTION]({ getters, dispatch }) {
const currentChat = getters[ const currentChat = getters[
ChatStore.GETTER_CURRENT_CURRENT_CHAT ChatStore.GETTER_CURRENT_CURRENT_CHAT
] as ChatType; ] as ChatType;
...@@ -996,7 +999,7 @@ export default { ...@@ -996,7 +999,7 @@ export default {
.finishChat() .finishChat()
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS)); .finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
}, },
async [ChatStore.ACTION_CHAT_USER_EXIT]({ getters, dispatch }) { async[ChatStore.ACTION_CHAT_USER_EXIT]({ getters, dispatch }) {
const currentChat = getters[ const currentChat = getters[
ChatStore.GETTER_CURRENT_CURRENT_CHAT ChatStore.GETTER_CURRENT_CURRENT_CHAT
] as ChatType; ] as ChatType;
...@@ -1014,7 +1017,7 @@ export default { ...@@ -1014,7 +1017,7 @@ export default {
.userExitChat() .userExitChat()
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS)); .finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
}, },
async [ChatStore.ACTION_CHAT_CS_EXIT]({ getters, dispatch }) { async[ChatStore.ACTION_CHAT_CS_EXIT]({ getters, dispatch }) {
const currentChat = getters[ const currentChat = getters[
ChatStore.GETTER_CURRENT_CURRENT_CHAT ChatStore.GETTER_CURRENT_CURRENT_CHAT
] as ChatType; ] as ChatType;
...@@ -1032,7 +1035,7 @@ export default { ...@@ -1032,7 +1035,7 @@ export default {
.csExitChat() .csExitChat()
.finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS)); .finally(() => dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS));
}, },
async [ChatStore.ACTION_CHAT_ADD_MEMBERS]( async[ChatStore.ACTION_CHAT_ADD_MEMBERS](
{ getters, dispatch }, { getters, dispatch },
uids: Parameters<ChatStore.ACTION_CHAT_ADD_MEMBERS>[0] uids: Parameters<ChatStore.ACTION_CHAT_ADD_MEMBERS>[0]
) { ) {
...@@ -1052,7 +1055,7 @@ export default { ...@@ -1052,7 +1055,7 @@ export default {
.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](
{ getters, dispatch }, { getters, dispatch },
uids: Parameters<ChatStore.ACTION_CHAT_REMOVE_MEMBER>[0] uids: Parameters<ChatStore.ACTION_CHAT_REMOVE_MEMBER>[0]
) { ) {
...@@ -1072,7 +1075,7 @@ export default { ...@@ -1072,7 +1075,7 @@ export default {
.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](
{ getters, dispatch }, { getters, dispatch },
uids: Parameters<ChatStore.ACTION_CHAT_ADD_CS>[0] uids: Parameters<ChatStore.ACTION_CHAT_ADD_CS>[0]
) { ) {
...@@ -1092,7 +1095,7 @@ export default { ...@@ -1092,7 +1095,7 @@ export default {
.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](
{ getters, dispatch }, { getters, dispatch },
uids: Parameters<ChatStore.ACTION_CHAT_REMOVE_CS>[0] uids: Parameters<ChatStore.ACTION_CHAT_REMOVE_CS>[0]
) { ) {
......
...@@ -31,7 +31,7 @@ export namespace ChatStore { ...@@ -31,7 +31,7 @@ export namespace ChatStore {
export type STATE_CHAT_SENDING_MESSAGE = dto.Message; export type STATE_CHAT_SENDING_MESSAGE = dto.Message;
export const STATE_CHAT_CURRENT_CHAT_ID = "当前chat-id"; export const STATE_CHAT_CURRENT_CHAT_ID = "当前chat-id";
export type STATE_CHAT_CURRENT_CHAT_ID = number | null; export type STATE_CHAT_CURRENT_CHAT_ID = number;
export const STATE_CHAT_CURRENT_CHAT_VERSION = "当前chat的Uniplat version"; export const STATE_CHAT_CURRENT_CHAT_VERSION = "当前chat的Uniplat version";
export type STATE_CHAT_CURRENT_CHAT_VERSION = number | null; export type STATE_CHAT_CURRENT_CHAT_VERSION = number | null;
export const STATE_CHAT_CURRENT_IS_CHAT_MEMBER = "是否是当前chat的成员"; export const STATE_CHAT_CURRENT_IS_CHAT_MEMBER = "是否是当前chat的成员";
...@@ -169,7 +169,7 @@ export namespace ChatStore { ...@@ -169,7 +169,7 @@ export namespace ChatStore {
export type MUTATION_CLEAR_CURRENT_CHAT_UNIPLAT_ID = () => void; export type MUTATION_CLEAR_CURRENT_CHAT_UNIPLAT_ID = () => void;
export const MUTATION_WITHDRAW = "撤回"; export const MUTATION_WITHDRAW = "撤回";
export type MUTATION_WITHDRAW = (id: number) => void; export type MUTATION_WITHDRAW = (ids: number[]) => void;
export const MUTATION_SAVE_MYSELF_ID = export const MUTATION_SAVE_MYSELF_ID =
"保存我的id:聊天窗口显示在右边那个人的id"; "保存我的id:聊天窗口显示在右边那个人的id";
......
...@@ -200,7 +200,9 @@ export class Xim { ...@@ -200,7 +200,9 @@ export class Xim {
} }
private setMessagesRead(chatId: number, msg: Message[]) { private setMessagesRead(chatId: number, msg: Message[]) {
if (msg.length === 0) return; if (!msg.length) {
return this.setRead(chatId, 1, 1);
}
return this.setRead(chatId, msg[0].id, msg[msg.length - 1].id); return this.setRead(chatId, msg[0].id, msg[msg.length - 1].id);
} }
......
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