338 lines
11 KiB
Objective-C
338 lines
11 KiB
Objective-C
//
|
|
// YMRoomOnLineViewController.m
|
|
// YUMI
|
|
//
|
|
// Created by YUMI on 2021/12/29.
|
|
//
|
|
|
|
#import "XPRoomOnLineViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <NIMSDK/NIMSDK.h>
|
|
#import <MJRefresh/MJRefresh.h>
|
|
#import <ReactiveObjC.h>
|
|
///Tool
|
|
#import "DJDKMIMOMColor.h"
|
|
#import "YUMIMacroUitls.h"
|
|
#import "UIButton+EnlargeTouchArea.h"
|
|
#import "NSArray+Safe.h"
|
|
///Model
|
|
#import "UserInfoModel.h"
|
|
#import "MicroQueueModel.h"
|
|
#import "RoomInfoModel.h"
|
|
#import "XPUserCardInfoModel.h"
|
|
#import "XPMessageRemoteExtModel.h"
|
|
///View
|
|
#import "XPRoomOnlineTableViewCell.h"
|
|
#import "XPRoomRoleEmptyTableViewCell.h"
|
|
///VC
|
|
#import "UserRoomCardViewController.h"
|
|
#import "XPRoomSettingPresenter.h"
|
|
#import "XPRoomSettingProtocol.h"
|
|
@interface XPRoomOnLineViewController ()<UITableViewDelegate, UITableViewDataSource, NIMChatManagerDelegate,XPRoomSettingProtocol>
|
|
///导航栏
|
|
@property (nonatomic,strong) UIView * navView;
|
|
///返回按钮
|
|
@property (nonatomic,strong) UIButton *backButton;
|
|
///显示标题
|
|
@property (nonatomic,strong) UILabel *titleLabel;
|
|
///背景图
|
|
@property (nonatomic,strong) UIImageView *backImageView;
|
|
///需要显示的数据
|
|
@property (nonatomic,strong) NSMutableArray *datasource;
|
|
///列表
|
|
@property (nonatomic,strong) UITableView *tableView;
|
|
///host
|
|
@property (nonatomic,weak) id<RoomHostDelegate>hostDelegate;
|
|
///房间的id
|
|
@property (nonatomic,copy) NSString *roomId;
|
|
|
|
@end
|
|
|
|
@implementation XPRoomOnLineViewController
|
|
- (void)dealloc {
|
|
[[NIMSDK sharedSDK].chatManager removeDelegate:self];
|
|
}
|
|
- (XPRoomSettingPresenter *)createPresenter {
|
|
return [[XPRoomSettingPresenter alloc] init];
|
|
}
|
|
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate {
|
|
if (self = [super init]) {
|
|
self.hostDelegate = delegate;
|
|
self.roomId= [NSString stringWithFormat:@"%ld", self.hostDelegate.getRoomInfo.uid];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
[super viewWillAppear:animated];
|
|
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
//监听云信消息
|
|
[[NIMSDK sharedSDK].chatManager addDelegate:self];
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
[self refreshData];
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self.view addSubview:self.backImageView];
|
|
[self.view addSubview:self.tableView];
|
|
[self.view addSubview:self.navView];
|
|
|
|
[self.navView addSubview:self.backButton];
|
|
[self.navView addSubview:self.titleLabel];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.view);
|
|
}];
|
|
|
|
[self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.top.mas_equalTo(self.view);
|
|
make.height.mas_equalTo(kNavigationHeight);
|
|
}];
|
|
|
|
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.trailing.bottom.mas_equalTo(self.view);
|
|
make.top.mas_equalTo(self.navView.mas_bottom);
|
|
}];
|
|
|
|
[self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.size.mas_equalTo(CGSizeMake(22, 22));
|
|
make.leading.mas_equalTo(self.navView).offset(8);
|
|
make.centerY.mas_equalTo(self.titleLabel);
|
|
}];
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.mas_equalTo(self.navView);
|
|
make.centerY.equalTo(self.navView.mas_bottom).mas_offset(-22);
|
|
}];
|
|
}
|
|
|
|
- (void)refreshData {
|
|
[XNDJTDDLoadingTool showLoading];
|
|
[self.presenter getRoomOnlineUserListWithRoomUid:self.roomId];
|
|
}
|
|
|
|
//获取房间在线用户成功
|
|
-(void)getRoomOnlineUserListSuccess:(NSArray *)list{
|
|
[XNDJTDDLoadingTool hideHUD];
|
|
NSMutableArray *temp = @[].mutableCopy;
|
|
for (XPMessageRemoteExtModel *model in list) {
|
|
if (model.platformRole == 0) {
|
|
[temp addObject:model];
|
|
}
|
|
}
|
|
self.datasource = temp;
|
|
|
|
[self.tableView reloadData];
|
|
self.tableView.hidden = NO;
|
|
}
|
|
|
|
-(void)getRoomOnlineUserFailure:(NSString *)msg {
|
|
[XNDJTDDLoadingTool showErrorWithMessage:msg];
|
|
self.tableView.hidden = NO;
|
|
}
|
|
|
|
#pragma mark - NIMChatManagerDelegate
|
|
- (void)onRecvMessages:(NSArray<NIMMessage *> *)messages {
|
|
for (NIMMessage * message in messages) {
|
|
// 非房间内消息不处理
|
|
if (message.session.sessionType != NIMSessionTypeChatroom) {
|
|
continue;
|
|
}
|
|
|
|
// 非本房间不处理
|
|
if (![message.session.sessionId isEqualToString:self.roomId]) {
|
|
continue;
|
|
}
|
|
if (message.messageType == NIMMessageTypeNotification) {
|
|
NIMNotificationObject *notiMsg = (NIMNotificationObject *)message.messageObject;
|
|
|
|
if (![notiMsg.content isKindOfClass:[NIMChatroomNotificationContent class]]) {
|
|
return;
|
|
}
|
|
|
|
NIMChatroomNotificationContent *content = (NIMChatroomNotificationContent *)notiMsg.content;
|
|
|
|
switch (content.eventType) {
|
|
case NIMChatroomEventTypeEnter:
|
|
case NIMChatroomEventTypeExit:
|
|
case NIMChatroomEventTypeAddManager:
|
|
case NIMChatroomEventTypeRemoveManager:
|
|
case NIMChatroomEventTypeAddBlack:
|
|
case NIMChatroomEventTypeRemoveBlack:
|
|
case NIMChatroomEventTypeQueueChange:
|
|
case NIMChatroomEventTypeKicked:
|
|
[self refreshData];
|
|
break;
|
|
default:
|
|
break;
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#pragma mark - UITableViewDelegate And UITableViewDataSource
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
return self.datasource.count > 0 ? self.datasource.count : 1;
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (self.datasource.count > 0) {
|
|
XPRoomOnlineTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPRoomOnlineTableViewCell class])];
|
|
if (cell == nil) {
|
|
cell = [[XPRoomOnlineTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPRoomOnlineTableViewCell class])];
|
|
}
|
|
XPMessageRemoteExtModel * member = [self.datasource xpSafeObjectAtIndex:indexPath.row];
|
|
cell.userInfo = member;
|
|
return cell;
|
|
}
|
|
|
|
XPRoomRoleEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPRoomRoleEmptyTableViewCell class])];
|
|
if (cell == nil) {
|
|
cell = [[XPRoomRoleEmptyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPRoomRoleEmptyTableViewCell class])];
|
|
}
|
|
cell.titleLabel.text = YMLocalizedString(@"XPRoomOnLineViewController0");
|
|
cell.backgroundColor = [UIColor clearColor];
|
|
return cell;
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (self.datasource.count > 0) {
|
|
return 60;
|
|
}
|
|
return KScreenHeight - kNavigationHeight;
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
if (self.datasource.count > 0) {
|
|
XPMessageRemoteExtModel * userInfo = [self.datasource xpSafeObjectAtIndex:indexPath.row];
|
|
if (userInfo.userVipInfoVO.enterHide) {
|
|
return;
|
|
}
|
|
RoomInfoModel * roomInfo = self.hostDelegate.getRoomInfo;
|
|
NSString * targetUid = userInfo.uid;
|
|
XPUserCardInfoModel * model = [[XPUserCardInfoModel alloc] init];
|
|
__block MicroQueueModel *micModel = nil;
|
|
[[self.hostDelegate.getMicroQueue allValues] enumerateObjectsUsingBlock:^(MicroQueueModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if (targetUid.integerValue == obj.userInfo.uid) {
|
|
model.position = [NSString stringWithFormat:@"%d", obj.microState.position];
|
|
model.posState = obj.microState.posState;
|
|
model.micState = obj.microState.micState;
|
|
micModel = obj;
|
|
*stop = YES;
|
|
}
|
|
}];
|
|
model.nick = self.hostDelegate.getUserInfo.nick;
|
|
model.uid = targetUid;
|
|
model.delegate = self.hostDelegate;
|
|
model.roomInfo = roomInfo;
|
|
model.superMangerList = self.hostDelegate.getRoomSuperAdminList;
|
|
model.micQueue = self.hostDelegate.getMicroQueue;
|
|
model.hideSendGiftItem = YES;
|
|
model.platformRole = micModel.userInfo.platformRole;
|
|
UserRoomCardViewController *vc = [[UserRoomCardViewController alloc] initWithUser:model controlUser:self.hostDelegate.getUserInfo];
|
|
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|
[self.hostDelegate.getCurrentNav presentViewController:vc animated:NO completion:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
@kWeakify(self);
|
|
[[NSNotificationCenter defaultCenter] addObserverForName:@"PopAfterUserCardAction" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull notification) {
|
|
@kStrongify(self);
|
|
[self clickChatAction];
|
|
}];
|
|
}
|
|
}
|
|
#pragma mark- XPUserCardViewControllerDelegate
|
|
-(void)clickChatAction{
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
}
|
|
#pragma mark - Event Response
|
|
- (void)backButtonAction:(UIButton *)sender {
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (UITableView *)tableView {
|
|
if (!_tableView) {
|
|
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
|
_tableView.delegate = self;
|
|
_tableView.dataSource = self;
|
|
_tableView.tableFooterView = [UIView new];
|
|
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
_tableView.backgroundColor = [UIColor clearColor];
|
|
_tableView.rowHeight = 60;
|
|
if (@available(iOS 11.0, *)) {
|
|
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
}
|
|
[_tableView registerClass:[XPRoomOnlineTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPRoomOnlineTableViewCell class])];
|
|
[_tableView registerClass:[XPRoomRoleEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPRoomRoleEmptyTableViewCell class])];
|
|
_tableView.hidden = YES;
|
|
}
|
|
return _tableView;
|
|
}
|
|
|
|
- (UIButton *)backButton {
|
|
if (!_backButton) {
|
|
_backButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
[_backButton setImage:[[UIImage imageNamed:@"home_search_white_back"]ms_SetImageForRTL] forState:UIControlStateNormal];
|
|
[_backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
[_backButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
|
|
}
|
|
return _backButton;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] init];
|
|
_titleLabel.textAlignment = NSTextAlignmentCenter;
|
|
_titleLabel.font = [UIFont systemFontOfSize:15];
|
|
_titleLabel.text = YMLocalizedString(@"XPRoomOnLineViewController1");
|
|
_titleLabel.textColor = [UIColor whiteColor];
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
- (UIView *)navView {
|
|
if (!_navView) {
|
|
_navView = [[UIView alloc] init];
|
|
_navView.backgroundColor = [UIColor clearColor];
|
|
}
|
|
return _navView;
|
|
}
|
|
|
|
|
|
- (UIImageView *)backImageView {
|
|
if (!_backImageView) {
|
|
_backImageView = [[UIImageView alloc] init];
|
|
_backImageView.userInteractionEnabled = YES;
|
|
_backImageView.layer.masksToBounds = YES;
|
|
_backImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
_backImageView.image = [[UIImage imageNamed:@"room_background"]ms_SetImageForRTL];
|
|
}
|
|
return _backImageView;
|
|
}
|
|
|
|
|
|
- (NSMutableArray *)datasource {
|
|
if (!_datasource) {
|
|
_datasource = [NSMutableArray array];
|
|
}
|
|
return _datasource;
|
|
}
|
|
@end
|