YOUPAILCIMSessionVC.m 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  1. //
  2. // YOUPAILCIMSessionVC.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/9/1.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCIMSessionVC.h"
  9. #import "YOUPAILCGiftModel.h"
  10. #import "YOUPAIUCIMVideoVC.h"
  11. #import "YOUPAILPChatTipView.h"
  12. #import "YOUPAIZYXianNvBangModel.h"
  13. #import "YOUPAIZYXianNvBangVC.h"
  14. #import "UIViewController+TFPresent.h"
  15. #import "YOUPAIXRWalletVC.h"
  16. #import <SVGAParser.h>
  17. #import <SVGAPlayer.h>
  18. #import "YOUPAILZCommonGiftView.h"
  19. #import "YOUPAIBBVideoRequestVC.h"
  20. #import "LZAlertWindow.h"
  21. #import "YOUPAIHRRechargePayWindow.h"
  22. #import "YOUPAILZIMCommonWordsVC.h"
  23. #import "YOUPAILZIMCommonWordModel.h"
  24. #import "YOUPAILCIMTool.h"
  25. #import "NIMMessageMaker.h"
  26. #import "YOUPAILZSessionCommonWordCell.h"
  27. #import "YOUPAIHRWebWindow.h"
  28. #import "YOUPAILCBannerModel.h"
  29. #import "YMReportViewController.h"
  30. #import "YOUPAILCVideoResponseVC.h"
  31. #import "YOUPAILZLiveGIftModel.h"
  32. @interface YOUPAILCIMSessionVC()<SVGAPlayerDelegate,UICollectionViewDelegate,UICollectionViewDataSource>
  33. @property (nonatomic,strong) UIImageView *currentImgV;
  34. @property (nonatomic,strong) UIButton *xianNvBangBtn;
  35. @property(nonatomic,strong)YOUPAIZYXianNvBangModel *fairyInfo;
  36. @property (nonatomic,strong)SVGAPlayer *svgaPlayer;
  37. @property (nonatomic,strong)SVGAParser *parser;
  38. @property (nonatomic,strong) UIButton *intimateBtn; // 亲密值按钮
  39. @property (nonatomic, weak) UICollectionView *youpaipcommonWordCollectionView;
  40. @property (nonatomic, strong) NSArray <YOUPAILZIMCommonWordModel *>*youpaipcommonWords;
  41. @end
  42. @implementation YOUPAILCIMSessionVC
  43. //- (UIStatusBarStyle)preferredStatusBarStyle{
  44. // return UIStatusBarStyleLightContent;
  45. //}
  46. - (void)dealloc{
  47. [[NSNotificationCenter defaultCenter] removeObserver:self];
  48. }
  49. - (void)viewWillAppear:(BOOL)animated{
  50. [super viewWillAppear:animated];
  51. self.navigationController.navigationBar.hidden = NO;
  52. }
  53. - (void)viewDidAppear:(BOOL)animated{
  54. [super viewDidAppear:animated];
  55. [self deletUnwantedVC];
  56. }
  57. - (void)viewWillDisappear:(BOOL)animated{
  58. [super viewWillDisappear:animated];
  59. [[NIMSDK sharedSDK].mediaManager stopRecord];
  60. [[NIMSDK sharedSDK].mediaManager stopPlay];
  61. }
  62. - (void)viewDidLoad{
  63. [super viewDidLoad];
  64. [UMengRecordTool umengEventCountWithId:EnterChatPage];
  65. [self youpaifrefreshUserInfo];
  66. UIButton* xianNvBangBtn = [[UIButton alloc]initWithFrame:CGRectMake(KScreenWidth - 13 -67, KScreenWidth-150,67,91.5)];
  67. [xianNvBangBtn setImage:[UIImage imageNamed:@"vqu_images_xiannv"] forState:UIControlStateNormal];
  68. [xianNvBangBtn addTarget:self action:@selector(youpaifxianNvBangBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  69. self.xianNvBangBtn = xianNvBangBtn;
  70. self.xianNvBangBtn.hidden = YES;
  71. [self.view addSubview:xianNvBangBtn];
  72. self.tableView.backgroundColor = HexColorFromRGBA(0xFAFAFC, 1);
  73. self.svgaPlayer = [[SVGAPlayer alloc] initWithFrame:[UIScreen mainScreen].bounds];
  74. self.svgaPlayer.contentMode = UIViewContentModeScaleAspectFit;
  75. self.svgaPlayer.delegate = self;
  76. self.svgaPlayer.userInteractionEnabled = NO;
  77. [[[UIApplication sharedApplication] keyWindow] addSubview:self.svgaPlayer];
  78. self.svgaPlayer.hidden = YES;
  79. self.svgaPlayer.loops = 1;
  80. self.svgaPlayer.clearsAfterStop = true;
  81. self.parser = [[SVGAParser alloc] init];
  82. [self youpaifaddTip];
  83. [self youpaiploadCommonWordsData];
  84. [self youpaifrequestUserinfoData];
  85. [self youpaifinitIntimateBtn];
  86. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifintimateChangeNotification:) name:@"VQUIMIntimateChangeNotification" object:nil];
  87. }
  88. #pragma mark - 删除不需要的视图控制器
  89. - (void)deletUnwantedVC{
  90. for (UIViewController *vc in self.navigationController.viewControllers) {
  91. if ([vc isKindOfClass:[YMReportViewController class]]) {
  92. [vc removeFromParentViewController];
  93. }
  94. }
  95. }
  96. -(void)sendMessage:(NIMMessage *)message{
  97. [super sendMessage:message];
  98. if ([self.type isEqualToString:@"1"]) {
  99. [UMengRecordTool umengEventCountWithId:PrivateChatHome];
  100. }else if ([self.type isEqualToString:@"2"]){
  101. [UMengRecordTool umengEventCountWithId:PrivateChatDynamic];
  102. }else if ([self.type isEqualToString:@"3"]){
  103. [UMengRecordTool umengEventCountWithId:PrivateChatMessage];
  104. }
  105. }
  106. - (void)youpaifinitIntimateBtn{
  107. UIButton *intimateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  108. [intimateBtn setImage:[UIImage imageNamed:@"vqu_images_im_chat_intimate"] forState:UIControlStateNormal];
  109. [intimateBtn setTitle:@"0°C" forState:UIControlStateNormal];
  110. [intimateBtn setTitleColor:LZFE66A4Color forState:UIControlStateNormal];
  111. intimateBtn.titleLabel.font = LCFont(8.0f);
  112. [intimateBtn addTarget:self action:@selector(youpaifintimateBtnClick) forControlEvents:UIControlEventTouchUpInside];
  113. CGFloat totalHeight = 52.0f;
  114. CGFloat imageSize = 40.0f;
  115. CGFloat titleHeight = 10.0f;
  116. intimateBtn.imageEdgeInsets = UIEdgeInsetsMake(- (totalHeight - imageSize), -(imageSize/2.0f)+4.0f, 0.0, - imageSize);
  117. intimateBtn.titleEdgeInsets = UIEdgeInsetsMake(0, - imageSize, - (totalHeight - titleHeight), 0);
  118. [self.view addSubview:intimateBtn];
  119. self.intimateBtn = intimateBtn;
  120. [intimateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  121. make.right.offset(-12.0f);
  122. make.top.offset(48.0f);
  123. make.size.mas_offset(CGSizeMake(40.0f, 52.0f));
  124. }];
  125. NSDictionary *dict = [[YOUPAILZIntimateManager shareManager].intimateDict objectForKey:self.session.sessionId];
  126. NSInteger grade = [[dict objectForKey:@"grade"] integerValue];
  127. NSString *score = [dict objectForKey:@"score"];
  128. if (score.length != 0 && ![LCSaveData getWhiteVersion]) {
  129. [self.intimateBtn setTitle:[NSString stringWithFormat:@"%@°C",score] forState:UIControlStateNormal];
  130. self.intimateBtn.hidden = NO;
  131. }else{
  132. [self.intimateBtn setTitle:[NSString stringWithFormat:@"%@°C",@"0.0"] forState:UIControlStateNormal];
  133. self.intimateBtn.hidden = YES;
  134. }
  135. // @weakify(self);
  136. // [LCHttpHelper requestWithURLString:GetIntimateList parameters:@{@"ids":self.session.sessionId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  137. // @strongify(self);
  138. // NSDictionary* dict = (NSDictionary*)responseObject;
  139. // NSInteger code = [[dict objectForKey:@"code"] integerValue];
  140. // if (code == 0) {//成功
  141. // NSArray *list = [[dict objectForKey:@"data"] objectForKey:@"list"];
  142. // for (NSDictionary *intimate in list) {
  143. // NSString *score = [NSString stringWithFormat:@"%@",[intimate objectForKey:@"score"]];
  144. // NSString *grade = [NSString stringWithFormat:@"%@",[intimate objectForKey:@"grade"]];
  145. // NSString *uid = [NSString stringWithFormat:@"%@",[intimate objectForKey:@"user_id"]];
  146. // [[YOUPAILZIntimateManager shareManager].intimateDict setObject:@{
  147. // @"score":[NSString stringWithFormat:@"%@",score],
  148. // @"grade":[NSString stringWithFormat:@"%@",grade],
  149. // } forKey:uid];
  150. // }
  151. //
  152. // NSDictionary *dict = [[YOUPAILZIntimateManager shareManager].intimateDict objectForKey:self.session.sessionId];
  153. // NSInteger grade = [[dict objectForKey:@"grade"] integerValue];
  154. // NSString *score = [dict objectForKey:@"score"];
  155. // if (score.length != 0 && ![LCSaveData getWhiteVersion]) {
  156. // [self.intimateBtn setTitle:[NSString stringWithFormat:@"%@°C",score] forState:UIControlStateNormal];
  157. // self.intimateBtn.hidden = NO;
  158. // }else{
  159. // [self.intimateBtn setTitle:[NSString stringWithFormat:@"%@°C",@"0.0"] forState:UIControlStateNormal];
  160. // self.intimateBtn.hidden = YES;
  161. // }
  162. // }
  163. // } failure:^(NSError *error) {
  164. //
  165. // }];
  166. }
  167. - (void)youpaifintimateBtnClick{
  168. @weakify(self);
  169. [LCHttpHelper requestWithURLString:AppConfig parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  170. @strongify(self);
  171. NSDictionary* dict = (NSDictionary*)responseObject;
  172. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  173. if (code==0) {//成功
  174. NSString *chatintimate = [[[dict objectForKey:@"data"]objectForKey:@"webUrl"] objectForKey:@"chatintimate"];
  175. chatintimate = [NSString stringWithFormat:@"%@&user_id=%@",chatintimate,self.session.sessionId];
  176. YOUPAILCBannerModel *model = [[YOUPAILCBannerModel alloc] init];
  177. model.youpaipwindow_link = chatintimate;
  178. model.youpaipgravity = @"full";
  179. YOUPAIHRWebWindow *window = [[YOUPAIHRWebWindow alloc] init];
  180. window.isTouchDismiss = YES;
  181. window.youpaipurl = model.youpaipwindow_link;
  182. window.youpaipgravity = model.youpaipgravity;
  183. [self TFPresentVC:window completion:^{}];
  184. }
  185. } failure:^(NSError *error) {
  186. }];
  187. }
  188. - (void)youpaifintimateChangeNotification:(NSNotification *)notify{
  189. NSDictionary *dict = [[YOUPAILZIntimateManager shareManager].intimateDict objectForKey:self.session.sessionId];
  190. NSString *score = [dict objectForKey:@"score"];
  191. if (score.length != 0 && ![LCSaveData getWhiteVersion]) {
  192. [self.intimateBtn setTitle:[NSString stringWithFormat:@"%@°C",score] forState:UIControlStateNormal];
  193. self.intimateBtn.hidden = NO;
  194. }else{
  195. [self.intimateBtn setTitle:[NSString stringWithFormat:@"%@°C",@"0.0"] forState:UIControlStateNormal];
  196. self.intimateBtn.hidden = YES;
  197. }
  198. }
  199. ///资料卡
  200. - (void)youpaifrequestUserinfoData{
  201. /// 特殊用户
  202. if ([self.session.sessionId isEqualToString:[LCSaveData getSysId]] ||
  203. [self.session.sessionId isEqualToString:@"11"] ||
  204. [[LCSaveData getServiceIdArr] containsObject:self.session.sessionId]) {
  205. return;
  206. }
  207. @weakify(self);
  208. [LCHttpHelper requestWithURLString:GetChatData parameters:@{@"user_id":self.session.sessionId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  209. @strongify(self);
  210. NSDictionary* dict = (NSDictionary*)responseObject;
  211. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  212. if (code==0) {//成功
  213. NSDictionary *data = [dict objectForKey:@"data"];
  214. if (data != nil && ![data isKindOfClass:NSNull.class]) {
  215. [self youpaifinitUserinfoUIWithDict:data];
  216. }
  217. }
  218. } failure:^(NSError *error) {
  219. }];
  220. }
  221. - (void)youpaifinitUserinfoUIWithDict:(NSDictionary *)dict{
  222. UIButton *headerV = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 165.0f + 8.0f)];
  223. [headerV addTarget:self action:@selector(goshowUserPage) forControlEvents:UIControlEventTouchUpInside];
  224. UIView *bgV = [[UIView alloc] init];
  225. bgV.backgroundColor = [UIColor whiteColor];
  226. bgV.layer.cornerRadius = 12.0f;
  227. bgV.clipsToBounds = YES;
  228. bgV.userInteractionEnabled = NO;
  229. [headerV addSubview:bgV];
  230. [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
  231. make.top.offset(8.0f);
  232. make.left.offset(16.0f);
  233. make.right.offset(-16.0f);
  234. make.bottom.offset(0.0f);
  235. }];
  236. UIButton *authenticationDescBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  237. UIButton *cityDescBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  238. UIButton *infoDescBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  239. UIButton *imageDescBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  240. NSArray *contents = @[
  241. @{@"image":[UIImage imageNamed:@"vqu_images_im_user_car_ver"],@"title":@" 认证状态:"},
  242. @{@"image":[UIImage imageNamed:@"vqu_images_im_user_car_address"],@"title":@" 所在城市:"},
  243. @{@"image":[UIImage imageNamed:@"vqu_images_im_user_car_info"],@"title":@" 基本信息:"},
  244. @{@"image":[UIImage imageNamed:@"vqu_images_im_user_car_image"],@"title":@" 近期靓照:"},
  245. ];
  246. NSArray *btns = @[authenticationDescBtn,cityDescBtn,infoDescBtn,imageDescBtn];
  247. for (NSInteger i = 0; i < btns.count; i ++) {
  248. NSDictionary *content = contents[i];
  249. UIButton *btn = btns[i];
  250. btn.userInteractionEnabled = NO;
  251. btn.frame = CGRectMake(12.0f, 8.0f + ((i + 1) * 8.0f) + i * 20.0f, 100.0f, 20.0f);
  252. [btn setImage:[content objectForKey:@"image"] forState:UIControlStateNormal];
  253. [btn setTitle:[content objectForKey:@"title"] forState:UIControlStateNormal];
  254. [btn setTitleColor:LZ273145Color forState:UIControlStateNormal];
  255. btn.titleLabel.font = LCFont14;
  256. [bgV addSubview:btn];
  257. }
  258. NSDictionary *auth = [dict objectForKey:@"auth"];
  259. UIImageView *realPersonImgV = [[UIImageView alloc] init];
  260. if ([[auth objectForKey:@"real_auth_status"] integerValue] == 0) { // 未认证
  261. realPersonImgV.image = [UIImage imageNamed:@"vqu_images_im_real_person_n"];
  262. }else{
  263. realPersonImgV.image = [UIImage imageNamed:@"vqu_images_im_real_person"];
  264. }
  265. [bgV addSubview:realPersonImgV];
  266. [realPersonImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  267. make.left.equalTo(authenticationDescBtn.mas_right).offset(4.0f);
  268. make.centerY.equalTo(authenticationDescBtn);
  269. make.size.mas_offset(CGSizeMake(64, 15));
  270. }];
  271. UIImageView *realNameImgV = [[UIImageView alloc] init];
  272. if ([[auth objectForKey:@"auth_status"] integerValue] == 0) { // 未认证
  273. realNameImgV.image = [UIImage imageNamed:@"vqu_images_im_real_name_n"];
  274. }else{
  275. realNameImgV.image = [UIImage imageNamed:@"vqu_images_im_real_name"];
  276. }
  277. [bgV addSubview:realNameImgV];
  278. [realNameImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  279. make.left.equalTo(realPersonImgV.mas_right).offset(4.0f);
  280. make.centerY.equalTo(authenticationDescBtn);
  281. make.size.mas_offset(CGSizeMake(64, 15));
  282. }];
  283. UILabel *cityL = [[UILabel alloc] init];
  284. cityL.textColor = LZ273145Color;
  285. cityL.text = [NSString stringWithFormat:@"%@市",[dict objectForKey:@"city"]];
  286. cityL.font = LCFont(13.0f);
  287. [bgV addSubview:cityL];
  288. [cityL mas_makeConstraints:^(MASConstraintMaker *make) {
  289. make.left.equalTo(cityDescBtn.mas_right).offset(4.0f);
  290. make.centerY.equalTo(cityDescBtn);
  291. }];
  292. UILabel *infoL = [[UILabel alloc] init];
  293. infoL.textColor = LZ273145Color;
  294. infoL.text = [dict objectForKey:@"base_info"];
  295. infoL.font = LCFont(13.0f);
  296. [bgV addSubview:infoL];
  297. [infoL mas_makeConstraints:^(MASConstraintMaker *make) {
  298. make.left.equalTo(infoDescBtn.mas_right).offset(4.0f);
  299. make.centerY.equalTo(infoDescBtn);
  300. }];
  301. UIView *imageBgV = [[UIView alloc] init];
  302. [bgV addSubview:imageBgV];
  303. [imageBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  304. make.left.equalTo(imageDescBtn.mas_right);
  305. make.top.equalTo(imageDescBtn.mas_top);
  306. make.height.offset(49.0f);
  307. }];
  308. NSMutableArray *imgVs = [NSMutableArray array];
  309. NSArray *imgs = [dict objectForKey:@"albumList"];
  310. for (NSInteger i = 0; i < imgs.count; i ++) {
  311. UIImageView *imgV = [[UIImageView alloc] init];
  312. imgV.contentMode = UIViewContentModeScaleAspectFill;
  313. imgV.layer.cornerRadius = 10.0f;
  314. imgV.clipsToBounds = YES;
  315. imgV.backgroundColor = [UIColor redColor];
  316. [imgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:[imgs[i] objectForKey:@"url"]]];
  317. [imageBgV addSubview:imgV];
  318. [imgVs addObject:imgV];
  319. }
  320. if (imgVs.count > 1) {
  321. [imgVs mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:4.0f leadSpacing:4.0f tailSpacing:4.0f];
  322. [imgVs mas_makeConstraints:^(MASConstraintMaker *make) {
  323. make.top.bottom.offset(0.0f);
  324. make.width.offset(49.0f);
  325. }];
  326. }else if (imgVs.count == 1){
  327. UIImageView *imgV = imgVs[0];
  328. [imgV mas_makeConstraints:^(MASConstraintMaker *make) {
  329. make.left.offset(4.0f);
  330. make.right.offset(-4.0f);
  331. make.width.offset(49.0f);
  332. make.top.bottom.offset(0.0f);
  333. }];
  334. }else{
  335. imageDescBtn.hidden = YES;
  336. imageBgV.hidden = YES;
  337. headerV.mj_h -= 57.0f;
  338. }
  339. self.tableView.tableHeaderView = headerV;
  340. }
  341. - (void)goshowUserPage{
  342. // YOUPAILZUserShowVC *userShow = [[YOUPAILZUserShowVC alloc] init];
  343. // userShow.youpaipuserId = self.session.sessionId;
  344. // [self.navigationController pushViewController:userShow animated:YES];
  345. YMPersonalPageViewModel *personalPageVM = [[YMPersonalPageViewModel alloc]initWithParams:@{
  346. ParamsId:@([self.session.sessionId intValue])
  347. }];
  348. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_PERSONAL_PAGE) withUserInfo:@{
  349. RouterViewModel:personalPageVM
  350. } completion:nil];
  351. }
  352. //反色情提示 add by leo 注释
  353. - (void)youpaifaddTip{
  354. if ([self.session.sessionId isEqualToString:[LCSaveData getSysId]] ||
  355. [self.session.sessionId isEqualToString:@"11"] ||
  356. [[LCSaveData getServiceIdArr] containsObject:self.session.sessionId]) {
  357. return;
  358. }
  359. [LCHttpHelper requestWithURLString:ChatTip parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  360. NSDictionary* dict = (NSDictionary*)responseObject;
  361. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  362. if (code==0) {//成功
  363. if ([[[dict objectForKey:@"data"] allKeys] containsObject:@"fairy"]) {
  364. if ((![[LCSaveData getSysId] isEqualToString:self.session.sessionId]) && (![self.session.sessionId isEqualToString:@"11"]) ) {
  365. self.xianNvBangBtn.hidden = NO;
  366. self.fairyInfo = [YOUPAIZYXianNvBangModel mj_objectWithKeyValues:[[dict objectForKey:@"data"] objectForKey:@"fairy"]];
  367. }
  368. }else{
  369. self.xianNvBangBtn.hidden = YES;
  370. }
  371. NSString *tip = [[dict objectForKey:@"data"]objectForKey:@"tip"];
  372. YOUPAILPChatTipView *chatTip = [[YOUPAILPChatTipView alloc]initWithFrame:CGRectMake(16.0f, -36.0f, KScreenWidth - 32.0f, 28.0f)];
  373. chatTip.layer.cornerRadius = 6.0f;
  374. chatTip.clipsToBounds = YES;
  375. // chatTip.tipLabel.text = tip;
  376. [self.view addSubview:chatTip];
  377. [chatTip ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
  378. NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@",tip]];
  379. NSTextAttachment *attch = [[NSTextAttachment alloc] init];
  380. attch.image = [UIImage imageNamed:@"vqu_images_im_notice"];
  381. // 设置图片大小
  382. attch.bounds = CGRectMake(0, -1, 12, 12);
  383. // 创建带有图片的富文本
  384. NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
  385. [attri insertAttributedString:string atIndex:0];
  386. chatTip.tipLabel.attributedText = attri;
  387. dispatch_async(dispatch_get_main_queue(), ^{
  388. [UIView animateWithDuration:2 animations:^{
  389. chatTip.frame = CGRectMake(16.0f, 8.0f, KScreenWidth - 32.0f, 28.0f);
  390. }completion:^(BOOL finished) {
  391. if (finished) {
  392. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  393. [UIView animateWithDuration:1 animations:^{
  394. chatTip.frame = CGRectMake(16.0f, -36.0f, KScreenWidth - 32.0f, 28.0f);
  395. }completion:^(BOOL finished) {
  396. if (finished) {
  397. [chatTip removeFromSuperview];
  398. }
  399. }];
  400. });
  401. }
  402. }];
  403. });
  404. }
  405. } failure:^(NSError *error) {
  406. }];
  407. }
  408. -(void)youpaifxianNvBangBtnClick
  409. {
  410. YOUPAIZYXianNvBangVC *VC= [[YOUPAIZYXianNvBangVC alloc]init];
  411. // VC.delegate = self;
  412. VC.youpaipuser_id = self.session.sessionId;
  413. VC.vWidth = KScreenWidth *(320.0/375.0);
  414. VC.vHeight = (VC.vWidth*137)/320.0+165;
  415. VC.youpaipinfoModel = self.fairyInfo;
  416. VC.youpaipisChat = YES;
  417. VC.isTouchDismiss = YES;
  418. [self TFPresentVC:VC completion:^{}];
  419. }
  420. #pragma mark - 刷新对方用户信息
  421. - (void)youpaifrefreshUserInfo{
  422. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[self.session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  423. // NIMUser* user = users[0];
  424. }];
  425. }
  426. #pragma mark - Cell事件 图片/视频点击查看 add by leo 注释
  427. - (BOOL)onTapCell:(NIMKitEvent *)event
  428. {
  429. BOOL handled = [super onTapCell:event];
  430. NSString *eventName = event.eventName;
  431. if ([eventName isEqualToString:NIMKitEventNameTapContent])
  432. {
  433. NIMMessage *message = event.messageModel.message;
  434. NSDictionary *actions = [self youpaifcellActions];
  435. NSString *value = actions[@(message.messageType)];
  436. if (value) {
  437. SEL selector = NSSelectorFromString(value);
  438. if (selector && [self respondsToSelector:selector]) {
  439. if (message.messageType == NIMMessageTypeImage) {
  440. self.currentImgV = event.contentImage;
  441. }
  442. SuppressPerformSelectorLeakWarning([self performSelector:selector withObject:message]);
  443. handled = YES;
  444. }
  445. }
  446. }
  447. else if([eventName isEqualToString:NIMKitEventNameTapLabelLink])
  448. {
  449. NSString *link = event.data;
  450. NSArray* tempArray = [[LCSaveData getTAppUrl] componentsSeparatedByString:@","];
  451. for (NSString* str in tempArray) {
  452. if([link rangeOfString:str].location !=NSNotFound) {
  453. ZCBaseWebVC* base = [[ZCBaseWebVC alloc]init];
  454. base.contentUrl = link;
  455. [self.navigationController pushViewController:base animated:YES];
  456. }
  457. }
  458. //跳转到控制器
  459. handled = YES;
  460. }
  461. if (!handled) {
  462. NSAssert(0, @"invalid event");
  463. }
  464. return handled;
  465. }
  466. //头像点击事件 add by leo 注释
  467. - (BOOL)onTapAvatar:(NIMMessage *)message{
  468. [self.sessionInputView endEditing:YES];
  469. // YOUPAILZUserShowVC *vc = [[YOUPAILZUserShowVC alloc] init];
  470. // if ([message.from isEqualToString:self.session.sessionId]) {
  471. // vc.youpaipuserId = message.session.sessionId;
  472. // }else{
  473. // vc.youpaipuserId = [LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id;
  474. // }
  475. // [self.navigationController pushViewController:vc animated:YES];
  476. NSString *userId = @"";
  477. if ([message.from isEqualToString:self.session.sessionId]) {
  478. userId = message.session.sessionId;
  479. }else{
  480. userId = [LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id;
  481. }
  482. YMPersonalPageViewModel *personalPageVM = [[YMPersonalPageViewModel alloc]initWithParams:@{
  483. ParamsId:@([userId intValue])
  484. }];
  485. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_PERSONAL_PAGE) withUserInfo:@{
  486. RouterViewModel:personalPageVM
  487. } completion:nil];
  488. return YES;
  489. }
  490. #pragma mark - Cell Actions 图片 视频点击事件
  491. - (NSDictionary *)youpaifcellActions
  492. {
  493. static NSDictionary *actions = nil;
  494. static dispatch_once_t onceToken;
  495. dispatch_once(&onceToken, ^{
  496. actions = @{@(NIMMessageTypeImage) : @"showImage:",
  497. @(NIMMessageTypeVideo) : @"showVideo:",
  498. @(NIMMessageTypeCustom): @"showCustom:"};
  499. });
  500. return actions;
  501. }
  502. - (void)showImage:(NIMMessage *)message
  503. {
  504. [self.view endEditing:YES];
  505. NSMutableArray* imageArray = [NSMutableArray array];
  506. for (int i =0; i<self.interactor.items.count; i++) {
  507. id modelInArray = [[self.interactor items] objectAtIndex:i];
  508. if ([modelInArray isKindOfClass:[NIMMessageModel class]])
  509. {
  510. NIMMessageModel *model = (NIMMessageModel *)modelInArray;
  511. if(model.message.messageType == NIMMessageTypeImage){
  512. [imageArray addObject:model.message];
  513. }
  514. }
  515. }
  516. NSArray* sortImageArray = [(NSArray*)imageArray sortedArrayUsingComparator:^NSComparisonResult(NIMMessage * _Nonnull obj1, NIMMessage * _Nonnull obj2) {
  517. return obj1.timestamp > obj2.timestamp;
  518. }];
  519. NSInteger count = imageArray.count;
  520. NSMutableArray *photos = [NSMutableArray arrayWithCapacity:count];
  521. for (NIMMessage *imageMessage in sortImageArray) {
  522. if (imageMessage.messageType == NIMMessageTypeImage) {
  523. NIMImageObject *object = (NIMImageObject *)imageMessage.messageObject;
  524. YBIBImageData *model = [YBIBImageData new];
  525. model.imageURL = [NSURL URLWithString:object.url];
  526. model.projectiveView = self.currentImgV;
  527. [photos addObject:model];
  528. }
  529. }
  530. if (count!=0) {
  531. YBImageBrowser *browser = [YBImageBrowser new];
  532. browser.dataSourceArray = photos;
  533. browser.currentPage = [sortImageArray indexOfObject:message];
  534. [browser show];
  535. }
  536. }
  537. - (void)showVideo:(NIMMessage *)message
  538. {
  539. NIMVideoObject *object = (NIMVideoObject*)message.messageObject;
  540. YOUPAILCIMVideoVC *playerViewController = [[YOUPAILCIMVideoVC alloc] initWithVideoObject:object];
  541. [self pushEffectPresentToVC:playerViewController];
  542. if(![[NSFileManager defaultManager] fileExistsAtPath:object.coverPath]){
  543. //如果封面图下载了,点进视频的时候再去下一把封面图
  544. __weak typeof(self) wself = self;
  545. [[NIMSDK sharedSDK].resourceManager download:object.coverUrl filepath:object.coverPath progress:nil completion:^(NSError *error) {
  546. if (!error) {
  547. [wself youpaifuiUpdateMessage:message];
  548. }
  549. }];
  550. }
  551. }
  552. //add by leo 注释 自定义消息
  553. - (void)showCustom:(NIMMessage *)message
  554. {
  555. //普通的自定义消息点击事件可以在这里做哦~
  556. NIMCustomObject *object = (NIMCustomObject*)message.messageObject;
  557. if ([object.attachment isKindOfClass:[YOUPAILCOneImageAttachment class]]) {
  558. YOUPAILCOneImageAttachment *attachment = (YOUPAILCOneImageAttachment *)object.attachment;
  559. if (attachment.link_type==1) {//打开H5页面
  560. ZCBaseWebVC* web = [[ZCBaseWebVC alloc]init];
  561. web.contentUrl = attachment.link_url;
  562. [self.navigationController pushViewController:web animated:YES];
  563. }else if (attachment.link_type==2){//跳转本地页面
  564. [self youpaifpageToStr:attachment.link_url];
  565. }
  566. }else if ([object.attachment isKindOfClass:[YOUPAILCMultiImageAttachment class]]){
  567. YOUPAILCMultiImageAttachment *attachment = (YOUPAILCMultiImageAttachment *)object.attachment;
  568. NSDictionary* dic;
  569. if ([message.localExt objectForKey:@"serial"]) {
  570. NSInteger ser = [[message.localExt objectForKey:@"serial"]integerValue];
  571. dic = attachment.imageArray[ser];
  572. }else{
  573. dic = attachment.imageArray[0];
  574. }
  575. if ([[dic objectForKey:@"link_type"] integerValue]==1) {//打开H5页面
  576. ZCBaseWebVC* web = [[ZCBaseWebVC alloc]init];
  577. web.contentUrl = [dic objectForKey:@"link_url"];
  578. [self.navigationController pushViewController:web animated:YES];
  579. }else if ([[dic objectForKey:@"link_type"] integerValue]==2){//跳转本地页面
  580. [self youpaifpageToStr:[dic objectForKey:@"link_url"]];
  581. }
  582. }else if([object.attachment isKindOfClass:[YOUPAILCMessageTxtAttachment class]]){
  583. YOUPAILCMessageTxtAttachment *attachment = (YOUPAILCMessageTxtAttachment *)object.attachment;
  584. if (attachment.link_type!=0) {
  585. if (attachment.link_type==1) {//打开H5页面
  586. ZCBaseWebVC* web = [[ZCBaseWebVC alloc]init];
  587. web.contentUrl = attachment.link_url;
  588. [self.navigationController pushViewController:web animated:YES];
  589. }else if (attachment.link_type==2){//跳转本地页面
  590. [self youpaifpageToStr:attachment.link_url];
  591. }else if(attachment.link_type==3){//执行本地逻辑
  592. NSDictionary* dict = [attachment.link_url mj_JSONObject];
  593. if([[dict objectForKey:@"action"]isEqualToString:@"add_qq_group"]){
  594. NSString* qqgroup = [[dict objectForKey:@"data"]objectForKey:@"groupId"];
  595. NSString* qqkey = [[dict objectForKey:@"data"]objectForKey:@"iosKey"];
  596. NSString *urlStr = [NSString stringWithFormat:@"mqqapi://card/show_pslcard?src_type=internal&version=1&uin=%@&key=%@&card_type=group&source=external", qqgroup,qqkey];
  597. NSURL *url = [NSURL URLWithString:urlStr];
  598. if([[UIApplication sharedApplication] canOpenURL:url]){
  599. [[UIApplication sharedApplication] openURL:url];
  600. }else{
  601. [ZCHUDHelper showTitle:[NSString stringWithFormat:@"你可以加入我们官方QQ群:%@",qqgroup]showtime:3.0];
  602. }
  603. }
  604. }
  605. }
  606. }else if ([object.attachment isKindOfClass:[YOUPAILPFollowAttachment class]]){
  607. YOUPAILPFollowAttachment *attachment = (YOUPAILPFollowAttachment *)object.attachment;
  608. //v1.0.7 type为18跳到聊天页面
  609. if(attachment.type==16||attachment.type==17)
  610. {
  611. // LCUserShowVC* userShow = [[LCUserShowVC alloc]init];
  612. // YOUPAILZUserShowVC* userShow = [[YOUPAILZUserShowVC alloc]init];
  613. // userShow.youpaipuserId = [NSString stringWithFormat:@"%zd",attachment.userid];
  614. // [self.navigationController pushViewController:userShow animated:YES];
  615. YMPersonalPageViewModel *personalPageVM = [[YMPersonalPageViewModel alloc]initWithParams:@{
  616. ParamsId:@(attachment.userid)
  617. }];
  618. [YMRouter openURL:stringFormat(@"%@%@", YM_ROUTER_URL_PREFIX, YM_ROUTER_PERSONAL_PAGE) withUserInfo:@{
  619. RouterViewModel:personalPageVM
  620. } completion:nil];
  621. }
  622. else
  623. {
  624. NSString* userId = [NSString stringWithFormat:@"%zd",attachment.userid];
  625. if (userId) {
  626. [self goChatPageWithUserId:userId];
  627. }
  628. }
  629. } else if (message.messageType == NIMMessageTypeCustom) { // 视频通话
  630. [self onVideoClick];
  631. }
  632. }
  633. - (void)goChatPageWithUserId:(NSString *)userId{
  634. @weakify(self);
  635. // [LCHttpHelper requestWithURLString:IsChat parameters:@{@"user_id":userId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  636. // NSDictionary* dict = (NSDictionary*)responseObject;
  637. // NSInteger code = [[dict objectForKey:@"code"] integerValue];
  638. // if (code==0) {//成功
  639. // NSInteger is_chat = [[[dict objectForKey:@"data"] objectForKey:@"is_chat"] integerValue];
  640. // NSString *msg = [[dict objectForKey:@"data"] objectForKey:@"msg"];
  641. // @strongify(self);
  642. // if (is_chat == 0) { /// 0不可以 1可以私信
  643. // LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"再想想" handler:^(LZAlertAction *action) {
  644. //
  645. // }];
  646. // cancelAction.cornerRadius = 5.0f;
  647. // cancelAction.color = LZ273145Color;
  648. // cancelAction.bgColor = LZF5F4F7Color;
  649. // LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"去充值" handler:^(LZAlertAction *action) {
  650. // @strongify(self);
  651. // YOUPAIHRRechargePayWindow *payWindow = [YOUPAIHRRechargePayWindow new];
  652. // payWindow.isTouchDismiss = NO;
  653. // [self.navigationController TFPresentVC:payWindow completion:^{
  654. //
  655. // }];
  656. // }];
  657. // confimAction.cornerRadius = 5.0f;
  658. // confimAction.color = [UIColor whiteColor];
  659. // confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]];
  660. // LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:msg action:@[cancelAction,confimAction]];
  661. // alert.contentTextAlignment = NSTextAlignmentCenter;
  662. // [self TFPresentVC:alert completion:^{}];
  663. // }else{
  664. NIMSession *session = [NIMSession session:userId type:NIMSessionTypeP2P];
  665. if (session) {
  666. [ZCHUDHelper show];
  667. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  668. @strongify(self);
  669. [ZCHUDHelper dismiss];
  670. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
  671. [self.navigationController pushViewController:vc animated:YES];
  672. }];
  673. }
  674. // }
  675. // }
  676. // } failure:^(NSError *error) {
  677. // }];
  678. }
  679. #pragma mark - NIMInputActionDelegate 礼物 视频 语音 照片 啥的 注释by leo
  680. - (void)onCameraClick{
  681. [self.interactor mediaShootPressed];
  682. }
  683. - (void)onSayHiClick{
  684. YOUPAILZIMCommonWordsVC *vc = [[YOUPAILZIMCommonWordsVC alloc] init];
  685. vc.youpaipto_uid = self.session.sessionId;
  686. vc.youpaipdataSource = self.youpaipcommonWords;
  687. @weakify(self);
  688. [vc setYoupaipreloadDataSourceBlock:^(NSArray<YOUPAILZIMCommonWordModel *> * _Nonnull youpaipdataSource) {
  689. @strongify(self);
  690. self.youpaipcommonWords = youpaipdataSource;
  691. [self.youpaipcommonWordCollectionView reloadData];
  692. }];
  693. [self.navigationController pushViewController:vc animated:YES];
  694. }
  695. - (void)youpaiploadCommonWordsData{
  696. if (self.sessionInputView == nil) {
  697. return;
  698. }
  699. @weakify(self);
  700. [LCHttpHelper requestWithURLString:GetCommonWord parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  701. @strongify(self);
  702. NSDictionary* dict = (NSDictionary*)responseObject;
  703. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  704. if (code==0) {//成功
  705. [self youpaifinitCommonWordCollectionView];
  706. self.youpaipcommonWords = [YOUPAILZIMCommonWordModel mj_objectArrayWithKeyValuesArray:[dict objectForKey:@"data"]];
  707. [self.youpaipcommonWordCollectionView reloadData];
  708. }
  709. } failure:^(NSError *error) {
  710. }];
  711. }
  712. - (void)youpaifinitCommonWordCollectionView{
  713. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  714. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  715. layout.minimumLineSpacing = 0.0f;
  716. layout.minimumInteritemSpacing = 8.0f;
  717. layout.sectionInset = UIEdgeInsetsMake(0.0f, 16.0f, 0.0f, 16.0f);
  718. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  719. collectionView.backgroundColor = [UIColor clearColor];
  720. collectionView.dataSource = self;
  721. collectionView.delegate = self;
  722. collectionView.showsVerticalScrollIndicator = NO;
  723. collectionView.showsHorizontalScrollIndicator = NO;
  724. [collectionView registerClass:[YOUPAILZSessionCommonWordCell class] forCellWithReuseIdentifier:NSStringFromClass(YOUPAILZSessionCommonWordCell.class)];
  725. [self.view addSubview:collectionView];
  726. self.youpaipcommonWordCollectionView = collectionView;
  727. [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  728. make.bottom.equalTo(self.sessionInputView.mas_top).offset(0.0f);
  729. make.left.right.offset(0.0f);
  730. make.height.offset(44.0f);
  731. }];
  732. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 44.0f)];
  733. }
  734. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  735. CGFloat width = [self.youpaipcommonWords[indexPath.item].youpaipword widthWithFont:LCFont(12.0f) constrainedToHeight:44.0f] + 16.0f;
  736. return CGSizeMake(width, 28.0f);
  737. }
  738. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  739. return self.youpaipcommonWords.count;
  740. }
  741. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  742. YOUPAILZSessionCommonWordCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(YOUPAILZSessionCommonWordCell.class) forIndexPath:indexPath];
  743. [cell youpaifreloadWithModel:self.youpaipcommonWords[indexPath.item]];
  744. return cell;
  745. }
  746. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  747. NIMSession *session = [NIMSession session:self.session.sessionId type:NIMSessionTypeP2P];
  748. NIMMessage *imMessage = [NIMMessageMaker msgWithText:self.youpaipcommonWords[indexPath.item].youpaipword];
  749. @weakify(self);
  750. [YOUPAILCIMTool sendMessage:imMessage sessionid:session.sessionId completion:^(NIMMessage *resultMsg,NSInteger filter,NSString *contentStr) {
  751. @strongify(self);
  752. if (filter==0) {
  753. [[[NIMSDK sharedSDK] chatManager] sendMessage:resultMsg toSession:session error:nil];
  754. }else{
  755. resultMsg.text = contentStr;
  756. [[[NIMSDK sharedSDK] chatManager] sendMessage:resultMsg toSession:session error:nil];
  757. }
  758. }];
  759. }
  760. - (void)onPhotoClick{
  761. [self.interactor mediaPicturePressed];
  762. }
  763. #pragma mark SVGAPlayerDelegate
  764. //- (void)svgaPlayerDidAnimatedToPercentage:(CGFloat)percentage
  765. //{
  766. // NSLog(@"percentage == %lf",percentage);
  767. // if (percentage == 1) {
  768. //// [self.player stopAnimation];
  769. //// self.player.hidden = YES;
  770. // }
  771. //}
  772. - (void)svgaPlayerDidFinishedAnimation:(SVGAPlayer *)player
  773. {
  774. self.svgaPlayer.hidden = YES;
  775. }
  776. - (void)onGiftClick{
  777. [self.sessionInputView endEditing:YES];
  778. YOUPAILZCommonGiftView *view = [YOUPAILZCommonGiftView new];
  779. view.isTouchDismiss = YES;
  780. view.youpaipisAnchor = NO;
  781. @weakify(self);
  782. [view setJumToWalletBlock1:^{
  783. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  784. // [[NSNotificationCenter defaultCenter] postNotificationName:@"InsufficientBalanceNotice" object:nil userInfo:nil];
  785. // YOUPAIXRWalletVC *coinRecharge = [[YOUPAIXRWalletVC alloc]init];
  786. // [self.navigationController pushViewController:coinRecharge animated:YES];
  787. //
  788. //
  789. // });
  790. YMAccountBalanceViewModel *accountBalanceVM = [[YMAccountBalanceViewModel alloc]initWithParams:@{
  791. ParamsId:@([[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id intValue])
  792. }];
  793. YMAccountBalanceRechargePopupView *customView = [[YMAccountBalanceRechargePopupView alloc]init];
  794. [customView ym_bindViewModel:accountBalanceVM];
  795. YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:nil popStyle:YMPopupStyleSmoothFromBottom dismissStyle:YMDismissStyleSmoothToBottom];
  796. popupView.priority = 999;
  797. popupView.cornerRadius = adapt(10);
  798. popupView.rectCorners = UIRectCornerTopLeft|UIRectCornerTopRight;
  799. popupView.positionStyle = YMPositionStyleBottom;
  800. popupView.isClickBgDismiss = YES;
  801. popupView.isHideBg = NO;
  802. popupView.bgAlpha = 0.5;
  803. [popupView pop];
  804. @weakify(popupView)
  805. customView.dismissBlock = ^{
  806. @strongify(popupView)
  807. [popupView dismissWithStyle:YMDismissStyleSmoothToBottom duration:2.0];
  808. };
  809. }];
  810. [view setYoupaiplzgiftblock:^(YOUPAILCGiftModel * _Nonnull giftModel, NSInteger count,NSString*categoryID) {
  811. @strongify(self);
  812. [LCHttpHelper requestWithURLString:SendGift_New parameters:@{@"type":@(2),@"to_uid":self.session.sessionId,@"gift_id":giftModel.youpaipid,@"num":@(count),@"gift_type_id":categoryID} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  813. NSDictionary* dict = (NSDictionary*)responseObject;
  814. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  815. if (code==0) {//成功
  816. NSInteger coin = [[[dict objectForKey:@"data"]objectForKey:@"coin"]integerValue];
  817. // [ZCHUDHelper showTitle:@"礼物赠送成功"];
  818. [UMengRecordTool umengEventCountWithId:GiveawayGiftMessage];
  819. [self.svgaPlayer stopAnimation];
  820. if (giftModel.youpaiptype == 1 && ![giftModel.youpaipsvga isEqualToString:@""]) {
  821. self.svgaPlayer.hidden = NO;
  822. }
  823. NSString* svgaName = [[giftModel.youpaipsvga componentsSeparatedByString:@"/"] lastObject];
  824. NSLog(@"%@",giftModel.youpaipsvga);
  825. NSString* svgaCanchesPath= [[NSString alloc]initWithFormat:@"%@/%@/%@",CachesPath,@"SVGA",svgaName];
  826. NSLog(@"%@",svgaCanchesPath);
  827. if (![LCTools giftSVGAWithSvgaUrlStr:giftModel.youpaipsvga]){
  828. NSString* urlStr = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,giftModel.youpaipsvga];
  829. @weakify(self);
  830. [self.parser parseWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
  831. @strongify(self);
  832. if (videoItem != nil) {
  833. self.svgaPlayer.videoItem = videoItem;
  834. [self.svgaPlayer startAnimation];
  835. }
  836. } failureBlock:^(NSError * _Nullable error) {
  837. @strongify(self);
  838. self.svgaPlayer.hidden = YES;
  839. }];
  840. [LCTools giftSVGAWithSvgaUrlStr:giftModel.youpaipsvga];
  841. }else{
  842. @weakify(self);
  843. [self.parser parseWithData:[LCTools giftSVGAWithSvgaUrlStr:giftModel.youpaipsvga] cacheKey:svgaCanchesPath completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
  844. @strongify(self);
  845. if (videoItem != nil) {
  846. self.svgaPlayer.videoItem = videoItem;
  847. [self.svgaPlayer startAnimation];
  848. }
  849. } failureBlock:^(NSError * _Nonnull error) {
  850. @strongify(self);
  851. self.svgaPlayer.hidden = YES;
  852. }];
  853. }
  854. }
  855. } failure:^(NSError *error) {
  856. }];
  857. }];
  858. [self TFPresentVC:view completion:^{
  859. }];
  860. }
  861. - (void)onVideoClick{
  862. if ([self.session.sessionId isEqualToString:[LCSaveData getServerId]]) {
  863. [ZCHUDHelper showTitle:@"暂时不能和客服视频通话"];
  864. return ;
  865. }
  866. if ([YOUPAILZChatRoomManager shareManager].chatroomWindow != nil && [YOUPAILZChatRoomManager shareManager].chatroomWindow.hidden == NO) {
  867. [ZCHUDHelper showTitle:@"你正在房间中,暂不可拨打视频"];
  868. return;
  869. }
  870. [UMengRecordTool umengEventCountWithId:StartVideoMessage];
  871. //v1.1.2 增加相机权限判断
  872. [UCAuthorityManager cameraAuthority:^{
  873. dispatch_async(dispatch_get_main_queue(), ^{
  874. [self.sessionInputView endEditing:YES];
  875. });
  876. [ZCHUDHelper show];
  877. if ([LCSaveData getWhiteVersion]) {//1
  878. [LCHttpHelper requestWithURLString:UserShowPage parameters:@{@"user_id":self.session.sessionId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  879. NSDictionary* dict = (NSDictionary*)responseObject;
  880. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  881. if (code==0) {//成功
  882. NSDictionary *data = [dict objectForKey:@"data"];
  883. YOUPAILCUserShowInfo *info = [YOUPAILCUserShowInfo mj_objectWithKeyValues:[data objectForKey:@"info"]];
  884. YOUPAIBBVideoRequestVC* chatRequest = [[YOUPAIBBVideoRequestVC alloc]init];
  885. YOUPAILCVideoChatModel *videoModel = [[YOUPAILCVideoChatModel alloc] init];
  886. videoModel.youpaiproom_id = [NSString stringWithFormat:@"C%@",[LCTools randomNumberWithLength:6]];
  887. videoModel.youpaipauditState = 1;
  888. videoModel.youpaipfrom_uid = [LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id;
  889. videoModel.youpaipfrom_nickname = [LCSaveModel getUserModel].youpaipuserinfo.youpaipnickname;
  890. videoModel.youpaipfrom_avatar = [LCSaveModel getUserModel].youpaipuserinfo.youpaipavatar;
  891. videoModel.youpaipto_uid = self.session.sessionId;
  892. videoModel.youpaipto_nickname = info.youpaipnickname;
  893. videoModel.youpaipto_avatar = info.youpaipavatar;
  894. chatRequest.youpaipvideoModel = videoModel;
  895. ZCBaseNavigationVC *nav = [[ZCBaseNavigationVC alloc]initWithRootViewController:chatRequest];
  896. //modify by leo fix bug ios13
  897. nav.modalPresentationStyle =0;
  898. [self.navigationController presentViewController:nav animated:YES completion:^{
  899. [ZCHUDHelper dismiss];
  900. }];
  901. }
  902. } failure:^(NSError *error) {
  903. [ZCHUDHelper dismiss];
  904. }];
  905. }else{//0
  906. // @"type":@"0" 代表视频通话, 1语音通话
  907. [LCHttpHelper requestWithURLString:CallChatType parameters:@{@"to_uid":self.session.sessionId,@"skill_id":@"",@"type":@"0"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  908. NSDictionary* dict = (NSDictionary*)responseObject;
  909. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  910. if (code==0) {//成功
  911. YOUPAILCVideoChatModel* videoModel = [YOUPAILCVideoChatModel mj_objectWithKeyValues:[dict objectForKey:@"data"]];
  912. [[YOUPAILZChatRoomManager shareManager] youpaifcloseChatRoom];
  913. [[NSNotificationCenter defaultCenter] postNotificationName:@"MeCallVideo" object:nil userInfo:nil];
  914. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  915. YOUPAILCVideoRequestVC* chatRequest = [[YOUPAILCVideoRequestVC alloc]init];
  916. chatRequest.youpaipvideoModel = videoModel;
  917. //modify by leo fix bug ios13
  918. ZCBaseNavigationVC *nav = [[ZCBaseNavigationVC alloc]initWithRootViewController:chatRequest];
  919. chatRequest.view.backgroundColor = HexColorFromRGBA(0x000000, 0.55);
  920. chatRequest.definesPresentationContext = YES;
  921. nav.modalPresentationStyle = UIModalPresentationOverCurrentContext;
  922. [self.navigationController presentViewController:nav animated:YES completion:^{
  923. // chatRequest.view.backgroundColor = HexColorFromRGBA(0x000000, 0.55);
  924. [ZCHUDHelper dismiss];
  925. }];
  926. });
  927. }
  928. } failure:^(NSError *error) {
  929. [ZCHUDHelper dismiss];
  930. }];
  931. }
  932. } denied:^{
  933. UIAlertController *systemAlert = [UIAlertController alertControllerWithTitle:@"请在iphone的“设置-隐私-相机”选项中,允许APP访问您的相机。" message:nil preferredStyle:UIAlertControllerStyleAlert];
  934. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"现在去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  935. if ([[UIDevice currentDevice].systemVersion floatValue] < 10.0)
  936. {
  937. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  938. }
  939. else
  940. {
  941. // 去系统设置页面
  942. if (@available(iOS 10.0, *)) {
  943. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  944. } else {
  945. // Fallback on earlier versions
  946. }
  947. }
  948. }];
  949. UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
  950. [systemAlert addAction:cancelAction];
  951. [systemAlert addAction:action];
  952. dispatch_async(dispatch_get_main_queue(), ^{
  953. [self presentViewController: systemAlert animated: YES completion: nil];
  954. });
  955. }];
  956. }
  957. - (void)pushEffectPresentToVC:(UIViewController*)vc{
  958. CATransition *transition = [CATransition animation];
  959. transition.duration = 0.25;
  960. transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
  961. transition.type = kCATransitionPush;
  962. transition.subtype = kCATransitionFromTop;
  963. [self.navigationController.view.layer addAnimation:transition forKey:nil];
  964. [self.navigationController pushViewController:vc animated:NO ];
  965. }
  966. //接收消息
  967. - (void)onRecvMessages:(NSArray *)messages
  968. {
  969. [super onRecvMessages:messages];
  970. NSLog(@"IM 收到消息了 🌵🥺🥺🥺🥺");
  971. NIMMessage *message = messages.firstObject;
  972. NIMSession *session = message.session;
  973. if (![session isEqual:self.session] || !messages.count)
  974. {
  975. // if ([LCSaveData getIsVideo]) {
  976. // YOUPAILCBaseVideoCallVC *videoVC = (YOUPAILCBaseVideoCallVC *)[ZCUtils getCurrentVC];
  977. // if([videoVC isKindOfClass:[YOUPAILCBaseVideoCallVC class]]){
  978. // NIMCustomObject *object = (NIMCustomObject*)message.messageObject;
  979. // if ([object.attachment isKindOfClass:[YOUPAILCGiftAttachment class]])
  980. // {
  981. // YOUPAILCGiftAttachment* attachment = (YOUPAILCGiftAttachment*)object.attachment;
  982. //
  983. // YOUPAILZLiveGIftModel *giftModel = [[YOUPAILZLiveGIftModel alloc] init];
  984. // giftModel.youpaipavatar = attachment.from_avatar; //赠送者头像
  985. // giftModel.youpaipnickName = attachment.from_nickname; //赠送者昵称
  986. // giftModel.youpaipgiftImage = attachment.gift_url; //礼物图片地址
  987. // giftModel.youpaipgiftCount = attachment.gift_count; //礼物个数
  988. // giftModel.youpaipuser_id = attachment.from_uid; // 发送者ID
  989. // giftModel.youpaipgift_id = attachment.gift_id; // //礼物id
  990. // giftModel.youpaipgift_svga = attachment.gift_svga; // //svga地址
  991. // giftModel.youpaipgift_type = attachment.gift_type; //礼物类型 0普通 1 svga动画礼物
  992. // giftModel.youpaipto_uid = attachment.to_uid; // 接收者ID
  993. // [videoVC giftMsgForIm:giftModel];
  994. // }
  995. // }
  996. //// [ZCHUDHelper showTitle:@"正在视频中"]
  997. //
  998. // }else{
  999. //
  1000. // }
  1001. return;
  1002. }
  1003. if (message.messageType == NIMMessageTypeCustom){
  1004. NIMCustomObject *object = (NIMCustomObject*)message.messageObject;
  1005. if ([object.attachment isKindOfClass:[YOUPAILCGiftAttachment class]])
  1006. {
  1007. YOUPAILCGiftAttachment* attachment = (YOUPAILCGiftAttachment*)object.attachment;
  1008. // [ZCHUDHelper showTitle:@"收到一个礼物"];
  1009. NSLog(@"%@",attachment.gift_url);
  1010. NSLog(@"%@",attachment.gift_svga);
  1011. [self.svgaPlayer stopAnimation];
  1012. if (attachment.gift_type == 1 && ![attachment.gift_svga isEqualToString:@""]) {
  1013. self.svgaPlayer.hidden = NO;
  1014. }
  1015. NSString* svgaName = [[attachment.gift_svga componentsSeparatedByString:@"/"] lastObject];
  1016. NSString* svgaCanchesPath= [[NSString alloc]initWithFormat:@"%@/%@/%@",CachesPath,@"SVGA",svgaName];
  1017. NSLog(@"%@",svgaCanchesPath);
  1018. if (![LCTools giftSVGAWithSvgaUrlStr:attachment.gift_svga]){
  1019. NSString* urlStr = [NSString stringWithFormat:@"%@/%@",[LCSaveData getImageUrl]?[LCSaveData getImageUrl]:BaseImgUrl,attachment.gift_svga];
  1020. @weakify(self);
  1021. [self.parser parseWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]] completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
  1022. @strongify(self);
  1023. if (videoItem != nil) {
  1024. self.svgaPlayer.videoItem = videoItem;
  1025. [self.svgaPlayer startAnimation];
  1026. }
  1027. } failureBlock:^(NSError * _Nullable error) {
  1028. @strongify(self);
  1029. self.svgaPlayer.hidden = YES;
  1030. }];
  1031. [LCTools giftSVGAWithSvgaUrlStr:attachment.gift_svga];
  1032. }else{
  1033. @weakify(self);
  1034. [self.parser parseWithData:[LCTools giftSVGAWithSvgaUrlStr:attachment.gift_svga] cacheKey:svgaCanchesPath completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
  1035. @strongify(self);
  1036. if (videoItem != nil) {
  1037. self.svgaPlayer.videoItem = videoItem;
  1038. [self.svgaPlayer startAnimation];
  1039. }
  1040. } failureBlock:^(NSError * _Nonnull error) {
  1041. @strongify(self);
  1042. self.svgaPlayer.hidden = YES;
  1043. }];
  1044. }
  1045. }
  1046. }
  1047. }
  1048. @end