Files
peko-ios/YuMi/Modules/YMRoom/View/MoreView/Presenter/XPMoreMenuPresenter.m

164 lines
5.9 KiB
Objective-C

//
// YMMoreMenuPresenter.m
// YUMI
//
// Created by YUMI on 2021/12/11.
//
#import "XPMoreMenuPresenter.h"
#import <NIMSDK/NIMSDK.h>
#import "Api+MoreMenu.h"
#import "ThemeColor+Room.h"
#import "AccountInfoStorage.h"
#import "ClientConfig.h"
#import "RtcManager.h"
#import "Api+AnchorPk.h"
///Model
#import "XPRoomMoreItemModel.h"
#import "RoomInfoModel.h"
#import "XPReleaseRadioModel.h"
#import "XPNobleTrumpetModel.h"
#import "XPRoomMoreMenuAction.h"
#import "XPRoomMoreMenuActionContext.h"
#import "XPRoomMoreMenuActionFactory.h"
///P
#import "XPMoreMenuProtocol.h"
#import "DJDKMIMOMColor.h"
@implementation XPMoreMenuPresenter
- (void)loadNIMMemberData:(void(^)(NSArray<NIMChatroomMember *> * _Nullable members))finish withRoomInfo:(RoomInfoModel *)roomInfo{
if (!finish) {
return;
}
NSString * uid = [AccountInfoStorage instance].getUid;
if (uid.length <= 0) {
finish(nil);
return;
}
NSString * roomId = [NSString stringWithFormat:@"%ld", roomInfo.roomId];
NIMChatroomMembersByIdsRequest *request = [[NIMChatroomMembersByIdsRequest alloc]init];
request.roomId = roomId;
request.userIds = @[uid];
[[NIMSDK sharedSDK].chatroomManager fetchChatroomMembersByIds:request completion:^(NSError * _Nullable error, NSArray<NIMChatroomMember *> * _Nullable members) {
if (members) {
finish(members);
} else {
finish(nil);
}
}];
}
- (void)getMoreMenuDataSourceWithNewArchitecture:(RoomInfoModel *)roomInfo
isSuperAdmin:(BOOL)isSuperAdmin
isOnMic:(BOOL)isOnMic
isAppSuperAdmin:(BOOL)isAppSuperAdmin {
// 创建上下文
XPRoomMoreMenuActionContext *context = [XPRoomMoreMenuActionContext
contextWithRoomInfo:roomInfo
userInfo:nil
hostDelegate:nil
presentingViewController:nil
isOnMic:isOnMic
isSuperAdmin:isSuperAdmin
isAppSuperAdmin:isAppSuperAdmin];
if (isAppSuperAdmin) {
// 超管使用固定组合
NSArray<XPRoomMoreMenuAction *> *actions = [XPRoomMoreMenuActionFactory createSuperAdminActionsWithContext:context];
[self convertActionsToModels:actions];
} else {
// 普通用户根据权限创建
@kWeakify(self);
[self loadNIMMemberData:^(NSArray<NIMChatroomMember *> * _Nullable members) {
@kStrongify(self);
BOOL isCreator = NO;
BOOL isManager = NO;
if (members && members.count > 0) {
NIMChatroomMember *member = members.firstObject;
isCreator = member.type == NIMChatroomMemberTypeCreator;
isManager = member.type == NIMChatroomMemberTypeManager;
}
NSArray<XPRoomMoreMenuAction *> *actions = [XPRoomMoreMenuActionFactory
createPanelActionsWithContext:context
isCreator:isCreator
isManager:isManager
isSuperAdmin:isSuperAdmin
isOnMic:isOnMic];
[self convertActionsToModels:actions];
} withRoomInfo:roomInfo];
}
}
// 将 Action 转换为数据模型
- (void)convertActionsToModels:(NSArray<XPRoomMoreMenuAction *> *)actions {
NSMutableArray *models = [NSMutableArray array];
for (XPRoomMoreMenuAction *action in actions) {
[models addObject:[action toItemModel]];
}
[[self getView] getMoreMenuDataSuccess:models];
}
/// 开启相亲模式
/// @param roomUid 房主的uid
- (void)openRoomDating:(NSString *)roomUid {
[Api openRoomDating:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
[[self getView] openRoomDatingSuccess];
}] roomUid:roomUid];
}
/// 关闭相亲模式
/// @param roomUid 房主的uid
- (void)closeRoomDating:(NSString *)roomUid {
[Api closeRoomDating:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
[[self getView] closeRoomDatingSuccess];
}] roomUid:roomUid];
}
///获取房间广播模板内容
/// @param type 房间类型
- (void)getRoomRadioMessageListWithType:(NSString *)type {
[Api roomRadioGetMsg:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
XPReleaseRadioModel * model = [XPReleaseRadioModel modelWithJSON:data.data];
[[self getView] getReleaseRadioSuccess:model];
}] roomType:type];
}
/// 获取房间VIP小喇叭信息
- (void)getRoomgetUserVipRoomTrumpet:(NSString *)roomUid {
[Api getUserVipRoomTrumpet:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
XPNobleTrumpetModel *model = [XPNobleTrumpetModel modelWithJSON:data.data];
[[self getView] getTrumpetSuccess:model];
}] roomUid:roomUid];
}
///结束个播跨房PK
- (void)requestFinishAnchorPK:(NSString *)roundId {
[Api requestEndAnchorRoomPk:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
[[self getView] endAnchorPkSuccess:code == 200 msg:msg];
} roundId:roundId];
}
/// 清空公屏
/// @param roomUid 房主的uid
/// @param uid 操作人的uid
- (void)cleanScreen:(NSString *)roomUid uid:(NSString *)uid {
[Api requestCleanScreen:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
[[self getView] cleanScreenSuccess];
}] roomUid:roomUid uid:uid];
}
/// 取消匹配随机PK
/// @param roomUid 房间UID
- (void)requestCancelMatchRandomPK:(NSString *)roomUid {
[Api cancelMatchRandomPK:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
[[self getView] cancelMatchRandomPKSuccess];
}] roomUid:roomUid];
}
@end