1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289 |
- //
- // 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;
- @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(@"ChatMsgListVC")]
- ||[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{
- [UIView animateWithDuration:0.25f animations:animation completion:^(BOOL finished) {
- [weakSelf _scrollToBottomRow];
- }];
- }
- }
- - (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 {
- [UIView animateWithDuration:0.25f animations: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;
- case CollectModel_StoreBook:///文本
- {
- [self _sendTextAction:@"图书" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_StoreBook),
- @"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_StoreCousre:///文本
- {
- [self _sendTextAction:@"课程" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_StoreCousre),
- @"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_MediaAritle:///文本
- {
- [self _sendTextAction:@"文章" ext:@{@"app":@(YES),
- @"app_type":@(CollectModel_MediaAritle),
- @"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];
- });
- NSString * text = @"";
- switch (message.body.type) {
- case EMMessageBodyTypeText:
- {
- EMTextMessageBody *body = (EMTextMessageBody *)aBody;
- text = body.text;
- }
- break;
- case EMMessageBodyTypeImage:
- text = @"[图片]";
- break;
- case EMMessageBodyTypeVideo:
- text = @"[视频]";
- break;
- case EMMessageBodyTypeVoice:
- text = @"[语音]";
- break;
- case EMMessageBodyTypeFile:
- text = @"[文件]";
- break;
- default:
- break;
- }
- NSLog(@"%@",@{@"ContactUserId":[NSString stringWithFormat:@"%ld",(long)self.toUserId],@"IndividualGroupId":@(self.IndividualGroupId),@"Text":text});
- 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),@"Text":text} 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
|