Files
yinmeng-ios/xplan-ios/Main/IM/MicroQueue/XPIMRoomMicQueueImpl.m
2021-10-21 21:35:01 +08:00

154 lines
4.2 KiB
Objective-C

//
// XPIMRoomMicQueueImpl.m
// xplan-ios
//
// Created by 冯硕 on 2021/10/21.
//
#import "XPIMRoomMicQueueImpl.h"
///Third
#import <NIMSDK/NIMSDK.h>
///Tool
#import "XPIMManager.h"
#import "AccountInfoStorage.h"
///Model
#import "MicroModel.h"
#import "MicroQueueItemModel.h"
#import "RoomInfoModel.h"
#import "UserInfoModel.h"
///P
#import "XPIMRoomMicQueueDelegate.h"
#define MIC_COUNT(Type) [self roomTypecpORnormal:Type]
@interface XPIMRoomMicQueueImpl ()
///麦序的状态 <麦序 麦序上的内容>
@property (nonatomic,strong) NSMutableDictionary<NSString *, MicroQueueItemModel *> *micQueue;
///正在上麦或者下麦
@property (nonatomic,assign) BOOL isLoadingMic;
///代理数组
@property (nonatomic,strong) NSMutableArray *delegateArray;
@end
@implementation XPIMRoomMicQueueImpl
// 给宏定义赋值
-(NSInteger )roomTypecpORnormal:(RoomType )type{
if (type == RoomType_Game){
return 9;
}else{
return 9;
}
}
///提前绑定一下麦序
- (void)configDefaultMicQueue {
RoomInfoModel * roomfInfo = [XPIMManager shareManager].chatRoomManager.getCurrentRoomInfo;
for (int i = 0 ; i < MIC_COUNT(roomfInfo.type); i++) {
MicroModel *state = [[MicroModel alloc]init];
state.posState = MicroPosStateType_Free;
state.micState = MicroMicStateType_Open;
MicroQueueItemModel *micSequence = [[MicroQueueItemModel alloc]init];
micSequence.microState = state;
micSequence.userInfo = nil;
[self.micQueue setObject:micSequence forKey:[NSString stringWithFormat:@"%d",i-1]];
}
}
#pragma mark - XPIMRoomMicQueueInterface
///进入房间成功之后根据扩展字段整理麦序
- (void)enterRoomRepairMicQueue:(NSDictionary *)micDictionary {
[self configDefaultMicQueue];
for (NSString *position in micDictionary.allKeys) {
MicroModel *state = [MicroModel modelWithJSON:micDictionary[position]];
MicroQueueItemModel *sequence = [self.micQueue objectForKey:position];
sequence.microState = state;
}
}
///获取房间队列
- (void)fetchRoomQueue:(NSString *)roomid {
[[NIMSDK sharedSDK].chatroomManager fetchChatroomQueue:roomid completion:^(NSError * _Nullable error, NSArray<NSDictionary<NSString *,NSString *> *> * _Nullable info) {
if (error == nil && info!= nil) {
for (NSDictionary *item in info) {
UserInfoModel *userInfo = [UserInfoModel modelWithJSON:item.allValues.firstObject];
NSString *position = item.allKeys.firstObject;
MicroQueueItemModel *sequence = [self.micQueue objectForKey:position];
sequence.userInfo = userInfo;
}
for (id<XPIMRoomMicQueueDelegate> delegate in self.delegateArray) {
if ([delegate respondsToSelector:@selector(onGetRoomMicroQueueSuccess:)]) {
[delegate onGetRoomMicroQueueSuccess:self.micQueue];
}
}
} else {
NSLog(@"获取队列失败");
}
}];
}
///麦序的队列
- (NSDictionary *)microQueue {
return [self.microQueue copy];
}
- (void)upMic:(NSString *)position {
if (self.isLoadingMic) {
#warning to do - 展示正在上麦toast
}
self.isLoadingMic = YES;
///这个坑位 有没有人
UserInfoModel *userInfo = [[self.micQueue objectForKey:position] userInfo];
if (userInfo) {
#warning to do - 展示用户卡片
} else {
NSString * uid = [[AccountInfoStorage instance] getUid];
[[[XPIMManager shareManager].chatRoomMemberManager rac_queryChatRoomMember:uid] subscribeNext:^(id _Nullable x) {
NIMChatroomMember * member = x;
if (member.type == NIMChatroomMemberTypeCreator || member.type == NIMTeamMemberTypeManager) {
} else {
}
}];
}
}
- (void)downMic:(NSString *)position {
}
///添加代理
- (void)addDelegate:(id<XPIMRoomMicQueueDelegate>)delegate {
if (delegate) {
[self.delegateArray addObject:delegate];
}
}
///移除代理
- (void)removeDelegate:(id<XPIMRoomMicQueueDelegate>)delegate {
if (delegate && [self.delegateArray containsObject:delegate]) {
[self.delegateArray removeObject:delegate];
delegate = nil;
}
}
#pragma mark - Getters And Setters
- (NSMutableDictionary<NSString *,MicroQueueItemModel *> *)micQueue {
if (!_micQueue) {
_micQueue= [NSMutableDictionary dictionary];
}
return _micQueue;
}
- (NSMutableArray *)delegateArray {
if (!_delegateArray) {
_delegateArray = [NSMutableArray array];
}
return _delegateArray;
}
@end