YMCallRecordViewModel.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // YMCallRecordViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/3/20.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMCallRecordViewModel.h"
  9. #import "YMCallRecordModel.h"
  10. #import "YOUPAILCIMSessionVC.h"
  11. @interface YMCallRecordViewModel ()
  12. /// 当前数据数量
  13. @property (nonatomic, assign) NSInteger currentSize;
  14. /// 列表数据
  15. @property (nonatomic, strong, readwrite) NSMutableArray <YMCallRecordCellViewModel*>*listDataArray;
  16. @end
  17. @implementation YMCallRecordViewModel
  18. - (void)ym_initialize{
  19. [super ym_initialize];
  20. self.customNavTitle = @"通话";
  21. self.currentPage = 1;
  22. self.currentSize = 10;
  23. }
  24. - (void)getCallRecordListData {
  25. @weakify(self)
  26. [ZCHUDHelper showWithStatus:@"加载中..."];
  27. [LCHttpHelper requestWithURLString:CallRecordList parameters:@{
  28. @"page":@(self.currentPage),
  29. @"limit":@(self.currentSize)
  30. } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  31. @strongify(self)
  32. [ZCHUDHelper dismiss];
  33. NSDictionary* dict = (NSDictionary*)responseObject;
  34. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  35. if (code == 0) {
  36. NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
  37. NSArray *result = [data arrayValueForKey:@"list" defaultValue:@[]];
  38. if (self.currentPage == 1) {
  39. [self.listDataArray removeAllObjects];
  40. }
  41. NSArray *viewModelArr = [[NSArray yy_modelArrayWithClass:[YMCallRecordModel class] json:result].rac_sequence map:^(YMCallRecordModel * _Nullable model) {
  42. YMCallRecordCellViewModel *viewModel = [[YMCallRecordCellViewModel alloc]initWithParams:@{
  43. ParamsModel:model
  44. }];
  45. return viewModel;
  46. }].array;
  47. [self.listDataArray addObjectsFromArray:viewModelArr];
  48. if(self.currentPage > 0 && self.currentPage % 5 == 0){
  49. [[SDImageCache sharedImageCache] clearMemory];
  50. }
  51. [self.refreshUISubject sendNext:@(result.count < self.currentSize ? YMFooterRefresh_HasNoMoreData : YMFooterRefresh_HasMoreData)];
  52. }else{
  53. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  54. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  55. [self.refreshUISubject sendNext:@(YMRefreshError)];
  56. });
  57. }
  58. } failure:^(NSError *error) {
  59. if(self.currentPage != 1){
  60. self.currentPage--;
  61. }
  62. [ZCHUDHelper showTitle:error.localizedDescription];
  63. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  64. [self.refreshUISubject sendNext:@(YMRefreshError)];
  65. });
  66. }];
  67. }
  68. - (void)gotoPrivateChatWithUserId:(NSInteger)userId{
  69. NIMSession *session = [NIMSession session:stringFormat(@"%ld",userId) type:NIMSessionTypeP2P];
  70. if (session) {
  71. [ZCHUDHelper show];
  72. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  73. [ZCHUDHelper dismiss];
  74. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
  75. vc.type = @"3";
  76. [[YMGlobalUtils getCurrentVC].navigationController pushViewController:vc animated:YES];
  77. }];
  78. }
  79. }
  80. - (NSMutableArray<YMCallRecordCellViewModel *> *)listDataArray{
  81. if (!_listDataArray) {
  82. _listDataArray = [NSMutableArray array];
  83. }
  84. return _listDataArray;
  85. }
  86. @end