123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745 |
- //
- // 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 ()<UIViewControllerPreviewingDelegate,UIGestureRecognizerDelegate,TYCyclePagerViewDelegate,TYCyclePagerViewDataSource>
- @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 <YOUPAILCBannerModel *> *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<NIMUser *> * _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<NIMUser *> * _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<NIMUser *> * _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<NIMConversationManager> manager = [[NIMSDK sharedSDK] conversationManager]; //删除最近会话
- //// [manager deleteRecentSession:recentSession];
- // //删除最近会话并且删除消息
- // id<NIMConversationManager> 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<UIViewControllerPreviewing> 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<UIViewControllerPreviewing> 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<NIMUser *> * _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<NIMConversationManager> 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
|