158 lines
5.1 KiB
Objective-C
158 lines
5.1 KiB
Objective-C
//
|
|
// DDRoomRequest.m
|
|
// DingDangApp
|
|
//
|
|
// Created by 触海 on 2023/12/13.
|
|
//
|
|
|
|
#import "DDRoomRequest.h"
|
|
/// Model
|
|
#import "RoomInfoModel.h"
|
|
#import "UserInfoModel.h"
|
|
#import "DDMessageCustomRemoteExtModel.h"
|
|
/// Tool
|
|
#import "DDRequestTool.h"
|
|
#import "DDLoginRequest.h"
|
|
//#import "NSObject+DDExtension.h"
|
|
/// Third
|
|
#import <ReactiveObjC/ReactiveObjC.h>
|
|
#import <NIMSDK/NIMSDK.h>
|
|
|
|
|
|
@implementation DDRoomRequest
|
|
#pragma mark - Public Method
|
|
#pragma mark - Init Room
|
|
/// 获取房间和用户的信息
|
|
+ (void)DD_GetRoomUserInformationWithRoomUid:(NSString *)roomUid success:(completed)success fail:(failure)fail {
|
|
RACSubject *roomSubject = [RACSubject subject];
|
|
RACSubject *userSubject = [RACSubject subject];
|
|
|
|
NSString *uid = [[AccountInfoStorage instance] getUid];
|
|
[[RACSignal combineLatest:@[roomSubject, userSubject] reduce:^id(RoomInfoModel *roomInfo, UserInfoModel *userInfo) {
|
|
success(roomInfo, userInfo);
|
|
return nil;
|
|
}] subscribeError:^(NSError * _Nullable error) {
|
|
fail(error);
|
|
}];
|
|
|
|
[DDLoginRequest DD_LoadRequestUserInfo:uid completed:^(UserInfoModel * _Nonnull userInfo) {
|
|
[userSubject sendNext:userInfo];
|
|
[userSubject sendCompleted];
|
|
}];
|
|
|
|
NSDictionary *param = @{
|
|
@"uid": roomUid,
|
|
@"intoUid": uid
|
|
};
|
|
|
|
/// /room/get
|
|
NSString *url = [DDEncryptManager dd_aesDecryptWithText:@"jXpOPAmK96W+TSfRtsEEeg=="];
|
|
[DDRequestTool DD_Request_GET:url params:param success:^(BaseModel * _Nonnull data) {
|
|
RoomInfoModel *roomModel = [RoomInfoModel DD_ModeWithJSON:data.data];
|
|
[roomSubject sendNext:roomModel];
|
|
[roomSubject sendCompleted];
|
|
} failure:^(NSInteger resCode, NSString * _Nonnull message) {
|
|
[roomSubject sendError:nil];
|
|
}];
|
|
}
|
|
|
|
|
|
/// 开启用户自己的房间
|
|
/// @param title 房间标题
|
|
/// @param type 房间类型
|
|
/// @param roomPwd 房间密码
|
|
/// @param roomDesc 房间介绍
|
|
/// @param backPic 房间背景
|
|
/// @param mgId 小游戏的id
|
|
+ (void)DD_OpenRoomTitle:(NSString *)title
|
|
type:(NSInteger)type
|
|
roomPwd:(NSString *)roomPwd
|
|
roomDesc:(NSString *)roomDesc
|
|
backPic:(NSString *)backPic
|
|
mgId:(NSString *)mgId success:(openCompleted)success fail:(failure)failure {
|
|
NSString *uid = [AccountInfoStorage instance].getUid;
|
|
NSString *ticket = [AccountInfoStorage instance].getTicket;
|
|
title = title.length <= 0 ? @"" : title;
|
|
roomPwd = roomPwd.length <= 0 ? @"" : roomPwd;
|
|
roomDesc = roomDesc.length <= 0 ? @"" : roomDesc;
|
|
backPic = backPic.length <= 0 ? @"" : backPic;
|
|
mgId = mgId.length <= 0 ? @"0" : mgId;
|
|
NSDictionary *param = @{
|
|
@"title" : title,
|
|
@"type" : @(type),
|
|
@"roomPwd" : roomPwd,
|
|
@"roomDesc" : roomDesc,
|
|
@"backPic" : backPic,
|
|
@"mgId" : mgId,
|
|
@"uid" : uid,
|
|
@"ticket" : ticket,
|
|
};
|
|
|
|
|
|
/// /room/open
|
|
NSString *url = [DDEncryptManager dd_aesDecryptWithText:@"wOBApINPXycOHm9BIPL1EA=="];
|
|
[DDRequestTool DD_Request_POST:url params:param success:^(BaseModel * _Nonnull data) {
|
|
RoomInfoModel *roomInfo = [RoomInfoModel DD_ModeWithJSON:data.data];
|
|
success(roomInfo);
|
|
} failure:^(NSInteger resCode, NSString * _Nonnull message) {
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
/// NIM Enter ROOM
|
|
+ (void)DD_EnterNIMRoom:(NSString *)roomId User:(UserInfoModel *)user {
|
|
NIMChatroomEnterRequest *request = [[NIMChatroomEnterRequest alloc] init];
|
|
request.roomId = roomId;
|
|
DDMessageCustomRemoteExtModel *extModel = [[DDMessageCustomRemoteExtModel alloc] initMessageRemoteExtModelWithUserModel:user];
|
|
|
|
|
|
NSMutableDictionary *roomExt = [NSMutableDictionary dictionaryWithObject:extModel.dd_modelDictionary forKey:[NSString stringWithFormat:@"%ld", user.uid]];
|
|
request.roomExt = [roomExt dd_toJSONString];
|
|
|
|
[[NIMSDK sharedSDK].chatroomManager enterChatroom:request completion:^(NSError * _Nullable error, NIMChatroom * _Nullable chatroom, NIMChatroomMember * _Nullable me) {
|
|
NSLog(@"云信房间初始化成功:%@",error);
|
|
|
|
if (error) {
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
}];
|
|
}
|
|
|
|
/// NIM Exit Room
|
|
+ (void)DD_ExitNIMRoom:(NSString *)roomId {
|
|
[[NIMSDK sharedSDK].chatroomManager exitChatroom:roomId completion:nil];
|
|
}
|
|
|
|
|
|
#pragma mark - Room Event
|
|
/// 房间收藏 1-收藏 2-取消收藏
|
|
+ (void)DD_RoomCollectionType:(NSInteger)type roomUid:(NSString *)roomUid success:(successEvent)success{
|
|
NSDictionary *param = @{
|
|
@"roomUid":roomUid,
|
|
@"type":@(type),
|
|
@"uid":[[AccountInfoStorage instance] getUid]
|
|
};
|
|
|
|
/// /fans/fansRoom
|
|
NSString *url = [DDEncryptManager dd_aesDecryptWithText:@"cWyMqgH9Rs8/dNrBGW76iA=="];
|
|
[DDRequestTool DD_Request_POST:url params:param success:^(BaseModel * _Nonnull data) {
|
|
if (data.code == 200) {
|
|
if (type == 1) {
|
|
[ToolsObject addPopVieToText: @"收藏成功"];
|
|
}
|
|
success();
|
|
}
|
|
} failure:^(NSInteger resCode, NSString * _Nonnull message) {
|
|
[ToolsObject addPopVieToText:message];
|
|
}];
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|