Files
featherVoice/QXLive/Message(音信)/Controller/群聊/QXGroupMemberViewController.m
2026-01-04 14:01:30 +08:00

186 lines
8.1 KiB
Objective-C

//
// QXGroupMemberViewController.m
// QXLive
//
// Created by 启星 on 2026/1/2.
//
#import "QXGroupMemberViewController.h"
#import "QXMessageServices.h"
#import "QXBlackListCell.h"
#import "QXUserHomePageViewController.h"
#import "ImSDK_Plus/V2TIMManager+Group.h"
@interface QXGroupMemberViewController ()<UITableViewDataSource,UITableViewDelegate,QXBlackListCellDelegate,UITextFieldDelegate>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)UIView *seachBgView;
@property (nonatomic,strong)UIImageView *searchImageView;
@property (nonatomic,strong)UITextField *textField;
@property (nonatomic,strong)UIButton *searchBtn;
@property (nonatomic,assign)BOOL isSearch;
@end
@implementation QXGroupMemberViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(void)setNavgationItems{
[super setNavgationItems];
self.navigationItem.title = @"群聊成员";
}
-(void)initSubViews{
self.page = 1;
self.seachBgView = [[UIView alloc] initWithFrame:CGRectMake(16, NavContentHeight, SCREEN_WIDTH-16*2, 35)];
self.seachBgView.backgroundColor = [UIColor colorWithHexString:@"#ffffff"];
self.seachBgView.layer.masksToBounds = YES;
self.seachBgView.layer.cornerRadius = 17.5;
[self.view addSubview:self.seachBgView];
self.searchImageView = [[UIImageView alloc] initWithFrame:CGRectMake(8, 5.5, 24, 24)];
self.searchImageView.image = [UIImage imageNamed:@"room_song_search"];
[self.seachBgView addSubview:self.searchImageView];
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(self.searchImageView.right+6, 0, self.seachBgView.width-self.searchImageView.right-6-8, 35)];
self.textField.placeholder = @"请输入ID/用户名搜索";
self.textField.font = [UIFont systemFontOfSize:14];
[self.textField addTarget:self action:@selector(textDidChange:) forControlEvents:(UIControlEventEditingChanged)];
self.textField.returnKeyType = UIReturnKeyDone;
self.textField.delegate = self;
self.textField.textColor = [UIColor colorWithHexString:@"#333333"];
[self.seachBgView addSubview:self.textField];
self.searchBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.seachBgView.width-60-10, 0, 60, 35)];
[self.searchBtn setTitle:@"搜索" forState:(UIControlStateNormal)];
self.searchBtn.titleLabel.font = [UIFont systemFontOfSize:14];
[self.searchBtn setTitleColor:QXConfig.themeColor forState:(UIControlStateNormal)];
[self.searchBtn addTarget:self action:@selector(searchAction:) forControlEvents:(UIControlEventTouchUpInside)];
[self.seachBgView addSubview:self.searchBtn];
[self.view addSubview:self.tableView];
[self getMemberListWithSearch:@""];
}
-(void)getMemberListWithSearch:(NSString*)search{
MJWeakSelf
[QXMessageServices getGroupMemberListWithPage:self.page search:search guildId:self.groupId successBlock:^(NSArray<QXUserHomeModel *> * _Nonnull list) {
if (weakSelf.page == 1) {
[weakSelf.dataArray removeAllObjects];
}
[weakSelf.dataArray addObjectsFromArray:list];
[weakSelf.tableView reloadData];
if (list.count == 0) {
weakSelf.tableView.mj_footer.state = MJRefreshStateNoMoreData;
}else{
[weakSelf.tableView.mj_footer endRefreshing];
}
[weakSelf.tableView.mj_header endRefreshing];
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
[weakSelf.tableView.mj_header endRefreshing];
[weakSelf.tableView.mj_footer endRefreshing];
}];
}
-(void)searchAction:(UIButton*)sender{
self.isSearch = YES;
[self getMemberListWithSearch:self.textField.text];
}
-(void)textDidChange:(UITextField*)textField{
if (textField.text.length == 0) {
self.isSearch = NO;
[self getMemberListWithSearch:@""];
}
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
QXBlackListCell *cell = [QXBlackListCell cellWithTableView:tableView];
cell.isNoIcon = YES;
cell.cellType = QXBlackListCellTypeGroupMember;
cell.groupMemberModel = self.dataArray[indexPath.row];
cell.delegate = self;
cell.removeBtn.hidden = !(self.isOwner.intValue==1);
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
QXUserHomePageViewController *vc = [[QXUserHomePageViewController alloc] init];
QXUserHomeModel *model = self.dataArray[indexPath.row];
vc.user_id = model.user_id;
[self.navigationController pushViewController:vc animated:YES];
}
-(void)didClickGroupMemberMoreBtnWithGroupMemberModel:(QXUserHomeModel *)groupMemberModel{
UIAlertController*al =[UIAlertController alertControllerWithTitle:@"禁言" message:@"" preferredStyle:(UIAlertControllerStyleActionSheet)];
if (groupMemberModel.is_mute.intValue == 1) {
[al addAction:[UIAlertAction actionWithTitle:@"解禁" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
[self muteMemberWithTime:0 groupMemberModel:groupMemberModel];
}]];
}else{
[al addAction:[UIAlertAction actionWithTitle:@"禁言1天" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
[self muteMemberWithTime:86400 groupMemberModel:groupMemberModel];
}]];
[al addAction:[UIAlertAction actionWithTitle:@"禁言5天" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
[self muteMemberWithTime:86400*5 groupMemberModel:groupMemberModel];
}]];
[al addAction:[UIAlertAction actionWithTitle:@"禁言10天" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
[self muteMemberWithTime:86400*10 groupMemberModel:groupMemberModel];
}]];
[al addAction:[UIAlertAction actionWithTitle:@"禁言30天" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
[self muteMemberWithTime:86400*30 groupMemberModel:groupMemberModel];
}]];
}
[al addAction:[UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
}]];
[self presentViewController:al animated:YES completion:nil];
}
-(void)muteMemberWithTime:(uint32_t)time groupMemberModel:(QXUserHomeModel*)groupMemberModel{
[[V2TIMManager sharedInstance] muteGroupMember:self.groupId member:[NSString stringWithFormat:@"u%@",groupMemberModel.user_id] muteTime:time succ:^{
if (time == 0) {
showToast(@"解禁成功");
}else{
showToast(@"禁言成功");
}
self.page = 1;
if (self.isSearch) {
[self getMemberListWithSearch:self.textField.text];
}else{
[self getMemberListWithSearch:@""];
}
} fail:^(int code, NSString * _Nullable desc) {
showToast(desc);
}];
}
-(UITableView *)tableView{
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.seachBgView.bottom+10, SCREEN_WIDTH, SCREEN_HEIGHT-self.seachBgView.bottom-10) style:(UITableViewStylePlain)];
_tableView.dataSource = self;
_tableView.delegate = self;
_tableView.backgroundColor = [UIColor clearColor];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.rowHeight = 60;
MJWeakSelf
_tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
weakSelf.page = 1;
if (self.isSearch) {
[self getMemberListWithSearch:self.textField.text];
}else{
[self getMemberListWithSearch:@""];
}
}];
_tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
weakSelf.page++;
if (self.isSearch) {
[self getMemberListWithSearch:self.textField.text];
}else{
[self getMemberListWithSearch:@""];
}
}];
}
return _tableView;
}
@end