YOUPAILCMessageVC.m 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. //
  2. // YOUPAILCMessageVC.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/4/12.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCMessageVC.h"
  9. #import "NTESBundleSetting.h"
  10. #import "NTESSessionUtil.h"
  11. #import "YOUPAILCGiftAttachment.h"
  12. #import "YOUPAILCMultiImageAttachment.h"
  13. #import "YOUPAILCOneImageAttachment.h"
  14. #import "YOUPAILCMessageTxtAttachment.h"
  15. #import "YOUPAILCCallAttachment.h"
  16. #import "UIViewController+TFPresent.h"
  17. #import "YOUPAIZYUpdateRemarkWindow.h"
  18. #import "YOUPAILCReportVC.h"
  19. #import "LZAlertWindow.h"
  20. #import "YOUPAIZhaPianTextAttachment.h"
  21. #import "YOUPAIZhaPianTextAttachment2.h"
  22. #import "TYCyclePagerView.h"
  23. #import "TYPageControl.h"
  24. #import "YOUPAILZHomeBannerCell.h"
  25. #import "YOUPAILCBannerModel.h"
  26. #import "YOUPAIFateTextAttachment.h"
  27. @interface YOUPAILCMessageVC ()<UIViewControllerPreviewingDelegate,UIGestureRecognizerDelegate,TYCyclePagerViewDelegate,TYCyclePagerViewDataSource>
  28. @property (nonatomic,strong) UILabel *youpaiptitleLabel;
  29. @property (nonatomic,assign) BOOL youpaipsupportsForceTouch;
  30. @property (nonatomic,strong) NSMutableDictionary *youpaippreviews;
  31. @property (nonatomic,strong) NSArray *youpaiptop_listArray;//置顶列表
  32. @property (nonatomic, weak) TYCyclePagerView *youpaipbannerView;
  33. @property (strong, nonatomic) TYPageControl *youpaippageControl;
  34. @property (strong, nonatomic) NSMutableArray *youpaipimageURLStringsGroup;
  35. @property (nonatomic, strong) NSArray <YOUPAILCBannerModel *> *youpaipbannerArray;
  36. @property (nonatomic, weak)UIView *headerV;
  37. @property (nonatomic, strong) UIView *tableHeader;
  38. @end
  39. @implementation YOUPAILCMessageVC
  40. - (UIStatusBarStyle)preferredStatusBarStyle{
  41. return UIStatusBarStyleLightContent;
  42. }
  43. - (void)viewWillAppear:(BOOL)animated{
  44. [super viewWillAppear:animated];
  45. [UMengRecordTool umengEnterViewWithName:NSStringFromClass(self.class)];
  46. if (![LCSaveData getHiddenGuideState] && ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 1 && [LCSaveModel getUserModel].youpaipuserinfo.youpaipis_anchor != 1) && ![LCSaveData getWhiteVersion]) {
  47. self.headerV.mj_h = 18.0f + ScaleSize(82.0f) + 74.0f;
  48. }else{
  49. self.headerV.mj_h = 18.0f + ScaleSize(82.0f);
  50. }
  51. // 隐藏行为公告,用户指南等 banner
  52. self.headerV.mj_h = 0.1;
  53. //消息列表适配暗黑模式 v1.5.6
  54. [self.tableView setBackgroundColor:[UIColor whiteColor]];
  55. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(youpaiflongTapAction:)];
  56. longPress.minimumPressDuration = 0.5; //定义按的时间
  57. longPress.numberOfTouchesRequired = 1;
  58. [self.tableView addGestureRecognizer:longPress];
  59. [self youpaifrefreshList];
  60. }
  61. - (void)viewWillDisappear:(BOOL)animated{
  62. [super viewWillDisappear:animated];
  63. [self.navigationController.navigationBar setDefaultBar];
  64. [UMengRecordTool umengOutViewWithName:NSStringFromClass(self.class)];
  65. }
  66. - (void)youpaifinitConfig{ //系统配置信息
  67. [LCHttpHelper requestWithURLString:AppConfig parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  68. NSDictionary* dict = (NSDictionary*)responseObject;
  69. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  70. if (code==0) {//成功
  71. self->_youpaiptop_listArray = [[[dict objectForKey:@"data"]objectForKey:@"config"] objectForKey:@"top_list"];
  72. for (NSString *sessionId in self->_youpaiptop_listArray) {
  73. NIMSession *session = [NIMSession session:sessionId type:NIMSessionTypeP2P];
  74. [NTESSessionUtil addRecentSessionMark:session type:NTESRecentSessionMarkTypeTop];
  75. }
  76. }
  77. } failure:^(NSError *error) {
  78. }];
  79. }
  80. - (void)viewDidLoad {
  81. [super viewDidLoad];
  82. [self.view setBackgroundColor:[UIColor clearColor]];
  83. //modify by leo 20191030
  84. /*
  85. self.navigationItem.title = @"消息";
  86. self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifsystemClick) image:[UIImage imageNamed:@"vqu_images_IM_im_remind"]];
  87. */
  88. self.youpaipsupportsForceTouch = [self.traitCollection respondsToSelector:@selector(forceTouchCapability)] && self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable;
  89. UIButton* sayHiBtn = [[UIButton alloc]initWithFrame:CGRectMake(0,0,24,44)];
  90. [sayHiBtn setImage:[UIImage imageNamed:@"vqu_images_nav_more_black"] forState:(UIControlStateNormal)];
  91. [sayHiBtn addTarget:self action:@selector(youpaifsayHiBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  92. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:sayHiBtn];
  93. [self youpaifinitConfig];
  94. [self youpaifinitUI];
  95. [self youpaifrequestBannerData];
  96. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifintimateChangeNotification:) name:@"VQUIMIntimateChangeNotification" object:nil];
  97. self.tableView.tableHeaderView = self.tableHeader;
  98. }
  99. - (void)youpaifintimateChangeNotification:(NSNotification *)notify{
  100. NSDictionary *dataDic = notify.userInfo;
  101. for (NSInteger i = 0 ; i < self.recentSessions.count; i ++) {
  102. NIMRecentSession *session = self.recentSessions[i];
  103. if ([session.session.sessionId isEqual:dataDic[@"uid"]]) {
  104. [UIView performWithoutAnimation:^{
  105. [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:i] withRowAnimation:UITableViewRowAnimationNone];
  106. }];
  107. break;
  108. }
  109. }
  110. }
  111. - (void)youpaifinitUI{
  112. if (self.isIntimateList) {
  113. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  114. make.left.mas_equalTo(0);
  115. make.right.mas_equalTo(0);
  116. make.top.mas_equalTo(0);
  117. make.bottom.mas_equalTo(0);
  118. }];
  119. return;
  120. }
  121. UIView *headerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 18.0f + ScaleSize(82.0f))];
  122. headerV.frame = CGRectMake(0, 0, kScreenWidth, 0.1);
  123. headerV.hidden = YES;
  124. [self.view addSubview:headerV];
  125. self.headerV = headerV;
  126. [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
  127. make.left.mas_equalTo(0);
  128. make.right.mas_equalTo(0);
  129. make.top.equalTo(headerV.mas_bottom).offset(0);
  130. make.bottom.mas_equalTo(0);
  131. }];
  132. TYCyclePagerView *bannerView = [[TYCyclePagerView alloc]initWithFrame:CGRectMake(0, 9.0f, KScreenWidth,ScaleSize(82.0f))];
  133. [headerV addSubview:bannerView];
  134. bannerView.isInfiniteLoop = YES;
  135. bannerView.autoScrollInterval = 6.0;
  136. bannerView.layer.cornerRadius = ScaleSize(10.0f);
  137. bannerView.clipsToBounds = YES;
  138. bannerView.dataSource = self;
  139. bannerView.delegate = self;
  140. [bannerView registerClass:[YOUPAILZHomeBannerCell class] forCellWithReuseIdentifier:@"cellId"];
  141. self.youpaipbannerView = bannerView;
  142. bannerView.backgroundColor = [UIColor whiteColor];
  143. TYPageControl *pageControl = [[TYPageControl alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(_youpaipbannerView.frame) - 26, CGRectGetWidth(_youpaipbannerView.frame), 26)];
  144. //pageControl.numberOfPages = _datas.count;
  145. pageControl.currentPageIndicatorSize = CGSizeMake(6, 6);
  146. pageControl.pageIndicatorSize = CGSizeMake(6, 6);
  147. // pageControl.currentPageIndicatorTintColor = [UIColor redColor];
  148. // pageControl.pageIndicatorTintColor = [UIColor grayColor];
  149. pageControl.pageIndicatorImage = [UIImage imageNamed:@"vqu_images_H_home_page_n"];
  150. pageControl.currentPageIndicatorImage = [UIImage imageNamed:@"vqu_images_H_home_page_s"];
  151. pageControl.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
  152. pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
  153. pageControl.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  154. pageControl.pageIndicatorSpaing = 1;
  155. [bannerView addSubview:pageControl];
  156. self.youpaippageControl = pageControl;
  157. }
  158. - (UIView *)tableHeader {
  159. if (!_tableHeader) {
  160. _tableHeader = [[UIView alloc] init];
  161. _tableHeader.frame = CGRectMake(0, 0, kScreenWidth, 130);
  162. _tableHeader.backgroundColor = [UIColor whiteColor];
  163. CGFloat anNiuKuanDu = kScreenWidth / 3.0;
  164. CGFloat anNiuGaoDu = 80;
  165. CGFloat biaoQianGaoDu = 20;
  166. CGFloat shangBianJu = 15;
  167. // 第一个按钮 - 在线客服
  168. UIButton *zaiXianKeHuAnNiu = [[UIButton alloc] init];
  169. zaiXianKeHuAnNiu.frame = CGRectMake(0, shangBianJu, anNiuKuanDu, anNiuGaoDu);
  170. [zaiXianKeHuAnNiu setImage:ImageByName(@"vqu_images_zaixiankefu") forState:UIControlStateNormal];
  171. zaiXianKeHuAnNiu.tag = 100;
  172. [zaiXianKeHuAnNiu addTarget:self action:@selector(tableHeaderButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  173. [_tableHeader addSubview:zaiXianKeHuAnNiu];
  174. UILabel *zaiXianKeHuBiaoQian = [[UILabel alloc] init];
  175. zaiXianKeHuBiaoQian.frame = CGRectMake(0, shangBianJu + anNiuGaoDu, anNiuKuanDu, biaoQianGaoDu);
  176. zaiXianKeHuBiaoQian.text = @"在线客服";
  177. zaiXianKeHuBiaoQian.textAlignment = NSTextAlignmentCenter;
  178. zaiXianKeHuBiaoQian.font = LCFont12;
  179. zaiXianKeHuBiaoQian.textColor = LZ273145Color;
  180. [_tableHeader addSubview:zaiXianKeHuBiaoQian];
  181. // 第二个按钮 - 系统消息
  182. UIButton *xiTongXiaoXiAnNiu = [[UIButton alloc] init];
  183. xiTongXiaoXiAnNiu.frame = CGRectMake(anNiuKuanDu, shangBianJu, anNiuKuanDu, anNiuGaoDu);
  184. [xiTongXiaoXiAnNiu setImage:ImageByName(@"vqu_images_xitongxiaoxi") forState:UIControlStateNormal];
  185. xiTongXiaoXiAnNiu.tag = 101;
  186. [xiTongXiaoXiAnNiu addTarget:self action:@selector(tableHeaderButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  187. [_tableHeader addSubview:xiTongXiaoXiAnNiu];
  188. UILabel *xiTongXiaoXiBiaoQian = [[UILabel alloc] init];
  189. xiTongXiaoXiBiaoQian.frame = CGRectMake(anNiuKuanDu, shangBianJu + anNiuGaoDu, anNiuKuanDu, biaoQianGaoDu);
  190. xiTongXiaoXiBiaoQian.text = @"系统消息";
  191. xiTongXiaoXiBiaoQian.textAlignment = NSTextAlignmentCenter;
  192. xiTongXiaoXiBiaoQian.font = LCFont12;
  193. xiTongXiaoXiBiaoQian.textColor = LZ273145Color;
  194. [_tableHeader addSubview:xiTongXiaoXiBiaoQian];
  195. // 第三个按钮 - 合作洽谈
  196. UIButton *heZuoQiaTanAnNiu = [[UIButton alloc] init];
  197. heZuoQiaTanAnNiu.frame = CGRectMake(anNiuKuanDu * 2, shangBianJu, anNiuKuanDu, anNiuGaoDu);
  198. [heZuoQiaTanAnNiu setImage:ImageByName(@"vqu_images_hezuoqiatan") forState:UIControlStateNormal];
  199. heZuoQiaTanAnNiu.tag = 102;
  200. [heZuoQiaTanAnNiu addTarget:self action:@selector(tableHeaderButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  201. [_tableHeader addSubview:heZuoQiaTanAnNiu];
  202. UILabel *heZuoQiaTanBiaoQian = [[UILabel alloc] init];
  203. heZuoQiaTanBiaoQian.frame = CGRectMake(anNiuKuanDu * 2, shangBianJu + anNiuGaoDu, anNiuKuanDu, biaoQianGaoDu);
  204. heZuoQiaTanBiaoQian.text = @"合作洽谈";
  205. heZuoQiaTanBiaoQian.textAlignment = NSTextAlignmentCenter;
  206. heZuoQiaTanBiaoQian.font = LCFont12;
  207. heZuoQiaTanBiaoQian.textColor = LZ273145Color;
  208. [_tableHeader addSubview:heZuoQiaTanBiaoQian];
  209. // // 添加底部分割线
  210. // UIView *fenGexian = [[UIView alloc] init];
  211. // fenGexian.frame = CGRectMake(0, 99, kScreenWidth, 1);
  212. // fenGexian.backgroundColor = LZF5F4F7Color;
  213. // [_tableHeader addSubview:fenGexian];
  214. }
  215. return _tableHeader;
  216. }
  217. // 按钮点击事件处理
  218. - (void)tableHeaderButtonClicked:(UIButton *)sender {
  219. NSInteger index = sender.tag - 100;
  220. switch (index) {
  221. case 0: // 在线客服
  222. [self handleOnlineCustomerService];
  223. break;
  224. case 1: // 系统消息
  225. [self youpaifsystemClick];
  226. break;
  227. case 2: // 合作洽谈
  228. [self handleCooperationConsultation];
  229. break;
  230. default:
  231. break;
  232. }
  233. }
  234. // 在线客服点击事件
  235. - (void)handleOnlineCustomerService {
  236. NIMSession *session = [NIMSession session:[LCSaveData getServerId] type:NIMSessionTypeP2P];
  237. if (session) {
  238. //@weakify(self);
  239. [ZCHUDHelper show];
  240. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  241. [ZCHUDHelper dismiss];
  242. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
  243. [[LCTools getContainNavigationControllerCurrentVC].navigationController pushViewController:vc animated:YES];
  244. }];
  245. }
  246. }
  247. // 合作洽谈点击事件
  248. - (void)handleCooperationConsultation {
  249. NIMSession *session = [NIMSession session:[LCSaveData getCooperationId] type:NIMSessionTypeP2P];
  250. if (session) {
  251. //@weakify(self);
  252. [ZCHUDHelper show];
  253. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  254. [ZCHUDHelper dismiss];
  255. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
  256. [[LCTools getContainNavigationControllerCurrentVC].navigationController pushViewController:vc animated:YES];
  257. }];
  258. }
  259. }
  260. #pragma mark - TYCyclePagerViewDataSource
  261. - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
  262. return self.youpaipimageURLStringsGroup.count;
  263. }
  264. - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
  265. YOUPAILZHomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndex:index];
  266. NSString *url;
  267. // absoluteString
  268. if (self.youpaipimageURLStringsGroup) {
  269. url = [self.youpaipimageURLStringsGroup[index] absoluteString];
  270. [cell.youpaipbgImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"banner_default"]];
  271. }
  272. cell.layer.cornerRadius = ScaleSize(10);
  273. cell.layer.masksToBounds = YES;
  274. cell.backgroundColor = [UIColor redColor];
  275. // cell.backgroundColor = _datas[index];
  276. // cell.label.text = [NSString stringWithFormat:@"index->%ld",index];
  277. return cell;
  278. }
  279. - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
  280. TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
  281. layout.itemSize = CGSizeMake(CGRectGetWidth(pageView.frame)*0.93, CGRectGetHeight(pageView.frame)*0.93);
  282. layout.itemSpacing = 20;
  283. // ScaleSize(10.0f)
  284. layout.layoutType = TYCyclePagerTransformLayoutNormal;
  285. //layout.minimumAlpha = 0.3;
  286. return layout;
  287. }
  288. - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index{
  289. YOUPAILCBannerModel* model = self.youpaipbannerArray[index];
  290. if (model.youpaiplink_type==1) {
  291. ZCBaseWebVC* baseWeb = [[ZCBaseWebVC alloc]init];
  292. baseWeb.contentUrl = model.youpaiplink_url;
  293. [self.navigationController pushViewController:baseWeb animated:YES];
  294. }else if (model.youpaiplink_type==2||model.youpaiplink_type==3){
  295. [self youpaifpageToStr:model.youpaiplink_url];
  296. }
  297. }
  298. - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {
  299. self.youpaippageControl.currentPage = toIndex;
  300. }
  301. /// 获取banner数据
  302. - (void)youpaifrequestBannerData{
  303. @weakify(self);
  304. [LCHttpHelper requestWithURLString:HomeBanner parameters:@{@"cate_id":@"5"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  305. @strongify(self);
  306. NSDictionary* dict = (NSDictionary*)responseObject;
  307. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  308. if (code==0) {//成功
  309. self.youpaipbannerArray = [YOUPAILCBannerModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"banner"]];
  310. [self youpaifreloadBannerData];
  311. }
  312. } failure:^(NSError *error) {
  313. }];
  314. }
  315. -(void)youpaifreloadBannerData{
  316. NSMutableArray *imgUrlArray = [NSMutableArray array];
  317. for (YOUPAILCBannerModel* model in self.youpaipbannerArray) {
  318. [imgUrlArray addObject:[LCTools getImageUrlWithAddress:model.youpaipimage]];
  319. }
  320. self.youpaippageControl.numberOfPages = imgUrlArray.count;
  321. self.youpaipimageURLStringsGroup = imgUrlArray;
  322. [self.youpaipbannerView reloadData];
  323. }
  324. #pragma mark-一键已读
  325. -(void)youpaifsayHiBtnClick{
  326. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) {
  327. }];
  328. cancelAction.cornerRadius = 24.0f;
  329. cancelAction.bgColor = LZF5F4F7Color;
  330. cancelAction.color = LZ273145Color;
  331. LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"确定" handler:^(LZAlertAction *action) {
  332. //一键已读
  333. [[NIMSDK sharedSDK].conversationManager markAllMessagesRead];
  334. }];
  335. confimAction.cornerRadius = 24.0f;
  336. confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]];
  337. confimAction.color = [UIColor whiteColor];
  338. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"一键已读" content:@"消息红点气泡会消失,但消息不丢失,也不会显示“已读”。" action:@[cancelAction,confimAction]];
  339. [self TFPresentVC:alert completion:^{}];
  340. }
  341. - (void)youpaifsystemClick{
  342. NIMSession *session = [NIMSession session:[LCSaveData getSysId] type:NIMSessionTypeP2P];
  343. if (session) {
  344. @weakify(self);
  345. [ZCHUDHelper show];
  346. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  347. @strongify(self);
  348. [ZCHUDHelper dismiss];
  349. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session];
  350. [self.navigationController pushViewController:vc animated:YES];
  351. }];
  352. }
  353. }
  354. - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
  355. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  356. if (self) {
  357. _youpaippreviews = [[NSMutableDictionary alloc] init];
  358. self.autoRemoveRemoteSession = [[NTESBundleSetting sharedConfig] autoRemoveRemoteSession];
  359. }
  360. return self;
  361. }
  362. - (void)youpaifrefreshList{
  363. if (self.recentSessions.count == 0) {//有时候会拿不到数据
  364. self.recentSessions = [[NIMSDK sharedSDK].conversationManager.allRecentSessions mutableCopy];//获取所有最近会话。
  365. }
  366. self.recentSessions = [self customSortRecents:self.recentSessions];
  367. [self.tableView reloadData];
  368. if (![self isNotDataSource]) {
  369. [self.tableView lz_hideEmptyView];
  370. }else{
  371. [self showEmptyView];
  372. }
  373. }
  374. - (void)showEmptyView{
  375. if (self.isIntimateList) {
  376. @weakify(self);
  377. [self.tableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_im_intimate_list_not_data"] title:@"亲密度≥37的亲密关系会在这里显示哦~" content:@"立即聊天,遇见亲密的Ta" btnTitle:@"去聊天" styleBlock:^(LYEmptyView * _Nonnull emptyView) {
  378. emptyView.imageSize = CGSizeMake(222, 95);
  379. emptyView.titleLabTextColor = LZ475A7DColor;
  380. emptyView.titleLabFont = LCFont14;
  381. emptyView.titleLabMargin = 24.0f;
  382. emptyView.detailLabTextColor = LZA3AABEColor;
  383. emptyView.detailLabFont = LCFont12;
  384. emptyView.detailLabMargin = 12.0f;
  385. emptyView.actionBtnFont = LCFont16;
  386. emptyView.actionBtnTitleColor = [UIColor whiteColor];
  387. emptyView.actionBtnHeight = 40.0f;
  388. emptyView.actionBtnWidth = 98.0f;
  389. emptyView.actionBtnCornerRadius = 20.0f;
  390. emptyView.actionBtnBackGroundColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake(98.0f, 40.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]];
  391. emptyView.actionBtnMargin = 24.0f;
  392. } block:^{
  393. @strongify(self);
  394. if (self.goMessageListPageBlock != nil) {
  395. self.goMessageListPageBlock();
  396. }
  397. }];
  398. }else{
  399. [self.tableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_call_video_data"] content:@"暂无消息记录"];
  400. for (UIView *view in self.tableView.subviews) {
  401. if ([view isKindOfClass:[LZEmptyView class]]) {
  402. view.userInteractionEnabled = NO;
  403. }
  404. }
  405. }
  406. }
  407. //对最近会话重新排序
  408. - (NSMutableArray *)customSortRecents:(NSMutableArray *)recentSessions
  409. {
  410. NSMutableArray *array = [[NSMutableArray alloc] initWithArray:recentSessions];
  411. [array sortUsingComparator:^NSComparisonResult(NIMRecentSession *obj1, NIMRecentSession *obj2) {
  412. NSInteger score1 = [NTESSessionUtil recentSessionIsMark:obj1 type:NTESRecentSessionMarkTypeTop]? 10 : 0;
  413. NSInteger score2 = [NTESSessionUtil recentSessionIsMark:obj2 type:NTESRecentSessionMarkTypeTop]? 10 : 0;
  414. if (obj1.lastMessage.timestamp > obj2.lastMessage.timestamp)
  415. {
  416. score1 += 1;
  417. }
  418. else if (obj1.lastMessage.timestamp < obj2.lastMessage.timestamp)
  419. {
  420. score2 += 1;
  421. }
  422. if (score1 == score2)
  423. {
  424. return NSOrderedSame;
  425. }
  426. return score1 > score2? NSOrderedAscending : NSOrderedDescending;
  427. }];
  428. return array;
  429. }
  430. #pragma mark - UITableViewDelegate
  431. //- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  432. // return YES;
  433. //}
  434. //- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
  435. //{
  436. // return UITableViewCellEditingStyleDelete;
  437. //}
  438. //- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  439. // NIMRecentSession *recentSession = self.recentSessions[indexPath.row];
  440. // if (editingStyle == UITableViewCellEditingStyleDelete) {
  441. //// id<NIMConversationManager> manager = [[NIMSDK sharedSDK] conversationManager]; //删除最近会话
  442. //// [manager deleteRecentSession:recentSession];
  443. // //删除最近会话并且删除消息
  444. // id<NIMConversationManager> manager = [[NIMSDK sharedSDK] conversationManager];
  445. // NIMDeleteMessagesOption* deleteOption = [[NIMDeleteMessagesOption alloc]init];
  446. // deleteOption.removeSession = YES;
  447. // deleteOption.removeTable = YES;
  448. // [manager deleteAllmessagesInSession:recentSession.session option:deleteOption];
  449. // }
  450. //}
  451. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  452. {
  453. if (self.youpaipsupportsForceTouch) {
  454. id<UIViewControllerPreviewing> preview = [self registerForPreviewingWithDelegate:self sourceView:cell];
  455. [self.youpaippreviews setObject:preview forKey:@(indexPath.row)];
  456. }
  457. }
  458. - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  459. {
  460. if (self.youpaipsupportsForceTouch) {
  461. id<UIViewControllerPreviewing> preview = [self.youpaippreviews objectForKey:@(indexPath.row)];
  462. [self unregisterForPreviewingWithContext:preview];
  463. [self.youpaippreviews removeObjectForKey:@(indexPath.row)];
  464. }
  465. }
  466. - (void)onSelectedRecent:(NIMRecentSession *)recentSession atIndexPath:(NSIndexPath *)indexPath{
  467. @weakify(self);
  468. [ZCHUDHelper show];
  469. [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[recentSession.session.sessionId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
  470. @strongify(self);
  471. [ZCHUDHelper dismiss];
  472. YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:recentSession.session];
  473. vc.type = @"3";
  474. [self.navigationController pushViewController:vc animated:YES];
  475. }];
  476. }
  477. - (NSString *)messageContent:(NIMMessage*)lastMessage{
  478. if (lastMessage.messageType == NIMMessageTypeCustom)
  479. {
  480. NIMCustomObject *object = (NIMCustomObject*)lastMessage.messageObject;
  481. NSString *text = @"";
  482. if ([object.attachment isKindOfClass:[YOUPAILCMessageTxtAttachment class]])
  483. {
  484. YOUPAILCMessageTxtAttachment* attachment = (YOUPAILCMessageTxtAttachment*)object.attachment;
  485. text = attachment.title;
  486. }
  487. if ([object.attachment isKindOfClass:[YOUPAIZhaPianTextAttachment class]])
  488. {
  489. }
  490. if ([object.attachment isKindOfClass:[YOUPAIZhaPianTextAttachment2 class]])
  491. {
  492. }
  493. if ([object.attachment isKindOfClass:[YOUPAILCMessageTxtAttachment class]])
  494. {
  495. YOUPAILCMessageTxtAttachment* attachment = (YOUPAILCMessageTxtAttachment*)object.attachment;
  496. text = attachment.title;
  497. }
  498. if ([object.attachment isKindOfClass:[YOUPAILCOneImageAttachment class]])
  499. {
  500. YOUPAILCOneImageAttachment* attachment = (YOUPAILCOneImageAttachment*)object.attachment;
  501. if (attachment.act_type==1) {
  502. text = attachment.act_string;
  503. }else{
  504. text = attachment.title;
  505. }
  506. }
  507. if ([object.attachment isKindOfClass:[YOUPAILCMultiImageAttachment class]])
  508. {
  509. YOUPAILCMultiImageAttachment* attachment = (YOUPAILCMultiImageAttachment*)object.attachment;
  510. if (attachment.imageArray.count != 0) {
  511. NSDictionary* topDict = attachment.imageArray[0];
  512. text = [topDict objectForKey:@"title"];
  513. }
  514. }
  515. if ([object.attachment isKindOfClass:[YOUPAILCGiftAttachment class]])
  516. {
  517. YOUPAILCGiftAttachment* attachment = (YOUPAILCGiftAttachment*)object.attachment;
  518. if ([[NSString stringWithFormat:@"%zd",attachment.from_uid] isEqualToString:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) {
  519. text = @"[赠送礼物]";
  520. }else{
  521. text = @"[收到礼物]";
  522. }
  523. }
  524. if ([object.attachment isKindOfClass:[YOUPAILPFollowAttachment class]]){
  525. //modify by leo v1.0.7 上线通知
  526. YOUPAILPFollowAttachment* attachment = (YOUPAILPFollowAttachment *)object.attachment;
  527. if(attachment.type == 16)
  528. {
  529. text = @"新增粉丝";
  530. }
  531. //modify by leo v1.0.8 动态更新
  532. else if(attachment.type == 17)
  533. {
  534. NSString *nickeName = attachment.nickname;
  535. text = [NSString stringWithFormat:@"%@更新了动态",nickeName];
  536. }
  537. else
  538. {
  539. NSString *nickeName = attachment.nickname;
  540. text = [NSString stringWithFormat:@"%@上线啦!",nickeName];
  541. }
  542. }
  543. if ([object.attachment isKindOfClass:[YOUPAIFateTextAttachment class]]) {
  544. text = @"[缘分牵线]";
  545. }
  546. if ([object.attachment isKindOfClass:[YOUPAILCCallAttachment class]])
  547. {
  548. YOUPAILCCallAttachment* attachment = (YOUPAILCCallAttachment*)object.attachment;
  549. if (attachment.calltype==1) {
  550. text = @"[视频通话]";
  551. }
  552. NSString* txtStr = @"";
  553. if (attachment.status==3) {
  554. txtStr =@"[超时未接听]";
  555. }else if (attachment.status==4){
  556. txtStr = [NSString stringWithFormat:@"[通话时长:%@]",[ZCUtils getMinTimeStrFromSS:attachment.call_time]];
  557. }
  558. NSLog(@"代表是自己发的%@-----%ld", [LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id , (long)attachment.from_uid);
  559. if ([[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id integerValue] == attachment.from_uid) {//代表是自己发的
  560. // NSLog(@"代表是自己发的%@-----%@", [LCSaveModel getUserModel].userinfo.user_id , attachment.from_uid);
  561. if (attachment.status==1) {
  562. txtStr = @"[已取消]";
  563. }else if (attachment.status==2){
  564. txtStr = @"[对方已拒绝]";
  565. }
  566. }else{
  567. if (attachment.status==1) {
  568. txtStr = @"[对方已取消]";
  569. }else if (attachment.status==2){
  570. txtStr = @"[已拒绝]";
  571. }
  572. }
  573. text = [NSString stringWithFormat:@"%@%@",text,txtStr];
  574. }
  575. return text;
  576. }else{
  577. if (lastMessage.messageType == NIMMessageTypeTip) {
  578. return @"[提醒消息]";
  579. }else{
  580. return [super messageContent:lastMessage];
  581. }
  582. }
  583. }
  584. -(void)youpaiflongTapAction:(UILongPressGestureRecognizer *)longPress {
  585. if (longPress.state == UIGestureRecognizerStateBegan) {
  586. AudioServicesPlaySystemSound(1519);
  587. }else if (longPress.state == UIGestureRecognizerStateEnded){
  588. CGPoint p = [longPress locationInView:self.tableView] ;// get longpress pt
  589. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p] ; // get indexpath from table with point .
  590. NIMRecentSession *recentSession = self.recentSessions[indexPath.section];
  591. if ([_youpaiptop_listArray containsObject:recentSession.session.sessionId]) {//置顶列表
  592. return;
  593. }
  594. @weakify(self);
  595. ZCAlertAction* deleteAction = [ZCAlertAction actionWithTitle:@"删除" andblock:^{
  596. @strongify(self);
  597. [self messagePopupWindowAction:@"deleteChat" andSession:recentSession.session];
  598. }];
  599. ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:@[deleteAction]];
  600. alertSheet.alertWindow.hidden = NO;
  601. [alertSheet show];
  602. NSLog(@"sessionI2 == %@",recentSession.session.sessionId);
  603. }
  604. }
  605. -(void)dealloc
  606. {
  607. [[NSNotificationCenter defaultCenter] removeObserver:self];
  608. NSLog(@"lcmessage dealloc");
  609. }
  610. #pragma mark ZYMessagePopupWindowDelegate
  611. -(void)messagePopupWindowAction:(NSString *)type andSession:(NIMSession *)session
  612. {
  613. if ([type isEqualToString:@"updateRemark"]) {//设置备注名
  614. YOUPAIZYUpdateRemarkWindow *VC= [[YOUPAIZYUpdateRemarkWindow alloc]init];
  615. VC.vWidth = KScreenWidth -68;
  616. VC.vHeight = ScaleHeight(187)+10;
  617. VC.youpaipsession = session;
  618. VC.isTouchDismiss = NO;
  619. [kAppDelegate.window.rootViewController TFPresentVC:VC completion:^{
  620. }];
  621. }
  622. if ([type isEqualToString:@"deleteChat"]) {//删除聊天
  623. WeakSelf;
  624. LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) {
  625. }];
  626. cancelAction.cornerRadius = 24.0f;
  627. cancelAction.color = LZ273145Color;
  628. cancelAction.bgColor = LZF5F4F7Color;
  629. LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"删除" handler:^(LZAlertAction *action) {
  630. [weakSelf deleteChatWithSession:session];
  631. }];
  632. confimAction.cornerRadius = 24.0f;
  633. confimAction.color = [UIColor whiteColor];
  634. confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]];
  635. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"确定删除该聊天?" action:@[cancelAction,confimAction]];
  636. alert.contentTextAlignment = NSTextAlignmentCenter;
  637. [self TFPresentVC:alert completion:^{}];
  638. }
  639. if ([type isEqualToString:@"top"]) {//置顶该聊天
  640. }
  641. if ([type isEqualToString:@"blacklist"]) {//加入黑名单
  642. }
  643. if ([type isEqualToString:@"report"]) {//举报
  644. YOUPAILCReportVC* report = [[YOUPAILCReportVC alloc]init];
  645. report.youpaipreport_uid = session.sessionId;
  646. report.youpaiptype = 4;
  647. [self.navigationController pushViewController:report animated:YES];
  648. }
  649. }
  650. #pragma mark ZYDeleteChatWindowDelegate
  651. -(void)deleteChatWithSession:(NIMSession *)session
  652. {
  653. id<NIMConversationManager> manager = [[NIMSDK sharedSDK] conversationManager];
  654. NIMDeleteMessagesOption* deleteOption = [[NIMDeleteMessagesOption alloc]init];
  655. deleteOption.removeSession = YES;
  656. deleteOption.removeTable = YES;
  657. [manager deleteAllmessagesInSession:session option:deleteOption];
  658. }
  659. #pragma mark - JXCategoryListContainerView
  660. - (UIView *)listView{
  661. return self.view;
  662. }
  663. @end