WFCUReadViewController.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // WFCUReadViewController.m
  3. // WFChatUIKit
  4. //
  5. // Created by Rain on 2023/3/25.
  6. // Copyright © 2023 Tom Lee. All rights reserved.
  7. //
  8. #import "WFCUReadViewController.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import <SDWebImage/SDWebImage.h>
  11. #import "WFCUImage.h"
  12. #import "WFCUGeneralImageTextTableViewCell.h"
  13. @interface WFCUReadViewController () <UITableViewDelegate, UITableViewDataSource>
  14. @property(nonatomic, strong)UITableView *tableView;
  15. @end
  16. #define CELL_HEIGHT 56
  17. @implementation WFCUReadViewController
  18. - (void)viewDidLoad {
  19. [super viewDidLoad];
  20. self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
  21. self.tableView.dataSource = self;
  22. self.tableView.delegate = self;
  23. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  24. if (@available(iOS 15, *)) {
  25. self.tableView.sectionHeaderTopPadding = 0;
  26. }
  27. [self.view addSubview:self.tableView];
  28. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUserInfoUpdated:) name:kUserInfoUpdated object:nil];
  29. }
  30. - (void)onUserInfoUpdated:(NSNotification *)notification {
  31. NSArray<WFCCUserInfo *> *userInfoList = notification.userInfo[@"userInfoList"];
  32. for (WFCCUserInfo *userInfo in userInfoList) {
  33. if([self.userIds containsObject:userInfo.userId]) {
  34. [self.tableView reloadData];
  35. break;
  36. }
  37. }
  38. }
  39. #pragma mark - UITableViewDataSource
  40. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  41. return self.userIds.count;
  42. }
  43. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  44. WFCUGeneralImageTextTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
  45. if(!cell) {
  46. cell = [[WFCUGeneralImageTextTableViewCell alloc] initWithReuseIdentifier:@"cell" cellHeight:CELL_HEIGHT];
  47. }
  48. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.userIds[indexPath.row] inGroup:self.groupId refresh:NO];
  49. [cell.portraitIV sd_setImageWithURL:[NSURL URLWithString:userInfo.portrait] placeholderImage:[WFCUImage imageNamed:@"PersonalChat"]];
  50. NSString *name = userInfo.friendAlias;
  51. if(!name.length) {
  52. name = userInfo.groupAlias;
  53. if(!name.length) {
  54. name = userInfo.displayName;
  55. if(!name.length) {
  56. name = self.userIds[indexPath.row];
  57. }
  58. }
  59. }
  60. cell.titleLable.text = name;
  61. return cell;
  62. }
  63. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  64. return CELL_HEIGHT;
  65. }
  66. - (void)dealloc {
  67. [[NSNotificationCenter defaultCenter] removeObserver:self];
  68. }
  69. @end