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,187 +13,237 @@ 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 {
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.reloadFromChannelInfo();
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.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() const channel = new Channel(this.uid, ChannelTypePerson);
this.channelInfo = WKSDK.shared().channelManager.getChannelInfo(channel);
this.channelInfoListener = (channelInfo: ChannelInfo) => { WKSDK.shared().channelManager.fetchChannelInfo(channel);
if (channelInfo.channel.channelType === ChannelTypePerson && channelInfo.channel.channelID === this.uid) { if (this.channelInfo) {
this.reloadChannelInfo() this.notifyListener();
}
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()
}
} }
}
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() { }
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()
}
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<UserInfoRouteData>) { sections(context: RouteContext<UserInfoRouteData>) {
context.setRouteData({ context.setRouteData({
uid: this.uid, uid: this.uid,
channelInfo: this.channelInfo, channelInfo: this.channelInfo,
fromChannel: this.fromChannel, fromChannel: this.fromChannel,
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
}
if(!this.fromChannel) {
return true
}
if(this.myIsManagerOrCreator()) {
return true
}
return false return false
} }
relation(): number { if (this.short_no === "") {
return this.channelInfo?.orgData?.follow || 0 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.short_no === "") {
if(this.channelInfo?.orgData.remark && this.channelInfo?.orgData.remark !== "" ) { return false;
return this.channelInfo?.orgData.remark } else {
} if (!this.fromChannel) {
if(this.fromSubscriberOfUser && this.fromSubscriberOfUser.remark && this.fromSubscriberOfUser.remark !== "") { return true;
return this.fromSubscriberOfUser.remark }
} if (this.myIsManagerOrCreator()) {
return this.channelInfo?.title return true;
}
return true;
} }
}
// 是否显示昵称 hasRemark() {
showNickname() { if (
if(this.hasRemark()) { this.channelInfo?.orgData.remark &&
return true this.channelInfo?.orgData.remark !== ""
} ) {
if(this.hasChannelNickname()) { return true;
return true
}
return false
} }
return false;
}
hasRemark() { hasChannelNickname() {
if(this.channelInfo?.orgData.remark && this.channelInfo?.orgData.remark !== "" ) { if (
return true this.fromSubscriberOfUser &&
} this.fromSubscriberOfUser.remark &&
return false this.fromSubscriberOfUser.remark !== ""
) {
return true;
} }
return false;
}
hasChannelNickname() { // 是否显示频道昵称
if(this.fromSubscriberOfUser && this.fromSubscriberOfUser.remark && this.fromSubscriberOfUser.remark !== "") { showChannelNickname() {
return true if (this.hasRemark() && this.hasChannelNickname()) {
} return true;
return false
} }
return false;
}
// 是否显示频道昵称 // 是否是本人
showChannelNickname() { isSelf() {
if(this.hasRemark() && this.hasChannelNickname()) { return WKApp.loginInfo.uid === this.uid;
return true }
}
return false
}
// 是否是本人 async reloadChannelInfo() {
isSelf() { this.channelInfo = WKSDK.shared().channelManager.getChannelInfo(
return WKApp.loginInfo.uid === this.uid new Channel(this.uid, ChannelTypePerson)
} );
if (this.uid && this.channelInfo) {
reloadChannelInfo() { const res = await WKApp.apiClient.get(`users/${this.uid}`, {
this.channelInfo = WKSDK.shared().channelManager.getChannelInfo(new Channel(this.uid, ChannelTypePerson)) param: { group_no: this.channelInfo?.channel?.channelID },
this.notifyListener() });
this.short_no = res.short_no;
} }
reloadFromChannelInfo() { this.notifyListener();
if(this.fromChannel) { }
this.fromChannelInfo = WKSDK.shared().channelManager.getChannelInfo(this.fromChannel) reloadFromChannelInfo() {
this.notifyListener() if (this.fromChannel) {
} this.fromChannelInfo = WKSDK.shared().channelManager.getChannelInfo(
this.fromChannel
);
this.notifyListener();
} }
} }
}