Commit 1ee879ff by Sixong.Zhu

update

parent 8b24464a
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
class="chat-input flex-none h-100" class="chat-input flex-none h-100"
v-if="hasInput" v-if="hasInput"
> >
<message-input @error="onError" /> <message-input @error="onError" @sent="onMessageSent" />
</div> </div>
</div> </div>
</div> </div>
...@@ -70,6 +70,11 @@ ...@@ -70,6 +70,11 @@
@chatStore.State(ChatStore.STATE_CHAT_CURRENT_IS_CHAT_ERROR) @chatStore.State(ChatStore.STATE_CHAT_CURRENT_IS_CHAT_ERROR)
private readonly chatError!: ChatStore.STATE_CHAT_CURRENT_IS_CHAT_ERROR; private readonly chatError!: ChatStore.STATE_CHAT_CURRENT_IS_CHAT_ERROR;
@chatStore.Getter(ChatStore.GETTER_CURRENT_CURRENT_CHAT)
private readonly currentChat!: ChatStore.GETTER_CURRENT_CURRENT_CHAT;
private setting = 0;
private get hasInput() { private get hasInput() {
return this.isChatMember && this.chatError !== this.chatId; return this.isChatMember && this.chatError !== this.chatId;
} }
...@@ -131,6 +136,21 @@ ...@@ -131,6 +136,21 @@
private openPayMessage(id: number) { private openPayMessage(id: number) {
this.$emit("open-pay-message", id); this.$emit("open-pay-message", id);
} }
private onMessageSent() {
if (this.setting) {
clearTimeout(this.setting);
}
this.setting = setTimeout(
() =>
this.currentChat &&
Chat.setRead(
this.currentChat.model_name,
this.currentChat.obj_id
),
300
);
}
} }
</script> </script>
......
...@@ -15,7 +15,7 @@ import { getChatModelInfo } from "../utils/chat-info"; ...@@ -15,7 +15,7 @@ import { getChatModelInfo } from "../utils/chat-info";
import { getUserInfo } from "../utils/user-info"; import { getUserInfo } from "../utils/user-info";
import Chat from "../xim"; import Chat from "../xim";
import { Chat as ChatType, Message } from "../xim/models/chat"; import { Chat as ChatType, Message } from "../xim/models/chat";
import xim, { ChatNotifyListener } from "../xim/xim"; import xim, { ChatNotifyListener, Xim } from "../xim/xim";
import { decodeJwt } from "uniplat-sdk"; import { decodeJwt } from "uniplat-sdk";
import { ChatStatus, ChatStore, ChatStoreState } from "./model"; import { ChatStatus, ChatStore, ChatStoreState } from "./model";
...@@ -32,7 +32,7 @@ function uniqueMessages( ...@@ -32,7 +32,7 @@ function uniqueMessages(
messages: NonNullable<ChatStore.STATE_CHAT_MSG_HISTORY> messages: NonNullable<ChatStore.STATE_CHAT_MSG_HISTORY>
) { ) {
const arr = [...messages]; const arr = [...messages];
return unique(arr, function(item, all) { return unique(arr, function (item, all) {
return all.findIndex((k) => k.id === item.id); return all.findIndex((k) => k.id === item.id);
}); });
} }
...@@ -366,7 +366,7 @@ export default { ...@@ -366,7 +366,7 @@ 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,
...@@ -480,7 +480,9 @@ export default { ...@@ -480,7 +480,9 @@ export default {
items items
); );
} }
dispatch(ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT).finally(resolve); dispatch(
ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT
).finally(resolve);
}) })
.catch(reject); .catch(reject);
}); });
...@@ -508,7 +510,9 @@ export default { ...@@ -508,7 +510,9 @@ export default {
ChatStore.MUTATION_SAVE_CHAT_LIST, ChatStore.MUTATION_SAVE_CHAT_LIST,
items items
); );
dispatch(ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT).finally(resolve); dispatch(
ChatStore.ACTION_REBUILD_UNREAD_MESSAGE_COUNT
).finally(resolve);
}) })
.catch(reject); .catch(reject);
}); });
...@@ -547,8 +551,8 @@ export default { ...@@ -547,8 +551,8 @@ export default {
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)
.then(() => .then(() =>
...@@ -557,7 +561,9 @@ export default { ...@@ -557,7 +561,9 @@ 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[ChatStore.GETTER_CURRENT_CURRENT_CHAT] as ChatType; const chat = getters[
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) return; if (!chatId) return;
let data: Message[] = []; let data: Message[] = [];
...@@ -614,7 +620,7 @@ export default { ...@@ -614,7 +620,7 @@ 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]
) { ) {
...@@ -639,7 +645,7 @@ export default { ...@@ -639,7 +645,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]
) { ) {
...@@ -667,7 +673,7 @@ export default { ...@@ -667,7 +673,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,
...@@ -687,7 +693,7 @@ export default { ...@@ -687,7 +693,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]
) { ) {
...@@ -704,7 +710,7 @@ export default { ...@@ -704,7 +710,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]
) { ) {
...@@ -722,7 +728,7 @@ export default { ...@@ -722,7 +728,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,
...@@ -732,7 +738,10 @@ export default { ...@@ -732,7 +738,10 @@ 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.startsWith('[') ? JSON.parse(e.msg) : [+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);
...@@ -746,7 +755,10 @@ export default { ...@@ -746,7 +755,10 @@ export default {
}; };
if (e.type === MessageType.Withdraw) { if (e.type === MessageType.Withdraw) {
dbController dbController
.removeMessage(e.chat_id, e.msg.startsWith('[') ? JSON.parse(e.msg) : [+e.msg]) .removeMessage(
e.chat_id,
e.msg.startsWith("[") ? JSON.parse(e.msg) : [+e.msg]
)
.finally(() => thenAction()); .finally(() => thenAction());
} else { } else {
thenAction(); thenAction();
...@@ -813,7 +825,7 @@ export default { ...@@ -813,7 +825,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
) { ) {
...@@ -878,8 +890,9 @@ export default { ...@@ -878,8 +890,9 @@ export default {
commit(ChatStore.MUTATION_INITING_CHAT_DONE); commit(ChatStore.MUTATION_INITING_CHAT_DONE);
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;
Chat.setRead(wantedChatRoom.model_name, wantedChatRoom.obj_id);
}, },
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);
...@@ -887,7 +900,7 @@ export default { ...@@ -887,7 +900,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);
...@@ -925,12 +938,12 @@ export default { ...@@ -925,12 +938,12 @@ 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);
}) })
); );
}, },
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(
...@@ -958,7 +971,7 @@ export default { ...@@ -958,7 +971,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;
...@@ -982,7 +995,7 @@ export default { ...@@ -982,7 +995,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;
...@@ -999,7 +1012,7 @@ export default { ...@@ -999,7 +1012,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;
...@@ -1017,7 +1030,7 @@ export default { ...@@ -1017,7 +1030,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;
...@@ -1035,7 +1048,7 @@ export default { ...@@ -1035,7 +1048,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]
) { ) {
...@@ -1055,7 +1068,7 @@ export default { ...@@ -1055,7 +1068,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]
) { ) {
...@@ -1075,7 +1088,7 @@ export default { ...@@ -1075,7 +1088,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]
) { ) {
...@@ -1095,7 +1108,7 @@ export default { ...@@ -1095,7 +1108,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]
) { ) {
......
...@@ -146,7 +146,9 @@ class Chat { ...@@ -146,7 +146,9 @@ class Chat {
return Promise.resolve(uri); return Promise.resolve(uri);
} }
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
xim.open(uri, this.token).catch(reject).finally(() => { xim.open(uri, this.token)
.catch(reject)
.finally(() => {
this.registerXimEvent(); this.registerXimEvent();
if (xim.isConnected()) { if (xim.isConnected()) {
resolve(); resolve();
...@@ -203,6 +205,15 @@ class Chat { ...@@ -203,6 +205,15 @@ class Chat {
public getAvatar() { public getAvatar() {
return this.defaultAvatar; return this.defaultAvatar;
} }
public setRead(model: string, obj: string) {
if (this.isBackend()) {
const sdk = this.getSdk();
if (sdk) {
sdk.getAxios().post(`/general/xim/model/${model}/${obj}/read`);
}
}
}
} }
export default new Chat(); export default new Chat();
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