WFCUBlackListViewController.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #import "WFCUImage.h"
  12. @interface WFCUBlackListViewController () <UITableViewDelegate, UITableViewDataSource>
  13. @property (nonatomic, strong) UITableView *tableView;
  14. @property (nonatomic, strong) NSMutableArray *dataArr;
  15. @end
  16. @implementation WFCUBlackListViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.title = WFCString(@"Blacklist");
  20. self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
  21. self.tableView.delegate = self;
  22. self.tableView.dataSource = self;
  23. if (@available(iOS 15, *)) {
  24. self.tableView.sectionHeaderTopPadding = 0;
  25. }
  26. self.dataArr = [[[WFCCIMService sharedWFCIMService] getBlackList:YES] mutableCopy];
  27. [self.tableView reloadData];
  28. [self.view addSubview:self.tableView];
  29. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  30. }
  31. #pragma mark - UITableViewDelegate
  32. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  33. return 48;
  34. }
  35. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  36. if (editingStyle == UITableViewCellEditingStyleDelete) {
  37. NSString *userId = [self.dataArr objectAtIndex:indexPath.row];
  38. __weak typeof(self) ws = self;
  39. [[WFCCIMService sharedWFCIMService] setBlackList:userId isBlackListed:NO success:^{
  40. [ws.dataArr removeObject:userId];
  41. [ws.tableView reloadData];
  42. } error:^(int error_code) {
  43. }];
  44. }
  45. }
  46. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
  47. return WFCString(@"Delete");
  48. }
  49. #pragma mark - UITableViewDataSource
  50. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  51. return self.dataArr.count;
  52. }
  53. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  54. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[self.dataArr objectAtIndex:indexPath.row] refresh:NO];
  55. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  56. if (!cell) {
  57. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  58. }
  59. [cell.imageView sd_setImageWithURL:[NSURL URLWithString:[userInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[WFCUImage imageNamed:@"PersonalChat"]];
  60. cell.textLabel.text = userInfo.displayName;
  61. return cell;
  62. }
  63. @end