EMChatViewController.m 127 KB

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