122 lines
4.8 KiB
Objective-C
122 lines
4.8 KiB
Objective-C
//
|
|
// MSRoomGamePresenter.m
|
|
// YuMi
|
|
//
|
|
// Created by duoban on 2024/5/28.
|
|
//
|
|
|
|
#import "MSRoomGamePresenter.h"
|
|
#import "Api+MSRoomGameApi.h"
|
|
#import "Api.h"
|
|
#import <ReactiveObjC/ReactiveObjC.h>
|
|
#import "UserInfoModel.h"
|
|
#import "WalletInfoModel.h"
|
|
#import "MSTabbarRoomGameModel.h"
|
|
#import "MSRoomGameProtocol.h"
|
|
#import "MSRoomGameModel.h"
|
|
#import <NIMSDK/NIMSDK.h>
|
|
#import "XPMessageRemoteExtModel.h"
|
|
@implementation MSRoomGamePresenter
|
|
-(void)getRoomGameConfig{
|
|
|
|
|
|
NSString * uid = [AccountInfoStorage instance].getUid;
|
|
NSString * ticket = [AccountInfoStorage instance].getTicket;
|
|
RACSubject* user = [RACSubject subject];
|
|
RACSubject* coin = [RACSubject subject];
|
|
RACSubject* game = [RACSubject subject];
|
|
|
|
[[RACSignal combineLatest:@[user,coin,game] reduce:^id(UserInfoModel* userModel,WalletInfoModel *coinModel,MSTabbarRoomGameModel *gameModel){
|
|
[[self getView]getRoomGameConfigSuccessWithUser:userModel coinModel:coinModel gameModel:gameModel];
|
|
return nil;
|
|
}] subscribeError:^(NSError * _Nullable error) {
|
|
|
|
}];
|
|
|
|
[Api getUserInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
UserInfoModel * infoModel = [UserInfoModel modelWithJSON:data.data];
|
|
|
|
[user sendNext:infoModel];
|
|
[user sendCompleted];
|
|
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
|
[user sendError:nil];
|
|
} showLoading:NO errorToast:NO] uid:uid];
|
|
|
|
|
|
[Api getUserWalletInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
WalletInfoModel * model = [WalletInfoModel modelWithDictionary:data.data];
|
|
[coin sendNext:model];
|
|
[coin sendCompleted];
|
|
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
|
[coin sendError:nil];
|
|
}] uid:uid ticket:ticket];
|
|
|
|
[Api getRoomGameHomeConfig:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
MSTabbarRoomGameModel *model = [MSTabbarRoomGameModel modelWithJSON:data.data];
|
|
[game sendNext:model];
|
|
[game sendCompleted];
|
|
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
|
[game sendError:nil];
|
|
}]];
|
|
}
|
|
///开始匹配游戏
|
|
-(void)startMatchGameWithroomId:(NSString *)roomId mgId:(NSString *)mgId gameMode:(NSString *)gameMode{
|
|
[Api startMatchGame:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
[[self getView]startMatchGameSuccess];
|
|
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
|
|
|
} showLoading:YES errorToast:YES] roomId:roomId mgId:mgId gameMode:gameMode];
|
|
}
|
|
///得到房间详情
|
|
-(void)getRoomGameDetailWithRoomType:(NSString *)roomType{
|
|
[Api getRoomGameDetails:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
MSRoomGameModel *model = [MSRoomGameModel modelWithJSON:data.data];
|
|
[[self getView]getRoomGameDetailsSuccessWithModel:model];
|
|
}] roomType:roomType];
|
|
}
|
|
- (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];
|
|
[[NIMSDK sharedSDK].chatroomManager enterChatroom:request completion:^(NSError * _Nullable error, NIMChatroom * _Nullable chatroom, NIMChatroomMember * _Nullable me) {
|
|
if (error) {
|
|
|
|
} else {
|
|
|
|
}
|
|
}];
|
|
|
|
}
|
|
|
|
- (void)exitNIMRoom:(NSString *)roomId {
|
|
[[NIMSDK sharedSDK].chatroomManager exitChatroom:roomId completion:nil];
|
|
|
|
}
|
|
@end
|