GroupManageTableViewController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. //
  2. // GroupManageTableViewController.m
  3. // WFChatUIKit
  4. //
  5. // Created by heavyrain lee on 2019/6/26.
  6. // Copyright © 2019 WildFireChat. All rights reserved.
  7. //
  8. #import "GroupManageTableViewController.h"
  9. #import "ManagerTableViewController.h"
  10. #import "GroupMuteTableViewController.h"
  11. #import "GroupMemberControlTableViewController.h"
  12. #import "UIView+Toast.h"
  13. @interface GroupManageTableViewController () <UITableViewDelegate, UITableViewDataSource>
  14. @property(nonatomic, strong)UITableView *tableView;
  15. @end
  16. @implementation GroupManageTableViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.title = WFCString(@"GroupManage");
  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:kGroupInfoUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
  28. if ([ws.groupInfo.target isEqualToString:note.object]) {
  29. ws.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:ws.groupInfo.target refresh:NO];
  30. [ws.tableView reloadData];
  31. }
  32. }];
  33. }
  34. - (BOOL)isGroupOwner {
  35. return [self.groupInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId];
  36. }
  37. - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
  38. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  39. if (cell == nil) {
  40. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  41. }
  42. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  43. cell.accessoryView = nil;
  44. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  45. cell.detailTextLabel.text = nil;
  46. if (indexPath.section == 0) {
  47. if (indexPath.row == 0) {
  48. if ([self isGroupOwner]) {
  49. cell.textLabel.text = WFCString(@"Manager");
  50. } else {
  51. cell.textLabel.text = WFCString(@"MuteSetting");
  52. }
  53. } else if(indexPath.row == 1) {
  54. if ([self isGroupOwner]) {
  55. cell.textLabel.text = WFCString(@"MuteSetting");
  56. } else {
  57. cell.textLabel.text = WFCString(@"MemberPrivilege");
  58. }
  59. } else if(indexPath.row == 2) {
  60. cell.textLabel.text = WFCString(@"MemberPrivilege");
  61. }
  62. } else if(indexPath.section == 1) {
  63. if (indexPath.row == 0) {
  64. cell.textLabel.text = WFCString(@"JoinGroupPermission");
  65. if (self.groupInfo.joinType == 0) {
  66. cell.detailTextLabel.text = WFCString(@"Free2Join");
  67. } else if(self.groupInfo.joinType == 1) {
  68. cell.detailTextLabel.text = WFCString(@"MemberInviteOnly");
  69. } else if(self.groupInfo.joinType == 2) {
  70. cell.detailTextLabel.text = WFCString(@"ManagerInviteOnly");
  71. }
  72. } else if(indexPath.row == 1) {
  73. cell.textLabel.text = WFCString(@"GroupVisiable");
  74. cell.detailTextLabel.text = WFCString(@"GroupCannotSearch");
  75. } else if(indexPath.row == 2) {
  76. cell.textLabel.text = WFCString(@"GroupHistoryMessage");
  77. if (self.groupInfo.historyMessage > 0) {
  78. cell.detailTextLabel.text = WFCString(@"GroupHistoryMessageAviable");
  79. } else {
  80. cell.detailTextLabel.text = WFCString(@"GroupHistoryMessageNotAviable");
  81. }
  82. } else if(indexPath.row == 3) {
  83. cell.textLabel.text = WFCString(@"GroupMaxMember");
  84. cell.detailTextLabel.text = [NSString stringWithFormat:@"%d", self.groupInfo.maxMemberCount];
  85. }
  86. }
  87. return cell;
  88. }
  89. - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  90. if (section == 0) {
  91. if ([self isGroupOwner]) {
  92. return 3; //管理员,设置禁言,群成员权限
  93. }
  94. return 2;//设置禁言,群成员权限
  95. } else if(section == 1) {
  96. if ([[WFCCIMService sharedWFCIMService] isCommercialServer]) {
  97. return 4;//加群方式,查找权限,历史消息,最大成员数
  98. } else {
  99. return 2;//加群方式,查找权限
  100. }
  101. }
  102. return 0;
  103. }
  104. -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  105. if (section == 0) {
  106. return WFCString(@"MemberManage");
  107. } else if(section == 1) {
  108. return WFCString(@"GroupGeneralSetting");
  109. }
  110. return nil;
  111. }
  112. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  113. return 30.f;
  114. }
  115. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  116. return 0.f;
  117. }
  118. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  119. return 2; //成员管理,加群设置
  120. }
  121. - (void)toManagerVC {
  122. ManagerTableViewController *mtvc = [[ManagerTableViewController alloc] init];
  123. mtvc.groupInfo = self.groupInfo;
  124. [self.navigationController pushViewController:mtvc animated:YES];
  125. }
  126. - (void)toMuteVC {
  127. GroupMuteTableViewController *gmtc = [[GroupMuteTableViewController alloc] init];
  128. gmtc.groupInfo = self.groupInfo;
  129. [self.navigationController pushViewController:gmtc animated:YES];
  130. }
  131. - (void)toMemberControlVC {
  132. GroupMemberControlTableViewController *gmcvc = [[GroupMemberControlTableViewController alloc] init];
  133. gmcvc.groupInfo = self.groupInfo;
  134. [self.navigationController pushViewController:gmcvc animated:YES];
  135. }
  136. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  137. if (indexPath.section == 0) {
  138. if (indexPath.row == 0) {
  139. if ([self isGroupOwner]) {
  140. [self toManagerVC];
  141. } else {
  142. [self toMuteVC];
  143. }
  144. } else if(indexPath.row == 1) {
  145. if ([self isGroupOwner]) {
  146. [self toMuteVC];
  147. } else {
  148. [self toMemberControlVC];
  149. }
  150. } else if(indexPath.row == 2) {
  151. [self toMemberControlVC];
  152. }
  153. } else if(indexPath.section == 1) {
  154. if (indexPath.row == 0) {
  155. UIAlertController* alertController = [UIAlertController alertControllerWithTitle:WFCString(@"JoinGroupPermission") message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  156. // Create cancel action.
  157. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  158. }];
  159. [alertController addAction:cancelAction];
  160. UIAlertAction *openAction = [UIAlertAction actionWithTitle:WFCString(@"Free2Join") style:self.groupInfo.joinType == 0 ? UIAlertActionStyleDestructive : UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  161. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_JoinType newValue:@"0" notifyLines:@[@(0)] notifyContent:nil success:^{
  162. // self.groupInfo.joinType = 0;
  163. // [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationFade];
  164. } error:^(int error_code) {
  165. [self.view makeToast:@"设置失败"];
  166. }];
  167. }];
  168. [alertController addAction:openAction];
  169. UIAlertAction *verifyAction = [UIAlertAction actionWithTitle:WFCString(@"MemberInviteOnly") style:self.groupInfo.joinType == 1 ? UIAlertActionStyleDestructive : UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  170. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_JoinType newValue:@"1" notifyLines:@[@(0)] notifyContent:nil success:^{
  171. // self.groupInfo.joinType = 1;
  172. // [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationFade];
  173. } error:^(int error_code) {
  174. [self.view makeToast:@"设置失败"];
  175. }];
  176. }];
  177. [alertController addAction:verifyAction];
  178. UIAlertAction *normalAction = [UIAlertAction actionWithTitle:WFCString(@"ManagerInviteOnly") style:self.groupInfo.joinType == 2 ? UIAlertActionStyleDestructive : UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  179. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_JoinType newValue:@"2" notifyLines:@[@(0)] notifyContent:nil success:^{
  180. // self.groupInfo.joinType = 2;
  181. // [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationFade];
  182. } error:^(int error_code) {
  183. [self.view makeToast:@"设置失败"];
  184. }];
  185. }];
  186. [alertController addAction:normalAction];
  187. [self.navigationController presentViewController:alertController animated:YES completion:nil];
  188. } else if(indexPath.row == 1) {
  189. UIAlertController* alertController = [UIAlertController alertControllerWithTitle:WFCString(@"GroupVisiable") message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  190. // Create cancel action.
  191. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  192. }];
  193. [alertController addAction:cancelAction];
  194. UIAlertAction *openAction = [UIAlertAction actionWithTitle:WFCString(@"GroupCanbeSearch") style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  195. }];
  196. [alertController addAction:openAction];
  197. UIAlertAction *verifyAction = [UIAlertAction actionWithTitle:WFCString(@"GroupCannotSearch") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  198. }];
  199. [alertController addAction:verifyAction];
  200. [self.navigationController presentViewController:alertController animated:YES completion:nil];
  201. } else if(indexPath.row == 2) {
  202. UIAlertController* alertController = [UIAlertController alertControllerWithTitle:WFCString(@"GroupHistoryMessage") message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  203. // Create cancel action.
  204. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  205. }];
  206. [alertController addAction:cancelAction];
  207. UIAlertAction *openAction = [UIAlertAction actionWithTitle:WFCString(@"GroupHistoryMessageAviable") style:self.groupInfo.historyMessage > 0 ? UIAlertActionStyleDestructive : UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  208. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_History_Message newValue:@"1" notifyLines:@[@(0)] notifyContent:nil success:^{
  209. self.groupInfo.historyMessage = 1;
  210. } error:^(int error_code) {
  211. [self.view makeToast:@"设置失败"];
  212. }];
  213. }];
  214. [alertController addAction:openAction];
  215. UIAlertAction *verifyAction = [UIAlertAction actionWithTitle:WFCString(@"GroupHistoryMessageNotAviable") style:self.groupInfo.historyMessage > 0 ? UIAlertActionStyleDefault : UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  216. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_History_Message newValue:@"0" notifyLines:@[@(0)] notifyContent:nil success:^{
  217. self.groupInfo.historyMessage = 0;
  218. } error:^(int error_code) {
  219. [self.view makeToast:@"设置失败"];
  220. }];
  221. }];
  222. [alertController addAction:verifyAction];
  223. [self.navigationController presentViewController:alertController animated:YES completion:nil];
  224. }
  225. }
  226. }
  227. @end