From 38e301c7082018fc94248be430dee71993c788ff Mon Sep 17 00:00:00 2001 From: wanglihui <1769794040@qq.com> Date: Sun, 21 Apr 2024 21:41:59 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=E4=BF=AE=E5=A4=8D=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E4=B8=8D=E6=98=BE=E7=A4=BA=E7=9F=AD=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Components/UserInfo/vm.tsx | 360 ++++++++++-------- 1 file changed, 208 insertions(+), 152 deletions(-) diff --git a/packages/tsdaodaobase/src/Components/UserInfo/vm.tsx b/packages/tsdaodaobase/src/Components/UserInfo/vm.tsx index 5f3c06d..e05e668 100644 --- a/packages/tsdaodaobase/src/Components/UserInfo/vm.tsx +++ b/packages/tsdaodaobase/src/Components/UserInfo/vm.tsx @@ -1,5 +1,11 @@ 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 { ProviderListener } from "../../Service/Provider"; import WKApp from "../../App"; @@ -7,187 +13,237 @@ import RouteContext from "../../Service/Context"; import { GroupRole } from "../../Service/Const"; export class UserInfoRouteData { - uid!: string - channelInfo?: ChannelInfo - fromChannel?: Channel - fromSubscriberOfUser?: Subscriber // 当前用户在频道内的订阅信息 - isSelf!:boolean // 是否是本人 - refresh!: () => void // 刷新 - + uid!: string; + channelInfo?: ChannelInfo; + fromChannel?: Channel; + fromSubscriberOfUser?: Subscriber; // 当前用户在频道内的订阅信息 + isSelf!: boolean; // 是否是本人 + refresh!: () => void; // 刷新 } export class UserInfoVM extends ProviderListener { - uid!: string - fromChannel?: Channel - fromSubscriberOfUser?: Subscriber - subscriberOfMy?:Subscriber // 当前登录用户在频道的订阅者信息 - fromChannelInfo?: ChannelInfo - channelInfo?: ChannelInfo - vercode?:string - channelInfoListener!: ChannelInfoListener - subscriberChangeListener?: SubscriberChangeListener + uid!: string; + fromChannel?: Channel; + fromSubscriberOfUser?: Subscriber; + subscriberOfMy?: Subscriber; // 当前登录用户在频道的订阅者信息 + fromChannelInfo?: ChannelInfo; + channelInfo?: ChannelInfo; + vercode?: string; + short_no?: string; + channelInfoListener!: ChannelInfoListener; + subscriberChangeListener?: SubscriberChangeListener; - constructor(uid: string, fromChannel?: Channel,vercode?:string) { - super() - this.uid = uid - this.fromChannel = fromChannel - this.vercode = vercode + constructor(uid: string, fromChannel?: Channel, vercode?: string) { + super(); + this.uid = uid; + this.fromChannel = fromChannel; + this.vercode = vercode; + } + + didMount(): void { + this.reloadSubscribers(); + + if ( + this.fromChannel && + this.fromChannel.channelType !== ChannelTypePerson + ) { + this.subscriberChangeListener = () => { + this.reloadSubscribers(); + }; + WKSDK.shared().channelManager.addSubscriberChangeListener( + this.subscriberChangeListener + ); + + // WKSDK.shared().channelManager.syncSubscribes(this.channel) } - didMount(): void { - - this.reloadSubscribers() - - if (this.fromChannel && this.fromChannel.channelType !== ChannelTypePerson) { - this.subscriberChangeListener = () => { - this.reloadSubscribers() - } - WKSDK.shared().channelManager.addSubscriberChangeListener(this.subscriberChangeListener) - - // WKSDK.shared().channelManager.syncSubscribes(this.channel) + this.reloadFromChannelInfo(); + this.channelInfoListener = (channelInfo: ChannelInfo) => { + if ( + channelInfo.channel.channelType === ChannelTypePerson && + channelInfo.channel.channelID === this.uid + ) { + this.reloadChannelInfo(); + } + if (this.fromChannel) { + if (channelInfo.channel.isEqual(this.fromChannel)) { + this.reloadFromChannelInfo(); } + } + this.notifyListener(); + }; + WKSDK.shared().channelManager.addListener(this.channelInfoListener); - this.reloadFromChannelInfo() - - this.channelInfoListener = (channelInfo: ChannelInfo) => { - if (channelInfo.channel.channelType === ChannelTypePerson && channelInfo.channel.channelID === this.uid) { - this.reloadChannelInfo() - } - if(this.fromChannel) { - if(channelInfo.channel.isEqual(this.fromChannel)) { - this.reloadFromChannelInfo() - } - } - this.notifyListener() - - } - WKSDK.shared().channelManager.addListener(this.channelInfoListener) - - const channel = new Channel(this.uid, ChannelTypePerson) - this.channelInfo = WKSDK.shared().channelManager.getChannelInfo(channel) - WKSDK.shared().channelManager.fetchChannelInfo(channel) - if (this.channelInfo) { - this.notifyListener() - } + const channel = new Channel(this.uid, ChannelTypePerson); + this.channelInfo = WKSDK.shared().channelManager.getChannelInfo(channel); + WKSDK.shared().channelManager.fetchChannelInfo(channel); + if (this.channelInfo) { + this.notifyListener(); } + } - didUnMount(): void { - if (this.subscriberChangeListener) { - WKSDK.shared().channelManager.removeSubscriberChangeListener(this.subscriberChangeListener) - } - WKSDK.shared().channelManager.removeListener(this.channelInfoListener) + didUnMount(): void { + if (this.subscriberChangeListener) { + WKSDK.shared().channelManager.removeSubscriberChangeListener( + this.subscriberChangeListener + ); } - - reloadSubscribers() { - if (this.fromChannel && this.fromChannel.channelType !== ChannelTypePerson) { - const subscribers = WKSDK.shared().channelManager.getSubscribes(this.fromChannel) - if (subscribers && subscribers.length > 0) { - for (const subscriber of subscribers) { - if (subscriber.uid === this.uid) { - this.fromSubscriberOfUser = subscriber - - }else if(subscriber.uid === WKApp.loginInfo.uid) { - this.subscriberOfMy = subscriber - } - } - } - this.notifyListener() - } + WKSDK.shared().channelManager.removeListener(this.channelInfoListener); + } + reloadSubscribers() { + if ( + this.fromChannel && + this.fromChannel.channelType !== ChannelTypePerson + ) { + const subscribers = WKSDK.shared().channelManager.getSubscribes( + this.fromChannel + ); + if (subscribers && subscribers.length > 0) { + for (const subscriber of subscribers) { + if (subscriber.uid === this.uid) { + this.fromSubscriberOfUser = subscriber; + } else if (subscriber.uid === WKApp.loginInfo.uid) { + this.subscriberOfMy = subscriber; + } + } + } + this.notifyListener(); } + } - sections(context: RouteContext) { - context.setRouteData({ - uid: this.uid, - channelInfo: this.channelInfo, - fromChannel: this.fromChannel, - fromSubscriberOfUser: this.fromSubscriberOfUser, - isSelf: this.isSelf(), - refresh: () => { - this.notifyListener() - } - }) - return WKApp.shared.userInfos(context) - } + sections(context: RouteContext) { + context.setRouteData({ + uid: this.uid, + channelInfo: this.channelInfo, + fromChannel: this.fromChannel, + fromSubscriberOfUser: this.fromSubscriberOfUser, + isSelf: this.isSelf(), + refresh: () => { + this.notifyListener(); + }, + }); + return WKApp.shared.userInfos(context); + } - myIsManagerOrCreator() { - return this.subscriberOfMy?.role === GroupRole.manager || this.subscriberOfMy?.role === GroupRole.owner - } + myIsManagerOrCreator() { + return ( + this.subscriberOfMy?.role === GroupRole.manager || + this.subscriberOfMy?.role === GroupRole.owner + ); + } - shouldShowShort() { - if( this.channelInfo?.orgData.short_no && this.channelInfo?.orgData.short_no == "") { - return false - } - if(!this.fromChannel) { - return true - } - if(this.myIsManagerOrCreator()) { - return true - } + shouldShowShort() { + if(!this.short_no){ return false } - relation(): number { - return this.channelInfo?.orgData?.follow || 0 + if (this.short_no === "") { + return false; + } else { + if (!this.fromChannel) { + return true; + } + if (this.myIsManagerOrCreator()) { + return true; + } + return true; + } + } + + relation(): number { + return this.channelInfo?.orgData?.follow || 0; + } + + displayName() { + if ( + this.channelInfo?.orgData.remark && + this.channelInfo?.orgData.remark !== "" + ) { + return this.channelInfo?.orgData.remark; + } + if ( + this.fromSubscriberOfUser && + this.fromSubscriberOfUser.remark && + this.fromSubscriberOfUser.remark !== "" + ) { + return this.fromSubscriberOfUser.remark; + } + return this.channelInfo?.title; + } + + // 是否显示昵称 + showNickname() { + if (!this.short_no) { + return false; } - displayName() { - if(this.channelInfo?.orgData.remark && this.channelInfo?.orgData.remark !== "" ) { - return this.channelInfo?.orgData.remark - } - if(this.fromSubscriberOfUser && this.fromSubscriberOfUser.remark && this.fromSubscriberOfUser.remark !== "") { - return this.fromSubscriberOfUser.remark - } - return this.channelInfo?.title + if (this.short_no === "") { + return false; + } else { + if (!this.fromChannel) { + return true; + } + if (this.myIsManagerOrCreator()) { + return true; + } + return true; } + } - // 是否显示昵称 - showNickname() { - if(this.hasRemark()) { - return true - } - if(this.hasChannelNickname()) { - return true - } - return false + hasRemark() { + if ( + this.channelInfo?.orgData.remark && + this.channelInfo?.orgData.remark !== "" + ) { + return true; } + return false; + } - hasRemark() { - if(this.channelInfo?.orgData.remark && this.channelInfo?.orgData.remark !== "" ) { - return true - } - return false + hasChannelNickname() { + if ( + this.fromSubscriberOfUser && + this.fromSubscriberOfUser.remark && + this.fromSubscriberOfUser.remark !== "" + ) { + return true; } + return false; + } - hasChannelNickname() { - if(this.fromSubscriberOfUser && this.fromSubscriberOfUser.remark && this.fromSubscriberOfUser.remark !== "") { - return true - } - return false + // 是否显示频道昵称 + showChannelNickname() { + if (this.hasRemark() && this.hasChannelNickname()) { + return true; } + return false; + } - // 是否显示频道昵称 - showChannelNickname() { - if(this.hasRemark() && this.hasChannelNickname()) { - return true - } - return false - } + // 是否是本人 + isSelf() { + return WKApp.loginInfo.uid === this.uid; + } - // 是否是本人 - isSelf() { - return WKApp.loginInfo.uid === this.uid - } - - reloadChannelInfo() { - this.channelInfo = WKSDK.shared().channelManager.getChannelInfo(new Channel(this.uid, ChannelTypePerson)) - this.notifyListener() + async reloadChannelInfo() { + this.channelInfo = WKSDK.shared().channelManager.getChannelInfo( + 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; } - reloadFromChannelInfo() { - if(this.fromChannel) { - this.fromChannelInfo = WKSDK.shared().channelManager.getChannelInfo(this.fromChannel) - this.notifyListener() - } + this.notifyListener(); + } + reloadFromChannelInfo() { + if (this.fromChannel) { + this.fromChannelInfo = WKSDK.shared().channelManager.getChannelInfo( + this.fromChannel + ); + this.notifyListener(); } -} \ No newline at end of file + } +}