| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- //
- // MOFollowRecordTool.m
- // MiMoLive
- //
- // Created by MiMo on 2025/6/16.
- //
- #import "MOFollowRecordTool.h"
- #define kShowFollwAnchorViewKey @"kShowFollwAnchorViewKey"
- @implementation MOFollowRecordTool
- + (BOOL)canShowFollowViewWithAnchorId:(NSString *)anchorId scene:(NSNumber *)scene {
-
- NSArray *followModelArray = (NSArray *)[[MODataCache sharedYYCache] objectForKey:kShowFollwAnchorViewKey];
-
- __block MOFollowAnchorModel *targetModel = nil;
- [followModelArray enumerateObjectsUsingBlock:^(MOFollowAnchorModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if ([obj.anchorId isEqualToString:anchorId]) {
- targetModel = obj;
- *stop = YES;
- }
- }];
-
- if (targetModel) {
- if ([targetModel.sceneArray containsObject:scene]) {//已经触发过的场景,不再触发
- return NO;
- }
- if (targetModel.sceneArray.count >= 2) {//当天同一主播只能触发两个场景
- return NO;
- }
-
- } else {
- if (followModelArray.count >= 3) {//今天之内触发过3个主播了
- return NO;
- }
- }
-
- return YES;
- }
- + (void)saveFollowViewWithAnchorId:(NSString *)anchorId scene:(NSNumber *)scene {
-
- NSArray *followModelArray = (NSArray *)[[MODataCache sharedYYCache] objectForKey:kShowFollwAnchorViewKey];
- NSMutableArray *tempArray = [NSMutableArray array];
-
- __block MOFollowAnchorModel *targetModel = nil;
- [followModelArray enumerateObjectsUsingBlock:^(MOFollowAnchorModel *_Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if ([NSDate isSameDay:[NSDate date] otherDate:obj.triggerDate]) {//把符合当天条件的对象加入到数组中
- [tempArray addObject:obj];
- if ([obj.anchorId isEqualToString:anchorId]) {
- targetModel = obj;
- }
- }
- }];
-
- if (targetModel) {
- if (![targetModel.sceneArray containsObject:scene]) {//数组已经存在对应的主播,添加场景数组
- NSMutableArray *sceneArray = [NSMutableArray arrayWithArray:targetModel.sceneArray];
- [sceneArray addObject:scene];
- targetModel.sceneArray = sceneArray;
- }
- } else {//新的主播
- targetModel = [[MOFollowAnchorModel alloc] init];
- targetModel.triggerDate = [NSDate date];
- targetModel.anchorId = anchorId;
- NSMutableArray *sceneArray = [NSMutableArray array];
- [sceneArray addObject:scene];
- targetModel.sceneArray = sceneArray;
- [tempArray addObject:targetModel];
- }
-
- [[MODataCache sharedYYCache] setObject:[tempArray copy] forKey:kShowFollwAnchorViewKey];
- }
- @end
|