YMChatNotificationViewModel.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. //
  2. // YMChatNotificationViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/21.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMChatNotificationViewModel.h"
  9. @interface YMChatNotificationViewModel ()
  10. /// 分组数据
  11. @property (nonatomic, strong, readwrite) NSArray <YMChatNotificationSectionViewModel*>*sectionDataArray;
  12. /// 消息通知功能操作
  13. @property (nonatomic, strong, readwrite) RACSubject *chatNotificationFunctionsOperationSubject;
  14. /// 是否开启缘分匹配
  15. @property (nonatomic, assign) BOOL isOpenPredestinedAffinity;
  16. /// 是否开启点赞通知
  17. @property (nonatomic, assign) BOOL isOpenLikesNotification;
  18. @end
  19. @implementation YMChatNotificationViewModel
  20. - (void)ym_initialize{
  21. [super ym_initialize];
  22. self.customNavTitle = @"消息通知";
  23. @weakify(self)
  24. [[self.chatNotificationFunctionsOperationSubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable value) {
  25. @strongify(self)
  26. switch ([value intValue]) {
  27. case YMChatNotificationFunctionsTypePersonalizedRecommendation:
  28. {
  29. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  30. if ([[OCUserDefaults objectForKey:kIS_HIDE_PERSONALIZED_RECOMMENDATION_TIPS] boolValue]) {
  31. [OCUserDefaults setBool:NO forKey:kIS_HIDE_PERSONALIZED_RECOMMENDATION_TIPS];
  32. [OCUserDefaults synchronize];
  33. } else {
  34. [OCUserDefaults setBool:YES forKey:kIS_HIDE_PERSONALIZED_RECOMMENDATION_TIPS];
  35. [OCUserDefaults synchronize];
  36. }
  37. dispatch_async(dispatch_get_main_queue(), ^{
  38. [self getChatNotificationListData];
  39. });
  40. });
  41. }
  42. break;
  43. case YMChatNotificationFunctionsTypePredestinedAffinity:
  44. {
  45. [self switchPredestinedAffinityInfo];
  46. }
  47. break;
  48. case YMChatNotificationFunctionsTypeLikesNotification:
  49. {
  50. [self switchLikesNotificationInfo];
  51. }
  52. break;
  53. case YMChatNotificationFunctionsTypeSound:
  54. {
  55. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  56. if ([LCSaveData getIMMsgVoice]) {
  57. [LCSaveData saveIMMsgVoice:NO];
  58. }else{
  59. [LCSaveData saveIMMsgVoice:YES];
  60. }
  61. dispatch_async(dispatch_get_main_queue(), ^{
  62. [self getChatNotificationListData];
  63. });
  64. });
  65. }
  66. break;
  67. case YMChatNotificationFunctionsTypeVibrate:
  68. {
  69. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  70. if ([LCSaveData getIMMsgShake]) {
  71. [LCSaveData saveIMMsgShake:NO];
  72. }else{
  73. [LCSaveData saveIMMsgShake:YES];
  74. }
  75. dispatch_async(dispatch_get_main_queue(), ^{
  76. [self getChatNotificationListData];
  77. });
  78. });
  79. }
  80. break;
  81. default:
  82. break;
  83. }
  84. }];
  85. }
  86. - (void)getChatNotificationListData{
  87. NSArray *dataArray = @[];
  88. if ([self isFemaleGender]) {
  89. dataArray = @[
  90. @{
  91. @"sectionHeader":@"推荐设置",
  92. @"sectionFooter":@"关闭后,将无法使用缘分页的推荐以及动态页的推荐和关注功能",
  93. @"isHideSectionHeader":@(NO),
  94. @"isHideSectionFooter":@(NO),
  95. @"dataSource":@[
  96. @{
  97. @"title":@"个性化推荐",
  98. @"isOpen":@([[OCUserDefaults objectForKey:kIS_HIDE_PERSONALIZED_RECOMMENDATION_TIPS] boolValue]),
  99. ParamsCategoryType:@(YMChatNotificationFunctionsTypePersonalizedRecommendation),
  100. }
  101. ]
  102. },
  103. @{
  104. @"sectionHeader":@"",
  105. @"sectionFooter":@"",
  106. @"isHideSectionHeader":@(YES),
  107. @"isHideSectionFooter":@(YES),
  108. @"dataSource":@[
  109. @{
  110. @"title":@"点赞通知",
  111. @"isOpen":@(YES),
  112. ParamsCategoryType:@(YMChatNotificationFunctionsTypeLikesNotification),
  113. }
  114. ]
  115. },
  116. @{
  117. @"sectionHeader":@"显示设置",
  118. @"sectionFooter":@"",
  119. @"isHideSectionHeader":@(NO),
  120. @"isHideSectionFooter":@(YES),
  121. @"dataSource":@[
  122. @{
  123. @"title":@"声音",
  124. @"isOpen":@([LCSaveData getIMMsgVoice] ? YES : NO),
  125. ParamsCategoryType:@(YMChatNotificationFunctionsTypeSound),
  126. },
  127. @{
  128. @"title":@"振动",
  129. @"isOpen":@([LCSaveData getIMMsgShake] ? YES : NO),
  130. ParamsCategoryType:@(YMChatNotificationFunctionsTypeVibrate),
  131. }
  132. ]
  133. },
  134. ];
  135. } else {
  136. dataArray = @[
  137. @{
  138. @"sectionHeader":@"推荐设置",
  139. @"sectionFooter":@"关闭后,将无法使用缘分页的推荐以及动态页的推荐和关注功能",
  140. @"isHideSectionHeader":@(NO),
  141. @"isHideSectionFooter":@(NO),
  142. @"dataSource":@[
  143. @{
  144. @"title":@"个性化推荐",
  145. @"isOpen":@([[OCUserDefaults objectForKey:kIS_HIDE_PERSONALIZED_RECOMMENDATION_TIPS] boolValue]),
  146. ParamsCategoryType:@(YMChatNotificationFunctionsTypePersonalizedRecommendation),
  147. }
  148. ]
  149. },
  150. @{
  151. @"sectionHeader":@"",
  152. @"sectionFooter":stringFormat(@"开启后,%@将用大数据为您匹配有缘人,牵线成功会发送缘分消息,关闭后,将不会收到缘分牵线。",[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]),
  153. @"isHideSectionHeader":@(YES),
  154. @"isHideSectionFooter":@(NO),
  155. @"dataSource":@[
  156. @{
  157. @"title":@"缘分牵线",
  158. @"isOpen":@(self.isOpenPredestinedAffinity == YES ? YES : NO),
  159. ParamsCategoryType:@(YMChatNotificationFunctionsTypePredestinedAffinity),
  160. }
  161. ]
  162. },
  163. @{
  164. @"sectionHeader":@"",
  165. @"sectionFooter":@"",
  166. @"isHideSectionHeader":@(YES),
  167. @"isHideSectionFooter":@(YES),
  168. @"dataSource":@[
  169. @{
  170. @"title":@"点赞通知",
  171. @"isOpen":@(self.isOpenLikesNotification == YES ? YES : NO),
  172. ParamsCategoryType:@(YMChatNotificationFunctionsTypeLikesNotification),
  173. }
  174. ]
  175. },
  176. @{
  177. @"sectionHeader":@"显示设置",
  178. @"sectionFooter":@"",
  179. @"isHideSectionHeader":@(NO),
  180. @"isHideSectionFooter":@(YES),
  181. @"dataSource":@[
  182. @{
  183. @"title":@"声音",
  184. @"isOpen":@([LCSaveData getIMMsgVoice] ? YES : NO),
  185. ParamsCategoryType:@(YMChatNotificationFunctionsTypeSound),
  186. },
  187. @{
  188. @"title":@"振动",
  189. @"isOpen":@([LCSaveData getIMMsgShake] ? YES : NO),
  190. ParamsCategoryType:@(YMChatNotificationFunctionsTypeVibrate),
  191. }
  192. ]
  193. },
  194. ];
  195. }
  196. self.sectionDataArray = [dataArray.rac_sequence map:^(NSDictionary * _Nullable dic) {
  197. YMChatNotificationSectionViewModel *viewModel = [[YMChatNotificationSectionViewModel alloc]initWithParams:@{
  198. ParamsModel:dic
  199. }];
  200. return viewModel;
  201. }].array;
  202. [self.refreshUISubject sendNext:@(YMRefreshUI)];
  203. }
  204. - (void)getPredestinedAffinityInfo{
  205. @weakify(self)
  206. [LCHttpHelper requestWithURLString:Mine_getFateMatch parameters:nil needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  207. @strongify(self)
  208. NSDictionary* dict = (NSDictionary*)responseObject;
  209. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  210. if (code == 0) {
  211. NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
  212. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  213. NSInteger fateMatch = [data integerValueForKey:@"fate_match" defaultValue:0];
  214. if (fateMatch == 1) {
  215. self.isOpenPredestinedAffinity = NO;
  216. } else {
  217. self.isOpenPredestinedAffinity = YES;
  218. }
  219. dispatch_async(dispatch_get_main_queue(), ^{
  220. [self getChatNotificationListData];
  221. });
  222. });
  223. }
  224. } failure:^(NSError *error) {
  225. [ZCHUDHelper showTitle:error.localizedDescription];
  226. }];
  227. }
  228. - (void)switchPredestinedAffinityInfo{
  229. NSInteger status = self.isOpenPredestinedAffinity == YES ? 1 : 0;
  230. @weakify(self)
  231. [LCHttpHelper requestWithURLString:Mine_setFateMatch parameters:@{
  232. @"fate_match":@(status)
  233. } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  234. @strongify(self)
  235. NSDictionary* dict = (NSDictionary*)responseObject;
  236. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  237. if (code == 0) {
  238. if (status == 1) {
  239. [ZCHUDHelper showTitle:@"关闭缘分牵线"];
  240. self.isOpenPredestinedAffinity = NO;
  241. }else{
  242. [ZCHUDHelper showTitle:@"打开缘分牵线"];
  243. self.isOpenPredestinedAffinity = YES;
  244. }
  245. [self getChatNotificationListData];
  246. }
  247. } failure:^(NSError *error) {
  248. [ZCHUDHelper showTitle:error.localizedDescription];
  249. }];
  250. }
  251. - (void)getLikesNotificationInfo{
  252. @weakify(self)
  253. [LCHttpHelper requestWithURLString:Mine_getLikesNotification parameters:nil needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  254. @strongify(self)
  255. NSDictionary* dict = (NSDictionary*)responseObject;
  256. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  257. if (code == 0) {
  258. NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
  259. // NSInteger fateMatch = [data integerValueForKey:@"fate_match" defaultValue:1]
  260. // if (fateMatch == 1) {
  261. // self.isOpenPredestinedAffinity = NO;
  262. // } else {
  263. // self.isOpenPredestinedAffinity = YES;
  264. // }
  265. [self getChatNotificationListData];
  266. }
  267. } failure:^(NSError *error) {
  268. [ZCHUDHelper showTitle:error.localizedDescription];
  269. }];
  270. }
  271. - (void)switchLikesNotificationInfo{
  272. NSInteger status = self.isOpenLikesNotification == YES ? 1 : 0;
  273. @weakify(self)
  274. [LCHttpHelper requestWithURLString:Mine_setLikesNotification parameters:@{
  275. @"status":@(status)
  276. } needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  277. @strongify(self)
  278. NSDictionary* dict = (NSDictionary*)responseObject;
  279. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  280. if (code == 0) {
  281. if (status == 1) {
  282. [ZCHUDHelper showTitle:@"关闭点赞通知"];
  283. self.isOpenLikesNotification = NO;
  284. }else{
  285. [ZCHUDHelper showTitle:@"打开点赞通知"];
  286. self.isOpenLikesNotification = YES;
  287. }
  288. [self getChatNotificationListData];
  289. }
  290. } failure:^(NSError *error) {
  291. [ZCHUDHelper showTitle:error.localizedDescription];
  292. }];
  293. }
  294. - (RACSubject *)chatNotificationFunctionsOperationSubject{
  295. if (!_chatNotificationFunctionsOperationSubject) {
  296. _chatNotificationFunctionsOperationSubject = [RACSubject subject];
  297. }
  298. return _chatNotificationFunctionsOperationSubject;
  299. }
  300. @end