fix: 🐛修复是否不显示短号

This commit is contained in:
wanglihui 2024-04-21 21:41:59 +08:00
parent 150247343a
commit 38e301c708

View File

@ -1,5 +1,11 @@
import { ChannelInfoListener, SubscriberChangeListener } from "wukongimjssdk"; import { ChannelInfoListener, SubscriberChangeListener } from "wukongimjssdk";
import { Channel, ChannelInfo, ChannelTypePerson, WKSDK, Subscriber } from "wukongimjssdk"; import {
Channel,
ChannelInfo,
ChannelTypePerson,
WKSDK,
Subscriber,
} from "wukongimjssdk";
import { Section } from "../../Service/Section"; import { Section } from "../../Service/Section";
import { ProviderListener } from "../../Service/Provider"; import { ProviderListener } from "../../Service/Provider";
import WKApp from "../../App"; import WKApp from "../../App";
@ -7,94 +13,104 @@ import RouteContext from "../../Service/Context";
import { GroupRole } from "../../Service/Const"; import { GroupRole } from "../../Service/Const";
export class UserInfoRouteData { export class UserInfoRouteData {
uid!: string uid!: string;
channelInfo?: ChannelInfo channelInfo?: ChannelInfo;
fromChannel?: Channel fromChannel?: Channel;
fromSubscriberOfUser?: Subscriber // 当前用户在频道内的订阅信息 fromSubscriberOfUser?: Subscriber; // 当前用户在频道内的订阅信息
isSelf!:boolean // 是否是本人 isSelf!: boolean; // 是否是本人
refresh!: () => void // 刷新 refresh!: () => void; // 刷新
} }
export class UserInfoVM extends ProviderListener { export class UserInfoVM extends ProviderListener {
uid!: string uid!: string;
fromChannel?: Channel fromChannel?: Channel;
fromSubscriberOfUser?: Subscriber fromSubscriberOfUser?: Subscriber;
subscriberOfMy?:Subscriber // 当前登录用户在频道的订阅者信息 subscriberOfMy?: Subscriber; // 当前登录用户在频道的订阅者信息
fromChannelInfo?: ChannelInfo fromChannelInfo?: ChannelInfo;
channelInfo?: ChannelInfo channelInfo?: ChannelInfo;
vercode?:string vercode?: string;
channelInfoListener!: ChannelInfoListener short_no?: string;
subscriberChangeListener?: SubscriberChangeListener channelInfoListener!: ChannelInfoListener;
subscriberChangeListener?: SubscriberChangeListener;
constructor(uid: string, fromChannel?: Channel,vercode?:string) { constructor(uid: string, fromChannel?: Channel, vercode?: string) {
super() super();
this.uid = uid this.uid = uid;
this.fromChannel = fromChannel this.fromChannel = fromChannel;
this.vercode = vercode this.vercode = vercode;
} }
didMount(): void { didMount(): void {
this.reloadSubscribers();
this.reloadSubscribers() if (
this.fromChannel &&
if (this.fromChannel && this.fromChannel.channelType !== ChannelTypePerson) { this.fromChannel.channelType !== ChannelTypePerson
) {
this.subscriberChangeListener = () => { this.subscriberChangeListener = () => {
this.reloadSubscribers() this.reloadSubscribers();
} };
WKSDK.shared().channelManager.addSubscriberChangeListener(this.subscriberChangeListener) WKSDK.shared().channelManager.addSubscriberChangeListener(
this.subscriberChangeListener
);
// WKSDK.shared().channelManager.syncSubscribes(this.channel) // WKSDK.shared().channelManager.syncSubscribes(this.channel)
} }
this.reloadFromChannelInfo() this.reloadFromChannelInfo();
this.channelInfoListener = (channelInfo: ChannelInfo) => { this.channelInfoListener = (channelInfo: ChannelInfo) => {
if (channelInfo.channel.channelType === ChannelTypePerson && channelInfo.channel.channelID === this.uid) { if (
this.reloadChannelInfo() channelInfo.channel.channelType === ChannelTypePerson &&
channelInfo.channel.channelID === this.uid
) {
this.reloadChannelInfo();
} }
if(this.fromChannel) { if (this.fromChannel) {
if(channelInfo.channel.isEqual(this.fromChannel)) { if (channelInfo.channel.isEqual(this.fromChannel)) {
this.reloadFromChannelInfo() this.reloadFromChannelInfo();
} }
} }
this.notifyListener() this.notifyListener();
};
WKSDK.shared().channelManager.addListener(this.channelInfoListener);
} const channel = new Channel(this.uid, ChannelTypePerson);
WKSDK.shared().channelManager.addListener(this.channelInfoListener) this.channelInfo = WKSDK.shared().channelManager.getChannelInfo(channel);
WKSDK.shared().channelManager.fetchChannelInfo(channel);
const channel = new Channel(this.uid, ChannelTypePerson)
this.channelInfo = WKSDK.shared().channelManager.getChannelInfo(channel)
WKSDK.shared().channelManager.fetchChannelInfo(channel)
if (this.channelInfo) { if (this.channelInfo) {
this.notifyListener() this.notifyListener();
} }
} }
didUnMount(): void { didUnMount(): void {
if (this.subscriberChangeListener) { if (this.subscriberChangeListener) {
WKSDK.shared().channelManager.removeSubscriberChangeListener(this.subscriberChangeListener) WKSDK.shared().channelManager.removeSubscriberChangeListener(
this.subscriberChangeListener
);
} }
WKSDK.shared().channelManager.removeListener(this.channelInfoListener) WKSDK.shared().channelManager.removeListener(this.channelInfoListener);
} }
reloadSubscribers() { reloadSubscribers() {
if (this.fromChannel && this.fromChannel.channelType !== ChannelTypePerson) { if (
const subscribers = WKSDK.shared().channelManager.getSubscribes(this.fromChannel) this.fromChannel &&
this.fromChannel.channelType !== ChannelTypePerson
) {
const subscribers = WKSDK.shared().channelManager.getSubscribes(
this.fromChannel
);
if (subscribers && subscribers.length > 0) { if (subscribers && subscribers.length > 0) {
for (const subscriber of subscribers) { for (const subscriber of subscribers) {
if (subscriber.uid === this.uid) { if (subscriber.uid === this.uid) {
this.fromSubscriberOfUser = subscriber this.fromSubscriberOfUser = subscriber;
} else if (subscriber.uid === WKApp.loginInfo.uid) {
}else if(subscriber.uid === WKApp.loginInfo.uid) { this.subscriberOfMy = subscriber;
this.subscriberOfMy = subscriber
} }
} }
} }
this.notifyListener() this.notifyListener();
} }
} }
sections(context: RouteContext<UserInfoRouteData>) { sections(context: RouteContext<UserInfoRouteData>) {
@ -105,89 +121,129 @@ export class UserInfoVM extends ProviderListener {
fromSubscriberOfUser: this.fromSubscriberOfUser, fromSubscriberOfUser: this.fromSubscriberOfUser,
isSelf: this.isSelf(), isSelf: this.isSelf(),
refresh: () => { refresh: () => {
this.notifyListener() this.notifyListener();
} },
}) });
return WKApp.shared.userInfos(context) return WKApp.shared.userInfos(context);
} }
myIsManagerOrCreator() { myIsManagerOrCreator() {
return this.subscriberOfMy?.role === GroupRole.manager || this.subscriberOfMy?.role === GroupRole.owner return (
this.subscriberOfMy?.role === GroupRole.manager ||
this.subscriberOfMy?.role === GroupRole.owner
);
} }
shouldShowShort() { shouldShowShort() {
if( this.channelInfo?.orgData.short_no && this.channelInfo?.orgData.short_no == "") { if(!this.short_no){
return false return false
} }
if(!this.fromChannel) {
return true if (this.short_no === "") {
return false;
} else {
if (!this.fromChannel) {
return true;
} }
if(this.myIsManagerOrCreator()) { if (this.myIsManagerOrCreator()) {
return true return true;
}
return true;
} }
return false
} }
relation(): number { relation(): number {
return this.channelInfo?.orgData?.follow || 0 return this.channelInfo?.orgData?.follow || 0;
} }
displayName() { displayName() {
if(this.channelInfo?.orgData.remark && this.channelInfo?.orgData.remark !== "" ) { if (
return this.channelInfo?.orgData.remark this.channelInfo?.orgData.remark &&
this.channelInfo?.orgData.remark !== ""
) {
return this.channelInfo?.orgData.remark;
} }
if(this.fromSubscriberOfUser && this.fromSubscriberOfUser.remark && this.fromSubscriberOfUser.remark !== "") { if (
return this.fromSubscriberOfUser.remark this.fromSubscriberOfUser &&
this.fromSubscriberOfUser.remark &&
this.fromSubscriberOfUser.remark !== ""
) {
return this.fromSubscriberOfUser.remark;
} }
return this.channelInfo?.title return this.channelInfo?.title;
} }
// 是否显示昵称 // 是否显示昵称
showNickname() { showNickname() {
if(this.hasRemark()) { if (!this.short_no) {
return true return false;
} }
if(this.hasChannelNickname()) {
return true if (this.short_no === "") {
return false;
} else {
if (!this.fromChannel) {
return true;
}
if (this.myIsManagerOrCreator()) {
return true;
}
return true;
} }
return false
} }
hasRemark() { hasRemark() {
if(this.channelInfo?.orgData.remark && this.channelInfo?.orgData.remark !== "" ) { if (
return true this.channelInfo?.orgData.remark &&
this.channelInfo?.orgData.remark !== ""
) {
return true;
} }
return false return false;
} }
hasChannelNickname() { hasChannelNickname() {
if(this.fromSubscriberOfUser && this.fromSubscriberOfUser.remark && this.fromSubscriberOfUser.remark !== "") { if (
return true this.fromSubscriberOfUser &&
this.fromSubscriberOfUser.remark &&
this.fromSubscriberOfUser.remark !== ""
) {
return true;
} }
return false return false;
} }
// 是否显示频道昵称 // 是否显示频道昵称
showChannelNickname() { showChannelNickname() {
if(this.hasRemark() && this.hasChannelNickname()) { if (this.hasRemark() && this.hasChannelNickname()) {
return true return true;
} }
return false return false;
} }
// 是否是本人 // 是否是本人
isSelf() { isSelf() {
return WKApp.loginInfo.uid === this.uid return WKApp.loginInfo.uid === this.uid;
} }
reloadChannelInfo() { async reloadChannelInfo() {
this.channelInfo = WKSDK.shared().channelManager.getChannelInfo(new Channel(this.uid, ChannelTypePerson)) this.channelInfo = WKSDK.shared().channelManager.getChannelInfo(
this.notifyListener() new Channel(this.uid, ChannelTypePerson)
);
if (this.uid && this.channelInfo) {
const res = await WKApp.apiClient.get(`users/${this.uid}`, {
param: { group_no: this.channelInfo?.channel?.channelID },
});
this.short_no = res.short_no;
}
this.notifyListener();
} }
reloadFromChannelInfo() { reloadFromChannelInfo() {
if(this.fromChannel) { if (this.fromChannel) {
this.fromChannelInfo = WKSDK.shared().channelManager.getChannelInfo(this.fromChannel) this.fromChannelInfo = WKSDK.shared().channelManager.getChannelInfo(
this.notifyListener() this.fromChannel
);
this.notifyListener();
} }
} }
} }