2021-10-18 19:10:13 +08:00
|
|
|
//
|
|
|
|
// XPRoomPresenter.m
|
|
|
|
// xplan-ios
|
|
|
|
//
|
|
|
|
// Created by 冯硕 on 2021/10/18.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "XPRoomPresenter.h"
|
|
|
|
///API
|
|
|
|
#import "Api+Room.h"
|
2021-11-17 19:29:14 +08:00
|
|
|
#import "Api+Gift.h"
|
2021-10-18 19:10:13 +08:00
|
|
|
#import "UserInfoModel.h"
|
|
|
|
///Tool
|
|
|
|
#import "AccountInfoStorage.h"
|
2021-11-17 19:29:14 +08:00
|
|
|
#import "XPGiftStorage.h"
|
2021-10-26 19:14:01 +08:00
|
|
|
#import "NSObject+MJExtension.h"
|
2021-11-17 19:29:14 +08:00
|
|
|
///Model
|
|
|
|
#import "GiftInfoModel.h"
|
2021-12-17 15:18:34 +08:00
|
|
|
#import "XPMessageRemoteExtModel.h"
|
2021-10-19 18:30:03 +08:00
|
|
|
///P
|
|
|
|
#import "XPRoomProtocol.h"
|
2021-10-18 19:10:13 +08:00
|
|
|
|
2021-10-26 19:14:01 +08:00
|
|
|
#import <NIMSDK/NIMSDK.h>
|
2021-11-04 17:48:32 +08:00
|
|
|
#import <ReactiveObjC/ReactiveObjC.h>
|
2021-10-26 19:14:01 +08:00
|
|
|
|
2021-10-18 19:10:13 +08:00
|
|
|
|
|
|
|
@implementation XPRoomPresenter
|
|
|
|
|
2021-11-04 17:48:32 +08:00
|
|
|
- (void)initEnterRoom:(NSString *)roomUid user:(NSString *)uid {
|
|
|
|
RACSubject* room = [RACSubject subject];
|
|
|
|
RACSubject* user = [RACSubject subject];
|
|
|
|
|
|
|
|
[[RACSignal combineLatest:@[room, user] reduce:^id(RoomInfoModel* room, UserInfoModel* user){
|
|
|
|
[[self getView] initEnterRoomSuccess:room user:user];
|
|
|
|
return nil;
|
|
|
|
}] subscribeError:^(NSError * _Nullable error) {
|
|
|
|
[[self getView] enterRoomFail];
|
|
|
|
}];
|
|
|
|
|
2021-10-21 17:55:51 +08:00
|
|
|
[Api getUserInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
|
|
UserInfoModel * infoModel = [UserInfoModel modelWithJSON:data.data];
|
2021-11-04 17:48:32 +08:00
|
|
|
[user sendNext:infoModel];
|
|
|
|
[user sendCompleted];
|
2021-10-21 17:55:51 +08:00
|
|
|
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
2021-11-04 17:48:32 +08:00
|
|
|
[user sendError:nil];
|
|
|
|
} showLoading:NO errorToast:NO] uid:uid];
|
|
|
|
|
2021-10-21 21:21:43 +08:00
|
|
|
[Api getRoomInfo:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
2021-10-21 17:55:51 +08:00
|
|
|
RoomInfoModel * model = [RoomInfoModel modelWithJSON:data.data];
|
2021-11-04 17:48:32 +08:00
|
|
|
[room sendNext:model];
|
|
|
|
[room sendCompleted];
|
2021-10-21 17:55:51 +08:00
|
|
|
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
2021-11-04 17:48:32 +08:00
|
|
|
[user sendError:nil];
|
2021-11-04 20:56:54 +08:00
|
|
|
} showLoading:NO errorToast:NO] uid:roomUid intoUid:uid];
|
2021-10-18 19:10:13 +08:00
|
|
|
}
|
|
|
|
|
2021-10-26 19:14:01 +08:00
|
|
|
- (void)enterNIMRoom:(NSString *)roomId user:(UserInfoModel *)userInfo {
|
|
|
|
NIMChatroomEnterRequest *request = [[NIMChatroomEnterRequest alloc] init];
|
|
|
|
request.roomId = roomId;
|
|
|
|
//设置ext
|
2021-12-17 15:18:34 +08:00
|
|
|
XPMessageRemoteExtModel * extModel = [[XPMessageRemoteExtModel alloc] init];
|
2021-12-16 20:22:01 +08:00
|
|
|
extModel.defUser = userInfo.defUser;
|
|
|
|
extModel.erbanNo = userInfo.erbanNo;
|
|
|
|
extModel.carName = userInfo.carName;
|
|
|
|
extModel.inRoomNameplatePic = userInfo.nameplatePic;
|
|
|
|
extModel.inRoomNameplateWord = userInfo.nameplateWord;
|
|
|
|
extModel.charmUrl = userInfo.userLevelVo.charmUrl;
|
|
|
|
extModel.experLevelSeq = userInfo.userLevelVo.experLevelSeq;
|
|
|
|
extModel.experUrl = userInfo.userLevelVo.experUrl;
|
2021-12-17 15:18:34 +08:00
|
|
|
extModel.newUser = userInfo.newUser;
|
|
|
|
|
2021-12-16 20:22:01 +08:00
|
|
|
NSMutableDictionary *ext = [NSMutableDictionary dictionaryWithObject:extModel.model2dictionary forKey:[NSString stringWithFormat:@"%ld", userInfo.uid]];
|
2021-10-26 19:14:01 +08:00
|
|
|
request.roomExt = [ext toJSONString];
|
|
|
|
|
|
|
|
[[NIMSDK sharedSDK].chatroomManager enterChatroom:request completion:^(NSError * _Nullable error, NIMChatroom * _Nullable chatroom, NIMChatroomMember * _Nullable me) {
|
|
|
|
if (error) {
|
|
|
|
[[self getView] enterRoomFail];
|
|
|
|
} else {
|
2021-12-09 15:36:59 +08:00
|
|
|
[[self getView] enterRoomSuccess:chatroom];
|
2021-10-26 19:14:01 +08:00
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
2021-10-18 19:10:13 +08:00
|
|
|
|
2021-10-27 23:05:03 +08:00
|
|
|
- (void)exitNIMRoom:(NSString *)roomId {
|
|
|
|
[[NIMSDK sharedSDK].chatroomManager exitChatroom:roomId completion:nil];
|
|
|
|
}
|
|
|
|
|
2021-10-18 19:10:13 +08:00
|
|
|
/// 开启用户自己的房间
|
|
|
|
/// @param title 房间标题
|
|
|
|
/// @param type 房间类型
|
|
|
|
/// @param roomPwd 房间密码
|
|
|
|
/// @param roomDesc 房间介绍
|
|
|
|
/// @param backPic 房间背景
|
2021-11-04 15:27:11 +08:00
|
|
|
- (void)openRoom:(NSString *)title
|
2021-11-04 17:48:32 +08:00
|
|
|
type:(RoomType)type
|
|
|
|
roomPwd:(NSString *)roomPwd
|
|
|
|
roomDesc:(NSString *)roomDesc
|
|
|
|
backPic:(NSString *)backPic {
|
|
|
|
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 = @"";
|
|
|
|
}
|
|
|
|
|
|
|
|
[Api openRoom:[self createHttpCompletion:^(BaseModel * _Nonnull data) {
|
|
|
|
RoomInfoModel * infoModel = [RoomInfoModel modelWithJSON:data.data];
|
|
|
|
[[self getView] openRoomSuccess:infoModel];
|
|
|
|
} fail:^(NSInteger code, NSString * _Nullable msg) {
|
|
|
|
[[self getView] enterRoomFail];
|
|
|
|
} showLoading:YES] title:title type:type roomPwd:roomPwd roomDesc:roomDesc backPic:backPic uid:uid ticket:ticket];
|
2021-10-18 19:10:13 +08:00
|
|
|
}
|
|
|
|
|
2021-11-17 19:29:14 +08:00
|
|
|
///福袋礼物爆出的礼物的bug
|
|
|
|
///进入房间的时候需要获取一次礼物信息 因为如果有人送礼物的话 如果是福袋礼物的话 爆出的礼物需要从礼物列表中获取 会导致公屏不显示那个礼物
|
|
|
|
/// 获取普通的礼物
|
|
|
|
/// @param roomUid 房主的uid 获取房间专属礼物
|
|
|
|
- (void)getNormalGiftList:(NSString *)roomUid {
|
|
|
|
///先不请求接口 从缓存中获取
|
|
|
|
[[XPGiftStorage shareStorage] getGiftDatasource:roomUid];
|
|
|
|
[Api requestNormalGiftList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) {
|
|
|
|
NSArray * info = [GiftInfoModel modelsWithArray:data.data[@"gift"]];
|
|
|
|
///把礼物信息保存一下
|
|
|
|
[[XPGiftStorage shareStorage] saveGiftDatasource:info roomUid:roomUid];
|
|
|
|
} roomUid:roomUid];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-18 19:10:13 +08:00
|
|
|
@end
|