123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225 |
- //
- // 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"
- #import "CountDataVC.h"
- #import "BookWCDetailVC.h"
- #import "BookListenVC.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,assign) BOOL isFirstLoadMsg;
- @property (nonatomic,assign) 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, assign) NSTimeInterval msgTimelTag;
- //@
- @property (nonatomic,assign) BOOL isWillInputAt;
- @property (strong, nonatomic) NoteBookShareVC *noteBookShareVC;
- @property (strong, nonatomic) UIImage *sendImage;
- //Typing
- @property (nonatomic,assign) BOOL isTyping;
- @property (nonatomic,assign) BOOL enableTyping;
- @property (nonatomic,copy) NSMutableArray *userInfoArray;
- @property (nonatomic,copy) NSMutableArray *chatDistoryArray;
- @property (nonatomic,assign) NSInteger UserId;
- @property (nonatomic,assign) BOOL backRoot;
- @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:^{
- if (weakSelf.backRoot) {
- [weakSelf back1];
- }else{
- weakSelf.hidesBottomBarWhenPushed = NO;
- [weakSelf.navigationController popViewControllerAnimated:YES];
- }
- }];
- [self.tabBtn setAction:^{
- [[UtilsTools getWindow] addSubview:weakSelf.drawerView];
- weakSelf.drawerView.SelectDrawerBlock = ^(NSIndexPath * _Nonnull indexPath) {
- if (![weakSelf.tabBarController isKindOfClass:[TabBarController class]]) {
- [TabBarController sharedTabBarController].tabBar.hidden = NO;
- [weakSelf.tabBarController.navigationController popViewControllerAnimated:NO];
- }
- if ([weakSelf.navigationController.viewControllers count] > 1) {
- [weakSelf.navigationController popToRootViewControllerAnimated:NO];
- }
- switch (indexPath.section) {
- case 0:
- {
- [[TabBarController sharedTabBarController] setSelectedIndex:indexPath.row];
- }
- break;
- case 1:
- {
- 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)}];
- });
- }
- break;
- default:
- {
- [[TabBarController sharedTabBarController] setSelectedIndex:3];
- 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:@(4 + indexPath.row)}];
- });
- }
- break;
- }
- };
- 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)back1
- {
- for (NSInteger i = (self.navigationController.viewControllers.count - 1); i >= 0 ;i --) {
- if ([self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyTDTopicDetailVC")]
- ||[self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"WorkFlowDetailsController")]
- ||[self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"SourceGroupSearchVC")]
- ||[self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyTDTopicSearchVC")]
- ||[self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"TDGroupInfoListVC")]
- ||[self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"CommonNoteVC")]
- ||[self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"SourceHomeVC")]
- ||[self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyInfoVC")]
- ||[self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"MyFavoriteVC")]
- ||[self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"BookWCDetailVC")]
- ||[self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"BookListenVC")]
- ||[self.navigationController.viewControllers[i] isKindOfClass:NSClassFromString(@"CommonHomeVC")]) {
- [self.navigationController popToViewController:self.navigationController.viewControllers[i] animated:YES];
- return;
- }
- }
- }
- - (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 {
- SHOWERROR(@"图片太大,请选择其他图片");
- }
- }];
- }
- }];
- } 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 == 0 ? [AppUserModel sharedAppUserModel].Id : 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 == 0 ? [AppUserModel sharedAppUserModel].Id : 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;
- case CollectModel_InterMail:
- text = @"站内信";
- break;
- case CollectModel_NoSignMail:
- 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 == 0 ? [AppUserModel sharedAppUserModel].Id : 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 == 0 ? [AppUserModel sharedAppUserModel].Id : 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 {
- SHOWERROR(@"获取群组失败");
- }
- }];
- }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];
- }
- #pragma mark - 点击自定义消息体
- - (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];
- MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
- vc.type = CollectModel_Aritle;
- vc.Id = itemModel.Id;
- [weakSelf.navigationController pushViewController:vc 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];
- MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
- vc.type = CollectModel_Aritle;
- vc.Id = itemModel.Id;
- [weakSelf.navigationController pushViewController:vc 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_TopicBooK:{
- if (sourceUserId == [AppUserModel sharedAppUserModel].Id || sourceUserId == 0) {
- NoteBookVC *vc = [NoteBookVC initNoteBookVC];
- vc.listType = MyFavoriteListLevelTypeA;
- vc.FolderId = Id;
- vc.myTitle = title;
- vc.VisitUserId = 0;
- vc.TypeValue = 1;
- [self.navigationController pushViewController:vc animated:YES];
- }else{
- OtherNoteBookVC * vc = [OtherNoteBookVC initOtherNoteBookVC];
- vc.listType = MyFavoriteListLevelTypeA ;
- vc.FolderId = Id;
- vc.CollectionDataId = Id;
- vc.CollectionType = CollectModel_TopicBooK;
- vc.TypeValue = 1;
- vc.myTitle = title;
- vc.VisitUserId = sourceUserId;
- [self.navigationController pushViewController:vc animated:YES];
- }
- }break;
- case CollectModel_TopicSubBooK:{
- if (sourceUserId == [AppUserModel sharedAppUserModel].Id || sourceUserId == 0) {
- NoteBookVC *vc = [NoteBookVC initNoteBookVC];
- vc.listType = MyFavoriteListLevelTypeB;
- vc.FolderId = Id;
- vc.myTitle = title;
- vc.TypeValue = 1;
- [self.navigationController pushViewController:vc animated:YES];
- }else{
- OtherNoteBookVC * vc = [OtherNoteBookVC initOtherNoteBookVC];
- vc.listType = MyFavoriteListLevelTypeB ;
- vc.FolderId = Id;
- vc.CollectionDataId = Id;
- vc.CollectionType = CollectModel_TopicSubBooK;
- vc.TypeValue = 1;
- 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_NoSignMail:{
- 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_StoreSound:
- {
- BookListenVC * vc = [BookListenVC initBookListenVC];
- vc.Id = Id;
- vc.MediaType = MediaMusicType;
- [self.navigationController pushViewController:vc animated:YES];
- }
- break;
- case CollectModel_StoreVideo:
- {
- BookWCDetailVC * vc = [BookWCDetailVC initBookWCDetailVC];
- vc.Id = 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;
- case CollectModel_financeCount:{
- CountDataVC *vc = [CountDataVC initCountDataVC];
- vc.index = 0;
- vc.titleStr = @"财务统计";
- [self.navigationController pushViewController:vc animated:YES];
- }break;
- case CollectModel_affairsCount:{
- CountDataVC *vc = [CountDataVC initCountDataVC];
- vc.index = 1;
- vc.titleStr = @"人事统计";
- [self.navigationController pushViewController:vc animated:YES];
- }break;
- case CollectModel_publishCount:{
- CountDataVC *vc = [CountDataVC initCountDataVC];
- vc.index = 2;
- vc.titleStr = @"出版统计";
- [self.navigationController pushViewController:vc animated:YES];
- }break;
- default:
- break;
- }
- }
- // OtherNoteBookVC * vc = [OtherNoteBookVC initOtherNoteBookVC];
- // vc.listType = MyFavoriteListLevelTypeA ;
- // vc.FolderId = model.CollectionDataId;
- // vc.CollectionDataId = model.CollectionDataId;
- // vc.CollectionType = model.CollectionType;
- // vc.Author = model.Data.Author;
- // vc.TypeValue = 1;
- // vc.myTitle = model.Title;
- // vc.VisitUserId = model.SourceUserId;
- // [self.navigationController pushViewController:vc animated:YES];
- //}break;
- //case CollectModel_TopicSubBooK:{
- // OtherNoteBookVC * vc = [OtherNoteBookVC initOtherNoteBookVC];
- // vc.listType = MyFavoriteListLevelTypeB ;
- // vc.FolderId = model.CollectionDataId;
- // vc.CollectionDataId = model.CollectionDataId;
- // vc.CollectionType = model.CollectionType;
- // vc.Author = model.Data.Author;
- // vc.TypeValue = 1;
- // vc.myTitle = model.Title;
- // vc.VisitUserId = model.SourceUserId;
- // [self.navigationController pushViewController:vc animated:YES];
- - (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) {
- SHOWERROR(@"下载原图失败");
- } 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 {
- SHOWERROR(@"获取原图失败");
- }
- }
- }];
- }
- - (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) {
- SHOWERROR(@"正在下载语音,稍后点击");
- 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) {
- SHOWERROR(@"下载语音失败");
- } 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) {
- SHOWERROR(@"正在下载视频,稍后点击");
- 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) {
- SHOWERROR(@"下载视频失败");
- } 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) {
- SHOWERROR(@"下载文件失败");
- } 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;
- case EMMessageTypeFile:
- {
- EMFileMessageBody *body = (EMFileMessageBody *)model.emModel.body;
- NSLog(@"%@",body.localPath);
- }
- 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) {
- SHOWERROR(@"下载原图失败");
- } 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 {
- SHOWERROR(@"获取原图失败");
- }
- }
- }];
- }
- - (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) {
- if (aError.code == EMErrorMessageRecallTimeLimit) {
- SHOWERROR(@"超过限制撤回时间,无法撤回");
- }
- } 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];
- SHOWERROR(@"转发消息失败");
- } else {
- if (aCompletionBlock) {
- aCompletionBlock(message);
- }
- SHOWSUCCESS(@"转发消息成功");
- }
- }];
- }
- - (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) {
- SHOWERROR(@"转发消息失败");
- } 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) {
- SHOWERROR(@"转发消息失败");
- } 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];
- [weakself returnMessge];
- if (weakself.isFirstLoadMsg) {
- weakself.isFirstLoadMsg = NO;
- [weakself _scrollToBottomRow];
- }
- });
- });
- }
- if (!aError && [aMessages count] == 0) {
- [weakself returnMessge];
- }
-
- [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 - 转发消息
- - (void)returnMessge
- {
- if (self.isReturn) {
- self.backRoot = YES;
- self.isReturn = NO;
- [[NSNotificationCenter defaultCenter] postNotificationName:MESSAGERETURNSUCCESS object:nil];
- switch (self.sendModel.SoureTypeId) {
- case CollectModel_Text:///文本
- {
- [self _sendTextAction:self.sendModel.Title ext:nil];
- }
- break;
- case CollectModel_Aritle:
- {
- [self _sendTextAction:@"文章" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_Aritle),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":@"来自-文章",
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":self.sendModel.MinUrl,
- @"app_url":self.sendModel.Url,
- }];
- }
- break;
- case CollectModel_Notice:
- {
- [self _sendTextAction:@"通知" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_Notice),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":@"来自-通知",
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":self.sendModel.MinUrl,
- @"app_url":self.sendModel.Url,
- }];
- }
- break;
- case CollectModel_NoteBook:
- {
- [self _sendTextAction:@"笔记" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_NoteBook),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":ISEmpty(self.sendModel.Author) ? @"" : self.sendModel.Author,
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":self.sendModel.MinUrl,
- @"app_url":self.sendModel.Url,
- }];
- }
- break;
- case CollectModel_NewTopic:
- {
- [self _sendTextAction:@"话题" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_NewTopic),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":ISEmpty(self.sendModel.Author) ? @"" : self.sendModel.Author,
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":self.sendModel.MinUrl,
- @"app_url":self.sendModel.Url,
- }];
- }
- break;
- case CollectModel_Toipc:
- {
- [self _sendTextAction:@"小组话题" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_Toipc),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_groupname":self.sendModel.GroupName,
- @"app_groupid":@(self.sendModel.GroupId),
- @"app_content":ISEmpty(self.sendModel.Author) ? @"" : self.sendModel.Author,
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":self.sendModel.MinUrl,
- @"app_url":self.sendModel.Url,
- }];
- }
- break;
- case CollectModel_InterMail:
- {
- [self _sendTextAction:@"站内信" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_InterMail),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":ISEmpty(self.sendModel.Author) ? @"" : self.sendModel.Author,
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":self.sendModel.MinUrl,
- @"app_url":self.sendModel.Url,
- }];
- }
- break;
- case CollectModel_NoSignMail:
- {
- [self _sendTextAction:@"站内信" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_InterMail),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":@"匿名",
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":self.sendModel.MinUrl,
- @"app_url":self.sendModel.Url,
- }];
- }
- break;
- case CollectModel_CollectFile:
- {
- [self _sendTextAction:@"收藏文件夹" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_CollectFile),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":@"来自-收藏文件夹",
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":self.sendModel.MinUrl,
- @"app_url":self.sendModel.Url,
- }];
- }
- break;
- case CollectModel_NoteFile:
- {
- [self _sendTextAction:@"笔记文件夹" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_NoteFile),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":@"来自-笔记文件夹",
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":self.sendModel.MinUrl,
- @"app_url":self.sendModel.Url,
- }];
- }
- break;
- case CollectModel_meetMian:
- {
- [self _sendTextAction:@"会议纪要" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_meetMian),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":@"来自-会议纪要",
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":self.sendModel.MinUrl,
- @"app_url":self.sendModel.Url,
- }];
- }
- break;
- case CollectModel_Image:///图片
- {
- [self _sendImageDataAction:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.sendModel.Url]]];
- }
- break;
- case CollectModel_file:///文件
- {
- [self _sendTextAction:@"文件" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_file),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":@"来自-文件",
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":self.sendModel.MinUrl,
- @"app_url":self.sendModel.Url,
- }];
- }
- break;
- case CollectModel_work:///工作
- {
- [self _sendTextAction:@"审批" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_work),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":@"来自-审批",
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":@"",
- @"app_url":@""
- }];
- }
- break;
- case CollectModel_meetDetail:///会议
- {
- [self _sendTextAction:@"会议" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_meetDetail),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":@"来自-会议",
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":@"",
- @"app_url":@""
- }];
- }
- break;
- case CollectModel_financeCount:///文本
- {
- [self _sendTextAction:@"财务统计" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_financeCount),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":@"来自-财务统计",
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":@"",
- @"app_url":@""
- }];
- }
- break;
- case CollectModel_affairsCount:///文本
- {
- [self _sendTextAction:@"人事统计" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_affairsCount),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":@"来自-人事统计",
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":@"",
- @"app_url":@""
- }];
- }
- break;
- case CollectModel_publishCount:///文本
- {
- [self _sendTextAction:@"出版统计" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_publishCount),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":@"来自-出版统计",
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":@"",
- @"app_url":@""
- }];
- }
- break;
- case CollectModel_TopicBooK:///文本
- {
- [self _sendTextAction:@"话题本" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_TopicBooK),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":@"来自-话题本",
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":@"",
- @"app_url":@""
- }];
- }
- break;
- case CollectModel_TopicSubBooK:///文本
- {
- [self _sendTextAction:@"话题本" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_TopicSubBooK),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":@"来自-话题本",
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":@"",
- @"app_url":@""
- }];
- }
- break;
- case CollectModel_StoreSound:///文本
- {
- [self _sendTextAction:@"音频" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_StoreSound),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":ISEmpty(self.sendModel.Author) ? @"" : self.sendModel.Author,
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":self.sendModel.MinUrl,
- @"app_url":self.sendModel.Url
- }];
- }
- break;
- case CollectModel_StoreVideo:///文本
- {
- [self _sendTextAction:@"视频" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_StoreVideo),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":ISEmpty(self.sendModel.Author) ? @"" : self.sendModel.Author,
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":self.sendModel.MinUrl,
- @"app_url":self.sendModel.Url
- }];
- }
- break;
- default:
- {
- [self _sendTextAction:@"出版统计" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_publishCount),
- @"app_title":self.sendModel.Title,
- @"app_id":@(self.sendModel.SoureId),
- @"app_content":@"来自-出版统计",
- @"app_sourceUserId":@(self.sendModel.SourceUserId),
- @"app_min_url":@"",
- @"app_url":@""
- }];
- }
- break;
- }
- }
- }
- #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.CollectionType = CollectModel_NoteBook;
- vc.ParentId = 0;
- 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;
- vc.sendModel = self.sendModel;
- vc.sendImage = self.sendImage;
- vc.isReturn = YES;
- [self.navigationController pushViewController:vc animated:YES];
- }
- @end
|