Commit ba4ae341 by Sixong.Zhu

alias name

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