Commit 01b506b6 by zhousil

Merge branch 'master' into release

parents df68099d 87ad0f2f
......@@ -47,6 +47,7 @@
import MessageInput from "@/customer-service/components/message-input.vue";
import messages from "@/customer-service/components/message-list.vue";
import { ChatStore, chatStore } from "@/customer-service/store/model";
import Chat from "@/customer-service/xim";
type RoomInfoTab = "customer" | "order";
......@@ -124,7 +125,7 @@
}
private onError(msg: string) {
this.$message.error(msg);
Chat.error(msg);
}
private dragControllerDiv(e: MouseEvent) {
......
......@@ -16,6 +16,30 @@
>
{{ isQuestionAnswerMessage ? "" : userName }}
</div>
<div class="d-flex">
<template
v-if="backend && showReadSummary && !isWithdrawMessage"
>
<div v-if="isMyMessage" class="msg-read pos-rel">
<span
@click="openReaderList"
class="pointer"
:class="{ all: isAllRead }"
>
<template v-if="isAllRead">全部已读</template>
<template v-else-if="data.read_count > 0"
>{{ data.read_count }}人已读</template
>
<template v-else>未读</template>
</span>
<who-read-list
v-if="readListVisibility"
@blur="readListVisibility = false"
:msgId="data.id"
:class="{ offset: readerListOffset }"
/>
</div>
</template>
<div
class="content-avatar d-flex align-items-start"
:class="{
......@@ -36,7 +60,8 @@
<avatar
v-if="!isQuestionAnswerMessage && !isWithdrawMessage"
:src="
chatRole === 'admin' || chatRole === 'customer-service'
chatRole === 'admin' ||
chatRole === 'customer-service'
? defaultAvatar
: avatar
"
......@@ -44,6 +69,7 @@
/>
</div>
</div>
</div>
<i
class="el-icon-warning text-danger"
......@@ -52,36 +78,17 @@
></i>
<i class="el-icon-loading" v-else-if="isSendingMessage"></i>
<template v-if="backend && showReadSummary && !isWithdrawMessage">
<div v-if="isMyMessage" class="msg-read pos-rel">
<span
@click="openReaderList"
class="pointer"
:class="{ all: isAllRead }"
>
<template v-if="isAllRead">全部已读</template>
<template v-else-if="data.read_count > 0"
>{{ data.read_count }}人已读</template
>
<template v-else>未读</template>
</span>
<who-read-list
v-if="readListVisibility"
@blur="readListVisibility = false"
:msgId="data.id"
:class="{ offset: readerListOffset }"
/>
</div>
</template>
<span
class="withdraw"
v-if="
isMyMessage &&
canWithdraw &&
isWithdraw &&
!isWithdrawMessage &&
!isQuestionAnswerMessage
!isQuestionAnswerMessage &&
isChatMember
"
@mouseenter="hoverWithdraw"
@click="withdraw"
>撤回此消息</span
>
......@@ -147,6 +154,7 @@
import xim from "./../xim";
import { ChatRole } from "@/customer-service/model";
import { getUserMapping } from "../utils/user-info";
import Xim from "@/customer-service/xim";
const twoMinutes = 2 * 60 * 1000;
......@@ -202,6 +210,9 @@
@chatStore.Getter(ChatStore.GETTER_CURRENT_CURRENT_CHAT)
private readonly currentChat!: ChatStore.GETTER_CURRENT_CURRENT_CHAT;
@chatStore.State(ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER)
private readonly isChatMember!: ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER;
@Prop({ type: Object, default: () => Object.create(null) })
private readonly data!: dto.Message;
......@@ -227,6 +238,8 @@
private readerListOffset = false;
private defaultMessageHandledStatus = dto.MessageHandled.Default;
private isWithdraw = true;
private get canWithdraw() {
if (this.backend && this.data) {
return new Date().valueOf() - this.data.ts * 1000 < twoMinutes;
......@@ -297,7 +310,8 @@
private getFilterUsername(name: string) {
if (
this.currentChat && this.currentChat.catalog === "福利宝" &&
this.currentChat &&
this.currentChat.catalog === "福利宝" &&
this.chatRole === "customer-service"
) {
return `采购顾问 ${name}`;
......@@ -398,6 +412,10 @@
}
private withdraw() {
if (new Date().valueOf() - this.data.ts * 1000 > twoMinutes) {
Xim.error("超过两分钟的消息不能撤回");
return;
}
ximInstance.withdraw(this.chatId!, this.data.id).finally(() => {
dbController
.removeMessage(this.chatId!, this.data.id)
......@@ -408,6 +426,11 @@
});
}
private hoverWithdraw() {
this.isWithdraw =
new Date().valueOf() - this.data.ts * 1000 < twoMinutes;
}
private openReaderList(e: MouseEvent) {
this.readerListOffset = e.x < 450;
this.readListVisibility = true;
......
......@@ -349,9 +349,10 @@ export default {
} else {
arr.push(eid);
}
setTimeoutId[eid] = setTimeout(() => {
arr.splice(arr.indexOf(eid), 1);
}, 4000);
setTimeoutId[eid] = setTimeout(
() => arr.splice(arr.indexOf(eid), 1),
4000
);
};
})(),
[ChatStore.MUTATION_CLEAR_CURRENT_CHAT_INPUTING]: (state) => {
......@@ -477,21 +478,31 @@ export default {
items.forEach((i) => (sum += i.unread_msg_count));
state[ChatStore.STATE_CURRENT_UNREAD_MESSAGE_COUNT] = sum;
},
async [ChatStore.ACTION_GET_CHAT_MESSAGES]({ state, commit }) {
async [ChatStore.ACTION_GET_CHAT_MESSAGES]({ state, commit, getters }) {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
const chat = getters[ChatStore.GETTER_CURRENT_CURRENT_CHAT];
const isMember = state[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER];
if (chatId == null) return;
let data: Message[] = [];
const getMessages = async () => {
const o = {
model: chat.model_name,
obj: chat.obj_id,
isMember,
};
data = await xim.queryLastPageMsg(chatType, chatId, 20, o);
};
if (isMember) {
const cache = await dbController.getChatMessages(chatId);
if (cache && cache.length) {
data = cache;
} else {
data = await xim.queryLastPageMsg(
chatType,
chatId,
20,
!state[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER]
);
await getMessages();
}
} else {
await getMessages();
}
try {
commit(ChatStore.MUTATION_PUSH_CHAT_MSG_HISTORY, data);
dbController.saveChatMessages(chatId, data);
......@@ -504,34 +515,46 @@ export default {
}
},
async [ChatStore.ACTION_GET_CHAT_MESSAGES_BEFORE_SPECIFIC_ID](
{ state, commit },
{ state, commit, getters },
msgId: Parameters<ChatStore.ACTION_GET_CHAT_MESSAGES_BEFORE_SPECIFIC_ID>[0]
) {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (chatId == null) return;
const chat = getters[ChatStore.GETTER_CURRENT_CURRENT_CHAT];
const o = {
model: chat.model_name,
obj: chat.obj_id,
isMember: state[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER],
};
const data = await xim.queryPrevPageMsg(
chatType,
chatId,
msgId,
10,
!state[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER]
o
);
commit(ChatStore.MUTATION_UNSHIFT_CHAT_MSG_HISTORY, data);
dbController.appendMessages(chatId, data);
return data;
},
async [ChatStore.ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID](
{ state, commit },
{ state, commit, getters },
msgId: Parameters<ChatStore.ACTION_GET_CHAT_MESSAGES_AFTER_SPECIFIC_ID>[0]
) {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
if (chatId == null) return;
const chat = getters[ChatStore.GETTER_CURRENT_CURRENT_CHAT];
const o = {
model: chat.model_name,
obj: chat.obj_id,
isMember: state[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER],
};
const data = await xim.queryNextPageMsg(
chatType,
chatId,
msgId,
10,
!state[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER]
o
);
commit(ChatStore.MUTATION_PUSH_CHAT_MSG_HISTORY, data);
dbController.appendMessages(chatId, data);
......@@ -618,7 +641,12 @@ export default {
dispatch(ChatStore.ACTION_GET_MY_CHAT_LIST);
return chatId;
},
async [ChatStore.ACTION_REGISTER_EVENT]({ dispatch, commit, state }) {
async [ChatStore.ACTION_REGISTER_EVENT]({
dispatch,
commit,
state,
getters,
}) {
const chatId = state[ChatStore.STATE_CHAT_CURRENT_CHAT_ID];
const onNewMsg = (e: Message) => {
if (e.chat_id === chatId) {
......@@ -637,11 +665,21 @@ export default {
if (msgs == null) return;
const oldestMsgId = msgs[0].id - 1;
const lastMsgId = msgs[msgs.length - 1].id + 1;
const chat = getters[ChatStore.GETTER_CURRENT_CURRENT_CHAT];
const o = {
model: chat.model_name,
obj: chat.obj_id,
isMember:
state[ChatStore.STATE_CHAT_CURRENT_IS_CHAT_MEMBER],
};
const freshMsgs = await xim.queryMsgs(
chatType,
chatId,
oldestMsgId < 1 ? 1 : oldestMsgId,
lastMsgId
lastMsgId,
20,
true,
o
);
commit(ChatStore.MUTATION_CLEAR_CHAT_MSG_HISTORY);
commit(
......
......@@ -165,12 +165,16 @@ export class Xim {
lid = 0,
rid = 0,
limit = DefaultMsgPageSize,
desc = true
desc: boolean,
p: { isMember: boolean; model: string; obj: string }
): Promise<Message[]> {
this.checkConnected();
if (this.client == null) {
throw new Error("client shouldn't undefined");
}
if (!p.isMember && p.model && p.obj) {
return this.queryMessageWhenIsNotMember(p, limit, lid, rid, desc);
}
const res = await this.client.fetchChatMsgs(chatType, chatId, {
lid,
rid,
......@@ -180,6 +184,25 @@ export class Xim {
return res.args[0];
}
private queryMessageWhenIsNotMember(
p: { isMember: boolean; model: string; obj: string },
limit: number,
lid: number,
rid: number,
desc: boolean
) {
return chat
.getSdk()
.getAxios()
.get(
`/general/xim/model/${p.model}/${
p.obj
}/msgs?lid=${lid}&rid=${rid}&limit=${limit}&desc=${
desc ? 0 : 1
}`
);
}
private setMessagesRead(chatId: number, msg: Message[]) {
if (msg.length === 0) return;
return this.setRead(chatId, msg[0].id, msg[msg.length - 1].id);
......@@ -190,10 +213,18 @@ export class Xim {
chatType: string,
chatId: number,
limit: number,
notToRead?: boolean
p: { isMember: boolean; model: string; obj: string }
) {
const data = await this.queryMsgs(chatType, chatId, 0, 0, limit, true);
if (!notToRead) {
const data = await this.queryMsgs(
chatType,
chatId,
0,
0,
limit,
true,
p
);
if (p && p.isMember) {
this.setMessagesRead(chatId, data);
}
return data;
......@@ -205,7 +236,7 @@ export class Xim {
chatId: number,
msgId: number,
limit: number,
notToRead?: boolean
p: { isMember: boolean; model: string; obj: string }
) {
const data = await this.queryMsgs(
chatType,
......@@ -213,9 +244,10 @@ export class Xim {
0,
msgId,
limit,
true
true,
p
);
if (!notToRead) {
if (p && p.isMember) {
this.setMessagesRead(chatId, data);
}
return data;
......@@ -227,7 +259,7 @@ export class Xim {
chatId: number,
msgId: number,
limit: number,
notToRead?: boolean
p: { isMember: boolean; model: string; obj: string }
) {
const data = await this.queryMsgs(
chatType,
......@@ -235,9 +267,10 @@ export class Xim {
msgId,
0,
limit,
false
false,
p
);
if (!notToRead) {
if (p && p.isMember) {
this.setMessagesRead(chatId, data);
}
return data;
......
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