// // YMRoomPresenter.m // YUMI // // Created by YUMI on 2021/10/18. // #import "XPRoomPresenter.h" #import "ClientConfig.h" ///API #import "Api+Room.h" #import "Api+Gift.h" #import "UserInfoModel.h" #import "GuildSuperAdminInfoModel.h" ///Tool #import "AccountInfoStorage.h" #import "XPGiftStorage.h" #import "NSObject+MJExtension.h" ///Model #import "GiftInfoModel.h" #import "XPMessageRemoteExtModel.h" #import "RoomNewUserGreetModel.h" #import "XPRoomRecommendModel.h" #import "XPRedPacketModel.h" #import "FirstChargeRoomWindowModel.h" #import "XPFreeGiftModel.h" ///P #import "XPRoomProtocol.h" #import #import @interface XPRoomPresenter () @end @implementation XPRoomPresenter - (void)initEnterRoom:(NSString *)roomUid user:(NSString *)uid { RACSubject* room = [RACSubject subject]; RACSubject* user = [RACSubject subject]; @kWeakify(self); [[RACSignal combineLatest:@[room, user] reduce:^id(RoomInfoModel* room, UserInfoModel* user){ @kStrongify(self); [[self getView] initEnterRoomSuccess:room user:user]; return nil; }] subscribeError:^(NSError * _Nullable error) { @kStrongify(self); [[self getView] enterRoomFail:error.code]; }]; [Api getUserInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) { @kStrongify(self); UserInfoModel * infoModel = [UserInfoModel modelWithJSON:data.data]; self.infoModel = infoModel; [user sendNext:infoModel]; [user sendCompleted]; } fail:^(NSInteger code, NSString * _Nullable msg) { [user sendError:nil]; } showLoading:YES errorToast:NO] uid:uid]; [Api getRoomInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) { RoomInfoModel *model = [RoomInfoModel modelWithJSON:data.data]; [room sendNext:model]; [room sendCompleted]; } fail:^(NSInteger code, NSString * _Nullable msg) { [room sendError:nil]; } showLoading:YES errorToast:YES] uid:roomUid intoUid:uid]; } - (void)enterNIMRoom:(NSString *)roomId user:(UserInfoModel *)userInfo { NIMChatroomEnterRequest *request = [[NIMChatroomEnterRequest alloc] init]; request.roomId = roomId; //设置ext XPMessageRemoteExtModel * extModel = [[XPMessageRemoteExtModel alloc] init]; extModel.defUser = userInfo.defUser; extModel.erbanNo = userInfo.erbanNo; extModel.carName = userInfo.carName; extModel.inRoomNameplatePic = userInfo.nameplatePic; extModel.inRoomNameplateWord = userInfo.nameplateWord; extModel.isCustomWord = userInfo.isCustomWord; extModel.charmUrl = userInfo.userLevelVo.charmUrl; extModel.experLevelSeq = userInfo.userLevelVo.experLevelSeq; extModel.experUrl = userInfo.userLevelVo.experUrl; extModel.newUser = userInfo.newUser; extModel.vipIcon = userInfo.userVipInfoVO.vipIcon; extModel.fromUid = userInfo.fromUid; extModel.fromType = userInfo.fromType; extModel.fromNick = userInfo.fromNick; extModel.iosBubbleUrl = userInfo.iosBubbleUrl; extModel.androidBubbleUrl = userInfo.androidBubbleUrl; extModel.enterHide = userInfo.userVipInfoVO.enterHide; extModel.preventKick = userInfo.userVipInfoVO.preventKick; extModel.enterRoomEffects = userInfo.userVipInfoVO.enterRoomEffects; extModel.gender = userInfo.gender; extModel.fromSayHelloChannel = userInfo.fromSayHelloChannel; extModel.platformRole = userInfo.platformRole; NSMutableDictionary *ext = [NSMutableDictionary dictionaryWithObject:extModel.model2dictionary forKey:[NSString stringWithFormat:@"%ld", 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); if (error) { [[self getView] enterRoomFail:error.code]; } else { [[self getView] enterRoomSuccess:chatroom]; } }]; NSString *publicChatRoomId = [NSString stringWithFormat:@"%@",[ClientConfig shareConfig].configInfo.publicChatRoomIdMap[userInfo.partitionId]]; NIMChatroomEnterRequest *publicChatRoomRequest = [[NIMChatroomEnterRequest alloc] init]; publicChatRoomRequest.roomId = publicChatRoomId; NSMutableDictionary *publicChatRoomExt = [NSMutableDictionary dictionaryWithObject:extModel.model2dictionary forKey:publicChatRoomId]; publicChatRoomRequest.roomExt = [publicChatRoomExt toJSONString]; [[NIMSDK sharedSDK].chatroomManager enterChatroom:publicChatRoomRequest completion:^(NSError * _Nullable error, NIMChatroom * _Nullable chatroom, NIMChatroomMember * _Nullable me) { // NSLog(@"111"); }]; } - (void)exitNIMRoom:(NSString *)roomId { [[NIMSDK sharedSDK].chatroomManager exitChatroom:roomId completion:nil]; NSString *publicChatRoomId = [NSString stringWithFormat:@"%@",[ClientConfig shareConfig].configInfo.publicChatRoomIdMap[self.infoModel.partitionId]]; [[NIMSDK sharedSDK].chatroomManager exitChatroom:publicChatRoomId completion:nil]; } /// 开启用户自己的房间 /// @param title 房间标题 /// @param type 房间类型 /// @param roomPwd 房间密码 /// @param roomDesc 房间介绍 /// @param backPic 房间背景 /// @param mgId 小游戏的id - (void)openRoom:(NSString *)title type:(RoomType)type roomPwd:(NSString *)roomPwd roomDesc:(NSString *)roomDesc backPic:(NSString *)backPic mgId:(NSString *)mgId{ NSString * uid = [AccountInfoStorage instance].getUid; NSString * ticket = [AccountInfoStorage instance].getTicket; if (title.length <= 0) { title = @""; } if (roomPwd.length <= 0) { roomPwd = @""; } if (roomDesc.length <= 0) { roomDesc = @""; } if (backPic.length <= 0) { backPic = @""; } if (mgId.length <= 0) { mgId = @"0"; } @kWeakify(self); [Api openRoom:[self createHttpCompletion:^(BaseModel * _Nonnull data) { @kStrongify(self); RoomInfoModel * infoModel = [RoomInfoModel modelWithJSON:data.data]; [[self getView] openRoomSuccess:infoModel]; } fail:^(NSInteger code, NSString * _Nullable msg) { @kStrongify(self); [[self getView] enterRoomFail:code]; } showLoading:NO] title:title type:type roomPwd:roomPwd roomDesc:roomDesc backPic:backPic uid:uid ticket:ticket mgId:mgId]; } ///福袋礼物爆出的礼物的bug ///进入房间的时候需要获取一次礼物信息 因为如果有人送礼物的话 如果是福袋礼物的话 爆出的礼物需要从礼物列表中获取 会导致公屏不显示那个礼物 /// 获取普通的礼物 /// @param roomUid 房主的uid 获取房间专属礼物 - (void)getNormalGiftList:(NSString *)roomUid { [[XPGiftStorage shareStorage] updateRoomUID:roomUid]; [Api requestAllTagsAndNormalGifts:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { if (code == 200 && data.data) { [[XPGiftStorage shareStorage] cacheTagsWith:data.data inRoom:roomUid]; } } roomUid:roomUid]; } /// 上报用户进房 /// @param roomUid 房间uid - (void)reportUserInterRoom:(NSString *)roomUid { if ([[AccountInfoStorage instance] getTicket].length < 1) { return; } [Api requestReportUserInterRoom:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { } uid:[[AccountInfoStorage instance] getUid] roomUid:roomUid ticket:[[AccountInfoStorage instance] getTicket]]; } /// 上报用户退房 /// @param roomUid 房间uid - (void)reportUserOutRoom:(NSString *)roomUid { if ([[AccountInfoStorage instance] getTicket].length < 1) { return; } [Api requestReportUserOutRoom:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { } uid:[[AccountInfoStorage instance] getUid] roomUid:roomUid ticket:[[AccountInfoStorage instance] getTicket]]; } /// 获取房间超管列表 /// @param roomUid 房间的uid - (void)getRoomSuperAdmin:(NSString *)roomUid { @kWeakify(self); [Api getRoomSuperAdminList:[self createHttpCompletion:^(BaseModel * _Nonnull data) { @kStrongify(self); NSArray * array = [GuildSuperAdminInfoModel modelsWithArray:data.data]; [[self getView] getRoomSuperAdminSuccess:array]; }] roomUid:roomUid]; } ///获取循环的推荐房间 /// @param roomUid 房间的uid - (void)getCycleAnchorRoomList:(NSString *)roomUid { @kWeakify(self); [Api requestNextAnchorRoom:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { @kStrongify(self); if (code == 200) { RoomInfoModel * infoModel = [RoomInfoModel modelWithJSON:data.data]; [[self getView] getNextAnchorRoomSuccess:infoModel]; } else { [[self getView] getNextAnchorRoomSuccess:nil]; } } roomUid:roomUid]; } - (void)getCurrentRoomInfo:(NSString *)roomUid { @kWeakify(self); NSString * uid= [AccountInfoStorage instance].getUid; [Api getRoomInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) { @kStrongify(self); RoomInfoModel * roomInfo = [RoomInfoModel modelWithDictionary:data.data]; [[self getView] getCurrentRoomInfoSuccess:roomInfo]; } fail:^(NSInteger code, NSString * _Nullable msg) { @kStrongify(self); [[self getView] getCurrentRoomInfoSuccess:nil]; }] uid:roomUid intoUid:uid]; } ///获取房间红包 - (void)getRedPacket:(NSString *)roomUid { @kWeakify(self); [Api requestRedPacket:[self createHttpCompletion:^(BaseModel * _Nonnull data) { @kStrongify(self); NSArray *array = [XPRedPacketModel modelsWithArray:data.data]; for (XPRedPacketModel *model in array) { model.timestamp = data.timestamp; } [[self getView] getRedPacketSuccess:array]; }] uid:roomUid isShowKind:@"1"]; } ///获取单个红包信息 -(void)getRedPacketInft:(NSString *)redEnvelopeId{ @kWeakify(self); [Api getRedPacket:[self createHttpCompletion:^(BaseModel * _Nonnull data) { @kStrongify(self); XPRedPacketModel *redModel = [XPRedPacketModel modelWithJSON:data.data]; redModel.timestamp = data.timestamp; redModel.sendUserNick = data.data[@"nick"]; redModel.sendUserAvatar = data.data[@"avatar"]; redModel.redEnvelopePosition = data.data[@"position"]; [[self getView]getRedPacketInfoSuccess:redModel]; }] redEnvelopeId:redEnvelopeId]; } -(void)getRoomFirstCharegWindow:(NSString *)roomUid{ @kWeakify(self); [Api requestRoomFirstCharegWindow:[self createHttpCompletion:^(BaseModel * _Nonnull data) { @kStrongify(self); FirstChargeRoomWindowModel *freeModel = [FirstChargeRoomWindowModel modelWithDictionary:data.data]; [[self getView]getRoomFirstChargeWindowSuccess:freeModel]; }showLoading:NO errorToast:NO] roomUid:roomUid]; } -(void)updateRoomFirstChargeWindow:(NSString *)roomUid{ [Api updateRoomFirstCharegWindow:[self createHttpCompletion:^(BaseModel * _Nonnull data) { }showLoading:NO errorToast:NO] roomUid:roomUid]; } - (void)requestShieldingWithType:(NSString *)type objId:(NSString *)objId{ @kWeakify(self); [Api requestShielding:[self createHttpCompletion:^(BaseModel * _Nonnull data) { @kStrongify(self); [[self getView] requestShieldingSuccess]; }] type:type objId:objId]; } -(void)getFreeGiftData{ @kWeakify(self); [Api requestFreeGiftData:[self createHttpCompletion:^(BaseModel * _Nonnull data) { @kStrongify(self); XPFreeGiftModel *freeModel = [XPFreeGiftModel modelWithDictionary:data.data]; [[self getView] getFreeGiftDataSuccess:freeModel]; }]]; } /// 获取已解锁照片id列表 /// @param roomUid 房间id -(void)getUnlockRoomAlbumPhotoListWithRoomUid:(NSString *)roomUid{ @kWeakify(self); [Api getUnlockRoomAlbumPhotoList:[self createHttpCompletion:^(BaseModel * _Nonnull data) { @kStrongify(self); [[self getView]getUnlockRoomAlbumPhotoListSuccessWithList:data.data]; } showLoading:NO errorToast:NO] roomUid:roomUid]; } ///得到踢人名单 /// @param roomUid 房间id -(void)getKickUserListWithRoomUid:(NSString *)roomUid{ @kWeakify(self); [Api getKickUserList:[self createHttpCompletion:^(BaseModel * _Nonnull data) { @kStrongify(self); [[self getView]getKickUserListSuccessWithList:data.data]; } fail:^(NSInteger code, NSString * _Nullable msg) { } showLoading:NO errorToast:NO] roomUid:roomUid]; } @end