123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- //
- // 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 <YMChatNotificationSectionViewModel*>*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
|