MOFollowRecordTool.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // MOFollowRecordTool.m
  3. // MiMoLive
  4. //
  5. // Created by MiMo on 2025/6/16.
  6. //
  7. #import "MOFollowRecordTool.h"
  8. #define kShowFollwAnchorViewKey @"kShowFollwAnchorViewKey"
  9. @implementation MOFollowRecordTool
  10. + (BOOL)canShowFollowViewWithAnchorId:(NSString *)anchorId scene:(NSNumber *)scene {
  11. NSArray *followModelArray = (NSArray *)[[MODataCache sharedYYCache] objectForKey:kShowFollwAnchorViewKey];
  12. __block MOFollowAnchorModel *targetModel = nil;
  13. [followModelArray enumerateObjectsUsingBlock:^(MOFollowAnchorModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  14. if ([obj.anchorId isEqualToString:anchorId]) {
  15. targetModel = obj;
  16. *stop = YES;
  17. }
  18. }];
  19. if (targetModel) {
  20. if ([targetModel.sceneArray containsObject:scene]) {//已经触发过的场景,不再触发
  21. return NO;
  22. }
  23. if (targetModel.sceneArray.count >= 2) {//当天同一主播只能触发两个场景
  24. return NO;
  25. }
  26. } else {
  27. if (followModelArray.count >= 3) {//今天之内触发过3个主播了
  28. return NO;
  29. }
  30. }
  31. return YES;
  32. }
  33. + (void)saveFollowViewWithAnchorId:(NSString *)anchorId scene:(NSNumber *)scene {
  34. NSArray *followModelArray = (NSArray *)[[MODataCache sharedYYCache] objectForKey:kShowFollwAnchorViewKey];
  35. NSMutableArray *tempArray = [NSMutableArray array];
  36. __block MOFollowAnchorModel *targetModel = nil;
  37. [followModelArray enumerateObjectsUsingBlock:^(MOFollowAnchorModel *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  38. if ([NSDate isSameDay:[NSDate date] otherDate:obj.triggerDate]) {//把符合当天条件的对象加入到数组中
  39. [tempArray addObject:obj];
  40. if ([obj.anchorId isEqualToString:anchorId]) {
  41. targetModel = obj;
  42. }
  43. }
  44. }];
  45. if (targetModel) {
  46. if (![targetModel.sceneArray containsObject:scene]) {//数组已经存在对应的主播,添加场景数组
  47. NSMutableArray *sceneArray = [NSMutableArray arrayWithArray:targetModel.sceneArray];
  48. [sceneArray addObject:scene];
  49. targetModel.sceneArray = sceneArray;
  50. }
  51. } else {//新的主播
  52. targetModel = [[MOFollowAnchorModel alloc] init];
  53. targetModel.triggerDate = [NSDate date];
  54. targetModel.anchorId = anchorId;
  55. NSMutableArray *sceneArray = [NSMutableArray array];
  56. [sceneArray addObject:scene];
  57. targetModel.sceneArray = sceneArray;
  58. [tempArray addObject:targetModel];
  59. }
  60. [[MODataCache sharedYYCache] setObject:[tempArray copy] forKey:kShowFollwAnchorViewKey];
  61. }
  62. @end