ManagerTableViewController.m 7.6 KB

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