2
0

GroupManageTableViewController.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. if (@available(iOS 15, *)) {
  22. self.tableView.sectionHeaderTopPadding = 0;
  23. }
  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:kGroupInfoUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
  31. NSArray<WFCCGroupInfo *> *groupInfoList = note.userInfo[@"groupInfoList"];
  32. for (WFCCGroupInfo *groupInfo in groupInfoList) {
  33. if ([ws.groupInfo.target isEqualToString:groupInfo.target]) {
  34. ws.groupInfo = groupInfo;
  35. [ws.tableView reloadData];
  36. break;
  37. }
  38. }
  39. }];
  40. }
  41. - (BOOL)isGroupOwner {
  42. return [self.groupInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId];
  43. }
  44. - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
  45. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  46. if (cell == nil) {
  47. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  48. }
  49. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  50. cell.accessoryView = nil;
  51. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  52. cell.detailTextLabel.text = nil;
  53. if (indexPath.section == 0) {
  54. if (indexPath.row == 0) {
  55. if ([self isGroupOwner]) {
  56. cell.textLabel.text = WFCString(@"Manager");
  57. } else {
  58. cell.textLabel.text = WFCString(@"MuteSetting");
  59. }
  60. } else if(indexPath.row == 1) {
  61. if ([self isGroupOwner]) {
  62. cell.textLabel.text = WFCString(@"MuteSetting");
  63. } else {
  64. cell.textLabel.text = WFCString(@"MemberPrivilege");
  65. }
  66. } else if(indexPath.row == 2) {
  67. cell.textLabel.text = WFCString(@"MemberPrivilege");
  68. }
  69. } else if(indexPath.section == 1) {
  70. if (indexPath.row == 0) {
  71. cell.textLabel.text = WFCString(@"JoinGroupPermission");
  72. if (self.groupInfo.joinType == 0) {
  73. cell.detailTextLabel.text = WFCString(@"Free2Join");
  74. } else if(self.groupInfo.joinType == 1) {
  75. cell.detailTextLabel.text = WFCString(@"MemberInviteOnly");
  76. } else if(self.groupInfo.joinType == 2) {
  77. cell.detailTextLabel.text = WFCString(@"ManagerInviteOnly");
  78. }
  79. } else if(indexPath.row == 1) {
  80. cell.textLabel.text = WFCString(@"GroupVisiable");
  81. if(self.groupInfo.searchable == 0)
  82. cell.detailTextLabel.text = WFCString(@"GroupCanbeSearch");
  83. else
  84. cell.detailTextLabel.text = WFCString(@"GroupCannotSearch");
  85. } else if(indexPath.row == 2) {
  86. cell.textLabel.text = WFCString(@"GroupHistoryMessage");
  87. if (self.groupInfo.historyMessage > 0) {
  88. cell.detailTextLabel.text = WFCString(@"GroupHistoryMessageAviable");
  89. } else {
  90. cell.detailTextLabel.text = WFCString(@"GroupHistoryMessageNotAviable");
  91. }
  92. } else if(indexPath.row == 3) {
  93. cell.textLabel.text = WFCString(@"GroupMaxMember");
  94. cell.detailTextLabel.text = [NSString stringWithFormat:@"%d", self.groupInfo.maxMemberCount];
  95. cell.accessoryType = UITableViewCellAccessoryNone;
  96. }
  97. }
  98. return cell;
  99. }
  100. - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  101. if (section == 0) {
  102. if ([self isGroupOwner]) {
  103. return 3; //管理员,设置禁言,群成员权限
  104. }
  105. return 2;//设置禁言,群成员权限
  106. } else if(section == 1) {
  107. if ([[WFCCIMService sharedWFCIMService] isCommercialServer]) {
  108. return 4;//加群方式,查找权限,历史消息,最大成员数
  109. } else {
  110. return 2;//加群方式,查找权限
  111. }
  112. }
  113. return 0;
  114. }
  115. -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  116. if (section == 0) {
  117. return WFCString(@"MemberManage");
  118. } else if(section == 1) {
  119. return WFCString(@"GroupGeneralSetting");
  120. }
  121. return nil;
  122. }
  123. -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  124. return 30.f;
  125. }
  126. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  127. return 0.f;
  128. }
  129. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  130. return 2; //成员管理,加群设置
  131. }
  132. - (void)toManagerVC {
  133. ManagerTableViewController *mtvc = [[ManagerTableViewController alloc] init];
  134. mtvc.groupInfo = self.groupInfo;
  135. [self.navigationController pushViewController:mtvc animated:YES];
  136. }
  137. - (void)toMuteVC {
  138. GroupMuteTableViewController *gmtc = [[GroupMuteTableViewController alloc] init];
  139. gmtc.groupInfo = self.groupInfo;
  140. [self.navigationController pushViewController:gmtc animated:YES];
  141. }
  142. - (void)toMemberControlVC {
  143. GroupMemberControlTableViewController *gmcvc = [[GroupMemberControlTableViewController alloc] init];
  144. gmcvc.groupInfo = self.groupInfo;
  145. [self.navigationController pushViewController:gmcvc animated:YES];
  146. }
  147. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  148. __weak typeof(self)ws = self;
  149. if (indexPath.section == 0) {
  150. if (indexPath.row == 0) {
  151. if ([self isGroupOwner]) {
  152. [self toManagerVC];
  153. } else {
  154. [self toMuteVC];
  155. }
  156. } else if(indexPath.row == 1) {
  157. if ([self isGroupOwner]) {
  158. [self toMuteVC];
  159. } else {
  160. [self toMemberControlVC];
  161. }
  162. } else if(indexPath.row == 2) {
  163. [self toMemberControlVC];
  164. }
  165. } else if(indexPath.section == 1) {
  166. if (indexPath.row == 0) {
  167. UIAlertController* alertController = [UIAlertController alertControllerWithTitle:WFCString(@"JoinGroupPermission") message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  168. // Create cancel action.
  169. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  170. }];
  171. [alertController addAction:cancelAction];
  172. UIAlertAction *openAction = [UIAlertAction actionWithTitle:WFCString(@"Free2Join") style:self.groupInfo.joinType == 0 ? UIAlertActionStyleDestructive : UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  173. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:ws.groupInfo.target type:Modify_Group_JoinType newValue:@"0" notifyLines:@[@(0)] notifyContent:nil success:^{
  174. ws.groupInfo.joinType = 0;
  175. [ws.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  176. } error:^(int error_code) {
  177. [ws.view makeToast:@"设置失败"];
  178. }];
  179. }];
  180. [alertController addAction:openAction];
  181. UIAlertAction *verifyAction = [UIAlertAction actionWithTitle:WFCString(@"MemberInviteOnly") style:self.groupInfo.joinType == 1 ? UIAlertActionStyleDestructive : UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  182. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:ws.groupInfo.target type:Modify_Group_JoinType newValue:@"1" notifyLines:@[@(0)] notifyContent:nil success:^{
  183. ws.groupInfo.joinType = 1;
  184. [ws.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  185. } error:^(int error_code) {
  186. [ws.view makeToast:@"设置失败"];
  187. }];
  188. }];
  189. [alertController addAction:verifyAction];
  190. UIAlertAction *normalAction = [UIAlertAction actionWithTitle:WFCString(@"ManagerInviteOnly") style:self.groupInfo.joinType == 2 ? UIAlertActionStyleDestructive : UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  191. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:ws.groupInfo.target type:Modify_Group_JoinType newValue:@"2" notifyLines:@[@(0)] notifyContent:nil success:^{
  192. ws.groupInfo.joinType = 2;
  193. [ws.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  194. } error:^(int error_code) {
  195. [ws.view makeToast:@"设置失败"];
  196. }];
  197. }];
  198. [alertController addAction:normalAction];
  199. [self.navigationController presentViewController:alertController animated:YES completion:nil];
  200. } else if(indexPath.row == 1) {
  201. UIAlertController* alertController = [UIAlertController alertControllerWithTitle:WFCString(@"GroupVisiable") message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  202. // Create cancel action.
  203. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  204. }];
  205. [alertController addAction:cancelAction];
  206. UIAlertAction *canSearchAction = [UIAlertAction actionWithTitle:WFCString(@"GroupCanbeSearch") style:self.groupInfo.searchable == 0 ? UIAlertActionStyleDestructive : UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  207. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:ws.groupInfo.target type:Modify_Group_Searchable newValue:@"0" notifyLines:@[@(0)] notifyContent:nil success:^{
  208. ws.groupInfo.searchable = 1;
  209. [ws.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  210. } error:^(int error_code) {
  211. [ws.view makeToast:@"设置失败"];
  212. }];
  213. }];
  214. [alertController addAction:canSearchAction];
  215. UIAlertAction *cantSearchAction = [UIAlertAction actionWithTitle:WFCString(@"GroupCannotSearch") style:self.groupInfo.searchable == 1 ? UIAlertActionStyleDestructive : UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  216. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:ws.groupInfo.target type:Modify_Group_Searchable newValue:@"1" notifyLines:@[@(0)] notifyContent:nil success:^{
  217. ws.groupInfo.searchable = 0;
  218. [ws.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  219. } error:^(int error_code) {
  220. [ws.view makeToast:@"设置失败"];
  221. }];
  222. }];
  223. [alertController addAction:cantSearchAction];
  224. [self.navigationController presentViewController:alertController animated:YES completion:nil];
  225. } else if(indexPath.row == 2) {
  226. UIAlertController* alertController = [UIAlertController alertControllerWithTitle:WFCString(@"GroupHistoryMessage") message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  227. // Create cancel action.
  228. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  229. }];
  230. [alertController addAction:cancelAction];
  231. UIAlertAction *openAction = [UIAlertAction actionWithTitle:WFCString(@"GroupHistoryMessageAviable") style:self.groupInfo.historyMessage > 0 ? UIAlertActionStyleDestructive : UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  232. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:ws.groupInfo.target type:Modify_Group_History_Message newValue:@"1" notifyLines:@[@(0)] notifyContent:nil success:^{
  233. ws.groupInfo.historyMessage = 1;
  234. [ws.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  235. } error:^(int error_code) {
  236. [ws.view makeToast:@"设置失败"];
  237. }];
  238. }];
  239. [alertController addAction:openAction];
  240. UIAlertAction *verifyAction = [UIAlertAction actionWithTitle:WFCString(@"GroupHistoryMessageNotAviable") style:self.groupInfo.historyMessage > 0 ? UIAlertActionStyleDefault : UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  241. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:ws.groupInfo.target type:Modify_Group_History_Message newValue:@"0" notifyLines:@[@(0)] notifyContent:nil success:^{
  242. ws.groupInfo.historyMessage = 0;
  243. [ws.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  244. } error:^(int error_code) {
  245. [ws.view makeToast:@"设置失败"];
  246. }];
  247. }];
  248. [alertController addAction:verifyAction];
  249. [self.navigationController presentViewController:alertController animated:YES completion:nil];
  250. }
  251. }
  252. }
  253. @end