123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- //
- // YMCallRecordViewModel.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/3/20.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMCallRecordViewModel.h"
- #import "YMCallRecordModel.h"
- #import "YOUPAILCIMSessionVC.h"
- @interface YMCallRecordViewModel ()
- /// 当前数据数量
- @property (nonatomic, assign) NSInteger currentSize;
- /// 列表数据
- @property (nonatomic, strong, readwrite) NSMutableArray <YMCallRecordCellViewModel*>*listDataArray;
- @end
- @implementation YMCallRecordViewModel
- - (void)ym_initialize{
- [super ym_initialize];
- self.customNavTitle = @"通话";
- self.currentPage = 1;
- self.currentSize = 10;
- }
- - (void)getCallRecordListData {
- @weakify(self)
- [ZCHUDHelper showWithStatus:@"加载中..."];
- [LCHttpHelper requestWithURLString:CallRecordList parameters:@{
- @"page":@(self.currentPage),
- @"limit":@(self.currentSize)
- } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- @strongify(self)
- [ZCHUDHelper dismiss];
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
- NSArray *result = [data arrayValueForKey:@"list" defaultValue:@[]];
- if (self.currentPage == 1) {
- [self.listDataArray removeAllObjects];
- }
- NSArray *viewModelArr = [[NSArray yy_modelArrayWithClass:[YMCallRecordModel class] json:result].rac_sequence map:^(YMCallRecordModel * _Nullable model) {
- YMCallRecordCellViewModel *viewModel = [[YMCallRecordCellViewModel alloc]initWithParams:@{
- ParamsModel:model
- }];
-
- return viewModel;
- }].array;
-
- [self.listDataArray addObjectsFromArray:viewModelArr];
-
- if(self.currentPage > 0 && self.currentPage % 5 == 0){
- [[SDImageCache sharedImageCache] clearMemory];
- }
-
- [self.refreshUISubject sendNext:@(result.count < self.currentSize ? YMFooterRefresh_HasNoMoreData : YMFooterRefresh_HasMoreData)];
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.refreshUISubject sendNext:@(YMRefreshError)];
- });
- }
-
- } failure:^(NSError *error) {
- if(self.currentPage != 1){
- self.currentPage--;
- }
- [ZCHUDHelper showTitle:error.localizedDescription];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.refreshUISubject sendNext:@(YMRefreshError)];
- });
- }];
- }
- - (void)gotoPrivateChatWithUserId:(NSInteger)userId{
- NIMSession *session = [NIMSession session:stringFormat(@"%ld",userId) type:NIMSessionTypeP2P];
- if (session) {
- [ZCHUDHelper show];
- [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
- [ZCHUDHelper dismiss];
- YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
- vc.type = @"3";
- [[YMGlobalUtils getCurrentVC].navigationController pushViewController:vc animated:YES];
- }];
- }
- }
- - (NSMutableArray<YMCallRecordCellViewModel *> *)listDataArray{
- if (!_listDataArray) {
- _listDataArray = [NSMutableArray array];
- }
- return _listDataArray;
- }
- @end
|