// // YMChatNotificationViewModel.m // MSYOUPAI // // Created by YoMi on 2024/2/21. // Copyright © 2024 MS. All rights reserved. // #import "YMChatNotificationViewModel.h" @interface YMChatNotificationViewModel () /// 分组数据 @property (nonatomic, strong, readwrite) NSArray *sectionDataArray; /// 消息通知功能操作 @property (nonatomic, strong, readwrite) RACSubject *chatNotificationFunctionsOperationSubject; /// 是否开启缘分匹配 @property (nonatomic, assign) BOOL isOpenPredestinedAffinity; /// 是否开启点赞通知 @property (nonatomic, assign) BOOL isOpenLikesNotification; @end @implementation YMChatNotificationViewModel - (void)ym_initialize{ [super ym_initialize]; self.customNavTitle = @"消息通知"; @weakify(self) [[self.chatNotificationFunctionsOperationSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable value) { @strongify(self) switch ([value intValue]) { case YMChatNotificationFunctionsTypePersonalizedRecommendation: { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ if ([[OCUserDefaults objectForKey:kIS_HIDE_PERSONALIZED_RECOMMENDATION_TIPS] boolValue]) { [OCUserDefaults setBool:NO forKey:kIS_HIDE_PERSONALIZED_RECOMMENDATION_TIPS]; [OCUserDefaults synchronize]; } else { [OCUserDefaults setBool:YES forKey:kIS_HIDE_PERSONALIZED_RECOMMENDATION_TIPS]; [OCUserDefaults synchronize]; } dispatch_async(dispatch_get_main_queue(), ^{ [self getChatNotificationListData]; }); }); } break; case YMChatNotificationFunctionsTypePredestinedAffinity: { [self switchPredestinedAffinityInfo]; } break; case YMChatNotificationFunctionsTypeLikesNotification: { [self switchLikesNotificationInfo]; } break; case YMChatNotificationFunctionsTypeSound: { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ if ([LCSaveData getIMMsgVoice]) { [LCSaveData saveIMMsgVoice:NO]; }else{ [LCSaveData saveIMMsgVoice:YES]; } dispatch_async(dispatch_get_main_queue(), ^{ [self getChatNotificationListData]; }); }); } break; case YMChatNotificationFunctionsTypeVibrate: { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ if ([LCSaveData getIMMsgShake]) { [LCSaveData saveIMMsgShake:NO]; }else{ [LCSaveData saveIMMsgShake:YES]; } dispatch_async(dispatch_get_main_queue(), ^{ [self getChatNotificationListData]; }); }); } break; default: break; } }]; } - (void)getChatNotificationListData{ NSArray *dataArray = @[]; if ([self isFemaleGender]) { dataArray = @[ @{ @"sectionHeader":@"推荐设置", @"sectionFooter":@"关闭后,将无法使用缘分页的推荐以及动态页的推荐和关注功能", @"isHideSectionHeader":@(NO), @"isHideSectionFooter":@(NO), @"dataSource":@[ @{ @"title":@"个性化推荐", @"isOpen":@([[OCUserDefaults objectForKey:kIS_HIDE_PERSONALIZED_RECOMMENDATION_TIPS] boolValue]), ParamsCategoryType:@(YMChatNotificationFunctionsTypePersonalizedRecommendation), } ] }, @{ @"sectionHeader":@"", @"sectionFooter":@"", @"isHideSectionHeader":@(YES), @"isHideSectionFooter":@(YES), @"dataSource":@[ @{ @"title":@"点赞通知", @"isOpen":@(YES), ParamsCategoryType:@(YMChatNotificationFunctionsTypeLikesNotification), } ] }, @{ @"sectionHeader":@"显示设置", @"sectionFooter":@"", @"isHideSectionHeader":@(NO), @"isHideSectionFooter":@(YES), @"dataSource":@[ @{ @"title":@"声音", @"isOpen":@([LCSaveData getIMMsgVoice] ? YES : NO), ParamsCategoryType:@(YMChatNotificationFunctionsTypeSound), }, @{ @"title":@"振动", @"isOpen":@([LCSaveData getIMMsgShake] ? YES : NO), ParamsCategoryType:@(YMChatNotificationFunctionsTypeVibrate), } ] }, ]; } else { dataArray = @[ @{ @"sectionHeader":@"推荐设置", @"sectionFooter":@"关闭后,将无法使用缘分页的推荐以及动态页的推荐和关注功能", @"isHideSectionHeader":@(NO), @"isHideSectionFooter":@(NO), @"dataSource":@[ @{ @"title":@"个性化推荐", @"isOpen":@([[OCUserDefaults objectForKey:kIS_HIDE_PERSONALIZED_RECOMMENDATION_TIPS] boolValue]), ParamsCategoryType:@(YMChatNotificationFunctionsTypePersonalizedRecommendation), } ] }, @{ @"sectionHeader":@"", @"sectionFooter":stringFormat(@"开启后,%@将用大数据为您匹配有缘人,牵线成功会发送缘分消息,关闭后,将不会收到缘分牵线。",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]), @"isHideSectionHeader":@(YES), @"isHideSectionFooter":@(NO), @"dataSource":@[ @{ @"title":@"缘分牵线", @"isOpen":@(self.isOpenPredestinedAffinity == YES ? YES : NO), ParamsCategoryType:@(YMChatNotificationFunctionsTypePredestinedAffinity), } ] }, @{ @"sectionHeader":@"", @"sectionFooter":@"", @"isHideSectionHeader":@(YES), @"isHideSectionFooter":@(YES), @"dataSource":@[ @{ @"title":@"点赞通知", @"isOpen":@(self.isOpenLikesNotification == YES ? YES : NO), ParamsCategoryType:@(YMChatNotificationFunctionsTypeLikesNotification), } ] }, @{ @"sectionHeader":@"显示设置", @"sectionFooter":@"", @"isHideSectionHeader":@(NO), @"isHideSectionFooter":@(YES), @"dataSource":@[ @{ @"title":@"声音", @"isOpen":@([LCSaveData getIMMsgVoice] ? YES : NO), ParamsCategoryType:@(YMChatNotificationFunctionsTypeSound), }, @{ @"title":@"振动", @"isOpen":@([LCSaveData getIMMsgShake] ? YES : NO), ParamsCategoryType:@(YMChatNotificationFunctionsTypeVibrate), } ] }, ]; } self.sectionDataArray = [dataArray.rac_sequence map:^(NSDictionary * _Nullable dic) { YMChatNotificationSectionViewModel *viewModel = [[YMChatNotificationSectionViewModel alloc]initWithParams:@{ ParamsModel:dic }]; return viewModel; }].array; [self.refreshUISubject sendNext:@(YMRefreshUI)]; } - (void)getPredestinedAffinityInfo{ @weakify(self) [LCHttpHelper requestWithURLString:Mine_getFateMatch parameters:nil needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self) NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSInteger fateMatch = [data integerValueForKey:@"fate_match" defaultValue:0]; if (fateMatch == 1) { self.isOpenPredestinedAffinity = NO; } else { self.isOpenPredestinedAffinity = YES; } dispatch_async(dispatch_get_main_queue(), ^{ [self getChatNotificationListData]; }); }); } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (void)switchPredestinedAffinityInfo{ NSInteger status = self.isOpenPredestinedAffinity == YES ? 1 : 0; @weakify(self) [LCHttpHelper requestWithURLString:Mine_setFateMatch parameters:@{ @"fate_match":@(status) } needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self) NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { if (status == 1) { [ZCHUDHelper showTitle:@"关闭缘分牵线"]; self.isOpenPredestinedAffinity = NO; }else{ [ZCHUDHelper showTitle:@"打开缘分牵线"]; self.isOpenPredestinedAffinity = YES; } [self getChatNotificationListData]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (void)getLikesNotificationInfo{ @weakify(self) [LCHttpHelper requestWithURLString:Mine_getLikesNotification parameters:nil needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self) NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}]; // NSInteger fateMatch = [data integerValueForKey:@"fate_match" defaultValue:1] // if (fateMatch == 1) { // self.isOpenPredestinedAffinity = NO; // } else { // self.isOpenPredestinedAffinity = YES; // } [self getChatNotificationListData]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (void)switchLikesNotificationInfo{ NSInteger status = self.isOpenLikesNotification == YES ? 1 : 0; @weakify(self) [LCHttpHelper requestWithURLString:Mine_setLikesNotification parameters:@{ @"status":@(status) } needToken:YES type:HttpRequestTypePost success:^(id responseObject) { @strongify(self) NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code == 0) { if (status == 1) { [ZCHUDHelper showTitle:@"关闭点赞通知"]; self.isOpenLikesNotification = NO; }else{ [ZCHUDHelper showTitle:@"打开点赞通知"]; self.isOpenLikesNotification = YES; } [self getChatNotificationListData]; } } failure:^(NSError *error) { [ZCHUDHelper showTitle:error.localizedDescription]; }]; } - (RACSubject *)chatNotificationFunctionsOperationSubject{ if (!_chatNotificationFunctionsOperationSubject) { _chatNotificationFunctionsOperationSubject = [RACSubject subject]; } return _chatNotificationFunctionsOperationSubject; } @end