TUIGroupPendencyDataProvider.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // TUIGroupPendencyViewModel.m
  3. // TXIMSDK_TUIKit_iOS
  4. //
  5. // Created by annidyfeng on 2019/6/18.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "TUIGroupPendencyDataProvider.h"
  9. #import <TIMCommon/TIMDefine.h>
  10. @interface TUIGroupPendencyDataProvider ()
  11. @property NSArray *dataList;
  12. @property(nonatomic, assign) uint64_t origSeq;
  13. @property(nonatomic, assign) uint64_t seq;
  14. @property(nonatomic, assign) uint64_t timestamp;
  15. @property(nonatomic, assign) uint64_t numPerPage;
  16. @end
  17. @implementation TUIGroupPendencyDataProvider
  18. - (instancetype)init {
  19. self = [super init];
  20. _numPerPage = 100;
  21. _dataList = @[];
  22. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onPendencyChanged:) name:TUIGroupPendencyCellData_onPendencyChanged object:nil];
  23. return self;
  24. }
  25. - (void)dealloc {
  26. [[NSNotificationCenter defaultCenter] removeObserver:self];
  27. }
  28. - (void)onPendencyChanged:(NSNotification *)notification {
  29. int unReadCnt = 0;
  30. for (TUIGroupPendencyCellData *data in self.dataList) {
  31. if (data.isRejectd || data.isAccepted) {
  32. continue;
  33. }
  34. unReadCnt++;
  35. }
  36. self.unReadCnt = unReadCnt;
  37. }
  38. - (void)loadData {
  39. if (self.isLoading) return;
  40. self.isLoading = YES;
  41. @weakify(self);
  42. [[V2TIMManager sharedInstance]
  43. getGroupApplicationList:^(V2TIMGroupApplicationResult *result) {
  44. @strongify(self);
  45. NSMutableArray *list = @[].mutableCopy;
  46. for (V2TIMGroupApplication *item in result.applicationList) {
  47. if ([item.groupID isEqualToString:self.groupId] && item.handleStatus == V2TIM_GROUP_APPLICATION_HANDLE_STATUS_UNHANDLED) {
  48. TUIGroupPendencyCellData *data = [[TUIGroupPendencyCellData alloc] initWithPendency:item];
  49. [list addObject:data];
  50. }
  51. }
  52. self.dataList = list;
  53. self.unReadCnt = (int)list.count;
  54. self.isLoading = NO;
  55. self.hasNextData = NO;
  56. ;
  57. }
  58. fail:nil];
  59. }
  60. - (void)acceptData:(TUIGroupPendencyCellData *)data {
  61. [data accept];
  62. self.unReadCnt--;
  63. }
  64. - (void)removeData:(TUIGroupPendencyCellData *)data {
  65. NSMutableArray *dataList = [NSMutableArray arrayWithArray:self.dataList];
  66. [dataList removeObject:data];
  67. self.dataList = dataList;
  68. [data reject];
  69. self.unReadCnt--;
  70. }
  71. @end