ChatRecordController.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // ChatRecordController.m
  3. // AIIM
  4. //
  5. // Created by qitewei on 2025/5/20.
  6. //
  7. #import "ChatRecordController.h"
  8. #import "chatCellView.h"
  9. #import "UserNetApi.h"
  10. @interface ChatRecordController ()<UITableViewDelegate,UITableViewDataSource>
  11. @property (nonatomic, strong) UIImageView * backgroudImageView;
  12. @property (nonatomic, strong) UITableView * tableView;
  13. @end
  14. @implementation ChatRecordController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. // [self setupRecordData];
  18. [self configUI];
  19. }
  20. - (void)configUI{
  21. [self setNavigationTitle:@"聊天记录"];
  22. [self setNavigationBarTransparent:YES];
  23. [self setNavigationBarBackgroundColor:UIColor.clearColor];
  24. [self setNavigationTitleColor:UIColor.whiteColor font:SYSBFONT(18)];
  25. [self addBarButtonWithImage:kImageMake(@"fanhui") position:BarButtonItemPositionLeft action:@selector(backToChat)];
  26. self.view.backgroundColor = UIColor.blackColor;
  27. [self.view addSubview:self.backgroudImageView];
  28. [self.backgroudImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.top.left.bottom.right.mas_equalTo(0);
  30. }];
  31. [self.view addSubview:self.tableView];
  32. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.top.mas_equalTo(SCREEN_TOP);
  34. make.left.right.bottom.mas_equalTo(0);
  35. }];
  36. }
  37. #pragma mark data
  38. - (void)setupRecordData{
  39. for (ChatMessageModel * model in self.dataArray) {
  40. NSLog(@"fromId:%@",model.fromId);
  41. [UserNetApi getUserinfo_id:model.fromId succ:^(int code, NSDictionary * _Nullable result) {
  42. NSDictionary * dataDict = result[@"data"] ?: @{};
  43. for (ChatMessageModel * item in self.dataArray) {
  44. if ([dataDict[@"id"] isEqualToString:item.fromId]) {
  45. item.avatar = dataDict[@"avatar"];
  46. item.nickName = dataDict[@"name"];
  47. }
  48. }
  49. // if (self.dataArray.lastObject == model) {
  50. //
  51. // }
  52. [self.tableView reloadData];
  53. } fail:^(NSError * _Nonnull error) {
  54. }];
  55. }
  56. }
  57. #pragma mark private
  58. - (void)backToChat{
  59. [self dismissViewControllerAnimated:YES completion:nil];
  60. }
  61. #pragma mark tableview delegate
  62. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  63. return self.dataArray.count;
  64. }
  65. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  66. ChatMessageModel *message = self.dataArray[indexPath.row];
  67. return [chatCellView cellHeightForMessage:message];
  68. }
  69. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  70. chatCellView * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(chatCellView.class) forIndexPath:indexPath];
  71. cell.parentViewController = self;
  72. ChatMessageModel *message = self.dataArray[indexPath.row];
  73. cell.messageModel = message;
  74. return cell;
  75. }
  76. #pragma mark lazy
  77. - (UIImageView *)backgroudImageView{
  78. if (!_backgroudImageView) {
  79. _backgroudImageView = [[UIImageView alloc] initWithImage:kImageMake(@"loginBG")];
  80. }
  81. return _backgroudImageView;
  82. }
  83. - (UITableView *)tableView{
  84. if (!_tableView) {
  85. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  86. _tableView.backgroundColor = UIColor.clearColor;
  87. _tableView.delegate = self;
  88. _tableView.dataSource = self;
  89. [_tableView registerClass:chatCellView.class forCellReuseIdentifier:NSStringFromClass(chatCellView.class)];
  90. }
  91. return _tableView;
  92. }
  93. - (NSMutableArray *)dataArray{
  94. if (!_dataArray) {
  95. _dataArray = [NSMutableArray array];
  96. }
  97. return _dataArray;
  98. }
  99. #pragma mark statusBar
  100. - (UIStatusBarStyle)preferredStatusBarStyle{
  101. return UIStatusBarStyleLightContent;
  102. }
  103. @end