123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- //
- // ManagerTableViewController.m
- // WFChatUIKit
- //
- // Created by heavyrain lee on 2019/6/26.
- // Copyright © 2019 WildFireChat. All rights reserved.
- //
- #import "ManagerTableViewController.h"
- #import <SDWebImage/SDWebImage.h>
- #import "WFCUContactListViewController.h"
- #import "WFCUImage.h"
- #import "UIView+Toast.h"
- @interface ManagerTableViewController () <UITableViewDelegate, UITableViewDataSource>
- @property(nonatomic, strong)UITableView *tableView;
- @property(nonatomic, strong)NSMutableArray<WFCCGroupMember *> *managerList;
- @end
- @implementation ManagerTableViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.title = WFCString(@"ManagerSetting");
-
- [self loadManagerList];
- self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
- if (@available(iOS 15, *)) {
- self.tableView.sectionHeaderTopPadding = 0;
- }
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
-
- self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
- [self.tableView reloadData];
-
- [self.view addSubview:self.tableView];
-
- __weak typeof(self)ws = self;
- [[NSNotificationCenter defaultCenter] addObserverForName:kGroupMemberUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
- if ([ws.groupInfo.target isEqualToString:note.object]) {
- [ws loadManagerList];
- [ws.tableView reloadData];
- }
- }];
- }
- - (void)loadManagerList {
- NSArray *memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupInfo.target forceUpdate:YES];
- self.managerList = [[NSMutableArray alloc] init];
- for (WFCCGroupMember *member in memberList) {
- if (member.type == Member_Type_Manager) {
- [self.managerList addObject:member];
- }
- }
- }
- - (void)selectMemberToAdd {
- WFCUContactListViewController *pvc = [[WFCUContactListViewController alloc] init];
- pvc.selectContact = YES;
- pvc.multiSelect = YES;
- __weak typeof(self)ws = self;
- pvc.selectResult = ^(NSArray<NSString *> *contacts) {
- [[WFCCIMService sharedWFCIMService] setGroupManager:self.groupInfo.target isSet:YES memberIds:contacts notifyLines:@[@(0)] notifyContent:nil success:^{
- for (NSString *memberId in contacts) {
- WFCCGroupMember *member = [[WFCCIMService sharedWFCIMService] getGroupMember:ws.groupInfo.target memberId:memberId];
- if (member) {
- member.type = Member_Type_Manager;
- [ws.managerList addObject:member];
- }
- }
- if (contacts.count) {
- [ws.tableView reloadData];
- }
- } error:^(int error_code) {
-
- }];
- };
- NSMutableArray *candidateUsers = [[NSMutableArray alloc] init];
- NSArray *memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupInfo.target forceUpdate:NO];
- for (WFCCGroupMember *member in memberList) {
- if ((member.type == Member_Type_Normal || member.type == Member_Type_Muted || member.type == Member_Type_Allowed) && ![member.memberId isEqualToString:self.groupInfo.owner]) {
- [candidateUsers addObject:member.memberId];
- }
- }
- if([candidateUsers count]) {
- pvc.candidateUsers = candidateUsers;
- UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:pvc];
- [self.navigationController presentViewController:navi animated:YES completion:nil];
- } else {
- [self.view makeToast:@"成员已全部添加"];
- }
- }
- - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
- }
-
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- cell.accessoryView = nil;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
-
- if (indexPath.section == 0) {
- WFCCUserInfo *owner = [[WFCCIMService sharedWFCIMService] getUserInfo:self.groupInfo.owner refresh:NO];
- [cell.imageView sd_setImageWithURL:[NSURL URLWithString:[owner.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
- cell.textLabel.text = owner.displayName;
- } else if(indexPath.section == 1) {
- if (indexPath.row == 0) {
- cell.imageView.image = [WFCUImage imageNamed:@"plus"];
- cell.textLabel.text = WFCString(@"AddManager");
- } else {
- WFCCUserInfo *manager = [[WFCCIMService sharedWFCIMService] getUserInfo:[self.managerList objectAtIndex:indexPath.row-1].memberId refresh:NO];
- [cell.imageView sd_setImageWithURL:[NSURL URLWithString:[manager.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage: [WFCUImage imageNamed:@"PersonalChat"]];
- cell.textLabel.text = manager.displayName;
- }
- }
-
-
- return cell;
- }
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 0 || (indexPath.section == 1 && indexPath.row == 0)) {
- return NO;
- }
- return YES;
- }
- - (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:WFCString(@"RemoveManager") handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
- __weak typeof(self)ws = self;
- [[WFCCIMService sharedWFCIMService] setGroupManager:self.groupInfo.target isSet:NO memberIds:@[[self.managerList objectAtIndex:indexPath.row-1].memberId] notifyLines:@[@(0)] notifyContent:nil success:^{
- for (WFCCGroupMember *member in ws.managerList) {
- if ([member.memberId isEqualToString:[ws.managerList objectAtIndex:indexPath.row-1].memberId]) {
- [ws.managerList removeObject:member];
- [ws.tableView reloadData];
- break;
- }
- }
- } error:^(int error_code) {
-
- }];
- }];
- UITableViewRowAction *editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:WFCString(@"Cancel") handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
- NSLog(@"点击了编辑");
- }];
- editAction.backgroundColor = [UIColor grayColor];
- return @[deleteAction, editAction];
- }
- - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if (section == 0) {
- return 1;
- } else if(section == 1) {
- return self.managerList.count+1;
- }
- return 0;
- }
- -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- if (section == 0) {
- return WFCString(@"GroupOwner");
- } else if(section == 1) {
- return WFCString(@"Manager");
- }
- return nil;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 30.f;
- }
- -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 0.f;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 2; //成员管理,加群设置
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 0) {
-
- } else if(indexPath.section == 1) {
- if (indexPath.row == 0) {
- [self selectMemberToAdd];
- } else {
-
- }
- }
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- @end
|