YMGuestCellViewModel.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. //
  2. // YMGuestCellViewModel.m
  3. // MSYOUPAI
  4. //
  5. // Created by YoMi on 2024/2/17.
  6. // Copyright © 2024 MS. All rights reserved.
  7. //
  8. #import "YMGuestCellViewModel.h"
  9. #import "YMRelationModel.h"
  10. #import "YOUPAILCIMSessionVC.h"
  11. @interface YMGuestCellViewModel ()
  12. /// 用户Id
  13. @property (nonatomic, assign, readwrite) NSInteger userId;
  14. /// 用户头像
  15. @property (nonatomic, copy, readwrite) NSString *userAvatar;
  16. /// 用户名称
  17. @property (nonatomic, copy, readwrite) NSString *userNickname;
  18. /// 用户性别和年龄图标
  19. @property (nonatomic, strong, readwrite) UIImage *userGenderAndAgeIcon;
  20. /// 用户性别和年龄文本
  21. @property (nonatomic, strong, readwrite) NSString *userGenderAndAgeText;
  22. /// 用户性别
  23. @property (nonatomic, strong, readwrite) NSString *userGender;
  24. /// 用户访问描述
  25. @property (nonatomic, copy, readwrite) NSString *userVisitDesc;
  26. /// 用户访问日期
  27. @property (nonatomic, copy, readwrite) NSString *userVisitDate;
  28. /// 是否隐藏提醒
  29. @property (nonatomic, assign, readwrite) BOOL isHideReminder;
  30. /// 是否搭讪
  31. @property (nonatomic, assign, readwrite) BOOL isCanPrivateChat;
  32. /// 心动或搭讪按钮标题 “心动”字样是给女用户的 “搭讪”字样是给男用户
  33. @property (nonatomic, strong, readwrite) NSString *heartbeatOrAccostButtonTitle;
  34. /// 心动或搭讪按钮图片
  35. @property (nonatomic, strong, readwrite) NSString *heartbeatOrAccostButtonImage;
  36. /// 心动或搭讪按钮标题颜色
  37. @property (nonatomic, strong, readwrite) UIColor *heartbeatOrAccostButtonTitleColor;
  38. /// 心动或搭讪按钮背景颜色
  39. @property (nonatomic, strong, readwrite) UIColor *heartbeatOrAccostButtonBackgroundColor;
  40. @end
  41. @implementation YMGuestCellViewModel
  42. - (void)ym_initialize{
  43. [super ym_initialize];
  44. if ([self.params[ParamsModel] isKindOfClass:[YMRelationModel class]]) {
  45. YMRelationModel *model = self.params[ParamsModel];
  46. self.userId = model.userid;
  47. self.userAvatar = model.avatar;
  48. self.userNickname = model.nickname;
  49. self.isCanPrivateChat = model.is_beckon;
  50. self.userGender = model.gender == 1 ? @"女" : @"男";
  51. self.userGenderAndAgeIcon = model.gender == 1 ? ImageByName(@"ym_personal_page_female_icon") : ImageByName(@"ym_personal_page_male_icon");
  52. self.userGenderAndAgeText = stringFormat(@"%ld",model.age);
  53. self.userVisitDesc = model.visitor_text;
  54. self.userVisitDate = stringFormat(@"%@看过你",model.add_time);
  55. self.isHideReminder = model.is_watch > 0 ? YES : NO;
  56. if (self.isCanPrivateChat) {
  57. self.heartbeatOrAccostButtonTitle = @"私信";
  58. self.heartbeatOrAccostButtonImage = @"ym_common_home_siliao";
  59. self.heartbeatOrAccostButtonTitleColor = HexColorFromRGB(0xFF70C5);
  60. self.heartbeatOrAccostButtonBackgroundColor = HexColorFromRGB(0xFFFFFF);
  61. } else {
  62. self.heartbeatOrAccostButtonTitle = [self isFemaleGender] ? @"心动" : @"搭讪";
  63. self.heartbeatOrAccostButtonImage = [self isFemaleGender] ? @"ym_common_home_heart" : @"ym_common_home_dashan";
  64. self.heartbeatOrAccostButtonTitleColor = HexColorFromRGB(0xFFFFFF);
  65. self.heartbeatOrAccostButtonBackgroundColor = HexColorFromRGB(0xFF70C5);
  66. }
  67. }
  68. }
  69. - (void)sendAccostRequest{
  70. if ([self isNeedGoddessCertified]) {
  71. return;
  72. }
  73. if(self.isCanPrivateChat){
  74. @weakify(self)
  75. NIMSession *session = [NIMSession session:stringFormat(@"%ld",self.userId) type:NIMSessionTypeP2P];
  76. if (session) {
  77. [ZCHUDHelper show];
  78. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  79. @strongify(self)
  80. [ZCHUDHelper dismiss];
  81. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
  82. vc.type = @"1";
  83. [[YMGlobalUtils getCurrentVC].navigationController pushViewController:vc animated:YES];
  84. }];
  85. }
  86. }else{
  87. @weakify(self)
  88. [LCHttpHelper requestWithURLString:HomeBeckonSend parameters:@{
  89. @"user_ids":stringFormat(@"[%ld]",self.userId)
  90. } needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  91. @strongify(self)
  92. NSDictionary* dict = (NSDictionary*)responseObject;
  93. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  94. if (code == 0) {
  95. NSDictionary *data = [dict dictionaryValueForKey:@"data" defaultValue:@{}];
  96. BOOL boole = [data boolValueForKey:@"boole" defaultValue:NO];
  97. if (boole) {
  98. self.isCanPrivateChat = YES;
  99. self.heartbeatOrAccostButtonTitle = @"私信";
  100. self.heartbeatOrAccostButtonImage = @"ym_common_home_siliao";
  101. self.heartbeatOrAccostButtonTitleColor = HexColorFromRGB(0xFF70C5);
  102. self.heartbeatOrAccostButtonBackgroundColor = HexColorFromRGB(0xFFFFFF);
  103. if (self.changeAccostStatusBlock) {
  104. self.changeAccostStatusBlock();
  105. }
  106. }
  107. }else{
  108. [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
  109. }
  110. } failure:^(NSError *error) {
  111. [ZCHUDHelper showTitle:error.localizedDescription];
  112. }];
  113. }
  114. }
  115. @end