2
0

GroupMuteTableViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. //
  2. // GroupMuteTableViewController.m
  3. // WFChatUIKit
  4. //
  5. // Created by heavyrain lee on 2019/6/26.
  6. // Copyright © 2019 WildFireChat. All rights reserved.
  7. //
  8. #import "GroupMuteTableViewController.h"
  9. #import "SDWebImage.h"
  10. #import "WFCUContactListViewController.h"
  11. #import "WFCUGeneralSwitchTableViewCell.h"
  12. #import "WFCUContactListViewController.h"
  13. @interface GroupMuteTableViewController () <UITableViewDelegate, UITableViewDataSource>
  14. @property(nonatomic, strong)UITableView *tableView;
  15. @property(nonatomic, strong)NSMutableArray<WFCCGroupMember *> *mutedMemberList;
  16. @property(nonatomic, strong)NSMutableArray<WFCCGroupMember *> *allowedMemberList;
  17. @end
  18. @implementation GroupMuteTableViewController
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. self.title = WFCString(@"GroupMuteSetting");
  22. [self loadMemberList];
  23. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
  24. self.tableView.delegate = self;
  25. self.tableView.dataSource = self;
  26. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  27. [self.tableView reloadData];
  28. [self.view addSubview:self.tableView];
  29. __weak typeof(self)ws = self;
  30. [[NSNotificationCenter defaultCenter] addObserverForName:kGroupMemberUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
  31. if ([ws.groupInfo.target isEqualToString:note.object]) {
  32. [ws loadMemberList];
  33. [ws.tableView reloadData];
  34. }
  35. }];
  36. }
  37. - (void)loadMemberList {
  38. NSArray *memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupInfo.target forceUpdate:YES];
  39. self.mutedMemberList = [[NSMutableArray alloc] init];
  40. self.allowedMemberList = [[NSMutableArray alloc] init];
  41. for (WFCCGroupMember *member in memberList) {
  42. if (member.type == Member_Type_Muted) {
  43. [self.mutedMemberList addObject:member];
  44. } else if (member.type == Member_Type_Allowed) {
  45. [self.allowedMemberList addObject:member];
  46. }
  47. }
  48. }
  49. - (void)selectMemberToAdd:(BOOL)isAllow {
  50. WFCUContactListViewController *pvc = [[WFCUContactListViewController alloc] init];
  51. pvc.selectContact = YES;
  52. pvc.multiSelect = YES;
  53. __weak typeof(self)ws = self;
  54. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  55. if (isAllow) {
  56. [[WFCCIMService sharedWFCIMService] allowGroupMember:self.groupInfo.target isSet:YES memberIds:contacts notifyLines:@[@(0)] notifyContent:nil success:^{
  57. [ws loadMemberList];
  58. [ws.tableView reloadData];
  59. } error:^(int error_code) {
  60. }];
  61. } else {
  62. [[WFCCIMService sharedWFCIMService] muteGroupMember:self.groupInfo.target isSet:YES memberIds:contacts notifyLines:@[@(0)] notifyContent:nil success:^{
  63. [ws loadMemberList];
  64. [ws.tableView reloadData];
  65. } error:^(int error_code) {
  66. }];
  67. }
  68. };
  69. NSMutableArray *candidateUsers = [[NSMutableArray alloc] init];
  70. NSArray *memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupInfo.target forceUpdate:NO];
  71. for (WFCCGroupMember *member in memberList) {
  72. if ((member.type == Member_Type_Normal || (isAllow && member.type == Member_Type_Muted) || (!isAllow && member.type == Member_Type_Allowed)) && ![member.memberId isEqualToString:self.groupInfo.owner]) {
  73. [candidateUsers addObject:member.memberId];
  74. }
  75. }
  76. pvc.candidateUsers = candidateUsers;
  77. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:pvc];
  78. [self.navigationController presentViewController:navi animated:YES completion:nil];
  79. }
  80. - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
  81. __weak typeof(self)ws = self;
  82. if (indexPath.section == 0) {
  83. WFCUGeneralSwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  84. if (cell == nil) {
  85. cell = [[WFCUGeneralSwitchTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  86. cell.textLabel.text = WFCString(@"MuteAll");
  87. cell.onSwitch = ^(BOOL value, void (^onDone)(BOOL success)) {
  88. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_Mute newValue:value?@"1":@"0" notifyLines:@[@(0)] notifyContent:nil success:^{
  89. ws.groupInfo.mute = value;
  90. onDone(YES);
  91. } error:^(int error_code) {
  92. onDone(NO);
  93. }];
  94. };
  95. }
  96. cell.on = self.groupInfo.mute;
  97. return cell;
  98. } else {
  99. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  100. if (cell == nil) {
  101. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  102. }
  103. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  104. cell.accessoryView = nil;
  105. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  106. if(indexPath.section == 1) {
  107. if (indexPath.row == 0) {
  108. cell.imageView.image = [UIImage imageNamed:@"plus"];
  109. cell.textLabel.text = WFCString(@"MuteMember");
  110. } else {
  111. WFCCUserInfo *member = [[WFCCIMService sharedWFCIMService] getUserInfo:[self.mutedMemberList objectAtIndex:indexPath.row-1].memberId refresh:NO];
  112. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:[member.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage: [UIImage imageNamed:@"PersonalChat"]];
  113. cell.textLabel.text = member.displayName;
  114. }
  115. } else if(indexPath.section == 2) {
  116. if (indexPath.row == 0) {
  117. cell.imageView.image = [UIImage imageNamed:@"plus"];
  118. cell.textLabel.text = WFCString(@"AllowMember");
  119. } else {
  120. WFCCUserInfo *member = [[WFCCIMService sharedWFCIMService] getUserInfo:[self.allowedMemberList objectAtIndex:indexPath.row-1].memberId refresh:NO];
  121. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:[member.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage: [UIImage imageNamed:@"PersonalChat"]];
  122. cell.textLabel.text = member.displayName;
  123. }
  124. }
  125. return cell;
  126. }
  127. }
  128. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  129. if (indexPath.section == 0 || (indexPath.section == 1 && indexPath.row == 0)) {
  130. return NO;
  131. }
  132. return YES;
  133. }
  134. - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
  135. UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:WFCString(@"Unmute") handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  136. __weak typeof(self)ws = self;
  137. if (indexPath.section == 1) {
  138. [[WFCCIMService sharedWFCIMService] muteGroupMember:self.groupInfo.target isSet:NO memberIds:@[[self.mutedMemberList objectAtIndex:indexPath.row-1].memberId] notifyLines:@[@(0)] notifyContent:nil success:^{
  139. for (WFCCGroupMember *member in ws.mutedMemberList) {
  140. if ([member.memberId isEqualToString:[ws.mutedMemberList objectAtIndex:indexPath.row-1].memberId]) {
  141. [ws.mutedMemberList removeObject:member];
  142. [ws.tableView reloadData];
  143. break;
  144. }
  145. }
  146. } error:^(int error_code) {
  147. }];
  148. } else if(indexPath.section == 2) {
  149. [[WFCCIMService sharedWFCIMService] allowGroupMember:self.groupInfo.target isSet:NO memberIds:@[[self.allowedMemberList objectAtIndex:indexPath.row-1].memberId] notifyLines:@[@(0)] notifyContent:nil success:^{
  150. for (WFCCGroupMember *member in ws.allowedMemberList) {
  151. if ([member.memberId isEqualToString:[ws.allowedMemberList objectAtIndex:indexPath.row-1].memberId]) {
  152. [ws.allowedMemberList removeObject:member];
  153. [ws.tableView reloadData];
  154. break;
  155. }
  156. }
  157. } error:^(int error_code) {
  158. }];
  159. }
  160. }];
  161. UITableViewRowAction *editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:WFCString(@"Cancel") handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  162. }];
  163. editAction.backgroundColor = [UIColor grayColor];
  164. return @[deleteAction, editAction];
  165. }
  166. - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  167. if (section == 0) {
  168. return 1;
  169. } else if(section == 1) {
  170. return self.mutedMemberList.count+1;
  171. } else if(section == 2) {
  172. return self.allowedMemberList.count+1;
  173. }
  174. return 0;
  175. }
  176. -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  177. if (section == 0) {
  178. return WFCString(@"MuteAll");
  179. } else if(section == 1) {
  180. return WFCString(@"MutedList");
  181. } else if(section == 2) {
  182. return WFCString(@"AllowList");
  183. }
  184. return nil;
  185. }
  186. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  187. return 30.f;
  188. }
  189. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  190. return 0.f;
  191. }
  192. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  193. return 3; //全员禁言,群成员禁言,允许发言成员
  194. }
  195. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  196. if (indexPath.section == 0) {
  197. } else if(indexPath.section == 1) {
  198. if (indexPath.row == 0) {
  199. [self selectMemberToAdd:NO];
  200. } else {
  201. }
  202. } else if(indexPath.section == 2) {
  203. if (indexPath.row == 0) {
  204. [self selectMemberToAdd:YES];
  205. } else {
  206. }
  207. }
  208. }
  209. - (void)dealloc {
  210. [[NSNotificationCenter defaultCenter] removeObserver:self];
  211. }
  212. @end