EMChatViewController.m 126 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049
  1. //
  2. // EMChatViewController.m
  3. // ChatDemo-UI3.0
  4. //
  5. // Created by XieYajie on 2019/1/18.
  6. // Copyright © 2019 XieYajie. All rights reserved.
  7. //
  8. #import <AVKit/AVKit.h>
  9. #import <Photos/Photos.h>
  10. #import <AVFoundation/AVFoundation.h>
  11. #import <AssetsLibrary/AssetsLibrary.h>
  12. #import <MobileCoreServices/MobileCoreServices.h>
  13. #import "EMChatViewController.h"
  14. #import "EMImageBrowser.h"
  15. #import "EMDateHelper.h"
  16. #import "EMAudioPlayerHelper.h"
  17. #import "EMConversationHelper.h"
  18. #import "EMMessageModel.h"
  19. #import "EMReadReceiptMemberModel.h"
  20. #import "EMChatBar.h"
  21. #import "EMMessageCell.h"
  22. #import "EMMessageTimeCell.h"
  23. #import "EMLocationViewController.h"
  24. #import "EMMsgTranspondViewController.h"
  25. #import "EMAtGroupMembersViewController.h"
  26. #import "FavoritesViewController.h"
  27. #import "ChatMsgDetailChatInfoVC.h"
  28. #import "ChatMsgPersonInfoVC.h"
  29. #import "ChatMsgListImModel.h"
  30. #import "MailListDetailVC.h"
  31. #import "FWZFileGetTool.h"
  32. #import "EMChatFileShowVC.h"
  33. #import "DrawerView.h"
  34. #import "TabBarController.h"
  35. #import "FWZGetNoteBookTool.h"
  36. #import "NoteBookVC.h"
  37. #import "OtherNoteBookVC.h"
  38. #import "MyFavoriteVC.h"
  39. #import "OtherFavoriteVC.h"
  40. #import "TDGroupInfoListVC.h"
  41. #import "DownFileViewController.h"
  42. #import "WorkFlowDetailsController.h"
  43. #import "MyTDGroupViewController.h"
  44. #import "HomeDetailController.h"
  45. #import "MyApprovalPageDetail.h"
  46. #import "NoteBookShareVC.h"
  47. #import "MoveViewController.h"
  48. #import "CountDataVC.h"
  49. @interface EMChatViewController ()<UIScrollViewDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, EMMultiDevicesDelegate, EMChatManagerDelegate, EMGroupManagerDelegate, EMChatroomManagerDelegate, EMChatBarDelegate, EMMessageCellDelegate, EMChatBarEmoticonViewDelegate, EMChatBarRecordAudioViewDelegate,EMMoreFunctionViewDelegate,EMReadReceiptMsgDelegate,NoteBookShareVCDelegate>
  50. @property (nonatomic, strong) dispatch_queue_t msgQueue;
  51. @property (nonatomic, strong) UIView * titleV;
  52. @property (nonatomic, strong) UIButton * backBtn;
  53. @property (nonatomic, strong) UIButton * tabBtn;
  54. @property (nonatomic, strong) UIButton * mangerBtn;
  55. @property (nonatomic, strong) UILabel * titleL;
  56. @property (strong,nonatomic) DrawerView *drawerView;
  57. @property (nonatomic) BOOL isFirstLoadMsg;
  58. @property (nonatomic) BOOL isViewDidAppear;
  59. @property (nonatomic, strong) EMConversationModel *conversationModel;
  60. @property (nonatomic, strong) NSString *moreMsgId; //第一条消息的消息id
  61. @property (nonatomic, strong) UILabel *titleLabel;
  62. @property (nonatomic, strong) UILabel *titleDetailLabel;
  63. @property (nonatomic, strong) EMChatBar *chatBar;
  64. @property (nonatomic, strong) UIImagePickerController *imagePicker;
  65. @property (nonatomic, strong) EMGroup *group;
  66. //阅读回执
  67. @property (nonatomic, strong) EMReadReceiptMsgViewController *readReceiptControl;
  68. //长按操作栏
  69. @property (strong, nonatomic) NSIndexPath *menuIndexPath;
  70. @property (nonatomic, strong) UIMenuController *menuController;
  71. @property (nonatomic, strong) UIMenuItem *deleteMenuItem;
  72. @property (nonatomic, strong) UIMenuItem *copyMenuItem;
  73. @property (nonatomic, strong) UIMenuItem *recallMenuItem;
  74. @property (nonatomic, strong) UIMenuItem *transpondMenuItem;
  75. @property (nonatomic, strong) UIMenuItem *playAndRecordMenuItem;
  76. //消息格式化
  77. @property (nonatomic) NSTimeInterval msgTimelTag;
  78. //@
  79. @property (nonatomic) BOOL isWillInputAt;
  80. @property (strong, nonatomic) NoteBookShareVC *noteBookShareVC;
  81. @property (strong, nonatomic) UIImage *sendImage;
  82. //Typing
  83. @property (nonatomic) BOOL isTyping;
  84. @property (nonatomic) BOOL enableTyping;
  85. @property (nonatomic, copy) NSMutableArray *userInfoArray;
  86. @property (nonatomic, copy) NSMutableArray *chatDistoryArray;
  87. @property (nonatomic, assign) NSInteger UserId;
  88. @end
  89. @implementation EMChatViewController
  90. - (instancetype)initWithConversationId:(NSString *)aId
  91. type:(EMConversationType)aType
  92. createIfNotExist:(BOOL)aIsCreate
  93. {
  94. self = [super init];
  95. if (self) {
  96. EMConversation *conversation = [[EMClient sharedClient].chatManager getConversation:aId type:aType createIfNotExist:aIsCreate];
  97. _conversationModel = [[EMConversationModel alloc] initWithEMModel:conversation];
  98. }
  99. return self;
  100. }
  101. - (instancetype)initWithCoversationModel:(EMConversationModel *)aConversationModel
  102. {
  103. self = [super init];
  104. if (self) {
  105. _conversationModel = aConversationModel;
  106. }
  107. return self;
  108. }
  109. - (void)viewDidLoad {
  110. [super viewDidLoad];
  111. NSLog(@"conversationId===%@",_conversationModel.emModel.conversationId);
  112. // Do any additional setup after loading the view.
  113. self.msgQueue = dispatch_queue_create("emmessage.com", NULL);
  114. self.msgTimelTag = -1;
  115. [self _setupChatSubviews];
  116. [[EMClient sharedClient] addMultiDevicesDelegate:self delegateQueue:nil];
  117. [[EMClient sharedClient].chatManager addDelegate:self delegateQueue:nil];
  118. [[EMClient sharedClient].groupManager addDelegate:self delegateQueue:nil];
  119. [[EMClient sharedClient].roomManager addDelegate:self delegateQueue:nil];
  120. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleWillPushCallController:) name:CALL_PUSH_VIEWCONTROLLER object:nil];
  121. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleCleanMessages:) name:CHAT_CLEANMESSAGES object:nil];
  122. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleGroupSubjectUpdated:) name:GROUP_SUBJECT_UPDATED object:nil];
  123. self.isTyping = NO;
  124. self.enableTyping = NO;
  125. if ([EMDemoOptions sharedOptions].isChatTyping && self.conversationModel.emModel.type == EMConversationTypeChat) {
  126. self.enableTyping = YES;
  127. }
  128. if (self.conversationModel.emModel.type == EMConversationTypeChatRoom) {
  129. [self _joinChatroom];
  130. } else {
  131. self.isFirstLoadMsg = YES;
  132. [self tableViewDidTriggerHeaderRefresh];
  133. }
  134. [self.view addSubview:self.noteBookShareVC.view];
  135. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapTableViewAction:)];
  136. [self.tableView addGestureRecognizer:tap];
  137. }
  138. - (void)viewWillAppear:(BOOL)animated
  139. {
  140. [super viewWillAppear:animated];
  141. self.isViewDidAppear = YES;
  142. [EMConversationHelper markAllAsRead:self.conversationModel];
  143. self.navigationController.navigationBar.hidden = YES;
  144. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deleteConversationMsg) name:DELETECONVERSATIONMSG object:nil];
  145. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  146. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  147. }
  148. - (void)viewWillDisappear:(BOOL)animated
  149. {
  150. [super viewWillDisappear:animated];
  151. self.isViewDidAppear = NO;
  152. if (self.enableTyping && self.isTyping) {
  153. [self _sendEndTyping];
  154. }
  155. if (self.chatBar.textView.text.length > 0) {
  156. [self saveUserInfoInDocument:self.chatBar.textView.text];
  157. }else{
  158. [self clearUserInfoInDocument];
  159. }
  160. [self.chatBar mas_updateConstraints:^(MASConstraintMaker *make) {
  161. if (@available(iOS 11.0, *)) {
  162. make.bottom.mas_equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  163. } else {
  164. make.bottom.mas_equalTo(self.view.mas_bottom);
  165. }
  166. }];
  167. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
  168. [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
  169. }
  170. - (void)dealloc
  171. {
  172. self.isViewDidAppear = NO;
  173. [self.chatBar removeFromSuperview];
  174. [[EMClient sharedClient] removeMultiDevicesDelegate:self];
  175. [[EMClient sharedClient].chatManager removeDelegate:self];
  176. [[EMClient sharedClient].groupManager removeDelegate:self];
  177. [[EMClient sharedClient].roomManager removeDelegate:self];
  178. [[NSNotificationCenter defaultCenter] removeObserver:self];
  179. }
  180. - (BOOL)canBecomeFirstResponder
  181. {
  182. return YES;
  183. }
  184. #pragma mark - Subviews
  185. - (void)_setupChatSubviews
  186. {
  187. NSLog(@"%@",self.conversationModel.emModel.conversationId);
  188. [self _setupNavigationBarTitle];
  189. self.view.backgroundColor = [UIColor whiteColor];
  190. self.showRefreshHeader = YES;
  191. self.chatBar = [[EMChatBar alloc] init];
  192. self.chatBar.delegate = self;
  193. [self.view addSubview:self.chatBar];
  194. [self.chatBar mas_makeConstraints:^(MASConstraintMaker *make) {
  195. make.left.mas_equalTo(self.view);
  196. make.right.mas_equalTo(self.view);
  197. if (@available(iOS 11.0, *)) {
  198. make.bottom.mas_equalTo(self.view.mas_safeAreaLayoutGuideBottom);
  199. } else {
  200. make.bottom.mas_equalTo(self.view.mas_bottom);
  201. }
  202. make.height.offset(56);
  203. }];
  204. if ([self getUserInfoInDocument].length > 0) {
  205. self.chatBar.textView.text = [self getUserInfoInDocument];
  206. }
  207. WS(weakSelf);
  208. self.chatBar.clickMore = ^(NSInteger index, NSString * _Nonnull title) {
  209. [weakSelf selectMoreMenu:index title:title];
  210. };
  211. [self _setupChatBarMoreViews];
  212. self.tableView.backgroundColor = kColor_LightGray;
  213. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  214. self.tableView.rowHeight = UITableViewAutomaticDimension;
  215. self.tableView.estimatedRowHeight = 130;
  216. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  217. make.top.mas_equalTo(self.titleV.mas_bottom);
  218. make.left.mas_equalTo(self.view);
  219. make.right.mas_equalTo(self.view);
  220. make.bottom.mas_equalTo(self.chatBar.mas_top);
  221. }];
  222. }
  223. -(DrawerView *)drawerView{
  224. if(!_drawerView){
  225. _drawerView = [[DrawerView alloc] init];
  226. }
  227. return _drawerView;
  228. }
  229. - (void)_setupNavigationBarTitle
  230. {
  231. [self.view addSubview:self.titleV];
  232. [self.titleV mas_makeConstraints:^(MASConstraintMaker *make) {
  233. make.top.left.right.mas_equalTo(self.view);
  234. make.height.mas_offset(IS_IPHONEX?88:64);
  235. }];
  236. [self.titleV addSubview:self.backBtn];
  237. [self.titleV addSubview:self.tabBtn];
  238. [self.titleV addSubview:self.titleL];
  239. [self.titleV addSubview:self.mangerBtn];
  240. [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  241. make.left.bottom.mas_equalTo(self.titleV);
  242. make.size.mas_offset(CGSizeMake(50, 44));
  243. }];
  244. [self.tabBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  245. make.bottom.mas_equalTo(self.titleV);
  246. make.left.mas_equalTo(self.backBtn.mas_right);
  247. make.size.mas_offset(CGSizeMake(35, 44));
  248. }];
  249. [self.mangerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  250. make.right.bottom.mas_equalTo(self.titleV);
  251. make.size.mas_offset(CGSizeMake(50, 44));
  252. }];
  253. [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  254. make.centerX.mas_equalTo(self.titleV);
  255. make.centerY.mas_equalTo(self.backBtn);
  256. make.height.mas_greaterThanOrEqualTo(10);
  257. make.width.mas_lessThanOrEqualTo(SCREEN_WIDTH - 160);
  258. }];
  259. self.titleL.text = self.conversationModel.name;
  260. WS(weakSelf);
  261. [self.backBtn setAction:^{
  262. weakSelf.hidesBottomBarWhenPushed = NO;
  263. [weakSelf.navigationController popViewControllerAnimated:YES];
  264. }];
  265. [self.tabBtn setAction:^{
  266. [[UtilsTools getWindow] addSubview:weakSelf.drawerView];
  267. weakSelf.drawerView.SelectDrawerBlock = ^(NSIndexPath * _Nonnull indexPath) {
  268. if (![weakSelf.tabBarController isKindOfClass:[TabBarController class]]) {
  269. [TabBarController sharedTabBarController].tabBar.hidden = NO;
  270. [weakSelf.tabBarController.navigationController popViewControllerAnimated:NO];
  271. }
  272. if ([weakSelf.navigationController.viewControllers count] > 1) {
  273. [weakSelf.navigationController popToRootViewControllerAnimated:NO];
  274. }
  275. switch (indexPath.section) {
  276. case 0:
  277. {
  278. [[TabBarController sharedTabBarController] setSelectedIndex:indexPath.row];
  279. }
  280. break;
  281. case 1:
  282. {
  283. switch (indexPath.row) {
  284. case 0:
  285. {
  286. [[TabBarController sharedTabBarController] setSelectedIndex:2];
  287. }
  288. break;
  289. case 1:
  290. {
  291. [[TabBarController sharedTabBarController] setSelectedIndex:2];
  292. }
  293. break;
  294. default:
  295. {
  296. [[TabBarController sharedTabBarController] setSelectedIndex:3];
  297. }
  298. break;
  299. }
  300. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  301. [[NSNotificationCenter defaultCenter] postNotificationName:DRAWERPUSHVC object:nil userInfo:@{VCINDEX:@(indexPath.row)}];
  302. });
  303. }
  304. break;
  305. default:
  306. {
  307. [[TabBarController sharedTabBarController] setSelectedIndex:3];
  308. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  309. [[NSNotificationCenter defaultCenter] postNotificationName:DRAWERPUSHVC object:nil userInfo:@{VCINDEX:@(4 + indexPath.row)}];
  310. });
  311. }
  312. break;
  313. }
  314. };
  315. weakSelf.drawerView.frame = CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT);// - kNavigationHeight
  316. }];
  317. [self.mangerBtn setAction:^{
  318. if (weakSelf.chatType == ChatType_SingleChat) {
  319. ChatMsgPersonInfoVC * vc = [ChatMsgPersonInfoVC initChatMsgPersonInfoVC];
  320. vc.refreshStatus = ^(BOOL isTop) {
  321. weakSelf.isTop = isTop;
  322. };
  323. vc.listId = weakSelf.listId;
  324. vc.IsTop = weakSelf.isTop;
  325. vc.model = weakSelf.sModel;
  326. [weakSelf.navigationController pushViewController:vc animated:YES];
  327. }else{
  328. ChatMsgDetailChatInfoVC *vc = [ChatMsgDetailChatInfoVC initChatMsgDetailChatInfoVC];
  329. vc.GroupChatImId = weakSelf.toUserId;
  330. vc.GroupId = weakSelf.GroupId;
  331. vc.GroupName = weakSelf.conversationModel.name;
  332. vc.upDataChatBlock = ^(NSString * _Nonnull name) {
  333. weakSelf.titleL.text = name;
  334. };
  335. [weakSelf.navigationController pushViewController:vc animated:YES];
  336. }
  337. }];
  338. }
  339. - (void)_setupChatBarMoreViews
  340. {
  341. //语音
  342. NSString *path = [self _getAudioOrVideoPath];
  343. EMChatBarRecordAudioView *recordView = [[EMChatBarRecordAudioView alloc] initWithRecordPath:path];
  344. recordView.delegate = self;
  345. self.chatBar.recordAudioView = recordView;
  346. //表情
  347. EMChatBarEmoticonView *moreEmoticonView = [[EMChatBarEmoticonView alloc] init];
  348. moreEmoticonView.delegate = self;
  349. self.chatBar.moreEmoticonView = moreEmoticonView;
  350. //更多
  351. if (self.conversationModel.emModel.type == EMConversationTypeGroupChat) {
  352. EMMoreFunctionView *moreFunction = [[EMMoreFunctionView alloc]init];
  353. moreFunction.delegate = self;
  354. self.chatBar.moreFunctionView = moreFunction;
  355. }
  356. }
  357. - (NSString *)_getAudioOrVideoPath
  358. {
  359. NSString *path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];
  360. path = [path stringByAppendingPathComponent:@"EMDemoRecord"];
  361. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
  362. [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];
  363. }
  364. return path;
  365. }
  366. #pragma mark - Table view data source
  367. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  368. return 1;
  369. }
  370. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  371. return [self.dataArray count];
  372. }
  373. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  374. id obj = [self.dataArray objectAtIndex:indexPath.row];
  375. NSString *cellString = nil;
  376. if ([obj isKindOfClass:[NSString class]]) {
  377. cellString = (NSString *)obj;
  378. } else if ([obj isKindOfClass:[EMMessageModel class]]) {
  379. EMMessageModel *model = (EMMessageModel *)obj;
  380. if (model.type == EMMessageTypeExtRecall) {
  381. cellString = @"您撤回一条消息";
  382. }
  383. }
  384. if ([cellString length] > 0) {
  385. EMMessageTimeCell *cell = (EMMessageTimeCell *)[tableView dequeueReusableCellWithIdentifier:@"EMMessageTimeCell"];
  386. // Configure the cell...
  387. if (cell == nil || !cell) {
  388. cell = [[EMMessageTimeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"EMMessageTimeCell"];
  389. }
  390. cell.timeLabel.text = cellString;
  391. return cell;
  392. } else {
  393. EMMessageModel *model = (EMMessageModel *)obj;
  394. if ([[model.emModel.ext objectForKey:@"app"] boolValue]) {
  395. model.type = EMMessageTypeExtApp;
  396. }
  397. NSString *identifier = [EMMessageCell cellIdentifierWithDirection:model.direction type:model.type];
  398. EMMessageCell *cell = (EMMessageCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
  399. // Configure the cell...
  400. if (cell == nil || !cell) {
  401. cell = [[EMMessageCell alloc] initWithDirection:model.direction type:model.type];
  402. cell.delegate = self;
  403. }
  404. if (self.chatType == ChatType_SingleChat) {
  405. if (model.emModel.direction == EMMessageDirectionSend){
  406. [cell setIconUrl:[AppUserModel sharedAppUserModel].AvatarUrl];
  407. }else{
  408. [cell setIconUrl:self.ReceiveIcon];
  409. }
  410. }else{
  411. [self.groupUserInfoArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  412. if ([obj isKindOfClass:[NSDictionary class]]) {
  413. if ([[obj objectForKey:@"ImId"] integerValue] == [model.emModel.from integerValue]) {
  414. [cell setIconUrl:[obj objectForKey:@"AvatarUrl"]];
  415. }
  416. }
  417. }];
  418. }
  419. cell.model = model;
  420. return cell;
  421. }
  422. }
  423. #pragma mark - UIScrollViewDelegate
  424. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
  425. {
  426. [self.view endEditing:YES];
  427. [self.chatBar clearMoreViewAndSelectedButton];
  428. }
  429. #pragma mark - UIImagePickerControllerDelegate
  430. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  431. {
  432. NSString *mediaType = info[UIImagePickerControllerMediaType];
  433. if ([mediaType isEqualToString:(NSString *)kUTTypeMovie]) {
  434. NSURL *videoURL = info[UIImagePickerControllerMediaURL];
  435. // we will convert it to mp4 format
  436. NSURL *mp4 = [self _videoConvert2Mp4:videoURL];
  437. NSFileManager *fileman = [NSFileManager defaultManager];
  438. if ([fileman fileExistsAtPath:videoURL.path]) {
  439. NSError *error = nil;
  440. [fileman removeItemAtURL:videoURL error:&error];
  441. if (error) {
  442. NSLog(@"failed to remove file, error:%@.", error);
  443. }
  444. }
  445. [self _sendVideoAction:mp4];
  446. } else {
  447. NSURL *url = info[UIImagePickerControllerReferenceURL];
  448. if (url == nil) {
  449. UIImage *orgImage = info[UIImagePickerControllerOriginalImage];
  450. NSData *data = UIImageJPEGRepresentation(orgImage, 1);
  451. [self _sendImageDataAction:data];
  452. } else {
  453. if ([[UIDevice currentDevice].systemVersion doubleValue] >= 9.0f) {
  454. PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
  455. [result enumerateObjectsUsingBlock:^(PHAsset *asset , NSUInteger idx, BOOL *stop){
  456. if (asset) {
  457. [[PHImageManager defaultManager] requestImageDataForAsset:asset options:nil resultHandler:^(NSData *data, NSString *uti, UIImageOrientation orientation, NSDictionary *dic){
  458. if (data != nil) {
  459. [self _sendImageDataAction:data];
  460. } else {
  461. SHOWERROR(@"图片太大,请选择其他图片");
  462. }
  463. }];
  464. }
  465. }];
  466. } else {
  467. ALAssetsLibrary *alasset = [[ALAssetsLibrary alloc] init];
  468. [alasset assetForURL:url resultBlock:^(ALAsset *asset) {
  469. if (asset) {
  470. ALAssetRepresentation* assetRepresentation = [asset defaultRepresentation];
  471. Byte *buffer = (Byte*)malloc((size_t)[assetRepresentation size]);
  472. NSUInteger bufferSize = [assetRepresentation getBytes:buffer fromOffset:0.0 length:(NSUInteger)[assetRepresentation size] error:nil];
  473. NSData *fileData = [NSData dataWithBytesNoCopy:buffer length:bufferSize freeWhenDone:YES];
  474. [self _sendImageDataAction:fileData];
  475. }
  476. } failureBlock:NULL];
  477. }
  478. }
  479. }
  480. [picker dismissViewControllerAnimated:YES completion:nil];
  481. }
  482. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  483. {
  484. [self.imagePicker dismissViewControllerAnimated:YES completion:nil];
  485. }
  486. #pragma mark - EMChatBarDelegate
  487. - (void)_willInputAt:(EMTextView *)aInputView
  488. {
  489. do {
  490. if (self.conversationModel.emModel.type != EMConversationTypeGroupChat) {
  491. break;
  492. }
  493. NSString *text = aInputView.text;
  494. // if (![text hasSuffix:@"@"]) {
  495. // break;
  496. // }
  497. EMGroup *group = [EMGroup groupWithId:self.conversationModel.emModel.conversationId];
  498. if (!group) {
  499. break;
  500. }
  501. [self.view endEditing:YES];
  502. EMAtGroupMembersViewController *controller = [[EMAtGroupMembersViewController alloc] initWithGroup:group];
  503. [self.navigationController pushViewController:controller animated:YES];
  504. [controller setSelectedCompletion:^(NSString * _Nonnull aName) {
  505. NSString *newStr = [NSString stringWithFormat:@"%@%@ ", text, aName];
  506. aInputView.text = newStr;
  507. aInputView.selectedRange = NSMakeRange(newStr.length, 0);
  508. [aInputView becomeFirstResponder];
  509. }];
  510. } while (0);
  511. }
  512. - (BOOL)inputView:(EMTextView *)aInputView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
  513. {
  514. self.isWillInputAt = NO;
  515. if ([text isEqualToString:@"\n"]) {
  516. [self _sendTextAction:aInputView.text ext:nil];
  517. return NO;
  518. } else if ([text isEqualToString:@"@"]) {
  519. self.isWillInputAt = YES;
  520. } else if ([text length] == 0) {
  521. }
  522. return YES;
  523. }
  524. - (void)inputViewDidChange:(EMTextView *)aInputView
  525. {
  526. if (self.isWillInputAt && self.conversationModel.emModel.type == EMConversationTypeGroupChat) {
  527. NSString *text = aInputView.text;
  528. if ([text hasSuffix:@"@"]) {
  529. self.isWillInputAt = NO;
  530. [self _willInputAt:aInputView];
  531. }
  532. }
  533. if (self.enableTyping) {
  534. if (!self.isTyping) {
  535. self.isTyping = YES;
  536. [self _sendBeginTyping];
  537. }
  538. }
  539. }
  540. - (void)chatBarClickMoreType:(SmartBarType)type
  541. {
  542. WS(weakSelf);
  543. switch (type) {
  544. case SmartBarPhoto:
  545. {
  546. [self chatBarDidPhotoAction];
  547. }
  548. break;
  549. case SmartBarCamera:
  550. {
  551. [self chatBarDidCameraAction];
  552. }
  553. break;
  554. case SmartBarNotes:
  555. {
  556. [[FWZGetNoteBookTool sharedTool] openNoteBookListChooseNoteBookBlock:^(NSMutableArray<MyNoteBookSubModel *> * _Nonnull noteArr) {
  557. NSLog(@"SmartBarNotes %@",noteArr);
  558. for (MyNoteBookSubModel * model in noteArr) {
  559. switch (model.AttributeValue) {
  560. case 1:
  561. {
  562. [weakSelf _sendTextAction:@"笔记" ext:@{@"app":@(YES),
  563. @"app_type":@(CollectModel_NoteBook),
  564. @"app_title":model.Title,
  565. @"app_id":@(model.MiddleId),
  566. @"app_content":@"来自-笔记",
  567. @"app_sourceUserId":@(model.SourceUserId == 0 ? [AppUserModel sharedAppUserModel].Id : model.SourceUserId),
  568. @"app_min_url":@"",
  569. @"app_url":@""
  570. }];
  571. }
  572. break;
  573. default:
  574. {
  575. [weakSelf _sendTextAction:@"笔记" ext:@{@"app":@(YES),
  576. @"app_type":@(CollectModel_NoteFile),
  577. @"app_title":model.FolderName,
  578. @"app_id":@(model.Id),
  579. @"app_sourceUserId":@(model.SourceUserId == 0 ? [AppUserModel sharedAppUserModel].Id : model.SourceUserId),
  580. @"app_content":@"来自-笔记",
  581. @"app_min_url":@"",
  582. @"app_url":@""
  583. }];
  584. }
  585. break;
  586. }
  587. }
  588. }];
  589. }
  590. break;
  591. case SmartBarCollection:
  592. {
  593. [[FWZGetNoteBookTool sharedTool] openCollectListChooseCollectBlock:^(NSMutableArray<MyFavoriteSubModel *> * _Nonnull collectArr) {
  594. NSLog(@"SmartBarCollection %@",collectArr);
  595. for (MyFavoriteSubModel * model in collectArr) {
  596. [weakSelf sendExtWithCollectModel:model];
  597. }
  598. }];
  599. }
  600. break;
  601. case SmartBarFile:
  602. {
  603. [self chatBarDidFileAction];
  604. }
  605. break;
  606. default:
  607. break;
  608. }
  609. }
  610. - (void)sendExtWithCollectModel:(MyFavoriteSubModel *)model
  611. {
  612. NSString * text = @"";
  613. switch (model.CollectionType) {
  614. case CollectModel_NewTopic:
  615. text = @"话题";
  616. break;
  617. case CollectModel_Toipc:
  618. text = @"话题";
  619. break;
  620. case CollectModel_Notice:
  621. text = @"通知";
  622. break;
  623. case CollectModel_NoteBook:
  624. text = @"笔记";
  625. break;
  626. case CollectModel_CollectFile:
  627. text = @"文件夹";
  628. break;
  629. case CollectModel_NoteFile:
  630. text = @"文件夹";
  631. break;
  632. case CollectModel_file:
  633. text = @"文件";
  634. break;
  635. case CollectModel_Image:
  636. text = @"图片";
  637. break;
  638. case CollectModel_meetMian:
  639. text = @"会议纪要";
  640. break;
  641. default:
  642. text = @"话题";
  643. break;
  644. }
  645. switch (model.AttributeValue) {
  646. case 1:
  647. {
  648. [self _sendTextAction:text ext:@{@"app":@(YES),
  649. @"app_type":@(model.CollectionType),
  650. @"app_title":model.Title,
  651. @"app_content":@"来自-收藏",
  652. @"app_sourceUserId":@(model.SourceUserId == 0 ? [AppUserModel sharedAppUserModel].Id : model.SourceUserId),
  653. @"app_id":@(model.CollectionDataId),
  654. @"app_min_url":model.Data.MinFile,
  655. @"app_url":model.Data.File
  656. }];
  657. }
  658. break;
  659. default:
  660. {
  661. [self _sendTextAction:text ext:@{@"app":@(YES),
  662. @"app_type":@(CollectModel_CollectFile),
  663. @"app_title":model.FolderName,
  664. @"app_content":@"来自-收藏",
  665. @"app_sourceUserId":@(model.SourceUserId == 0 ? [AppUserModel sharedAppUserModel].Id : model.SourceUserId),
  666. @"app_id":@(model.Id),
  667. @"app_min_url":model.Data.MinFile,
  668. @"app_url":model.Data.File
  669. }];
  670. }
  671. break;
  672. }
  673. }
  674. - (void)chatBarDidPhotoAction
  675. {
  676. WS(weakSelf);
  677. [self.view endEditing:YES];
  678. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:9 delegate:nil];
  679. [imagePickerVc setNavLeftBarButtonSettingBlock:^(UIButton *leftButton){
  680. leftButton.hidden = YES;
  681. }];
  682. imagePickerVc.showSelectBtn = NO;
  683. imagePickerVc.allowCrop = YES;
  684. imagePickerVc.cropRect = CGRectMake(0, (SCREEN_HEIGHT - SCREEN_WIDTH) * 0.5, SCREEN_WIDTH, SCREEN_WIDTH);
  685. imagePickerVc.allowTakePicture = NO;
  686. imagePickerVc.allowTakeVideo = NO;
  687. imagePickerVc.allowPickingOriginalPhoto = NO;
  688. imagePickerVc.allowPickingGif = NO;
  689. [imagePickerVc setIsStatusBarDefault:YES];
  690. [imagePickerVc setNaviTitleColor:[UIColor blackColor]];
  691. [imagePickerVc setBarItemTextColor:[UIColor blackColor]];
  692. [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
  693. // if (assets.count > 0) {
  694. // for (PHAsset *asset in assets) {
  695. // PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
  696. // options.version = PHImageRequestOptionsVersionCurrent;
  697. // options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
  698. // PHImageManager *manager = [PHImageManager defaultManager];
  699. // [manager requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
  700. // AVURLAsset *urlAsset = (AVURLAsset *)asset;
  701. // NSURL *url = urlAsset.URL;
  702. // [weakSelf _sendVideoAction:url];
  703. // }];
  704. // }
  705. // }
  706. if (photos.count > 0) {
  707. for (UIImage * image in photos) {
  708. NSData *data = UIImageJPEGRepresentation(image, 1);
  709. [weakSelf _sendImageDataAction:data];
  710. }
  711. }
  712. }];
  713. [self presentViewController:imagePickerVc animated:YES completion:nil];
  714. }
  715. - (void)chatBarDidCameraAction
  716. {
  717. [self.view endEditing:YES];
  718. //#if TARGET_IPHONE_SIMULATOR
  719. // [EMAlertController showErrorAlert:@"模拟器不支持照相机"];
  720. //#elif TARGET_OS_IPHONE
  721. self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
  722. self.imagePicker.mediaTypes = @[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie];
  723. [self presentViewController:self.imagePicker animated:YES completion:nil];
  724. //#endif
  725. }
  726. - (void)chatBarDidFileAction
  727. {
  728. WS(weakSelf);
  729. [[FWZFileGetTool sharedTool] openFileWithCrop:YES showImgBlock:^(NSString * _Nonnull fileUrlStr) {
  730. } choosFileBlock:^(NSData * _Nonnull fileData, NSString * _Nonnull fileName) {
  731. // EMFileMessageBody * body = [[EMFileMessageBody alloc] initWithData:fileData displayName:fileName];
  732. // [weakSelf _sendMessageWithBody:body ext:nil isUpload:YES];
  733. SHOWLOADING
  734. [[HttpManager sharedHttpManager] HeaderUploadFileUrl:Host(Modify_UserImages_Post) parameters:@{} fileData:fileData fileKey:@"file" fileName:fileName mimeType:@"multipart/form-data" success:^(id _Nonnull responseObject) {
  735. REMOVESHOW
  736. NSDictionary * dict = responseObject[0];
  737. if ([dict[@"FileType"] isEqualToString:@"image"]) {
  738. [weakSelf _sendImageDataAction:fileData];
  739. }else{
  740. [weakSelf _sendTextAction:@"文件" ext:@{@"app":@(YES),
  741. @"app_type":@(CollectModel_file),
  742. @"app_title":fileName,
  743. @"app_content":@"来自-文件夹",
  744. @"app_sourceUserId":@([AppUserModel sharedAppUserModel].Id),
  745. @"app_id":@([dict[@"FileId"] integerValue]),
  746. @"app_min_url":dict[@"MinAbsolutePath"],
  747. @"app_url":dict[@"AbsolutePath"]
  748. }];
  749. }
  750. } failure:^(NSError * _Nonnull error) {
  751. REMOVESHOW
  752. }];
  753. }];
  754. }
  755. - (void)chatBarDidLocationAction
  756. {
  757. EMLocationViewController *controller = [[EMLocationViewController alloc] init];
  758. [controller setSendCompletion:^(CLLocationCoordinate2D aCoordinate, NSString * _Nonnull aAddress) {
  759. [self _sendLocationAction:aCoordinate address:aAddress];
  760. }];
  761. UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
  762. [self.navigationController presentViewController:navController animated:YES completion:nil];
  763. }
  764. - (void)chatBarDidCallAction
  765. {
  766. self.alertController = [UIAlertController alertControllerWithTitle:@"实时通话类型" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  767. __weak typeof(self) weakself = self;
  768. if (self.conversationModel.emModel.type == EMConversationTypeChat) {
  769. [self.alertController addAction:[UIAlertAction actionWithTitle:@"语音通话" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  770. [weakself.chatBar clearMoreViewAndSelectedButton];
  771. [[NSNotificationCenter defaultCenter] postNotificationName:CALL_MAKE1V1 object:@{CALL_CHATTER:weakself.conversationModel.emModel.conversationId, CALL_TYPE:@(EMCallTypeVoice)}];
  772. }]];
  773. [self.alertController addAction:[UIAlertAction actionWithTitle:@"视频通话" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  774. [weakself.chatBar clearMoreViewAndSelectedButton];
  775. [[NSNotificationCenter defaultCenter] postNotificationName:CALL_MAKE1V1 object:@{CALL_CHATTER:weakself.conversationModel.emModel.conversationId, CALL_TYPE:@(EMCallTypeVideo)}];
  776. }]];
  777. } else {
  778. [self.alertController addAction:[UIAlertAction actionWithTitle:@"会议模式" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  779. [weakself.chatBar clearMoreViewAndSelectedButton];
  780. [[NSNotificationCenter defaultCenter] postNotificationName:CALL_MAKECONFERENCE object:@{CALL_TYPE:@(EMConferenceTypeLargeCommunication), CALL_MODEL:weakself.conversationModel, NOTIF_NAVICONTROLLER:self.navigationController}];
  781. }]];
  782. [self.alertController addAction:[UIAlertAction actionWithTitle:@"互动模式" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  783. [weakself.chatBar clearMoreViewAndSelectedButton];
  784. [[NSNotificationCenter defaultCenter] postNotificationName:CALL_MAKECONFERENCE object:@{CALL_TYPE:@(EMConferenceTypeLive), CALL_MODEL:weakself.conversationModel, NOTIF_NAVICONTROLLER:self.navigationController}];
  785. }]];
  786. }
  787. [self.alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  788. }]];
  789. [[NSNotificationCenter defaultCenter] postNotificationName:@"didAlert" object:@{@"alert":self.alertController}];
  790. [self presentViewController:self.alertController animated:YES completion:nil];
  791. }
  792. //阅读回执跳转
  793. - (void)chatBarMoreFunctionReadReceipt
  794. {
  795. self.readReceiptControl = [[EMReadReceiptMsgViewController alloc]init];
  796. self.readReceiptControl.delegate = self;
  797. self.readReceiptControl.modalPresentationStyle = 0;
  798. //[self.navigationController pushViewController:readReceipt animated:NO];
  799. [self presentViewController:self.readReceiptControl animated:NO completion:nil];
  800. }
  801. //阅读回执发送信息
  802. - (void)sendReadReceiptMsg:(NSString *)msg
  803. {
  804. NSString *str = msg;
  805. NSLog(@"\n%@",str);
  806. if (self.conversationModel.emModel.type == EMConversationTypeGroupChat) {
  807. [[EMClient sharedClient].groupManager getGroupSpecificationFromServerWithId:self.conversationModel.emModel.conversationId completion:^(EMGroup *aGroup, EMError *aError) {
  808. NSLog(@"\n -------- sendError: %@",aError);
  809. if (!aError) {
  810. self.group = aGroup;
  811. //是群主才可以发送阅读回执信息
  812. [self _sendTextAction:str ext:@{MSG_EXT_READ_RECEIPT:@"receipt"}];
  813. } else {
  814. SHOWERROR(@"获取群组失败");
  815. }
  816. }];
  817. }else {
  818. [self _sendTextAction:str ext:nil];
  819. }
  820. }
  821. - (void)chatBarDidShowMoreViewAction:(BOOL)isKeyBord
  822. {
  823. WS(weakSelf);
  824. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  825. dispatch_async(dispatch_get_main_queue(), ^{
  826. [weakSelf.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
  827. make.bottom.mas_equalTo(weakSelf.chatBar.mas_top);
  828. }];
  829. [weakSelf performSelector:@selector(_scrollToBottomRow) withObject:nil afterDelay:0.1];
  830. });
  831. });
  832. }
  833. #pragma mark - EMChatBarRecordAudioViewDelegate
  834. - (void)chatBarRecordAudioViewStartRecord
  835. {
  836. }
  837. - (void)chatBarRecordAudioViewStopRecord:(NSString *)aPath
  838. timeLength:(NSInteger)aTimeLength
  839. {
  840. EMVoiceMessageBody *body = [[EMVoiceMessageBody alloc] initWithLocalPath:aPath displayName:@"audio"];
  841. body.duration = (int)aTimeLength;
  842. if(body.duration < 1){
  843. [self showHint:@"按键时间太短."];
  844. return;
  845. }
  846. [self _sendMessageWithBody:body ext:nil isUpload:YES];
  847. }
  848. - (void)chatBarRecordAudioViewCancelRecord
  849. {
  850. }
  851. #pragma mark - EMChatBarEmoticonViewDelegate
  852. - (void)didSelectedEmoticonModel:(EMEmoticonModel *)aModel
  853. {
  854. if (aModel.type == EMEmotionTypeEmoji) {
  855. [self.chatBar inputViewAppendText:aModel.name];
  856. } if (aModel.type == EMEmotionTypeGif) {
  857. NSDictionary *ext = @{MSG_EXT_GIF:@(YES), MSG_EXT_GIF_ID:aModel.eId};
  858. [self _sendTextAction:aModel.name ext:ext];
  859. }
  860. }
  861. - (void)didChatBarEmoticonViewSendAction
  862. {
  863. [self _sendTextAction:self.chatBar.textView.text ext:nil];
  864. }
  865. #pragma mark - EMMessageCellDelegate
  866. //阅读回执详情
  867. - (void)messageReadReceiptDetil:(EMMessageCell *)aCell
  868. {
  869. self.readReceiptControl = [[EMReadReceiptMsgViewController alloc] initWithMessageCell:aCell groupId:self.conversationModel.emModel.conversationId];
  870. self.readReceiptControl.modalPresentationStyle = 0;
  871. //[self.navigationController pushViewController:readReceiptControl animated:NO];
  872. [self presentViewController:self.readReceiptControl animated:NO completion:nil];
  873. }
  874. - (void)messageCellDidSelected:(EMMessageCell *)aCell
  875. {
  876. if (aCell.model.type == EMMessageTypeImage) {
  877. [self _imageMessageCellDidSelected:aCell];
  878. } else if (aCell.model.type == EMMessageTypeLocation) {
  879. [self _locationMessageCellDidSelected:aCell];
  880. } else if (aCell.model.type == EMMessageTypeVoice) {
  881. [self _audioMessageCellDidSelected:aCell];
  882. } else if (aCell.model.type == EMMessageTypeVideo) {
  883. [self _videoMessageCellDidSelected:aCell];
  884. } else if (aCell.model.type == EMMessageTypeFile) {
  885. [self _fileMessageCellDidSelected:aCell];
  886. } else if (aCell.model.type == EMMessageTypeExtCall) {
  887. [self _callMessageCellDidSelected:aCell];
  888. } else if (aCell.model.type == EMMessageTypeExtApp) {
  889. [self appPushWithDictionary:aCell.model.emModel.ext];
  890. } else if (aCell.model.type == EMMessageTypeText) {
  891. }
  892. }
  893. - (void)messageClickUserIcon:(EMMessageCell *)aCell
  894. {
  895. WS(weakSelf);
  896. EMMessage * eModel = (EMMessage *)aCell.model.emModel;
  897. if (self.chatType == ChatType_SingleChat) {
  898. if (eModel.direction == EMMessageDirectionSend){
  899. self.UserId = [AppUserModel sharedAppUserModel].Id;
  900. }else{
  901. self.UserId = self.toUserId;
  902. }
  903. }else{
  904. [self.groupUserInfoArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  905. if ([obj isKindOfClass:[NSDictionary class]]) {
  906. if ([[obj objectForKey:@"ImId"] integerValue] == [eModel.from integerValue]) {
  907. weakSelf.UserId = [[obj objectForKey:@"UserId"] integerValue];
  908. }
  909. }
  910. }];
  911. }
  912. MailListDetailVC * vc = [MailListDetailVC initMailListDetailVC];
  913. vc.indexId = self.UserId;
  914. [self.navigationController pushViewController:vc animated:YES];
  915. }
  916. #pragma mark - 点击自定义消息体
  917. - (void)appPushWithDictionary:(NSDictionary *)dict
  918. {
  919. WS(weakSelf);
  920. CollectModelType type = [[dict objectForKey:@"app_type"] intValue];
  921. NSInteger sourceUserId = [[dict objectForKey:@"app_sourceUserId"] integerValue];
  922. NSInteger Id = [[dict objectForKey:@"app_id"] integerValue];
  923. NSString * title = [dict objectForKey:@"app_title"];
  924. NSString * url = [dict objectForKey:@"app_url"];
  925. switch (type) {
  926. case CollectModel_Group:
  927. {
  928. TDGroupInfoListVC * vc = [TDGroupInfoListVC initTDGroupInfoListVC];
  929. vc.GroupId = Id;
  930. vc.titleStr = title;
  931. [self.navigationController pushViewController:vc animated:YES];
  932. }break;
  933. case CollectModel_file:{
  934. DownFileViewController * vc = [[DownFileViewController alloc] init];
  935. FlowAttachmentsModel * model = [[FlowAttachmentsModel alloc] init];
  936. model.Title = title;
  937. model.SoureId = Id;
  938. model.Url = url;
  939. model.MinUrl = dict[@"app_min_url"];
  940. vc.model = model;
  941. [self.navigationController pushViewController:vc animated:YES];
  942. }break;
  943. case CollectModel_Image:{
  944. DownFileViewController * vc = [[DownFileViewController alloc] init];
  945. FlowAttachmentsModel * model = [[FlowAttachmentsModel alloc] init];
  946. model.Title = title;
  947. model.SoureId = Id;
  948. model.Url = url;
  949. model.MinUrl = dict[@"app_min_url"];
  950. vc.model = model;
  951. [self.navigationController pushViewController:vc animated:YES];
  952. }break;
  953. case CollectModel_Aritle:{
  954. SHOWLOADING
  955. [[HttpManager sharedHttpManager] GETWithUrl:[NSString stringWithFormat:@"%@%ld",Article_Detail_Get,(long)Id] parameters:@{} success:^(id _Nonnull responseObject) {
  956. REMOVESHOW;
  957. Item *itemModel = [[Item alloc]initWithDictionary:responseObject error:nil];
  958. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  959. vc.type = CollectModel_Aritle;
  960. vc.Id = itemModel.Id;
  961. [weakSelf.navigationController pushViewController:vc animated:YES];
  962. } failure:^(NSError * _Nonnull error) {
  963. SHOWERROR([ZYCTool handerResultData:error]);
  964. }];
  965. }break;
  966. case CollectModel_Text:{
  967. SHOWLOADING
  968. [[HttpManager sharedHttpManager] GETWithUrl:[NSString stringWithFormat:@"%@%ld",Article_Detail_Get,(long)Id] parameters:@{} success:^(id _Nonnull responseObject) {
  969. REMOVESHOW;
  970. Item *itemModel = [[Item alloc]initWithDictionary:responseObject error:nil];
  971. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  972. vc.type = CollectModel_Aritle;
  973. vc.Id = itemModel.Id;
  974. [weakSelf.navigationController pushViewController:vc animated:YES];
  975. } failure:^(NSError * _Nonnull error) {
  976. SHOWERROR([ZYCTool handerResultData:error]);
  977. }];
  978. }break;
  979. case CollectModel_Notice:{
  980. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  981. vc.type = CollectModel_Notice;
  982. vc.Id = Id;
  983. [self.navigationController pushViewController:vc animated:YES];
  984. }break;
  985. case CollectModel_Toipc:{
  986. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  987. vc.type = CollectModel_Toipc;
  988. vc.Id = Id;
  989. [self.navigationController pushViewController:vc animated:YES];
  990. }break;
  991. case CollectModel_NewTopic:{
  992. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  993. vc.type = CollectModel_NewTopic;
  994. vc.Id = Id;
  995. [self.navigationController pushViewController:vc animated:YES];
  996. }break;
  997. case CollectModel_NoteBook:{
  998. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  999. vc.type = CollectModel_NoteBook;
  1000. vc.Id = Id;
  1001. [self.navigationController pushViewController:vc animated:YES];
  1002. }break;
  1003. case CollectModel_Collect:{
  1004. }break;
  1005. case CollectModel_CollectFile:{
  1006. if (sourceUserId == [AppUserModel sharedAppUserModel].Id || sourceUserId == 0) {
  1007. MyFavoriteVC *vc = [MyFavoriteVC initMyFavoriteVC];
  1008. vc.listType = Id == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
  1009. vc.FolderId = Id;
  1010. vc.myTitle = title;
  1011. [self.navigationController pushViewController:vc animated:YES];
  1012. }else{
  1013. OtherFavoriteVC *vc = [OtherFavoriteVC initOtherFavoriteVC];
  1014. vc.listType = Id == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
  1015. vc.FolderId = Id;
  1016. vc.myTitle = title;
  1017. vc.VisitUserId = sourceUserId;
  1018. [self.navigationController pushViewController:vc animated:YES];
  1019. }
  1020. }break;
  1021. case CollectModel_NoteFile:{
  1022. if (sourceUserId == [AppUserModel sharedAppUserModel].Id || sourceUserId == 0) {
  1023. NoteBookVC *vc = [NoteBookVC initNoteBookVC];
  1024. vc.listType = Id == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
  1025. vc.FolderId = Id;
  1026. vc.myTitle = title;
  1027. vc.VisitUserId = 0;
  1028. [self.navigationController pushViewController:vc animated:YES];
  1029. }else{
  1030. OtherNoteBookVC *vc = [OtherNoteBookVC initOtherNoteBookVC];
  1031. vc.listType = Id == 0 ? MyFavoriteListLevelTypeA : MyFavoriteListLevelTypeB;
  1032. vc.FolderId = Id;
  1033. vc.myTitle = title;
  1034. vc.VisitUserId = sourceUserId;
  1035. [self.navigationController pushViewController:vc animated:YES];
  1036. }
  1037. }break;
  1038. case CollectModel_InterMail:{
  1039. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  1040. vc.type = CollectModel_InterMail;
  1041. vc.Id = Id;
  1042. [self.navigationController pushViewController:vc animated:YES];
  1043. }break;
  1044. case CollectModel_meetDetail:{
  1045. WorkFlowDetailsController *vc = [[WorkFlowDetailsController alloc] initWithId:Id];
  1046. [self.navigationController pushViewController:vc animated:YES];
  1047. }break;
  1048. case CollectModel_work:{
  1049. MyApprovalPageDetail * vc = [[MyApprovalPageDetail alloc]init];
  1050. vc.pageType = Type_ONEC;
  1051. vc.indexId = Id;
  1052. vc.title = title;
  1053. vc.TodoId = Id;
  1054. [self.navigationController pushViewController:vc animated:YES];
  1055. }break;
  1056. case CollectModel_meetMian:{
  1057. MyTDTopicDetailVC * vc = [MyTDTopicDetailVC initMyTDTopicDetailVC];
  1058. vc.type = CollectModel_meetMian;
  1059. vc.Id = Id;
  1060. [self.navigationController pushViewController:vc animated:YES];
  1061. }break;
  1062. case CollectModel_financeCount:{
  1063. CountDataVC *vc = [CountDataVC initCountDataVC];
  1064. vc.index = 0;
  1065. vc.titleStr = @"财务统计";
  1066. [self.navigationController pushViewController:vc animated:YES];
  1067. }break;
  1068. case CollectModel_affairsCount:{
  1069. CountDataVC *vc = [CountDataVC initCountDataVC];
  1070. vc.index = 1;
  1071. vc.titleStr = @"人事统计";
  1072. [self.navigationController pushViewController:vc animated:YES];
  1073. }break;
  1074. case CollectModel_publishCount:{
  1075. CountDataVC *vc = [CountDataVC initCountDataVC];
  1076. vc.index = 2;
  1077. vc.titleStr = @"出版统计";
  1078. [self.navigationController pushViewController:vc animated:YES];
  1079. }break;
  1080. default:
  1081. break;
  1082. }
  1083. }
  1084. - (void)_imageMessageCellDidSelected:(EMMessageCell *)aCell
  1085. {
  1086. __weak typeof(self) weakself = self;
  1087. void (^downloadThumbBlock)(EMMessageModel *aModel) = ^(EMMessageModel *aModel) {
  1088. [weakself showHint:@"获取缩略图..."];
  1089. [[EMClient sharedClient].chatManager downloadMessageThumbnail:aModel.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
  1090. if (!error) {
  1091. [weakself.tableView reloadData];
  1092. }
  1093. }];
  1094. };
  1095. EMImageMessageBody *body = (EMImageMessageBody*)aCell.model.emModel.body;
  1096. BOOL isCustomDownload = !([EMClient sharedClient].options.isAutoTransferMessageAttachments);
  1097. if (body.thumbnailDownloadStatus == EMDownloadStatusFailed) {
  1098. if (isCustomDownload) {
  1099. [self _showCustomTransferFileAlertView];
  1100. } else {
  1101. downloadThumbBlock(aCell.model);
  1102. }
  1103. return;
  1104. }
  1105. BOOL isAutoDownloadThumbnail = [EMClient sharedClient].options.isAutoDownloadThumbnail;
  1106. if (body.thumbnailDownloadStatus == EMDownloadStatusPending && !isAutoDownloadThumbnail) {
  1107. downloadThumbBlock(aCell.model);
  1108. return;
  1109. }
  1110. if (body.downloadStatus == EMDownloadStatusSucceed) {
  1111. UIImage *image = [UIImage imageWithContentsOfFile:body.localPath];
  1112. if (image) {
  1113. [[EMImageBrowser sharedBrowser] showImages:@[image] fromController:self];
  1114. return;
  1115. }
  1116. }
  1117. if (isCustomDownload) {
  1118. [self _showCustomTransferFileAlertView];
  1119. return;
  1120. }
  1121. [self showHudInView:self.view hint:@"下载原图..."];
  1122. [[EMClient sharedClient].chatManager downloadMessageAttachment:aCell.model.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
  1123. [weakself hideHud];
  1124. if (error) {
  1125. SHOWERROR(@"下载原图失败");
  1126. } else {
  1127. if (message.direction == EMMessageDirectionReceive && !message.isReadAcked) {
  1128. [[EMClient sharedClient].chatManager sendMessageReadAck:message.messageId toUser:message.conversationId completion:nil];
  1129. }
  1130. NSString *localPath = [(EMImageMessageBody *)message.body localPath];
  1131. UIImage *image = [UIImage imageWithContentsOfFile:localPath];
  1132. if (image) {
  1133. [[EMImageBrowser sharedBrowser] showImages:@[image] fromController:self];
  1134. } else {
  1135. SHOWERROR(@"获取原图失败");
  1136. }
  1137. }
  1138. }];
  1139. }
  1140. - (void)_locationMessageCellDidSelected:(EMMessageCell *)aCell
  1141. {
  1142. EMLocationMessageBody *body = (EMLocationMessageBody *)aCell.model.emModel.body;
  1143. EMLocationViewController *controller = [[EMLocationViewController alloc] initWithLocation:CLLocationCoordinate2DMake(body.latitude, body.longitude)];
  1144. UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
  1145. [self.navigationController presentViewController:navController animated:YES completion:nil];
  1146. }
  1147. - (void)_audioMessageCellDidSelected:(EMMessageCell *)aCell
  1148. {
  1149. if (aCell.model.isPlaying) {
  1150. [[EMAudioPlayerHelper sharedHelper] stopPlayer];
  1151. aCell.model.isPlaying = NO;
  1152. [self.tableView reloadData];
  1153. return;
  1154. }
  1155. EMVoiceMessageBody *body = (EMVoiceMessageBody*)aCell.model.emModel.body;
  1156. if (body.downloadStatus == EMDownloadStatusDownloading) {
  1157. SHOWERROR(@"正在下载语音,稍后点击");
  1158. return;
  1159. }
  1160. __weak typeof(self) weakself = self;
  1161. void (^playBlock)(EMMessageModel *aModel) = ^(EMMessageModel *aModel) {
  1162. id model = [EMAudioPlayerHelper sharedHelper].model;
  1163. if (model && [model isKindOfClass:[EMMessageModel class]]) {
  1164. EMMessageModel *oldModel = (EMMessageModel *)model;
  1165. if (oldModel.isPlaying) {
  1166. oldModel.isPlaying = NO;
  1167. }
  1168. }
  1169. if (!aModel.emModel.isReadAcked) {
  1170. [[EMClient sharedClient].chatManager sendMessageReadAck:aModel.emModel.messageId toUser:aModel.emModel.conversationId completion:nil];
  1171. }
  1172. aModel.isPlaying = YES;
  1173. if (!aModel.emModel.isRead) {
  1174. aModel.emModel.isRead = YES;
  1175. }
  1176. [weakself.tableView reloadData];
  1177. [[EMAudioPlayerHelper sharedHelper] startPlayerWithPath:body.localPath model:aModel AVAudioSessionCategory:AVAudioSessionCategoryPlayback completion:^(NSError * _Nonnull error) {
  1178. aModel.isPlaying = NO;
  1179. [weakself.tableView reloadData];
  1180. }];
  1181. };
  1182. if (body.downloadStatus == EMDownloadStatusSucceed) {
  1183. playBlock(aCell.model);
  1184. return;
  1185. }
  1186. if (![EMClient sharedClient].options.isAutoTransferMessageAttachments) {
  1187. [self _showCustomTransferFileAlertView];
  1188. return;
  1189. }
  1190. [self showHudInView:self.view hint:@"下载语音..."];
  1191. [[EMClient sharedClient].chatManager downloadMessageAttachment:aCell.model.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
  1192. [weakself hideHud];
  1193. if (error) {
  1194. SHOWERROR(@"下载语音失败");
  1195. } else {
  1196. playBlock(aCell.model);
  1197. }
  1198. }];
  1199. }
  1200. - (void)_videoMessageCellDidSelected:(EMMessageCell *)aCell
  1201. {
  1202. EMVideoMessageBody *body = (EMVideoMessageBody*)aCell.model.emModel.body;
  1203. NSFileManager *fileManager = [NSFileManager defaultManager];
  1204. BOOL isCustomDownload = !([EMClient sharedClient].options.isAutoTransferMessageAttachments);
  1205. if (body.thumbnailDownloadStatus == EMDownloadStatusFailed || ![fileManager fileExistsAtPath:body.thumbnailLocalPath]) {
  1206. [self showHint:@"下载缩略图"];
  1207. if (!isCustomDownload) {
  1208. [[EMClient sharedClient].chatManager downloadMessageThumbnail:aCell.model.emModel progress:nil completion:nil];
  1209. }
  1210. }
  1211. if (body.downloadStatus == EMDownloadStatusDownloading) {
  1212. SHOWERROR(@"正在下载视频,稍后点击");
  1213. return;
  1214. }
  1215. void (^playBlock)(NSString *aPath) = ^(NSString *aPathe) {
  1216. NSURL *videoURL = [NSURL fileURLWithPath:aPathe];
  1217. AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];
  1218. playerViewController.player = [AVPlayer playerWithURL:videoURL];
  1219. playerViewController.videoGravity = AVLayerVideoGravityResizeAspect;
  1220. playerViewController.showsPlaybackControls = YES;
  1221. [self presentViewController:playerViewController animated:YES completion:^{
  1222. [playerViewController.player play];
  1223. }];
  1224. };
  1225. if (body.downloadStatus == EMDownloadStatusSuccessed && [fileManager fileExistsAtPath:body.localPath]) {
  1226. playBlock(body.localPath);
  1227. return;
  1228. }
  1229. if (isCustomDownload) {
  1230. [self _showCustomTransferFileAlertView];
  1231. } else {
  1232. [self showHudInView:self.view hint:@"下载视频..."];
  1233. __weak typeof(self) weakself = self;
  1234. [[EMClient sharedClient].chatManager downloadMessageAttachment:aCell.model.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
  1235. [weakself hideHud];
  1236. if (error) {
  1237. SHOWERROR(@"下载视频失败");
  1238. } else {
  1239. if (!message.isReadAcked) {
  1240. [[EMClient sharedClient].chatManager sendMessageReadAck:message.messageId toUser:message.conversationId completion:nil];
  1241. }
  1242. playBlock([(EMVideoMessageBody*)message.body localPath]);
  1243. }
  1244. }];
  1245. }
  1246. }
  1247. - (void)_fileMessageCellDidSelected:(EMMessageCell *)aCell
  1248. {
  1249. WS(weakSelf);
  1250. [[EMClient sharedClient].chatManager downloadMessageAttachment:aCell.model.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
  1251. [weakSelf hideHud];
  1252. if (error) {
  1253. SHOWERROR(@"下载文件失败");
  1254. } else {
  1255. if (message.direction == EMMessageDirectionReceive && !message.isReadAcked) {
  1256. [[EMClient sharedClient].chatManager sendMessageReadAck:message.messageId toUser:message.conversationId completion:nil];
  1257. }
  1258. NSString *remotePath = [(EMImageMessageBody *)message.body remotePath];
  1259. NSString *displayName = [(EMImageMessageBody *)message.body displayName];
  1260. dispatch_async(dispatch_get_main_queue(), ^{
  1261. EMChatFileShowVC * vc = [EMChatFileShowVC initEMChatFileShowVC];
  1262. vc.fileUrl = remotePath;
  1263. vc.titleStr = displayName;
  1264. [weakSelf.navigationController pushViewController:vc animated:YES];
  1265. });
  1266. }
  1267. }];
  1268. }
  1269. - (void)_callMessageCellDidSelected:(EMMessageCell *)aCell
  1270. {
  1271. [[NSNotificationCenter defaultCenter] postNotificationName:CALL_SELECTCONFERENCECELL object:aCell.model.emModel];
  1272. }
  1273. - (void)messageCellDidLongPress:(EMMessageCell *)aCell
  1274. {
  1275. self.menuIndexPath = [self.tableView indexPathForCell:aCell];
  1276. [self _showMenuViewController:aCell model:aCell.model];
  1277. }
  1278. - (void)messageCellDidResend:(EMMessageModel *)aModel
  1279. {
  1280. if (aModel.emModel.status != EMMessageStatusFailed && aModel.emModel.status != EMMessageStatusPending) {
  1281. return;
  1282. }
  1283. __weak typeof(self) weakself = self;
  1284. [[[EMClient sharedClient] chatManager] resendMessage:aModel.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
  1285. [weakself.tableView reloadData];
  1286. }];
  1287. [self.tableView reloadData];
  1288. }
  1289. #pragma mark - EMMultiDevicesDelegate
  1290. - (void)multiDevicesGroupEventDidReceive:(EMMultiDevicesEvent)aEvent
  1291. groupId:(NSString *)aGroupId
  1292. ext:(id)aExt
  1293. {
  1294. if (aEvent == EMMultiDevicesEventGroupDestroy || aEvent == EMMultiDevicesEventGroupLeave) {
  1295. if ([self.conversationModel.emModel.conversationId isEqualToString:aGroupId]) {
  1296. [self.navigationController popToViewController:self animated:YES];
  1297. [self.navigationController popViewControllerAnimated:YES];
  1298. }
  1299. }
  1300. }
  1301. #pragma mark - EMChatManagerDelegate
  1302. - (BOOL)_isNeedSendReadAckForMessage:(EMMessage *)aMessage
  1303. isMarkRead:(BOOL)aIsMarkRead
  1304. {
  1305. if (!self.isViewDidAppear || aMessage.direction == EMMessageDirectionSend || aMessage.isReadAcked || aMessage.chatType != EMChatTypeChat) {
  1306. return NO;
  1307. }
  1308. EMMessageBody *body = aMessage.body;
  1309. if (!aIsMarkRead && (body.type == EMMessageBodyTypeVideo || body.type == EMMessageBodyTypeVoice || body.type == EMMessageBodyTypeImage)) {
  1310. return NO;
  1311. }
  1312. return YES;
  1313. }
  1314. - (void)messagesDidReceive:(NSArray *)aMessages
  1315. {
  1316. __weak typeof(self) weakself = self;
  1317. dispatch_async(self.msgQueue, ^{
  1318. NSString *conId = weakself.conversationModel.emModel.conversationId;
  1319. NSMutableArray *msgArray = [[NSMutableArray alloc] init];
  1320. for (int i = 0; i < [aMessages count]; i++) {
  1321. EMMessage *msg = aMessages[i];
  1322. if (![msg.conversationId isEqualToString:conId]) {
  1323. continue;
  1324. }
  1325. if (msg.isNeedGroupAck && !msg.isReadAcked) {
  1326. [[EMClient sharedClient].chatManager sendGroupMessageReadAck:msg.messageId toGroup:msg.conversationId content:@"123" completion:^(EMError *error) {
  1327. if (error) {
  1328. NSLog(@"\n ------ error %@",error.errorDescription);
  1329. }
  1330. }];
  1331. }
  1332. if ([weakself _isNeedSendReadAckForMessage:msg isMarkRead:NO]) {
  1333. [[EMClient sharedClient].chatManager sendMessageReadAck:msg.messageId toUser:msg.conversationId completion:nil];
  1334. }
  1335. [weakself.conversationModel.emModel markMessageAsReadWithId:msg.messageId error:nil];
  1336. [msgArray addObject:msg];
  1337. }
  1338. NSArray *formated = [weakself _formatMessages:msgArray];
  1339. [weakself.dataArray addObjectsFromArray:formated];
  1340. dispatch_async(dispatch_get_main_queue(), ^{
  1341. [weakself.tableView reloadData];
  1342. [weakself _scrollToBottomRow];
  1343. });
  1344. });
  1345. }
  1346. - (void)messagesDidRecall:(NSArray *)aMessages {
  1347. __block NSMutableArray *sameObject = [NSMutableArray array];
  1348. [aMessages enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  1349. EMMessage *msg = (EMMessage *)obj;
  1350. [self.dataArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  1351. if ([obj isKindOfClass:[EMMessageModel class]]) {
  1352. EMMessageModel *model = (EMMessageModel *)obj;
  1353. if ([model.emModel.messageId isEqualToString:msg.messageId]) {
  1354. // 如果上一行是时间,且下一行也是时间
  1355. if (idx - 1 >= 0) {
  1356. id nextMessage = nil;
  1357. id prevMessage = [self.dataArray objectAtIndex:(idx - 1)];
  1358. if (idx + 1 < [self.dataArray count]) {
  1359. nextMessage = [self.dataArray objectAtIndex:(idx + 1)];
  1360. }
  1361. if ((!nextMessage
  1362. || [nextMessage isKindOfClass:[NSString class]])
  1363. && [prevMessage isKindOfClass:[NSString class]]) {
  1364. [sameObject addObject:prevMessage];
  1365. }
  1366. }
  1367. [sameObject addObject:model];
  1368. *stop = YES;
  1369. }
  1370. }
  1371. }];
  1372. }];
  1373. if (sameObject.count > 0) {
  1374. for (id obj in sameObject) {
  1375. [self.dataArray removeObject:obj];
  1376. }
  1377. [self.tableView reloadData];
  1378. }
  1379. }
  1380. //为了从home会话列表切进来触发 群组阅读回执 和 消息已读回执
  1381. - (void)sendDidReadReceipt
  1382. {
  1383. __weak typeof(self) weakself = self;
  1384. NSString *conId = weakself.conversationModel.emModel.conversationId;
  1385. void (^block)(NSArray *aMessages, EMError *aError) = ^(NSArray *aMessages, EMError *aError) {
  1386. NSLog(@"\n-------unread: %d messageCount: %lu msgid: %@",self.conversationModel.emModel.unreadMessagesCount,(unsigned long)[aMessages count],self.moreMsgId);
  1387. if (!aError && [aMessages count]) {
  1388. for (int i = 0; i < [aMessages count]; i++) {
  1389. EMMessage *msg = aMessages[i];
  1390. if (![msg.conversationId isEqualToString:conId]) {
  1391. continue;
  1392. }
  1393. if (msg.isNeedGroupAck && !msg.isReadAcked) {
  1394. [[EMClient sharedClient].chatManager sendGroupMessageReadAck:msg.messageId toGroup:msg.conversationId content:@"123" completion:^(EMError *error) {
  1395. if (error) {
  1396. NSLog(@"\n ------ error %@",error.errorDescription);
  1397. }
  1398. }];
  1399. }
  1400. if ([weakself _isNeedSendReadAckForMessage:msg isMarkRead:NO] && (weakself.conversationModel.emModel.type == EMConversationTypeChat)) {
  1401. [[EMClient sharedClient].chatManager sendMessageReadAck:msg.messageId toUser:msg.conversationId completion:nil];
  1402. [weakself.conversationModel.emModel markMessageAsReadWithId:msg.messageId error:nil];
  1403. }
  1404. }
  1405. }
  1406. };
  1407. [self.conversationModel.emModel loadMessagesStartFromId:self.moreMsgId count:self.conversationModel.emModel.unreadMessagesCount searchDirection:EMMessageSearchDirectionUp completion:block];
  1408. }
  1409. //收到群消息已读回执
  1410. - (void)groupMessageDidRead:(EMMessage *)aMessage groupAcks:(NSArray *)aGroupAcks
  1411. {
  1412. EMMessageModel *msgModel;
  1413. EMGroupMessageAck *msgAck = aGroupAcks[0];
  1414. for (int i=0; i<[self.dataArray count]; i++) {
  1415. if([self.dataArray[i] isKindOfClass:[EMMessageModel class]]){
  1416. msgModel = (EMMessageModel *)self.dataArray[i];
  1417. }else{
  1418. continue;
  1419. }
  1420. if([msgModel.emModel.messageId isEqualToString:msgAck.messageId]){
  1421. msgModel.readReceiptCount = [NSString stringWithFormat:@"阅读回执,已读用户(%d)",msgModel.emModel.groupAckCount];
  1422. msgModel.emModel.isReadAcked = YES;
  1423. [[EMClient sharedClient].chatManager sendMessageReadAck:msgModel.emModel.messageId toUser:msgModel.emModel.conversationId completion:nil];
  1424. [self.dataArray setObject:msgModel atIndexedSubscript:i];
  1425. __weak typeof(self) weakself = self;
  1426. dispatch_async(dispatch_get_main_queue(), ^{
  1427. [weakself.tableView reloadData];
  1428. [weakself _scrollToBottomRow];
  1429. });
  1430. break;
  1431. }
  1432. }
  1433. }
  1434. // 收到已读回执
  1435. - (void)messagesDidRead:(NSArray *)aMessages
  1436. {
  1437. __weak typeof(self) weakself = self;
  1438. dispatch_async(self.msgQueue, ^{
  1439. NSString *conId = weakself.conversationModel.emModel.conversationId;
  1440. __block BOOL isReladView = NO;
  1441. for (EMMessage *message in aMessages) {
  1442. if (![conId isEqualToString:message.conversationId]){
  1443. continue;
  1444. }
  1445. [weakself.dataArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  1446. if ([obj isKindOfClass:[EMMessageModel class]]) {
  1447. EMMessageModel *model = (EMMessageModel *)obj;
  1448. if ([model.emModel.messageId isEqualToString:message.messageId]) {
  1449. model.emModel.isReadAcked = YES;
  1450. isReladView = YES;
  1451. *stop = YES;
  1452. }
  1453. }
  1454. }];
  1455. }
  1456. BOOL changeRead = NO;
  1457. NSInteger msgCount = weakself.dataArray.count - 1;
  1458. for (NSInteger i = msgCount; i >= 0; i --) {
  1459. if ([weakself.dataArray[i] isKindOfClass:[EMMessageModel class]]) {
  1460. EMMessageModel *model = (EMMessageModel *)weakself.dataArray[i];
  1461. if (model.emModel.isReadAcked == YES)
  1462. {
  1463. changeRead = YES;
  1464. }
  1465. if (changeRead) {
  1466. model.emModel.isReadAcked = YES;
  1467. }
  1468. }
  1469. }
  1470. if (isReladView) {
  1471. dispatch_async(dispatch_get_main_queue(), ^{
  1472. [weakself.tableView reloadData];
  1473. });
  1474. }
  1475. });
  1476. }
  1477. - (void)messageStatusDidChange:(EMMessage *)aMessage
  1478. error:(EMError *)aError
  1479. {
  1480. __weak typeof(self) weakself = self;
  1481. dispatch_async(self.msgQueue, ^{
  1482. NSString *conId = weakself.conversationModel.emModel.conversationId;
  1483. if (![conId isEqualToString:aMessage.conversationId]){
  1484. return ;
  1485. }
  1486. __block NSUInteger index = NSNotFound;
  1487. __block EMMessageModel *reloadModel = nil;
  1488. [self.dataArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
  1489. if ([obj isKindOfClass:[EMMessageModel class]]) {
  1490. EMMessageModel *model = (EMMessageModel *)obj;
  1491. if ([model.emModel.messageId isEqualToString:aMessage.messageId]) {
  1492. reloadModel = model;
  1493. index = idx;
  1494. *stop = YES;
  1495. }
  1496. }
  1497. }];
  1498. if (index != NSNotFound) {
  1499. dispatch_async(dispatch_get_main_queue(), ^{
  1500. [weakself.dataArray replaceObjectAtIndex:index withObject:reloadModel];
  1501. [weakself.tableView beginUpdates];
  1502. [weakself.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
  1503. [weakself.tableView endUpdates];
  1504. });
  1505. }
  1506. });
  1507. }
  1508. - (void)cmdMessagesDidReceive:(NSArray *)aCmdMessages
  1509. {
  1510. __weak typeof(self) weakself = self;
  1511. dispatch_async(self.msgQueue, ^{
  1512. NSString *conId = weakself.conversationModel.emModel.conversationId;
  1513. for (EMMessage *message in aCmdMessages) {
  1514. if (![conId isEqualToString:message.conversationId]) {
  1515. continue;
  1516. }
  1517. EMCmdMessageBody *body = (EMCmdMessageBody *)message.body;
  1518. NSString *str = @"";
  1519. if ([body.action isEqualToString:MSG_TYPING_BEGIN]) {
  1520. str = @"正在输入...";
  1521. }
  1522. dispatch_async(dispatch_get_main_queue(), ^{
  1523. self.titleDetailLabel.text = str;
  1524. });
  1525. }
  1526. });
  1527. }
  1528. #pragma mark - EMGroupManagerDelegate
  1529. - (void)didLeaveGroup:(EMGroup *)aGroup
  1530. reason:(EMGroupLeaveReason)aReason
  1531. {
  1532. EMConversation *conversation = self.conversationModel.emModel;
  1533. if (conversation.type == EMChatTypeGroupChat && [aGroup.groupId isEqualToString:conversation.conversationId]) {
  1534. [self.navigationController popToViewController:self animated:YES];
  1535. [self.navigationController popViewControllerAnimated:YES];
  1536. }
  1537. }
  1538. #pragma mark - EMChatroomManagerDelegate
  1539. //有用户加入聊天室
  1540. - (void)userDidJoinChatroom:(EMChatroom *)aChatroom
  1541. user:(NSString *)aUsername
  1542. {
  1543. EMConversation *conversation = self.conversationModel.emModel;
  1544. if (conversation.type == EMChatTypeChatRoom && [aChatroom.chatroomId isEqualToString:conversation.conversationId]) {
  1545. NSString *str = [NSString stringWithFormat:@"%@ 进入聊天室", aUsername];
  1546. [self showHint:str];
  1547. }
  1548. }
  1549. - (void)userDidLeaveChatroom:(EMChatroom *)aChatroom
  1550. user:(NSString *)aUsername
  1551. {
  1552. EMConversation *conversation = self.conversationModel.emModel;
  1553. if (conversation.type == EMChatTypeChatRoom && [aChatroom.chatroomId isEqualToString:conversation.conversationId]) {
  1554. NSString *str = [NSString stringWithFormat:@"%@ 离开聊天室", aUsername];
  1555. [self showHint:str];
  1556. }
  1557. }
  1558. - (void)didDismissFromChatroom:(EMChatroom *)aChatroom
  1559. reason:(EMChatroomBeKickedReason)aReason
  1560. {
  1561. EMConversation *conversation = self.conversationModel.emModel;
  1562. if (conversation.type == EMChatTypeChatRoom && [aChatroom.chatroomId isEqualToString:conversation.conversationId]) {
  1563. [self.navigationController popToViewController:self animated:YES];
  1564. [self.navigationController popViewControllerAnimated:YES];
  1565. }
  1566. }
  1567. #pragma mark - KeyBoard
  1568. - (void)keyBoardWillShow:(NSNotification *)note
  1569. {
  1570. // 获取用户信息
  1571. NSDictionary *userInfo = [NSDictionary dictionaryWithDictionary:note.userInfo];
  1572. // 获取键盘高度
  1573. CGRect keyBoardBounds = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  1574. CGFloat keyBoardHeight = keyBoardBounds.size.height;
  1575. // 获取键盘动画时间
  1576. CGFloat animationTime = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
  1577. // 定义好动作
  1578. WS(weakSelf);
  1579. void (^animation)(void) = ^void(void) {
  1580. [weakSelf.chatBar mas_updateConstraints:^(MASConstraintMaker *make) {
  1581. if (@available(iOS 11.0, *)) {
  1582. make.bottom.mas_equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom).offset(-keyBoardHeight + EMVIEWBOTTOMMARGIN);
  1583. } else {
  1584. make.bottom.mas_equalTo(weakSelf.view.mas_bottom).offset(-keyBoardHeight);
  1585. }
  1586. }];
  1587. };
  1588. if (animationTime > 0) {
  1589. [UIView animateWithDuration:animationTime animations:animation completion:^(BOOL finished) {
  1590. [weakSelf _scrollToBottomRow];
  1591. }];
  1592. } else {
  1593. animation();
  1594. }
  1595. }
  1596. - (void)keyBoardWillHide:(NSNotification *)note
  1597. {
  1598. // 获取用户信息
  1599. NSDictionary *userInfo = [NSDictionary dictionaryWithDictionary:note.userInfo];
  1600. // 获取键盘动画时间
  1601. CGFloat animationTime = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
  1602. // 定义好动作
  1603. WS(weakSelf);
  1604. void (^animation)(void) = ^void(void) {
  1605. [weakSelf.chatBar mas_updateConstraints:^(MASConstraintMaker *make) {
  1606. if (@available(iOS 11.0, *)) {
  1607. make.bottom.mas_equalTo(weakSelf.view.mas_safeAreaLayoutGuideBottom);
  1608. } else {
  1609. make.bottom.mas_equalTo(weakSelf.view.mas_bottom);
  1610. }
  1611. }];
  1612. };
  1613. if (animationTime > 0) {
  1614. [UIView animateWithDuration:animationTime animations:animation];
  1615. } else {
  1616. animation();
  1617. }
  1618. if (self.enableTyping) {
  1619. [self _sendEndTyping];
  1620. }
  1621. }
  1622. #pragma mark - NSNotification
  1623. - (UIImagePickerController *)imagePicker
  1624. {
  1625. if (!_imagePicker) {
  1626. _imagePicker = [[UIImagePickerController alloc] init];
  1627. _imagePicker.delegate = self;
  1628. }
  1629. return _imagePicker;
  1630. }
  1631. - (void)handleWillPushCallController:(NSNotification *)aNotif
  1632. {
  1633. [self.imagePicker dismissViewControllerAnimated:YES completion:nil];
  1634. [[EMImageBrowser sharedBrowser] dismissViewController];
  1635. [[EMAudioPlayerHelper sharedHelper] stopPlayer];
  1636. }
  1637. - (void)handleCleanMessages:(NSNotification *)aNotif
  1638. {
  1639. NSString *chatId = aNotif.object;
  1640. if (chatId && [chatId isEqualToString:self.conversationModel.emModel.conversationId]) {
  1641. [self.conversationModel.emModel deleteAllMessages:nil];
  1642. [self.dataArray removeAllObjects];
  1643. [self.tableView reloadData];
  1644. }
  1645. }
  1646. - (void)handleGroupSubjectUpdated:(NSNotification *)aNotif
  1647. {
  1648. EMGroup *group = aNotif.object;
  1649. if (!group) {
  1650. return;
  1651. }
  1652. NSString *groupId = group.groupId;
  1653. if ([groupId isEqualToString:self.conversationModel.emModel.conversationId]) {
  1654. self.conversationModel.name = group.subject;
  1655. self.titleLabel.text = group.subject;
  1656. }
  1657. }
  1658. #pragma mark - Gesture Recognizer
  1659. - (void)handleTapTableViewAction:(UITapGestureRecognizer *)aTap
  1660. {
  1661. if (aTap.state == UIGestureRecognizerStateEnded) {
  1662. [self.view endEditing:YES];
  1663. [self.chatBar clearMoreViewAndSelectedButton];
  1664. [self performSelector:@selector(_scrollToBottomRow) withObject:nil afterDelay:0.1];
  1665. }
  1666. }
  1667. #pragma mark - Private
  1668. - (void)_joinChatroom
  1669. {
  1670. __weak typeof(self) weakself = self;
  1671. [self showHudInView:self.view hint:@"加入聊天室..."];
  1672. [[EMClient sharedClient].roomManager joinChatroom:self.conversationModel.emModel.conversationId completion:^(EMChatroom *aChatroom, EMError *aError) {
  1673. [weakself hideHud];
  1674. if (aError) {
  1675. [EMAlertController showErrorAlert:@"加入聊天室失败"];
  1676. [weakself.navigationController popViewControllerAnimated:YES];
  1677. } else {
  1678. weakself.isFirstLoadMsg = YES;
  1679. [weakself tableViewDidTriggerHeaderRefresh];
  1680. }
  1681. }];
  1682. }
  1683. - (void)_scrollToBottomRow
  1684. {
  1685. if ([self.dataArray count] > 0) {
  1686. NSInteger toRow = self.dataArray.count - 1;
  1687. NSIndexPath *toIndexPath = [NSIndexPath indexPathForRow:toRow inSection:0];
  1688. [self.tableView scrollToRowAtIndexPath:toIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
  1689. }
  1690. }
  1691. - (void)_showCustomTransferFileAlertView
  1692. {
  1693. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"(づ。◕‿‿◕。)づ" message:@"需要自定义实现上传附件方法" preferredStyle:UIAlertControllerStyleAlert];
  1694. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleCancel handler:nil];
  1695. [alertController addAction:okAction];
  1696. [self presentViewController:alertController animated:YES completion:nil];
  1697. }
  1698. - (NSURL *)_videoConvert2Mp4:(NSURL *)movUrl
  1699. {
  1700. NSURL *mp4Url = nil;
  1701. AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:movUrl options:nil];
  1702. NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
  1703. if ([compatiblePresets containsObject:AVAssetExportPresetHighestQuality]) {
  1704. AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]initWithAsset:avAsset presetName:AVAssetExportPresetHighestQuality];
  1705. NSString *mp4Path = [NSString stringWithFormat:@"%@/%d%d.mp4", [self _getAudioOrVideoPath], (int)[[NSDate date] timeIntervalSince1970], arc4random() % 100000];
  1706. mp4Url = [NSURL fileURLWithPath:mp4Path];
  1707. exportSession.outputURL = mp4Url;
  1708. exportSession.shouldOptimizeForNetworkUse = YES;
  1709. exportSession.outputFileType = AVFileTypeMPEG4;
  1710. dispatch_semaphore_t wait = dispatch_semaphore_create(0l);
  1711. [exportSession exportAsynchronouslyWithCompletionHandler:^{
  1712. switch ([exportSession status]) {
  1713. case AVAssetExportSessionStatusFailed: {
  1714. NSLog(@"failed, error:%@.", exportSession.error);
  1715. } break;
  1716. case AVAssetExportSessionStatusCancelled: {
  1717. NSLog(@"cancelled.");
  1718. } break;
  1719. case AVAssetExportSessionStatusCompleted: {
  1720. NSLog(@"completed.");
  1721. } break;
  1722. default: {
  1723. NSLog(@"others.");
  1724. } break;
  1725. }
  1726. dispatch_semaphore_signal(wait);
  1727. }];
  1728. long timeout = dispatch_semaphore_wait(wait, DISPATCH_TIME_FOREVER);
  1729. if (timeout) {
  1730. NSLog(@"timeout.");
  1731. }
  1732. if (wait) {
  1733. //dispatch_release(wait);
  1734. wait = nil;
  1735. }
  1736. }
  1737. return mp4Url;
  1738. }
  1739. #pragma mark - Menu Controller
  1740. - (UIMenuController *)menuController
  1741. {
  1742. if (_menuController == nil) {
  1743. _menuController = [UIMenuController sharedMenuController];
  1744. }
  1745. return _menuController;
  1746. }
  1747. - (UIMenuItem *)deleteMenuItem
  1748. {
  1749. if (_deleteMenuItem == nil) {
  1750. _deleteMenuItem = [[UIMenuItem alloc] initWithTitle:@"删除" action:@selector(deleteMenuItemAction:)];
  1751. }
  1752. return _deleteMenuItem;
  1753. }
  1754. - (UIMenuItem *)copyMenuItem
  1755. {
  1756. if (_copyMenuItem == nil) {
  1757. _copyMenuItem = [[UIMenuItem alloc] initWithTitle:@"复制" action:@selector(copyMenuItemAction:)];
  1758. }
  1759. return _copyMenuItem;
  1760. }
  1761. - (UIMenuItem *)transpondMenuItem
  1762. {
  1763. if (_transpondMenuItem == nil) {
  1764. _transpondMenuItem = [[UIMenuItem alloc] initWithTitle:@"转发" action:@selector(transpondMenuItemAction:)];
  1765. }
  1766. return _transpondMenuItem;
  1767. }
  1768. - (UIMenuItem *)recallMenuItem
  1769. {
  1770. if (_recallMenuItem == nil) {
  1771. _recallMenuItem = [[UIMenuItem alloc] initWithTitle:@"撤回" action:@selector(recallMenuItemAction:)];
  1772. }
  1773. return _recallMenuItem;
  1774. }
  1775. - (UIMenuItem *)playAndRecordMenuItem
  1776. {
  1777. if (_playAndRecordMenuItem == nil) {
  1778. _playAndRecordMenuItem = [[UIMenuItem alloc] initWithTitle:@"听筒播放" action:@selector(playAndRecordMenuItemAction:)];
  1779. }
  1780. return _playAndRecordMenuItem;
  1781. }
  1782. //删除消息
  1783. - (void)deleteMenuItemAction:(UIMenuItem *)aItem
  1784. {
  1785. if (self.menuIndexPath == nil) {
  1786. return;
  1787. }
  1788. EMMessageModel *model = [self.dataArray objectAtIndex:self.menuIndexPath.row];
  1789. [self.conversationModel.emModel deleteMessageWithId:model.emModel.messageId error:nil];
  1790. NSMutableIndexSet *indexs = [NSMutableIndexSet indexSetWithIndex:self.menuIndexPath.row];
  1791. NSMutableArray *indexPaths = [NSMutableArray arrayWithObjects:self.menuIndexPath, nil];
  1792. if (self.menuIndexPath.row - 1 >= 0) {
  1793. id nextMessage = nil;
  1794. id prevMessage = [self.dataArray objectAtIndex:(self.menuIndexPath.row - 1)];
  1795. if (self.menuIndexPath.row + 1 < [self.dataArray count]) {
  1796. nextMessage = [self.dataArray objectAtIndex:(self.menuIndexPath.row + 1)];
  1797. }
  1798. if ((!nextMessage || [nextMessage isKindOfClass:[NSString class]]) && [prevMessage isKindOfClass:[NSString class]]) {
  1799. [indexs addIndex:self.menuIndexPath.row - 1];
  1800. [indexPaths addObject:[NSIndexPath indexPathForRow:(self.menuIndexPath.row - 1) inSection:0]];
  1801. }
  1802. }
  1803. [self.dataArray removeObjectsAtIndexes:indexs];
  1804. [self.tableView beginUpdates];
  1805. [self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
  1806. [self.tableView endUpdates];
  1807. if ([self.dataArray count] == 0) {
  1808. self.msgTimelTag = -1;
  1809. }
  1810. self.menuIndexPath = nil;
  1811. }
  1812. - (void)copyMenuItemAction:(UIMenuItem *)aItem
  1813. {
  1814. if (self.menuIndexPath == nil) {
  1815. return;
  1816. }
  1817. EMMessageModel *model = [self.dataArray objectAtIndex:self.menuIndexPath.row];
  1818. if (model.type == EMMessageTypeText) {
  1819. EMTextMessageBody *body = (EMTextMessageBody *)model.emModel.body;
  1820. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1821. pasteboard.string = body.text;
  1822. }
  1823. if (model.type == EMMessageTypeImage) {
  1824. EMMessageCell *cell = [self.tableView cellForRowAtIndexPath:self.menuIndexPath];
  1825. [[UIPasteboard generalPasteboard]setData:UIImagePNGRepresentation(cell.bubbleView.image) forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]];
  1826. }
  1827. self.menuIndexPath = nil;
  1828. }
  1829. - (void)transpondMenuItemAction:(UIMenuItem *)aItem
  1830. {
  1831. if (self.menuIndexPath == nil) {
  1832. return;
  1833. }
  1834. EMMessageModel *model = [self.dataArray objectAtIndex:self.menuIndexPath.row];
  1835. // EMMsgTranspondViewController *controller = [[EMMsgTranspondViewController alloc] initWithModel:model];
  1836. // [self.navigationController pushViewController:controller animated:YES];
  1837. //
  1838. // __weak typeof(self) weakself = self;
  1839. // [controller setDoneCompletion:^(EMMessageModel * _Nonnull aModel, NSString * _Nonnull aUsername) {
  1840. // [weakself _transpondMsg:aModel toUser:aUsername];
  1841. // }];
  1842. // if (self.IsShareText) {
  1843. // model.Title = self.shareText;
  1844. // model.SoureTypeId = 1;
  1845. // }else{
  1846. // model.SoureId = self.Id;
  1847. // model.SoureTypeId = self.type;
  1848. // model.Title = self.currentNoteModel.Title;
  1849. // model.Author = self.currentNoteModel.UserName;
  1850. // vc.type = CollectModel_NewTopic;
  1851. // }
  1852. switch (model.type) {
  1853. case EMMessageTypeText:
  1854. {
  1855. FlowAttachmentsModel * sendModel = [[FlowAttachmentsModel alloc] init];
  1856. EMTextMessageBody *body = (EMTextMessageBody *)model.emModel.body;
  1857. sendModel.Title = body.text;
  1858. sendModel.SoureTypeId = 1;
  1859. self.sendModel = sendModel;
  1860. [self shareHander];
  1861. }
  1862. break;
  1863. case EMMessageTypeImage:
  1864. {
  1865. [self shareImage:model];
  1866. // EMTextMessageBody *body = (EMTextMessageBody *)model.emModel.body;
  1867. // self.sendModel.image = body.text;
  1868. // self.sendModel.SoureTypeId = 301;
  1869. }
  1870. break;
  1871. case EMMessageTypeExtApp:
  1872. {
  1873. NSDictionary * dict = model.emModel.ext;
  1874. CollectModelType type = [[dict objectForKey:@"app_type"] intValue];
  1875. NSInteger sourceUserId = [[dict objectForKey:@"app_sourceUserId"] integerValue];
  1876. NSInteger Id = [[dict objectForKey:@"app_id"] integerValue];
  1877. NSString * title = [dict objectForKey:@"app_title"];
  1878. NSString * url = [dict objectForKey:@"app_url"];
  1879. FlowAttachmentsModel * sendModel = [[FlowAttachmentsModel alloc] init];
  1880. sendModel.Title = title;
  1881. sendModel.SoureTypeId = type;
  1882. sendModel.SoureId = Id;
  1883. sendModel.Url = url;
  1884. sendModel.SourceUserId = sourceUserId;
  1885. self.sendModel = sendModel;
  1886. [self shareHander];
  1887. }
  1888. break;
  1889. default:
  1890. break;
  1891. }
  1892. self.menuIndexPath = nil;
  1893. }
  1894. - (void)shareImage:(EMMessageModel *)model
  1895. {
  1896. __weak typeof(self) weakself = self;
  1897. void (^downloadThumbBlock)(EMMessageModel *aModel) = ^(EMMessageModel *aModel) {
  1898. [weakself showHint:@"获取缩略图..."];
  1899. [[EMClient sharedClient].chatManager downloadMessageThumbnail:aModel.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
  1900. if (!error) {
  1901. [weakself.tableView reloadData];
  1902. }
  1903. }];
  1904. };
  1905. EMImageMessageBody *body = (EMImageMessageBody*)model.emModel.body;
  1906. BOOL isCustomDownload = !([EMClient sharedClient].options.isAutoTransferMessageAttachments);
  1907. if (body.thumbnailDownloadStatus == EMDownloadStatusFailed) {
  1908. if (isCustomDownload) {
  1909. [self _showCustomTransferFileAlertView];
  1910. } else {
  1911. downloadThumbBlock(model);
  1912. }
  1913. return;
  1914. }
  1915. BOOL isAutoDownloadThumbnail = [EMClient sharedClient].options.isAutoDownloadThumbnail;
  1916. if (body.thumbnailDownloadStatus == EMDownloadStatusPending && !isAutoDownloadThumbnail) {
  1917. downloadThumbBlock(model);
  1918. return;
  1919. }
  1920. FlowAttachmentsModel * sendModel = [[FlowAttachmentsModel alloc] init];
  1921. sendModel.SoureTypeId = 301;
  1922. self.sendModel = sendModel;
  1923. if (body.downloadStatus == EMDownloadStatusSucceed) {
  1924. UIImage *image = [UIImage imageWithContentsOfFile:body.localPath];
  1925. if (image) {
  1926. self.sendImage = image;
  1927. [self shareHander];
  1928. // [[EMImageBrowser sharedBrowser] showImages:@[image] fromController:self];
  1929. return;
  1930. }
  1931. }
  1932. if (isCustomDownload) {
  1933. [self _showCustomTransferFileAlertView];
  1934. return;
  1935. }
  1936. [self showHudInView:self.view hint:@"下载原图..."];
  1937. [[EMClient sharedClient].chatManager downloadMessageAttachment:model.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
  1938. [weakself hideHud];
  1939. if (error) {
  1940. SHOWERROR(@"下载原图失败");
  1941. } else {
  1942. if (message.direction == EMMessageDirectionReceive && !message.isReadAcked) {
  1943. [[EMClient sharedClient].chatManager sendMessageReadAck:message.messageId toUser:message.conversationId completion:nil];
  1944. }
  1945. NSString *localPath = [(EMImageMessageBody *)message.body localPath];
  1946. UIImage *image = [UIImage imageWithContentsOfFile:localPath];
  1947. if (image) {
  1948. weakself.sendImage = image;
  1949. [weakself shareHander];
  1950. // [[EMImageBrowser sharedBrowser] showImages:@[image] fromController:self];
  1951. } else {
  1952. SHOWERROR(@"获取原图失败");
  1953. }
  1954. }
  1955. }];
  1956. }
  1957. - (void)recallMenuItemAction:(UIMenuItem *)aItem
  1958. {
  1959. if (self.menuIndexPath == nil) {
  1960. return;
  1961. }
  1962. NSIndexPath *indexPath = self.menuIndexPath;
  1963. __weak typeof(self) weakself = self;
  1964. EMMessageModel *model = [self.dataArray objectAtIndex:self.menuIndexPath.row];
  1965. [[EMClient sharedClient].chatManager recallMessage:model.emModel completion:^(EMMessage *aMessage, EMError *aError) {
  1966. if (aError) {
  1967. if (aError.code == EMErrorMessageRecallTimeLimit) {
  1968. SHOWERROR(@"超过限制撤回时间,无法撤回");
  1969. }
  1970. } else {
  1971. EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithText:@"您撤回一条消息"];
  1972. NSString *from = [[EMClient sharedClient] currentUsername];
  1973. NSString *to = self.conversationModel.emModel.conversationId;
  1974. EMMessage *message = [[EMMessage alloc] initWithConversationID:to from:from to:to body:body ext:@{MSG_EXT_RECALL:@(YES)}];
  1975. message.chatType = (EMChatType)self.conversationModel.emModel.type;
  1976. message.isRead = YES;
  1977. message.timestamp = model.emModel.timestamp;
  1978. message.localTime = model.emModel.localTime;
  1979. [weakself.conversationModel.emModel insertMessage:message error:nil];
  1980. EMMessageModel *model = [[EMMessageModel alloc] initWithEMMessage:message];
  1981. [weakself.dataArray replaceObjectAtIndex:indexPath.row withObject:model];
  1982. [weakself.tableView reloadData];
  1983. }
  1984. }];
  1985. self.menuIndexPath = nil;
  1986. }
  1987. - (void)playAndRecordMenuItemAction:(UIMenuItem *)aItem
  1988. {
  1989. if (self.menuIndexPath == nil) {
  1990. return;
  1991. }
  1992. EMMessageModel *model = [self.dataArray objectAtIndex:self.menuIndexPath.row];
  1993. [self playVoice:model];
  1994. self.menuIndexPath = nil;
  1995. }
  1996. - (void)playVoice:(EMMessageModel *)model
  1997. {
  1998. if (model.isPlaying) {
  1999. [[EMAudioPlayerHelper sharedHelper] stopPlayer];
  2000. model.isPlaying = NO;
  2001. [self.tableView reloadData];
  2002. return;
  2003. }
  2004. EMVoiceMessageBody *body = (EMVoiceMessageBody*)model.emModel.body;
  2005. if (body.downloadStatus == EMDownloadStatusDownloading) {
  2006. [EMAlertController showInfoAlert:@"正在下载语音,稍后点击"];
  2007. return;
  2008. }
  2009. __weak typeof(self) weakself = self;
  2010. void (^playBlock)(EMMessageModel *aModel) = ^(EMMessageModel *aModel) {
  2011. id model = [EMAudioPlayerHelper sharedHelper].model;
  2012. if (model && [model isKindOfClass:[EMMessageModel class]]) {
  2013. EMMessageModel *oldModel = (EMMessageModel *)model;
  2014. if (oldModel.isPlaying) {
  2015. oldModel.isPlaying = NO;
  2016. }
  2017. }
  2018. if (!aModel.emModel.isReadAcked) {
  2019. [[EMClient sharedClient].chatManager sendMessageReadAck:aModel.emModel.messageId toUser:aModel.emModel.conversationId completion:nil];
  2020. }
  2021. aModel.isPlaying = YES;
  2022. if (!aModel.emModel.isRead) {
  2023. aModel.emModel.isRead = YES;
  2024. }
  2025. [weakself.tableView reloadData];
  2026. [[EMAudioPlayerHelper sharedHelper] startPlayerWithPath:body.localPath model:aModel AVAudioSessionCategory:AVAudioSessionCategoryPlayAndRecord completion:^(NSError * _Nonnull error) {
  2027. aModel.isPlaying = NO;
  2028. [weakself.tableView reloadData];
  2029. }];
  2030. };
  2031. if (body.downloadStatus == EMDownloadStatusSucceed) {
  2032. playBlock(model);
  2033. return;
  2034. }
  2035. if (![EMClient sharedClient].options.isAutoTransferMessageAttachments) {
  2036. [self _showCustomTransferFileAlertView];
  2037. return;
  2038. }
  2039. [self showHudInView:self.view hint:@"下载语音..."];
  2040. [[EMClient sharedClient].chatManager downloadMessageAttachment:model.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
  2041. [weakself hideHud];
  2042. if (error) {
  2043. [EMAlertController showErrorAlert:@"下载语音失败"];
  2044. } else {
  2045. playBlock(model);
  2046. }
  2047. }];
  2048. }
  2049. - (void)_showMenuViewController:(EMMessageCell *)aCell
  2050. model:(EMMessageModel *)aModel
  2051. {
  2052. [self becomeFirstResponder];
  2053. NSMutableArray *items = [[NSMutableArray alloc] init];
  2054. if (aModel.type == EMMessageTypeText || aModel.type == EMMessageTypeImage) {
  2055. [items addObject:self.copyMenuItem];
  2056. [items addObject:self.transpondMenuItem];
  2057. // } else if (aModel.type == EMMessageTypeLocation || aModel.type == EMMessageTypeImage || aModel.type == EMMessageTypeVideo) {
  2058. // [items addObject:self.transpondMenuItem];
  2059. }else if(aModel.type == EMMessageTypeExtApp){
  2060. [items addObject:self.transpondMenuItem];
  2061. }else if(aModel.type == EMMessageTypeVoice){
  2062. [items addObject:self.playAndRecordMenuItem];
  2063. }
  2064. if (aModel.emModel.direction == EMMessageDirectionSend) {
  2065. [items addObject:self.recallMenuItem];
  2066. }
  2067. [items addObject:self.deleteMenuItem];
  2068. [self.menuController setMenuItems:items];
  2069. [self.menuController setTargetRect:aCell.bubbleView.frame inView:aCell];
  2070. [self.menuController setMenuVisible:YES animated:NO];
  2071. }
  2072. #pragma mark - Transpond Message
  2073. - (void)_forwardMsgWithBody:(EMMessageBody *)aBody
  2074. to:(NSString *)aTo
  2075. ext:(NSDictionary *)aExt
  2076. completion:(void (^)(EMMessage *message))aCompletionBlock
  2077. {
  2078. NSString *from = [[EMClient sharedClient] currentUsername];
  2079. EMMessage *message = [[EMMessage alloc] initWithConversationID:aTo from:from to:aTo body:aBody ext:aExt];
  2080. message.chatType = EMChatTypeChat;
  2081. __weak typeof(self) weakself = self;
  2082. [[EMClient sharedClient].chatManager sendMessage:message progress:nil completion:^(EMMessage *message, EMError *error) {
  2083. if (error) {
  2084. [weakself.conversationModel.emModel deleteMessageWithId:message.messageId error:nil];
  2085. SHOWERROR(@"转发消息失败");
  2086. } else {
  2087. if (aCompletionBlock) {
  2088. aCompletionBlock(message);
  2089. }
  2090. SHOWSUCCESS(@"转发消息成功");
  2091. }
  2092. }];
  2093. }
  2094. - (void)_forwardImageMsg:(EMMessage *)aMsg
  2095. toUser:(NSString *)aUsername
  2096. {
  2097. NSString *thumbnailLocalPath = [(EMImageMessageBody *)aMsg.body thumbnailLocalPath];
  2098. __weak typeof(self) weakself = self;
  2099. void (^block)(EMMessage *aMessage) = ^(EMMessage *aMessage) {
  2100. EMImageMessageBody *oldBody = (EMImageMessageBody *)aMessage.body;
  2101. EMImageMessageBody *newBody = [[EMImageMessageBody alloc] initWithData:nil thumbnailData:[NSData dataWithContentsOfFile:oldBody.thumbnailLocalPath]];
  2102. newBody.thumbnailRemotePath = oldBody.thumbnailRemotePath;
  2103. newBody.remotePath = oldBody.remotePath;
  2104. [weakself _forwardMsgWithBody:newBody to:aUsername ext:aMsg.ext completion:^(EMMessage *message) {
  2105. [(EMImageMessageBody *)message.body setLocalPath:oldBody.localPath];
  2106. [[EMClient sharedClient].chatManager updateMessage:message completion:nil];
  2107. }];
  2108. };
  2109. if (![[NSFileManager defaultManager] fileExistsAtPath:thumbnailLocalPath]) {
  2110. [[EMClient sharedClient].chatManager downloadMessageThumbnail:aMsg progress:nil completion:^(EMMessage *message, EMError *error) {
  2111. if (error) {
  2112. SHOWERROR(@"转发消息失败");
  2113. } else {
  2114. block(aMsg);
  2115. }
  2116. }];
  2117. } else {
  2118. block(aMsg);
  2119. }
  2120. }
  2121. - (void)_forwardVideoMsg:(EMMessage *)aMsg
  2122. toUser:(NSString *)aUsername
  2123. {
  2124. EMVideoMessageBody *oldBody = (EMVideoMessageBody *)aMsg.body;
  2125. __weak typeof(self) weakself = self;
  2126. void (^block)(EMMessage *aMessage) = ^(EMMessage *aMessage) {
  2127. EMVideoMessageBody *newBody = [[EMVideoMessageBody alloc] initWithLocalPath:oldBody.localPath displayName:oldBody.displayName];
  2128. newBody.thumbnailLocalPath = oldBody.thumbnailLocalPath;
  2129. [weakself _forwardMsgWithBody:newBody to:aUsername ext:aMsg.ext completion:^(EMMessage *message) {
  2130. [(EMVideoMessageBody *)message.body setLocalPath:[(EMVideoMessageBody *)aMessage.body localPath]];
  2131. [[EMClient sharedClient].chatManager updateMessage:message completion:nil];
  2132. }];
  2133. };
  2134. if (![[NSFileManager defaultManager] fileExistsAtPath:oldBody.localPath]) {
  2135. [[EMClient sharedClient].chatManager downloadMessageAttachment:aMsg progress:nil completion:^(EMMessage *message, EMError *error) {
  2136. if (error) {
  2137. SHOWERROR(@"转发消息失败");
  2138. } else {
  2139. block(aMsg);
  2140. }
  2141. }];
  2142. } else {
  2143. block(aMsg);
  2144. }
  2145. }
  2146. - (void)_transpondMsg:(EMMessageModel *)aModel
  2147. toUser:(NSString *)aUsername
  2148. {
  2149. EMMessageBodyType type = aModel.emModel.body.type;
  2150. if (type == EMMessageBodyTypeText || type == EMMessageBodyTypeLocation) {
  2151. [self _forwardMsgWithBody:aModel.emModel.body to:aUsername ext:aModel.emModel.ext completion:nil];
  2152. } else if (type == EMMessageBodyTypeImage) {
  2153. [self _forwardImageMsg:aModel.emModel toUser:aUsername];
  2154. } else if (type == EMMessageBodyTypeVideo) {
  2155. [self _forwardVideoMsg:aModel.emModel toUser:aUsername];
  2156. }
  2157. }
  2158. #pragma mark - Send Message
  2159. - (void)_sendTextAction:(NSString *)aText
  2160. ext:(NSDictionary *)aExt
  2161. {
  2162. [self.chatBar clearInputViewText];
  2163. [self clearUserInfoInDocument];
  2164. if ([aText length] == 0) {
  2165. return;
  2166. }
  2167. //TODO: 处理@
  2168. //messageExt
  2169. //TODO: 处理表情
  2170. // NSString *sendText = [EaseConvertToCommonEmoticonsHelper convertToCommonEmoticons:aText];
  2171. EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithText:aText];
  2172. [self _sendMessageWithBody:body ext:aExt isUpload:NO];
  2173. if (self.enableTyping) {
  2174. [self _sendEndTyping];
  2175. }
  2176. }
  2177. - (void)_sendImageDataAction:(NSData *)aImageData
  2178. {
  2179. EMImageMessageBody *body = [[EMImageMessageBody alloc] initWithData:aImageData displayName:@"image"];
  2180. [self _sendMessageWithBody:body ext:nil isUpload:YES];
  2181. }
  2182. - (void)_sendLocationAction:(CLLocationCoordinate2D)aCoord
  2183. address:(NSString *)aAddress
  2184. {
  2185. EMLocationMessageBody *body = [[EMLocationMessageBody alloc] initWithLatitude:aCoord.latitude longitude:aCoord.longitude address:aAddress];
  2186. [self _sendMessageWithBody:body ext:nil isUpload:NO];
  2187. }
  2188. - (void)_sendVideoAction:(NSURL *)aUrl
  2189. {
  2190. EMVideoMessageBody *body = [[EMVideoMessageBody alloc] initWithLocalPath:[aUrl path] displayName:@"video.mp4"];
  2191. [self _sendMessageWithBody:body ext:nil isUpload:YES];
  2192. }
  2193. - (void)_sendBeginTyping
  2194. {
  2195. NSString *from = [[EMClient sharedClient] currentUsername];
  2196. NSString *to = self.conversationModel.emModel.conversationId;
  2197. EMCmdMessageBody *body = [[EMCmdMessageBody alloc] initWithAction:MSG_TYPING_BEGIN];
  2198. body.isDeliverOnlineOnly = YES;
  2199. EMMessage *message = [[EMMessage alloc] initWithConversationID:to from:from to:to body:body ext:nil];
  2200. message.chatType = (EMChatType)self.conversationModel.emModel.type;
  2201. [[EMClient sharedClient].chatManager sendMessage:message progress:nil completion:nil];
  2202. }
  2203. //正在输入
  2204. - (void)_sendEndTyping
  2205. {
  2206. self.isTyping = NO;
  2207. NSString *from = [[EMClient sharedClient] currentUsername];
  2208. NSString *to = self.conversationModel.emModel.conversationId;
  2209. EMCmdMessageBody *body = [[EMCmdMessageBody alloc] initWithAction:MSG_TYPING_END];
  2210. body.isDeliverOnlineOnly = YES;
  2211. EMMessage *message = [[EMMessage alloc] initWithConversationID:to from:from to:to body:body ext:nil];
  2212. message.chatType = (EMChatType)self.conversationModel.emModel.type;
  2213. [[EMClient sharedClient].chatManager sendMessage:message progress:nil completion:nil];
  2214. }
  2215. #pragma mark - Data
  2216. - (NSArray *)_formatMessages:(NSArray<EMMessage *> *)aMessages
  2217. {
  2218. NSMutableArray *formated = [[NSMutableArray alloc] init];
  2219. for (int i = 0; i < [aMessages count]; i++) {
  2220. EMMessage *msg = aMessages[i];
  2221. // cmd消息不展示
  2222. if(msg.body.type == EMMessageBodyTypeCmd) {
  2223. continue;
  2224. }
  2225. if (msg.chatType == EMChatTypeChat && msg.isReadAcked && (msg.body.type == EMMessageBodyTypeText || msg.body.type == EMMessageBodyTypeLocation)) {
  2226. //
  2227. [[EMClient sharedClient].chatManager sendMessageReadAck:msg.messageId toUser:msg.conversationId completion:nil];
  2228. } else if (msg.chatType == EMChatTypeGroupChat && !msg.isReadAcked && (msg.body.type == EMMessageBodyTypeText || msg.body.type == EMMessageBodyTypeLocation)) {
  2229. }
  2230. CGFloat interval = (self.msgTimelTag - msg.timestamp) / 1000;
  2231. if (self.msgTimelTag < 0 || interval > 60 || interval < -60) {
  2232. NSString *timeStr = [EMDateHelper formattedTimeFromTimeInterval:msg.timestamp];
  2233. [formated addObject:timeStr];
  2234. self.msgTimelTag = msg.timestamp;
  2235. }
  2236. EMMessageModel *model = [[EMMessageModel alloc] initWithEMMessage:msg];
  2237. [formated addObject:model];
  2238. }
  2239. return formated;
  2240. }
  2241. - (void)tableViewDidTriggerHeaderRefresh
  2242. {
  2243. __weak typeof(self) weakself = self;
  2244. void (^block)(NSArray *aMessages, EMError *aError) = ^(NSArray *aMessages, EMError *aError) {
  2245. if (!aError && [aMessages count]) {
  2246. EMMessage *msg = aMessages[0];
  2247. weakself.moreMsgId = msg.messageId;
  2248. dispatch_async(self.msgQueue, ^{
  2249. NSArray *formated = [weakself _formatMessages:aMessages];
  2250. [weakself.dataArray insertObjects:formated atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [formated count])]];
  2251. if (![weakself.dataArray.firstObject isKindOfClass:[NSString class]]) {
  2252. [weakself.dataArray removeObjectAtIndex:0];
  2253. }
  2254. dispatch_async(dispatch_get_main_queue(), ^{
  2255. [weakself.tableView reloadData];
  2256. [weakself returnMessge];
  2257. if (weakself.isFirstLoadMsg) {
  2258. weakself.isFirstLoadMsg = NO;
  2259. [weakself _scrollToBottomRow];
  2260. }
  2261. });
  2262. });
  2263. }
  2264. if (!aError && [aMessages count] == 0) {
  2265. [weakself returnMessge];
  2266. }
  2267. [weakself tableViewDidFinishTriggerHeader:YES reload:NO];
  2268. };
  2269. if ([EMDemoOptions sharedOptions].isPriorityGetMsgFromServer) {
  2270. EMConversation *conversation = self.conversationModel.emModel;
  2271. [EMClient.sharedClient.chatManager asyncFetchHistoryMessagesFromServer:conversation.conversationId
  2272. conversationType:conversation.type
  2273. startMessageId:self.moreMsgId
  2274. pageSize:50
  2275. completion:^(EMCursorResult *aResult, EMError *aError)
  2276. {
  2277. block(aResult.list, aError);
  2278. }];
  2279. } else {
  2280. [self.conversationModel.emModel loadMessagesStartFromId:self.moreMsgId
  2281. count:50
  2282. searchDirection:EMMessageSearchDirectionUp
  2283. completion:block];
  2284. if(self.conversationModel.emModel.unreadMessagesCount > 0){
  2285. [self sendDidReadReceipt];
  2286. }
  2287. }
  2288. }
  2289. #pragma mark - 转发消息
  2290. - (void)returnMessge
  2291. {
  2292. if (self.isReturn) {
  2293. self.isReturn = NO;
  2294. [[NSNotificationCenter defaultCenter] postNotificationName:MESSAGERETURNSUCCESS object:nil];
  2295. switch (self.sendModel.SoureTypeId) {
  2296. case CollectModel_Text:///文本
  2297. {
  2298. [self _sendTextAction:self.sendModel.Title ext:nil];
  2299. }
  2300. break;
  2301. case CollectModel_Aritle:
  2302. {
  2303. [self _sendTextAction:@"文章" ext:@{@"app":@(YES),
  2304. @"app_type":@(CollectModel_Aritle),
  2305. @"app_title":self.sendModel.Title,
  2306. @"app_id":@(self.sendModel.SoureId),
  2307. @"app_content":@"来自-文章",
  2308. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2309. @"app_min_url":self.sendModel.MinUrl,
  2310. @"app_url":self.sendModel.Url,
  2311. }];
  2312. }
  2313. break;
  2314. case CollectModel_Notice:
  2315. {
  2316. [self _sendTextAction:@"通知" ext:@{@"app":@(YES),
  2317. @"app_type":@(CollectModel_Notice),
  2318. @"app_title":self.sendModel.Title,
  2319. @"app_id":@(self.sendModel.SoureId),
  2320. @"app_content":@"来自-通知",
  2321. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2322. @"app_min_url":self.sendModel.MinUrl,
  2323. @"app_url":self.sendModel.Url,
  2324. }];
  2325. }
  2326. break;
  2327. case CollectModel_NoteBook:
  2328. {
  2329. [self _sendTextAction:@"笔记" ext:@{@"app":@(YES),
  2330. @"app_type":@(CollectModel_NoteBook),
  2331. @"app_title":self.sendModel.Title,
  2332. @"app_id":@(self.sendModel.SoureId),
  2333. @"app_content":@"来自-笔记",
  2334. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2335. @"app_min_url":self.sendModel.MinUrl,
  2336. @"app_url":self.sendModel.Url,
  2337. }];
  2338. }
  2339. break;
  2340. case CollectModel_NewTopic:
  2341. {
  2342. [self _sendTextAction:@"话题" ext:@{@"app":@(YES),
  2343. @"app_type":@(CollectModel_NewTopic),
  2344. @"app_title":self.sendModel.Title,
  2345. @"app_id":@(self.sendModel.SoureId),
  2346. @"app_content":@"来自-话题",
  2347. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2348. @"app_min_url":self.sendModel.MinUrl,
  2349. @"app_url":self.sendModel.Url,
  2350. }];
  2351. }
  2352. break;
  2353. case CollectModel_Toipc:
  2354. {
  2355. [self _sendTextAction:@"话题" ext:@{@"app":@(YES),
  2356. @"app_type":@(CollectModel_Toipc),
  2357. @"app_title":self.sendModel.Title,
  2358. @"app_id":@(self.sendModel.SoureId),
  2359. @"app_content":@"来自-话题",
  2360. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2361. @"app_min_url":self.sendModel.MinUrl,
  2362. @"app_url":self.sendModel.Url,
  2363. }];
  2364. }
  2365. break;
  2366. case CollectModel_InterMail:
  2367. {
  2368. [self _sendTextAction:@"站内信" ext:@{@"app":@(YES),
  2369. @"app_type":@(CollectModel_InterMail),
  2370. @"app_title":self.sendModel.Title,
  2371. @"app_id":@(self.sendModel.SoureId),
  2372. @"app_content":@"来自-站内信",
  2373. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2374. @"app_min_url":self.sendModel.MinUrl,
  2375. @"app_url":self.sendModel.Url,
  2376. }];
  2377. }
  2378. break;
  2379. case CollectModel_CollectFile:
  2380. {
  2381. [self _sendTextAction:@"收藏文件夹" ext:@{@"app":@(YES),
  2382. @"app_type":@(CollectModel_CollectFile),
  2383. @"app_title":self.sendModel.Title,
  2384. @"app_id":@(self.sendModel.SoureId),
  2385. @"app_content":@"来自-收藏文件夹",
  2386. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2387. @"app_min_url":self.sendModel.MinUrl,
  2388. @"app_url":self.sendModel.Url,
  2389. }];
  2390. }
  2391. break;
  2392. case CollectModel_NoteFile:
  2393. {
  2394. [self _sendTextAction:@"笔记文件夹" ext:@{@"app":@(YES),
  2395. @"app_type":@(CollectModel_NoteFile),
  2396. @"app_title":self.sendModel.Title,
  2397. @"app_id":@(self.sendModel.SoureId),
  2398. @"app_content":@"来自-笔记文件夹",
  2399. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2400. @"app_min_url":self.sendModel.MinUrl,
  2401. @"app_url":self.sendModel.Url,
  2402. }];
  2403. }
  2404. break;
  2405. case CollectModel_meetMian:
  2406. {
  2407. [self _sendTextAction:@"会议纪要" ext:@{@"app":@(YES),
  2408. @"app_type":@(CollectModel_meetMian),
  2409. @"app_title":self.sendModel.Title,
  2410. @"app_id":@(self.sendModel.SoureId),
  2411. @"app_content":@"来自-会议纪要",
  2412. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2413. @"app_min_url":self.sendModel.MinUrl,
  2414. @"app_url":self.sendModel.Url,
  2415. }];
  2416. }
  2417. break;
  2418. case CollectModel_Image:///图片
  2419. {
  2420. [self _sendTextAction:@"审批" ext:@{@"app":@(YES),
  2421. @"app_type":@(CollectModel_Image),
  2422. @"app_title":self.sendModel.Title,
  2423. @"app_id":@(self.sendModel.SoureId),
  2424. @"app_content":@"来自-审批",
  2425. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2426. @"app_min_url":self.sendModel.MinUrl,
  2427. @"app_url":self.sendModel.Url,
  2428. }];
  2429. }
  2430. break;
  2431. case CollectModel_file:///文件
  2432. {
  2433. [self _sendTextAction:@"文件" ext:@{@"app":@(YES),
  2434. @"app_type":@(CollectModel_file),
  2435. @"app_title":self.sendModel.Title,
  2436. @"app_id":@(self.sendModel.SoureId),
  2437. @"app_content":@"来自-文件",
  2438. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2439. @"app_min_url":self.sendModel.MinUrl,
  2440. @"app_url":self.sendModel.Url,
  2441. }];
  2442. }
  2443. break;
  2444. case CollectModel_work:///工作
  2445. {
  2446. [self _sendTextAction:@"审批" ext:@{@"app":@(YES),
  2447. @"app_type":@(CollectModel_work),
  2448. @"app_title":self.sendModel.Title,
  2449. @"app_id":@(self.sendModel.SoureId),
  2450. @"app_content":@"来自-审批",
  2451. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2452. @"app_min_url":@"",
  2453. @"app_url":@""
  2454. }];
  2455. }
  2456. break;
  2457. case CollectModel_meetDetail:///会议
  2458. {
  2459. [self _sendTextAction:@"会议" ext:@{@"app":@(YES),
  2460. @"app_type":@(CollectModel_meetDetail),
  2461. @"app_title":self.sendModel.Title,
  2462. @"app_id":@(self.sendModel.SoureId),
  2463. @"app_content":@"来自-会议",
  2464. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2465. @"app_min_url":@"",
  2466. @"app_url":@""
  2467. }];
  2468. }
  2469. break;
  2470. case CollectModel_financeCount:///文本
  2471. {
  2472. [self _sendTextAction:@"财务统计" ext:@{@"app":@(YES),
  2473. @"app_type":@(CollectModel_financeCount),
  2474. @"app_title":self.sendModel.Title,
  2475. @"app_id":@(self.sendModel.SoureId),
  2476. @"app_content":@"来自-财务统计",
  2477. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2478. @"app_min_url":@"",
  2479. @"app_url":@""
  2480. }];
  2481. }
  2482. break;
  2483. case CollectModel_affairsCount:///文本
  2484. {
  2485. [self _sendTextAction:@"人事统计" ext:@{@"app":@(YES),
  2486. @"app_type":@(CollectModel_affairsCount),
  2487. @"app_title":self.sendModel.Title,
  2488. @"app_id":@(self.sendModel.SoureId),
  2489. @"app_content":@"来自-人事统计",
  2490. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2491. @"app_min_url":@"",
  2492. @"app_url":@""
  2493. }];
  2494. }
  2495. break;
  2496. case CollectModel_publishCount:///文本
  2497. {
  2498. [self _sendTextAction:@"出版统计" ext:@{@"app":@(YES),
  2499. @"app_type":@(CollectModel_publishCount),
  2500. @"app_title":self.sendModel.Title,
  2501. @"app_id":@(self.sendModel.SoureId),
  2502. @"app_content":@"来自-出版统计",
  2503. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2504. @"app_min_url":@"",
  2505. @"app_url":@""
  2506. }];
  2507. }
  2508. break;
  2509. default:
  2510. {
  2511. [self _sendTextAction:@"出版统计" ext:@{@"app":@(YES),
  2512. @"app_type":@(CollectModel_publishCount),
  2513. @"app_title":self.sendModel.Title,
  2514. @"app_id":@(self.sendModel.SoureId),
  2515. @"app_content":@"来自-出版统计",
  2516. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2517. @"app_min_url":@"",
  2518. @"app_url":@""
  2519. }];
  2520. }
  2521. break;
  2522. }
  2523. }
  2524. }
  2525. #pragma mark - Action
  2526. - (void)backAction
  2527. {
  2528. [[EMAudioPlayerHelper sharedHelper] stopPlayer];
  2529. [EMConversationHelper resortConversationsLatestMessage];
  2530. EMConversation *conversation = self.conversationModel.emModel;
  2531. if (conversation.type == EMChatTypeChatRoom) {
  2532. [[EMClient sharedClient].roomManager leaveChatroom:conversation.conversationId completion:nil];
  2533. }
  2534. [self.navigationController popViewControllerAnimated:YES];
  2535. }
  2536. //删除该会话所有消息,同时清除内存和数据库中的消息
  2537. - (void)deleteAllMessageAction
  2538. {
  2539. EMError *error = nil;
  2540. [self.conversationModel.emModel deleteAllMessages:&error];
  2541. if (!error) {
  2542. [self.dataArray removeAllObjects];
  2543. [self.tableView reloadData];
  2544. }
  2545. }
  2546. - (void)groupOrChatroomInfoAction
  2547. {
  2548. if (self.conversationModel.emModel.type == EMConversationTypeGroupChat) {
  2549. [[NSNotificationCenter defaultCenter] postNotificationName:GROUP_INFO_PUSHVIEWCONTROLLER object:@{NOTIF_ID:self.conversationModel.emModel.conversationId, NOTIF_NAVICONTROLLER:self.navigationController}];
  2550. } else if (self.conversationModel.emModel.type == EMConversationTypeChatRoom) {
  2551. [[NSNotificationCenter defaultCenter] postNotificationName:CHATROOM_INFO_PUSHVIEWCONTROLLER object:@{NOTIF_ID:self.conversationModel.emModel.conversationId, NOTIF_NAVICONTROLLER:self.navigationController}];
  2552. }
  2553. }
  2554. //发送消息体
  2555. - (void)_sendMessageWithBody:(EMMessageBody *)aBody
  2556. ext:(NSDictionary *)aExt
  2557. isUpload:(BOOL)aIsUpload
  2558. {
  2559. if (!([EMClient sharedClient].options.isAutoTransferMessageAttachments) && aIsUpload) {
  2560. [self _showCustomTransferFileAlertView];
  2561. return;
  2562. }
  2563. NSString *from = [[EMClient sharedClient] currentUsername];
  2564. NSString *to = self.conversationModel.emModel.conversationId;
  2565. EMMessage *message = [[EMMessage alloc] initWithConversationID:to from:from to:to body:aBody ext:aExt];
  2566. //是否需要发送阅读回执
  2567. if([aExt objectForKey:MSG_EXT_READ_RECEIPT]) {
  2568. message.isNeedGroupAck = YES;
  2569. }
  2570. message.chatType = (EMChatType)self.conversationModel.emModel.type;
  2571. __weak typeof(self) weakself = self;
  2572. [[EMClient sharedClient].chatManager sendMessage:message progress:nil completion:^(EMMessage *message, EMError *error) {
  2573. NSArray *formated = [weakself _formatMessages:@[message]];
  2574. [weakself.dataArray addObjectsFromArray:formated];
  2575. dispatch_async(dispatch_get_main_queue(), ^{
  2576. [weakself.tableView reloadData];
  2577. [weakself _scrollToBottomRow];
  2578. });
  2579. NSLog(@"%@",@{@"ContactUserId":[NSString stringWithFormat:@"%ld",(long)self.toUserId],@"IndividualGroupId":@(self.IndividualGroupId)});
  2580. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2581. [[HttpManager sharedHttpManager] POSTUrl:Host(Often_Contact_Add_Post) parameters:@{@"ContactUserId":[NSString stringWithFormat:@"%ld",(long)self.toUserId],@"IndividualGroupId":@(self.IndividualGroupId),@"ChatType":@(self.chatType)} responseStyle:JOSN success:^(id _Nonnull responseObject) {
  2582. NSLog(@"%@",responseObject);
  2583. if ([responseObject isKindOfClass:[NSDictionary class]]) {
  2584. NSInteger listId = [[responseObject objectForKey:@"Id"] integerValue];
  2585. if (listId > 0) {
  2586. weakself.listId = listId;
  2587. weakself.isTop = [[responseObject objectForKey:@"IsTop"] integerValue];
  2588. }
  2589. }
  2590. } failure:^(NSError * _Nonnull error) {
  2591. }];
  2592. });
  2593. }];
  2594. }
  2595. #pragma mark - CustomView
  2596. - (UIView *)titleV
  2597. {
  2598. if (!_titleV) {
  2599. _titleV = [UIView new];
  2600. _titleV.backgroundColor = [UIColor whiteColor];
  2601. }
  2602. return _titleV;
  2603. }
  2604. - (UIButton *)backBtn
  2605. {
  2606. if (!_backBtn) {
  2607. _backBtn = [UIButton new];
  2608. [_backBtn setImage:[UIImage imageNamed:@"back_black_icon"] forState:UIControlStateNormal];
  2609. }
  2610. return _backBtn;
  2611. }
  2612. - (UIButton *)tabBtn
  2613. {
  2614. if (!_tabBtn) {
  2615. _tabBtn = [UIButton new];
  2616. [_tabBtn setImage:[UIImage imageNamed:@"menu_black_icon"] forState:UIControlStateNormal];
  2617. }
  2618. return _tabBtn;
  2619. }
  2620. - (UILabel *)titleL
  2621. {
  2622. if (!_titleL) {
  2623. _titleL = [UILabel new];
  2624. [_titleL setTextColor: UIColorHex(0A0A0A)];
  2625. _titleL.font = [UIFont systemFontOfSize:18];
  2626. }
  2627. return _titleL;
  2628. }
  2629. - (UIButton *)mangerBtn
  2630. {
  2631. if (!_mangerBtn) {
  2632. _mangerBtn = [UIButton new];
  2633. [_mangerBtn setImage:[UIImage imageNamed:@"chatmsg_detailchat_more_icon"] forState:UIControlStateNormal];
  2634. }
  2635. return _mangerBtn;
  2636. }
  2637. - (NSMutableArray *)userInfoArray
  2638. {
  2639. if (!_userInfoArray) {
  2640. _userInfoArray = [NSMutableArray array];
  2641. }
  2642. return _userInfoArray;
  2643. }
  2644. - (void)selectMoreMenu:(NSInteger)index title:(NSString *)title
  2645. {
  2646. switch (index) {
  2647. case 0:{
  2648. [self chatBarDidCameraAction];
  2649. }break;
  2650. case 1:{
  2651. [self chatBarDidPhotoAction];
  2652. }break;
  2653. case 2:{
  2654. FavoritesViewController *favorites = [[FavoritesViewController alloc] init];
  2655. favorites.title = @"我的笔记";
  2656. [self.navigationController pushViewController:favorites animated:YES];
  2657. }break;
  2658. case 3:{
  2659. FavoritesViewController *favorites = [[FavoritesViewController alloc] init];
  2660. favorites.title = @"我的收藏";
  2661. [self.navigationController pushViewController:favorites animated:YES];
  2662. }break;
  2663. default:
  2664. break;
  2665. }
  2666. }
  2667. - (NSMutableArray *)chatDistoryArray
  2668. {
  2669. if(!_chatDistoryArray)
  2670. {
  2671. _chatDistoryArray = [[NSMutableArray alloc] initWithArray:USERDEFAULTSGET(@"ChatList")];
  2672. }
  2673. return _chatDistoryArray;
  2674. }
  2675. - (NSString *)getUserInfoInDocument{
  2676. for (NSDictionary * dict in self.chatDistoryArray) {
  2677. if ([[dict objectForKey:@"ImId"] isEqualToString:self.conversationModel.emModel.conversationId]) {
  2678. NSString * text = [dict objectForKey:@"text"];
  2679. return text;
  2680. }
  2681. }
  2682. return @"";
  2683. }
  2684. - (void)clearUserInfoInDocument
  2685. {
  2686. for (NSDictionary * dict in self.chatDistoryArray) {
  2687. if ([[dict objectForKey:@"ImId"] isEqualToString:self.conversationModel.emModel.conversationId]) {
  2688. [self.chatDistoryArray removeObject:dict];
  2689. break;
  2690. }
  2691. }
  2692. USERDEFAULTSSET(self.chatDistoryArray,@"ChatList");
  2693. }
  2694. - (void)saveUserInfoInDocument:(NSString *)text{
  2695. for (NSDictionary * dict in self.chatDistoryArray) {
  2696. if ([[dict objectForKey:@"ImId"] isEqualToString:self.conversationModel.emModel.conversationId]) {
  2697. [self.chatDistoryArray removeObject:dict];
  2698. break;
  2699. }
  2700. }
  2701. [self.chatDistoryArray addObject:@{@"ImId":self.conversationModel.emModel.conversationId,@"text":text}];
  2702. USERDEFAULTSSET(self.chatDistoryArray,@"ChatList");
  2703. }
  2704. - (void)deleteConversationMsg
  2705. {
  2706. WS(weakSelf);
  2707. [[EMClient sharedClient].chatManager deleteConversation:self.conversationModel.emModel.conversationId isDeleteMessages:YES completion:^(NSString *aConversationId, EMError *aError) {
  2708. [weakSelf deleteAllMessageAction];
  2709. }];
  2710. }
  2711. #pragma mark - 转发
  2712. - (void)shareHander{
  2713. [self.noteBookShareVC initNoteBookShareData];
  2714. self.noteBookShareVC.view.hidden = !self.noteBookShareVC.view.hidden;
  2715. }
  2716. - (NoteBookShareVC *)noteBookShareVC{
  2717. if (_noteBookShareVC == nil) {
  2718. _noteBookShareVC = [NoteBookShareVC initNoteBookShareVC];
  2719. [_noteBookShareVC.view setFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  2720. [_noteBookShareVC.view setHidden:YES];
  2721. _noteBookShareVC.delegate = self;
  2722. }
  2723. return _noteBookShareVC;
  2724. }
  2725. -(void)userSelectType:(NSString *)typeName WithIndexPath:(NSIndexPath *)indexPath{
  2726. self.noteBookShareVC.view.hidden = !self.noteBookShareVC.view.hidden;
  2727. if ([typeName isEqualToString:@"发给微信好友"]) {
  2728. }else if ([typeName isEqualToString:@"发到朋友圈"]){
  2729. }else if ([typeName isEqualToString:@"发到微博"]){
  2730. }else if ([typeName isEqualToString:@"发给QQ好友"]){
  2731. }else if ([typeName isEqualToString:@"发到消息"]){
  2732. }else if ([typeName isEqualToString:@"发到小组"]){
  2733. // [self returnToGroup];
  2734. }else if ([typeName isEqualToString:@"发到笔记"]){
  2735. [self returnToNote];
  2736. }else if ([typeName isEqualToString:@"发到话题"]){
  2737. [self returnToTopic];
  2738. }else{
  2739. }
  2740. }
  2741. #pragma mark - 分享功能
  2742. //- (void)returnToGroup
  2743. //{
  2744. // MyTDGroupViewController * vc = [[MyTDGroupViewController alloc] init];
  2745. // vc.type = CollectModel_Group;
  2746. // FlowAttachmentsModel * model = [[FlowAttachmentsModel alloc] init];
  2747. // model.SoureId = self.Id;
  2748. // model.SoureTypeId = self.type;
  2749. // model.Title = self.currentNoteModel.Title;
  2750. // model.Author = self.currentNoteModel.UserName;
  2751. // vc.sendModel = model;
  2752. // vc.isReturn = YES;
  2753. // [self.navigationController pushViewController:vc animated:YES];
  2754. //}
  2755. - (void)returnToNote
  2756. {
  2757. MoveViewController * vc = [MoveViewController initMoveViewController];
  2758. vc.isFromCreateBookVc = YES;
  2759. vc.TypeId = CreateNotesType;
  2760. vc.ParentId = 0;
  2761. vc.sendModel = self.sendModel;
  2762. vc.sendImage = self.sendImage;
  2763. vc.isReturn = YES;
  2764. [self.navigationController pushViewController:vc animated:YES];
  2765. }
  2766. - (void)returnToTopic
  2767. {
  2768. MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC];
  2769. vc.type = CollectModel_NewTopic;
  2770. // if (self.IsShareText) {
  2771. // model.Title = self.shareText;
  2772. // model.SoureTypeId = 1;
  2773. // }else{
  2774. // model.SoureId = self.Id;
  2775. // model.SoureTypeId = self.type;
  2776. // model.Title = self.currentNoteModel.Title;
  2777. // model.Author = self.currentNoteModel.UserName;
  2778. // vc.type = CollectModel_NewTopic;
  2779. // }
  2780. vc.sendModel = self.sendModel;
  2781. vc.sendImage = self.sendImage;
  2782. vc.isReturn = YES;
  2783. [self.navigationController pushViewController:vc animated:YES];
  2784. }
  2785. @end