EMChatViewController.m 128 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047
  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. [EMAlertController showErrorAlert:@"图片太大,请选择其他图片"];
  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. [EMAlertController showErrorAlert:@"获取群组失败"];
  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. [EMAlertController showErrorAlert:@"下载原图失败"];
  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. [EMAlertController showErrorAlert:@"获取原图失败"];
  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. [EMAlertController showInfoAlert:@"正在下载语音,稍后点击"];
  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. [EMAlertController showErrorAlert:@"下载语音失败"];
  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. [EMAlertController showInfoAlert:@"正在下载视频,稍后点击"];
  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. [EMAlertController showErrorAlert:@"下载视频失败"];
  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. [EMAlertController showErrorAlert:@"下载文件失败"];
  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. [EMAlertController showErrorAlert:@"下载原图失败"];
  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. [EMAlertController showErrorAlert:@"获取原图失败"];
  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. [EMAlertController showErrorAlert:aError.errorDescription];
  1968. } else {
  1969. EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithText:@"您撤回一条消息"];
  1970. NSString *from = [[EMClient sharedClient] currentUsername];
  1971. NSString *to = self.conversationModel.emModel.conversationId;
  1972. EMMessage *message = [[EMMessage alloc] initWithConversationID:to from:from to:to body:body ext:@{MSG_EXT_RECALL:@(YES)}];
  1973. message.chatType = (EMChatType)self.conversationModel.emModel.type;
  1974. message.isRead = YES;
  1975. message.timestamp = model.emModel.timestamp;
  1976. message.localTime = model.emModel.localTime;
  1977. [weakself.conversationModel.emModel insertMessage:message error:nil];
  1978. EMMessageModel *model = [[EMMessageModel alloc] initWithEMMessage:message];
  1979. [weakself.dataArray replaceObjectAtIndex:indexPath.row withObject:model];
  1980. [weakself.tableView reloadData];
  1981. }
  1982. }];
  1983. self.menuIndexPath = nil;
  1984. }
  1985. - (void)playAndRecordMenuItemAction:(UIMenuItem *)aItem
  1986. {
  1987. if (self.menuIndexPath == nil) {
  1988. return;
  1989. }
  1990. EMMessageModel *model = [self.dataArray objectAtIndex:self.menuIndexPath.row];
  1991. [self playVoice:model];
  1992. self.menuIndexPath = nil;
  1993. }
  1994. - (void)playVoice:(EMMessageModel *)model
  1995. {
  1996. if (model.isPlaying) {
  1997. [[EMAudioPlayerHelper sharedHelper] stopPlayer];
  1998. model.isPlaying = NO;
  1999. [self.tableView reloadData];
  2000. return;
  2001. }
  2002. EMVoiceMessageBody *body = (EMVoiceMessageBody*)model.emModel.body;
  2003. if (body.downloadStatus == EMDownloadStatusDownloading) {
  2004. [EMAlertController showInfoAlert:@"正在下载语音,稍后点击"];
  2005. return;
  2006. }
  2007. __weak typeof(self) weakself = self;
  2008. void (^playBlock)(EMMessageModel *aModel) = ^(EMMessageModel *aModel) {
  2009. id model = [EMAudioPlayerHelper sharedHelper].model;
  2010. if (model && [model isKindOfClass:[EMMessageModel class]]) {
  2011. EMMessageModel *oldModel = (EMMessageModel *)model;
  2012. if (oldModel.isPlaying) {
  2013. oldModel.isPlaying = NO;
  2014. }
  2015. }
  2016. if (!aModel.emModel.isReadAcked) {
  2017. [[EMClient sharedClient].chatManager sendMessageReadAck:aModel.emModel.messageId toUser:aModel.emModel.conversationId completion:nil];
  2018. }
  2019. aModel.isPlaying = YES;
  2020. if (!aModel.emModel.isRead) {
  2021. aModel.emModel.isRead = YES;
  2022. }
  2023. [weakself.tableView reloadData];
  2024. [[EMAudioPlayerHelper sharedHelper] startPlayerWithPath:body.localPath model:aModel AVAudioSessionCategory:AVAudioSessionCategoryPlayAndRecord completion:^(NSError * _Nonnull error) {
  2025. aModel.isPlaying = NO;
  2026. [weakself.tableView reloadData];
  2027. }];
  2028. };
  2029. if (body.downloadStatus == EMDownloadStatusSucceed) {
  2030. playBlock(model);
  2031. return;
  2032. }
  2033. if (![EMClient sharedClient].options.isAutoTransferMessageAttachments) {
  2034. [self _showCustomTransferFileAlertView];
  2035. return;
  2036. }
  2037. [self showHudInView:self.view hint:@"下载语音..."];
  2038. [[EMClient sharedClient].chatManager downloadMessageAttachment:model.emModel progress:nil completion:^(EMMessage *message, EMError *error) {
  2039. [weakself hideHud];
  2040. if (error) {
  2041. [EMAlertController showErrorAlert:@"下载语音失败"];
  2042. } else {
  2043. playBlock(model);
  2044. }
  2045. }];
  2046. }
  2047. - (void)_showMenuViewController:(EMMessageCell *)aCell
  2048. model:(EMMessageModel *)aModel
  2049. {
  2050. [self becomeFirstResponder];
  2051. NSMutableArray *items = [[NSMutableArray alloc] init];
  2052. if (aModel.type == EMMessageTypeText || aModel.type == EMMessageTypeImage) {
  2053. [items addObject:self.copyMenuItem];
  2054. [items addObject:self.transpondMenuItem];
  2055. // } else if (aModel.type == EMMessageTypeLocation || aModel.type == EMMessageTypeImage || aModel.type == EMMessageTypeVideo) {
  2056. // [items addObject:self.transpondMenuItem];
  2057. }else if(aModel.type == EMMessageTypeExtApp){
  2058. [items addObject:self.transpondMenuItem];
  2059. }else if(aModel.type == EMMessageTypeVoice){
  2060. [items addObject:self.playAndRecordMenuItem];
  2061. }
  2062. if (aModel.emModel.direction == EMMessageDirectionSend) {
  2063. [items addObject:self.recallMenuItem];
  2064. }
  2065. [items addObject:self.deleteMenuItem];
  2066. [self.menuController setMenuItems:items];
  2067. [self.menuController setTargetRect:aCell.bubbleView.frame inView:aCell];
  2068. [self.menuController setMenuVisible:YES animated:NO];
  2069. }
  2070. #pragma mark - Transpond Message
  2071. - (void)_forwardMsgWithBody:(EMMessageBody *)aBody
  2072. to:(NSString *)aTo
  2073. ext:(NSDictionary *)aExt
  2074. completion:(void (^)(EMMessage *message))aCompletionBlock
  2075. {
  2076. NSString *from = [[EMClient sharedClient] currentUsername];
  2077. EMMessage *message = [[EMMessage alloc] initWithConversationID:aTo from:from to:aTo body:aBody ext:aExt];
  2078. message.chatType = EMChatTypeChat;
  2079. __weak typeof(self) weakself = self;
  2080. [[EMClient sharedClient].chatManager sendMessage:message progress:nil completion:^(EMMessage *message, EMError *error) {
  2081. if (error) {
  2082. [weakself.conversationModel.emModel deleteMessageWithId:message.messageId error:nil];
  2083. [EMAlertController showErrorAlert:@"转发消息失败"];
  2084. } else {
  2085. if (aCompletionBlock) {
  2086. aCompletionBlock(message);
  2087. }
  2088. [EMAlertController showSuccessAlert:@"转发消息成功"];
  2089. }
  2090. }];
  2091. }
  2092. - (void)_forwardImageMsg:(EMMessage *)aMsg
  2093. toUser:(NSString *)aUsername
  2094. {
  2095. NSString *thumbnailLocalPath = [(EMImageMessageBody *)aMsg.body thumbnailLocalPath];
  2096. __weak typeof(self) weakself = self;
  2097. void (^block)(EMMessage *aMessage) = ^(EMMessage *aMessage) {
  2098. EMImageMessageBody *oldBody = (EMImageMessageBody *)aMessage.body;
  2099. EMImageMessageBody *newBody = [[EMImageMessageBody alloc] initWithData:nil thumbnailData:[NSData dataWithContentsOfFile:oldBody.thumbnailLocalPath]];
  2100. newBody.thumbnailRemotePath = oldBody.thumbnailRemotePath;
  2101. newBody.remotePath = oldBody.remotePath;
  2102. [weakself _forwardMsgWithBody:newBody to:aUsername ext:aMsg.ext completion:^(EMMessage *message) {
  2103. [(EMImageMessageBody *)message.body setLocalPath:oldBody.localPath];
  2104. [[EMClient sharedClient].chatManager updateMessage:message completion:nil];
  2105. }];
  2106. };
  2107. if (![[NSFileManager defaultManager] fileExistsAtPath:thumbnailLocalPath]) {
  2108. [[EMClient sharedClient].chatManager downloadMessageThumbnail:aMsg progress:nil completion:^(EMMessage *message, EMError *error) {
  2109. if (error) {
  2110. [EMAlertController showErrorAlert:@"转发消息失败"];
  2111. } else {
  2112. block(aMsg);
  2113. }
  2114. }];
  2115. } else {
  2116. block(aMsg);
  2117. }
  2118. }
  2119. - (void)_forwardVideoMsg:(EMMessage *)aMsg
  2120. toUser:(NSString *)aUsername
  2121. {
  2122. EMVideoMessageBody *oldBody = (EMVideoMessageBody *)aMsg.body;
  2123. __weak typeof(self) weakself = self;
  2124. void (^block)(EMMessage *aMessage) = ^(EMMessage *aMessage) {
  2125. EMVideoMessageBody *newBody = [[EMVideoMessageBody alloc] initWithLocalPath:oldBody.localPath displayName:oldBody.displayName];
  2126. newBody.thumbnailLocalPath = oldBody.thumbnailLocalPath;
  2127. [weakself _forwardMsgWithBody:newBody to:aUsername ext:aMsg.ext completion:^(EMMessage *message) {
  2128. [(EMVideoMessageBody *)message.body setLocalPath:[(EMVideoMessageBody *)aMessage.body localPath]];
  2129. [[EMClient sharedClient].chatManager updateMessage:message completion:nil];
  2130. }];
  2131. };
  2132. if (![[NSFileManager defaultManager] fileExistsAtPath:oldBody.localPath]) {
  2133. [[EMClient sharedClient].chatManager downloadMessageAttachment:aMsg progress:nil completion:^(EMMessage *message, EMError *error) {
  2134. if (error) {
  2135. [EMAlertController showErrorAlert:@"转发消息失败"];
  2136. } else {
  2137. block(aMsg);
  2138. }
  2139. }];
  2140. } else {
  2141. block(aMsg);
  2142. }
  2143. }
  2144. - (void)_transpondMsg:(EMMessageModel *)aModel
  2145. toUser:(NSString *)aUsername
  2146. {
  2147. EMMessageBodyType type = aModel.emModel.body.type;
  2148. if (type == EMMessageBodyTypeText || type == EMMessageBodyTypeLocation) {
  2149. [self _forwardMsgWithBody:aModel.emModel.body to:aUsername ext:aModel.emModel.ext completion:nil];
  2150. } else if (type == EMMessageBodyTypeImage) {
  2151. [self _forwardImageMsg:aModel.emModel toUser:aUsername];
  2152. } else if (type == EMMessageBodyTypeVideo) {
  2153. [self _forwardVideoMsg:aModel.emModel toUser:aUsername];
  2154. }
  2155. }
  2156. #pragma mark - Send Message
  2157. - (void)_sendTextAction:(NSString *)aText
  2158. ext:(NSDictionary *)aExt
  2159. {
  2160. [self.chatBar clearInputViewText];
  2161. [self clearUserInfoInDocument];
  2162. if ([aText length] == 0) {
  2163. return;
  2164. }
  2165. //TODO: 处理@
  2166. //messageExt
  2167. //TODO: 处理表情
  2168. // NSString *sendText = [EaseConvertToCommonEmoticonsHelper convertToCommonEmoticons:aText];
  2169. EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithText:aText];
  2170. [self _sendMessageWithBody:body ext:aExt isUpload:NO];
  2171. if (self.enableTyping) {
  2172. [self _sendEndTyping];
  2173. }
  2174. }
  2175. - (void)_sendImageDataAction:(NSData *)aImageData
  2176. {
  2177. EMImageMessageBody *body = [[EMImageMessageBody alloc] initWithData:aImageData displayName:@"image"];
  2178. [self _sendMessageWithBody:body ext:nil isUpload:YES];
  2179. }
  2180. - (void)_sendLocationAction:(CLLocationCoordinate2D)aCoord
  2181. address:(NSString *)aAddress
  2182. {
  2183. EMLocationMessageBody *body = [[EMLocationMessageBody alloc] initWithLatitude:aCoord.latitude longitude:aCoord.longitude address:aAddress];
  2184. [self _sendMessageWithBody:body ext:nil isUpload:NO];
  2185. }
  2186. - (void)_sendVideoAction:(NSURL *)aUrl
  2187. {
  2188. EMVideoMessageBody *body = [[EMVideoMessageBody alloc] initWithLocalPath:[aUrl path] displayName:@"video.mp4"];
  2189. [self _sendMessageWithBody:body ext:nil isUpload:YES];
  2190. }
  2191. - (void)_sendBeginTyping
  2192. {
  2193. NSString *from = [[EMClient sharedClient] currentUsername];
  2194. NSString *to = self.conversationModel.emModel.conversationId;
  2195. EMCmdMessageBody *body = [[EMCmdMessageBody alloc] initWithAction:MSG_TYPING_BEGIN];
  2196. body.isDeliverOnlineOnly = YES;
  2197. EMMessage *message = [[EMMessage alloc] initWithConversationID:to from:from to:to body:body ext:nil];
  2198. message.chatType = (EMChatType)self.conversationModel.emModel.type;
  2199. [[EMClient sharedClient].chatManager sendMessage:message progress:nil completion:nil];
  2200. }
  2201. //正在输入
  2202. - (void)_sendEndTyping
  2203. {
  2204. self.isTyping = NO;
  2205. NSString *from = [[EMClient sharedClient] currentUsername];
  2206. NSString *to = self.conversationModel.emModel.conversationId;
  2207. EMCmdMessageBody *body = [[EMCmdMessageBody alloc] initWithAction:MSG_TYPING_END];
  2208. body.isDeliverOnlineOnly = YES;
  2209. EMMessage *message = [[EMMessage alloc] initWithConversationID:to from:from to:to body:body ext:nil];
  2210. message.chatType = (EMChatType)self.conversationModel.emModel.type;
  2211. [[EMClient sharedClient].chatManager sendMessage:message progress:nil completion:nil];
  2212. }
  2213. #pragma mark - Data
  2214. - (NSArray *)_formatMessages:(NSArray<EMMessage *> *)aMessages
  2215. {
  2216. NSMutableArray *formated = [[NSMutableArray alloc] init];
  2217. for (int i = 0; i < [aMessages count]; i++) {
  2218. EMMessage *msg = aMessages[i];
  2219. // cmd消息不展示
  2220. if(msg.body.type == EMMessageBodyTypeCmd) {
  2221. continue;
  2222. }
  2223. if (msg.chatType == EMChatTypeChat && msg.isReadAcked && (msg.body.type == EMMessageBodyTypeText || msg.body.type == EMMessageBodyTypeLocation)) {
  2224. //
  2225. [[EMClient sharedClient].chatManager sendMessageReadAck:msg.messageId toUser:msg.conversationId completion:nil];
  2226. } else if (msg.chatType == EMChatTypeGroupChat && !msg.isReadAcked && (msg.body.type == EMMessageBodyTypeText || msg.body.type == EMMessageBodyTypeLocation)) {
  2227. }
  2228. CGFloat interval = (self.msgTimelTag - msg.timestamp) / 1000;
  2229. if (self.msgTimelTag < 0 || interval > 60 || interval < -60) {
  2230. NSString *timeStr = [EMDateHelper formattedTimeFromTimeInterval:msg.timestamp];
  2231. [formated addObject:timeStr];
  2232. self.msgTimelTag = msg.timestamp;
  2233. }
  2234. EMMessageModel *model = [[EMMessageModel alloc] initWithEMMessage:msg];
  2235. [formated addObject:model];
  2236. }
  2237. return formated;
  2238. }
  2239. - (void)tableViewDidTriggerHeaderRefresh
  2240. {
  2241. __weak typeof(self) weakself = self;
  2242. void (^block)(NSArray *aMessages, EMError *aError) = ^(NSArray *aMessages, EMError *aError) {
  2243. if (!aError && [aMessages count]) {
  2244. EMMessage *msg = aMessages[0];
  2245. weakself.moreMsgId = msg.messageId;
  2246. dispatch_async(self.msgQueue, ^{
  2247. NSArray *formated = [weakself _formatMessages:aMessages];
  2248. [weakself.dataArray insertObjects:formated atIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [formated count])]];
  2249. if (![weakself.dataArray.firstObject isKindOfClass:[NSString class]]) {
  2250. [weakself.dataArray removeObjectAtIndex:0];
  2251. }
  2252. dispatch_async(dispatch_get_main_queue(), ^{
  2253. [weakself.tableView reloadData];
  2254. [weakself returnMessge];
  2255. if (weakself.isFirstLoadMsg) {
  2256. weakself.isFirstLoadMsg = NO;
  2257. [weakself _scrollToBottomRow];
  2258. }
  2259. });
  2260. });
  2261. }
  2262. if (!aError && [aMessages count] == 0) {
  2263. [weakself returnMessge];
  2264. }
  2265. [weakself tableViewDidFinishTriggerHeader:YES reload:NO];
  2266. };
  2267. if ([EMDemoOptions sharedOptions].isPriorityGetMsgFromServer) {
  2268. EMConversation *conversation = self.conversationModel.emModel;
  2269. [EMClient.sharedClient.chatManager asyncFetchHistoryMessagesFromServer:conversation.conversationId
  2270. conversationType:conversation.type
  2271. startMessageId:self.moreMsgId
  2272. pageSize:50
  2273. completion:^(EMCursorResult *aResult, EMError *aError)
  2274. {
  2275. block(aResult.list, aError);
  2276. }];
  2277. } else {
  2278. [self.conversationModel.emModel loadMessagesStartFromId:self.moreMsgId
  2279. count:50
  2280. searchDirection:EMMessageSearchDirectionUp
  2281. completion:block];
  2282. if(self.conversationModel.emModel.unreadMessagesCount > 0){
  2283. [self sendDidReadReceipt];
  2284. }
  2285. }
  2286. }
  2287. #pragma mark - 转发消息
  2288. - (void)returnMessge
  2289. {
  2290. if (self.isReturn) {
  2291. self.isReturn = NO;
  2292. [[NSNotificationCenter defaultCenter] postNotificationName:MESSAGERETURNSUCCESS object:nil];
  2293. switch (self.sendModel.SoureTypeId) {
  2294. case CollectModel_Text:///文本
  2295. {
  2296. [self _sendTextAction:self.sendModel.Title ext:nil];
  2297. }
  2298. break;
  2299. case CollectModel_Aritle:
  2300. {
  2301. [self _sendTextAction:@"文章" ext:@{@"app":@(YES),
  2302. @"app_type":@(CollectModel_Aritle),
  2303. @"app_title":self.sendModel.Title,
  2304. @"app_id":@(self.sendModel.SoureId),
  2305. @"app_content":self.sendModel.Author.length > 0 ? [NSString stringWithFormat:@"来自-%@",self.sendModel.Author] : @"",
  2306. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2307. @"app_min_url":self.sendModel.MinUrl,
  2308. @"app_url":self.sendModel.Url,
  2309. }];
  2310. }
  2311. break;
  2312. case CollectModel_Notice:
  2313. {
  2314. [self _sendTextAction:@"通知" ext:@{@"app":@(YES),
  2315. @"app_type":@(CollectModel_Notice),
  2316. @"app_title":self.sendModel.Title,
  2317. @"app_id":@(self.sendModel.SoureId),
  2318. @"app_content":self.sendModel.Author.length > 0 ? [NSString stringWithFormat:@"来自-%@",self.sendModel.Author] : @"",
  2319. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2320. @"app_min_url":self.sendModel.MinUrl,
  2321. @"app_url":self.sendModel.Url,
  2322. }];
  2323. }
  2324. break;
  2325. case CollectModel_NoteBook:
  2326. {
  2327. [self _sendTextAction:@"笔记" ext:@{@"app":@(YES),
  2328. @"app_type":@(CollectModel_NoteBook),
  2329. @"app_title":self.sendModel.Title,
  2330. @"app_id":@(self.sendModel.SoureId),
  2331. @"app_content":self.sendModel.Author.length > 0 ? [NSString stringWithFormat:@"来自-%@",self.sendModel.Author] : @"",
  2332. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2333. @"app_min_url":self.sendModel.MinUrl,
  2334. @"app_url":self.sendModel.Url,
  2335. }];
  2336. }
  2337. break;
  2338. case CollectModel_NewTopic:
  2339. {
  2340. [self _sendTextAction:@"话题" ext:@{@"app":@(YES),
  2341. @"app_type":@(CollectModel_NewTopic),
  2342. @"app_title":self.sendModel.Title,
  2343. @"app_id":@(self.sendModel.SoureId),
  2344. @"app_content":self.sendModel.Author.length > 0 ? [NSString stringWithFormat:@"来自-%@",self.sendModel.Author] : @"",
  2345. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2346. @"app_min_url":self.sendModel.MinUrl,
  2347. @"app_url":self.sendModel.Url,
  2348. }];
  2349. }
  2350. break;
  2351. case CollectModel_Toipc:
  2352. {
  2353. [self _sendTextAction:@"话题" ext:@{@"app":@(YES),
  2354. @"app_type":@(CollectModel_Toipc),
  2355. @"app_title":self.sendModel.Title,
  2356. @"app_id":@(self.sendModel.SoureId),
  2357. @"app_content":self.sendModel.Author.length > 0 ? [NSString stringWithFormat:@"来自-%@",self.sendModel.Author] : @"",
  2358. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2359. @"app_min_url":self.sendModel.MinUrl,
  2360. @"app_url":self.sendModel.Url,
  2361. }];
  2362. }
  2363. break;
  2364. case CollectModel_InterMail:
  2365. {
  2366. [self _sendTextAction:@"站内信" ext:@{@"app":@(YES),
  2367. @"app_type":@(CollectModel_InterMail),
  2368. @"app_title":self.sendModel.Title,
  2369. @"app_id":@(self.sendModel.SoureId),
  2370. @"app_content":self.sendModel.Author.length > 0 ? [NSString stringWithFormat:@"来自-%@",self.sendModel.Author] : @"",
  2371. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2372. @"app_min_url":self.sendModel.MinUrl,
  2373. @"app_url":self.sendModel.Url,
  2374. }];
  2375. }
  2376. break;
  2377. case CollectModel_CollectFile:
  2378. {
  2379. [self _sendTextAction:@"收藏文件夹" ext:@{@"app":@(YES),
  2380. @"app_type":@(CollectModel_CollectFile),
  2381. @"app_title":self.sendModel.Title,
  2382. @"app_id":@(self.sendModel.SoureId),
  2383. @"app_content":self.sendModel.Author.length > 0 ? [NSString stringWithFormat:@"来自-%@",self.sendModel.Author] : @"",
  2384. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2385. @"app_min_url":self.sendModel.MinUrl,
  2386. @"app_url":self.sendModel.Url,
  2387. }];
  2388. }
  2389. break;
  2390. case CollectModel_NoteFile:
  2391. {
  2392. [self _sendTextAction:@"笔记文件夹" ext:@{@"app":@(YES),
  2393. @"app_type":@(CollectModel_NoteFile),
  2394. @"app_title":self.sendModel.Title,
  2395. @"app_id":@(self.sendModel.SoureId),
  2396. @"app_content":self.sendModel.Author.length > 0 ? [NSString stringWithFormat:@"来自-%@",self.sendModel.Author] : @"",
  2397. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2398. @"app_min_url":self.sendModel.MinUrl,
  2399. @"app_url":self.sendModel.Url,
  2400. }];
  2401. }
  2402. break;
  2403. case CollectModel_meetMian:
  2404. {
  2405. [self _sendTextAction:@"会议纪要" ext:@{@"app":@(YES),
  2406. @"app_type":@(CollectModel_meetMian),
  2407. @"app_title":self.sendModel.Title,
  2408. @"app_id":@(self.sendModel.SoureId),
  2409. @"app_content":self.sendModel.Author.length > 0 ? [NSString stringWithFormat:@"来自-%@",self.sendModel.Author] : @"",
  2410. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2411. @"app_min_url":self.sendModel.MinUrl,
  2412. @"app_url":self.sendModel.Url,
  2413. }];
  2414. }
  2415. break;
  2416. case CollectModel_Image:///图片
  2417. {
  2418. [self _sendTextAction:@"审批" ext:@{@"app":@(YES),
  2419. @"app_type":@(CollectModel_Image),
  2420. @"app_title":self.sendModel.Title,
  2421. @"app_id":@(self.sendModel.SoureId),
  2422. @"app_content":self.sendModel.Author.length > 0 ? [NSString stringWithFormat:@"来自-%@",self.sendModel.Author] : @"",
  2423. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2424. @"app_min_url":self.sendModel.MinUrl,
  2425. @"app_url":self.sendModel.Url,
  2426. }];
  2427. }
  2428. break;
  2429. case CollectModel_file:///文件
  2430. {
  2431. [self _sendTextAction:@"文件" ext:@{@"app":@(YES),
  2432. @"app_type":@(CollectModel_file),
  2433. @"app_title":self.sendModel.Title,
  2434. @"app_id":@(self.sendModel.SoureId),
  2435. @"app_content":self.sendModel.Author.length > 0 ? [NSString stringWithFormat:@"来自-%@",self.sendModel.Author] : @"",
  2436. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2437. @"app_min_url":self.sendModel.MinUrl,
  2438. @"app_url":self.sendModel.Url,
  2439. }];
  2440. }
  2441. break;
  2442. case CollectModel_work:///工作
  2443. {
  2444. [self _sendTextAction:@"审批" ext:@{@"app":@(YES),
  2445. @"app_type":@(CollectModel_work),
  2446. @"app_title":self.sendModel.Title,
  2447. @"app_id":@(self.sendModel.SoureId),
  2448. @"app_content":[NSString stringWithFormat:@"来自-%@",self.sendModel.Author],
  2449. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2450. @"app_min_url":@"",
  2451. @"app_url":@""
  2452. }];
  2453. }
  2454. break;
  2455. case CollectModel_meetDetail:///会议
  2456. {
  2457. [self _sendTextAction:@"会议" ext:@{@"app":@(YES),
  2458. @"app_type":@(CollectModel_meetDetail),
  2459. @"app_title":self.sendModel.Title,
  2460. @"app_id":@(self.sendModel.SoureId),
  2461. @"app_content":[NSString stringWithFormat:@"来自-%@",self.sendModel.Author],
  2462. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2463. @"app_min_url":@"",
  2464. @"app_url":@""
  2465. }];
  2466. }
  2467. break;
  2468. case CollectModel_financeCount:///文本
  2469. {
  2470. [self _sendTextAction:@"财务统计" ext:@{@"app":@(YES),
  2471. @"app_type":@(CollectModel_financeCount),
  2472. @"app_title":self.sendModel.Title,
  2473. @"app_id":@(self.sendModel.SoureId),
  2474. @"app_content":@"来自-财务统计",
  2475. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2476. @"app_min_url":@"",
  2477. @"app_url":@""
  2478. }];
  2479. }
  2480. break;
  2481. case CollectModel_affairsCount:///文本
  2482. {
  2483. [self _sendTextAction:@"人事统计" ext:@{@"app":@(YES),
  2484. @"app_type":@(CollectModel_affairsCount),
  2485. @"app_title":self.sendModel.Title,
  2486. @"app_id":@(self.sendModel.SoureId),
  2487. @"app_content":@"来自-人事统计",
  2488. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2489. @"app_min_url":@"",
  2490. @"app_url":@""
  2491. }];
  2492. }
  2493. break;
  2494. case CollectModel_publishCount:///文本
  2495. {
  2496. [self _sendTextAction:@"出版统计" ext:@{@"app":@(YES),
  2497. @"app_type":@(CollectModel_publishCount),
  2498. @"app_title":self.sendModel.Title,
  2499. @"app_id":@(self.sendModel.SoureId),
  2500. @"app_content":@"来自-出版统计",
  2501. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2502. @"app_min_url":@"",
  2503. @"app_url":@""
  2504. }];
  2505. }
  2506. break;
  2507. default:
  2508. {
  2509. [self _sendTextAction:@"出版统计" ext:@{@"app":@(YES),
  2510. @"app_type":@(CollectModel_publishCount),
  2511. @"app_title":self.sendModel.Title,
  2512. @"app_id":@(self.sendModel.SoureId),
  2513. @"app_content":@"来自-出版统计",
  2514. @"app_sourceUserId":@(self.sendModel.SourceUserId),
  2515. @"app_min_url":@"",
  2516. @"app_url":@""
  2517. }];
  2518. }
  2519. break;
  2520. }
  2521. }
  2522. }
  2523. #pragma mark - Action
  2524. - (void)backAction
  2525. {
  2526. [[EMAudioPlayerHelper sharedHelper] stopPlayer];
  2527. [EMConversationHelper resortConversationsLatestMessage];
  2528. EMConversation *conversation = self.conversationModel.emModel;
  2529. if (conversation.type == EMChatTypeChatRoom) {
  2530. [[EMClient sharedClient].roomManager leaveChatroom:conversation.conversationId completion:nil];
  2531. }
  2532. [self.navigationController popViewControllerAnimated:YES];
  2533. }
  2534. //删除该会话所有消息,同时清除内存和数据库中的消息
  2535. - (void)deleteAllMessageAction
  2536. {
  2537. EMError *error = nil;
  2538. [self.conversationModel.emModel deleteAllMessages:&error];
  2539. if (!error) {
  2540. [self.dataArray removeAllObjects];
  2541. [self.tableView reloadData];
  2542. }
  2543. }
  2544. - (void)groupOrChatroomInfoAction
  2545. {
  2546. if (self.conversationModel.emModel.type == EMConversationTypeGroupChat) {
  2547. [[NSNotificationCenter defaultCenter] postNotificationName:GROUP_INFO_PUSHVIEWCONTROLLER object:@{NOTIF_ID:self.conversationModel.emModel.conversationId, NOTIF_NAVICONTROLLER:self.navigationController}];
  2548. } else if (self.conversationModel.emModel.type == EMConversationTypeChatRoom) {
  2549. [[NSNotificationCenter defaultCenter] postNotificationName:CHATROOM_INFO_PUSHVIEWCONTROLLER object:@{NOTIF_ID:self.conversationModel.emModel.conversationId, NOTIF_NAVICONTROLLER:self.navigationController}];
  2550. }
  2551. }
  2552. //发送消息体
  2553. - (void)_sendMessageWithBody:(EMMessageBody *)aBody
  2554. ext:(NSDictionary *)aExt
  2555. isUpload:(BOOL)aIsUpload
  2556. {
  2557. if (!([EMClient sharedClient].options.isAutoTransferMessageAttachments) && aIsUpload) {
  2558. [self _showCustomTransferFileAlertView];
  2559. return;
  2560. }
  2561. NSString *from = [[EMClient sharedClient] currentUsername];
  2562. NSString *to = self.conversationModel.emModel.conversationId;
  2563. EMMessage *message = [[EMMessage alloc] initWithConversationID:to from:from to:to body:aBody ext:aExt];
  2564. //是否需要发送阅读回执
  2565. if([aExt objectForKey:MSG_EXT_READ_RECEIPT]) {
  2566. message.isNeedGroupAck = YES;
  2567. }
  2568. message.chatType = (EMChatType)self.conversationModel.emModel.type;
  2569. __weak typeof(self) weakself = self;
  2570. [[EMClient sharedClient].chatManager sendMessage:message progress:nil completion:^(EMMessage *message, EMError *error) {
  2571. NSArray *formated = [weakself _formatMessages:@[message]];
  2572. [weakself.dataArray addObjectsFromArray:formated];
  2573. dispatch_async(dispatch_get_main_queue(), ^{
  2574. [weakself.tableView reloadData];
  2575. [weakself _scrollToBottomRow];
  2576. });
  2577. NSLog(@"%@",@{@"ContactUserId":[NSString stringWithFormat:@"%ld",(long)self.toUserId],@"IndividualGroupId":@(self.IndividualGroupId)});
  2578. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  2579. [[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) {
  2580. NSLog(@"%@",responseObject);
  2581. if ([responseObject isKindOfClass:[NSDictionary class]]) {
  2582. NSInteger listId = [[responseObject objectForKey:@"Id"] integerValue];
  2583. if (listId > 0) {
  2584. weakself.listId = listId;
  2585. weakself.isTop = [[responseObject objectForKey:@"IsTop"] integerValue];
  2586. }
  2587. }
  2588. } failure:^(NSError * _Nonnull error) {
  2589. }];
  2590. });
  2591. }];
  2592. }
  2593. #pragma mark - CustomView
  2594. - (UIView *)titleV
  2595. {
  2596. if (!_titleV) {
  2597. _titleV = [UIView new];
  2598. _titleV.backgroundColor = [UIColor whiteColor];
  2599. }
  2600. return _titleV;
  2601. }
  2602. - (UIButton *)backBtn
  2603. {
  2604. if (!_backBtn) {
  2605. _backBtn = [UIButton new];
  2606. [_backBtn setImage:[UIImage imageNamed:@"back_black_icon"] forState:UIControlStateNormal];
  2607. }
  2608. return _backBtn;
  2609. }
  2610. - (UIButton *)tabBtn
  2611. {
  2612. if (!_tabBtn) {
  2613. _tabBtn = [UIButton new];
  2614. [_tabBtn setImage:[UIImage imageNamed:@"menu_black_icon"] forState:UIControlStateNormal];
  2615. }
  2616. return _tabBtn;
  2617. }
  2618. - (UILabel *)titleL
  2619. {
  2620. if (!_titleL) {
  2621. _titleL = [UILabel new];
  2622. [_titleL setTextColor: UIColorHex(0A0A0A)];
  2623. _titleL.font = [UIFont systemFontOfSize:18];
  2624. }
  2625. return _titleL;
  2626. }
  2627. - (UIButton *)mangerBtn
  2628. {
  2629. if (!_mangerBtn) {
  2630. _mangerBtn = [UIButton new];
  2631. [_mangerBtn setImage:[UIImage imageNamed:@"chatmsg_detailchat_more_icon"] forState:UIControlStateNormal];
  2632. }
  2633. return _mangerBtn;
  2634. }
  2635. - (NSMutableArray *)userInfoArray
  2636. {
  2637. if (!_userInfoArray) {
  2638. _userInfoArray = [NSMutableArray array];
  2639. }
  2640. return _userInfoArray;
  2641. }
  2642. - (void)selectMoreMenu:(NSInteger)index title:(NSString *)title
  2643. {
  2644. switch (index) {
  2645. case 0:{
  2646. [self chatBarDidCameraAction];
  2647. }break;
  2648. case 1:{
  2649. [self chatBarDidPhotoAction];
  2650. }break;
  2651. case 2:{
  2652. FavoritesViewController *favorites = [[FavoritesViewController alloc] init];
  2653. favorites.title = @"我的笔记";
  2654. [self.navigationController pushViewController:favorites animated:YES];
  2655. }break;
  2656. case 3:{
  2657. FavoritesViewController *favorites = [[FavoritesViewController alloc] init];
  2658. favorites.title = @"我的收藏";
  2659. [self.navigationController pushViewController:favorites animated:YES];
  2660. }break;
  2661. default:
  2662. break;
  2663. }
  2664. }
  2665. - (NSMutableArray *)chatDistoryArray
  2666. {
  2667. if(!_chatDistoryArray)
  2668. {
  2669. _chatDistoryArray = [[NSMutableArray alloc] initWithArray:USERDEFAULTSGET(@"ChatList")];
  2670. }
  2671. return _chatDistoryArray;
  2672. }
  2673. - (NSString *)getUserInfoInDocument{
  2674. for (NSDictionary * dict in self.chatDistoryArray) {
  2675. if ([[dict objectForKey:@"ImId"] isEqualToString:self.conversationModel.emModel.conversationId]) {
  2676. NSString * text = [dict objectForKey:@"text"];
  2677. return text;
  2678. }
  2679. }
  2680. return @"";
  2681. }
  2682. - (void)clearUserInfoInDocument
  2683. {
  2684. for (NSDictionary * dict in self.chatDistoryArray) {
  2685. if ([[dict objectForKey:@"ImId"] isEqualToString:self.conversationModel.emModel.conversationId]) {
  2686. [self.chatDistoryArray removeObject:dict];
  2687. break;
  2688. }
  2689. }
  2690. USERDEFAULTSSET(self.chatDistoryArray,@"ChatList");
  2691. }
  2692. - (void)saveUserInfoInDocument:(NSString *)text{
  2693. for (NSDictionary * dict in self.chatDistoryArray) {
  2694. if ([[dict objectForKey:@"ImId"] isEqualToString:self.conversationModel.emModel.conversationId]) {
  2695. [self.chatDistoryArray removeObject:dict];
  2696. break;
  2697. }
  2698. }
  2699. [self.chatDistoryArray addObject:@{@"ImId":self.conversationModel.emModel.conversationId,@"text":text}];
  2700. USERDEFAULTSSET(self.chatDistoryArray,@"ChatList");
  2701. }
  2702. - (void)deleteConversationMsg
  2703. {
  2704. WS(weakSelf);
  2705. [[EMClient sharedClient].chatManager deleteConversation:self.conversationModel.emModel.conversationId isDeleteMessages:YES completion:^(NSString *aConversationId, EMError *aError) {
  2706. [weakSelf deleteAllMessageAction];
  2707. }];
  2708. }
  2709. #pragma mark - 转发
  2710. - (void)shareHander{
  2711. [self.noteBookShareVC initNoteBookShareData];
  2712. self.noteBookShareVC.view.hidden = !self.noteBookShareVC.view.hidden;
  2713. }
  2714. - (NoteBookShareVC *)noteBookShareVC{
  2715. if (_noteBookShareVC == nil) {
  2716. _noteBookShareVC = [NoteBookShareVC initNoteBookShareVC];
  2717. [_noteBookShareVC.view setFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT)];
  2718. [_noteBookShareVC.view setHidden:YES];
  2719. _noteBookShareVC.delegate = self;
  2720. }
  2721. return _noteBookShareVC;
  2722. }
  2723. -(void)userSelectType:(NSString *)typeName WithIndexPath:(NSIndexPath *)indexPath{
  2724. self.noteBookShareVC.view.hidden = !self.noteBookShareVC.view.hidden;
  2725. if ([typeName isEqualToString:@"发给微信好友"]) {
  2726. }else if ([typeName isEqualToString:@"发到朋友圈"]){
  2727. }else if ([typeName isEqualToString:@"发到微博"]){
  2728. }else if ([typeName isEqualToString:@"发给QQ好友"]){
  2729. }else if ([typeName isEqualToString:@"发到消息"]){
  2730. }else if ([typeName isEqualToString:@"发到小组"]){
  2731. // [self returnToGroup];
  2732. }else if ([typeName isEqualToString:@"发到笔记"]){
  2733. [self returnToNote];
  2734. }else if ([typeName isEqualToString:@"发到话题"]){
  2735. [self returnToTopic];
  2736. }else{
  2737. }
  2738. }
  2739. #pragma mark - 分享功能
  2740. //- (void)returnToGroup
  2741. //{
  2742. // MyTDGroupViewController * vc = [[MyTDGroupViewController alloc] init];
  2743. // vc.type = CollectModel_Group;
  2744. // FlowAttachmentsModel * model = [[FlowAttachmentsModel alloc] init];
  2745. // model.SoureId = self.Id;
  2746. // model.SoureTypeId = self.type;
  2747. // model.Title = self.currentNoteModel.Title;
  2748. // model.Author = self.currentNoteModel.UserName;
  2749. // vc.sendModel = model;
  2750. // vc.isReturn = YES;
  2751. // [self.navigationController pushViewController:vc animated:YES];
  2752. //}
  2753. - (void)returnToNote
  2754. {
  2755. MoveViewController * vc = [MoveViewController initMoveViewController];
  2756. vc.isFromCreateBookVc = YES;
  2757. vc.TypeId = CreateNotesType;
  2758. vc.ParentId = 0;
  2759. vc.sendModel = self.sendModel;
  2760. vc.sendImage = self.sendImage;
  2761. vc.isReturn = YES;
  2762. [self.navigationController pushViewController:vc animated:YES];
  2763. }
  2764. - (void)returnToTopic
  2765. {
  2766. MyTDTopicCreateVC * vc = [MyTDTopicCreateVC initMyTDTopicCreateVC];
  2767. vc.type = CollectModel_NewTopic;
  2768. // if (self.IsShareText) {
  2769. // model.Title = self.shareText;
  2770. // model.SoureTypeId = 1;
  2771. // }else{
  2772. // model.SoureId = self.Id;
  2773. // model.SoureTypeId = self.type;
  2774. // model.Title = self.currentNoteModel.Title;
  2775. // model.Author = self.currentNoteModel.UserName;
  2776. // vc.type = CollectModel_NewTopic;
  2777. // }
  2778. vc.sendModel = self.sendModel;
  2779. vc.sendImage = self.sendImage;
  2780. vc.isReturn = YES;
  2781. [self.navigationController pushViewController:vc animated:YES];
  2782. }
  2783. @end