Files
ifish/Ifish/controllers/IfishTabControllers/消息/IfishIMFiles/IfishChatVC/IfishSessionViewController.m
T
2017-08-15 16:59:01 +08:00

950 lines
35 KiB
Objective-C

//
// IfishSessionViewController.m
// Ifish
//
// Created by imac on 16/9/13.
// Copyright © 2016年 lianxiang. All rights reserved.
//
#import "IfishSessionViewController.h"
@import MobileCoreServices;
@import AVFoundation;
#import "Reachability.h"
#import "UIActionSheet+NTESBlock.h"
#import "NTESCustomSysNotificationSender.h"
//#import "NTESSessionConfig.h"
#import "NIMMediaItem.h"
#import "NTESSessionMsgConverter.h"
#import "NTESFileLocationHelper.h"
#import "NTESSessionMsgConverter.h"
//#import "UIView+Toast.h"
//#import "Toast+UIView.h"
#import "NTESSnapchatAttachment.h"
#import "NTESJanKenPonAttachment.h"
#import "NTESFileTransSelectViewController.h"
#import "NTESAudioChatViewController.h"
#import "NTESWhiteboardViewController.h"
#import "NTESVideoChatViewController.h"
#import "NTESChartletAttachment.h"
#import "NTESGalleryViewController.h"
#import "NTESVideoViewController.h"
#import "NTESFilePreViewController.h"
#import "NTESAudio2TextViewController.h"
#import "NSDictionary+NTESJson.h"
#import "NIMAdvancedTeamCardViewController.h"
#import "NTESSessionRemoteHistoryViewController.h"
#import "NIMNormalTeamCardViewController.h"
#import "UIView+NTES.h"
#import "NTESBundleSetting.h"
#import "NTESPersonalCardViewController.h"
#import "NTESSessionSnapchatContentView.h"
#import "NTESSessionLocalHistoryViewController.h"
#import "NIMContactSelectViewController.h"
#import "SVProgressHUD.h"
#import "NTESSessionCardViewController.h"
#import "NTESFPSLabel.h"
#import "UIAlertView+NTESBlock.h"
#import "NIMKit.h"
#import "NTESSessionUtil.h"
#import "CTAssetsPickerController.h"
#import "NIMKitMediaFetcher.h"
#import "NIMKitLocationPoint.h"
#import "NIMLocationViewController.h"
#import "SessionConfig.h"
#import "PushMasssageWebViewController.h"
#import "ShareReportViewController.h"
#import "KanHuBaoGaoModel.h"
#import "PingfenModel.h"
#import "NIMSessionConfig.h"
@interface IfishSessionViewController ()
<UIImagePickerControllerDelegate,
UINavigationControllerDelegate,
NIMSystemNotificationManagerDelegate,
NTESTimerHolderDelegate,
NIMMediaManagerDelgate,
NIMContactSelectDelegate
>
@property (nonatomic,strong) SessionConfig *sessionConfig;
@property (nonatomic,strong) NTESCustomSysNotificationSender *notificaionSender;
@property (nonatomic,strong) NTESTimerHolder *titleTimer;
@property (nonatomic,strong) NTESFPSLabel *fpsLabel;
@property (nonatomic,strong) UIView *currentSingleSnapView;
@property (nonatomic,strong) UIImagePickerController *imagePicker;
@property (nonatomic,strong) NIMKitMediaFetcher *mediaFetcher;
@end
@implementation IfishSessionViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
_notificaionSender = [[NTESCustomSysNotificationSender alloc] init];
BOOL disableCommandTyping = self.disableCommandTyping || (self.session.sessionType == NIMSessionTypeP2P &&[[NIMSDK sharedSDK].userManager isUserInBlackList:self.session.sessionId]);
if (!disableCommandTyping) {
_titleTimer = [[NTESTimerHolder alloc] init];
[[[NIMSDK sharedSDK] systemNotificationManager] addDelegate:self];
}
if ([[NTESBundleSetting sharedConfig] showFps])
{
self.fpsLabel = [[NTESFPSLabel alloc] initWithFrame:CGRectZero];
[self.view addSubview:self.fpsLabel];
self.fpsLabel.right = self.view.width;
self.fpsLabel.top = self.tableView.top + self.tableView.contentInset.top;
}
[self setNav];
//+ 号中只用相册 摄像 位置
}
-(void)viewWillAppear:(BOOL)animated{
//判断是否是爱鱼奇官方帐号
if (self.isAiYuQi) {
self.sessionInputView.hidden = YES;
}else{
self.sessionInputView.hidden = NO;
}
}
-(void)setNav{
if (_navState ==1) {
[self setWhiteNav];
}else{
[self setBalcknav];
}
}
-(void)setBalcknav{
//黑色
UIButton *bakbutton = [UIButton buttonWithType:UIButtonTypeCustom];
bakbutton.frame = CGRectMake(0,0,48,44);
[bakbutton setImage:[UIImage imageNamed:@"arrow_l"] forState:UIControlStateNormal];
[bakbutton addTarget: self action: @selector(goBackAction) forControlEvents: UIControlEventTouchUpInside];
UIBarButtonItem *back=[[UIBarButtonItem alloc] initWithCustomView:bakbutton];
self.navigationItem.leftBarButtonItem=back;
UILabel*labe=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 44)];
labe.text=[self sessionTitle];;
labe.textAlignment=NSTextAlignmentCenter;
labe.textColor=[UIColor whiteColor];
self.navigationItem.titleView=labe;
}
-(void)setWhiteNav{
//白色
UIButton *bakbutton = [UIButton buttonWithType:UIButtonTypeCustom];
bakbutton.frame = CGRectMake(0,0,48,44);
[bakbutton setImage:[UIImage imageNamed:@"arrow_b"] forState:UIControlStateNormal];
[bakbutton addTarget: self action: @selector(goBackAction) forControlEvents: UIControlEventTouchUpInside];
UIBarButtonItem *back=[[UIBarButtonItem alloc] initWithCustomView:bakbutton];
self.navigationItem.leftBarButtonItem=back;
UILabel*labe=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 60, 44)];
labe.text=[self sessionTitle];;
labe.textAlignment=NSTextAlignmentCenter;
labe.textColor=[UIColor blackColor];
self.navigationItem.titleView=labe;
}
-(void)goBackAction{
[self.navigationController popViewControllerAnimated:YES];
}
- (id<NIMSessionConfig>)sessionConfig{
if (_sessionConfig == nil) {
_sessionConfig = [[SessionConfig alloc] init];
_sessionConfig.session = self.session;
}
return _sessionConfig;
}
#pragma mark - NIMSystemNotificationManagerProcol
- (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.title = @"正在输入...";
[_titleTimer startTimer:5
delegate:self
repeats:NO];
}
}
}
- (void)onNTESTimerFired:(NTESTimerHolder *)holder
{
self.title = [self sessionTitle];
}
- (NSString *)sessionTitle{
if ([self.session.sessionId isEqualToString:[NIMSDK sharedSDK].loginManager.currentAccount]) {
return @"我的电脑";
}
return [super sessionTitle];
//使用 爱鱼奇用户系统 用户名 在父类中改
//return self.targetChatname;
}
- (void)onTextChanged:(id)sender
{
[_notificaionSender sendTypingState:self.session];
}
- (void)onSelectChartlet:(NSString *)chartletId
catalog:(NSString *)catalogId
{
NTESChartletAttachment *attachment = [[NTESChartletAttachment alloc] init];
attachment.chartletId = chartletId;
attachment.chartletCatalog = catalogId;
[self sendMessage:[NTESSessionMsgConverter msgWithChartletAttachment:attachment]];
}
#pragma mark - 石头剪子布
- (void)mediaJankenponPressed
{
NTESJanKenPonAttachment *attachment = [[NTESJanKenPonAttachment alloc] init];
attachment.value = arc4random() % 3 + 1;
[self sendMessage:[NTESSessionMsgConverter msgWithJenKenPon:attachment]];
}
#pragma mark - 实时语音
#pragma mark - 实时语音
- (void)onTapMediaItemAudioChat:(NIMMediaItem *)item
{
if ([self checkCondition]) {
//由于音视频聊天里头有音频和视频聊天界面的切换,直接用present的话页面过渡会不太自然,这里还是用push,然后做出present的效果
NTESAudioChatViewController *vc = [[NTESAudioChatViewController alloc] initWithCallee:self.session.sessionId];
CATransition *transition = [CATransition animation];
transition.duration = 0.25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromTop;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
self.navigationController.navigationBarHidden = YES;
[self.navigationController pushViewController:vc animated:NO];
}
}
#pragma mark - 视频聊天
- (void)onTapMediaItemVideoChat:(NIMMediaItem *)item
{
if ([self checkCondition]) {
//由于音视频聊天里头有音频和视频聊天界面的切换,直接用present的话页面过渡会不太自然,这里还是用push,然后做出present的效果
NTESVideoChatViewController *vc = [[NTESVideoChatViewController alloc] initWithCallee:self.session.sessionId];
CATransition *transition = [CATransition animation];
transition.duration = 0.25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromTop;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
self.navigationController.navigationBarHidden = YES;
[self.navigationController pushViewController:vc animated:NO];
}
}
#pragma mark - 文件传输
- (void)mediaFileTransPressed
{
NTESFileTransSelectViewController *vc = [[NTESFileTransSelectViewController alloc]
initWithNibName:nil bundle:nil];
__weak typeof(self) wself = self;
vc.completionBlock = ^void(id sender,NSString *ext){
if ([sender isKindOfClass:[NSString class]]) {
[wself sendMessage:[NTESSessionMsgConverter msgWithFilePath:sender]];
}else if ([sender isKindOfClass:[NSData class]]){
[wself sendMessage:[NTESSessionMsgConverter msgWithFileData:sender extension:ext]];
}
};
[self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - 阅后即焚
- (void)onTapMediaItemSnapChat:(NIMMediaItem *)item
{
UIActionSheet *sheet;
BOOL isCamraAvailable = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
if (isCamraAvailable) {
sheet = [[UIActionSheet alloc] initWithTitle:@"请选择" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册中选取",@"拍照",nil];
}else{
sheet = [[UIActionSheet alloc] initWithTitle:@"请选择" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相册中选取",nil];
}
__weak typeof(self) wself = self;
[sheet showInView:self.view completionHandler:^(NSInteger index) {
switch (index) {
case 0:{
//相册
[wself.mediaFetcher fetchPhotoFromLibrary:^(NSString *path, PHAssetMediaType type) {
if (type == PHAssetMediaTypeImage) {
[wself sendSnapchatMessagePath:path];
}else{
dispatch_async(dispatch_get_main_queue(), ^{
[wself.view makeToast:@"阅后即焚只支持图片"];
});
}
}];
}
break;
case 1:{
//相机
[wself.mediaFetcher fetchMediaFromCamera:^(NSString *path, UIImage *image) {
if (image) {
[wself sendSnapchatMessage:image];
}
}];
}
break;
default:
return;
}
}];
}
- (void)sendSnapchatMessagePath:(NSString *)path
{
NTESSnapchatAttachment *attachment = [[NTESSnapchatAttachment alloc] init];
[attachment setImageFilePath:path];
[self sendMessage:[NTESSessionMsgConverter msgWithSnapchatAttachment:attachment]];
}
- (void)sendSnapchatMessage:(UIImage *)image
{
NTESSnapchatAttachment *attachment = [[NTESSnapchatAttachment alloc] init];
[attachment setImage:image];
[self sendMessage:[NTESSessionMsgConverter msgWithSnapchatAttachment:attachment]];
}
#pragma mark - 白板
- (void)mediaWhiteBoardPressed
{
NTESWhiteboardViewController *vc = [[NTESWhiteboardViewController alloc] initWithSessionID:nil
peerID:self.session.sessionId
types:NIMRTSServiceReliableTransfer | NIMRTSServiceAudio
info:@"白板演示"];
[self presentViewController:vc animated:NO completion:nil];
}
#pragma mark - 提醒消息
- (void)mediaTipPressed
{
UIAlertView *alert =[[UIAlertView alloc] initWithTitle:nil message:@"输入提醒" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert showAlertWithCompletionHandler:^(NSInteger index) {
switch (index) {
case 1:{
UITextField *textField = [alert textFieldAtIndex:0];
NIMMessage *message = [NTESSessionMsgConverter msgWithTip:textField.text];
[self sendMessage:message];
}
break;
default:
break;
}
}];
}
#pragma mark - 录音事件
- (void)onRecordFailed:(NSError *)error
{
[self.view makeToast:@"录音失败"];
}
- (BOOL)recordFileCanBeSend:(NSString *)filepath
{
NSURL *URL = [NSURL fileURLWithPath:filepath];
AVURLAsset *urlAsset = [[AVURLAsset alloc]initWithURL:URL options:nil];
CMTime time = urlAsset.duration;
CGFloat mediaLength = CMTimeGetSeconds(time);
return mediaLength > 2;
}
- (void)showRecordFileNotSendReason
{
[self.view makeToast:@"录音时间太短"];
}
#pragma mark - Cell事件
- (void)onTapCell:(NIMKitEvent *)event
{
//remoteExt 服务器扩展
BOOL handled = NO;
NSString *eventName = event.eventName;
if ([eventName isEqualToString:NIMKitEventNameTapContent])
{
NIMMessage *message = event.messageModel.message;
NSDictionary *actions = [self cellActions];
NSString *value = actions[@(message.messageType)];
if (value) {
SEL selector = NSSelectorFromString(value);
if (selector && [self respondsToSelector:selector]) {
SuppressPerformSelectorLeakWarning([self performSelector:selector withObject:message]);
handled = YES;
}
}
}
else if([eventName isEqualToString:NIMKitEventNameTapLabelLink])
{
NSString *link = event.data;
//[self.view makeToast:[NSString stringWithFormat:@"tap link : %@",link]
//];
PushMasssageWebViewController *urlVC=[[PushMasssageWebViewController alloc] init];
urlVC.pushtitle = @"浏览网页";
urlVC.pushlink = link;
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:urlVC animated:YES];
handled = YES;
}
else if([eventName isEqualToString:NIMDemoEventNameOpenSnapPicture])
{
NIMCustomObject *object = event.messageModel.message.messageObject;
NTESSnapchatAttachment *attachment = (NTESSnapchatAttachment *)object.attachment;
if(attachment.isFired){
return;
}
UIView *sender = event.data;
self.currentSingleSnapView = [NTESGalleryViewController alertSingleSnapViewWithMessage:object.message baseView:sender];
handled = YES;
}
else if([eventName isEqualToString:NIMDemoEventNameCloseSnapPicture])
{
//点击很快的时候可能会触发两次查看,所以这里不管有没有查看过 先强直销毁掉
NIMCustomObject *object = event.messageModel.message.messageObject;
UIView *senderView = event.data;
[senderView dismissPresentedView:YES complete:nil];
NTESSnapchatAttachment *attachment = (NTESSnapchatAttachment *)object.attachment;
if(attachment.isFired){
return;
}
attachment.isFired = YES;
NIMMessage *message = object.message;
if ([NTESBundleSetting sharedConfig].autoRemoveSnapMessage) {
[[NIMSDK sharedSDK].conversationManager deleteMessage:message];
[self uiDeleteMessage:message];
}else{
[[NIMSDK sharedSDK].conversationManager updateMessage:message forSession:message.session completion:nil];
[self uiUpdateMessage:message];
}
[[NSFileManager defaultManager] removeItemAtPath:attachment.filepath error:nil];
handled = YES;
self.currentSingleSnapView = nil;
}
else if ([eventName isEqualToString:NIMDemoEventNameCloseSnapPicture])
{
}
if (!handled) {
NSAssert(0, @"invalid event");
}
}
- (void)onLongPressCell:(NIMMessage *)message inView:(UIView *)view
{
[super onLongPressCell:message
inView:view];
}
#pragma mark - 头像点击事件
- (void)onTapAvatar:(NSString *)userId{
//爱鱼奇
// UserModel*umodel=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
// NSString *localUserId =[NSString stringWithFormat:@"%@",umodel.userId];
// if ([userId isEqualToString:localUserId]) {
//
// InfoViewController *vc = [[InfoViewController alloc] init];
// [self.navigationController pushViewController:vc animated:YES];
//
// }else{
//// // UIViewController *vc = [[NTESPersonalCardViewController alloc] initWithUserId:userId];
//// // [self.navigationController pushViewController:vc animated:YES];
// ////需要获取爱鱼奇用户信息非本地用户暂无 建议查询爱鱼奇自己的用户系统
// NIMUser *user = [[NIMSDK sharedSDK].userManager userInfo:userId];
// //本地sdk缓存
// NSLog(@"user1%@",user);
// NSArray *IDArr=@[userId];
//
// [[NIMSDK sharedSDK].userManager fetchUserInfos:IDArr completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
// NIMUser *user = users[0];
// //云信服务器
// NSLog(@"user2%@",user);
//
// }];
//
//
//
// }
//
//云信
//UIViewController *vc = [[NTESPersonalCardViewController alloc] initWithUserId:userId];
// [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - Cell Actions
- (void)showImage:(NIMMessage *)message
{
self.hidesBottomBarWhenPushed = YES;
NIMImageObject *object = message.messageObject;
NTESGalleryItem *item = [[NTESGalleryItem alloc] init];
item.thumbPath = [object thumbPath];
item.imageURL = [object url];
item.name = [object displayName];
NTESGalleryViewController *vc = [[NTESGalleryViewController alloc] initWithItem:item];
[self.navigationController pushViewController:vc animated:YES];
if(![[NSFileManager defaultManager] fileExistsAtPath:object.thumbPath]){
//如果缩略图下跪了,点进看大图的时候再去下一把缩略图
__weak typeof(self) wself = self;
[[NIMSDK sharedSDK].resourceManager download:object.thumbUrl filepath:object.thumbPath progress:nil completion:^(NSError *error) {
if (!error) {
[wself uiUpdateMessage:message];
}
}];
}
}
- (void)showVideo:(NIMMessage *)message
{
NIMVideoObject *object = message.messageObject;
NTESVideoViewController *playerViewController = [[NTESVideoViewController alloc] initWithVideoObject:object];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:playerViewController animated:YES];
if(![[NSFileManager defaultManager] fileExistsAtPath:object.coverPath]){
//如果封面图下跪了,点进视频的时候再去下一把封面图
__weak typeof(self) wself = self;
[[NIMSDK sharedSDK].resourceManager download:object.coverUrl filepath:object.coverPath progress:nil completion:^(NSError *error) {
if (!error) {
[wself uiUpdateMessage:message];
}
}];
}
}
- (void)showLocation:(NIMMessage *)message
{
NIMLocationObject *object = message.messageObject;
NIMKitLocationPoint *locationPoint = [[NIMKitLocationPoint alloc] initWithLocationObject:object];
NIMLocationViewController *vc = [[NIMLocationViewController alloc] initWithLocationPoint:locationPoint];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)showFile:(NIMMessage *)message
{
NIMFileObject *object = message.messageObject;
NTESFilePreViewController *vc = [[NTESFilePreViewController alloc] initWithFileObject:object];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)showCustom:(NIMMessage *)message
{
//普通的自定义消息点击事件可以在这里做哦~
}
#pragma mark - 导航按钮
- (void)onTouchUpInfoBtn:(id)sender{
NTESSessionCardViewController *vc = [[NTESSessionCardViewController alloc] initWithSession:self.session];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)enterHistory:(id)sender{
[self.view endEditing:YES];
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"选择操作" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"云消息记录",@"搜索本地消息记录",@"清空本地聊天记录", nil];
[sheet showInView:self.view completionHandler:^(NSInteger index) {
switch (index) {
case 0:{ //查看云端消息
NTESSessionRemoteHistoryViewController *vc = [[NTESSessionRemoteHistoryViewController alloc] initWithSession:self.session];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
break;
}
case 1:{ //搜索本地消息
NTESSessionLocalHistoryViewController *vc = [[NTESSessionLocalHistoryViewController alloc] initWithSession:self.session];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
break;
}
case 2:{ //清空聊天记录
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"确定清空聊天记录?" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:nil, nil];
__weak UIActionSheet *wSheet;
[sheet showInView:self.view completionHandler:^(NSInteger index) {
if (index == wSheet.destructiveButtonIndex) {
BOOL removeRecentSession = [NTESBundleSetting sharedConfig].removeSessionWheDeleteMessages;
[[NIMSDK sharedSDK].conversationManager deleteAllmessagesInSession:self.session removeRecentSession:removeRecentSession];
}
}];
break;
}
default:
break;
}
}];
}
- (void)enterTeamCard:(id)sender{
NIMTeam *team = [[NIMSDK sharedSDK].teamManager teamById:self.session.sessionId];
UIViewController *vc;
if (team.type == NIMTeamTypeNormal) {
vc = [[NIMNormalTeamCardViewController alloc] initWithTeam:team];
}else if(team.type == NIMTeamTypeAdvanced){
vc = [[NIMAdvancedTeamCardViewController alloc] initWithTeam:team];
}
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - 菜单
- (NSArray *)menusItems:(NIMMessage *)message
{
NSMutableArray *items = [NSMutableArray array];
NSArray *defaultItems = [super menusItems:message];
if (defaultItems) {
[items addObjectsFromArray:defaultItems];
}
// if ([NTESSessionUtil canMessageBeForwarded:message]) {
// [items addObject:[[UIMenuItem alloc] initWithTitle:@"转发" action:@selector(forwardMessage:)]];
// }
// if ([NTESSessionUtil canMessageBeRevoked:message]) {
// [items addObject:[[UIMenuItem alloc] initWithTitle:@"撤回" action:@selector(revokeMessage:)]];
// }
// if (message.messageType == NIMMessageTypeAudio) {
// [items addObject:[[UIMenuItem alloc] initWithTitle:@"转文字" action:@selector(audio2Text:)]];
// }
return items;
}
- (void)audio2Text:(id)sender
{
NIMMessage *message = [self messageForMenu];
__weak typeof(self) wself = self;
NTESAudio2TextViewController *vc = [[NTESAudio2TextViewController alloc] initWithMessage:message];
vc.completeHandler = ^(void){
[wself uiUpdateMessage:message];
};
[self presentViewController:vc
animated:YES
completion:nil];
}
- (void)forwardMessage:(id)sender
{
NIMMessage *message = [self messageForMenu];
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"选择会话类型" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"个人",@"群组", nil];
__weak typeof(self) weakSelf = self;
[sheet showInView:self.view completionHandler:^(NSInteger index) {
switch (index) {
case 0:{
NIMContactFriendSelectConfig *config = [[NIMContactFriendSelectConfig alloc] init];
config.needMutiSelected = NO;
NIMContactSelectViewController *vc = [[NIMContactSelectViewController alloc] initWithConfig:config];
vc.finshBlock = ^(NSArray *array){
NSString *userId = array.firstObject;
NIMSession *session = [NIMSession session:userId type:NIMSessionTypeP2P];
[weakSelf forwardMessage:message toSession:session];
};
[vc show];
}
break;
case 1:{
NIMContactTeamSelectConfig *config = [[NIMContactTeamSelectConfig alloc] init];
NIMContactSelectViewController *vc = [[NIMContactSelectViewController alloc] initWithConfig:config];
vc.finshBlock = ^(NSArray *array){
NSString *teamId = array.firstObject;
NIMSession *session = [NIMSession session:teamId type:NIMSessionTypeTeam];
[weakSelf forwardMessage:message toSession:session];
};
[vc show];
}
break;
case 2:
break;
default:
break;
}
}];
}
- (void)revokeMessage:(id)sender
{
NIMMessage *message = [self messageForMenu];
__weak typeof(self) weakSelf = self;
[[NIMSDK sharedSDK].chatManager revokeMessage:message completion:^(NSError * _Nullable error) {
if (error) {
if (error.code == NIMRemoteErrorCodeDomainExpireOld) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"发送时间超过2分钟的消息,不能被撤回" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alert show];
}else{
NSLog(@"revoke message eror code %zd",error.code);
[weakSelf.view makeToast:@"消息撤回失败,请重试"];
}
}
else
{
NIMMessageModel *model = [self uiDeleteMessage:message];
NIMMessage *tip = [NTESSessionMsgConverter msgWithTip:[NTESSessionUtil tipOnMessageRevoked:message]];
tip.timestamp = model.messageTime;
[self uiAddMessages:@[tip]];
tip.timestamp = message.timestamp;
// saveMessage 方法执行成功后会触发 onRecvMessages: 回调,但是这个回调上来的 NIMMessage 时间为服务器时间,和界面上的时间有一定出入,所以要提前先在界面上插入一个和被删消息的界面时间相符的 Tip, 当触发 onRecvMessages: 回调时,组件判断这条消息已经被插入过了,就会忽略掉。
[[NIMSDK sharedSDK].conversationManager saveMessage:tip forSession:message.session completion:nil];
}
}];
}
- (void)forwardMessage:(NIMMessage *)message toSession:(NIMSession *)session
{
NSString *name;
if (session.sessionType == NIMSessionTypeP2P)
{
name = [[NIMKit sharedKit] infoByUser:session.sessionId inSession:session].showName;
}
else
{
name = [[NIMKit sharedKit] infoByTeam:session.sessionId].showName;
}
NSString *tip = [NSString stringWithFormat:@"确认转发给 %@ ?",name];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"确认转发" message:tip delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
__weak typeof(self) weakSelf = self;
[alert showAlertWithCompletionHandler:^(NSInteger index) {
if(index == 1){
[[NIMSDK sharedSDK].chatManager forwardMessage:message toSession:session error:nil];
[weakSelf.view makeToast:@"已发送" ];
}
}];
}
#pragma mark - 辅助方法
- (BOOL)checkCondition
{
BOOL result = YES;
if (![[Reachability reachabilityForInternetConnection] isReachable]) {
[self.view makeToast:@"请检查网络"];
result = NO;
}
NSString *currentAccount = [[NIMSDK sharedSDK].loginManager currentAccount];
if ([currentAccount isEqualToString:self.session.sessionId]) {
[self.view makeToast:@"不能和自己通话哦" ];
result = NO;
}
return result;
}
- (NSDictionary *)cellActions
{
static NSDictionary *actions = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
actions = @{@(NIMMessageTypeImage) : @"showImage:",
@(NIMMessageTypeAudio) : @"playAudio:",
@(NIMMessageTypeVideo) : @"showVideo:",
@(NIMMessageTypeLocation) : @"showLocation:",
@(NIMMessageTypeFile) : @"showFile:",
@(NIMMessageTypeCustom): @"showCustom:"};
});
return actions;
}
- (BOOL)shouldAutorotate{
return !self.currentSingleSnapView;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc
{
[[[NIMSDK sharedSDK] systemNotificationManager] removeDelegate:self];
[_fpsLabel invalidate];
}
- (void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
self.fpsLabel.right = self.view.width;
self.fpsLabel.top = self.tableView.top + self.tableView.contentInset.top;
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[[NIMSDK sharedSDK].mediaManager stopRecord];
[[NIMSDK sharedSDK].mediaManager stopPlay];
}
//爱鱼奇消息扩展
-(void)onTapContentText:(RemoteExtMassageModel *)massageModel
{
//all_shops_push 所有商家推送
if ([massageModel.pushType isEqualToString:@"all_push"]||[massageModel.pushType isEqualToString:@"all_ios_push"]||[massageModel.pushType isEqualToString:@"all_shops_push"]) {
if (![massageModel.pushlink isKindOfClass:[NSNull class]] &&massageModel.pushlink &&![massageModel.pushlink isEqualToString:@""]) {
PushMasssageWebViewController *webVC = [[PushMasssageWebViewController alloc] init];
webVC.pushlink = massageModel.pushlink;
webVC.pushtitle = massageModel.pushTitle;
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:webVC animated:YES];
}
}else if ([massageModel.pushType isEqualToString:@"send_report"]){
if (![massageModel.pushId isKindOfClass:[NSNull class]] && ![massageModel.pushlink isKindOfClass:[NSNull class]] && massageModel.pushId !=nil && massageModel.pushlink!=nil) {
[self kanHuBaoGaoXiangQingwithReportId:massageModel.pushId addUrl:massageModel.pushlink];
}else{
[self.view makeToast:@"reportId 或 url 为空"];
}
}
}
//查询看护报告详情
-(void)kanHuBaoGaoXiangQingwithReportId:(NSString*)reportId addUrl:(NSString *)shareUrl{
[AFNOHeaderHttpTool getLookReportById:reportId success:^(id response) {
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
if ([resultDic[@"result"] isEqualToString:@"100"]) {
NSDictionary *dataDic = resultDic[@"data"];
ShareReportViewController *shareVC=[[ShareReportViewController alloc] init];
KanHuBaoGaoModel *bagM =[[KanHuBaoGaoModel alloc] init];
bagM.shareImg = dataDic[@"shareImg"];
bagM.timestamp = dataDic[@"timestamp"];
bagM.totalIndex = dataDic[@"totalIndex"];
bagM.baifenbi = dataDic[@"baifenbi"];
bagM.reportId = dataDic[@"reportId"];
bagM.userImg = dataDic[@"userImg"];
bagM.shopsName =dataDic[@"shopsName"];
bagM.signature = dataDic[@"signature"];
shareVC.baGaoMod = bagM;
PingfenModel *PFMode1=[[PingfenModel alloc] init];
PFMode1.pingFenDesc = dataDic[@"index1Text"];
PFMode1.pingFenNumber = dataDic[@"index1"];
PingfenModel *PFMode2=[[PingfenModel alloc] init];
PFMode2.pingFenDesc = dataDic[@"index2Text"];
PFMode2.pingFenNumber = dataDic[@"index2"];
PingfenModel *PFMode3=[[PingfenModel alloc] init];
PFMode3.pingFenDesc = dataDic[@"index3Text"];
PFMode3.pingFenNumber = dataDic[@"index3"];
NSArray *pingfenArr=@[PFMode1,PFMode2,PFMode3];
shareVC.pinFenArr = pingfenArr;
NSString *suggesttrue=dataDic[@"suggestion"];
shareVC.suggesttrue = suggesttrue;
shareVC.shareUrl = shareUrl;
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:shareVC animated:YES];
}else{
[self.view makeToast:@"看护报告详情查询失败"];
}
} failure:^(NSError *err) {
[self.view makeToast:@"请检查网络"];
}];
}
@end