GroupMuteTableViewController.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. @end
  17. @implementation GroupMuteTableViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.title = WFCString(@"GroupMuteSetting");
  21. [self loadMutedMemberList];
  22. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
  23. self.tableView.delegate = self;
  24. self.tableView.dataSource = self;
  25. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  26. [self.tableView reloadData];
  27. [self.view addSubview:self.tableView];
  28. __weak typeof(self)ws = self;
  29. [[NSNotificationCenter defaultCenter] addObserverForName:kGroupMemberUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
  30. if ([ws.groupInfo.target isEqualToString:note.object]) {
  31. [ws loadMutedMemberList];
  32. [ws.tableView reloadData];
  33. }
  34. }];
  35. }
  36. - (void)loadMutedMemberList {
  37. NSArray *memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupInfo.target forceUpdate:YES];
  38. self.mutedMemberList = [[NSMutableArray alloc] init];
  39. for (WFCCGroupMember *member in memberList) {
  40. if (member.type == Member_Type_Muted) {
  41. [self.mutedMemberList addObject:member];
  42. }
  43. }
  44. }
  45. - (void)selectMemberToAdd {
  46. WFCUContactListViewController *pvc = [[WFCUContactListViewController alloc] init];
  47. pvc.selectContact = YES;
  48. pvc.multiSelect = YES;
  49. __weak typeof(self)ws = self;
  50. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  51. [[WFCCIMService sharedWFCIMService] muteGroupMember:self.groupInfo.target isSet:YES memberIds:contacts notifyLines:@[@(0)] notifyContent:nil success:^{
  52. for (NSString *memberId in contacts) {
  53. WFCCGroupMember *member = [[WFCCIMService sharedWFCIMService] getGroupMember:ws.groupInfo.target memberId:memberId];
  54. if (member) {
  55. member.type = Member_Type_Muted;
  56. [ws.mutedMemberList addObject:member];
  57. }
  58. }
  59. if (contacts.count) {
  60. [ws.tableView reloadData];
  61. }
  62. } error:^(int error_code) {
  63. }];
  64. };
  65. NSMutableArray *candidateUsers = [[NSMutableArray alloc] init];
  66. NSArray *memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupInfo.target forceUpdate:NO];
  67. for (WFCCGroupMember *member in memberList) {
  68. if (member.type == Member_Type_Normal && ![member.memberId isEqualToString:self.groupInfo.owner]) {
  69. [candidateUsers addObject:member.memberId];
  70. }
  71. }
  72. pvc.candidateUsers = candidateUsers;
  73. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:pvc];
  74. [self.navigationController presentViewController:navi animated:YES completion:nil];
  75. }
  76. - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
  77. if (indexPath.section == 0) {
  78. WFCUGeneralSwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  79. if (cell == nil) {
  80. cell = [[WFCUGeneralSwitchTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  81. cell.textLabel.text = WFCString(@"MuteAll");
  82. cell.onSwitch = ^(BOOL value, void (^onDone)(BOOL success)) {
  83. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_Mute newValue:value?@"1":@"0" notifyLines:@[@(0)] notifyContent:nil success:^{
  84. onDone(YES);
  85. } error:^(int error_code) {
  86. onDone(NO);
  87. }];
  88. };
  89. }
  90. cell.on = self.groupInfo.mute;
  91. return cell;
  92. } else {
  93. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  94. if (cell == nil) {
  95. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  96. }
  97. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  98. cell.accessoryView = nil;
  99. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  100. if(indexPath.section == 1) {
  101. if (indexPath.row == 0) {
  102. cell.imageView.image = [UIImage imageNamed:@"plus"];
  103. cell.textLabel.text = WFCString(@"MuteMember");
  104. } else {
  105. WFCCUserInfo *member = [[WFCCIMService sharedWFCIMService] getUserInfo:[self.mutedMemberList objectAtIndex:indexPath.row-1].memberId refresh:NO];
  106. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:[member.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage: [UIImage imageNamed:@"PersonalChat"]];
  107. cell.textLabel.text = member.displayName;
  108. }
  109. }
  110. return cell;
  111. }
  112. }
  113. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  114. if (indexPath.section == 0 || (indexPath.section == 1 && indexPath.row == 0)) {
  115. return NO;
  116. }
  117. return YES;
  118. }
  119. - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
  120. UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:WFCString(@"Unmute") handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  121. __weak typeof(self)ws = self;
  122. [[WFCCIMService sharedWFCIMService] muteGroupMember:self.groupInfo.target isSet:NO memberIds:@[[self.mutedMemberList objectAtIndex:indexPath.row-1].memberId] notifyLines:@[@(0)] notifyContent:nil success:^{
  123. for (WFCCGroupMember *member in ws.mutedMemberList) {
  124. if ([member.memberId isEqualToString:[ws.mutedMemberList objectAtIndex:indexPath.row-1].memberId]) {
  125. [ws.mutedMemberList removeObject:member];
  126. [ws.tableView reloadData];
  127. break;
  128. }
  129. }
  130. } error:^(int error_code) {
  131. }];
  132. }];
  133. UITableViewRowAction *editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:WFCString(@"Cancel") handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
  134. NSLog(@"点击了编辑");
  135. }];
  136. editAction.backgroundColor = [UIColor grayColor];
  137. return @[deleteAction, editAction];
  138. }
  139. - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  140. if (section == 0) {
  141. return 1;
  142. } else if(section == 1) {
  143. return self.mutedMemberList.count+1;
  144. }
  145. return 0;
  146. }
  147. -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  148. if (section == 0) {
  149. return WFCString(@"MuteAll");
  150. } else if(section == 1) {
  151. return WFCString(@"MutedMemberList");
  152. }
  153. return nil;
  154. }
  155. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  156. return 30.f;
  157. }
  158. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  159. return 0.f;
  160. }
  161. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  162. return 2; //成员管理,加群设置
  163. }
  164. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  165. if (indexPath.section == 0) {
  166. } else if(indexPath.section == 1) {
  167. if (indexPath.row == 0) {
  168. [self selectMemberToAdd];
  169. } else {
  170. }
  171. }
  172. }
  173. - (void)dealloc {
  174. [[NSNotificationCenter defaultCenter] removeObserver:self];
  175. }
  176. @end