WFCUReceiptViewController.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // WFCUReceiptViewController.m
  3. // WFChatUIKit
  4. //
  5. // Created by heavyrain2012 on 2020/5/20.
  6. // Copyright © 2020 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUReceiptViewController.h"
  9. #import "WFCUReadViewController.h"
  10. #import "XLPageViewController.h"
  11. #import "CommonTableViewController.h"
  12. #import "WFCUUtilities.h"
  13. @interface WFCUReceiptViewController () <XLPageViewControllerDelegate, XLPageViewControllerDataSrouce>
  14. @property (nonatomic, strong)NSMutableDictionary<NSString *, NSNumber *> *readDict;
  15. @property (nonatomic, strong)NSMutableArray *readedUserIds;
  16. @property (nonatomic, strong)NSMutableArray *unReadedUserIds;
  17. @property (nonatomic, strong) NSArray *titles;
  18. @property (nonatomic, strong) XLPageViewController *pageViewController;
  19. @end
  20. @implementation WFCUReceiptViewController
  21. - (void)viewDidLoad {
  22. self.view.backgroundColor = [UIColor whiteColor];
  23. if (self.message.conversation.type != Group_Type) {
  24. [self.navigationController popViewControllerAnimated:YES];
  25. return;
  26. }
  27. [super viewDidLoad];
  28. self.view.backgroundColor = [UIColor whiteColor];
  29. self.title = @"消息阅读状态";
  30. self.view.backgroundColor = [UIColor whiteColor];
  31. //配置
  32. XLPageViewControllerConfig *config = [XLPageViewControllerConfig defaultConfig];
  33. // config.showTitleInNavigationBar = true;
  34. config.titleViewStyle = XLPageTitleViewStyleSegmented;
  35. config.separatorLineHidden = true;
  36. //设置缩进
  37. config.titleViewInset = UIEdgeInsetsMake(5, 50, 5, 50);
  38. self.pageViewController = [[XLPageViewController alloc] initWithConfig:config];
  39. CGRect bounds = self.view.bounds;
  40. bounds.origin.y = [WFCUUtilities wf_navigationFullHeight];
  41. bounds.size.height -= ([WFCUUtilities wf_navigationFullHeight] + [WFCUUtilities wf_safeDistanceBottom]);
  42. self.pageViewController.view.frame = bounds;
  43. self.pageViewController.delegate = self;
  44. self.pageViewController.dataSource = self;
  45. [self addChildViewController:self.pageViewController];
  46. [self.view addSubview:self.pageViewController.view];
  47. self.readDict = [[WFCCIMService sharedWFCIMService] getConversationRead:self.message.conversation];
  48. self.readedUserIds = [[NSMutableArray alloc] init];
  49. int64_t sendTime = self.message.serverTime;
  50. [self.readDict enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSNumber * _Nonnull obj, BOOL * _Nonnull stop) {
  51. if ([obj longLongValue] >= sendTime) {
  52. [self.readedUserIds addObject:key];
  53. }
  54. }];
  55. self.unReadedUserIds = [[NSMutableArray alloc] init];
  56. if(self.message.conversation.type == Single_Type) {
  57. if (![self.readedUserIds containsObject:self.message.conversation.target]) {
  58. [self.unReadedUserIds addObject:self.message.conversation.target];
  59. }
  60. } else {
  61. WFCCGroupInfo *groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:self.message.conversation.target refresh:NO];
  62. NSArray<WFCCGroupMember *> *members = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.message.conversation.target forceUpdate:NO];
  63. NSMutableArray<NSString *> *tobeRemoveUserIds = [[NSMutableArray alloc] init];
  64. [self.readedUserIds enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
  65. BOOL exist = NO;
  66. for (WFCCGroupMember *member in members) {
  67. if([member.memberId isEqualToString:obj]) {
  68. if(groupInfo.historyMessage || member.createTime < self.message.serverTime) {
  69. exist = YES;
  70. }
  71. }
  72. }
  73. if(!exist) {
  74. [tobeRemoveUserIds addObject:obj];
  75. }
  76. }];
  77. [self.readedUserIds removeObjectsInArray:tobeRemoveUserIds];
  78. for (WFCCGroupMember *member in members) {
  79. if (![self.readedUserIds containsObject:member.memberId]) {
  80. [self.unReadedUserIds addObject:member.memberId];
  81. }
  82. }
  83. [self.unReadedUserIds removeObjectsInArray:tobeRemoveUserIds];
  84. }
  85. [self.readedUserIds removeObject:self.message.fromUser];
  86. [self.unReadedUserIds removeObject:self.message.fromUser];
  87. self.titles = @[[NSString stringWithFormat:@"已读(%ld)", self.readedUserIds.count], [NSString stringWithFormat:@"未读(%ld)", self.unReadedUserIds.count]];
  88. }
  89. /*
  90. #pragma mark - Navigation
  91. // In a storyboard-based application, you will often want to do a little preparation before navigation
  92. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  93. // Get the new view controller using [segue destinationViewController].
  94. // Pass the selected object to the new view controller.
  95. }
  96. */
  97. #pragma mark TableViewDelegate&DataSource
  98. - (UIViewController *)pageViewController:(XLPageViewController *)pageViewController viewControllerForIndex:(NSInteger)index {
  99. WFCUReadViewController *vc = [[WFCUReadViewController alloc] init];
  100. if(index == 0) {
  101. vc.userIds = self.readedUserIds;
  102. } else {
  103. vc.userIds = self.unReadedUserIds;
  104. }
  105. return vc;
  106. }
  107. - (NSString *)pageViewController:(XLPageViewController *)pageViewController titleForIndex:(NSInteger)index {
  108. return self.titles[index];
  109. }
  110. - (NSInteger)pageViewControllerNumberOfPage {
  111. return self.titles.count;
  112. }
  113. - (void)pageViewController:(XLPageViewController *)pageViewController didSelectedAtIndex:(NSInteger)index {
  114. }
  115. @end