WFCUConferenceUnmuteRequestTableViewController.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // WFCUConferenceUnmuteRequestTableViewController.m
  3. // WFChatUIKit
  4. //
  5. // Created by Rain on 2022/10/3.
  6. // Copyright © 2022 Wildfirechat. All rights reserved.
  7. //
  8. #import "WFCUConferenceUnmuteRequestTableViewController.h"
  9. #import "UIColor+YH.h"
  10. #import "WFCUConferenceMemberTableViewCell.h"
  11. #import "WFCUConferenceManager.h"
  12. #import <SDWebImage/SDWebImage.h>
  13. #import "WFCUUtilities.h"
  14. #import "WFCUImage.h"
  15. @interface WFCUConferenceUnmuteRequestTableViewController () <UITableViewDataSource, UITableViewDelegate>
  16. @property (nonatomic, strong)UITableView *tableView;
  17. @property(nonatomic, strong)UIButton *acceptAllBtn;
  18. @property(nonatomic, strong)UIButton *rejectAllBtn;
  19. @property(nonatomic, strong)NSMutableArray<NSString *> *members;
  20. @end
  21. @implementation WFCUConferenceUnmuteRequestTableViewController
  22. #if WFCU_SUPPORT_VOIP
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.view.backgroundColor = [UIColor whiteColor];
  26. CGRect bounds = self.view.bounds;
  27. CGFloat buttonHeight = 48;
  28. CGFloat buttonWidth = bounds.size.width/2 - 16 - 8;
  29. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, bounds.size.height - [WFCUUtilities wf_safeDistanceBottom] - buttonHeight - 16)];
  30. self.tableView.delegate = self;
  31. self.tableView.dataSource = self;
  32. if (@available(iOS 15, *)) {
  33. self.tableView.sectionHeaderTopPadding = 0;
  34. }
  35. self.tableView.sectionIndexColor = [UIColor colorWithHexString:@"0x4e4e4e"];
  36. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  37. [self.view addSubview:self.tableView];
  38. [self.tableView reloadData];
  39. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:WFCString(@"C") style:UIBarButtonItemStyleDone target:self action:@selector(onClose:)];
  40. if(self.isAudio) {
  41. self.members = [WFCUConferenceManager sharedInstance].applyingUnmuteAudioMembers;
  42. self.title = @"请求打开麦克风成员";
  43. } else {
  44. self.members = [WFCUConferenceManager sharedInstance].applyingUnmuteVideoMembers;
  45. self.title = @"请求打开摄像头成员";
  46. }
  47. if(self.members.count) {
  48. self.acceptAllBtn = [self createBtn:CGRectMake(16, bounds.size.height - [WFCUUtilities wf_safeDistanceBottom] - buttonHeight - 16, buttonWidth, buttonHeight) title:@"全部同意" action:@selector(onAcceptAllBtnPressed:)];
  49. self.rejectAllBtn = [self createBtn:CGRectMake(bounds.size.width - 16 - buttonWidth, bounds.size.height - [WFCUUtilities wf_safeDistanceBottom] - buttonHeight - 16, buttonWidth, buttonHeight) title:@"全部拒绝" action:@selector(onRejectAllBtnPressed:)];
  50. }
  51. }
  52. - (void)onAcceptAllBtnPressed:(id)sender {
  53. [[WFCUConferenceManager sharedInstance] approveAllMemberUnmute:YES isAudio:self.isAudio];
  54. [self.tableView reloadData];
  55. }
  56. - (void)onRejectAllBtnPressed:(id)sender {
  57. [[WFCUConferenceManager sharedInstance] approveAllMemberUnmute:NO isAudio:self.isAudio];
  58. [self.tableView reloadData];
  59. }
  60. - (void)onClose:(id)sender {
  61. [self dismissViewControllerAnimated:YES completion:nil];
  62. }
  63. - (void)onAcceptBtn:(UIButton *)sender {
  64. int row = (int)sender.tag;
  65. NSString *userId = self.members[row];
  66. [[WFCUConferenceManager sharedInstance] approveMember:userId unmute:YES isAudio:self.isAudio];
  67. [self.tableView reloadData];
  68. }
  69. - (void)onRejectBtn:(UIButton *)sender {
  70. int row = (int)sender.tag;
  71. NSString *userId = self.members[row];
  72. [[WFCUConferenceManager sharedInstance] approveMember:userId unmute:NO isAudio:self.isAudio];
  73. [self.tableView reloadData];
  74. }
  75. - (UIButton *)createBtn:(CGRect)frame title:(NSString *)title action:(SEL)action {
  76. UIButton *btn = [[UIButton alloc] initWithFrame:frame];
  77. [btn setTitle:title forState:UIControlStateNormal];
  78. btn.titleLabel.font = [UIFont systemFontOfSize:14];
  79. [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  80. btn.layer.borderWidth = 1;
  81. btn.layer.borderColor = [UIColor grayColor].CGColor;
  82. btn.layer.masksToBounds = YES;
  83. btn.layer.cornerRadius = 5.f;
  84. [btn addTarget:self action:action forControlEvents:UIControlEventTouchDown];
  85. [self.view addSubview:btn];
  86. return btn;
  87. }
  88. #pragma mark - UITableViewDataSource<NSObject>
  89. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  90. return self.members.count;
  91. }
  92. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  93. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  94. if(!cell) {
  95. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  96. CGSize size = cell.bounds.size;
  97. size.width = self.view.bounds.size.width;
  98. CGFloat buttonWidth = 56;
  99. UIButton *reject = [[UIButton alloc] initWithFrame:CGRectMake(size.width - 8 - buttonWidth, 0, buttonWidth, size.height)];
  100. [reject setTitle:WFCString(@"Reject") forState:UIControlStateNormal];
  101. [reject setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  102. [reject addTarget:self action:@selector(onRejectBtn:) forControlEvents:UIControlEventTouchDown];
  103. reject.layer.masksToBounds = YES;
  104. reject.layer.cornerRadius = 3.f;
  105. UIButton *accept = [[UIButton alloc] initWithFrame:CGRectMake(size.width - 8 - buttonWidth - 4 - buttonWidth, 0, buttonWidth, size.height)];
  106. [accept setTitle:WFCString(@"Agree") forState:UIControlStateNormal];
  107. [accept setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  108. [accept addTarget:self action:@selector(onAcceptBtn:) forControlEvents:UIControlEventTouchDown];
  109. accept.layer.masksToBounds = YES;
  110. accept.layer.cornerRadius = 3.f;
  111. [cell.contentView addSubview:reject];
  112. [cell.contentView addSubview:accept];
  113. }
  114. for (UIView *view in cell.contentView.subviews) {
  115. if([view isKindOfClass:[UIButton class]]) {
  116. [cell.contentView bringSubviewToFront:view];
  117. }
  118. }
  119. NSString *userId = self.members[indexPath.row];
  120. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:userId refresh:NO];
  121. cell.textLabel.text = userInfo.friendAlias.length?userInfo.friendAlias:userInfo.displayName;
  122. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:userInfo.portrait] placeholderImage:[WFCUImage imageNamed:@"PersonalChat"]];
  123. cell.tag = indexPath.row;
  124. return cell;
  125. }
  126. #endif
  127. @end