361 lines
14 KiB
Objective-C
361 lines
14 KiB
Objective-C
//
|
||
// YMRoomSettingPresenter.m
|
||
// YUMI
|
||
//
|
||
// Created by YUMI on 2021/12/27.
|
||
//
|
||
|
||
#import "XPRoomSettingPresenter.h"
|
||
#import <NIMSDK/NIMSDK.h>
|
||
///Tool
|
||
#import "AccountInfoStorage.h"
|
||
#import "Api+RoomSetting.h"
|
||
#import "DESEncrypt.h"
|
||
#import "YUMIConstant.h"
|
||
#import "ClientConfig.h"
|
||
///Model
|
||
#import "RoomInfoModel.h"
|
||
///P
|
||
#import "XPRoomSettingProtocol.h"
|
||
#import "XPMessageRemoteExtModel.h"
|
||
@implementation XPRoomSettingPresenter
|
||
|
||
- (void)getRoomSettingList:(RoomInfoModel *)roomInfo isSuperAdmin:(BOOL)isSuperAdmin {
|
||
XPRoomSettingItemModel * titleItem = [[XPRoomSettingItemModel alloc] init];
|
||
titleItem.title = YMLocalizedString(@"XPRoomSettingPresenter0");
|
||
titleItem.subTitle = roomInfo.title;
|
||
titleItem.type = RoomSettingItemType_Title;
|
||
|
||
XPRoomSettingItemModel * lockItem = [[XPRoomSettingItemModel alloc] init];
|
||
lockItem.title = YMLocalizedString(@"XPRoomSettingPresenter1");
|
||
lockItem.switchState = roomInfo.roomPwd.length > 0;
|
||
lockItem.type = RoomSettingItemType_Lock;
|
||
|
||
XPRoomSettingItemModel * pwdItem;
|
||
if (roomInfo.roomPwd.length > 0) {
|
||
pwdItem = [[XPRoomSettingItemModel alloc] init];
|
||
NSString * roomPwd = [DESEncrypt decryptUseDES:roomInfo.roomPwd key:KeyWithType(KeyType_PasswordEncode)];
|
||
pwdItem.title = roomPwd;
|
||
pwdItem.type = RoomSettingItemType_Pwd;
|
||
}
|
||
|
||
XPRoomSettingItemModel *classItem = [[XPRoomSettingItemModel alloc] init];
|
||
classItem.title = YMLocalizedString(@"XPRoomSettingPresenter2");
|
||
classItem.subTitle = roomInfo.sortName;
|
||
classItem.type = RoomSettingItemType_Class;
|
||
|
||
XPRoomSettingItemModel *avatarItem = [[XPRoomSettingItemModel alloc] init];
|
||
avatarItem.title = YMLocalizedString(@"RoomSetting_1.0.17_0");
|
||
avatarItem.avatar = roomInfo.avatar;
|
||
avatarItem.type = RoomSettingItemType_Avatar;
|
||
|
||
XPRoomSettingItemModel *tagItem = [[XPRoomSettingItemModel alloc] init];
|
||
tagItem.title = YMLocalizedString(@"XPRoomSettingPresenter3");
|
||
tagItem.subTitle = roomInfo.roomTag;
|
||
tagItem.type = RoomSettingItemType_Tag;
|
||
|
||
XPRoomSettingItemModel * managerItem = [[XPRoomSettingItemModel alloc] init];
|
||
managerItem.title = YMLocalizedString(@"XPRoomSettingPresenter4");
|
||
managerItem.type = RoomSettingItemType_Manager_List;
|
||
|
||
XPRoomSettingItemModel * blackItem = [[XPRoomSettingItemModel alloc] init];
|
||
blackItem.title = YMLocalizedString(@"XPRoomSettingPresenter5");
|
||
blackItem.type = RoomSettingItemType_Black_List;
|
||
|
||
XPRoomSettingItemModel * giftEffectItem = [[XPRoomSettingItemModel alloc] init];
|
||
giftEffectItem.title = YMLocalizedString(@"XPRoomSettingPresenter6");
|
||
giftEffectItem.switchState = roomInfo.hasAnimationEffect;
|
||
giftEffectItem.type = RoomSettingItemType_Gift_Effect;
|
||
|
||
XPRoomSettingItemModel * messageScreedItem = [[XPRoomSettingItemModel alloc] init];
|
||
messageScreedItem.title = YMLocalizedString(@"XPRoomSettingPresenter7");
|
||
messageScreedItem.switchState = !roomInfo.isCloseScreen;
|
||
messageScreedItem.type = RoomSettingItemType_Message_Screen;
|
||
|
||
XPRoomSettingItemModel * arrangeMicItem = [[XPRoomSettingItemModel alloc] init];
|
||
arrangeMicItem.title = YMLocalizedString(@"XPRoomSettingPresenter8");
|
||
arrangeMicItem.switchState = roomInfo.roomModeType == RoomModeType_Open_Micro_Mode;
|
||
arrangeMicItem.type = RoomSettingItemType_Arrange_Mic;
|
||
|
||
XPRoomSettingItemModel * leaveItem = [[XPRoomSettingItemModel alloc] init];
|
||
leaveItem.title = YMLocalizedString(@"XPRoomSettingPresenter9");
|
||
leaveItem.switchState = roomInfo.leaveMode;
|
||
leaveItem.type = RoomSettingItemType_Leave_Model;
|
||
|
||
XPRoomSettingItemModel * giftValueItem = [[XPRoomSettingItemModel alloc] init];
|
||
giftValueItem.title = roomInfo.showGiftValue ? YMLocalizedString(@"XPMoreMenuPresenter27") : YMLocalizedString(@"XPMoreMenuPresenter3");
|
||
giftValueItem.switchState = roomInfo.showGiftValue;
|
||
giftValueItem.type = RoomSettingItemType_Gift_Value_Model;
|
||
|
||
NSString * roomId = [NSString stringWithFormat:@"%ld", roomInfo.roomId];
|
||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||
///获取房间角色
|
||
NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
|
||
request.roomId = roomId;
|
||
request.userIds = @[uid];
|
||
@kWeakify(self);
|
||
[[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
|
||
@kStrongify(self);
|
||
NSArray * array;
|
||
if (error == nil) {
|
||
NIMChatroomMember *member = members.firstObject;
|
||
|
||
// 是否是创建者或超级管理员
|
||
BOOL isCreatorOrSuperAdmin = (member.type == NIMChatroomMemberTypeCreator || isSuperAdmin);
|
||
BOOL isManagerOrAbove = (member.type == NIMChatroomMemberTypeManager || isCreatorOrSuperAdmin);
|
||
|
||
// 是否设置了房间密码
|
||
BOOL hasRoomPwd = (roomInfo.roomPwd.length > 0);
|
||
|
||
// 构建基础数组
|
||
NSMutableArray *firstSection = [@[titleItem, lockItem] mutableCopy];
|
||
if (hasRoomPwd) {
|
||
[firstSection addObject:pwdItem];
|
||
}
|
||
|
||
NSMutableArray *secondSection = [@[tagItem] mutableCopy];
|
||
NSMutableArray *thirdSection = [@[blackItem, giftEffectItem, messageScreedItem] mutableCopy];
|
||
|
||
// 添加创建者和超级管理员特有的选项
|
||
if (isCreatorOrSuperAdmin) {
|
||
[secondSection insertObject:avatarItem atIndex:0];
|
||
[thirdSection insertObject:managerItem atIndex:0];
|
||
}
|
||
|
||
// 添加根据房间类型和身份的特定选项
|
||
if (roomInfo.type == RoomType_Anchor) {
|
||
// 主播房间(直播间)
|
||
array = @[firstSection, secondSection, thirdSection];
|
||
} else {
|
||
// 其他类型房间
|
||
if (member.type == NIMChatroomMemberTypeCreator) {
|
||
[thirdSection addObjectsFromArray:@[arrangeMicItem, leaveItem]];
|
||
} else if (isManagerOrAbove) {
|
||
[thirdSection addObject:arrangeMicItem];
|
||
}
|
||
array = @[firstSection, secondSection, thirdSection];
|
||
}
|
||
|
||
// 若为迷你游戏房间则直接使用前述设置的 `array`
|
||
if (roomInfo.type == RoomType_MiniGame) {
|
||
array = @[firstSection, secondSection, thirdSection];
|
||
}
|
||
|
||
// 将构建后的数组存入 list,并加入礼物特效项
|
||
NSMutableArray *list = [array mutableCopy];
|
||
if (isManagerOrAbove) {
|
||
NSMutableArray *thirdSubList = [list[2] mutableCopy];
|
||
[thirdSubList addObject:giftValueItem];
|
||
list[2] = thirdSubList;
|
||
}
|
||
|
||
// 返回数据
|
||
[[self getView] getRoomSettingListSuccess:list];
|
||
}
|
||
}];
|
||
}
|
||
|
||
/// 获取房间信息
|
||
/// @param roomUid 房主的uid
|
||
- (void)getRoomInfo:(NSString *)roomUid {
|
||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||
@kWeakify(self);
|
||
[Api getRoomInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||
@kStrongify(self);
|
||
RoomInfoModel * roomInfo = [RoomInfoModel modelWithDictionary:data.data];
|
||
[[self getView] getRoomInfoSuccess:roomInfo];
|
||
} showLoading:YES] uid:roomUid intoUid:uid];
|
||
}
|
||
/// 开启排麦
|
||
/// @param roomUid 房主的uid
|
||
- (void)openRoomArrangeMic:(NSString *)roomUid {
|
||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||
@kWeakify(self);
|
||
[Api openRoomArrangeMic:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||
@kStrongify(self);
|
||
[[self getView] openRoomArrangeMicSuccess];
|
||
} showLoading:YES] roomUid:roomUid operUid:uid];
|
||
}
|
||
|
||
/// 关闭排麦
|
||
/// @param roomUid 房主的uid
|
||
- (void)closeRoomArrangeMic:(NSString *)roomUid {
|
||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||
@kWeakify(self);
|
||
[Api closeRoomArrangeMic:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||
@kStrongify(self);
|
||
[[self getView] closeRoomArrangeMicSuccess];
|
||
} showLoading:YES] roomUid:roomUid operUid:uid];
|
||
}
|
||
|
||
/// 开启离开模式
|
||
/// @param roomUid 房主的uid
|
||
- (void)openRoomLeaveMode:(NSString *)roomUid {
|
||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||
@kWeakify(self);
|
||
[Api openRoomLeaveMode:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||
@kStrongify(self);
|
||
[[self getView] openRoomArrangeMicSuccess];
|
||
} showLoading:YES] roomUid:roomUid uid:uid];
|
||
}
|
||
|
||
/// 关闭离开模式
|
||
/// @param roomUid 房主的uid
|
||
- (void)closeRoomLeaveMode:(NSString *)roomUid {
|
||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||
@kWeakify(self);
|
||
[Api closeRoomLeaveMode:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||
@kStrongify(self);
|
||
[[self getView] closeRoomArrangeMicSuccess];
|
||
} showLoading:YES] roomUid:roomUid uid:uid];
|
||
}
|
||
|
||
/// 更新公屏状态
|
||
/// @param isCloseScreen 是否关闭公屏
|
||
/// @param roomId 房间的id
|
||
- (void)updateRoomMessageScreenState:(BOOL)isCloseScreen roomId:(NSString *)roomId {
|
||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||
NSString * ticket = [AccountInfoStorage instance].getTicket;
|
||
NSString * isCleScreenStr = isCloseScreen ? @"1" : @"0";
|
||
@kWeakify(self);
|
||
[Api updateRoomInfoMessageState:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||
@kStrongify(self);
|
||
RoomInfoModel * roomInfo = [RoomInfoModel modelWithDictionary:data.data];
|
||
[[self getView] updateRoomMessageScreenStateSuccess:roomInfo];
|
||
} showLoading:YES] roomId:roomId isCloseScreen:isCleScreenStr ticket:ticket uid:uid];
|
||
}
|
||
|
||
|
||
/// 更新房间信息
|
||
/// @param title 房间标题
|
||
/// @param roomPwd 房间密码
|
||
/// @param tagId 房间tag
|
||
/// @param hasAnimationEffect 是否开启房间特效
|
||
/// @param roomUid 房间uid
|
||
/// @param roomId 群聊的id
|
||
/// @param mgId 小游戏的id
|
||
- (void)updateRoomInfo:(NSString *)title
|
||
roomPwd:(NSString *)roomPwd
|
||
tagId:(NSString *)tagId
|
||
classifyId:(NSString *)classifyId
|
||
hasAnimationEffect:(BOOL)hasAnimationEffect
|
||
roomUid:(NSString *)roomUid
|
||
roomId:(NSString *)roomId
|
||
type:(RoomType)type
|
||
itemType:(RoomSettingItemType)itemType
|
||
mgId:(NSString *)mgId
|
||
backPic:(NSString *)backPic
|
||
avatar:(nonnull NSString *)avatar {
|
||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||
NSString * ticket = [AccountInfoStorage instance].getTicket;
|
||
NSMutableDictionary * params = [NSMutableDictionary dictionary];
|
||
[params setObject:ticket forKey:@"ticket"];
|
||
[params setObject:uid forKey:@"uid"];
|
||
[params setObject:roomUid forKey:@"roomUid"];
|
||
if (title.length > 0) {
|
||
[params setObject:title forKey:@"title"];
|
||
}
|
||
if(backPic.length > 0){
|
||
[params setObject:backPic forKey:@"backPic"];
|
||
}
|
||
if (roomPwd.length > 0) {
|
||
[params setObject:roomPwd forKey:@"roomPwd"];
|
||
} else{
|
||
[params setObject:@"" forKey:@"roomPwd"];
|
||
}
|
||
|
||
if (tagId.length > 0) {
|
||
[params setObject:tagId forKey:@"tagId"];
|
||
}
|
||
if (classifyId.length > 0) {
|
||
[params setObject:classifyId forKey:@"singleRoomSortId"];
|
||
}
|
||
[params setObject:@(type) forKey:@"type"];
|
||
|
||
[params setObject:@(hasAnimationEffect) forKey:@"hasAnimationEffect"];
|
||
|
||
if (mgId.length > 0) {
|
||
[params setObject:mgId forKey:@"mgId"];
|
||
}
|
||
|
||
if (avatar.length > 0) {
|
||
[params setObject:avatar forKey:@"avatar"];
|
||
}
|
||
|
||
///获取房间角色
|
||
NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
|
||
request.roomId = roomId;
|
||
request.userIds = @[uid];
|
||
@kWeakify(self);
|
||
[[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
|
||
@kStrongify(self);
|
||
if (error == nil) {
|
||
NIMChatroomMember * member = members.firstObject;
|
||
if (member.type == NIMTeamMemberTypeOwner) {
|
||
@kWeakify(self);
|
||
[Api ownerUpdateRoomInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||
@kStrongify(self);
|
||
RoomInfoModel * roomInfo = [RoomInfoModel modelWithJSON:data.data];
|
||
[[self getView] updateRoomInfoSuccess:roomInfo itemType:itemType];
|
||
}fail:^(NSInteger code, NSString * _Nullable msg) {
|
||
@kStrongify(self);
|
||
[[self getView] updateRoomInfoFail:msg];
|
||
} showLoading:YES] params:params];
|
||
} else if(member.type == NIMTeamMemberTypeManager) {
|
||
@kWeakify(self);
|
||
[Api managerUpdateRoomInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||
@kStrongify(self);
|
||
RoomInfoModel * roomInfo = [RoomInfoModel modelWithJSON:data.data];
|
||
[[self getView] updateRoomInfoSuccess:roomInfo itemType:itemType];
|
||
}fail:^(NSInteger code, NSString * _Nullable msg) {
|
||
@kStrongify(self);
|
||
[[self getView] updateRoomInfoFail:msg];
|
||
} showLoading:YES] params:params];
|
||
}
|
||
} else {
|
||
[[self getView] updateRoomInfoFail:YMLocalizedString(@"XPRoomSettingPresenter10")];
|
||
}
|
||
}];
|
||
|
||
}
|
||
/// 获取房间在线用户
|
||
/// @param roomUid roomUid
|
||
-(void)getRoomOnlineUserListWithRoomUid:(NSString *)roomUid{
|
||
@kWeakify(self);
|
||
[Api requestRoomOnlineUserList:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||
@kStrongify(self);
|
||
NSArray *list = [XPMessageRemoteExtModel modelsWithArray:data.data];
|
||
[[self getView]getRoomOnlineUserListSuccess:list];
|
||
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
||
|
||
}] roomUid:roomUid];
|
||
}
|
||
/// 关闭房间礼物值
|
||
/// @param roomUid 房间的uid
|
||
- (void)closeRoomGiftValue:(NSString *)roomUid itemModel:(XPRoomSettingItemModel *)itemModel{
|
||
@kWeakify(self);
|
||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||
[Api closeRoomGiftValue:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||
@kStrongify(self);
|
||
[[self getView] closeRoomGiftValueSuccessWithItemModel:itemModel];
|
||
}fail:^(NSInteger code, NSString * _Nullable msg) {
|
||
@kStrongify(self);
|
||
[[self getView] closeRoomGiftValueFailWithItemModel:itemModel];
|
||
}] uid:uid roomUid:roomUid];
|
||
}
|
||
/// 开启房间礼物值
|
||
/// @param roomUid 房间的uid
|
||
- (void)openRoomGiftValue:(NSString *)roomUid itemModel:(XPRoomSettingItemModel *)itemModel{
|
||
@kWeakify(self);
|
||
NSString * uid = [AccountInfoStorage instance].getUid;
|
||
[Api openRoomGiftValue:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
||
@kStrongify(self);
|
||
[[self getView] openRoomGiftValueSuccessWithItemModel:itemModel];
|
||
}fail:^(NSInteger code, NSString * _Nullable msg) {
|
||
@kStrongify(self);
|
||
[[self getView] openRoomGiftValueFailWithItemModel:itemModel];
|
||
}] uid:uid roomUid:roomUid];
|
||
}
|
||
|
||
@end
|