WFCUBlackListViewController.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // WFCUBlackListViewController.m
  3. // WFChatUIKit
  4. //
  5. // Created by Heavyrain.Lee on 2019/7/31.
  6. // Copyright © 2019 Wildfire Chat. All rights reserved.
  7. //
  8. #import "WFCUBlackListViewController.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import <SDWebImage/SDWebImage.h>
  11. @interface WFCUBlackListViewController () <UITableViewDelegate, UITableViewDataSource>
  12. @property (nonatomic, strong) UITableView *tableView;
  13. @property (nonatomic, strong) NSMutableArray *dataArr;
  14. @end
  15. @implementation WFCUBlackListViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. self.title = WFCString(@"Blacklist");
  19. self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
  20. self.tableView.delegate = self;
  21. self.tableView.dataSource = self;
  22. self.dataArr = [[[WFCCIMService sharedWFCIMService] getBlackList:YES] mutableCopy];
  23. [self.tableView reloadData];
  24. [self.view addSubview:self.tableView];
  25. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  26. }
  27. #pragma mark - UITableViewDelegate
  28. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  29. return 48;
  30. }
  31. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  32. if (editingStyle == UITableViewCellEditingStyleDelete) {
  33. NSString *userId = [self.dataArr objectAtIndex:indexPath.row];
  34. __weak typeof(self) ws = self;
  35. [[WFCCIMService sharedWFCIMService] setBlackList:userId isBlackListed:NO success:^{
  36. [ws.dataArr removeObject:userId];
  37. [ws.tableView reloadData];
  38. } error:^(int error_code) {
  39. }];
  40. }
  41. }
  42. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
  43. return WFCString(@"Delete");
  44. }
  45. #pragma mark - UITableViewDataSource
  46. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  47. return self.dataArr.count;
  48. }
  49. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  50. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[self.dataArr objectAtIndex:indexPath.row] refresh:NO];
  51. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  52. if (!cell) {
  53. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  54. }
  55. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:[userInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[UIImage imageNamed:@"PersonalChat"]];
  56. cell.textLabel.text = userInfo.displayName;
  57. return cell;
  58. }
  59. @end