12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780 |
- //
- // EMChatViewController.m
- // ChatDemo-UI3.0
- //
- // Created by XieYajie on 2019/1/18.
- // Copyright © 2019 XieYajie. All rights reserved.
- //
- #import <AVKit/AVKit.h>
- #import <Photos/Photos.h>
- #import <AVFoundation/AVFoundation.h>
- #import <AssetsLibrary/AssetsLibrary.h>
- #import <MobileCoreServices/MobileCoreServices.h>
- #import "EMChatViewController.h"
- #import "EMImageBrowser.h"
- #import "EMDateHelper.h"
- #import "EMAudioPlayerHelper.h"
- #import "EMConversationHelper.h"
- #import "EMMessageModel.h"
- #import "EMReadReceiptMemberModel.h"
- #import "EMChatBar.h"
- #import "EMMessageCell.h"
- #import "EMMessageTimeCell.h"
- #import "EMLocationViewController.h"
- #import "EMMsgTranspondViewController.h"
- #import "EMAtGroupMembersViewController.h"
- #import "FavoritesViewController.h"
- #import "ChatMsgDetailChatInfoVC.h"
- #import "ChatMsgPersonInfoVC.h"
- #import "ChatMsgListImModel.h"
- #import "MailListDetailVC.h"
- #import "FWZFileGetTool.h"
- #import "EMChatFileShowVC.h"
- #import "DrawerView.h"
- #import "TabBarController.h"
- #import "FWZGetNoteBookTool.h"
- #import "NoteBookVC.h"
- #import "OtherNoteBookVC.h"
- #import "MyFavoriteVC.h"
- #import "OtherFavoriteVC.h"
- #import "TDGroupInfoListVC.h"
- #import "DownFileViewController.h"
- #import "WorkFlowDetailsController.h"
- #import "MyTDGroupViewController.h"
- #import "HomeDetailController.h"
- #import "MyApprovalPageDetail.h"
- #import "NoteBookShareVC.h"
- #import "MoveViewController.h"
- @interface EMChatViewController ()<UIScrollViewDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, EMMultiDevicesDelegate, EMChatManagerDelegate, EMGroupManagerDelegate, EMChatroomManagerDelegate, EMChatBarDelegate, EMMessageCellDelegate, EMChatBarEmoticonViewDelegate, EMChatBarRecordAudioViewDelegate,EMMoreFunctionViewDelegate,EMReadReceiptMsgDelegate,NoteBookShareVCDelegate>
- @property (nonatomic, strong) dispatch_queue_t msgQueue;
- @property (nonatomic, strong) UIView * titleV;
- @property (nonatomic, strong) UIButton * backBtn;
- @property (nonatomic, strong) UIButton * tabBtn;
- @property (nonatomic, strong) UIButton * mangerBtn;
- @property (nonatomic, strong) UILabel * titleL;
- @property (strong,nonatomic) DrawerView *drawerView;
- @property (nonatomic) BOOL isFirstLoadMsg;
- @property (nonatomic) BOOL isViewDidAppear;
- @property (nonatomic, strong) EMConversationModel *conversationModel;
- @property (nonatomic, strong) NSString *moreMsgId; //第一条消息的消息id
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UILabel *titleDetailLabel;
- @property (nonatomic, strong) EMChatBar *chatBar;
- @property (nonatomic, strong) UIImagePickerController *imagePicker;
- @property (nonatomic, strong) EMGroup *group;
- //阅读回执
- @property (nonatomic, strong) EMReadReceiptMsgViewController *readReceiptControl;
- //长按操作栏
- @property (strong, nonatomic) NSIndexPath *menuIndexPath;
- @property (nonatomic, strong) UIMenuController *menuController;
- @property (nonatomic, strong) UIMenuItem *deleteMenuItem;
- @property (nonatomic, strong) UIMenuItem *copyMenuItem;
- @property (nonatomic, strong) UIMenuItem *recallMenuItem;
- @property (nonatomic, strong) UIMenuItem *transpondMenuItem;
- @property (nonatomic, strong) UIMenuItem *playAndRecordMenuItem;
- //消息格式化
- @property (nonatomic) NSTimeInterval msgTimelTag;
- //@
- @property (nonatomic) BOOL isWillInputAt;
- @property (strong, nonatomic) NoteBookShareVC *noteBookShareVC;
- @property (strong, nonatomic) UIImage *sendImage;
- @property (copy, nonatomic) FlowAttachmentsModel *sendModel;
- //Typing
- @property (nonatomic) BOOL isTyping;
- @property (nonatomic) BOOL enableTyping;
- @property (nonatomic, copy) NSMutableArray *userInfoArray;
- @property (nonatomic, copy) NSMutableArray *chatDistoryArray;
- @property (nonatomic, assign) NSInteger UserId;
- @end
- @implementation EMChatViewController
- - (instancetype)initWithConversationId:(NSString *)aId
- type:(EMConversationType)aType
- createIfNotExist:(BOOL)aIsCreate
- {
- self = [super init];
- if (self) {
- EMConversation *conversation = [[EMClient sharedClient].chatManager getConversation:aId type:aType createIfNotExist:aIsCreate];
- _conversationModel = [[EMConversationModel alloc] initWithEMModel:conversation];
- }
-
- return self;
- }
- - (instancetype)initWithCoversationModel:(EMConversationModel *)aConversationModel
- {
- self = [super init];
- if (self) {
- _conversationModel = aConversationModel;
- }
-
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- NSLog(@"conversationId===%@",_conversationModel.emModel.conversationId);
- // Do any additional setup after loading the view.
- self.msgQueue = dispatch_queue_create("emmessage.com", NULL);
- self.msgTimelTag = -1;
- [self _setupChatSubviews];
-
- [[EMClient sharedClient] addMultiDevicesDelegate:self delegateQueue:nil];
- [[EMClient sharedClient].chatManager addDelegate:self delegateQueue:nil];
- [[EMClient sharedClient].groupManager addDelegate:self delegateQueue:nil];
- [[EMClient sharedClient].roomManager addDelegate:self delegateQueue:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleWillPushCallController:) name:CALL_PUSH_VIEWCONTROLLER object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleCleanMessages:) name:CHAT_CLEANMESSAGES object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleGroupSubjectUpdated:) name:GROUP_SUBJECT_UPDATED object:nil];
-
- self.isTyping = NO;
- self.enableTyping = NO;
- if ([EMDemoOptions sharedOptions].isChatTyping && self.conversationModel.emModel.type == EMConversationTypeChat) {
- self.enableTyping = YES;
- }
-
- if (self.conversationModel.emModel.type == EMConversationTypeChatRoom) {
- [self _joinChatroom];
- } else {
- self.isFirstLoadMsg = YES;
- [self tableViewDidTriggerHeaderRefresh];
- }
- [self.view addSubview:self.noteBookShareVC.view];
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapTableViewAction:)];
- [self.tableView addGestureRecognizer:tap];
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
- self.isViewDidAppear = YES;
- [EMConversationHelper markAllAsRead:self.conversationModel];
- self.navigationController.navigationBar.hidden = YES;
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deleteConversationMsg) name:DELETECONVERSATIONMSG object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillHide:) name:UIKeyboardWillHideNotification object:nil];
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
-
- self.isViewDidAppear = NO;
-
- if (self.enableTyping && self.isTyping) {
- [self _sendEndTyping];
- }
- if (self.chatBar.textView.text.length > 0) {
- [self saveUserInfoInDocument:self.chatBar.textView.text];
- }else{
- [self clearUserInfoInDocument];
- }
- [self.chatBar mas_updateConstraints:^(MASConstraintMaker *make) {
- if (@available(iOS 11.0, *)) {
- make.bottom.mas_equalTo(self.view.mas_safeAreaLayoutGuideBottom);
- } else {
- make.bottom.mas_equalTo(self.view.mas_bottom);
- }
- }];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
- [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
- }
- - (void)dealloc
- {
- self.isViewDidAppear = NO;
- [self.chatBar removeFromSuperview];
- [[EMClient sharedClient] removeMultiDevicesDelegate:self];
- [[EMClient sharedClient].chatManager removeDelegate:self];
- [[EMClient sharedClient].groupManager removeDelegate:self];
- [[EMClient sharedClient].roomManager removeDelegate:self];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (BOOL)canBecomeFirstResponder
- {
- return YES;
- }
- #pragma mark - Subviews
- - (void)_setupChatSubviews
- {
- NSLog(@"%@",self.conversationModel.emModel.conversationId);
- [self _setupNavigationBarTitle];
- self.view.backgroundColor = [UIColor whiteColor];
- self.showRefreshHeader = YES;
-
- self.chatBar = [[EMChatBar alloc] init];
- self.chatBar.delegate = self;
-
- [self.view addSubview:self.chatBar];
- [self.chatBar mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.mas_equalTo(self.view);
- make.right.mas_equalTo(self.view);
- if (@available(iOS 11.0, *)) {
- make.bottom.mas_equalTo(self.view.mas_safeAreaLayoutGuideBottom);
- } else {
- make.bottom.mas_equalTo(self.view.mas_bottom);
- }
- make.height.offset(56);
- }];
- if ([self getUserInfoInDocument].length > 0) {
- self.chatBar.textView.text = [self getUserInfoInDocument];
- }
- WS(weakSelf);
- self.chatBar.clickMore = ^(NSInteger index, NSString * _Nonnull title) {
- [weakSelf selectMoreMenu:index title:title];
- };
- [self _setupChatBarMoreViews];
- self.tableView.backgroundColor = kColor_LightGray;
- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- self.tableView.rowHeight = UITableViewAutomaticDimension;
- self.tableView.estimatedRowHeight = 130;
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.titleV.mas_bottom);
- make.left.mas_equalTo(self.view);
- make.right.mas_equalTo(self.view);
- make.bottom.mas_equalTo(self.chatBar.mas_top);
- }];
- }
- -(DrawerView *)drawerView{
- if(!_drawerView){
- _drawerView = [[DrawerView alloc] init];
- }
- return _drawerView;
- }
- - (void)_setupNavigationBarTitle
- {
- [self.view addSubview:self.titleV];
- [self.titleV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.mas_equalTo(self.view);
- make.height.mas_offset(IS_IPHONEX?88:64);
- }];
- [self.titleV addSubview:self.backBtn];
- [self.titleV addSubview:self.tabBtn];
- [self.titleV addSubview:self.titleL];
- [self.titleV addSubview:self.mangerBtn];
-
- [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.mas_equalTo(self.titleV);
- make.size.mas_offset(CGSizeMake(50, 44));
- }];
- [self.tabBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(self.titleV);
- make.left.mas_equalTo(self.backBtn.mas_right);
- make.size.mas_offset(CGSizeMake(35, 44));
- }];
- [self.mangerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.bottom.mas_equalTo(self.titleV);
- make.size.mas_offset(CGSizeMake(50, 44));
- }];
- [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.titleV);
- make.centerY.mas_equalTo(self.backBtn);
- make.height.mas_greaterThanOrEqualTo(10);
- make.width.mas_lessThanOrEqualTo(SCREEN_WIDTH - 160);
- }];
- self.titleL.text = self.conversationModel.name;
- WS(weakSelf);
- [self.backBtn setAction:^{
- weakSelf.hidesBottomBarWhenPushed = NO;
- [weakSelf.navigationController popViewControllerAnimated:YES];
- }];
- [self.tabBtn setAction:^{
- [[UtilsTools getWindow] addSubview:weakSelf.drawerView];
- weakSelf.drawerView.SelectDrawerBlock = ^(NSIndexPath * _Nonnull indexPath) {
- if ([weakSelf.navigationController.viewControllers count] > 1) {
- [weakSelf.navigationController popToRootViewControllerAnimated:NO];
- }
- if (indexPath.section == 0) {
- [[TabBarController sharedTabBarController] setSelectedIndex:indexPath.row];
- }else{
- ///@"站内信", @"通知", @"收藏",@"笔记", @"设置"
- switch (indexPath.row) {
- case 0:
- {
- [[TabBarController sharedTabBarController] setSelectedIndex:2];
- }
- break;
- case 1:
- {
- [[TabBarController sharedTabBarController] setSelectedIndex:2];
- }
- break;
- default:
- {
- [[TabBarController sharedTabBarController] setSelectedIndex:3];
- }
- break;
- }
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [[NSNotificationCenter defaultCenter] postNotificationName:DRAWERPUSHVC object:nil userInfo:@{VCINDEX:@(indexPath.row)}];
- });
- }
- };
- weakSelf.drawerView.frame = CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT);// - kNavigationHeight
- }];
- [self.mangerBtn setAction:^{
- if (weakSelf.chatType == ChatType_SingleChat) {
- ChatMsgPersonInfoVC * vc = [ChatMsgPersonInfoVC initChatMsgPersonInfoVC];
- vc.refreshStatus = ^(BOOL isTop) {
- weakSelf.isTop = isTop;
- };
- vc.listId = weakSelf.listId;
- vc.IsTop = weakSelf.isTop;
- vc.model = weakSelf.sModel;
- [weakSelf.navigationController pushViewController:vc animated:YES];
- }else{
- ChatMsgDetailChatInfoVC *vc = [ChatMsgDetailChatInfoVC initChatMsgDetailChatInfoVC];
- vc.GroupChatImId = weakSelf.toUserId;
- vc.GroupId = weakSelf.GroupId;
- vc.GroupName = weakSelf.conversationModel.name;
- vc.upDataChatBlock = ^(NSString * _Nonnull name) {
- weakSelf.titleL.text = name;
- };
- [weakSelf.navigationController pushViewController:vc animated:YES];
- }
- }];
- }
- - (void)_setupChatBarMoreViews
- {
- //语音
- NSString *path = [self _getAudioOrVideoPath];
- EMChatBarRecordAudioView *recordView = [[EMChatBarRecordAudioView alloc] initWithRecordPath:path];
- recordView.delegate = self;
- self.chatBar.recordAudioView = recordView;
- //表情
- EMChatBarEmoticonView *moreEmoticonView = [[EMChatBarEmoticonView alloc] init];
- moreEmoticonView.delegate = self;
- self.chatBar.moreEmoticonView = moreEmoticonView;
- //更多
- if (self.conversationModel.emModel.type == EMConversationTypeGroupChat) {
- EMMoreFunctionView *moreFunction = [[EMMoreFunctionView alloc]init];
- moreFunction.delegate = self;
- self.chatBar.moreFunctionView = moreFunction;
- }
- }
- - (NSString *)_getAudioOrVideoPath
- {
- NSString *path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
- path = [path stringByAppendingPathComponent:@"EMDemoRecord"];
- if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
- [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
- }
-
- return path;
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [self.dataArray count];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- id obj = [self.dataArray objectAtIndex:indexPath.row];
-
- NSString *cellString = nil;
- if ([obj isKindOfClass:[NSString class]]) {
- cellString = (NSString *)obj;
- } else if ([obj isKindOfClass:[EMMessageModel class]]) {
- EMMessageModel *model = (EMMessageModel *)obj;
- if (model.type == EMMessageTypeExtRecall) {
- cellString = @"您撤回一条消息";
- }
- }
-
- if ([cellString length] > 0) {
- EMMessageTimeCell *cell = (EMMessageTimeCell *)[tableView dequeueReusableCellWithIdentifier:@"EMMessageTimeCell"];
- // Configure the cell...
- if (cell == nil || !cell) {
- cell = [[EMMessageTimeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"EMMessageTimeCell"];
- }
-
- cell.timeLabel.text = cellString;
-
- return cell;
- } else {
- EMMessageModel *model = (EMMessageModel *)obj;
- if ([[model.emModel.ext objectForKey:@"app"] boolValue]) {
- model.type = EMMessageTypeExtApp;
- }
- NSString *identifier = [EMMessageCell cellIdentifierWithDirection:model.direction type:model.type];
- EMMessageCell *cell = (EMMessageCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
-
- // Configure the cell...
- if (cell == nil || !cell) {
- cell = [[EMMessageCell alloc] initWithDirection:model.direction type:model.type];
- cell.delegate = self;
- }
- if (self.chatType == ChatType_SingleChat) {
- if (model.emModel.direction == EMMessageDirectionSend){
- [cell setIconUrl:[AppUserModel sharedAppUserModel].AvatarUrl];
- }else{
- [cell setIconUrl:self.ReceiveIcon];
- }
- }else{
- [self.groupUserInfoArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if ([obj isKindOfClass:[NSDictionary class]]) {
- if ([[obj objectForKey:@"ImId"] integerValue] == [model.emModel.from integerValue]) {
- [cell setIconUrl:[obj objectForKey:@"AvatarUrl"]];
- }
- }
- }];
- }
- cell.model = model;
- return cell;
- }
- }
- #pragma mark - UIScrollViewDelegate
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- {
- [self.view endEditing:YES];
- [self.chatBar clearMoreViewAndSelectedButton];
- }
- #pragma mark - UIImagePickerControllerDelegate
- - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
- {
- NSString *mediaType = info[UIImagePickerControllerMediaType];
- if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]) {
- NSURL *videoURL = info[UIImagePickerControllerMediaURL];
- // we will convert it to mp4 format
- NSURL *mp4 = [self _videoConvert2Mp4:videoURL];
- NSFileManager *fileman = [NSFileManager defaultManager];
- if ([fileman fileExistsAtPath:videoURL.path]) {
- NSError *error = nil;
- [fileman removeItemAtURL:videoURL error:&error];
- if (error) {
- NSLog(@"failed to remove file, error:%@.", error);
- }
- }
- [self _sendVideoAction:mp4];
- } else {
- NSURL *url = info[UIImagePickerControllerReferenceURL];
- if (url == nil) {
- UIImage *orgImage = info[UIImagePickerControllerOriginalImage];
- NSData *data = UIImageJPEGRepresentation(orgImage, 1);
- [self _sendImageDataAction:data];
- } else {
- if ([[UIDevice currentDevice].systemVersion doubleValue] >= 9.0f) {
- PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
- [result enumerateObjectsUsingBlock:^(PHAsset *asset , NSUInteger idx, BOOL *stop){
- if (asset) {
- [[PHImageManager defaultManager] requestImageDataForAsset:asset options:nil resultHandler:^(NSData *data, NSString *uti, UIImageOrientation orientation, NSDictionary *dic){
- if (data != nil) {
- [self _sendImageDataAction:data];
- } else {
- [EMAlertController showErrorAlert:@"图片太大,请选择其他图片"];
- }
- }];
- }
- }];
- } else {
- ALAssetsLibrary *alasset = [[ALAssetsLibrary alloc] init];
- [alasset assetForURL:url resultBlock:^(ALAsset *asset) {
- if (asset) {
- ALAssetRepresentation* assetRepresentation = [asset defaultRepresentation];
- Byte *buffer = (Byte*)malloc((size_t)[assetRepresentation size]);
- NSUInteger bufferSize = [assetRepresentation getBytes:buffer fromOffset:0.0 length:(NSUInteger)[assetRepresentation size] error:nil];
- NSData *fileData = [NSData dataWithBytesNoCopy:buffer length:bufferSize freeWhenDone:YES];
- [self _sendImageDataAction:fileData];
- }
- } failureBlock:NULL];
- }
- }
- }
- [picker dismissViewControllerAnimated:YES completion:nil];
- }
- - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
- {
- [self.imagePicker dismissViewControllerAnimated:YES completion:nil];
- }
- #pragma mark - EMChatBarDelegate
- - (void)_willInputAt:(EMTextView *)aInputView
- {
- do {
- if (self.conversationModel.emModel.type != EMConversationTypeGroupChat) {
- break;
- }
-
- NSString *text = aInputView.text;
- // if (![text hasSuffix:@"@"]) {
- // break;
- // }
-
- EMGroup *group = [EMGroup groupWithId:self.conversationModel.emModel.conversationId];
- if (!group) {
- break;
- }
-
- [self.view endEditing:YES];
- EMAtGroupMembersViewController *controller = [[EMAtGroupMembersViewController alloc] initWithGroup:group];
- [self.navigationController pushViewController:controller animated:YES];
- [controller setSelectedCompletion:^(NSString * _Nonnull aName) {
- NSString *newStr = [NSString stringWithFormat:@"%@%@ ", text, aName];
- aInputView.text = newStr;
- aInputView.selectedRange = NSMakeRange(newStr.length, 0);
- [aInputView becomeFirstResponder];
- }];
-
- } while (0);
- }
- - (BOOL)inputView:(EMTextView *)aInputView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
- {
- self.isWillInputAt = NO;
- if ([text isEqualToString:@"\n"]) {
- [self _sendTextAction:aInputView.text ext:nil];
- return NO;
- } else if ([text isEqualToString:@"@"]) {
- self.isWillInputAt = YES;
- } else if ([text length] == 0) {
-
- }
- return YES;
- }
- - (void)inputViewDidChange:(EMTextView *)aInputView
- {
- if (self.isWillInputAt && self.conversationModel.emModel.type == EMConversationTypeGroupChat) {
- NSString *text = aInputView.text;
- if ([text hasSuffix:@"@"]) {
- self.isWillInputAt = NO;
- [self _willInputAt:aInputView];
- }
- }
-
- if (self.enableTyping) {
- if (!self.isTyping) {
- self.isTyping = YES;
- [self _sendBeginTyping];
- }
- }
- }
- - (void)chatBarClickMoreType:(SmartBarType)type
- {
- WS(weakSelf);
- switch (type) {
- case SmartBarPhoto:
- {
- [self chatBarDidPhotoAction];
- }
- break;
- case SmartBarCamera:
- {
- [self chatBarDidCameraAction];
- }
- break;
- case SmartBarNotes:
- {
- [[FWZGetNoteBookTool sharedTool] openNoteBookListChooseNoteBookBlock:^(NSMutableArray<MyNoteBookSubModel *> * _Nonnull noteArr) {
- NSLog(@"SmartBarNotes %@",noteArr);
- for (MyNoteBookSubModel * model in noteArr) {
- switch (model.AttributeValue) {
- case 1:
- {
- [weakSelf _sendTextAction:@"[笔记]" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_NoteBook),
- @"app_title":model.Title,
- @"app_id":@(model.MiddleId),
- @"app_content":@"来自-笔记",
- @"app_sourceUserId":@(model.SourceUserId),
- @"app_min_url":@"",
- @"app_url":@""
- }];
- }
- break;
- default:
- {
- [weakSelf _sendTextAction:@"[笔记]" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_NoteFile),
- @"app_title":model.FolderName,
- @"app_id":@(model.Id),
- @"app_sourceUserId":@(model.SourceUserId),
- @"app_content":@"来自-笔记",
- @"app_min_url":@"",
- @"app_url":@""
- }];
- }
- break;
- }
- }
- }];
- }
- break;
- case SmartBarCollection:
- {
- [[FWZGetNoteBookTool sharedTool] openCollectListChooseCollectBlock:^(NSMutableArray<MyFavoriteSubModel *> * _Nonnull collectArr) {
- NSLog(@"SmartBarCollection %@",collectArr);
- for (MyFavoriteSubModel * model in collectArr) {
- [weakSelf sendExtWithCollectModel:model];
- }
- }];
- }
- break;
- case SmartBarFile:
- {
- [self chatBarDidFileAction];
- }
- break;
- default:
- break;
- }
- }
- - (void)sendExtWithCollectModel:(MyFavoriteSubModel *)model
- {
- NSString * text = @"";
- switch (model.CollectionType) {
- case CollectModel_NewTopic:
- text = @"[话题]";
- break;
- case CollectModel_Toipc:
- text = @"[话题]";
- break;
- case CollectModel_Notice:
- text = @"[通知]";
- break;
- case CollectModel_NoteBook:
- text = @"[笔记]";
- break;
- case CollectModel_CollectFile:
- text = @"[文件夹]";
- break;
- case CollectModel_NoteFile:
- text = @"[文件夹]";
- break;
- case CollectModel_file:
- text = @"[文件]";
- break;
- case CollectModel_Image:
- text = @"[图片]";
- break;
- case CollectModel_meetMian:
- text = @"[会议纪要]";
- break;
- default:
- text = @"[话题]";
- break;
- }
- switch (model.AttributeValue) {
- case 1:
- {
- [self _sendTextAction:text ext:@{@"app":@(YES),
- @"app_type":@(model.CollectionType),
- @"app_title":model.Title,
- @"app_content":@"来自-收藏",
- @"app_sourceUserId":@(model.SourceUserId),
- @"app_id":@(model.CollectionDataId),
- @"app_min_url":model.Data.MinFile,
- @"app_url":model.Data.File
- }];
- }
- break;
- default:
- {
- [self _sendTextAction:text ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_CollectFile),
- @"app_title":model.FolderName,
- @"app_content":@"来自-收藏",
- @"app_sourceUserId":@(model.SourceUserId),
- @"app_id":@(model.Id),
- @"app_min_url":model.Data.MinFile,
- @"app_url":model.Data.File
- }];
- }
- break;
- }
- }
- - (void)chatBarDidPhotoAction
- {
- WS(weakSelf);
- [self.view endEditing:YES];
- TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:9 delegate:nil];
- [imagePickerVc setNavLeftBarButtonSettingBlock:^(UIButton *leftButton){
- leftButton.hidden = YES;
- }];
- imagePickerVc.showSelectBtn = NO;
- imagePickerVc.allowCrop = YES;
- imagePickerVc.cropRect = CGRectMake(0, (SCREEN_HEIGHT - SCREEN_WIDTH) * 0.5, SCREEN_WIDTH, SCREEN_WIDTH);
- imagePickerVc.allowTakePicture = NO;
- imagePickerVc.allowTakeVideo = NO;
- imagePickerVc.allowPickingOriginalPhoto = NO;
- imagePickerVc.allowPickingGif = NO;
- [imagePickerVc setIsStatusBarDefault:YES];
- [imagePickerVc setNaviTitleColor:[UIColor blackColor]];
- [imagePickerVc setBarItemTextColor:[UIColor blackColor]];
- [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
- // if (assets.count > 0) {
- // for (PHAsset *asset in assets) {
- // PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
- // options.version = PHImageRequestOptionsVersionCurrent;
- // options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
- // PHImageManager *manager = [PHImageManager defaultManager];
- // [manager requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
- // AVURLAsset *urlAsset = (AVURLAsset *)asset;
- // NSURL *url = urlAsset.URL;
- // [weakSelf _sendVideoAction:url];
- // }];
- // }
- // }
- if (photos.count > 0) {
- for (UIImage * image in photos) {
- NSData *data = UIImageJPEGRepresentation(image, 1);
- [weakSelf _sendImageDataAction:data];
- }
- }
- }];
- [self presentViewController:imagePickerVc animated:YES completion:nil];
- }
- - (void)chatBarDidCameraAction
- {
- [self.view endEditing:YES];
-
- //#if TARGET_IPHONE_SIMULATOR
- // [EMAlertController showErrorAlert:@"模拟器不支持照相机"];
- //#elif TARGET_OS_IPHONE
- self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
- self.imagePicker.mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie];
- [self presentViewController:self.imagePicker animated:YES completion:nil];
- //#endif
- }
- - (void)chatBarDidFileAction
- {
- WS(weakSelf);
- [[FWZFileGetTool sharedTool] openFileWithCrop:YES showImgBlock:^(NSString * _Nonnull fileUrlStr) {
-
- } choosFileBlock:^(NSData * _Nonnull fileData, NSString * _Nonnull fileName) {
- // EMFileMessageBody * body = [[EMFileMessageBody alloc] initWithData:fileData displayName:fileName];
- // [weakSelf _sendMessageWithBody:body ext:nil isUpload:YES];
- SHOWLOADING
- [[HttpManager sharedHttpManager] HeaderUploadFileUrl:Host(Modify_UserImages_Post) parameters:@{} fileData:fileData fileKey:@"file" fileName:fileName mimeType:@"multipart/form-data" success:^(id _Nonnull responseObject) {
- REMOVESHOW
- NSDictionary * dict = responseObject[0];
- if ([dict[@"FileType"] isEqualToString:@"image"]) {
- [weakSelf _sendImageDataAction:fileData];
- }else{
- [weakSelf _sendTextAction:@"[文件]" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_file),
- @"app_title":fileName,
- @"app_content":@"",
- @"app_sourceUserId":@([AppUserModel sharedAppUserModel].Id),
- @"app_id":@([dict[@"FileId"] integerValue]),
- @"app_min_url":dict[@"MinAbsolutePath"],
- @"app_url":dict[@"AbsolutePath"]
- }];
- }
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- }];
- }];
- }
- - (void)chatBarDidLocationAction
- {
- EMLocationViewController *controller = [[EMLocationViewController alloc] init];
- [controller setSendCompletion:^(CLLocationCoordinate2D aCoordinate, NSString * _Nonnull aAddress) {
- [self _sendLocationAction:aCoordinate address:aAddress];
- }];
- UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
- [self.navigationController presentViewController:navController animated:YES completion:nil];
- }
- - (void)chatBarDidCallAction
- {
- self.alertController = [UIAlertController alertControllerWithTitle:@"实时通话类型" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
-
- __weak typeof(self) weakself = self;
- if (self.conversationModel.emModel.type == EMConversationTypeChat) {
- [self.alertController addAction:[UIAlertAction actionWithTitle:@"语音通话" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [weakself.chatBar clearMoreViewAndSelectedButton];
- [[NSNotificationCenter defaultCenter] postNotificationName:CALL_MAKE1V1 object:@{CALL_CHATTER:weakself.conversationModel.emModel.conversationId, CALL_TYPE:@(EMCallTypeVoice)}];
- }]];
- [self.alertController addAction:[UIAlertAction actionWithTitle:@"视频通话" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [weakself.chatBar clearMoreViewAndSelectedButton];
- [[NSNotificationCenter defaultCenter] postNotificationName:CALL_MAKE1V1 object:@{CALL_CHATTER:weakself.conversationModel.emModel.conversationId, CALL_TYPE:@(EMCallTypeVideo)}];
- }]];
- } else {
- [self.alertController addAction:[UIAlertAction actionWithTitle:@"会议模式" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [weakself.chatBar clearMoreViewAndSelectedButton];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:CALL_MAKECONFERENCE object:@{CALL_TYPE:@(EMConferenceTypeLargeCommunication), CALL_MODEL:weakself.conversationModel, NOTIF_NAVICONTROLLER:self.navigationController}];
- }]];
- [self.alertController addAction:[UIAlertAction actionWithTitle:@"互动模式" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [weakself.chatBar clearMoreViewAndSelectedButton];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:CALL_MAKECONFERENCE object:@{CALL_TYPE:@(EMConferenceTypeLive), CALL_MODEL:weakself.conversationModel, NOTIF_NAVICONTROLLER:self.navigationController}];
- }]];
- }
-
- [self.alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- }]];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"didAlert" object:@{@"alert":self.alertController}];
- [self presentViewController:self.alertController animated:YES completion:nil];
- }
- //阅读回执跳转
- - (void)chatBarMoreFunctionReadReceipt
- {
- self.readReceiptControl = [[EMReadReceiptMsgViewController alloc]init];
- self.readReceiptControl.delegate = self;
- self.readReceiptControl.modalPresentationStyle = 0;
- //[self.navigationController pushViewController:readReceipt animated:NO];
- [self presentViewController:self.readReceiptControl animated:NO completion:nil];
- }
- //阅读回执发送信息
- - (void)sendReadReceiptMsg:(NSString *)msg
- {
- NSString *str = msg;
- NSLog(@"\n%@",str);
- if (self.conversationModel.emModel.type == EMConversationTypeGroupChat) {
- [[EMClient sharedClient].groupManager getGroupSpecificationFromServerWithId:self.conversationModel.emModel.conversationId completion:^(EMGroup *aGroup, EMError *aError) {
- NSLog(@"\n -------- sendError: %@",aError);
- if (!aError) {
- self.group = aGroup;
- //是群主才可以发送阅读回执信息
- [self _sendTextAction:str ext:@{MSG_EXT_READ_RECEIPT:@"receipt"}];
- } else {
- [EMAlertController showErrorAlert:@"获取群组失败"];
- }
- }];
- }else {
- [self _sendTextAction:str ext:nil];
- }
- }
- - (void)chatBarDidShowMoreViewAction:(BOOL)isKeyBord
- {
- WS(weakSelf);
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.bottom.mas_equalTo(weakSelf.chatBar.mas_top);
- }];
- [weakSelf performSelector:@selector(_scrollToBottomRow) withObject:nil afterDelay:0.1];
- });
- });
- }
- #pragma mark - EMChatBarRecordAudioViewDelegate
- - (void)chatBarRecordAudioViewStartRecord
- {
-
- }
- - (void)chatBarRecordAudioViewStopRecord:(NSString *)aPath
- timeLength:(NSInteger)aTimeLength
- {
- EMVoiceMessageBody *body = [[EMVoiceMessageBody alloc] initWithLocalPath:aPath displayName:@"audio"];
- body.duration = (int)aTimeLength;
- if(body.duration < 1){
- [self showHint:@"按键时间太短."];
- return;
- }
- [self _sendMessageWithBody:body ext:nil isUpload:YES];
- }
- - (void)chatBarRecordAudioViewCancelRecord
- {
-
- }
- #pragma mark - EMChatBarEmoticonViewDelegate
- - (void)didSelectedEmoticonModel:(EMEmoticonModel *)aModel
- {
- if (aModel.type == EMEmotionTypeEmoji) {
- [self.chatBar inputViewAppendText:aModel.name];
- } if (aModel.type == EMEmotionTypeGif) {
- NSDictionary *ext = @{MSG_EXT_GIF:@(YES), MSG_EXT_GIF_ID:aModel.eId};
- [self _sendTextAction:aModel.name ext:ext];
- }
- }
- - (void)didChatBarEmoticonViewSendAction
- {
- [self _sendTextAction:self.chatBar.textView.text ext:nil];
- }
- #pragma mark - EMMessageCellDelegate
- //阅读回执详情
- - (void)messageReadReceiptDetil:(EMMessageCell *)aCell
- {
- self.readReceiptControl = [[EMReadReceiptMsgViewController alloc] initWithMessageCell:aCell groupId:self.conversationModel.emModel.conversationId];
- self.readReceiptControl.modalPresentationStyle = 0;
- //[self.navigationController pushViewController:readReceiptControl animated:NO];
- [self presentViewController:self.readReceiptControl animated:NO completion:nil];
-
- }
- - (void)messageCellDidSelected:(EMMessageCell *)aCell
- {
- if (aCell.model.type == EMMessageTypeImage) {
- [self _imageMessageCellDidSelected:aCell];
- } else if (aCell.model.type == EMMessageTypeLocation) {
- [self _locationMessageCellDidSelected:aCell];
- } else if (aCell.model.type == EMMessageTypeVoice) {
- [self _audioMessageCellDidSelected:aCell];
- } else if (aCell.model.type == EMMessageTypeVideo) {
- [self _videoMessageCellDidSelected:aCell];
- } else if (aCell.model.type == EMMessageTypeFile) {
- [self _fileMessageCellDidSelected:aCell];
- } else if (aCell.model.type == EMMessageTypeExtCall) {
- [self _callMessageCellDidSelected:aCell];
- } else if (aCell.model.type == EMMessageTypeExtApp) {
- [self appPushWithDictionary:aCell.model.emModel.ext];
- } else if (aCell.model.type == EMMessageTypeText) {
-
- }
- }
- - (void)messageClickUserIcon:(EMMessageCell *)aCell
- {
- WS(weakSelf);
- EMMessage * eModel = (EMMessage *)aCell.model.emModel;
- if (self.chatType == ChatType_SingleChat) {
- if (eModel.direction == EMMessageDirectionSend){
- self.UserId = [AppUserModel sharedAppUserModel].Id;
- }else{
- self.UserId = self.toUserId;
- }
- }else{
- [self.groupUserInfoArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if ([obj isKindOfClass:[NSDictionary class]]) {
- if ([[obj objectForKey:@"ImId"] integerValue] == [eModel.from integerValue]) {
- weakSelf.UserId = [[obj objectForKey:@"UserId"] integerValue];
- }
- }
- }];
- }
- MailListDetailVC * vc = [MailListDetailVC initMailListDetailVC];
- vc.indexId = self.UserId;
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)appPushWithDictionary:(NSDictionary *)dict
- {
- WS(weakSelf);
- CollectModelType type = [[dict objectForKey:@"app_type"] intValue];
- NSInteger sourceUserId = [[dict objectForKey:@"app_sourceUserId"] integerValue];
- NSInteger Id = [[dict objectForKey:@"app_id"] integerValue];
- NSString * title = [dict objectForKey:@"app_title"];
- NSString * url = [dict objectForKey:@"app_url"];
- switch (type) {
- case CollectModel_Group:
- {
- TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC];
- vc.GroupId = Id;
- vc.titleStr = title;
- [self.navigationController pushViewController:vc animated:YES];
- }break;
- case CollectModel_file:{
- DownFileViewController * vc = [[DownFileViewController alloc] init];
- FlowAttachmentsModel * model = [[FlowAttachmentsModel alloc] init];
- model.Title = title;
- model.SoureId = Id;
- model.Url = url;
- model.MinUrl = dict[@"app_min_url"];
- vc.model = model;
- [self.navigationController pushViewController:vc animated:YES];
- }break;
- case CollectModel_Image:{
- DownFileViewController * vc = [[DownFileViewController alloc] init];
- FlowAttachmentsModel * model = [[FlowAttachmentsModel alloc] init];
- model.Title = title;
- model.SoureId = Id;
- model.Url = url;
- model.MinUrl = dict[@"app_min_url"];
- vc.model = model;
- [self.navigationController pushViewController:vc animated:YES];
- }break;
- case CollectModel_Aritle:{
- SHOWLOADING
- [[HttpManager sharedHttpManager] GETWithUrl:[NSString stringWithFormat:@"%@%ld",Article_Detail_Get,(long)Id] parameters:@{} success:^(id _Nonnull responseObject) {
- REMOVESHOW;
- Item *itemModel = [[Item alloc]initWithDictionary:responseObject error:nil];
- HomeDetailController *homeDetail = [[HomeDetailController alloc] init];
- [homeDetail loadCurrentModel:itemModel];
- [weakSelf.navigationController pushViewController:homeDetail animated:YES];
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }break;
- case CollectModel_Text:{
- SHOWLOADING
- [[HttpManager sharedHttpManager] GETWithUrl:[NSString stringWithFormat:@"%@%ld",Article_Detail_Get,(long)Id] parameters:@{} success:^(id _Nonnull responseObject) {
- REMOVESHOW;
- Item *itemModel = [[Item alloc]initWithDictionary:responseObject error:nil];
- HomeDetailController *homeDetail = [[HomeDetailController alloc] init];
- [homeDetail loadCurrentModel:itemModel];
- [weakSelf.navigationController pushViewController:homeDetail animated:YES];
- } failure:^(NSError * _Nonnull error) {
- SHOWERROR([ZYCTool handerResultData:error]);
- }];
- }break;
- case CollectModel_Notice:{
- MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
- vc.type = CollectModel_Notice;
- vc.Id = Id;
- [self.navigationController pushViewController:vc animated:YES];
- }break;
- case CollectModel_Toipc:{
- MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
- vc.type = CollectModel_Toipc;
- vc.Id = Id;
- [self.navigationController pushViewController:vc animated:YES];
- }break;
- case CollectModel_NewTopic:{
- MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
- vc.type = CollectModel_NewTopic;
- vc.Id = Id;
- [self.navigationController pushViewController:vc animated:YES];
- }break;
- case CollectModel_NoteBook:{
- MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
- vc.type = CollectModel_NoteBook;
- vc.Id = Id;
- [self.navigationController pushViewController:vc animated:YES];
- }break;
- case CollectModel_Collect:{
-
- }break;
- case CollectModel_CollectFile:{
- if (sourceUserId == [AppUserModel sharedAppUserModel].Id || sourceUserId == 0) {
- MyFavoriteVC *vc = [MyFavoriteVC initMyFavoriteVC];
- vc.listType = Id == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
- vc.FolderId = Id;
- vc.myTitle = title;
- [self.navigationController pushViewController:vc animated:YES];
- }else{
- OtherFavoriteVC *vc = [OtherFavoriteVC initOtherFavoriteVC];
- vc.listType = Id == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
- vc.FolderId = Id;
- vc.myTitle = title;
- vc.VisitUserId = sourceUserId;
- [self.navigationController pushViewController:vc animated:YES];
- }
- }break;
- case CollectModel_NoteFile:{
- if (sourceUserId == [AppUserModel sharedAppUserModel].Id || sourceUserId == 0) {
- NoteBookVC *vc = [NoteBookVC initNoteBookVC];
- vc.listType = Id == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
- vc.FolderId = Id;
- vc.myTitle = title;
- vc.VisitUserId = 0;
- [self.navigationController pushViewController:vc animated:YES];
- }else{
- OtherNoteBookVC *vc = [OtherNoteBookVC initOtherNoteBookVC];
- vc.listType = Id == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
- vc.FolderId = Id;
- vc.myTitle = title;
- vc.VisitUserId = sourceUserId;
- [self.navigationController pushViewController:vc animated:YES];
- }
- }break;
- case CollectModel_InterMail:{
- MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
- vc.type = CollectModel_InterMail;
- vc.Id = Id;
- [self.navigationController pushViewController:vc animated:YES];
- }break;
- case CollectModel_meetDetail:{
- WorkFlowDetailsController *vc = [[WorkFlowDetailsController alloc] initWithId:Id];
- [self.navigationController pushViewController:vc animated:YES];
- }break;
- case CollectModel_work:{
- MyApprovalPageDetail * vc = [[MyApprovalPageDetail alloc]init];
- vc.pageType = Type_ONEC;
- vc.indexId = Id;
- vc.title = title;
- vc.TodoId = Id;
- [self.navigationController pushViewController:vc animated:YES];
- }break;
- case CollectModel_meetMian:{
- MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
- vc.type = CollectModel_meetMian;
- vc.Id = Id;
- [self.navigationController pushViewController:vc animated:YES];
- }break;
- default:
- break;
- }
- }
- - (void)_imageMessageCellDidSelected:(EMMessageCell *)aCell
- {
- __weak typeof(self) weakself = self;
- void (^downloadThumbBlock)(EMMessageModel *aModel) = ^(EMMessageModel *aModel) {
- [weakself showHint:@"获取缩略图..."];
- [[EMClient sharedClient].chatManager downloadMessageThumbnail:aModel.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
- if (!error) {
- [weakself.tableView reloadData];
- }
- }];
- };
-
- EMImageMessageBody *body = (EMImageMessageBody*)aCell.model.emModel.body;
- BOOL isCustomDownload = !([EMClient sharedClient].options.isAutoTransferMessageAttachments);
- if (body.thumbnailDownloadStatus == EMDownloadStatusFailed) {
- if (isCustomDownload) {
- [self _showCustomTransferFileAlertView];
- } else {
- downloadThumbBlock(aCell.model);
- }
-
- return;
- }
-
- BOOL isAutoDownloadThumbnail = [EMClient sharedClient].options.isAutoDownloadThumbnail;
- if (body.thumbnailDownloadStatus == EMDownloadStatusPending && !isAutoDownloadThumbnail) {
- downloadThumbBlock(aCell.model);
- return;
- }
-
- if (body.downloadStatus == EMDownloadStatusSucceed) {
- UIImage *image = [UIImage imageWithContentsOfFile:body.localPath];
- if (image) {
- [[EMImageBrowser sharedBrowser] showImages:@[image] fromController:self];
- return;
- }
- }
-
- if (isCustomDownload) {
- [self _showCustomTransferFileAlertView];
- return;
- }
-
- [self showHudInView:self.view hint:@"下载原图..."];
- [[EMClient sharedClient].chatManager downloadMessageAttachment:aCell.model.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
- [weakself hideHud];
- if (error) {
- [EMAlertController showErrorAlert:@"下载原图失败"];
- } else {
- if (message.direction == EMMessageDirectionReceive && !message.isReadAcked) {
- [[EMClient sharedClient].chatManager sendMessageReadAck:message.messageId toUser:message.conversationId completion:nil];
- }
-
- NSString *localPath = [(EMImageMessageBody *)message.body localPath];
- UIImage *image = [UIImage imageWithContentsOfFile:localPath];
- if (image) {
- [[EMImageBrowser sharedBrowser] showImages:@[image] fromController:self];
- } else {
- [EMAlertController showErrorAlert:@"获取原图失败"];
- }
- }
- }];
- }
- - (void)_locationMessageCellDidSelected:(EMMessageCell *)aCell
- {
- EMLocationMessageBody *body = (EMLocationMessageBody *)aCell.model.emModel.body;
- EMLocationViewController *controller = [[EMLocationViewController alloc] initWithLocation:CLLocationCoordinate2DMake(body.latitude, body.longitude)];
- UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
- [self.navigationController presentViewController:navController animated:YES completion:nil];
- }
- - (void)_audioMessageCellDidSelected:(EMMessageCell *)aCell
- {
- if (aCell.model.isPlaying) {
- [[EMAudioPlayerHelper sharedHelper] stopPlayer];
- aCell.model.isPlaying = NO;
- [self.tableView reloadData];
- return;
- }
-
- EMVoiceMessageBody *body = (EMVoiceMessageBody*)aCell.model.emModel.body;
- if (body.downloadStatus == EMDownloadStatusDownloading) {
- [EMAlertController showInfoAlert:@"正在下载语音,稍后点击"];
- return;
- }
-
- __weak typeof(self) weakself = self;
- void (^playBlock)(EMMessageModel *aModel) = ^(EMMessageModel *aModel) {
- id model = [EMAudioPlayerHelper sharedHelper].model;
- if (model && [model isKindOfClass:[EMMessageModel class]]) {
- EMMessageModel *oldModel = (EMMessageModel *)model;
- if (oldModel.isPlaying) {
- oldModel.isPlaying = NO;
- }
- }
-
- if (!aModel.emModel.isReadAcked) {
- [[EMClient sharedClient].chatManager sendMessageReadAck:aModel.emModel.messageId toUser:aModel.emModel.conversationId completion:nil];
- }
-
- aModel.isPlaying = YES;
- if (!aModel.emModel.isRead) {
- aModel.emModel.isRead = YES;
- }
- [weakself.tableView reloadData];
-
- [[EMAudioPlayerHelper sharedHelper] startPlayerWithPath:body.localPath model:aModel AVAudioSessionCategory:AVAudioSessionCategoryPlayback completion:^(NSError * _Nonnull error) {
- aModel.isPlaying = NO;
- [weakself.tableView reloadData];
- }];
- };
-
- if (body.downloadStatus == EMDownloadStatusSucceed) {
- playBlock(aCell.model);
- return;
- }
-
- if (![EMClient sharedClient].options.isAutoTransferMessageAttachments) {
- [self _showCustomTransferFileAlertView];
- return;
- }
-
- [self showHudInView:self.view hint:@"下载语音..."];
- [[EMClient sharedClient].chatManager downloadMessageAttachment:aCell.model.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
- [weakself hideHud];
- if (error) {
- [EMAlertController showErrorAlert:@"下载语音失败"];
- } else {
- playBlock(aCell.model);
- }
- }];
- }
- - (void)_videoMessageCellDidSelected:(EMMessageCell *)aCell
- {
- EMVideoMessageBody *body = (EMVideoMessageBody*)aCell.model.emModel.body;
- NSFileManager *fileManager = [NSFileManager defaultManager];
- BOOL isCustomDownload = !([EMClient sharedClient].options.isAutoTransferMessageAttachments);
- if (body.thumbnailDownloadStatus == EMDownloadStatusFailed || ![fileManager fileExistsAtPath:body.thumbnailLocalPath]) {
- [self showHint:@"下载缩略图"];
- if (!isCustomDownload) {
- [[EMClient sharedClient].chatManager downloadMessageThumbnail:aCell.model.emModel progress:nil completion:nil];
- }
- }
-
- if (body.downloadStatus == EMDownloadStatusDownloading) {
- [EMAlertController showInfoAlert:@"正在下载视频,稍后点击"];
- return;
- }
-
- void (^playBlock)(NSString *aPath) = ^(NSString *aPathe) {
- NSURL *videoURL = [NSURL fileURLWithPath:aPathe];
- AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
- playerViewController.player = [AVPlayer playerWithURL:videoURL];
- playerViewController.videoGravity = AVLayerVideoGravityResizeAspect;
- playerViewController.showsPlaybackControls = YES;
- [self presentViewController:playerViewController animated:YES completion:^{
- [playerViewController.player play];
- }];
- };
-
- if (body.downloadStatus == EMDownloadStatusSuccessed && [fileManager fileExistsAtPath:body.localPath]) {
- playBlock(body.localPath);
- return;
- }
-
- if (isCustomDownload) {
- [self _showCustomTransferFileAlertView];
- } else {
- [self showHudInView:self.view hint:@"下载视频..."];
- __weak typeof(self) weakself = self;
- [[EMClient sharedClient].chatManager downloadMessageAttachment:aCell.model.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
- [weakself hideHud];
- if (error) {
- [EMAlertController showErrorAlert:@"下载视频失败"];
- } else {
- if (!message.isReadAcked) {
- [[EMClient sharedClient].chatManager sendMessageReadAck:message.messageId toUser:message.conversationId completion:nil];
- }
- playBlock([(EMVideoMessageBody*)message.body localPath]);
- }
- }];
- }
- }
- - (void)_fileMessageCellDidSelected:(EMMessageCell *)aCell
- {
- WS(weakSelf);
- [[EMClient sharedClient].chatManager downloadMessageAttachment:aCell.model.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
- [weakSelf hideHud];
- if (error) {
- [EMAlertController showErrorAlert:@"下载文件失败"];
- } else {
- if (message.direction == EMMessageDirectionReceive && !message.isReadAcked) {
- [[EMClient sharedClient].chatManager sendMessageReadAck:message.messageId toUser:message.conversationId completion:nil];
- }
- NSString *remotePath = [(EMImageMessageBody *)message.body remotePath];
- NSString *displayName = [(EMImageMessageBody *)message.body displayName];
- dispatch_async(dispatch_get_main_queue(), ^{
- EMChatFileShowVC * vc = [EMChatFileShowVC initEMChatFileShowVC];
- vc.fileUrl = remotePath;
- vc.titleStr = displayName;
- [weakSelf.navigationController pushViewController:vc animated:YES];
- });
- }
- }];
- }
- - (void)_callMessageCellDidSelected:(EMMessageCell *)aCell
- {
- [[NSNotificationCenter defaultCenter] postNotificationName:CALL_SELECTCONFERENCECELL object:aCell.model.emModel];
- }
- - (void)messageCellDidLongPress:(EMMessageCell *)aCell
- {
- self.menuIndexPath = [self.tableView indexPathForCell:aCell];
- [self _showMenuViewController:aCell model:aCell.model];
- }
- - (void)messageCellDidResend:(EMMessageModel *)aModel
- {
- if (aModel.emModel.status != EMMessageStatusFailed && aModel.emModel.status != EMMessageStatusPending) {
- return;
- }
-
- __weak typeof(self) weakself = self;
- [[[EMClient sharedClient] chatManager] resendMessage:aModel.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
- [weakself.tableView reloadData];
- }];
-
- [self.tableView reloadData];
- }
- #pragma mark - EMMultiDevicesDelegate
- - (void)multiDevicesGroupEventDidReceive:(EMMultiDevicesEvent)aEvent
- groupId:(NSString *)aGroupId
- ext:(id)aExt
- {
- if (aEvent == EMMultiDevicesEventGroupDestroy || aEvent == EMMultiDevicesEventGroupLeave) {
- if ([self.conversationModel.emModel.conversationId isEqualToString:aGroupId]) {
- [self.navigationController popToViewController:self animated:YES];
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- }
- #pragma mark - EMChatManagerDelegate
- - (BOOL)_isNeedSendReadAckForMessage:(EMMessage *)aMessage
- isMarkRead:(BOOL)aIsMarkRead
- {
- if (!self.isViewDidAppear || aMessage.direction == EMMessageDirectionSend || aMessage.isReadAcked || aMessage.chatType != EMChatTypeChat) {
- return NO;
- }
-
- EMMessageBody *body = aMessage.body;
- if (!aIsMarkRead && (body.type == EMMessageBodyTypeVideo || body.type == EMMessageBodyTypeVoice || body.type == EMMessageBodyTypeImage)) {
- return NO;
- }
-
- return YES;
- }
- - (void)messagesDidReceive:(NSArray *)aMessages
- {
- __weak typeof(self) weakself = self;
- dispatch_async(self.msgQueue, ^{
- NSString *conId = weakself.conversationModel.emModel.conversationId;
- NSMutableArray *msgArray = [[NSMutableArray alloc] init];
- for (int i = 0; i < [aMessages count]; i++) {
- EMMessage *msg = aMessages[i];
- if (![msg.conversationId isEqualToString:conId]) {
- continue;
- }
- if (msg.isNeedGroupAck && !msg.isReadAcked) {
- [[EMClient sharedClient].chatManager sendGroupMessageReadAck:msg.messageId toGroup:msg.conversationId content:@"123" completion:^(EMError *error) {
- if (error) {
- NSLog(@"\n ------ error %@",error.errorDescription);
- }
- }];
- }
- if ([weakself _isNeedSendReadAckForMessage:msg isMarkRead:NO]) {
- [[EMClient sharedClient].chatManager sendMessageReadAck:msg.messageId toUser:msg.conversationId completion:nil];
- }
- [weakself.conversationModel.emModel markMessageAsReadWithId:msg.messageId error:nil];
- [msgArray addObject:msg];
- }
-
- NSArray *formated = [weakself _formatMessages:msgArray];
- [weakself.dataArray addObjectsFromArray:formated];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakself.tableView reloadData];
- [weakself _scrollToBottomRow];
- });
- });
- }
- - (void)messagesDidRecall:(NSArray *)aMessages {
- __block NSMutableArray *sameObject = [NSMutableArray array];
- [aMessages enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- EMMessage *msg = (EMMessage *)obj;
- [self.dataArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if ([obj isKindOfClass:[EMMessageModel class]]) {
- EMMessageModel *model = (EMMessageModel *)obj;
- if ([model.emModel.messageId isEqualToString:msg.messageId]) {
- // 如果上一行是时间,且下一行也是时间
- if (idx - 1 >= 0) {
- id nextMessage = nil;
- id prevMessage = [self.dataArray objectAtIndex:(idx - 1)];
- if (idx + 1 < [self.dataArray count]) {
- nextMessage = [self.dataArray objectAtIndex:(idx + 1)];
- }
- if ((!nextMessage
- || [nextMessage isKindOfClass:[NSString class]])
- && [prevMessage isKindOfClass:[NSString class]]) {
- [sameObject addObject:prevMessage];
- }
- }
-
- [sameObject addObject:model];
- *stop = YES;
- }
- }
- }];
- }];
-
- if (sameObject.count > 0) {
- for (id obj in sameObject) {
- [self.dataArray removeObject:obj];
- }
-
- [self.tableView reloadData];
- }
- }
- //为了从home会话列表切进来触发 群组阅读回执 和 消息已读回执
- - (void)sendDidReadReceipt
- {
- __weak typeof(self) weakself = self;
- NSString *conId = weakself.conversationModel.emModel.conversationId;
- void (^block)(NSArray *aMessages, EMError *aError) = ^(NSArray *aMessages, EMError *aError) {
- NSLog(@"\n-------unread: %d messageCount: %lu msgid: %@",self.conversationModel.emModel.unreadMessagesCount,(unsigned long)[aMessages count],self.moreMsgId);
- if (!aError && [aMessages count]) {
- for (int i = 0; i < [aMessages count]; i++) {
- EMMessage *msg = aMessages[i];
- if (![msg.conversationId isEqualToString:conId]) {
- continue;
- }
- if (msg.isNeedGroupAck && !msg.isReadAcked) {
- [[EMClient sharedClient].chatManager sendGroupMessageReadAck:msg.messageId toGroup:msg.conversationId content:@"123" completion:^(EMError *error) {
- if (error) {
- NSLog(@"\n ------ error %@",error.errorDescription);
- }
- }];
- }
- if ([weakself _isNeedSendReadAckForMessage:msg isMarkRead:NO] && (weakself.conversationModel.emModel.type == EMConversationTypeChat)) {
- [[EMClient sharedClient].chatManager sendMessageReadAck:msg.messageId toUser:msg.conversationId completion:nil];
- [weakself.conversationModel.emModel markMessageAsReadWithId:msg.messageId error:nil];
- }
- }
- }
- };
- [self.conversationModel.emModel loadMessagesStartFromId:self.moreMsgId count:self.conversationModel.emModel.unreadMessagesCount searchDirection:EMMessageSearchDirectionUp completion:block];
-
- }
- //收到群消息已读回执
- - (void)groupMessageDidRead:(EMMessage *)aMessage groupAcks:(NSArray *)aGroupAcks
- {
- EMMessageModel *msgModel;
- EMGroupMessageAck *msgAck = aGroupAcks[0];
- for (int i=0; i<[self.dataArray count]; i++) {
- if([self.dataArray[i] isKindOfClass:[EMMessageModel class]]){
- msgModel = (EMMessageModel *)self.dataArray[i];
- }else{
- continue;
- }
- if([msgModel.emModel.messageId isEqualToString:msgAck.messageId]){
- msgModel.readReceiptCount = [NSString stringWithFormat:@"阅读回执,已读用户(%d)",msgModel.emModel.groupAckCount];
- msgModel.emModel.isReadAcked = YES;
- [[EMClient sharedClient].chatManager sendMessageReadAck:msgModel.emModel.messageId toUser:msgModel.emModel.conversationId completion:nil];
- [self.dataArray setObject:msgModel atIndexedSubscript:i];
- __weak typeof(self) weakself = self;
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakself.tableView reloadData];
- [weakself _scrollToBottomRow];
- });
- break;
- }
- }
- }
- // 收到已读回执
- - (void)messagesDidRead:(NSArray *)aMessages
- {
- __weak typeof(self) weakself = self;
- dispatch_async(self.msgQueue, ^{
- NSString *conId = weakself.conversationModel.emModel.conversationId;
- __block BOOL isReladView = NO;
- for (EMMessage *message in aMessages) {
- if (![conId isEqualToString:message.conversationId]){
- continue;
- }
-
- [weakself.dataArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
- if ([obj isKindOfClass:[EMMessageModel class]]) {
- EMMessageModel *model = (EMMessageModel *)obj;
- if ([model.emModel.messageId isEqualToString:message.messageId]) {
- model.emModel.isReadAcked = YES;
- isReladView = YES;
- *stop = YES;
- }
- }
- }];
- }
- BOOL changeRead = NO;
- NSInteger msgCount = weakself.dataArray.count - 1;
- for (NSInteger i = msgCount; i >= 0; i --) {
- if ([weakself.dataArray[i] isKindOfClass:[EMMessageModel class]]) {
- EMMessageModel *model = (EMMessageModel *)weakself.dataArray[i];
- if (model.emModel.isReadAcked == YES)
- {
- changeRead = YES;
- }
- if (changeRead) {
- model.emModel.isReadAcked = YES;
- }
- }
- }
-
- if (isReladView) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakself.tableView reloadData];
- });
- }
- });
- }
- - (void)messageStatusDidChange:(EMMessage *)aMessage
- error:(EMError *)aError
- {
- __weak typeof(self) weakself = self;
- dispatch_async(self.msgQueue, ^{
- NSString *conId = weakself.conversationModel.emModel.conversationId;
- if (![conId isEqualToString:aMessage.conversationId]){
- return ;
- }
-
- __block NSUInteger index = NSNotFound;
- __block EMMessageModel *reloadModel = nil;
- [self.dataArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
- if ([obj isKindOfClass:[EMMessageModel class]]) {
- EMMessageModel *model = (EMMessageModel *)obj;
- if ([model.emModel.messageId isEqualToString:aMessage.messageId]) {
- reloadModel = model;
- index = idx;
- *stop = YES;
- }
- }
- }];
-
- if (index != NSNotFound) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakself.dataArray replaceObjectAtIndex:index withObject:reloadModel];
- [weakself.tableView beginUpdates];
- [weakself.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
- [weakself.tableView endUpdates];
- });
- }
-
- });
- }
- - (void)cmdMessagesDidReceive:(NSArray *)aCmdMessages
- {
- __weak typeof(self) weakself = self;
- dispatch_async(self.msgQueue, ^{
- NSString *conId = weakself.conversationModel.emModel.conversationId;
- for (EMMessage *message in aCmdMessages) {
-
- if (![conId isEqualToString:message.conversationId]) {
- continue;
- }
-
- EMCmdMessageBody *body = (EMCmdMessageBody *)message.body;
- NSString *str = @"";
- if ([body.action isEqualToString:MSG_TYPING_BEGIN]) {
- str = @"正在输入...";
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- self.titleDetailLabel.text = str;
- });
- }
- });
- }
- #pragma mark - EMGroupManagerDelegate
- - (void)didLeaveGroup:(EMGroup *)aGroup
- reason:(EMGroupLeaveReason)aReason
- {
- EMConversation *conversation = self.conversationModel.emModel;
- if (conversation.type == EMChatTypeGroupChat && [aGroup.groupId isEqualToString:conversation.conversationId]) {
- [self.navigationController popToViewController:self animated:YES];
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- #pragma mark - EMChatroomManagerDelegate
- //有用户加入聊天室
- - (void)userDidJoinChatroom:(EMChatroom *)aChatroom
- user:(NSString *)aUsername
- {
- EMConversation *conversation = self.conversationModel.emModel;
- if (conversation.type == EMChatTypeChatRoom && [aChatroom.chatroomId isEqualToString:conversation.conversationId]) {
- NSString *str = [NSString stringWithFormat:@"%@ 进入聊天室", aUsername];
- [self showHint:str];
- }
- }
- - (void)userDidLeaveChatroom:(EMChatroom *)aChatroom
- user:(NSString *)aUsername
- {
- EMConversation *conversation = self.conversationModel.emModel;
- if (conversation.type == EMChatTypeChatRoom && [aChatroom.chatroomId isEqualToString:conversation.conversationId]) {
- NSString *str = [NSString stringWithFormat:@"%@ 离开聊天室", aUsername];
- [self showHint:str];
- }
- }
- - (void)didDismissFromChatroom:(EMChatroom *)aChatroom
- reason:(EMChatroomBeKickedReason)aReason
- {
- EMConversation *conversation = self.conversationModel.emModel;
- if (conversation.type == EMChatTypeChatRoom && [aChatroom.chatroomId isEqualToString:conversation.conversationId]) {
- [self.navigationController popToViewController:self animated:YES];
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- #pragma mark - KeyBoard
- - (void)keyBoardWillShow:(NSNotification *)note
- {
- // 获取用户信息
- NSDictionary *userInfo = [NSDictionary dictionaryWithDictionary:note.userInfo];
- // 获取键盘高度
- CGRect keyBoardBounds = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
- CGFloat keyBoardHeight = keyBoardBounds.size.height;
- // 获取键盘动画时间
- CGFloat animationTime = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
-
- // 定义好动作
- WS(weakSelf);
- void (^animation)(void) = ^void(void) {
- [weakSelf.chatBar mas_updateConstraints:^(MASConstraintMaker *make) {
- if (@available(iOS 11.0, *)) {
- make.bottom.mas_equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom).offset(-keyBoardHeight + EMVIEWBOTTOMMARGIN);
- } else {
- make.bottom.mas_equalTo(weakSelf.view.mas_bottom).offset(-keyBoardHeight);
- }
- }];
- };
-
- if (animationTime > 0) {
- [UIView animateWithDuration:animationTime animations:animation completion:^(BOOL finished) {
- [weakSelf _scrollToBottomRow];
- }];
- } else {
- animation();
- }
- }
- - (void)keyBoardWillHide:(NSNotification *)note
- {
- // 获取用户信息
- NSDictionary *userInfo = [NSDictionary dictionaryWithDictionary:note.userInfo];
- // 获取键盘动画时间
- CGFloat animationTime = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
-
- // 定义好动作
- WS(weakSelf);
- void (^animation)(void) = ^void(void) {
- [weakSelf.chatBar mas_updateConstraints:^(MASConstraintMaker *make) {
- if (@available(iOS 11.0, *)) {
- make.bottom.mas_equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom);
- } else {
- make.bottom.mas_equalTo(weakSelf.view.mas_bottom);
- }
- }];
- };
-
- if (animationTime > 0) {
- [UIView animateWithDuration:animationTime animations:animation];
- } else {
- animation();
- }
-
- if (self.enableTyping) {
- [self _sendEndTyping];
- }
- }
- #pragma mark - NSNotification
- - (UIImagePickerController *)imagePicker
- {
- if (!_imagePicker) {
- _imagePicker = [[UIImagePickerController alloc] init];
- _imagePicker.delegate = self;
- }
- return _imagePicker;
- }
- - (void)handleWillPushCallController:(NSNotification *)aNotif
- {
- [self.imagePicker dismissViewControllerAnimated:YES completion:nil];
- [[EMImageBrowser sharedBrowser] dismissViewController];
- [[EMAudioPlayerHelper sharedHelper] stopPlayer];
- }
- - (void)handleCleanMessages:(NSNotification *)aNotif
- {
- NSString *chatId = aNotif.object;
- if (chatId && [chatId isEqualToString:self.conversationModel.emModel.conversationId]) {
- [self.conversationModel.emModel deleteAllMessages:nil];
-
- [self.dataArray removeAllObjects];
- [self.tableView reloadData];
- }
- }
- - (void)handleGroupSubjectUpdated:(NSNotification *)aNotif
- {
- EMGroup *group = aNotif.object;
- if (!group) {
- return;
- }
-
- NSString *groupId = group.groupId;
- if ([groupId isEqualToString:self.conversationModel.emModel.conversationId]) {
- self.conversationModel.name = group.subject;
- self.titleLabel.text = group.subject;
- }
- }
- #pragma mark - Gesture Recognizer
- - (void)handleTapTableViewAction:(UITapGestureRecognizer *)aTap
- {
- if (aTap.state == UIGestureRecognizerStateEnded) {
- [self.view endEditing:YES];
- [self.chatBar clearMoreViewAndSelectedButton];
- [self performSelector:@selector(_scrollToBottomRow) withObject:nil afterDelay:0.1];
- }
- }
- #pragma mark - Private
- - (void)_joinChatroom
- {
- __weak typeof(self) weakself = self;
- [self showHudInView:self.view hint:@"加入聊天室..."];
- [[EMClient sharedClient].roomManager joinChatroom:self.conversationModel.emModel.conversationId completion:^(EMChatroom *aChatroom, EMError *aError) {
- [weakself hideHud];
- if (aError) {
- [EMAlertController showErrorAlert:@"加入聊天室失败"];
- [weakself.navigationController popViewControllerAnimated:YES];
- } else {
- weakself.isFirstLoadMsg = YES;
- [weakself tableViewDidTriggerHeaderRefresh];
- }
- }];
- }
- - (void)_scrollToBottomRow
- {
- if ([self.dataArray count] > 0) {
- NSInteger toRow = self.dataArray.count - 1;
- NSIndexPath *toIndexPath = [NSIndexPath indexPathForRow:toRow inSection:0];
- [self.tableView scrollToRowAtIndexPath:toIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
- }
- }
- - (void)_showCustomTransferFileAlertView
- {
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"(づ。◕‿‿◕。)づ" message:@"需要自定义实现上传附件方法" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleCancel handler:nil];
- [alertController addAction:okAction];
- [self presentViewController:alertController animated:YES completion:nil];
- }
- - (NSURL *)_videoConvert2Mp4:(NSURL *)movUrl
- {
- NSURL *mp4Url = nil;
- AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:movUrl options:nil];
- NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
-
- if ([compatiblePresets containsObject:AVAssetExportPresetHighestQuality]) {
- AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetHighestQuality];
- NSString *mp4Path = [NSString stringWithFormat:@"%@/%d%d.mp4", [self _getAudioOrVideoPath], (int)[[NSDate date] timeIntervalSince1970], arc4random() % 100000];
- mp4Url = [NSURL fileURLWithPath:mp4Path];
- exportSession.outputURL = mp4Url;
- exportSession.shouldOptimizeForNetworkUse = YES;
- exportSession.outputFileType = AVFileTypeMPEG4;
- dispatch_semaphore_t wait = dispatch_semaphore_create(0l);
- [exportSession exportAsynchronouslyWithCompletionHandler:^{
- switch ([exportSession status]) {
- case AVAssetExportSessionStatusFailed: {
- NSLog(@"failed, error:%@.", exportSession.error);
- } break;
- case AVAssetExportSessionStatusCancelled: {
- NSLog(@"cancelled.");
- } break;
- case AVAssetExportSessionStatusCompleted: {
- NSLog(@"completed.");
- } break;
- default: {
- NSLog(@"others.");
- } break;
- }
- dispatch_semaphore_signal(wait);
- }];
- long timeout = dispatch_semaphore_wait(wait, DISPATCH_TIME_FOREVER);
- if (timeout) {
- NSLog(@"timeout.");
- }
-
- if (wait) {
- //dispatch_release(wait);
- wait = nil;
- }
- }
-
- return mp4Url;
- }
- #pragma mark - Menu Controller
- - (UIMenuController *)menuController
- {
- if (_menuController == nil) {
- _menuController = [UIMenuController sharedMenuController];
- }
-
- return _menuController;
- }
- - (UIMenuItem *)deleteMenuItem
- {
- if (_deleteMenuItem == nil) {
- _deleteMenuItem = [[UIMenuItem alloc] initWithTitle:@"删除" action:@selector(deleteMenuItemAction:)];
- }
-
- return _deleteMenuItem;
- }
- - (UIMenuItem *)copyMenuItem
- {
- if (_copyMenuItem == nil) {
- _copyMenuItem = [[UIMenuItem alloc] initWithTitle:@"复制" action:@selector(copyMenuItemAction:)];
- }
-
- return _copyMenuItem;
- }
- - (UIMenuItem *)transpondMenuItem
- {
- if (_transpondMenuItem == nil) {
- _transpondMenuItem = [[UIMenuItem alloc] initWithTitle:@"转发" action:@selector(transpondMenuItemAction:)];
- }
- return _transpondMenuItem;
- }
- - (UIMenuItem *)recallMenuItem
- {
- if (_recallMenuItem == nil) {
- _recallMenuItem = [[UIMenuItem alloc] initWithTitle:@"撤回" action:@selector(recallMenuItemAction:)];
- }
- return _recallMenuItem;
- }
- - (UIMenuItem *)playAndRecordMenuItem
- {
- if (_playAndRecordMenuItem == nil) {
- _playAndRecordMenuItem = [[UIMenuItem alloc] initWithTitle:@"听筒播放" action:@selector(playAndRecordMenuItemAction:)];
- }
- return _playAndRecordMenuItem;
- }
- //删除消息
- - (void)deleteMenuItemAction:(UIMenuItem *)aItem
- {
- if (self.menuIndexPath == nil) {
- return;
- }
-
- EMMessageModel *model = [self.dataArray objectAtIndex:self.menuIndexPath.row];
- [self.conversationModel.emModel deleteMessageWithId:model.emModel.messageId error:nil];
-
- NSMutableIndexSet *indexs = [NSMutableIndexSet indexSetWithIndex:self.menuIndexPath.row];
- NSMutableArray *indexPaths = [NSMutableArray arrayWithObjects:self.menuIndexPath, nil];
- if (self.menuIndexPath.row - 1 >= 0) {
- id nextMessage = nil;
- id prevMessage = [self.dataArray objectAtIndex:(self.menuIndexPath.row - 1)];
- if (self.menuIndexPath.row + 1 < [self.dataArray count]) {
- nextMessage = [self.dataArray objectAtIndex:(self.menuIndexPath.row + 1)];
- }
- if ((!nextMessage || [nextMessage isKindOfClass:[NSString class]]) && [prevMessage isKindOfClass:[NSString class]]) {
- [indexs addIndex:self.menuIndexPath.row - 1];
- [indexPaths addObject:[NSIndexPath indexPathForRow:(self.menuIndexPath.row - 1) inSection:0]];
- }
- }
-
- [self.dataArray removeObjectsAtIndexes:indexs];
- [self.tableView beginUpdates];
- [self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
- [self.tableView endUpdates];
-
- if ([self.dataArray count] == 0) {
- self.msgTimelTag = -1;
- }
-
- self.menuIndexPath = nil;
- }
- - (void)copyMenuItemAction:(UIMenuItem *)aItem
- {
- if (self.menuIndexPath == nil) {
- return;
- }
-
- EMMessageModel *model = [self.dataArray objectAtIndex:self.menuIndexPath.row];
- if (model.type == EMMessageTypeText) {
- EMTextMessageBody *body = (EMTextMessageBody *)model.emModel.body;
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- pasteboard.string = body.text;
- }
- if (model.type == EMMessageTypeImage) {
- EMMessageCell *cell = [self.tableView cellForRowAtIndexPath:self.menuIndexPath];
- [[UIPasteboard generalPasteboard]setData:UIImagePNGRepresentation(cell.bubbleView.image) forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]];
- }
- self.menuIndexPath = nil;
- }
- - (void)transpondMenuItemAction:(UIMenuItem *)aItem
- {
- if (self.menuIndexPath == nil) {
- return;
- }
-
- EMMessageModel *model = [self.dataArray objectAtIndex:self.menuIndexPath.row];
- // EMMsgTranspondViewController *controller = [[EMMsgTranspondViewController alloc] initWithModel:model];
- // [self.navigationController pushViewController:controller animated:YES];
- //
- // __weak typeof(self) weakself = self;
- // [controller setDoneCompletion:^(EMMessageModel * _Nonnull aModel, NSString * _Nonnull aUsername) {
- // [weakself _transpondMsg:aModel toUser:aUsername];
- // }];
-
- // if (self.IsShareText) {
- // model.Title = self.shareText;
- // model.SoureTypeId = 1;
- // }else{
- // model.SoureId = self.Id;
- // model.SoureTypeId = self.type;
- // model.Title = self.currentNoteModel.Title;
- // model.Author = self.currentNoteModel.UserName;
- // vc.type = CollectModel_NewTopic;
- // }
- switch (model.type) {
- case EMMessageTypeText:
- {
- FlowAttachmentsModel * sendModel = [[FlowAttachmentsModel alloc] init];
- EMTextMessageBody *body = (EMTextMessageBody *)model.emModel.body;
- sendModel.Title = body.text;
- sendModel.SoureTypeId = 1;
- self.sendModel = sendModel;
- [self shareHander];
- }
- break;
- case EMMessageTypeImage:
- {
- [self shareImage:model];
- // EMTextMessageBody *body = (EMTextMessageBody *)model.emModel.body;
- // self.sendModel.image = body.text;
- // self.sendModel.SoureTypeId = 301;
- }
- break;
- case EMMessageTypeExtApp:
- {
- NSDictionary * dict = model.emModel.ext;
- CollectModelType type = [[dict objectForKey:@"app_type"] intValue];
- NSInteger sourceUserId = [[dict objectForKey:@"app_sourceUserId"] integerValue];
- NSInteger Id = [[dict objectForKey:@"app_id"] integerValue];
- NSString * title = [dict objectForKey:@"app_title"];
- NSString * url = [dict objectForKey:@"app_url"];
- FlowAttachmentsModel * sendModel = [[FlowAttachmentsModel alloc] init];
- sendModel.Title = title;
- sendModel.SoureTypeId = type;
- sendModel.SoureId = Id;
- sendModel.Url = url;
- sendModel.SourceUserId = sourceUserId;
- self.sendModel = sendModel;
- [self shareHander];
- }
- break;
- default:
- break;
- }
- self.menuIndexPath = nil;
- }
- - (void)shareImage:(EMMessageModel *)model
- {
- __weak typeof(self) weakself = self;
- void (^downloadThumbBlock)(EMMessageModel *aModel) = ^(EMMessageModel *aModel) {
- [weakself showHint:@"获取缩略图..."];
- [[EMClient sharedClient].chatManager downloadMessageThumbnail:aModel.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
- if (!error) {
- [weakself.tableView reloadData];
- }
- }];
- };
-
- EMImageMessageBody *body = (EMImageMessageBody*)model.emModel.body;
- BOOL isCustomDownload = !([EMClient sharedClient].options.isAutoTransferMessageAttachments);
- if (body.thumbnailDownloadStatus == EMDownloadStatusFailed) {
- if (isCustomDownload) {
- [self _showCustomTransferFileAlertView];
- } else {
- downloadThumbBlock(model);
- }
-
- return;
- }
-
- BOOL isAutoDownloadThumbnail = [EMClient sharedClient].options.isAutoDownloadThumbnail;
- if (body.thumbnailDownloadStatus == EMDownloadStatusPending && !isAutoDownloadThumbnail) {
- downloadThumbBlock(model);
- return;
- }
- FlowAttachmentsModel * sendModel = [[FlowAttachmentsModel alloc] init];
- sendModel.SoureTypeId = 301;
- self.sendModel = sendModel;
- if (body.downloadStatus == EMDownloadStatusSucceed) {
- UIImage *image = [UIImage imageWithContentsOfFile:body.localPath];
- if (image) {
- self.sendImage = image;
- [self shareHander];
- // [[EMImageBrowser sharedBrowser] showImages:@[image] fromController:self];
- return;
- }
- }
-
- if (isCustomDownload) {
- [self _showCustomTransferFileAlertView];
- return;
- }
-
- [self showHudInView:self.view hint:@"下载原图..."];
- [[EMClient sharedClient].chatManager downloadMessageAttachment:model.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
- [weakself hideHud];
- if (error) {
- [EMAlertController showErrorAlert:@"下载原图失败"];
- } else {
- if (message.direction == EMMessageDirectionReceive && !message.isReadAcked) {
- [[EMClient sharedClient].chatManager sendMessageReadAck:message.messageId toUser:message.conversationId completion:nil];
- }
-
- NSString *localPath = [(EMImageMessageBody *)message.body localPath];
- UIImage *image = [UIImage imageWithContentsOfFile:localPath];
- if (image) {
- weakself.sendImage = image;
- [weakself shareHander];
- // [[EMImageBrowser sharedBrowser] showImages:@[image] fromController:self];
- } else {
- [EMAlertController showErrorAlert:@"获取原图失败"];
- }
- }
- }];
- }
- - (void)recallMenuItemAction:(UIMenuItem *)aItem
- {
- if (self.menuIndexPath == nil) {
- return;
- }
-
- NSIndexPath *indexPath = self.menuIndexPath;
- __weak typeof(self) weakself = self;
- EMMessageModel *model = [self.dataArray objectAtIndex:self.menuIndexPath.row];
- [[EMClient sharedClient].chatManager recallMessage:model.emModel completion:^(EMMessage *aMessage, EMError *aError) {
- if (aError) {
- [EMAlertController showErrorAlert:aError.errorDescription];
- } else {
- EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithText:@"您撤回一条消息"];
- NSString *from = [[EMClient sharedClient] currentUsername];
- NSString *to = self.conversationModel.emModel.conversationId;
- EMMessage *message = [[EMMessage alloc] initWithConversationID:to from:from to:to body:body ext:@{MSG_EXT_RECALL:@(YES)}];
- message.chatType = (EMChatType)self.conversationModel.emModel.type;
- message.isRead = YES;
- message.timestamp = model.emModel.timestamp;
- message.localTime = model.emModel.localTime;
- [weakself.conversationModel.emModel insertMessage:message error:nil];
-
- EMMessageModel *model = [[EMMessageModel alloc] initWithEMMessage:message];
- [weakself.dataArray replaceObjectAtIndex:indexPath.row withObject:model];
- [weakself.tableView reloadData];
- }
- }];
-
- self.menuIndexPath = nil;
- }
- - (void)playAndRecordMenuItemAction:(UIMenuItem *)aItem
- {
- if (self.menuIndexPath == nil) {
- return;
- }
- EMMessageModel *model = [self.dataArray objectAtIndex:self.menuIndexPath.row];
- [self playVoice:model];
- self.menuIndexPath = nil;
- }
- - (void)playVoice:(EMMessageModel *)model
- {
- if (model.isPlaying) {
- [[EMAudioPlayerHelper sharedHelper] stopPlayer];
- model.isPlaying = NO;
- [self.tableView reloadData];
- return;
- }
-
- EMVoiceMessageBody *body = (EMVoiceMessageBody*)model.emModel.body;
- if (body.downloadStatus == EMDownloadStatusDownloading) {
- [EMAlertController showInfoAlert:@"正在下载语音,稍后点击"];
- return;
- }
-
- __weak typeof(self) weakself = self;
- void (^playBlock)(EMMessageModel *aModel) = ^(EMMessageModel *aModel) {
- id model = [EMAudioPlayerHelper sharedHelper].model;
- if (model && [model isKindOfClass:[EMMessageModel class]]) {
- EMMessageModel *oldModel = (EMMessageModel *)model;
- if (oldModel.isPlaying) {
- oldModel.isPlaying = NO;
- }
- }
-
- if (!aModel.emModel.isReadAcked) {
- [[EMClient sharedClient].chatManager sendMessageReadAck:aModel.emModel.messageId toUser:aModel.emModel.conversationId completion:nil];
- }
-
- aModel.isPlaying = YES;
- if (!aModel.emModel.isRead) {
- aModel.emModel.isRead = YES;
- }
- [weakself.tableView reloadData];
- [[EMAudioPlayerHelper sharedHelper] startPlayerWithPath:body.localPath model:aModel AVAudioSessionCategory:AVAudioSessionCategoryPlayAndRecord completion:^(NSError * _Nonnull error) {
- aModel.isPlaying = NO;
- [weakself.tableView reloadData];
- }];
- };
-
- if (body.downloadStatus == EMDownloadStatusSucceed) {
- playBlock(model);
- return;
- }
-
- if (![EMClient sharedClient].options.isAutoTransferMessageAttachments) {
- [self _showCustomTransferFileAlertView];
- return;
- }
-
- [self showHudInView:self.view hint:@"下载语音..."];
- [[EMClient sharedClient].chatManager downloadMessageAttachment:model.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
- [weakself hideHud];
- if (error) {
- [EMAlertController showErrorAlert:@"下载语音失败"];
- } else {
- playBlock(model);
- }
- }];
- }
- - (void)_showMenuViewController:(EMMessageCell *)aCell
- model:(EMMessageModel *)aModel
- {
- [self becomeFirstResponder];
- NSMutableArray *items = [[NSMutableArray alloc] init];
- if (aModel.type == EMMessageTypeText || aModel.type == EMMessageTypeImage) {
- [items addObject:self.copyMenuItem];
- [items addObject:self.transpondMenuItem];
- // } else if (aModel.type == EMMessageTypeLocation || aModel.type == EMMessageTypeImage || aModel.type == EMMessageTypeVideo) {
- // [items addObject:self.transpondMenuItem];
- }else if(aModel.type == EMMessageTypeExtApp){
- [items addObject:self.transpondMenuItem];
- }else if(aModel.type == EMMessageTypeVoice){
- [items addObject:self.playAndRecordMenuItem];
- }
-
- if (aModel.emModel.direction == EMMessageDirectionSend) {
- [items addObject:self.recallMenuItem];
- }
- [items addObject:self.deleteMenuItem];
- [self.menuController setMenuItems:items];
- [self.menuController setTargetRect:aCell.bubbleView.frame inView:aCell];
- [self.menuController setMenuVisible:YES animated:NO];
- }
- #pragma mark - Transpond Message
- - (void)_forwardMsgWithBody:(EMMessageBody *)aBody
- to:(NSString *)aTo
- ext:(NSDictionary *)aExt
- completion:(void (^)(EMMessage *message))aCompletionBlock
- {
- NSString *from = [[EMClient sharedClient] currentUsername];
- EMMessage *message = [[EMMessage alloc] initWithConversationID:aTo from:from to:aTo body:aBody ext:aExt];
- message.chatType = EMChatTypeChat;
-
- __weak typeof(self) weakself = self;
- [[EMClient sharedClient].chatManager sendMessage:message progress:nil completion:^(EMMessage *message, EMError *error) {
- if (error) {
- [weakself.conversationModel.emModel deleteMessageWithId:message.messageId error:nil];
- [EMAlertController showErrorAlert:@"转发消息失败"];
- } else {
- if (aCompletionBlock) {
- aCompletionBlock(message);
- }
- [EMAlertController showSuccessAlert:@"转发消息成功"];
- }
- }];
- }
- - (void)_forwardImageMsg:(EMMessage *)aMsg
- toUser:(NSString *)aUsername
- {
- NSString *thumbnailLocalPath = [(EMImageMessageBody *)aMsg.body thumbnailLocalPath];
-
- __weak typeof(self) weakself = self;
- void (^block)(EMMessage *aMessage) = ^(EMMessage *aMessage) {
- EMImageMessageBody *oldBody = (EMImageMessageBody *)aMessage.body;
- EMImageMessageBody *newBody = [[EMImageMessageBody alloc] initWithData:nil thumbnailData:[NSData dataWithContentsOfFile:oldBody.thumbnailLocalPath]];
- newBody.thumbnailRemotePath = oldBody.thumbnailRemotePath;
- newBody.remotePath = oldBody.remotePath;
-
- [weakself _forwardMsgWithBody:newBody to:aUsername ext:aMsg.ext completion:^(EMMessage *message) {
- [(EMImageMessageBody *)message.body setLocalPath:oldBody.localPath];
- [[EMClient sharedClient].chatManager updateMessage:message completion:nil];
- }];
- };
-
- if (![[NSFileManager defaultManager] fileExistsAtPath:thumbnailLocalPath]) {
- [[EMClient sharedClient].chatManager downloadMessageThumbnail:aMsg progress:nil completion:^(EMMessage *message, EMError *error) {
- if (error) {
- [EMAlertController showErrorAlert:@"转发消息失败"];
- } else {
- block(aMsg);
- }
- }];
- } else {
- block(aMsg);
- }
- }
- - (void)_forwardVideoMsg:(EMMessage *)aMsg
- toUser:(NSString *)aUsername
- {
- EMVideoMessageBody *oldBody = (EMVideoMessageBody *)aMsg.body;
- __weak typeof(self) weakself = self;
- void (^block)(EMMessage *aMessage) = ^(EMMessage *aMessage) {
- EMVideoMessageBody *newBody = [[EMVideoMessageBody alloc] initWithLocalPath:oldBody.localPath displayName:oldBody.displayName];
- newBody.thumbnailLocalPath = oldBody.thumbnailLocalPath;
-
- [weakself _forwardMsgWithBody:newBody to:aUsername ext:aMsg.ext completion:^(EMMessage *message) {
- [(EMVideoMessageBody *)message.body setLocalPath:[(EMVideoMessageBody *)aMessage.body localPath]];
- [[EMClient sharedClient].chatManager updateMessage:message completion:nil];
- }];
- };
-
- if (![[NSFileManager defaultManager] fileExistsAtPath:oldBody.localPath]) {
- [[EMClient sharedClient].chatManager downloadMessageAttachment:aMsg progress:nil completion:^(EMMessage *message, EMError *error) {
- if (error) {
- [EMAlertController showErrorAlert:@"转发消息失败"];
- } else {
- block(aMsg);
- }
- }];
- } else {
- block(aMsg);
- }
- }
- - (void)_transpondMsg:(EMMessageModel *)aModel
- toUser:(NSString *)aUsername
- {
- EMMessageBodyType type = aModel.emModel.body.type;
- if (type == EMMessageBodyTypeText || type == EMMessageBodyTypeLocation) {
- [self _forwardMsgWithBody:aModel.emModel.body to:aUsername ext:aModel.emModel.ext completion:nil];
- } else if (type == EMMessageBodyTypeImage) {
- [self _forwardImageMsg:aModel.emModel toUser:aUsername];
- } else if (type == EMMessageBodyTypeVideo) {
- [self _forwardVideoMsg:aModel.emModel toUser:aUsername];
- }
- }
- #pragma mark - Send Message
- - (void)_sendTextAction:(NSString *)aText
- ext:(NSDictionary *)aExt
- {
- [self.chatBar clearInputViewText];
- [self clearUserInfoInDocument];
- if ([aText length] == 0) {
- return;
- }
-
- //TODO: 处理@
- //messageExt
-
- //TODO: 处理表情
- // NSString *sendText = [EaseConvertToCommonEmoticonsHelper convertToCommonEmoticons:aText];
-
- EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithText:aText];
- [self _sendMessageWithBody:body ext:aExt isUpload:NO];
-
- if (self.enableTyping) {
- [self _sendEndTyping];
- }
- }
- - (void)_sendImageDataAction:(NSData *)aImageData
- {
- EMImageMessageBody *body = [[EMImageMessageBody alloc] initWithData:aImageData displayName:@"image"];
- [self _sendMessageWithBody:body ext:nil isUpload:YES];
- }
- - (void)_sendLocationAction:(CLLocationCoordinate2D)aCoord
- address:(NSString *)aAddress
- {
- EMLocationMessageBody *body = [[EMLocationMessageBody alloc] initWithLatitude:aCoord.latitude longitude:aCoord.longitude address:aAddress];
- [self _sendMessageWithBody:body ext:nil isUpload:NO];
- }
- - (void)_sendVideoAction:(NSURL *)aUrl
- {
- EMVideoMessageBody *body = [[EMVideoMessageBody alloc] initWithLocalPath:[aUrl path] displayName:@"video.mp4"];
- [self _sendMessageWithBody:body ext:nil isUpload:YES];
- }
- - (void)_sendBeginTyping
- {
- NSString *from = [[EMClient sharedClient] currentUsername];
- NSString *to = self.conversationModel.emModel.conversationId;
- EMCmdMessageBody *body = [[EMCmdMessageBody alloc] initWithAction:MSG_TYPING_BEGIN];
- body.isDeliverOnlineOnly = YES;
- EMMessage *message = [[EMMessage alloc] initWithConversationID:to from:from to:to body:body ext:nil];
- message.chatType = (EMChatType)self.conversationModel.emModel.type;
- [[EMClient sharedClient].chatManager sendMessage:message progress:nil completion:nil];
- }
- //正在输入
- - (void)_sendEndTyping
- {
- self.isTyping = NO;
-
- NSString *from = [[EMClient sharedClient] currentUsername];
- NSString *to = self.conversationModel.emModel.conversationId;
- EMCmdMessageBody *body = [[EMCmdMessageBody alloc] initWithAction:MSG_TYPING_END];
- body.isDeliverOnlineOnly = YES;
- EMMessage *message = [[EMMessage alloc] initWithConversationID:to from:from to:to body:body ext:nil];
- message.chatType = (EMChatType)self.conversationModel.emModel.type;
- [[EMClient sharedClient].chatManager sendMessage:message progress:nil completion:nil];
- }
- #pragma mark - Data
- - (NSArray *)_formatMessages:(NSArray<EMMessage *> *)aMessages
- {
- NSMutableArray *formated = [[NSMutableArray alloc] init];
- for (int i = 0; i < [aMessages count]; i++) {
- EMMessage *msg = aMessages[i];
- // cmd消息不展示
- if(msg.body.type == EMMessageBodyTypeCmd) {
- continue;
- }
- if (msg.chatType == EMChatTypeChat && msg.isReadAcked && (msg.body.type == EMMessageBodyTypeText || msg.body.type == EMMessageBodyTypeLocation)) {
- //
- [[EMClient sharedClient].chatManager sendMessageReadAck:msg.messageId toUser:msg.conversationId completion:nil];
- } else if (msg.chatType == EMChatTypeGroupChat && !msg.isReadAcked && (msg.body.type == EMMessageBodyTypeText || msg.body.type == EMMessageBodyTypeLocation)) {
- }
-
- CGFloat interval = (self.msgTimelTag - msg.timestamp) / 1000;
- if (self.msgTimelTag < 0 || interval > 60 || interval < -60) {
- NSString *timeStr = [EMDateHelper formattedTimeFromTimeInterval:msg.timestamp];
- [formated addObject:timeStr];
- self.msgTimelTag = msg.timestamp;
- }
-
- EMMessageModel *model = [[EMMessageModel alloc] initWithEMMessage:msg];
- [formated addObject:model];
- }
-
- return formated;
- }
- - (void)tableViewDidTriggerHeaderRefresh
- {
- __weak typeof(self) weakself = self;
- void (^block)(NSArray *aMessages, EMError *aError) = ^(NSArray *aMessages, EMError *aError) {
- if (!aError && [aMessages count]) {
- EMMessage *msg = aMessages[0];
- weakself.moreMsgId = msg.messageId;
- dispatch_async(self.msgQueue, ^{
- NSArray *formated = [weakself _formatMessages:aMessages];
- [weakself.dataArray insertObjects:formated atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [formated count])]];
- if (![weakself.dataArray.firstObject isKindOfClass:[NSString class]]) {
- [weakself.dataArray removeObjectAtIndex:0];
- }
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakself.tableView reloadData];
- if (weakself.isFirstLoadMsg) {
- weakself.isFirstLoadMsg = NO;
- [weakself _scrollToBottomRow];
- }
- });
- });
- }
-
- [weakself tableViewDidFinishTriggerHeader:YES reload:NO];
- };
- if ([EMDemoOptions sharedOptions].isPriorityGetMsgFromServer) {
- EMConversation *conversation = self.conversationModel.emModel;
- [EMClient.sharedClient.chatManager asyncFetchHistoryMessagesFromServer:conversation.conversationId
- conversationType:conversation.type
- startMessageId:self.moreMsgId
- pageSize:50
- completion:^(EMCursorResult *aResult, EMError *aError)
- {
- block(aResult.list, aError);
- }];
- } else {
- [self.conversationModel.emModel loadMessagesStartFromId:self.moreMsgId
- count:50
- searchDirection:EMMessageSearchDirectionUp
- completion:block];
- if(self.conversationModel.emModel.unreadMessagesCount > 0){
- [self sendDidReadReceipt];
- }
- }
- }
- #pragma mark - Action
- - (void)backAction
- {
- [[EMAudioPlayerHelper sharedHelper] stopPlayer];
- [EMConversationHelper resortConversationsLatestMessage];
-
- EMConversation *conversation = self.conversationModel.emModel;
- if (conversation.type == EMChatTypeChatRoom) {
- [[EMClient sharedClient].roomManager leaveChatroom:conversation.conversationId completion:nil];
- }
-
- [self.navigationController popViewControllerAnimated:YES];
- }
- //删除该会话所有消息,同时清除内存和数据库中的消息
- - (void)deleteAllMessageAction
- {
- EMError *error = nil;
- [self.conversationModel.emModel deleteAllMessages:&error];
- if (!error) {
- [self.dataArray removeAllObjects];
- [self.tableView reloadData];
- }
- }
- - (void)groupOrChatroomInfoAction
- {
- if (self.conversationModel.emModel.type == EMConversationTypeGroupChat) {
- [[NSNotificationCenter defaultCenter] postNotificationName:GROUP_INFO_PUSHVIEWCONTROLLER object:@{NOTIF_ID:self.conversationModel.emModel.conversationId, NOTIF_NAVICONTROLLER:self.navigationController}];
- } else if (self.conversationModel.emModel.type == EMConversationTypeChatRoom) {
- [[NSNotificationCenter defaultCenter] postNotificationName:CHATROOM_INFO_PUSHVIEWCONTROLLER object:@{NOTIF_ID:self.conversationModel.emModel.conversationId, NOTIF_NAVICONTROLLER:self.navigationController}];
- }
- }
- //发送消息体
- - (void)_sendMessageWithBody:(EMMessageBody *)aBody
- ext:(NSDictionary *)aExt
- isUpload:(BOOL)aIsUpload
- {
- if (!([EMClient sharedClient].options.isAutoTransferMessageAttachments) && aIsUpload) {
- [self _showCustomTransferFileAlertView];
- return;
- }
-
- NSString *from = [[EMClient sharedClient] currentUsername];
- NSString *to = self.conversationModel.emModel.conversationId;
- EMMessage *message = [[EMMessage alloc] initWithConversationID:to from:from to:to body:aBody ext:aExt];
-
- //是否需要发送阅读回执
- if([aExt objectForKey:MSG_EXT_READ_RECEIPT]) {
- message.isNeedGroupAck = YES;
- }
-
- message.chatType = (EMChatType)self.conversationModel.emModel.type;
- __weak typeof(self) weakself = self;
- [[EMClient sharedClient].chatManager sendMessage:message progress:nil completion:^(EMMessage *message, EMError *error) {
- NSArray *formated = [weakself _formatMessages:@[message]];
- [weakself.dataArray addObjectsFromArray:formated];
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakself.tableView reloadData];
- [weakself _scrollToBottomRow];
- });
- NSLog(@"%@",@{@"ContactUserId":[NSString stringWithFormat:@"%ld",(long)self.toUserId],@"IndividualGroupId":@(self.IndividualGroupId)});
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- [[HttpManager sharedHttpManager] POSTUrl:Host(Often_Contact_Add_Post) parameters:@{@"ContactUserId":[NSString stringWithFormat:@"%ld",(long)self.toUserId],@"IndividualGroupId":@(self.IndividualGroupId),@"ChatType":@(self.chatType)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
- NSLog(@"%@",responseObject);
- if ([responseObject isKindOfClass:[NSDictionary class]]) {
- NSInteger listId = [[responseObject objectForKey:@"Id"] integerValue];
- if (listId > 0) {
- weakself.listId = listId;
- weakself.isTop = [[responseObject objectForKey:@"IsTop"] integerValue];
- }
- }
- } failure:^(NSError * _Nonnull error) {
-
- }];
- });
- }];
-
- }
- #pragma mark - CustomView
- - (UIView *)titleV
- {
- if (!_titleV) {
- _titleV = [UIView new];
- _titleV.backgroundColor = [UIColor whiteColor];
- }
- return _titleV;
- }
- - (UIButton *)backBtn
- {
- if (!_backBtn) {
- _backBtn = [UIButton new];
- [_backBtn setImage:[UIImage imageNamed:@"back_black_icon"] forState:UIControlStateNormal];
- }
- return _backBtn;
- }
- - (UIButton *)tabBtn
- {
- if (!_tabBtn) {
- _tabBtn = [UIButton new];
- [_tabBtn setImage:[UIImage imageNamed:@"menu_black_icon"] forState:UIControlStateNormal];
- }
- return _tabBtn;
- }
- - (UILabel *)titleL
- {
- if (!_titleL) {
- _titleL = [UILabel new];
- [_titleL setTextColor: UIColorHex(0A0A0A)];
- _titleL.font = [UIFont systemFontOfSize:18];
- }
- return _titleL;
- }
- - (UIButton *)mangerBtn
- {
- if (!_mangerBtn) {
- _mangerBtn = [UIButton new];
- [_mangerBtn setImage:[UIImage imageNamed:@"chatmsg_detailchat_more_icon"] forState:UIControlStateNormal];
- }
- return _mangerBtn;
- }
- - (NSMutableArray *)userInfoArray
- {
- if (!_userInfoArray) {
- _userInfoArray = [NSMutableArray array];
- }
- return _userInfoArray;
- }
- - (void)selectMoreMenu:(NSInteger)index title:(NSString *)title
- {
- switch (index) {
- case 0:{
- [self chatBarDidCameraAction];
- }break;
- case 1:{
- [self chatBarDidPhotoAction];
- }break;
- case 2:{
- FavoritesViewController *favorites = [[FavoritesViewController alloc] init];
- favorites.title = @"我的笔记";
- [self.navigationController pushViewController:favorites animated:YES];
- }break;
- case 3:{
- FavoritesViewController *favorites = [[FavoritesViewController alloc] init];
- favorites.title = @"我的收藏";
- [self.navigationController pushViewController:favorites animated:YES];
- }break;
-
- default:
- break;
- }
- }
- - (NSMutableArray *)chatDistoryArray
- {
- if(!_chatDistoryArray)
- {
- _chatDistoryArray = [[NSMutableArray alloc] initWithArray:USERDEFAULTSGET(@"ChatList")];
- }
- return _chatDistoryArray;
- }
- - (NSString *)getUserInfoInDocument{
- for (NSDictionary * dict in self.chatDistoryArray) {
- if ([[dict objectForKey:@"ImId"] isEqualToString:self.conversationModel.emModel.conversationId]) {
- NSString * text = [dict objectForKey:@"text"];
- return text;
- }
- }
- return @"";
- }
- - (void)clearUserInfoInDocument
- {
- for (NSDictionary * dict in self.chatDistoryArray) {
- if ([[dict objectForKey:@"ImId"] isEqualToString:self.conversationModel.emModel.conversationId]) {
- [self.chatDistoryArray removeObject:dict];
- break;
- }
- }
- USERDEFAULTSSET(self.chatDistoryArray,@"ChatList");
- }
- - (void)saveUserInfoInDocument:(NSString *)text{
- for (NSDictionary * dict in self.chatDistoryArray) {
- if ([[dict objectForKey:@"ImId"] isEqualToString:self.conversationModel.emModel.conversationId]) {
- [self.chatDistoryArray removeObject:dict];
- break;
- }
- }
- [self.chatDistoryArray addObject:@{@"ImId":self.conversationModel.emModel.conversationId,@"text":text}];
- USERDEFAULTSSET(self.chatDistoryArray,@"ChatList");
- }
- - (void)deleteConversationMsg
- {
- WS(weakSelf);
- [[EMClient sharedClient].chatManager deleteConversation:self.conversationModel.emModel.conversationId isDeleteMessages:YES completion:^(NSString *aConversationId, EMError *aError) {
- [weakSelf deleteAllMessageAction];
- }];
- }
- #pragma mark - 转发
- - (void)shareHander{
- [self.noteBookShareVC initNoteBookShareData];
- self.noteBookShareVC.view.hidden = !self.noteBookShareVC.view.hidden;
- }
- - (NoteBookShareVC *)noteBookShareVC{
- if (_noteBookShareVC == nil) {
- _noteBookShareVC = [NoteBookShareVC initNoteBookShareVC];
- [_noteBookShareVC.view setFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT)];
- [_noteBookShareVC.view setHidden:YES];
- _noteBookShareVC.delegate = self;
- }
- return _noteBookShareVC;
- }
- -(void)userSelectType:(NSString *)typeName WithIndexPath:(NSIndexPath *)indexPath{
- self.noteBookShareVC.view.hidden = !self.noteBookShareVC.view.hidden;
- if ([typeName isEqualToString:@"发给微信好友"]) {
-
- }else if ([typeName isEqualToString:@"发到朋友圈"]){
-
- }else if ([typeName isEqualToString:@"发到微博"]){
-
- }else if ([typeName isEqualToString:@"发给QQ好友"]){
-
- }else if ([typeName isEqualToString:@"发到消息"]){
-
- }else if ([typeName isEqualToString:@"发到小组"]){
- // [self returnToGroup];
- }else if ([typeName isEqualToString:@"发到笔记"]){
- [self returnToNote];
- }else if ([typeName isEqualToString:@"发到话题"]){
- [self returnToTopic];
- }else{
- }
- }
- #pragma mark - 分享功能
- //- (void)returnToGroup
- //{
- // MyTDGroupViewController * vc = [[MyTDGroupViewController alloc] init];
- // vc.type = CollectModel_Group;
- // FlowAttachmentsModel * model = [[FlowAttachmentsModel alloc] init];
- // model.SoureId = self.Id;
- // model.SoureTypeId = self.type;
- // model.Title = self.currentNoteModel.Title;
- // model.Author = self.currentNoteModel.UserName;
- // vc.sendModel = model;
- // vc.isReturn = YES;
- // [self.navigationController pushViewController:vc animated:YES];
- //}
- - (void)returnToNote
- {
- MoveViewController * vc = [MoveViewController initMoveViewController];
- vc.isFromCreateBookVc = YES;
- vc.TypeId = CreateNotesType;
- vc.ParentId = 0;
- // if (self.IsShareText) {
- // model.Title = self.shareText;
- // model.SoureTypeId = 1;
- // }else{
- // model.SoureId = self.Id;
- // model.SoureTypeId = self.type;
- // model.Title = self.currentNoteModel.Title;
- // model.Author = self.currentNoteModel.UserName;
- // vc.type = CollectModel_NoteBook;
- // }
- vc.sendModel = self.sendModel;
- vc.sendImage = self.sendImage;
- vc.isReturn = YES;
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)returnToTopic
- {
- MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC];
- vc.type = CollectModel_NewTopic;
- // if (self.IsShareText) {
- // model.Title = self.shareText;
- // model.SoureTypeId = 1;
- // }else{
- // model.SoureId = self.Id;
- // model.SoureTypeId = self.type;
- // model.Title = self.currentNoteModel.Title;
- // model.Author = self.currentNoteModel.UserName;
- // vc.type = CollectModel_NewTopic;
- // }
- vc.sendModel = self.sendModel;
- vc.sendImage = self.sendImage;
- vc.isReturn = YES;
- [self.navigationController pushViewController:vc animated:YES];
- }
- @end
|