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"
|
|
|
|
#import "UserInfoModel.h"
|
|
|
|
///Tool
|
|
|
|
#import "AccountInfoStorage.h"
|
2021-10-26 19:14:01 +08:00
|
|
|
#import "NSObject+MJExtension.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
|
|
|
|
NSMutableDictionary *extSource = [NSMutableDictionary dictionary];
|
|
|
|
//defUser
|
|
|
|
if (userInfo) {
|
|
|
|
[extSource setObject:@(userInfo.defUser) forKey:@"defUser"];
|
|
|
|
[extSource setObject:@(userInfo.erbanNo) forKey:@"erbanNo"];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableDictionary *ext = [NSMutableDictionary dictionaryWithObject:extSource 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) {
|
|
|
|
[[self getView] enterRoomFail];
|
|
|
|
} else {
|
|
|
|
[[self getView] enterRoomSuccess];
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@end
|