Commit f3428a56 by Sixong.Zhu

user info

parent 3083860b
......@@ -3,7 +3,7 @@ import { parserMessage } from ".";
import { chatStore, ChatStore } from "@/customer-service/store/model";
import { formatTime, TimeFormatRule } from "@/customer-service/utils/time";
import { Chat as ChatItem } from "@/customer-service/xim/models/chat";
import Xim from "@/customer-service/xim";
import { getUserInfo } from "@/customer-service/utils/user-info";
@Component({ components: {} })
export default class ChatList extends Vue {
......@@ -61,18 +61,9 @@ export default class ChatList extends Vue {
protected parseMesage(data: ChatItem) {
if (data.last_msg_sender && data.last_msg_sender !== "0") {
if (this.userNames[data.last_msg_sender] === undefined) {
this.updateUserName({ id: data.last_msg_sender, name: "" });
Xim.getSdk()
.model("user")
.detail(data.last_msg_sender)
.query()
.then((userInfo: any) => {
this.updateUserName({
id: data.last_msg_sender,
name: userInfo.row.first_name.display as string,
});
})
.catch(() => { });
const id = data.last_msg_sender
this.updateUserName({ id, name: "" });
getUserInfo(id).then(d => this.updateUserName({ id, name: d.name }))
}
}
if (data.last_msg_content === "") {
......
......@@ -35,9 +35,7 @@
/>
<avatar
v-if="
(avatar || showHostAvatar) &&
!isQuestionAnswerMessage &&
!isWithdrawMessage
avatar && !isQuestionAnswerMessage && !isWithdrawMessage
"
:src="
chatRole === 'admin' || chatRole === 'customer-service'
......@@ -145,6 +143,7 @@
import QuestionAnswerMessage from "./message-item/question-answer-message.vue";
import xim from "./../xim";
import { ChatRole } from "@/customer-service/model";
import { getUserMapping } from "../utils/user-info";
const twoMinutes = 2 * 60 * 1000;
......@@ -221,7 +220,6 @@
private readerListOffset = false;
private defaultMessageHandledStatus = dto.MessageHandled.Default;
private showHostAvatar: boolean = false;
private get canWithdraw() {
if (this.backend && this.data) {
......@@ -292,25 +290,12 @@
}
private get avatar() {
const avatar = chat.getUserMapping();
if (Object.getOwnPropertyNames(avatar).length > 0) {
this.showHostAvatar = true;
} else {
this.showHostAvatar = false;
}
if (this.isSendingMessage) {
if (avatar && this.chatMyId) {
const user = avatar[this.chatMyId];
if (user && user.avatar) {
return user.avatar;
}
}
}
const mapping = getUserMapping();
if (avatar && this.data) {
const value = avatar[this.data.eid];
if (value && value.avatar) {
return value.avatar;
if (this.data) {
const value = mapping[this.data.eid];
if (value && value.icon) {
return value.icon;
}
}
......@@ -320,14 +305,18 @@
private get chatRole() {
if (this.chatMembers) {
const t = this.chatMembers.find((i) => i.eid === this.data.eid);
if (t?.type === ChatRole.Default) {
if (t) {
if (t.type === ChatRole.Default) {
return "default";
} else if (t?.type === ChatRole.Admin) {
}
if (t.type === ChatRole.Admin) {
return "admin";
} else if (t?.type === ChatRole.CustomerService) {
}
if (t.type === ChatRole.CustomerService) {
return "customer-service";
}
}
}
return "";
}
......
......@@ -63,8 +63,8 @@
import { unique } from "../utils";
import avatar from "@/customer-service/components/avatar.vue";
import { ChatStore } from "@/customer-service/store/model";
import chat from "@/customer-service/xim/index";
import xim from "@/customer-service/xim/xim";
import { getUserInfo } from "../utils/user-info";
const chatStoreNamespace = namespace("chatStore");
......@@ -116,8 +116,8 @@
}
private async getUserNameByid(eid: string) {
const data = await chat.getSdk().model("user").detail(eid).query();
return data.row.first_name.value as string;
const data = await getUserInfo(eid);
return data.name;
}
private async getReader() {
......
......@@ -65,11 +65,6 @@ export interface ChatOption {
eventHub?: Vue;
/**
* 用户信息(头像,别名)可选
*/
user?: { icon?: string; username?: string };
message?: ChatMessageController;
}
......
......@@ -1060,23 +1060,15 @@ export default {
return Promise.resolve({ id, name: cache[id] });
}
return new Promise<{ id: string; name: string }>(
(resolve, reject) => {
Chat.getSdk()
.model("user")
.detail(id)
.query()
.then((userInfo: any) => {
const name = userInfo.row.first_name
.display as string;
(resolve, reject) =>
getUserInfo(id).then(d => {
Vue.set(
state[ChatStore.STATE_CHAT_USERNAME],
id,
name
d.name
);
resolve({ id, name });
})
.catch(reject);
}
resolve({ id, name: d.name });
}).catch(reject)
);
},
},
......
......@@ -4,8 +4,10 @@ export type UserMapping = {
[eid: string]: {
name: string;
phone: string;
icon: string;
};
};
const userMapping: UserMapping = {};
export const getUserMapping = () => userMapping;
......@@ -14,10 +16,19 @@ export async function getUserInfo(eid: string) {
if (userMapping[eid]) {
return userMapping[eid];
}
const info = await Chat.getSdk().model("user").detail(eid).query();
const info = await Chat.getSdk().domainService('passport', 'anonymous', `oidc.account/user_info?id=${eid}`).request<any, any, {
avatar_url: string;
email: string;
id: string;
mobile: string;
realname: string;
uniplatId: string;
username: string;
}>('get');
const data = {
name: info.row.first_name.value as string,
phone: info.row.last_name.value as string,
name: info.username || info.realname || info.mobile || info.mobile,
phone: info.mobile,
icon: info.avatar_url
};
userMapping[eid] = data;
return data;
......
......@@ -27,9 +27,6 @@ class Chat implements ChatMessageController {
private connected = false;
private messageController: ChatMessageController | null = null;
private userMapping: { [key: string]: { name: string; avatar: string } } =
{};
public onReady(action: () => void) {
if (this.connected) {
action();
......@@ -54,12 +51,6 @@ class Chat implements ChatMessageController {
(this.serviceType = option.serviceType);
option.product && (this.product = option.product);
this.eventHub = option.eventHub || null;
if (option.user) {
this.userMapping[this._sdk().global.uid] = {
name: option.user.username || "",
avatar: option.user.icon || "",
};
}
option.message && (this.messageController = option.message);
......@@ -171,10 +162,6 @@ class Chat implements ChatMessageController {
this.debug(`client status ${e}`);
}
public getUserMapping() {
return this.userMapping;
}
private debug(message: string) {
ChatLoggerService.logger && ChatLoggerService.logger.debug(message);
}
......
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