Commit ba4ae341 by Sixong.Zhu

alias name

parent 40cbc7b7
......@@ -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 { getUserInfo } from "@/customer-service/utils/user-info";
import { ChatUserInfoService } from "@/customer-service/utils/user-info";
@Component({ components: {} })
export default class ChatList extends Vue {
......@@ -64,9 +64,11 @@ 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) {
const id = data.last_msg_sender
const id = data.last_msg_sender;
this.updateUserName({ id, name: "" });
getUserInfo(id).then(d => this.updateUserName({ id, name: d.name }))
ChatUserInfoService.getUserInfo(id).then((d) =>
this.updateUserName({ id, name: d.alias_name || d.name })
);
}
}
if (data.last_msg_content === "") {
......
......@@ -350,7 +350,7 @@
if (this.chatMembers) {
const t = this.chatMembers.find((i) => i.eid === this.data.eid);
if (t) {
return this.getFilterUsername(t.name);
return this.getFilterUsername(t.alias_name || t.name);
}
}
return "";
......
......@@ -58,7 +58,7 @@
import avatar from "@/customer-service/components/avatar.vue";
import { ChatStore } from "@/customer-service/store/model";
import xim from "@/customer-service/xim/xim";
import { getUserInfo } from "../utils/user-info";
import { ChatUserInfoService } from "../utils/user-info";
const chatStoreNamespace = namespace("chatStore");
......@@ -113,7 +113,7 @@
}
private async getUserNameByid(eid: string) {
const data = await getUserInfo(eid);
const data = await ChatUserInfoService.getUserInfo(eid);
return data.name;
}
......
......@@ -216,6 +216,7 @@ export interface TransferedChatItem extends BaseChatItem {
export type ChatMemberExtraInfo = {
name?: string;
phone?: string;
alias_name?: string;
};
export interface ChatMember {
......@@ -242,6 +243,7 @@ export interface ChatMember {
update_time: number;
name: string;
phone: string;
alias_name?: string;
}
export type ChatMembers = readonly ChatMember[];
......
......@@ -12,7 +12,7 @@ import {
import { isAccessibleUrl } from "../service/tools";
import { unique } from "../utils";
import { getChatModelInfo } from "../utils/chat-info";
import { getUserInfo } from "../utils/user-info";
import { ChatUserInfoService } from "../utils/user-info";
import Chat from "../xim";
import { Chat as ChatType, Message } from "../xim/models/chat";
import xim, { ChatNotifyListener, Xim } from "../xim/xim";
......@@ -910,7 +910,9 @@ export default {
chatMembers.map(async (member) => {
let result: NonNullable<ChatStore.STATE_CURRENT_CHAT_MEMBERS>[number];
try {
const data = await getUserInfo(member.eid);
const data = await ChatUserInfoService.getUserInfo(
member.eid
);
result = {
...member,
...data,
......@@ -1164,7 +1166,7 @@ export default {
}
return new Promise<{ id: string; name: string }>(
(resolve, reject) =>
getUserInfo(id)
ChatUserInfoService.getUserInfo(id)
.then((d) => {
Vue.set(
state[ChatStore.STATE_CHAT_USERNAME],
......
......@@ -6,6 +6,7 @@ export type UserMapping = {
name: string;
phone: string;
icon: string;
alias_name: string;
};
};
......@@ -19,29 +20,50 @@ interface UserInfo {
realname: string;
uniplatId: string;
username: string;
alias_name: string;
}
export const getUserMapping = () => userMapping;
export async function getUserInfo(eid: string, sdk?: UniplatSdk) {
if (userMapping[eid]) {
return userMapping[eid];
export class ChatUserInfoService {
public static async getUserInfo(eid: string, sdk?: UniplatSdk) {
if (userMapping[eid]) {
return userMapping[eid];
}
if (!+eid || +eid < 0) {
return { name: "", phone: "", icon: "", alias_name: "" };
}
const info = await (sdk || Chat.getSdk())
.domainService(
"passport",
"anonymous",
`oidc.account/user_info?id=${eid}`
)
.request<any, any, UserInfo>("get");
const data = {
name: info.username || info.realname || info.mobile || info.mobile,
phone: info.mobile,
icon: info.avatar_url,
alias_name: info.alias_name,
};
userMapping[eid] = data;
return data;
}
if (!+eid || +eid < 0) {
return { name: "", phone: "", icon: "" };
public static updateCache(uid: string, alias_name: string) {
const t = userMapping[uid];
t && (t.alias_name = alias_name);
}
public static setAliasName(
uid: string | number,
name: string,
sdk?: UniplatSdk
) {
return (sdk || Chat.getSdk())
.domainService("passport", "anonymous", `oidc.account/set_alias`)
.request<any, any, {}>("post", {
data: { id: uid, alias_name: name },
});
}
const info = await (sdk || Chat.getSdk())
.domainService(
"passport",
"anonymous",
`oidc.account/user_info?id=${eid}`
)
.request<any, any, UserInfo>("get");
const data = {
name: info.username || info.realname || info.mobile || info.mobile,
phone: info.mobile,
icon: info.avatar_url,
};
userMapping[eid] = 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