Commit b948fa15 by Sixong.Zhu

update 消息流加载机制

parent b8911ba3
......@@ -78,12 +78,7 @@
/>
<avatar
v-if="!isQuestionAnswerMessage && !isWithdrawMessage"
:src="
chatRole === 'admin' ||
chatRole === 'customer-service'
? defaultAvatar
: avatar
"
:src="avatar || defaultAvatar"
shape="circle"
/>
</div>
......@@ -224,8 +219,8 @@
@chatStore.State(ChatStore.STATE_CHAT_CURRENT_USER_UID)
private readonly chatMyId!: ChatStore.STATE_CHAT_CURRENT_USER_UID;
@chatStore.Getter(ChatStore.STATE_CURRENT_CHAT_MEMBERS)
private readonly allChatMembers!: ChatStore.STATE_CURRENT_CHAT_MEMBERS;
@chatStore.State(ChatStore.STATE_ALL_HISTORY_CHAT_MEMBERS)
private readonly allChatMembers!: ChatStore.STATE_ALL_HISTORY_CHAT_MEMBERS;
@chatStore.Getter(ChatStore.GETTER_CURRENT_CHAT_PRESENT_MEMBERS)
private readonly chatMembers!: ChatStore.GETTER_CURRENT_CHAT_PRESENT_MEMBERS;
......@@ -403,7 +398,7 @@
if (this.chatMembers) {
const t = this.chatMembers.find((i) => i.eid === this.data.eid);
if (t) {
const name = this.getFilterUsername(t.alias_name || t.name);
const name = this.getFilterUsername(t.alias_name, t.name);
if (name) {
return name;
}
......@@ -413,15 +408,18 @@
return this.refetchUsername;
}
private getFilterUsername(name: string) {
private getFilterUsername(name1: string, name2: string) {
const backend = Xim.isBackend();
if (
this.currentChat &&
this.currentChat.catalog === "福利宝" &&
this.chatRole === "customer-service"
) {
return `采购顾问 ${name}`;
return backend && name1
? `采购顾问 ${name1}(${name2})`
: `采购顾问 ${name1 || name2}`;
}
return name;
return backend && name1 ? `${name1}(${name2})` : name1 || name2;
}
private get avatar() {
......@@ -615,7 +613,14 @@
if (this.data && this.data.eid) {
ChatUserInfoService.getUserInfo(this.data.eid).then((r) => {
if (r) {
this.refetchUsername = r.alias_name || r.name || r.phone;
if (Xim.isBackend() && r.alias_name) {
this.refetchUsername = `${r.alias_name}(${
r.name || r.phone
})`;
} else {
this.refetchUsername =
r.alias_name || r.name || r.phone;
}
r.icon && (this.refetchUserIcon = r.icon);
}
});
......
......@@ -159,6 +159,7 @@ export default {
[ChatStore.STATE_CHAT_MY_UID]: null,
[ChatStore.STATE_CHAT_SOURCE]: ServiceType.Frontend,
[ChatStore.STATE_CURRENT_CHAT_MEMBERS]: null,
[ChatStore.STATE_ALL_HISTORY_CHAT_MEMBERS]: null,
[ChatStore.STATE_CURRENT_CHAT_TITLE]: "",
[ChatStore.STATE_FUNC_SCROLL_TO_BOTTOM]: () => true,
[ChatStore.STATE_FUNC_ON_NEW_MSG]: () => true,
......@@ -881,7 +882,7 @@ export default {
commit(ChatStore.MUTATION_CLEAR_CHAT_MSG_HISTORY);
commit(ChatStore.MUTATION_SAVE_CURRENT_CHAT_ID, chatId);
await getChatModelInfo(
getChatModelInfo(
wantedChatRoom.model_name,
wantedChatRoom.obj_id,
wantedChatRoom.detail_name
......@@ -895,13 +896,13 @@ export default {
ChatStore.MUTATION_SAVE_CURRENT_CHAT_UNIPLAT_ID,
info.uniplatId
);
dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS);
})
.catch(console.error);
commit(ChatStore.MUTATION_INITING_CHAT);
removeRegisterChatEvents.forEach((k) => k());
removeRegisterChatEvents = [];
try {
await dispatch(ChatStore.ACTION_GET_CHAT_MEMBERS);
await Promise.all([
dispatch(ChatStore.ACTION_REGISTER_EVENT),
dispatch(ChatStore.ACTION_GET_CHAT_MESSAGES),
......@@ -937,7 +938,7 @@ export default {
const getChatMembersResult = await xim.fetchChatMembers(chatId);
if (!getChatMembersResult) return;
const chatMembers = getChatMembersResult.args[0] as ChatMember[];
let newChatMembers = await Promise.all(
const all = await Promise.all(
chatMembers.map(async (member) => {
let result: NonNullable<ChatStore.STATE_CURRENT_CHAT_MEMBERS>[number];
try {
......@@ -956,7 +957,8 @@ export default {
return result;
})
);
newChatMembers = newChatMembers.filter((it) => !it.is_exited);
state[ChatStore.STATE_ALL_HISTORY_CHAT_MEMBERS] = all;
const newChatMembers = all.filter((it) => !it.is_exited);
const member = newChatMembers.find(
(it) =>
it.eid ===
......@@ -969,6 +971,7 @@ export default {
commit(ChatStore.MUTATION_CHAT_UPDATE_IS_MEMBER, false);
commit(ChatStore.MUTATION_CHAT_UPDATE_USER_TYPE, "0");
}
commit(
ChatStore.MUTATION_SAVE_CURRENT_CHAT_MEMBERS,
unique(newChatMembers, function (item, all) {
......
......@@ -73,6 +73,11 @@ export namespace ChatStore {
| readonly (dto.ChatMember & dto.ChatMemberExtraInfo)[]
| null;
export const STATE_ALL_HISTORY_CHAT_MEMBERS = "当前会话历史所有参与者";
export type STATE_ALL_HISTORY_CHAT_MEMBERS =
| readonly (dto.ChatMember & dto.ChatMemberExtraInfo)[]
| null;
export const STATE_CURRENT_CHAT_TITLE = "会话标题";
export type STATE_CURRENT_CHAT_TITLE = string;
......
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