新增公共房间管理器 PublicRoomManager,负责管理用户进入公共聊天房间的逻辑;在 ClientConfig.m 中添加对公共房间管理器的配置更新通知;在多个文件中集成公共房间管理器,确保用户信息更新和状态管理的正确性;更新相关文档以提供使用指南和集成说明。
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#import "UserInfoModel.h"
|
||||
#import "XPLoginAuthCodeVC.h"
|
||||
#import "FirstRechargeManager.h"
|
||||
|
||||
@implementation PILoginManager
|
||||
+(void)loginWithVC:(MvpViewController *)VC isLoginPhone:(BOOL)isLoginPhone{
|
||||
[XNDJTDDLoadingTool showLoading];
|
||||
@@ -70,6 +71,7 @@
|
||||
return;
|
||||
}
|
||||
[XNDJTDDLoadingTool showSuccessWithMessage:YMLocalizedString(@"PKIDLoginViewController0")];
|
||||
|
||||
[PILoginManager jumpToHomeVCWithInviteCode:@""];
|
||||
});
|
||||
|
||||
|
@@ -121,21 +121,22 @@ typedef NS_ENUM(NSUInteger, LoginType) {
|
||||
}
|
||||
|
||||
- (void)setupBottomPolicy {
|
||||
|
||||
UIView *view_1 = [[UIView alloc] init];
|
||||
UIView *view_2 = [[UIView alloc] init];
|
||||
UIStackView *stackView = [[UIStackView alloc] initWithArrangedSubviews:@[
|
||||
view_1,
|
||||
self.agreeButton,
|
||||
self.policyLabel,
|
||||
view_2
|
||||
]];
|
||||
stackView.spacing = 8;
|
||||
stackView.alignment = UIStackViewAlignmentCenter;
|
||||
stackView.distribution = UIStackViewDistributionFill;
|
||||
[self.view addSubview:stackView];
|
||||
[stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(self.view);
|
||||
if (isMSRTL()) {
|
||||
make.width.mas_equalTo(290);
|
||||
}
|
||||
make.bottom.mas_equalTo(self.view).offset(-44);
|
||||
make.height.mas_equalTo(34);
|
||||
make.width.mas_lessThanOrEqualTo(self.view).offset(-32);
|
||||
}];
|
||||
|
||||
[self.agreeButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
@@ -150,7 +151,7 @@ typedef NS_ENUM(NSUInteger, LoginType) {
|
||||
[self.view addSubview:smsLogin];
|
||||
[smsLogin mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(self.view);
|
||||
make.bottom.mas_equalTo(self.view).offset(-104);
|
||||
make.bottom.mas_equalTo(self.view).offset(-124);
|
||||
make.size.mas_equalTo(CGSizeMake(48, 48));
|
||||
}];
|
||||
}
|
||||
@@ -357,6 +358,9 @@ typedef NS_ENUM(NSUInteger, LoginType) {
|
||||
_policyLabel.numberOfLines = 0;
|
||||
|
||||
NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginViewController6")];
|
||||
if ([[UIScreen mainScreen] bounds].size.width < 450 && (isMSPT() || isMSTR())) {
|
||||
attString = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"XPLoginViewController6.1")];
|
||||
}
|
||||
attString.yy_color = UIColorFromRGB(0x7B7B7D);
|
||||
NSRange userRange = [attString.string rangeOfString:YMLocalizedString(@"XPLoginViewController7")];
|
||||
[attString addAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0x313131)} range:userRange];
|
||||
|
260
YuMi/Modules/YMMessage/Tool/NIMSDKManager.h
Normal file
260
YuMi/Modules/YMMessage/Tool/NIMSDKManager.h
Normal file
@@ -0,0 +1,260 @@
|
||||
//
|
||||
// NIMSDKManager.h
|
||||
// YUMI
|
||||
//
|
||||
// Created by YUMI on 2024/12/19.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <NIMSDK/NIMSDK.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// MARK: - NIMSDK配置模型
|
||||
@interface NIMSDKConfigModel : NSObject
|
||||
|
||||
@property (nonatomic, copy) NSString *appKey; // 云信AppKey
|
||||
@property (nonatomic, copy) NSString *apnsCername; // APNS证书名称
|
||||
@property (nonatomic, assign) BOOL shouldConsiderRevokedMessageUnreadCount; // 撤回消息计入未读数
|
||||
@property (nonatomic, assign) BOOL shouldSyncStickTopSessionInfos; // 同步置顶会话信息
|
||||
@property (nonatomic, assign) BOOL enabledHttpsForInfo; // 启用HTTPS信息传输
|
||||
@property (nonatomic, assign) BOOL enabledHttpsForMessage; // 启用HTTPS消息传输
|
||||
|
||||
@end
|
||||
|
||||
// MARK: - NIMSDK登录状态枚举
|
||||
typedef NS_ENUM(NSInteger, NIMSDKLoginStatus) {
|
||||
NIMSDKLoginStatusNotLogin = 0, // 未登录
|
||||
NIMSDKLoginStatusLogging, // 登录中
|
||||
NIMSDKLoginStatusLogined, // 已登录
|
||||
NIMSDKLoginStatusLogout, // 已登出
|
||||
NIMSDKLoginStatusKickout, // 被踢出
|
||||
NIMSDKLoginStatusAutoLoginFailed // 自动登录失败
|
||||
};
|
||||
|
||||
// MARK: - NIMSDK登录回调
|
||||
typedef void(^NIMSDKLoginCompletion)(NSError * _Nullable error);
|
||||
typedef void(^NIMSDKLogoutCompletion)(NSError * _Nullable error);
|
||||
typedef void(^NIMSDKStatusChangeBlock)(NIMSDKLoginStatus status);
|
||||
|
||||
// MARK: - NIMSDKManager代理协议
|
||||
@protocol NIMSDKManagerDelegate <NSObject>
|
||||
|
||||
@optional
|
||||
// 登录状态变化
|
||||
- (void)nimSDKManager:(id)manager didChangeLoginStatus:(NIMSDKLoginStatus)status;
|
||||
// 自动登录失败
|
||||
- (void)nimSDKManager:(id)manager didAutoLoginFailed:(NSError *)error;
|
||||
// 被踢出
|
||||
- (void)nimSDKManager:(id)manager didKickout:(NIMLoginKickoutResult *)result;
|
||||
// 收到消息
|
||||
- (void)nimSDKManager:(id)manager didReceiveMessages:(NSArray<NIMMessage *> *)messages;
|
||||
// 收到广播消息
|
||||
- (void)nimSDKManager:(id)manager didReceiveBroadcastMessage:(NIMBroadcastMessage *)broadcastMessage;
|
||||
|
||||
@end
|
||||
|
||||
// MARK: - NIMSDKManager主类
|
||||
@interface NIMSDKManager : NSObject
|
||||
|
||||
// MARK: - 单例方法
|
||||
+ (instancetype)sharedManager;
|
||||
|
||||
// MARK: - 配置和初始化
|
||||
/**
|
||||
配置NIMSDK
|
||||
@param config 配置模型
|
||||
*/
|
||||
- (void)configureWithConfig:(NIMSDKConfigModel *)config;
|
||||
|
||||
/**
|
||||
初始化NIMSDK
|
||||
@param completion 完成回调
|
||||
*/
|
||||
- (void)initializeWithCompletion:(void(^)(NSError * _Nullable error))completion;
|
||||
|
||||
/**
|
||||
注册自定义消息解码器
|
||||
@param decoder 解码器实例
|
||||
*/
|
||||
- (void)registerCustomDecoder:(id<NIMCustomAttachmentCoding>)decoder;
|
||||
|
||||
// MARK: - 登录管理
|
||||
/**
|
||||
登录
|
||||
@param account 账号
|
||||
@param token 登录token
|
||||
@param completion 完成回调
|
||||
*/
|
||||
- (void)loginWithAccount:(NSString *)account
|
||||
token:(NSString *)token
|
||||
completion:(NIMSDKLoginCompletion)completion;
|
||||
|
||||
/**
|
||||
自动登录
|
||||
@param data 自动登录数据
|
||||
@param completion 完成回调
|
||||
*/
|
||||
- (void)autoLoginWithData:(NSDictionary *)data
|
||||
completion:(NIMSDKLoginCompletion)completion;
|
||||
|
||||
/**
|
||||
登出
|
||||
@param completion 完成回调
|
||||
*/
|
||||
- (void)logoutWithCompletion:(NIMSDKLogoutCompletion)completion;
|
||||
|
||||
/**
|
||||
强制登出
|
||||
@param completion 完成回调
|
||||
*/
|
||||
- (void)forceLogoutWithCompletion:(NIMSDKLogoutCompletion)completion;
|
||||
|
||||
// MARK: - 状态查询
|
||||
/**
|
||||
获取当前登录状态
|
||||
@return 登录状态
|
||||
*/
|
||||
- (NIMSDKLoginStatus)currentLoginStatus;
|
||||
|
||||
/**
|
||||
是否已登录
|
||||
@return 是否已登录
|
||||
*/
|
||||
- (BOOL)isLogined;
|
||||
|
||||
/**
|
||||
获取当前登录账号
|
||||
@return 当前登录账号
|
||||
*/
|
||||
- (NSString *)currentAccount;
|
||||
|
||||
// MARK: - 推送管理
|
||||
/**
|
||||
更新APNS设备Token
|
||||
@param deviceToken 设备Token
|
||||
*/
|
||||
- (void)updateApnsToken:(NSData *)deviceToken;
|
||||
|
||||
/**
|
||||
处理推送消息
|
||||
@param userInfo 推送消息内容
|
||||
@return 是否处理成功
|
||||
*/
|
||||
- (BOOL)handlePushNotification:(NSDictionary *)userInfo;
|
||||
|
||||
// MARK: - 代理管理
|
||||
/**
|
||||
添加代理
|
||||
@param delegate 代理对象
|
||||
*/
|
||||
- (void)addDelegate:(id<NIMSDKManagerDelegate>)delegate;
|
||||
|
||||
/**
|
||||
移除代理
|
||||
@param delegate 代理对象
|
||||
*/
|
||||
- (void)removeDelegate:(id<NIMSDKManagerDelegate>)delegate;
|
||||
|
||||
/**
|
||||
设置登录状态变化回调
|
||||
@param block 回调block
|
||||
*/
|
||||
- (void)setLoginStatusChangeBlock:(NIMSDKStatusChangeBlock)block;
|
||||
|
||||
// MARK: - 消息管理
|
||||
/**
|
||||
发送消息
|
||||
@param message 消息对象
|
||||
@param session 会话对象
|
||||
@param completion 完成回调
|
||||
*/
|
||||
- (void)sendMessage:(NIMMessage *)message
|
||||
toSession:(NIMSession *)session
|
||||
completion:(void(^)(NSError * _Nullable error))completion;
|
||||
|
||||
/**
|
||||
获取未读消息数
|
||||
@return 未读消息数
|
||||
*/
|
||||
- (NSInteger)unreadMessageCount;
|
||||
|
||||
/**
|
||||
获取所有会话
|
||||
@return 会话列表
|
||||
*/
|
||||
- (NSArray<NIMRecentSession *> *)allRecentSessions;
|
||||
|
||||
// MARK: - 用户管理
|
||||
/**
|
||||
获取用户信息
|
||||
@param userId 用户ID
|
||||
@return 用户信息
|
||||
*/
|
||||
- (NIMUser *)userInfo:(NSString *)userId;
|
||||
|
||||
/**
|
||||
获取用户信息(异步)
|
||||
@param userIds 用户ID数组
|
||||
@param completion 完成回调
|
||||
*/
|
||||
- (void)fetchUserInfos:(NSArray<NSString *> *)userIds
|
||||
completion:(void(^)(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error))completion;
|
||||
|
||||
// MARK: - 聊天室管理
|
||||
/**
|
||||
进入聊天室
|
||||
@param roomId 房间ID
|
||||
@param completion 完成回调
|
||||
*/
|
||||
- (void)enterChatroom:(NSString *)roomId
|
||||
completion:(void(^)(NSError * _Nullable error))completion;
|
||||
|
||||
/**
|
||||
退出聊天室
|
||||
@param roomId 房间ID
|
||||
@param completion 完成回调
|
||||
*/
|
||||
- (void)exitChatroom:(NSString *)roomId
|
||||
completion:(void(^)(NSError * _Nullable error))completion;
|
||||
|
||||
// MARK: - 工具方法
|
||||
/**
|
||||
创建自定义消息
|
||||
@param attachment 自定义附件
|
||||
@return 消息对象
|
||||
*/
|
||||
- (NIMMessage *)createCustomMessageWithAttachment:(id<NIMCustomAttachment>)attachment;
|
||||
|
||||
/**
|
||||
创建文本消息
|
||||
@param text 文本内容
|
||||
@return 消息对象
|
||||
*/
|
||||
- (NIMMessage *)createTextMessage:(NSString *)text;
|
||||
|
||||
/**
|
||||
创建图片消息
|
||||
@param image 图片对象
|
||||
@return 消息对象
|
||||
*/
|
||||
- (NIMMessage *)createImageMessage:(UIImage *)image;
|
||||
|
||||
/**
|
||||
创建音频消息
|
||||
@param filePath 音频文件路径
|
||||
@param duration 音频时长
|
||||
@return 消息对象
|
||||
*/
|
||||
- (NIMMessage *)createAudioMessage:(NSString *)filePath duration:(NSTimeInterval)duration;
|
||||
|
||||
// MARK: - 清理方法
|
||||
/**
|
||||
清理资源
|
||||
*/
|
||||
- (void)cleanup;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
406
YuMi/Modules/YMMessage/Tool/NIMSDKManager.m
Normal file
406
YuMi/Modules/YMMessage/Tool/NIMSDKManager.m
Normal file
@@ -0,0 +1,406 @@
|
||||
//
|
||||
// NIMSDKManager.m
|
||||
// YUMI
|
||||
//
|
||||
// Created by YUMI on 2024/12/19.
|
||||
//
|
||||
|
||||
#import "NIMSDKManager.h"
|
||||
#import "CustomAttachmentDecoder.h"
|
||||
#import "YUMIConstant.h"
|
||||
|
||||
@interface NIMSDKManager () <NIMLoginManagerDelegate, NIMChatManagerDelegate, NIMSystemNotificationManagerDelegate, NIMBroadcastManagerDelegate>
|
||||
|
||||
@property (nonatomic, strong) NIMSDKConfigModel *config;
|
||||
@property (nonatomic, assign) NIMSDKLoginStatus loginStatus;
|
||||
@property (nonatomic, strong) NSMutableArray<id<NIMSDKManagerDelegate>> *delegates;
|
||||
@property (nonatomic, copy) NIMSDKStatusChangeBlock statusChangeBlock;
|
||||
@property (nonatomic, assign) BOOL isInitialized;
|
||||
|
||||
@end
|
||||
|
||||
@implementation NIMSDKManager
|
||||
|
||||
#pragma mark - 单例方法
|
||||
|
||||
+ (instancetype)sharedManager {
|
||||
static NIMSDKManager *instance = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
instance = [[NIMSDKManager alloc] init];
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_delegates = [NSMutableArray array];
|
||||
_loginStatus = NIMSDKLoginStatusNotLogin;
|
||||
_isInitialized = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - 配置和初始化
|
||||
|
||||
- (void)configureWithConfig:(NIMSDKConfigModel *)config {
|
||||
self.config = config;
|
||||
}
|
||||
|
||||
- (void)initializeWithCompletion:(void(^)(NSError * _Nullable error))completion {
|
||||
if (self.isInitialized) {
|
||||
if (completion) {
|
||||
completion(nil);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查配置
|
||||
if (!self.config || !self.config.appKey) {
|
||||
NSError *error = [NSError errorWithDomain:@"NIMSDKManager"
|
||||
code:-1
|
||||
userInfo:@{NSLocalizedDescriptionKey: @"NIMSDK配置不完整"}];
|
||||
if (completion) {
|
||||
completion(error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建SDK选项
|
||||
NIMSDKOption *option = [NIMSDKOption optionWithAppKey:self.config.appKey];
|
||||
if (self.config.apnsCername) {
|
||||
option.apnsCername = self.config.apnsCername;
|
||||
}
|
||||
|
||||
// 注册SDK
|
||||
[[NIMSDK sharedSDK] registerWithOption:option];
|
||||
|
||||
// 注册自定义解码器
|
||||
[self registerCustomDecoder:[[CustomAttachmentDecoder alloc] init]];
|
||||
|
||||
// 配置SDK参数
|
||||
[NIMSDKConfig sharedConfig].shouldConsiderRevokedMessageUnreadCount = self.config.shouldConsiderRevokedMessageUnreadCount;
|
||||
[[NIMSDKConfig sharedConfig] setShouldSyncStickTopSessionInfos:self.config.shouldSyncStickTopSessionInfos];
|
||||
[NIMSDKConfig sharedConfig].enabledHttpsForInfo = self.config.enabledHttpsForInfo;
|
||||
[NIMSDKConfig sharedConfig].enabledHttpsForMessage = self.config.enabledHttpsForMessage;
|
||||
|
||||
// 添加代理
|
||||
[[NIMSDK sharedSDK].loginManager addDelegate:self];
|
||||
[[NIMSDK sharedSDK].chatManager addDelegate:self];
|
||||
[[NIMSDK sharedSDK].systemNotificationManager addDelegate:self];
|
||||
[[NIMSDK sharedSDK].broadcastManager addDelegate:self];
|
||||
|
||||
self.isInitialized = YES;
|
||||
|
||||
if (completion) {
|
||||
completion(nil);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)registerCustomDecoder:(id<NIMCustomAttachmentCoding>)decoder {
|
||||
[NIMCustomObject registerCustomDecoder:decoder];
|
||||
}
|
||||
|
||||
#pragma mark - 登录管理
|
||||
|
||||
- (void)loginWithAccount:(NSString *)account
|
||||
token:(NSString *)token
|
||||
completion:(NIMSDKLoginCompletion)completion {
|
||||
|
||||
if (!self.isInitialized) {
|
||||
NSError *error = [NSError errorWithDomain:@"NIMSDKManager"
|
||||
code:-2
|
||||
userInfo:@{NSLocalizedDescriptionKey: @"NIMSDK未初始化"}];
|
||||
if (completion) {
|
||||
completion(error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
self.loginStatus = NIMSDKLoginStatusLogging;
|
||||
[self notifyStatusChange];
|
||||
|
||||
[[NIMSDK sharedSDK].loginManager login:account
|
||||
token:token
|
||||
completion:^(NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (error) {
|
||||
self.loginStatus = NIMSDKLoginStatusNotLogin;
|
||||
} else {
|
||||
self.loginStatus = NIMSDKLoginStatusLogined;
|
||||
}
|
||||
[self notifyStatusChange];
|
||||
|
||||
if (completion) {
|
||||
completion(error);
|
||||
}
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)autoLoginWithData:(NSDictionary *)data
|
||||
completion:(NIMSDKLoginCompletion)completion {
|
||||
|
||||
if (!self.isInitialized) {
|
||||
NSError *error = [NSError errorWithDomain:@"NIMSDKManager"
|
||||
code:-2
|
||||
userInfo:@{NSLocalizedDescriptionKey: @"NIMSDK未初始化"}];
|
||||
if (completion) {
|
||||
completion(error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
self.loginStatus = NIMSDKLoginStatusLogging;
|
||||
[self notifyStatusChange];
|
||||
|
||||
[[NIMSDK sharedSDK].loginManager autoLogin:data];
|
||||
|
||||
// 注意:自动登录的结果通过代理方法回调
|
||||
// 这里暂时返回成功,实际结果通过代理通知
|
||||
if (completion) {
|
||||
completion(nil);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)logoutWithCompletion:(NIMSDKLogoutCompletion)completion {
|
||||
[[NIMSDK sharedSDK].loginManager logout:^(NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (!error) {
|
||||
self.loginStatus = NIMSDKLoginStatusLogout;
|
||||
[self notifyStatusChange];
|
||||
}
|
||||
|
||||
if (completion) {
|
||||
completion(error);
|
||||
}
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)forceLogoutWithCompletion:(NIMSDKLogoutCompletion)completion {
|
||||
// 强制登出,清理所有状态
|
||||
[[NIMSDK sharedSDK].loginManager logout:^(NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.loginStatus = NIMSDKLoginStatusLogout;
|
||||
[self notifyStatusChange];
|
||||
|
||||
if (completion) {
|
||||
completion(error);
|
||||
}
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - 状态查询
|
||||
|
||||
- (NIMSDKLoginStatus)currentLoginStatus {
|
||||
return self.loginStatus;
|
||||
}
|
||||
|
||||
- (BOOL)isLogined {
|
||||
return [[NIMSDK sharedSDK].loginManager isLogined];
|
||||
}
|
||||
|
||||
- (NSString *)currentAccount {
|
||||
return [[NIMSDK sharedSDK].loginManager currentAccount];
|
||||
}
|
||||
|
||||
#pragma mark - 推送管理
|
||||
|
||||
- (void)updateApnsToken:(NSData *)deviceToken {
|
||||
[[NIMSDK sharedSDK] updateApnsToken:deviceToken];
|
||||
}
|
||||
|
||||
- (BOOL)handlePushNotification:(NSDictionary *)userInfo {
|
||||
// 处理推送消息的逻辑
|
||||
// 这里可以根据具体的推送格式进行解析和处理
|
||||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark - 代理管理
|
||||
|
||||
- (void)addDelegate:(id<NIMSDKManagerDelegate>)delegate {
|
||||
if (delegate && ![self.delegates containsObject:delegate]) {
|
||||
[self.delegates addObject:delegate];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeDelegate:(id<NIMSDKManagerDelegate>)delegate {
|
||||
[self.delegates removeObject:delegate];
|
||||
}
|
||||
|
||||
- (void)setLoginStatusChangeBlock:(NIMSDKStatusChangeBlock)block {
|
||||
self.statusChangeBlock = block;
|
||||
}
|
||||
|
||||
#pragma mark - 消息管理
|
||||
|
||||
- (void)sendMessage:(NIMMessage *)message
|
||||
toSession:(NIMSession *)session
|
||||
completion:(void(^)(NSError * _Nullable error))completion {
|
||||
[[NIMSDK sharedSDK].chatManager sendMessage:message
|
||||
toSession:session
|
||||
error:nil];
|
||||
// 注意:实际发送结果通过代理方法回调
|
||||
if (completion) {
|
||||
completion(nil);
|
||||
}
|
||||
}
|
||||
|
||||
- (NSInteger)unreadMessageCount {
|
||||
return [[NIMSDK sharedSDK].conversationManager allUnreadCount];
|
||||
}
|
||||
|
||||
- (NSArray<NIMRecentSession *> *)allRecentSessions {
|
||||
return [[NIMSDK sharedSDK].conversationManager allRecentSessions];
|
||||
}
|
||||
|
||||
#pragma mark - 用户管理
|
||||
|
||||
- (NIMUser *)userInfo:(NSString *)userId {
|
||||
return [[NIMSDK sharedSDK].userManager userInfo:userId];
|
||||
}
|
||||
|
||||
- (void)fetchUserInfos:(NSArray<NSString *> *)userIds
|
||||
completion:(void(^)(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error))completion {
|
||||
[[NIMSDK sharedSDK].userManager fetchUserInfos:userIds
|
||||
completion:completion];
|
||||
}
|
||||
|
||||
#pragma mark - 聊天室管理
|
||||
|
||||
- (void)enterChatroom:(NSString *)roomId
|
||||
completion:(void(^)(NSError * _Nullable error))completion {
|
||||
[[NIMSDK sharedSDK].chatroomManager enterChatroom:roomId
|
||||
completion:completion];
|
||||
}
|
||||
|
||||
- (void)exitChatroom:(NSString *)roomId
|
||||
completion:(void(^)(NSError * _Nullable error))completion {
|
||||
[[NIMSDK sharedSDK].chatroomManager exitChatroom:roomId
|
||||
completion:completion];
|
||||
}
|
||||
|
||||
#pragma mark - 工具方法
|
||||
|
||||
- (NIMMessage *)createCustomMessageWithAttachment:(id<NIMCustomAttachment>)attachment {
|
||||
NIMCustomObject *customObject = [[NIMCustomObject alloc] init];
|
||||
customObject.attachment = attachment;
|
||||
|
||||
NIMMessage *message = [[NIMMessage alloc] init];
|
||||
message.messageObject = customObject;
|
||||
return message;
|
||||
}
|
||||
|
||||
- (NIMMessage *)createTextMessage:(NSString *)text {
|
||||
return [[NIMMessage alloc] initWithText:text];
|
||||
}
|
||||
|
||||
- (NIMMessage *)createImageMessage:(UIImage *)image {
|
||||
NIMImageObject *imageObject = [[NIMImageObject alloc] initWithImage:image];
|
||||
NIMMessage *message = [[NIMMessage alloc] init];
|
||||
message.messageObject = imageObject;
|
||||
return message;
|
||||
}
|
||||
|
||||
- (NIMMessage *)createAudioMessage:(NSString *)filePath duration:(NSTimeInterval)duration {
|
||||
NIMAudioObject *audioObject = [[NIMAudioObject alloc] initWithSourcePath:filePath];
|
||||
audioObject.duration = duration;
|
||||
|
||||
NIMMessage *message = [[NIMMessage alloc] init];
|
||||
message.messageObject = audioObject;
|
||||
return message;
|
||||
}
|
||||
|
||||
#pragma mark - 清理方法
|
||||
|
||||
- (void)cleanup {
|
||||
// 移除代理
|
||||
[[NIMSDK sharedSDK].loginManager removeDelegate:self];
|
||||
[[NIMSDK sharedSDK].chatManager removeDelegate:self];
|
||||
[[NIMSDK sharedSDK].systemNotificationManager removeDelegate:self];
|
||||
[[NIMSDK sharedSDK].broadcastManager removeDelegate:self];
|
||||
|
||||
// 清理状态
|
||||
self.loginStatus = NIMSDKLoginStatusNotLogin;
|
||||
self.isInitialized = NO;
|
||||
[self.delegates removeAllObjects];
|
||||
self.statusChangeBlock = nil;
|
||||
}
|
||||
|
||||
#pragma mark - 私有方法
|
||||
|
||||
- (void)notifyStatusChange {
|
||||
// 通知代理
|
||||
for (id<NIMSDKManagerDelegate> delegate in self.delegates) {
|
||||
if ([delegate respondsToSelector:@selector(nimSDKManager:didChangeLoginStatus:)]) {
|
||||
[delegate nimSDKManager:self didChangeLoginStatus:self.loginStatus];
|
||||
}
|
||||
}
|
||||
|
||||
// 通知block
|
||||
if (self.statusChangeBlock) {
|
||||
self.statusChangeBlock(self.loginStatus);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - NIMLoginManagerDelegate
|
||||
|
||||
- (void)onAutoLoginFailed:(NSError *)error {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.loginStatus = NIMSDKLoginStatusAutoLoginFailed;
|
||||
[self notifyStatusChange];
|
||||
|
||||
// 通知代理
|
||||
for (id<NIMSDKManagerDelegate> delegate in self.delegates) {
|
||||
if ([delegate respondsToSelector:@selector(nimSDKManager:didAutoLoginFailed:)]) {
|
||||
[delegate nimSDKManager:self didAutoLoginFailed:error];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)onKickout:(NIMLoginKickoutResult *)result {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.loginStatus = NIMSDKLoginStatusKickout;
|
||||
[self notifyStatusChange];
|
||||
|
||||
// 通知代理
|
||||
for (id<NIMSDKManagerDelegate> delegate in self.delegates) {
|
||||
if ([delegate respondsToSelector:@selector(nimSDKManager:didKickout:)]) {
|
||||
[delegate nimSDKManager:self didKickout:result];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark - NIMChatManagerDelegate
|
||||
|
||||
- (void)onRecvMessages:(NSArray<NIMMessage *> *)messages {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// 通知代理
|
||||
for (id<NIMSDKManagerDelegate> delegate in self.delegates) {
|
||||
if ([delegate respondsToSelector:@selector(nimSDKManager:didReceiveMessages:)]) {
|
||||
[delegate nimSDKManager:self didReceiveMessages:messages];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark - NIMBroadcastManagerDelegate
|
||||
|
||||
- (void)onReceiveBroadcastMessage:(NIMBroadcastMessage *)broadcastMessage {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// 通知代理
|
||||
for (id<NIMSDKManagerDelegate> delegate in self.delegates) {
|
||||
if ([delegate respondsToSelector:@selector(nimSDKManager:didReceiveBroadcastMessage:)]) {
|
||||
[delegate nimSDKManager:self didReceiveBroadcastMessage:broadcastMessage];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@end
|
||||
|
@@ -42,7 +42,7 @@
|
||||
}
|
||||
|
||||
- (void)setupUI {
|
||||
_backgroundImage = [[UIImageView alloc] init];
|
||||
_backgroundImage = [[UIImageView alloc] initWithImage:kImage(@"cp_bg")];
|
||||
self.backgroundImage.contentMode = UIViewContentModeScaleAspectFit;
|
||||
[self addSubview:self.backgroundImage];
|
||||
[self.backgroundImage mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
|
73
YuMi/Modules/YMRoom/Manager/PublicRoomManager.h
Normal file
73
YuMi/Modules/YMRoom/Manager/PublicRoomManager.h
Normal file
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// PublicRoomManager.h
|
||||
// YUMI
|
||||
//
|
||||
// Created by YUMI on 2024/12/19.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <NIMSDK/NIMSDK.h>
|
||||
|
||||
@class UserInfoModel;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
* 公共聊天房间管理器
|
||||
* 负责管理用户进入公共聊天房间的逻辑
|
||||
*/
|
||||
@interface PublicRoomManager : NSObject
|
||||
|
||||
#pragma mark - 单例方法
|
||||
+ (instancetype)sharedManager;
|
||||
|
||||
#pragma mark - 生命周期管理
|
||||
/**
|
||||
* 初始化公共房间管理器
|
||||
* 在用户登录成功后调用
|
||||
*/
|
||||
- (void)initialize;
|
||||
|
||||
/**
|
||||
* 重置公共房间管理器
|
||||
* 在用户登出时调用,清理所有状态
|
||||
*/
|
||||
- (void)reset;
|
||||
|
||||
#pragma mark - 状态查询
|
||||
/**
|
||||
* 是否已初始化
|
||||
*/
|
||||
- (BOOL)isInitialized;
|
||||
|
||||
/**
|
||||
* 是否已进入公共房间
|
||||
*/
|
||||
- (BOOL)isInPublicRoom;
|
||||
|
||||
/**
|
||||
* 获取当前公共房间ID
|
||||
*/
|
||||
- (NSString *)currentPublicRoomId;
|
||||
|
||||
// 更新来自 config 的数据
|
||||
- (void)updateConfig;
|
||||
|
||||
- (void)updateUserInfo:(UserInfoModel *)userInfo;
|
||||
|
||||
#pragma mark - 手动控制
|
||||
/**
|
||||
* 手动进入公共房间
|
||||
* @param completion 完成回调
|
||||
*/
|
||||
- (void)enterPublicRoomWithCompletion:(void(^)(NSError * _Nullable error))completion;
|
||||
|
||||
/**
|
||||
* 手动退出公共房间
|
||||
* @param completion 完成回调
|
||||
*/
|
||||
- (void)exitPublicRoomWithCompletion:(void(^)(NSError * _Nullable error))completion;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
346
YuMi/Modules/YMRoom/Manager/PublicRoomManager.m
Normal file
346
YuMi/Modules/YMRoom/Manager/PublicRoomManager.m
Normal file
@@ -0,0 +1,346 @@
|
||||
//
|
||||
// PublicRoomManager.m
|
||||
// YUMI
|
||||
//
|
||||
// Created by YUMI on 2024/12/19.
|
||||
//
|
||||
|
||||
#import "PublicRoomManager.h"
|
||||
#import "UserInfoModel.h"
|
||||
#import "ClientConfig.h"
|
||||
#import "AccountInfoStorage.h"
|
||||
#import "XPMessageRemoteExtModel.h"
|
||||
|
||||
@interface PublicRoomManager () <NIMChatManagerDelegate>
|
||||
|
||||
@property (nonatomic, assign) BOOL isInitialized;
|
||||
@property (nonatomic, assign) BOOL isInPublicRoom;
|
||||
@property (nonatomic, copy) NSString *currentPublicRoomId;
|
||||
@property (nonatomic, copy) NSString *currentUserId;
|
||||
@property (nonatomic, strong) UserInfoModel *userInfo;
|
||||
|
||||
@end
|
||||
|
||||
@implementation PublicRoomManager
|
||||
|
||||
#pragma mark - 单例方法
|
||||
|
||||
+ (instancetype)sharedManager {
|
||||
static dispatch_once_t onceToken;
|
||||
static PublicRoomManager *instance;
|
||||
dispatch_once(&onceToken, ^{
|
||||
instance = [[self alloc] init];
|
||||
[instance initialize];
|
||||
});
|
||||
return instance;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_isInitialized = NO;
|
||||
_isInPublicRoom = NO;
|
||||
_currentPublicRoomId = nil;
|
||||
_currentUserId = nil;
|
||||
_userInfo = nil;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - 生命周期管理
|
||||
|
||||
- (void)initialize {
|
||||
// 防止重复初始化
|
||||
if (self.isInitialized) {
|
||||
NSLog(@"PublicRoomManager: 已经初始化,跳过重复初始化");
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查用户是否已登录
|
||||
// NSString *uid = [AccountInfoStorage instance].getUid;
|
||||
// if (uid.length == 0) {
|
||||
// NSLog(@"PublicRoomManager: 用户未登录,无法初始化");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 检查是否已获取到用户信息
|
||||
// UserInfoModel *userInfo = [AccountInfoStorage instance].getHomeUserInfo;
|
||||
// if (!userInfo || !userInfo.partitionId) {
|
||||
// NSLog(@"PublicRoomManager: 用户信息不完整,等待用户信息更新");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 检查配置信息是否已加载
|
||||
// ClientDataModel *configInfo = [ClientConfig shareConfig].configInfo;
|
||||
// if (!configInfo || !configInfo.publicChatRoomIdMap) {
|
||||
// NSLog(@"PublicRoomManager: 配置信息未加载,等待配置更新");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// 保存用户信息
|
||||
// self.userInfo = userInfo;
|
||||
// self.currentUserId = uid;
|
||||
|
||||
// 注册云信代理
|
||||
[[NIMSDK sharedSDK].chatManager addDelegate:self];
|
||||
|
||||
// 标记为已初始化
|
||||
self.isInitialized = YES;
|
||||
|
||||
// NSLog(@"PublicRoomManager: 初始化成功,用户ID: %@, 分区ID: %@", uid, userInfo.partitionId);
|
||||
|
||||
// 尝试进入公共房间
|
||||
// [self tryEnterPublicRoom];
|
||||
}
|
||||
|
||||
- (void)reset {
|
||||
NSLog(@"PublicRoomManager: 开始重置");
|
||||
|
||||
// 退出公共房间
|
||||
if (self.isInPublicRoom && self.currentPublicRoomId) {
|
||||
[self exitPublicRoomWithCompletion:^(NSError * _Nullable error) {
|
||||
if (error) {
|
||||
NSLog(@"PublicRoomManager: 退出公共房间失败: %@", error);
|
||||
} else {
|
||||
NSLog(@"PublicRoomManager: 退出公共房间成功");
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
// 移除云信代理
|
||||
[[NIMSDK sharedSDK].chatManager removeDelegate:self];
|
||||
|
||||
// 重置状态
|
||||
self.isInitialized = NO;
|
||||
self.isInPublicRoom = NO;
|
||||
self.currentPublicRoomId = nil;
|
||||
self.currentUserId = nil;
|
||||
self.userInfo = nil;
|
||||
|
||||
NSLog(@"PublicRoomManager: 重置完成");
|
||||
}
|
||||
|
||||
#pragma mark - 状态查询
|
||||
|
||||
- (BOOL)isInitialized {
|
||||
return _isInitialized;
|
||||
}
|
||||
|
||||
- (BOOL)isInPublicRoom {
|
||||
return _isInPublicRoom;
|
||||
}
|
||||
|
||||
- (NSString *)currentPublicRoomId {
|
||||
return _currentPublicRoomId;
|
||||
}
|
||||
|
||||
#pragma mark - 私有方法
|
||||
|
||||
- (void)tryEnterPublicRoom {
|
||||
if (!self.isInitialized || !self.userInfo) {
|
||||
NSLog(@"PublicRoomManager: 未初始化或用户信息缺失,无法进入公共房间");
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取公共房间ID
|
||||
NSString *partitionId = self.userInfo.partitionId;
|
||||
ClientDataModel *configInfo = [ClientConfig shareConfig].configInfo;
|
||||
NSDictionary *publicChatRoomIdMap = configInfo.publicChatRoomIdMap;
|
||||
|
||||
if (!publicChatRoomIdMap || !partitionId) {
|
||||
NSLog(@"PublicRoomManager: 公共房间配置或分区ID缺失");
|
||||
return;
|
||||
}
|
||||
|
||||
NSNumber *roomId = publicChatRoomIdMap[partitionId];
|
||||
if (!roomId) {
|
||||
NSLog(@"PublicRoomManager: 未找到分区 %@ 对应的公共房间ID", partitionId);
|
||||
return;
|
||||
}
|
||||
|
||||
NSLog(@"PublicRoomManager: 尝试进入公共房间,分区ID: %@, 房间ID: %@", partitionId, roomId);
|
||||
|
||||
// 进入公共房间
|
||||
[self enterPublicRoomWithRoomId:roomId.stringValue completion:^(NSError * _Nullable error) {
|
||||
if (error) {
|
||||
NSLog(@"PublicRoomManager: 进入公共房间失败: %@", error);
|
||||
} else {
|
||||
NSLog(@"PublicRoomManager: 进入公共房间成功");
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)enterPublicRoomWithRoomId:(NSString *)roomId completion:(void(^)(NSError * _Nullable error))completion {
|
||||
if (!self.userInfo) {
|
||||
NSError *error = [NSError errorWithDomain:@"PublicRoomManager"
|
||||
code:-1
|
||||
userInfo:@{NSLocalizedDescriptionKey: @"用户信息缺失"}];
|
||||
if (completion) {
|
||||
completion(error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建进房请求
|
||||
NIMChatroomEnterRequest *request = [[NIMChatroomEnterRequest alloc] init];
|
||||
request.roomId = roomId;
|
||||
|
||||
// 设置扩展信息
|
||||
XPMessageRemoteExtModel *extModel = [[XPMessageRemoteExtModel alloc] init];
|
||||
extModel.defUser = self.userInfo.defUser;
|
||||
extModel.erbanNo = self.userInfo.erbanNo;
|
||||
extModel.carName = self.userInfo.carName;
|
||||
extModel.inRoomNameplatePic = self.userInfo.nameplatePic;
|
||||
extModel.inRoomNameplateWord = self.userInfo.nameplateWord;
|
||||
extModel.isCustomWord = self.userInfo.isCustomWord;
|
||||
extModel.charmUrl = self.userInfo.userLevelVo.charmUrl;
|
||||
extModel.experLevelSeq = self.userInfo.userLevelVo.experLevelSeq;
|
||||
extModel.experUrl = self.userInfo.userLevelVo.experUrl;
|
||||
extModel.newUser = self.userInfo.newUser;
|
||||
extModel.vipIcon = self.userInfo.userVipInfoVO.nameplateUrl;
|
||||
extModel.iosBubbleUrl = self.userInfo.iosBubbleUrl;
|
||||
extModel.androidBubbleUrl = self.userInfo.androidBubbleUrl;
|
||||
extModel.enterHide = self.userInfo.userVipInfoVO.enterHide;
|
||||
extModel.preventKick = self.userInfo.userVipInfoVO.preventKick;
|
||||
extModel.enterRoomEffects = self.userInfo.userVipInfoVO.enterRoomEffects;
|
||||
extModel.gender = self.userInfo.gender;
|
||||
extModel.fromSayHelloChannel = self.userInfo.fromSayHelloChannel;
|
||||
extModel.platformRole = self.userInfo.platformRole;
|
||||
extModel.nick = self.userInfo.nick;
|
||||
|
||||
NSMutableDictionary *ext = [NSMutableDictionary dictionaryWithObject:extModel.model2dictionary
|
||||
forKey:[NSString stringWithFormat:@"%ld", self.userInfo.uid]];
|
||||
request.roomExt = [ext toJSONString];
|
||||
|
||||
// 进入房间
|
||||
@kWeakify(self);
|
||||
[[NIMSDK sharedSDK].chatroomManager enterChatroom:request completion:^(NSError * _Nullable error, NIMChatroom * _Nullable chatroom, NIMChatroomMember * _Nullable me) {
|
||||
@kStrongify(self);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (error) {
|
||||
NSLog(@"PublicRoomManager: 进入公共房间失败: %@", error);
|
||||
if (completion) {
|
||||
completion(error);
|
||||
}
|
||||
} else {
|
||||
NSLog(@"PublicRoomManager: 进入公共房间成功,房间ID: %@", roomId);
|
||||
self.isInPublicRoom = YES;
|
||||
self.currentPublicRoomId = roomId;
|
||||
if (completion) {
|
||||
completion(nil);
|
||||
}
|
||||
}
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - 手动控制
|
||||
|
||||
- (void)enterPublicRoomWithCompletion:(void(^)(NSError * _Nullable error))completion {
|
||||
if (!self.isInitialized) {
|
||||
NSError *error = [NSError errorWithDomain:@"PublicRoomManager"
|
||||
code:-2
|
||||
userInfo:@{NSLocalizedDescriptionKey: @"管理器未初始化"}];
|
||||
if (completion) {
|
||||
completion(error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.isInPublicRoom) {
|
||||
NSLog(@"PublicRoomManager: 已在公共房间中");
|
||||
if (completion) {
|
||||
completion(nil);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
[self tryEnterPublicRoom];
|
||||
}
|
||||
|
||||
- (void)exitPublicRoomWithCompletion:(void(^)(NSError * _Nullable error))completion {
|
||||
if (!self.isInPublicRoom || !self.currentPublicRoomId) {
|
||||
NSLog(@"PublicRoomManager: 未在公共房间中");
|
||||
if (completion) {
|
||||
completion(nil);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@kWeakify(self);
|
||||
[[NIMSDK sharedSDK].chatroomManager exitChatroom:self.currentPublicRoomId completion:^(NSError * _Nullable error) {
|
||||
@kStrongify(self);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (error) {
|
||||
NSLog(@"PublicRoomManager: 退出公共房间失败: %@", error);
|
||||
} else {
|
||||
NSLog(@"PublicRoomManager: 退出公共房间成功");
|
||||
self.isInPublicRoom = NO;
|
||||
self.currentPublicRoomId = nil;
|
||||
}
|
||||
if (completion) {
|
||||
completion(error);
|
||||
}
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - 用户信息更新处理
|
||||
|
||||
- (void)updateUserInfo:(UserInfoModel *)userInfo {
|
||||
if (!userInfo || !userInfo.partitionId) {
|
||||
NSLog(@"PublicRoomManager: 用户信息更新失败,信息不完整");
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查用户是否切换
|
||||
if (self.currentUserId && ![self.currentUserId isEqualToString:[NSString stringWithFormat:@"%ld", userInfo.uid]]) {
|
||||
NSLog(@"PublicRoomManager: 检测到用户切换,重置管理器");
|
||||
[self reset];
|
||||
}
|
||||
|
||||
self.userInfo = userInfo;
|
||||
self.currentUserId = [NSString stringWithFormat:@"%ld", userInfo.uid];
|
||||
|
||||
// 如果已初始化但未在公共房间,尝试进入
|
||||
if (self.isInitialized && !self.isInPublicRoom) {
|
||||
[self tryEnterPublicRoom];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - 配置更新处理
|
||||
|
||||
- (void)updateConfig {
|
||||
if (!self.isInitialized) {
|
||||
NSLog(@"PublicRoomManager: 未初始化,跳过配置更新");
|
||||
return;
|
||||
}
|
||||
|
||||
ClientDataModel *configInfo = [ClientConfig shareConfig].configInfo;
|
||||
if (!configInfo || !configInfo.publicChatRoomIdMap) {
|
||||
NSLog(@"PublicRoomManager: 配置信息不完整,跳过配置更新");
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果未在公共房间,尝试进入
|
||||
if (!self.isInPublicRoom) {
|
||||
[self tryEnterPublicRoom];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - NIMChatManagerDelegate
|
||||
|
||||
- (void)onRecvMessages:(NSArray<NIMMessage *> *)messages {
|
||||
// 只处理公共房间的消息
|
||||
for (NIMMessage *message in messages) {
|
||||
if (message.session.sessionType == NIMSessionTypeChatroom) {
|
||||
NSString *sessionId = message.session.sessionId;
|
||||
if ([sessionId isEqualToString:self.currentPublicRoomId]) {
|
||||
NSLog(@"PublicRoomManager: 收到公共房间消息: %@", message.text);
|
||||
// 这里可以添加公共房间消息的处理逻辑
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
@@ -95,6 +95,7 @@
|
||||
|
||||
#import "RoomResourceManager.h"
|
||||
#import "SocialShareManager.h"
|
||||
#import "PublicRoomManager.h"
|
||||
|
||||
NSString * const kUserFirstLoginKey = @"kUserFirstLoginKey";
|
||||
NSString * const kHadLaunchApp = @"kHadLaunchApp";
|
||||
@@ -389,6 +390,10 @@ UIKIT_EXTERN NSString *kTabShowAnchorCardKey;
|
||||
[[XPSkillCardPlayerManager shareInstance] setUserInfoModel:userInfo];
|
||||
[[XPSkillCardPlayerManager shareInstance] requestBravoGiftTabInfomation];
|
||||
[[RoomBoomManager sharedManager] saveUserInfo:userInfo];
|
||||
|
||||
// 更新公共房间管理器的用户信息
|
||||
[[PublicRoomManager sharedManager] updateUserInfo:userInfo];
|
||||
|
||||
[self getRoomGameInfo];
|
||||
[AccountInfoStorage instance].name = self.userInfo.nick;
|
||||
|
||||
|
Reference in New Issue
Block a user