// // YMMineBlackListViewController.m // YUMI // // Created by YUMI on 2022/4/25. // #import "XPMineBlackListViewController.h" ///Third #import #import #import "XPMineBlackListTableViewCell.h" #import "XPMineFriendEmptyTableViewCell.h" #import "NSArray+Safe.h" ///Model #import "UserInfoModel.h" ///P #import "XPMineBlackListPresenter.h" #import "XPMineBlackListProtocol.h" @interface XPMineBlackListViewController () ///列表 @property (nonatomic,strong) UITableView *tableView; /// @property (nonatomic,strong) NSMutableArray *datasource; @end @implementation XPMineBlackListViewController - (__kindof id)createPresenter { return [[XPMineBlackListPresenter alloc] init]; } - (void)viewDidLoad { [super viewDidLoad]; NSArray *array = [[NIMSDK sharedSDK].userManager myBlackList]; if (array.count > 0) { NSMutableArray * uids = [NSMutableArray array]; for (int i = 0; i< array.count; i++) { NIMUser * user = [array xpSafeObjectAtIndex:i]; [uids addObject:user.userId]; } [self.presenter getUserListInfo:uids]; } [self initSubViews]; [self initSubViewConstraints]; } #pragma mark - Private Method - (void)initSubViews { self.title = YMLocalizedString(@"XPMineBlackListViewController0"); [self.view addSubview:self.tableView]; } - (void)initSubViewConstraints { [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_equalTo(self.view); }]; } #pragma mark - UITableViewDelegate And UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.datasource.count > 0 ? self.datasource.count : 1; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return self.datasource.count > 0 ? 60 : 500; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (self.datasource.count > 0) { XPMineBlackListTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineBlackListTableViewCell class])]; cell.userInfo = [self.datasource xpSafeObjectAtIndex:indexPath.row]; @kWeakify(self); [cell setHandleTapRemove:^(UserInfoModel * _Nonnull userInfo) { @kStrongify(self); [[NIMSDK sharedSDK].userManager removeFromBlackBlackList:[NSString stringWithFormat:@"%ld", userInfo.uid] completion:^(NSError * _Nullable error) { if (error == nil) { [self.datasource removeObject:userInfo]; [self.tableView reloadData]; } }]; }]; return cell; } XPMineFriendEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineFriendEmptyTableViewCell class])]; return cell; } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ if (self.datasource.count > 0) { return UITableViewCellEditingStyleDelete; } return UITableViewCellEditingStyleNone; } -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{ return YMLocalizedString(@"XPMineBlackListViewController1"); } -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if (editingStyle ==UITableViewCellEditingStyleDelete){ if (self.datasource.count > 0) { UserInfoModel *userInfo = [self.datasource xpSafeObjectAtIndex:indexPath.row]; [[NIMSDK sharedSDK].userManager removeFromBlackBlackList:[NSString stringWithFormat:@"%ld", userInfo.uid] completion:^(NSError * _Nullable error) { if (error == nil) { [self.datasource removeObject:userInfo]; [self.tableView reloadData]; } }]; } } } #pragma mark - XPMineBlackListPrototcol - (void)getUserListInfoSuccess:(NSArray *)array { [self.datasource addObjectsFromArray:array]; [self.tableView reloadData]; } #pragma mark - Getters And Setters - (UITableView *)tableView { if (!_tableView) { _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.tableFooterView = [UIView new]; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.backgroundColor = [UIColor clearColor]; if (@available(iOS 11.0, *)) { _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } [_tableView registerClass:[XPMineBlackListTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineBlackListTableViewCell class])]; [_tableView registerClass:[XPMineFriendEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineFriendEmptyTableViewCell class])]; } return _tableView; } - (NSMutableArray *)datasource { if (!_datasource) { _datasource = [NSMutableArray array]; } return _datasource; } @end