123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- //
- // YMReceivedLikesCellViewModel.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/17.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMReceivedLikesCellViewModel.h"
- #import "YMRelationModel.h"
- #import "YOUPAILCIMSessionVC.h"
- @interface YMReceivedLikesCellViewModel ()
- /// 用户Id
- @property (nonatomic, assign, readwrite) NSInteger userId;
- /// 用户头像
- @property (nonatomic, copy, readwrite) NSString *userAvatar;
- /// 用户名称
- @property (nonatomic, copy, readwrite) NSString *userNickname;
- /// 用户描述
- @property (nonatomic, copy, readwrite) NSString *userDesc;
- /// 是否搭讪
- @property (nonatomic, assign, readwrite) BOOL isCanPrivateChat;
- /// 心动或搭讪按钮标题 “心动”字样是给女用户的 “搭讪”字样是给男用户
- @property (nonatomic, strong, readwrite) NSString *heartbeatOrAccostButtonTitle;
- /// 心动或搭讪按钮图片
- @property (nonatomic, strong, readwrite) NSString *heartbeatOrAccostButtonImage;
- /// 心动或搭讪按钮标题颜色
- @property (nonatomic, strong, readwrite) UIColor *heartbeatOrAccostButtonTitleColor;
- /// 心动或搭讪按钮背景颜色
- @property (nonatomic, strong, readwrite) UIColor *heartbeatOrAccostButtonBackgroundColor;
- @end
- @implementation YMReceivedLikesCellViewModel
- - (void)ym_initialize{
- [super ym_initialize];
- if ([self.params[ParamsModel] isKindOfClass:[YMRelationModel class]]) {
- YMRelationModel *model = self.params[ParamsModel];
- self.userId = model.userid;
- self.userAvatar = model.avatar;
- self.userNickname = model.nickname;
- NSMutableString *desc = [NSMutableString string];
- if (model.gender == 1) {
- [desc appendFormat:@"女 | "];
- }else{
- [desc appendFormat:@"男 | "];
- }
-
- if (model.age != 0) {
- [desc appendFormat:@"%ld岁 | ",model.age];
- }
-
- self.userDesc = [desc substringToIndex:desc.length - 2];
-
- self.isCanPrivateChat = model.is_beckon;
- if (self.isCanPrivateChat) {
- self.heartbeatOrAccostButtonTitle = @"私信";
- self.heartbeatOrAccostButtonImage = @"ym_common_home_siliao";
- self.heartbeatOrAccostButtonTitleColor = HexColorFromRGB(0xFF70C5);
- self.heartbeatOrAccostButtonBackgroundColor = HexColorFromRGB(0xFFFFFF);
- } else {
- self.heartbeatOrAccostButtonTitle = [self isFemaleGender] ? @"心动" : @"搭讪";
- self.heartbeatOrAccostButtonImage = [self isFemaleGender] ? @"ym_common_home_heart" : @"ym_common_home_dashan";
- self.heartbeatOrAccostButtonTitleColor = HexColorFromRGB(0xFFFFFF);
- self.heartbeatOrAccostButtonBackgroundColor = HexColorFromRGB(0xFF70C5);
- }
- }
-
- }
- - (void)sendAccostRequest{
- if ([self isNeedGoddessCertified]) {
- return;
- }
- if(self.isCanPrivateChat){
- @weakify(self)
- NIMSession *session = [NIMSession session:stringFormat(@"%ld",self.userId) type:NIMSessionTypeP2P];
- if (session) {
- [ZCHUDHelper show];
- [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
- // @strongify(self)
- [ZCHUDHelper dismiss];
- YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
- vc.type = @"1";
- [[YMGlobalUtils getCurrentVC].navigationController pushViewController:vc animated:YES];
- }];
- }
- }else{
- @weakify(self)
- [LCHttpHelper requestWithURLString:HomeBeckonSend parameters:@{
- @"user_ids":stringFormat(@"[%ld]",self.userId)
- } 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:@{}];
- BOOL boole = [data boolValueForKey:@"boole" defaultValue:NO];
-
- if (boole) {
- self.isCanPrivateChat = YES;
- self.heartbeatOrAccostButtonTitle = @"私信";
- self.heartbeatOrAccostButtonImage = @"ym_common_home_siliao";
- self.heartbeatOrAccostButtonTitleColor = HexColorFromRGB(0xFF70C5);
- self.heartbeatOrAccostButtonBackgroundColor = HexColorFromRGB(0xFFFFFF);
- if (self.changeAccostStatusBlock) {
- self.changeAccostStatusBlock();
- }
- }
-
- }else{
- [ZCHUDHelper showTitle:[dict stringValueForKey:@"message" defaultValue:@""]];
- }
- } failure:^(NSError *error) {
- [ZCHUDHelper showTitle:error.localizedDescription];
- }];
- }
- }
- @end
|