Files
yinmeng-ios-store/yinmeng-ios/yinmeng-ios/Main/YinMeng/Room/Presenter/MewRoomPresenter.m

181 lines
6.3 KiB
Objective-C

//
// MewRoomPresenter.m
// mew-ios
//
// Created by 触海 on 2023/11/7.
//
#import "MewRoomPresenter.h"
///Api
#import "Api+Room.h"
#import "Api+Gift.h"
///Model
#import "UserInfoModel.h"
#import "MewRoomInfoModel.h"
#import "AccountInfoStorage.h"
#import "MewMessageRemoteExtModel.h"
#import "MewGiftReceiveInfoModel.h"
///P
#import "MewRoomProtocol.h"
///Third
#import <ReactiveObjC/ReactiveObjC.h>
#import <NIMSDK/NIMSDK.h>
@implementation MewRoomPresenter
#pragma mark - Public Method
- (void)mew_initEnterCurrentRoom:(NSString *)roomUid user:(NSString *)uid {
RACSubject *room = [RACSubject subject];
RACSubject *user = [RACSubject subject];
/// RAC监听用户和房间值的改变
[[RACSignal combineLatest:@[room, user] reduce:^id(MewRoomInfoModel *room, UserInfoModel *user){
[[self getView] mew_initEnterCurrentRoomSuccess:room user:user];
return nil;
}] subscribeError:^(NSError * _Nullable error) {
[[self getView] enterCurrentRoomFail:error.code];
}];
/// 获取用户信息
[Api getUserInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
UserInfoModel *userInfo = [UserInfoModel mewModelWithJSON:data.data];
[user sendNext:userInfo];
[user sendCompleted];
} fail:^(NSInteger code, NSString * _Nullable msg) {
[user sendError:nil];
}] uid:uid];
/// 获取房间信息
[Api Mew_GetRoomInformation:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
MewRoomInfoModel *roomInfo = [MewRoomInfoModel mewModelWithJSON:data.data];
[room sendNext:roomInfo];
[room sendCompleted];
} fail:^(NSInteger code, NSString * _Nullable msg) {
[room sendError:nil];
}] uid:roomUid intoUid:uid];
}
/// 云信进房
- (void)mew_enterNIMCurrentRoom:(NSString *)roomUid user:(UserInfoModel *)userInfo {
NIMChatroomEnterRequest *request = [[NIMChatroomEnterRequest alloc] init];
request.roomId = roomUid;
MewMessageRemoteExtModel *extModel = [[MewMessageRemoteExtModel alloc] init];
extModel.erbanNo = userInfo.erbanNo;
extModel.vipIcon = userInfo.userVipInfoVO.vipIcon;
extModel.gender = userInfo.gender;
NSMutableDictionary *ext = [NSMutableDictionary dictionaryWithObject:extModel.mewModel2dictionary forKey:[NSString stringWithFormat:@"%ld", userInfo.uid]];
request.roomExt = [ext mewToJSONString];
/// 云信进房
[[NIMSDK sharedSDK].chatroomManager enterChatroom:request completion:^(NSError * _Nullable error, NIMChatroom * _Nullable chatroom, NIMChatroomMember * _Nullable me) {
if (error) {
[[self getView] enterCurrentRoomFail:error.code];
} else {
[[self getView] enterCurrentRoomSuccess:chatroom];
}
}];
}
/// 云信退房
- (void)mew_exitNIMCurrentRoom:(NSString *)roomUid {
[[NIMSDK sharedSDK].chatroomManager exitChatroom:roomUid completion:nil];
}
/// 开启用户自己的房间
/// @param title 房间标题
/// @param type 房间类型
/// @param roomPwd 房间密码
/// @param roomDesc 房间介绍
/// @param backPic 房间背景
/// @param mgId 小游戏的id
- (void)mew_openUserRoom:(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";
}
[Api Mew_OpenRoom:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
MewRoomInfoModel *roomInfo = [MewRoomInfoModel mewModelWithJSON:data.data];
[[self getView] openCurrentRoomSuccess:roomInfo];
} fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] enterCurrentRoomFail:code];
}] title:title type:type roomPwd:roomPwd roomDesc:roomDesc backPic:backPic uid:uid ticket:ticket mgId:mgId];
}
/// 上报用户进房
/// @param roomUid 房间uid
- (void)mew_reportUserInterRoom:(NSString *)roomUid {
if ([[AccountInfoStorage instance] getTicket].length < 1) {
return;
}
[Api Mew_RequestReportUserInterRoom:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
} uid:[[AccountInfoStorage instance] getUid] roomUid:roomUid ticket:[[AccountInfoStorage instance] getTicket]];
}
/// 上报用户退房
/// @param roomUid 房间uid
- (void)mew_reportUserOutRoom:(NSString *)roomUid {
if ([[AccountInfoStorage instance] getTicket].length < 1) {
return;
}
[Api Mew_RequestReportUserOutRoom:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
} uid:[[AccountInfoStorage instance] getUid] roomUid:roomUid ticket:[[AccountInfoStorage instance] getTicket]];
}
/// Mew 送礼物 房间内给麦位上的某个用户送普通的薯片礼物,默认写死
/// @param targetUids 送礼物的人
/// @param roomUid 房主的uid
- (void)mew_sendRoomGift:(NSString *)targetUids
roomUid:(NSString *)roomUid {
NSString *uid = [AccountInfoStorage instance].getUid;
NSString *giftNum = @"1";
// 房间内给麦位上的人送礼物
NSString *sendType = @"3";
// 薯片的giftid
NSString * giftId = @"2";
// 普通礼物
NSString *giftSource = @"1";
// 礼物类型
NSString *giftType = @"2";
// 送一个人
NSString *roomSendType = @"3";
[Api Mew_RequestSendGift:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
MewGiftReceiveInfoModel *receive = [MewGiftReceiveInfoModel mewModelWithJSON:data.data];
receive.sourceType = giftSource;
receive.roomSendGiftType = roomSendType;
[[self getView] mew_sendRoomGiftSuccess:receive originDic:data.data uidCount:1];
} fail:^(NSInteger code, NSString * _Nullable msg) {
[[self getView] mew_sendRoomGiftFailWithCode:code msg:msg];
}] targetUids:targetUids giftNum:giftNum sendType:sendType giftId:giftId giftSource:giftSource giftType:giftType roomUid:roomUid msg:@"" uid:uid];
}
@end