// // YOUPAILCMessageVC.m // LiveChat // // Created by 张灿 on 2018/4/12. // Copyright © 2018年 caicai. All rights reserved. // #import "YOUPAILCMessageVC.h" #import "NTESBundleSetting.h" #import "NTESSessionUtil.h" #import "YOUPAILCGiftAttachment.h" #import "YOUPAILCMultiImageAttachment.h" #import "YOUPAILCOneImageAttachment.h" #import "YOUPAILCMessageTxtAttachment.h" #import "YOUPAILCCallAttachment.h" #import "UIViewController+TFPresent.h" #import "YOUPAIZYUpdateRemarkWindow.h" #import "YOUPAILCReportVC.h" #import "LZAlertWindow.h" #import "YOUPAIZhaPianTextAttachment.h" #import "YOUPAIZhaPianTextAttachment2.h" #import "TYCyclePagerView.h" #import "TYPageControl.h" #import "YOUPAILZHomeBannerCell.h" #import "YOUPAILCBannerModel.h" #import "YOUPAIFateTextAttachment.h" @interface YOUPAILCMessageVC () @property (nonatomic,strong) UILabel *youpaiptitleLabel; @property (nonatomic,assign) BOOL youpaipsupportsForceTouch; @property (nonatomic,strong) NSMutableDictionary *youpaippreviews; @property (nonatomic,strong) NSArray *youpaiptop_listArray;//置顶列表 @property (nonatomic, weak) TYCyclePagerView *youpaipbannerView; @property (strong, nonatomic) TYPageControl *youpaippageControl; @property (strong, nonatomic) NSMutableArray *youpaipimageURLStringsGroup; @property (nonatomic, strong) NSArray *youpaipbannerArray; @property (nonatomic, weak)UIView *headerV; @property (nonatomic, strong) UIView *tableHeader; @end @implementation YOUPAILCMessageVC - (UIStatusBarStyle)preferredStatusBarStyle{ return UIStatusBarStyleLightContent; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [UMengRecordTool umengEnterViewWithName:NSStringFromClass(self.class)]; if (![LCSaveData getHiddenGuideState] && ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 1 && [LCSaveModel getUserModel].youpaipuserinfo.youpaipis_anchor != 1) && ![LCSaveData getWhiteVersion]) { self.headerV.mj_h = 18.0f + ScaleSize(82.0f) + 74.0f; }else{ self.headerV.mj_h = 18.0f + ScaleSize(82.0f); } // 隐藏行为公告,用户指南等 banner self.headerV.mj_h = 0.1; //消息列表适配暗黑模式 v1.5.6 [self.tableView setBackgroundColor:[UIColor whiteColor]]; UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(youpaiflongTapAction:)]; longPress.minimumPressDuration = 0.5; //定义按的时间 longPress.numberOfTouchesRequired = 1; [self.tableView addGestureRecognizer:longPress]; [self youpaifrefreshList]; } - (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; [self.navigationController.navigationBar setDefaultBar]; [UMengRecordTool umengOutViewWithName:NSStringFromClass(self.class)]; } - (void)youpaifinitConfig{ //系统配置信息 [LCHttpHelper requestWithURLString:AppConfig parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 self->_youpaiptop_listArray = [[[dict objectForKey:@"data"]objectForKey:@"config"] objectForKey:@"top_list"]; for (NSString *sessionId in self->_youpaiptop_listArray) { NIMSession *session = [NIMSession session:sessionId type:NIMSessionTypeP2P]; [NTESSessionUtil addRecentSessionMark:session type:NTESRecentSessionMarkTypeTop]; } } } failure:^(NSError *error) { }]; } - (void)viewDidLoad { [super viewDidLoad]; [self.view setBackgroundColor:[UIColor clearColor]]; //modify by leo 20191030 /* self.navigationItem.title = @"消息"; self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifsystemClick) image:[UIImage imageNamed:@"vqu_images_IM_im_remind"]]; */ self.youpaipsupportsForceTouch = [self.traitCollection respondsToSelector:@selector(forceTouchCapability)] && self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable; UIButton* sayHiBtn = [[UIButton alloc]initWithFrame:CGRectMake(0,0,24,44)]; [sayHiBtn setImage:[UIImage imageNamed:@"vqu_images_nav_more_black"] forState:(UIControlStateNormal)]; [sayHiBtn addTarget:self action:@selector(youpaifsayHiBtnClick) forControlEvents:(UIControlEventTouchUpInside)]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:sayHiBtn]; [self youpaifinitConfig]; [self youpaifinitUI]; [self youpaifrequestBannerData]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifintimateChangeNotification:) name:@"VQUIMIntimateChangeNotification" object:nil]; self.tableView.tableHeaderView = self.tableHeader; } - (void)youpaifintimateChangeNotification:(NSNotification *)notify{ NSDictionary *dataDic = notify.userInfo; for (NSInteger i = 0 ; i < self.recentSessions.count; i ++) { NIMRecentSession *session = self.recentSessions[i]; if ([session.session.sessionId isEqual:dataDic[@"uid"]]) { [UIView performWithoutAnimation:^{ [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:i] withRowAnimation:UITableViewRowAnimationNone]; }]; break; } } } - (void)youpaifinitUI{ if (self.isIntimateList) { [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.mas_equalTo(0); make.bottom.mas_equalTo(0); }]; return; } UIView *headerV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 18.0f + ScaleSize(82.0f))]; headerV.frame = CGRectMake(0, 0, kScreenWidth, 0.1); headerV.hidden = YES; [self.view addSubview:headerV]; self.headerV = headerV; [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(0); make.right.mas_equalTo(0); make.top.equalTo(headerV.mas_bottom).offset(0); make.bottom.mas_equalTo(0); }]; TYCyclePagerView *bannerView = [[TYCyclePagerView alloc]initWithFrame:CGRectMake(0, 9.0f, KScreenWidth,ScaleSize(82.0f))]; [headerV addSubview:bannerView]; bannerView.isInfiniteLoop = YES; bannerView.autoScrollInterval = 6.0; bannerView.layer.cornerRadius = ScaleSize(10.0f); bannerView.clipsToBounds = YES; bannerView.dataSource = self; bannerView.delegate = self; [bannerView registerClass:[YOUPAILZHomeBannerCell class] forCellWithReuseIdentifier:@"cellId"]; self.youpaipbannerView = bannerView; bannerView.backgroundColor = [UIColor whiteColor]; TYPageControl *pageControl = [[TYPageControl alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(_youpaipbannerView.frame) - 26, CGRectGetWidth(_youpaipbannerView.frame), 26)]; //pageControl.numberOfPages = _datas.count; pageControl.currentPageIndicatorSize = CGSizeMake(6, 6); pageControl.pageIndicatorSize = CGSizeMake(6, 6); // pageControl.currentPageIndicatorTintColor = [UIColor redColor]; // pageControl.pageIndicatorTintColor = [UIColor grayColor]; pageControl.pageIndicatorImage = [UIImage imageNamed:@"vqu_images_H_home_page_n"]; pageControl.currentPageIndicatorImage = [UIImage imageNamed:@"vqu_images_H_home_page_s"]; pageControl.contentInset = UIEdgeInsetsMake(0, 0, 0, 0); pageControl.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; pageControl.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; pageControl.pageIndicatorSpaing = 1; [bannerView addSubview:pageControl]; self.youpaippageControl = pageControl; } - (UIView *)tableHeader { if (!_tableHeader) { _tableHeader = [[UIView alloc] init]; _tableHeader.frame = CGRectMake(0, 0, kScreenWidth, 130); _tableHeader.backgroundColor = [UIColor whiteColor]; CGFloat anNiuKuanDu = kScreenWidth / 3.0; CGFloat anNiuGaoDu = 80; CGFloat biaoQianGaoDu = 20; CGFloat shangBianJu = 15; // 第一个按钮 - 在线客服 UIButton *zaiXianKeHuAnNiu = [[UIButton alloc] init]; zaiXianKeHuAnNiu.frame = CGRectMake(0, shangBianJu, anNiuKuanDu, anNiuGaoDu); [zaiXianKeHuAnNiu setImage:ImageByName(@"vqu_images_zaixiankefu") forState:UIControlStateNormal]; zaiXianKeHuAnNiu.tag = 100; [zaiXianKeHuAnNiu addTarget:self action:@selector(tableHeaderButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; [_tableHeader addSubview:zaiXianKeHuAnNiu]; UILabel *zaiXianKeHuBiaoQian = [[UILabel alloc] init]; zaiXianKeHuBiaoQian.frame = CGRectMake(0, shangBianJu + anNiuGaoDu, anNiuKuanDu, biaoQianGaoDu); zaiXianKeHuBiaoQian.text = @"在线客服"; zaiXianKeHuBiaoQian.textAlignment = NSTextAlignmentCenter; zaiXianKeHuBiaoQian.font = LCFont12; zaiXianKeHuBiaoQian.textColor = LZ273145Color; [_tableHeader addSubview:zaiXianKeHuBiaoQian]; // 第二个按钮 - 系统消息 UIButton *xiTongXiaoXiAnNiu = [[UIButton alloc] init]; xiTongXiaoXiAnNiu.frame = CGRectMake(anNiuKuanDu, shangBianJu, anNiuKuanDu, anNiuGaoDu); [xiTongXiaoXiAnNiu setImage:ImageByName(@"vqu_images_xitongxiaoxi") forState:UIControlStateNormal]; xiTongXiaoXiAnNiu.tag = 101; [xiTongXiaoXiAnNiu addTarget:self action:@selector(tableHeaderButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; [_tableHeader addSubview:xiTongXiaoXiAnNiu]; UILabel *xiTongXiaoXiBiaoQian = [[UILabel alloc] init]; xiTongXiaoXiBiaoQian.frame = CGRectMake(anNiuKuanDu, shangBianJu + anNiuGaoDu, anNiuKuanDu, biaoQianGaoDu); xiTongXiaoXiBiaoQian.text = @"系统消息"; xiTongXiaoXiBiaoQian.textAlignment = NSTextAlignmentCenter; xiTongXiaoXiBiaoQian.font = LCFont12; xiTongXiaoXiBiaoQian.textColor = LZ273145Color; [_tableHeader addSubview:xiTongXiaoXiBiaoQian]; // 第三个按钮 - 合作洽谈 UIButton *heZuoQiaTanAnNiu = [[UIButton alloc] init]; heZuoQiaTanAnNiu.frame = CGRectMake(anNiuKuanDu * 2, shangBianJu, anNiuKuanDu, anNiuGaoDu); [heZuoQiaTanAnNiu setImage:ImageByName(@"vqu_images_hezuoqiatan") forState:UIControlStateNormal]; heZuoQiaTanAnNiu.tag = 102; [heZuoQiaTanAnNiu addTarget:self action:@selector(tableHeaderButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; [_tableHeader addSubview:heZuoQiaTanAnNiu]; UILabel *heZuoQiaTanBiaoQian = [[UILabel alloc] init]; heZuoQiaTanBiaoQian.frame = CGRectMake(anNiuKuanDu * 2, shangBianJu + anNiuGaoDu, anNiuKuanDu, biaoQianGaoDu); heZuoQiaTanBiaoQian.text = @"合作洽谈"; heZuoQiaTanBiaoQian.textAlignment = NSTextAlignmentCenter; heZuoQiaTanBiaoQian.font = LCFont12; heZuoQiaTanBiaoQian.textColor = LZ273145Color; [_tableHeader addSubview:heZuoQiaTanBiaoQian]; // // 添加底部分割线 // UIView *fenGexian = [[UIView alloc] init]; // fenGexian.frame = CGRectMake(0, 99, kScreenWidth, 1); // fenGexian.backgroundColor = LZF5F4F7Color; // [_tableHeader addSubview:fenGexian]; } return _tableHeader; } // 按钮点击事件处理 - (void)tableHeaderButtonClicked:(UIButton *)sender { NSInteger index = sender.tag - 100; switch (index) { case 0: // 在线客服 [self handleOnlineCustomerService]; break; case 1: // 系统消息 [self youpaifsystemClick]; break; case 2: // 合作洽谈 [self handleCooperationConsultation]; break; default: break; } } // 在线客服点击事件 - (void)handleOnlineCustomerService { NIMSession *session = [NIMSession session:[LCSaveData getServerId] type:NIMSessionTypeP2P]; if (session) { //@weakify(self); [ZCHUDHelper show]; [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray * _Nullable users, NSError * _Nullable error) { [ZCHUDHelper dismiss]; YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session]; [[LCTools getContainNavigationControllerCurrentVC].navigationController pushViewController:vc animated:YES]; }]; } } // 合作洽谈点击事件 - (void)handleCooperationConsultation { NIMSession *session = [NIMSession session:[LCSaveData getCooperationId] type:NIMSessionTypeP2P]; if (session) { //@weakify(self); [ZCHUDHelper show]; [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray * _Nullable users, NSError * _Nullable error) { [ZCHUDHelper dismiss]; YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session]; [[LCTools getContainNavigationControllerCurrentVC].navigationController pushViewController:vc animated:YES]; }]; } } #pragma mark - TYCyclePagerViewDataSource - (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView { return self.youpaipimageURLStringsGroup.count; } - (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index { YOUPAILZHomeBannerCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndex:index]; NSString *url; // absoluteString if (self.youpaipimageURLStringsGroup) { url = [self.youpaipimageURLStringsGroup[index] absoluteString]; [cell.youpaipbgImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"banner_default"]]; } cell.layer.cornerRadius = ScaleSize(10); cell.layer.masksToBounds = YES; cell.backgroundColor = [UIColor redColor]; // cell.backgroundColor = _datas[index]; // cell.label.text = [NSString stringWithFormat:@"index->%ld",index]; return cell; } - (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView { TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init]; layout.itemSize = CGSizeMake(CGRectGetWidth(pageView.frame)*0.93, CGRectGetHeight(pageView.frame)*0.93); layout.itemSpacing = 20; // ScaleSize(10.0f) layout.layoutType = TYCyclePagerTransformLayoutNormal; //layout.minimumAlpha = 0.3; return layout; } - (void)pagerView:(TYCyclePagerView *)pageView didSelectedItemCell:(__kindof UICollectionViewCell *)cell atIndex:(NSInteger)index{ YOUPAILCBannerModel* model = self.youpaipbannerArray[index]; if (model.youpaiplink_type==1) { ZCBaseWebVC* baseWeb = [[ZCBaseWebVC alloc]init]; baseWeb.contentUrl = model.youpaiplink_url; [self.navigationController pushViewController:baseWeb animated:YES]; }else if (model.youpaiplink_type==2||model.youpaiplink_type==3){ [self youpaifpageToStr:model.youpaiplink_url]; } } - (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex { self.youpaippageControl.currentPage = toIndex; } /// 获取banner数据 - (void)youpaifrequestBannerData{ @weakify(self); [LCHttpHelper requestWithURLString:HomeBanner parameters:@{@"cate_id":@"5"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { @strongify(self); NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 self.youpaipbannerArray = [YOUPAILCBannerModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"]objectForKey:@"banner"]]; [self youpaifreloadBannerData]; } } failure:^(NSError *error) { }]; } -(void)youpaifreloadBannerData{ NSMutableArray *imgUrlArray = [NSMutableArray array]; for (YOUPAILCBannerModel* model in self.youpaipbannerArray) { [imgUrlArray addObject:[LCTools getImageUrlWithAddress:model.youpaipimage]]; } self.youpaippageControl.numberOfPages = imgUrlArray.count; self.youpaipimageURLStringsGroup = imgUrlArray; [self.youpaipbannerView reloadData]; } #pragma mark-一键已读 -(void)youpaifsayHiBtnClick{ LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) { }]; cancelAction.cornerRadius = 24.0f; cancelAction.bgColor = LZF5F4F7Color; cancelAction.color = LZ273145Color; LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"确定" handler:^(LZAlertAction *action) { //一键已读 [[NIMSDK sharedSDK].conversationManager markAllMessagesRead]; }]; confimAction.cornerRadius = 24.0f; confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]]; confimAction.color = [UIColor whiteColor]; LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"一键已读" content:@"消息红点气泡会消失,但消息不丢失,也不会显示“已读”。" action:@[cancelAction,confimAction]]; [self TFPresentVC:alert completion:^{}]; } - (void)youpaifsystemClick{ NIMSession *session = [NIMSession session:[LCSaveData getSysId] type:NIMSessionTypeP2P]; if (session) { @weakify(self); [ZCHUDHelper show]; [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[session.sessionId] completion:^(NSArray * _Nullable users, NSError * _Nullable error) { @strongify(self); [ZCHUDHelper dismiss]; YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:session]; [self.navigationController pushViewController:vc animated:YES]; }]; } } - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { _youpaippreviews = [[NSMutableDictionary alloc] init]; self.autoRemoveRemoteSession = [[NTESBundleSetting sharedConfig] autoRemoveRemoteSession]; } return self; } - (void)youpaifrefreshList{ if (self.recentSessions.count == 0) {//有时候会拿不到数据 self.recentSessions = [[NIMSDK sharedSDK].conversationManager.allRecentSessions mutableCopy];//获取所有最近会话。 } self.recentSessions = [self customSortRecents:self.recentSessions]; [self.tableView reloadData]; if (![self isNotDataSource]) { [self.tableView lz_hideEmptyView]; }else{ [self showEmptyView]; } } - (void)showEmptyView{ if (self.isIntimateList) { @weakify(self); [self.tableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_im_intimate_list_not_data"] title:@"亲密度≥37的亲密关系会在这里显示哦~" content:@"立即聊天,遇见亲密的Ta" btnTitle:@"去聊天" styleBlock:^(LYEmptyView * _Nonnull emptyView) { emptyView.imageSize = CGSizeMake(222, 95); emptyView.titleLabTextColor = LZ475A7DColor; emptyView.titleLabFont = LCFont14; emptyView.titleLabMargin = 24.0f; emptyView.detailLabTextColor = LZA3AABEColor; emptyView.detailLabFont = LCFont12; emptyView.detailLabMargin = 12.0f; emptyView.actionBtnFont = LCFont16; emptyView.actionBtnTitleColor = [UIColor whiteColor]; emptyView.actionBtnHeight = 40.0f; emptyView.actionBtnWidth = 98.0f; emptyView.actionBtnCornerRadius = 20.0f; emptyView.actionBtnBackGroundColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake(98.0f, 40.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]]; emptyView.actionBtnMargin = 24.0f; } block:^{ @strongify(self); if (self.goMessageListPageBlock != nil) { self.goMessageListPageBlock(); } }]; }else{ [self.tableView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_call_video_data"] content:@"暂无消息记录"]; for (UIView *view in self.tableView.subviews) { if ([view isKindOfClass:[LZEmptyView class]]) { view.userInteractionEnabled = NO; } } } } //对最近会话重新排序 - (NSMutableArray *)customSortRecents:(NSMutableArray *)recentSessions { NSMutableArray *array = [[NSMutableArray alloc] initWithArray:recentSessions]; [array sortUsingComparator:^NSComparisonResult(NIMRecentSession *obj1, NIMRecentSession *obj2) { NSInteger score1 = [NTESSessionUtil recentSessionIsMark:obj1 type:NTESRecentSessionMarkTypeTop]? 10 : 0; NSInteger score2 = [NTESSessionUtil recentSessionIsMark:obj2 type:NTESRecentSessionMarkTypeTop]? 10 : 0; if (obj1.lastMessage.timestamp > obj2.lastMessage.timestamp) { score1 += 1; } else if (obj1.lastMessage.timestamp < obj2.lastMessage.timestamp) { score2 += 1; } if (score1 == score2) { return NSOrderedSame; } return score1 > score2? NSOrderedAscending : NSOrderedDescending; }]; return array; } #pragma mark - UITableViewDelegate //- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // return YES; //} //- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath //{ // return UITableViewCellEditingStyleDelete; //} //- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { // NIMRecentSession *recentSession = self.recentSessions[indexPath.row]; // if (editingStyle == UITableViewCellEditingStyleDelete) { //// id manager = [[NIMSDK sharedSDK] conversationManager]; //删除最近会话 //// [manager deleteRecentSession:recentSession]; // //删除最近会话并且删除消息 // id manager = [[NIMSDK sharedSDK] conversationManager]; // NIMDeleteMessagesOption* deleteOption = [[NIMDeleteMessagesOption alloc]init]; // deleteOption.removeSession = YES; // deleteOption.removeTable = YES; // [manager deleteAllmessagesInSession:recentSession.session option:deleteOption]; // } //} - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if (self.youpaipsupportsForceTouch) { id preview = [self registerForPreviewingWithDelegate:self sourceView:cell]; [self.youpaippreviews setObject:preview forKey:@(indexPath.row)]; } } - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if (self.youpaipsupportsForceTouch) { id preview = [self.youpaippreviews objectForKey:@(indexPath.row)]; [self unregisterForPreviewingWithContext:preview]; [self.youpaippreviews removeObjectForKey:@(indexPath.row)]; } } - (void)onSelectedRecent:(NIMRecentSession *)recentSession atIndexPath:(NSIndexPath *)indexPath{ @weakify(self); [ZCHUDHelper show]; [[[NIMSDK sharedSDK] userManager] fetchUserInfos:@[recentSession.session.sessionId] completion:^(NSArray * _Nullable users, NSError * _Nullable error) { @strongify(self); [ZCHUDHelper dismiss]; YOUPAILCIMSessionVC *vc = [[YOUPAILCIMSessionVC alloc] initWithSession:recentSession.session]; vc.type = @"3"; [self.navigationController pushViewController:vc animated:YES]; }]; } - (NSString *)messageContent:(NIMMessage*)lastMessage{ if (lastMessage.messageType == NIMMessageTypeCustom) { NIMCustomObject *object = (NIMCustomObject*)lastMessage.messageObject; NSString *text = @""; if ([object.attachment isKindOfClass:[YOUPAILCMessageTxtAttachment class]]) { YOUPAILCMessageTxtAttachment* attachment = (YOUPAILCMessageTxtAttachment*)object.attachment; text = attachment.title; } if ([object.attachment isKindOfClass:[YOUPAIZhaPianTextAttachment class]]) { } if ([object.attachment isKindOfClass:[YOUPAIZhaPianTextAttachment2 class]]) { } if ([object.attachment isKindOfClass:[YOUPAILCMessageTxtAttachment class]]) { YOUPAILCMessageTxtAttachment* attachment = (YOUPAILCMessageTxtAttachment*)object.attachment; text = attachment.title; } if ([object.attachment isKindOfClass:[YOUPAILCOneImageAttachment class]]) { YOUPAILCOneImageAttachment* attachment = (YOUPAILCOneImageAttachment*)object.attachment; if (attachment.act_type==1) { text = attachment.act_string; }else{ text = attachment.title; } } if ([object.attachment isKindOfClass:[YOUPAILCMultiImageAttachment class]]) { YOUPAILCMultiImageAttachment* attachment = (YOUPAILCMultiImageAttachment*)object.attachment; if (attachment.imageArray.count != 0) { NSDictionary* topDict = attachment.imageArray[0]; text = [topDict objectForKey:@"title"]; } } if ([object.attachment isKindOfClass:[YOUPAILCGiftAttachment class]]) { YOUPAILCGiftAttachment* attachment = (YOUPAILCGiftAttachment*)object.attachment; if ([[NSString stringWithFormat:@"%zd",attachment.from_uid] isEqualToString:[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id]) { text = @"[赠送礼物]"; }else{ text = @"[收到礼物]"; } } if ([object.attachment isKindOfClass:[YOUPAILPFollowAttachment class]]){ //modify by leo v1.0.7 上线通知 YOUPAILPFollowAttachment* attachment = (YOUPAILPFollowAttachment *)object.attachment; if(attachment.type == 16) { text = @"新增粉丝"; } //modify by leo v1.0.8 动态更新 else if(attachment.type == 17) { NSString *nickeName = attachment.nickname; text = [NSString stringWithFormat:@"%@更新了动态",nickeName]; } else { NSString *nickeName = attachment.nickname; text = [NSString stringWithFormat:@"%@上线啦!",nickeName]; } } if ([object.attachment isKindOfClass:[YOUPAIFateTextAttachment class]]) { text = @"[缘分牵线]"; } if ([object.attachment isKindOfClass:[YOUPAILCCallAttachment class]]) { YOUPAILCCallAttachment* attachment = (YOUPAILCCallAttachment*)object.attachment; if (attachment.calltype==1) { text = @"[视频通话]"; } NSString* txtStr = @""; if (attachment.status==3) { txtStr =@"[超时未接听]"; }else if (attachment.status==4){ txtStr = [NSString stringWithFormat:@"[通话时长:%@]",[ZCUtils getMinTimeStrFromSS:attachment.call_time]]; } NSLog(@"代表是自己发的%@-----%ld", [LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id , (long)attachment.from_uid); if ([[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id integerValue] == attachment.from_uid) {//代表是自己发的 // NSLog(@"代表是自己发的%@-----%@", [LCSaveModel getUserModel].userinfo.user_id , attachment.from_uid); if (attachment.status==1) { txtStr = @"[已取消]"; }else if (attachment.status==2){ txtStr = @"[对方已拒绝]"; } }else{ if (attachment.status==1) { txtStr = @"[对方已取消]"; }else if (attachment.status==2){ txtStr = @"[已拒绝]"; } } text = [NSString stringWithFormat:@"%@%@",text,txtStr]; } return text; }else{ if (lastMessage.messageType == NIMMessageTypeTip) { return @"[提醒消息]"; }else{ return [super messageContent:lastMessage]; } } } -(void)youpaiflongTapAction:(UILongPressGestureRecognizer *)longPress { if (longPress.state == UIGestureRecognizerStateBegan) { AudioServicesPlaySystemSound(1519); }else if (longPress.state == UIGestureRecognizerStateEnded){ CGPoint p = [longPress locationInView:self.tableView] ;// get longpress pt NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p] ; // get indexpath from table with point . NIMRecentSession *recentSession = self.recentSessions[indexPath.section]; if ([_youpaiptop_listArray containsObject:recentSession.session.sessionId]) {//置顶列表 return; } @weakify(self); ZCAlertAction* deleteAction = [ZCAlertAction actionWithTitle:@"删除" andblock:^{ @strongify(self); [self messagePopupWindowAction:@"deleteChat" andSession:recentSession.session]; }]; ZCAlertSheetView* alertSheet = [[ZCAlertSheetView alloc]initWithTitle:nil andShowCancelButton:YES andAction:@[deleteAction]]; alertSheet.alertWindow.hidden = NO; [alertSheet show]; NSLog(@"sessionI2 == %@",recentSession.session.sessionId); } } -(void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; NSLog(@"lcmessage dealloc"); } #pragma mark ZYMessagePopupWindowDelegate -(void)messagePopupWindowAction:(NSString *)type andSession:(NIMSession *)session { if ([type isEqualToString:@"updateRemark"]) {//设置备注名 YOUPAIZYUpdateRemarkWindow *VC= [[YOUPAIZYUpdateRemarkWindow alloc]init]; VC.vWidth = KScreenWidth -68; VC.vHeight = ScaleHeight(187)+10; VC.youpaipsession = session; VC.isTouchDismiss = NO; [kAppDelegate.window.rootViewController TFPresentVC:VC completion:^{ }]; } if ([type isEqualToString:@"deleteChat"]) {//删除聊天 WeakSelf; LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) { }]; cancelAction.cornerRadius = 24.0f; cancelAction.color = LZ273145Color; cancelAction.bgColor = LZF5F4F7Color; LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"删除" handler:^(LZAlertAction *action) { [weakSelf deleteChatWithSession:session]; }]; confimAction.cornerRadius = 24.0f; confimAction.color = [UIColor whiteColor]; confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]]; LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"确定删除该聊天?" action:@[cancelAction,confimAction]]; alert.contentTextAlignment = NSTextAlignmentCenter; [self TFPresentVC:alert completion:^{}]; } if ([type isEqualToString:@"top"]) {//置顶该聊天 } if ([type isEqualToString:@"blacklist"]) {//加入黑名单 } if ([type isEqualToString:@"report"]) {//举报 YOUPAILCReportVC* report = [[YOUPAILCReportVC alloc]init]; report.youpaipreport_uid = session.sessionId; report.youpaiptype = 4; [self.navigationController pushViewController:report animated:YES]; } } #pragma mark ZYDeleteChatWindowDelegate -(void)deleteChatWithSession:(NIMSession *)session { id manager = [[NIMSDK sharedSDK] conversationManager]; NIMDeleteMessagesOption* deleteOption = [[NIMDeleteMessagesOption alloc]init]; deleteOption.removeSession = YES; deleteOption.removeTable = YES; [manager deleteAllmessagesInSession:session option:deleteOption]; } #pragma mark - JXCategoryListContainerView - (UIView *)listView{ return self.view; } @end