1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024 |
- //
- // YOUPAIBBUCIMP2PSessionVC.m
- // VQU
- // Created by Elaine on 2021/10/26.
- // Copyright © 2021 MS. All rights reserved.
- //
- #import "YOUPAIBBUCIMP2PSessionVC.h"
- #import "NIMSessionConfigurateProtocol.h"
- #import "NIMKit.h"
- #import "NIMMessageCellProtocol.h"
- #import "NIMMessageModel.h"
- #import "NIMKitUtil.h"
- #import "NIMCustomLeftBarView.h"
- #import "NIMBadgeView.h"
- #import "UITableView+NIMScrollToBottom.h"
- #import "NIMMessageMaker.h"
- #import "UIView+NIM.h"
- #import "NIMKitTitleView.h"
- #import "NIMKitKeyboardInfo.h"
- #import "YOUPAIBBNIMSessionConfigurator.h"
- #import "NIMKitInfoFetchOption.h"
- #import "YOUPAIUCIMP2PSessionConfig.h"
- #import "NTESTimerHolder.h"
- #import "NSDictionary+NTESJson.h"
- #import "NTESCustomSysNotificationSender.h"
- #import "UIViewController+TFPresent.h"
- #import "YOUPAIZYIMSessionDetailWindow.h"
- #import "YOUPAIZYUpdateRemarkWindow.h"
- #import "YOUPAILCReportVC.h"
- #import "YOUPAILZUserShowVC.h"
- #import "LZAlertWindow.h"
- @interface YOUPAIBBUCIMP2PSessionVC ()<NIMMediaManagerDelegate,UCBaseTouchTableViewDelegate,NIMSystemNotificationManagerDelegate,NTESTimerHolderDelegate,ZYIMSessionDetailWindowDelegate>
- @property (nonatomic,readwrite) NIMMessage *messageForMenu;
- @property (nonatomic,strong) UILabel *youpaiptitleLabel;
- @property (nonatomic,strong) UILabel *youpaipsubTitleLabel;
- @property (nonatomic,strong) NSIndexPath *youpaiplastVisibleIndexPathBeforeRotation;
- @property (nonatomic,strong) YOUPAIUCIMP2PSessionConfig* youpaipsessionConfig;
- @property (nonatomic,strong) NIMCustomLeftBarView* youpaipbadgeBarView;
- @property (nonatomic,strong) NTESCustomSysNotificationSender *youpaipnotificaionSender;
- @property (nonatomic,strong) NTESTimerHolder *youpaiptitleTimer;
- @end
- @implementation YOUPAIBBUCIMP2PSessionVC
- #pragma mark - 子类实现
- - (void)youpaifprofileClick{
- NSLog(@"头像点击啦");
- }
- - (instancetype)initWithSession:(NIMSession *)session{
- self = [super initWithNibName:nil bundle:nil];
- if (self) {
- _session = session;
- }
- return self;
- }
- - (void)dealloc
- {
- [self removeListener];
- [[NIMKit sharedKit].robotTemplateParser clean];
-
- _youpaiptableView.delegate = nil;
- _youpaiptableView.dataSource = nil;
- }
- - (void)viewDidAppear:(BOOL)animated{
- [super viewDidAppear:animated];
- //判断是否有本地消息记录 用来判断是否是第一次聊天
- [self youpaifcheckLocalMessage];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = LCBkgColor;
- _youpaipnotificaionSender = [[NTESCustomSysNotificationSender alloc] init];
- BOOL youpaipdisableCommandTyping = self.youpaipdisableCommandTyping || (self.session.sessionType == NIMSessionTypeP2P &&[[NIMSDK sharedSDK].userManager isUserInBlackList:self.session.sessionId]);
- if (!youpaipdisableCommandTyping) {
- _youpaiptitleTimer = [[NTESTimerHolder alloc] init];
- [[NIMSDK sharedSDK].systemNotificationManager addDelegate:self];
- }
- //导航栏
- [self youpaifsetupNav];
- //消息 tableView
- [self youpaifsetupTableView];
- //输入框 inputView
- [self youpaifsetupInputView];
- //会话相关逻辑配置器安装
- [self youpaifsetupConfigurator];
- //添加监听
- [self addListener];
- //进入会话时,标记所有消息已读,并发送已读回执
- [self markRead];
- //更新已读位置
- [self uiCheckReceipts:nil];
- }
- - (void)youpaifsetupNav
- {
- //子类实现
- [self setUpTitleView];
-
- //导航栏设置
- NIMCustomLeftBarView *leftBarView = [[NIMCustomLeftBarView alloc] initWithFrame:CGRectMake(0, 0, 70, 44)];
-
- leftBarView.badgeView.badgeTextColor = [UIColor whiteColor];
- leftBarView.backImgV.image = [UIImage imageNamed:@"vqu_images_IM_session_Back"];
- [leftBarView addTarget:self action:@selector(youpaifbackClick) forControlEvents:UIControlEventTouchUpInside];
- self.navigationController.navigationBar.barTintColor = LCNavColor;
- UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftBarView];
-
- // if (@available(iOS 11.0, *)) {
- // leftBarView.translatesAutoresizingMaskIntoConstraints = NO;
- // }
- self.youpaipbadgeBarView = leftBarView;
- self.navigationItem.leftBarButtonItem = leftItem;
- //设置不进入聊天详情的页面号
-
- if (@available(iOS 15.0, *)) {
- UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
- appearance.backgroundEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleRegular];
- [appearance setBackgroundColor:LCNavColor];
- appearance.backgroundEffect = nil;
- appearance.shadowColor = [UIColor clearColor];
- NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
- textAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
- appearance.titleTextAttributes = textAttrs;
- self.navigationController.navigationBar.standardAppearance = appearance;
- self.navigationController.navigationBar.scrollEdgeAppearance = appearance;
- }
-
- // if (![self.session.sessionId isEqualToString:[LCSaveData getSysId]] && (![self.session.sessionId isEqualToString:[LCSaveData getServerId]])) {
- // self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifuserSetClick) image:[UIImage imageNamed:@"vqu_images_IM_im_details"]];
- // }
-
- [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) {//成功
- NSArray *array = [[[dict objectForKey:@"data"]objectForKey:@"config"] objectForKey:@"no_info"];
- if (![array containsObject:self.session.sessionId]) {
- self.navigationItem.rightBarButtonItems = @[[UIBarButtonItem itemWithTarget:self action:@selector(youpaifuserSetClick) image:[UIImage imageNamed:@"vqu_images_IM_im_details"]]] ;
-
-
- }
- }
- } failure:^(NSError *error) {}];
-
-
-
-
-
-
-
-
-
- }
- - (void)youpaifbackClick{
- [self.navigationController popViewControllerAnimated:YES];
- }
- #pragma mark-更多
- - (void)youpaifuserSetClick{
-
- YOUPAIZYIMSessionDetailWindow *vc= [[YOUPAIZYIMSessionDetailWindow alloc]init];
- vc.vWidth = KScreenWidth -68;
- vc.vHeight = 315+25+30;
- vc.youpaipsession = self.session;
- vc.youpaipdelegate = self;
- vc.isTouchDismiss = YES;
- [self TFPresentVC:vc completion:^{}];
-
-
- }
- - (void)youpaifsetupTableView
- {
- self.view.backgroundColor = LCBkgColor;
- self.youpaiptableView = [[YOUPAIUCBaseTouchTableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, KScreenWidth, KScreenHeight-NavBarHeight) style:UITableViewStylePlain];
- self.youpaiptableView.touchDelegate = self;
- self.youpaiptableView.backgroundColor = LCBkgColor;
- self.youpaiptableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- self.youpaiptableView.estimatedRowHeight = 0;
- self.youpaiptableView.estimatedSectionHeaderHeight = 0;
- self.youpaiptableView.estimatedSectionFooterHeight = 0;
- self.youpaiptableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- if ([self.sessionConfig respondsToSelector:@selector(sessionBackgroundImage)] && [self.sessionConfig sessionBackgroundImage]) {
- UIImageView *imgView = [[UIImageView alloc] initWithFrame:self.view.bounds];
- imgView.image = [self.sessionConfig sessionBackgroundImage];
- imgView.contentMode = UIViewContentModeScaleAspectFill;
- self.youpaiptableView.backgroundView = imgView;
- }
- if (@available(iOS 15.0, *)) {
- self.youpaiptableView.sectionHeaderTopPadding = 0;
- }
- [self.view addSubview:self.youpaiptableView];
- }
- - (void)youpaifsetupInputView
- {
- if ([self shouldShowInputView])
- {
- self.youpaipsessionInputView = [[YOUPAIBBNIMInputView alloc] initWithFrame:CGRectMake(0, 0, self.view.nim_width,0) config:self.sessionConfig];
- self.youpaipsessionInputView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
- [self.youpaipsessionInputView setSession:self.session];
- [self.youpaipsessionInputView youpaifsetInputDelegate:self];
- [self.youpaipsessionInputView youpaifsetInputActionDelegate:self];
- [self.youpaipsessionInputView youpaifrefreshStatus:BBNIMInputStatusText];
- [self.view addSubview:_youpaipsessionInputView];
- // self.youpaipsessionInputView
- self.youpaiptableView.nim_height -= self.youpaipsessionInputView.youpaiptoolBar.nim_height;
- }
- }
- - (void)youpaifsetupConfigurator
- {
- _youpaipconfigurator = [[YOUPAIBBNIMSessionConfigurator alloc] init];
- [_youpaipconfigurator youpaifuc_setup:self];
-
- BOOL youpaipneedProximityMonitor = [self needProximityMonitor];
- [[NIMSDK sharedSDK].mediaManager setNeedProximityMonitor:youpaipneedProximityMonitor];
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- [self.youpaipinteractor onViewWillAppear];
- [self.navigationController.navigationBar setBackgroundColor:LCNavColor];
- if (@available(iOS 15.0, *)) {
- [self.navigationController.navigationBar.scrollEdgeAppearance setBackgroundColor:LCNavColor];
- [self.navigationController.navigationBar.standardAppearance setBackgroundColor:LCNavColor];
- }
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [self.youpaipsessionInputView endEditing:YES];
- // [self.navigationController.navigationBar setBackgroundColor:[UIColor clearColor]];
- // if (@available(iOS 15.0, *)) {
- // [self.navigationController.navigationBar.scrollEdgeAppearance setBackgroundColor:[UIColor clearColor]];
- // [self.navigationController.navigationBar.standardAppearance setBackgroundColor:[UIColor clearColor]];
- // }
- }
- - (void)viewDidDisappear:(BOOL)animated
- {
- [super viewDidDisappear:animated];
- [self.youpaipinteractor onViewDidDisappear];
- }
- - (void)viewDidLayoutSubviews
- {
- [self changeLeftBarBadge:self.conversationManager.allUnreadCount];
- [self.youpaipinteractor resetLayout];
- }
- #pragma mark - 第一次聊天的提示信息
- - (void)youpaifcheckLocalMessage{
- NIMMessageSearchOption* option = [[NIMMessageSearchOption alloc]init];
- option.allMessageTypes = YES;
- option.order = NIMMessageSearchOrderDesc;
- [[[NIMSDK sharedSDK] conversationManager] searchMessages:self.session option:option result:^(NSError * _Nullable error, NSArray<NIMMessage *> * _Nullable messages) {
- if (messages.count==0 && [LCSaveModel getUserModel].youpaipuserinfo.youpaipgender==2) {
- //不是系统和客服才请求
- if (![self.session.sessionId isEqualToString:[LCSaveData getSysId]] && ![self.session.sessionId isEqualToString:[LCSaveData getServerId]]) {//请求提示信息
-
- }
- }
-
- }];
- }
- #pragma mark - 对方输入状态
- - (void)onReceiveCustomSystemNotification:(NIMCustomSystemNotification *)notification
- {
- if (!notification.sendToOnlineUsersOnly) {
- return;
- }
- NSData *data = [[notification content] dataUsingEncoding:NSUTF8StringEncoding];
- if (data) {
- NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data
- options:0
- error:nil];
- if ([dict jsonInteger:NTESNotifyID] == NTESCommandTyping && self.session.sessionType == NIMSessionTypeP2P && [notification.sender isEqualToString:self.session.sessionId])
- {
- [self refreshSessionTitle:@"对方正在输入..."];
- [_youpaiptitleTimer startTimer:5
- delegate:self
- repeats:NO];
- }
- }
- }
- - (void)onNTESTimerFired:(NTESTimerHolder *)holder
- {
- [self refreshSessionTitle:self.youpaifsessionTitle];
-
- }
- #pragma mark - 消息收发接口
- - (void)sendMessage:(NIMMessage *)message
- {
- [self.youpaipinteractor sendMessage:message];
- }
- #pragma mark - Touch Event
- - (void)didTouchesBegan:(YOUPAIUCBaseTouchTableView *)tableView{
- [_youpaipsessionInputView endEditing:YES];
- }
- - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
- {
- [super touchesBegan:touches withEvent:event];
- [_youpaipsessionInputView endEditing:YES];
- }
- #pragma mark - NIMSessionConfiguratorDelegate
- - (void)didFetchMessageData
- {
- [self uiCheckReceipts:nil];
- [self.youpaiptableView reloadData];
- [self.youpaiptableView nim_scrollToBottom:NO];
- }
- - (void)didRefreshMessageData
- {
- [self refreshSessionTitle:self.youpaifsessionTitle];
- [self refreshSessionSubTitle:self.sessionSubTitle];
- [self.youpaiptableView reloadData];
- }
- - (void)didPullUpMessageData {}
- #pragma mark - 会话title
- - (NSString *)youpaifsessionTitle
- {
- NSString *title = @"";
- NIMSessionType type = self.session.sessionType;
- switch (type) {
- case NIMSessionTypeTeam:{
- NIMTeam *team = [[[NIMSDK sharedSDK] teamManager] teamById:self.session.sessionId];
- title = [NSString stringWithFormat:@"%@(%zd)",[team teamName],[team memberNumber]];
- }
- break;
- case NIMSessionTypeP2P:{
- title = [NIMKitUtil showNick:self.session.sessionId inSession:self.session];
- }
- break;
- default:
- break;
- }
- return title;
- }
- - (NSString *)sessionSubTitle{return @"";};
- #pragma mark - NIMChatManagerDelegate
- //开始发送
- - (void)willSendMessage:(NIMMessage *)message
- {
- id<NIMSessionInteractor> youpaipinteractor = self.youpaipinteractor;
-
- if ([message.session isEqual:self.session]) {
- if ([youpaipinteractor findMessageModel:message]) {
- [youpaipinteractor updateMessage:message];
- }else{
- [youpaipinteractor addMessages:@[message]];
- }
- }
- }
- //上传资源文件成功
- - (void)uploadAttachmentSuccess:(NSString *)urlString
- forMessage:(NIMMessage *)message
- {
- //如果需要使用富文本推送,可以在这里进行 message apns payload 的设置
- }
- //发送结果
- - (void)sendMessage:(NIMMessage *)message didCompleteWithError:(NSError *)error
- {
- if ([message.session isEqual:_session])
- {
- [self.youpaipinteractor updateMessage:message];
- if (message.session.sessionType == NIMSessionTypeTeam)
- {
- //如果是群的话需要检查一下回执显示情况
- NIMMessageReceipt *receipt = [[NIMMessageReceipt alloc] initWithMessage:message];
- [self.youpaipinteractor checkReceipts:@[receipt]];
- }
- }
- }
- //发送进度
- -(void)sendMessage:(NIMMessage *)message progress:(float)progress
- {
- if ([message.session isEqual:_session]) {
- [self.youpaipinteractor updateMessage:message];
- }
- }
- //接收消息
- - (void)onRecvMessages:(NSArray *)messages
- {
-
- if ([self shouldAddListenerForNewMsg])
- {
- NIMMessage *message = messages.firstObject;
- NIMSession *session = message.session;
- if (![session isEqual:self.session] || !messages.count)
- {
- return;
- }
- [self uiAddMessages:messages];
- [self.youpaipinteractor markRead];
- }
- }
- - (void)fetchMessageAttachment:(NIMMessage *)message progress:(float)progress
- {
- if ([message.session isEqual:_session])
- {
- [self.youpaipinteractor updateMessage:message];
- }
- }
- - (void)fetchMessageAttachment:(NIMMessage *)message didCompleteWithError:(NSError *)error
- {
- if ([message.session isEqual:_session])
- {
- NIMMessageModel *model = [self.youpaipinteractor findMessageModel:message];
- //下完缩略图之后,因为比例有变化,重新刷下宽高。
- [model cleanCache];
- [self.youpaipinteractor updateMessage:message];
- }
- }
- - (void)onRecvMessageReceipts:(NSArray<NIMMessageReceipt *> *)receipts
- {
- if ([self shouldAddListenerForNewMsg])
- {
- NSMutableArray *handledReceipts = [[NSMutableArray alloc] init];
- for (NIMMessageReceipt *receipt in receipts) {
- if ([receipt.session isEqual:self.session])
- {
- [handledReceipts addObject:receipt];
- }
- }
- if (handledReceipts.count)
- {
- [self uiCheckReceipts:handledReceipts];
- }
- }
- }
- #pragma mark - NIMConversationManagerDelegate
- - (void)messagesDeletedInSession:(NIMSession *)session{
- [self.youpaipinteractor resetMessages:nil];
- [self.youpaiptableView reloadData];
- }
- - (void)didAddRecentSession:(NIMRecentSession *)recentSession
- totalUnreadCount:(NSInteger)totalUnreadCount{
- [self changeUnreadCount:recentSession totalUnreadCount:totalUnreadCount];
- }
- - (void)didUpdateRecentSession:(NIMRecentSession *)recentSession
- totalUnreadCount:(NSInteger)totalUnreadCount{
- [self changeUnreadCount:recentSession totalUnreadCount:totalUnreadCount];
- }
- - (void)didRemoveRecentSession:(NIMRecentSession *)recentSession
- totalUnreadCount:(NSInteger)totalUnreadCount{
- [self changeUnreadCount:recentSession totalUnreadCount:totalUnreadCount];
- }
- - (void)changeUnreadCount:(NIMRecentSession *)recentSession
- totalUnreadCount:(NSInteger)totalUnreadCount{
- if ([recentSession.session isEqual:self.session]) {
- return;
- }
- [self changeLeftBarBadge:totalUnreadCount];
- }
- #pragma mark - NIMMediaManagerDelegate
- - (void)recordAudio:(NSString *)filePath didBeganWithError:(NSError *)error {
- if (!filePath || error) {
- _youpaipsessionInputView.youpaiprecording = NO;
- [self onRecordFailed:error];
- }
- }
- - (void)recordAudio:(NSString *)filePath didCompletedWithError:(NSError *)error {
- if(!error) {
- if ([self recordFileCanBeSend:filePath]) {
- [self sendMessage:[NIMMessageMaker msgWithAudio:filePath]];
- }else{
- [self showRecordFileNotSendReason];
- }
- } else {
- [self onRecordFailed:error];
- }
- _youpaipsessionInputView.youpaiprecording = NO;
- }
- - (void)recordAudioDidCancelled {
- _youpaipsessionInputView.youpaiprecording = NO;
- }
- - (void)recordAudioProgress:(NSTimeInterval)currentTime {
- [_youpaipsessionInputView youpaifupdateAudioRecordTime:currentTime];
- }
- - (void)recordAudioInterruptionBegin {
- [[NIMSDK sharedSDK].mediaManager cancelRecord];
- }
- #pragma mark - 录音相关接口
- - (void)onRecordFailed:(NSError *)error{}
- - (BOOL)recordFileCanBeSend:(NSString *)filepath
- {
- return YES;
- }
- - (void)showRecordFileNotSendReason{}
- #pragma mark - BBNIMInputDelegate
- - (void)didChangeInputHeight:(CGFloat)inputHeight
- {
- [self.youpaipinteractor changeLayout:inputHeight];
- }
- #pragma mark - NIMInputActionDelegate
- - (BOOL)onTapMediaItem:(NIMMediaItem *)item{
- SEL sel = item.selctor;
- BOOL youpaiphandled = sel && [self respondsToSelector:sel];
- if (youpaiphandled) {
- NIMKit_SuppressPerformSelectorLeakWarning([self performSelector:sel withObject:item]);
- youpaiphandled = YES;
- }
- return youpaiphandled;
- }
- - (void)onTextChanged:(id)sender{
- [_youpaipnotificaionSender sendTypingState:self.session];
- }
- - (void)onSendText:(NSString *)text atUsers:(NSArray *)atUsers
- {
- NSMutableArray *users = [NSMutableArray arrayWithArray:atUsers];
- if (self.session.sessionType == NIMSessionTypeP2P)
- {
- [users addObject:self.session.sessionId];
- }
- NSString *robotsToSend = [self robotsToSend:users];
-
- NIMMessage *message = nil;
- if (robotsToSend.length)
- {
- message = [NIMMessageMaker msgWithRobotQuery:text toRobot:robotsToSend];
- }
- else
- {
- message = [NIMMessageMaker msgWithText:text];
- }
-
- if (atUsers.count)
- {
- NIMMessageApnsMemberOption *apnsOption = [[NIMMessageApnsMemberOption alloc] init];
- apnsOption.userIds = atUsers;
- apnsOption.forcePush = YES;
-
- NIMKitInfoFetchOption *option = [[NIMKitInfoFetchOption alloc] init];
- option.session = self.session;
-
- NSString *me = [[NIMKit sharedKit].provider infoByUser:[NIMSDK sharedSDK].loginManager.currentAccount option:option].showName;
- apnsOption.apnsContent = [NSString stringWithFormat:@"%@在群里@了你",me];
- message.apnsMemberOption = apnsOption;
- }
- [self sendMessage:message];
- }
- - (NSString *)robotsToSend:(NSArray *)atUsers
- {
- for (NSString *userId in atUsers)
- {
- if ([[NIMSDK sharedSDK].robotManager isValidRobot:userId])
- {
- return userId;
- }
- }
- return nil;
- }
- - (void)onSelectChartlet:(NSString *)chartletId
- catalog:(NSString *)catalogId{}
- - (void)onCancelRecording
- {
- [[NIMSDK sharedSDK].mediaManager cancelRecord];
- }
- - (void)onStopRecording
- {
- [[NIMSDK sharedSDK].mediaManager stopRecord];
- }
- - (void)onStartRecording
- {
- _youpaipsessionInputView.youpaiprecording = YES;
-
- NIMAudioType type = [self recordAudioType];
- NSTimeInterval duration = [NIMKit sharedKit].config.recordMaxDuration;
-
- [[NIMSDK sharedSDK].mediaManager addDelegate:self];
-
- [[NIMSDK sharedSDK].mediaManager record:type
- duration:duration];
- }
- #pragma mark - NIMMessageCellDelegate
- - (BOOL)onTapCell:(NIMKitEvent *)event{
- BOOL youpaiphandle = NO;
- NSString *eventName = event.eventName;
- if ([eventName isEqualToString:NIMKitEventNameTapAudio])
- {
- [self.youpaipinteractor mediaAudioPressed:event.messageModel];
- youpaiphandle = YES;
- }
- if ([eventName isEqualToString:NIMKitEventNameTapRobotBlock]) {
- NSDictionary *param = event.data;
- NIMMessage *message = [NIMMessageMaker msgWithRobotSelect:param[@"text"] target:param[@"target"] params:param[@"param"] toRobot:param[@"robotId"]];
- [self sendMessage:message];
- youpaiphandle = YES;
- }
- if ([eventName isEqualToString:NIMKitEventNameTapRobotContinueSession]) {
- NIMRobotObject *robotObject = (NIMRobotObject *)event.messageModel.message.messageObject;
- NIMRobot *robot = [[NIMSDK sharedSDK].robotManager robotInfo:robotObject.robotId];
- NSString *text = [NSString stringWithFormat:@"%@%@%@",NIMInputAtStartChar,robot.nickname,NIMInputAtEndChar];
-
- NIMInputAtItem *item = [[NIMInputAtItem alloc] init];
- item.uid = robot.userId;
- item.name = robot.nickname;
- [self.youpaipsessionInputView.youpaipatCache addAtItem:item];
-
- [self.youpaipsessionInputView.youpaiptoolBar youpaifinsertText:text];
-
- youpaiphandle = YES;
- }
-
- return youpaiphandle;
- }
- - (void)onRetryMessage:(NIMMessage *)message
- {
- if (message.isReceivedMsg) {
- [[[NIMSDK sharedSDK] chatManager] fetchMessageAttachment:message
- error:nil];
- }else{
- [[[NIMSDK sharedSDK] chatManager] resendMessage:message
- error:nil];
- }
- }
- - (BOOL)onLongPressCell:(NIMMessage *)message
- inView:(UIView *)view
- {
- BOOL youpaiphandle = NO;
- NSArray *items = [self menusItems:message];
- if ([items count] && [self becomeFirstResponder]) {
- UIMenuController *controller = [UIMenuController sharedMenuController];
- controller.menuItems = items;
- _messageForMenu = message;
- [controller setTargetRect:view.bounds inView:view];
- [controller setMenuVisible:YES animated:YES];
- youpaiphandle = YES;
- }
- return youpaiphandle;
- }
- - (BOOL)disableAudioPlayedStatusIcon:(NIMMessage *)message
- {
- BOOL youpaipdisable = NO;
- if ([self.sessionConfig respondsToSelector:@selector(disableAudioPlayedStatusIcon)])
- {
- youpaipdisable = [self.sessionConfig disableAudioPlayedStatusIcon];
- }
- return youpaipdisable;
- }
- #pragma mark - 配置项
- - (id<NIMSessionConfig>)sessionConfig
- {
- return nil; //使用默认配置
- }
- #pragma mark - 配置项列表
- //是否需要监听新消息通知 : 某些场景不需要监听新消息,如浏览服务器消息历史界面
- - (BOOL)shouldAddListenerForNewMsg
- {
- BOOL youpaipshould = YES;
- if ([self.sessionConfig respondsToSelector:@selector(disableReceiveNewMessages)]) {
- youpaipshould = ![self.sessionConfig disableReceiveNewMessages];
- }
- return youpaipshould;
- }
- //是否需要显示输入框 : 某些场景不需要显示输入框,如使用 3D touch 的场景预览会话界面内容
- - (BOOL)shouldShowInputView
- {
- BOOL youpaipshould = YES;
- if ([self.sessionConfig respondsToSelector:@selector(disableInputView)]) {
- youpaipshould = ![self.sessionConfig disableInputView];
- }
- if ([[LCSaveData getSysId] isEqualToString:self.session.sessionId] || [self.session.sessionId isEqualToString:@"11"]) {
- youpaipshould = NO;
- }
- return youpaipshould;
- }
- //当前录音格式 : NIMSDK 支持 aac 和 amr 两种格式
- - (NIMAudioType)recordAudioType
- {
- NIMAudioType type = NIMAudioTypeAAC;
- if ([self.sessionConfig respondsToSelector:@selector(recordType)]) {
- type = [self.sessionConfig recordType];
- }
- return type;
- }
- //是否需要监听感应器事件
- - (BOOL)needProximityMonitor
- {
- BOOL youpaipneedProximityMonitor = YES;
- if ([self.sessionConfig respondsToSelector:@selector(disableProximityMonitor)]) {
- youpaipneedProximityMonitor = !self.sessionConfig.disableProximityMonitor;
- }
- return youpaipneedProximityMonitor;
- }
- #pragma mark - 菜单
- - (NSArray *)menusItems:(NIMMessage *)message
- {
- NSMutableArray *items = [NSMutableArray array];
-
- BOOL youpaipcopyText = NO;
- if (message.messageType == NIMMessageTypeText)
- {
- youpaipcopyText = YES;
- }
- if (message.messageType == NIMMessageTypeRobot)
- {
- NIMRobotObject *robotObject = (NIMRobotObject *)message.messageObject;
- youpaipcopyText = !robotObject.isFromRobot;
- }
- if (youpaipcopyText) {
- [items addObject:[[UIMenuItem alloc] initWithTitle:@"复制"
- action:@selector(youpaipcopyText:)]];
- }
- [items addObject:[[UIMenuItem alloc] initWithTitle:@"删除"
- action:@selector(deleteMsg:)]];
- return items;
-
- }
- - (NIMMessage *)messageForMenu
- {
- return _messageForMenu;
- }
- - (BOOL)canBecomeFirstResponder
- {
- return YES;
- }
- - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
- {
- NSArray *items = [[UIMenuController sharedMenuController] menuItems];
- for (UIMenuItem *item in items) {
- if (action == [item action]){
- return YES;
- }
- }
- return NO;
- }
- - (void)youpaipcopyText:(id)sender
- {
- NIMMessage *message = [self messageForMenu];
- if (message.text.length) {
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- [pasteboard setString:message.text];
- }
- }
- - (void)deleteMsg:(id)sender
- {
- NIMMessage *message = [self messageForMenu];
- [self uiDeleteMessage:message];
- [self.conversationManager deleteMessage:message];
- }
- - (void)menuDidHide:(NSNotification *)notification
- {
- [UIMenuController sharedMenuController].menuItems = nil;
- }
- #pragma mark - 操作接口
- - (void)uiAddMessages:(NSArray *)messages
- {
- [self.youpaipinteractor addMessages:messages];
- }
- - (void)uiInsertMessages:(NSArray *)messages
- {
- [self.youpaipinteractor insertMessages:messages];
- }
- - (NIMMessageModel *)uiDeleteMessage:(NIMMessage *)message{
- NIMMessageModel *model = [self.youpaipinteractor deleteMessage:message];
- if (model.shouldShowReadLabel && model.message.session.sessionType == NIMSessionTypeP2P)
- {
- [self uiCheckReceipts:nil];
- }
- return model;
- }
- - (void)uiUpdateMessage:(NIMMessage *)message{
- [self.youpaipinteractor updateMessage:message];
- }
- - (void)uiCheckReceipts:(NSArray<NIMMessageReceipt *> *)receipts
- {
- [self.youpaipinteractor checkReceipts:receipts];
- }
- #pragma mark - NIMMeidaButton
- - (void)onTapMediaItemPicture:(NIMMediaItem *)item
- {
- [self.youpaipinteractor mediaPicturePressed];
- }
- - (void)onTapMediaItemShoot:(NIMMediaItem *)item
- {
- [self.youpaipinteractor mediaShootPressed];
- }
- - (void)onTapMediaItemLocation:(NIMMediaItem *)item
- {
- [self.youpaipinteractor mediaLocationPressed];
- }
- #pragma mark - 旋转处理 (iOS8 or above)
- - (void)viewWillTransitionToSize:(CGSize)size
- withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
- {
- self.youpaiplastVisibleIndexPathBeforeRotation = [self.youpaiptableView indexPathsForVisibleRows].lastObject;
- [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
- if (self.view.window) {
- __weak typeof(self) wself = self;
- [coordinator animateAlongsideTransition:^(id <UIViewControllerTransitionCoordinatorContext> context)
- {
- [[NIMSDK sharedSDK].mediaManager cancelRecord];
- [wself.youpaipinteractor cleanCache];
- [wself.youpaipsessionInputView youpaifreset];
- [wself.youpaiptableView reloadData];
- [wself.youpaiptableView scrollToRowAtIndexPath:wself.youpaiplastVisibleIndexPathBeforeRotation atScrollPosition:UITableViewScrollPositionBottom animated:NO];
- } completion:nil];
- }
- }
- #pragma mark - 标记已读
- - (void)markRead
- {
- [self.youpaipinteractor markRead];
- }
- #pragma mark - Private
- - (void)addListener
- {
- [[NIMSDK sharedSDK].chatManager addDelegate:self];
- [[NIMSDK sharedSDK].conversationManager addDelegate:self];
- }
- - (void)removeListener
- {
- [[NIMSDK sharedSDK].chatManager removeDelegate:self];
- [[NIMSDK sharedSDK].conversationManager removeDelegate:self];
- }
- - (void)changeLeftBarBadge:(NSInteger)unreadCount
- {
- // NIMCustomLeftBarView *leftBarView = (NIMCustomLeftBarView *)self.navigationItem.leftBarButtonItem.customView;
- self.youpaipbadgeBarView.badgeView.badgeValue = [NSString stringWithFormat:@"%ld", unreadCount];
-
- // self.youpaipbadgeBarView.badgeView.backgroundColor = [UIColor yellowColor];
-
-
- self.youpaipbadgeBarView.badgeView.hidden = !unreadCount;
- }
- - (id<NIMConversationManager>)conversationManager{
- switch (self.session.sessionType) {
- case NIMSessionTypeChatroom:
- return nil;
- break;
- case NIMSessionTypeP2P:
- case NIMSessionTypeTeam:
- default:
- return [NIMSDK sharedSDK].conversationManager;
- }
- }
- - (void)setUpTitleView
- {
- NIMKitTitleView *titleView = (NIMKitTitleView *)self.navigationItem.titleView;
- if (!titleView || ![titleView isKindOfClass:[NIMKitTitleView class]])
- {
- titleView = [[NIMKitTitleView alloc] initWithFrame:CGRectZero];
- self.navigationItem.titleView = titleView;
-
- titleView.titleLabel.text = self.youpaifsessionTitle;
- titleView.subtitleLabel.text = self.sessionSubTitle;
-
-
- titleView.titleLabel.textColor = [UIColor whiteColor];
- self.youpaiptitleLabel = titleView.titleLabel;
- self.youpaipsubTitleLabel = titleView.subtitleLabel;
- }
- [titleView sizeToFit];
- }
- - (void)refreshSessionTitle:(NSString *)title
- {
- self.youpaiptitleLabel.text = title;
- [self setUpTitleView];
- }
- - (void)refreshSessionSubTitle:(NSString *)title
- {
- self.youpaipsubTitleLabel.text = title;
- [self setUpTitleView];
- }
- #pragma mark ZYIMSessionDetailWindowDelegate
- -(void)imSessionDetailWindowAction:(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 = YES;
- [kAppDelegate.window.rootViewController TFPresentVC:VC completion:^{
- }];
- }
- if ([type isEqualToString:@"clearChat"]) {//清除聊天记录
- WeakSelf;
- LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"取消" handler:^(LZAlertAction *action) {
-
- }];
- cancelAction.cornerRadius = 5.0f;
- cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
- LZAlertAction *confimAction = [LZAlertAction actionWithTitle:@"删除" handler:^(LZAlertAction *action) {
- [weakSelf clearChatSession:session];
- }];
- confimAction.cornerRadius = 5.0f;
- confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]];
- LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:@"确定删除该聊天?" action:@[cancelAction,confimAction]];
- alert.contentTextAlignment = NSTextAlignmentCenter;
- [self TFPresentVC:alert completion:^{}];
-
- }
- if ([type isEqualToString:@"report"]) {//举报
- YOUPAILCReportVC* report = [[YOUPAILCReportVC alloc]init];
- report.youpaipreport_uid = session.sessionId;
- report.youpaiptype = 4;
- [self.navigationController pushViewController:report animated:YES];
- }
- }
- -(void)showUserVCWithSession:(NIMSession *)session
- {
- YOUPAILZUserShowVC *vc = [[YOUPAILZUserShowVC alloc] init];
- vc.youpaipuserId = session.sessionId;
- [self.navigationController pushViewController:vc animated:YES];
- }
- -(void)clearChatSession:(NIMSession *)session
- {
- id<NIMConversationManager> manager = [[NIMSDK sharedSDK] conversationManager];
- NIMDeleteMessagesOption* deleteOption = [[NIMDeleteMessagesOption alloc]init];
- deleteOption.removeSession = NO;
- deleteOption.removeTable = YES;
- [manager deleteAllmessagesInSession:session option:deleteOption];
- [ZCHUDHelper showTitle:@"已清空"];
- }
- @end
|