2
0

WFCUGroupFilesViewController.m 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // WFCUGroupFilesViewController.m
  3. // WFChatUIKit
  4. //
  5. // Created by dali on 2020/8/2.
  6. // Copyright © 2020 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUGroupFilesViewController.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. @interface WFCUGroupFilesViewController () <UITableViewDelegate, UITableViewDataSource>
  11. @property(nonatomic, strong)UITableView *tableView;
  12. @property(nonatomic, strong)UIActivityIndicatorView *activityView;
  13. @property(nonatomic, strong)NSMutableArray<WFCCFileRecord *> *fileRecords;
  14. @end
  15. @implementation WFCUGroupFilesViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
  19. self.tableView.dataSource = self;
  20. self.tableView.delegate = self;
  21. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  22. [self.view addSubview:self.tableView];
  23. self.activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  24. self.activityView.center = self.view.center;
  25. [self.view addSubview:self.activityView];
  26. __weak typeof(self)ws = self;
  27. [[WFCCIMService sharedWFCIMService] getConversationFiles:self.conversation beforeMessageUid:0 count:20 success:^(NSArray<WFCCFileRecord *> *files) {
  28. ws.fileRecords = [files mutableCopy];
  29. [ws.tableView reloadData];
  30. ws.activityView.hidden = YES;
  31. } error:^(int error_code) {
  32. NSLog(@"load fire record error %d", error_code);
  33. ws.activityView.hidden = YES;
  34. }];
  35. }
  36. - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
  37. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  38. if (!cell) {
  39. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
  40. }
  41. WFCCFileRecord *record = self.fileRecords[indexPath.row];
  42. cell.textLabel.text = record.name;
  43. cell.detailTextLabel.text = [NSString stringWithFormat:@"from user %@", record.userId];
  44. return cell;
  45. }
  46. - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  47. return self.fileRecords.count;
  48. }
  49. -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  50. if (editingStyle == UITableViewCellEditingStyleDelete) {
  51. WFCCFileRecord *record = self.fileRecords[indexPath.row];
  52. __weak typeof(self) ws = self;
  53. [[WFCCIMService sharedWFCIMService] deleteFileRecord:record.messageUid success:^{
  54. [ws.fileRecords removeObject:record];
  55. [ws.tableView reloadData];
  56. } error:^(int error_code) {
  57. }];
  58. }
  59. }
  60. -(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
  61. return @"delete";
  62. }
  63. @end