WFCUMessageListViewController.m 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276
  1. //
  2. // MessageListViewController.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/8/31.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUMessageListViewController.h"
  9. #import <AVFoundation/AVFoundation.h>
  10. #import "WFCUImagePreviewViewController.h"
  11. #import "WFCUVoiceRecordView.h"
  12. #import "WFCUImageCell.h"
  13. #import "WFCUTextCell.h"
  14. #import "WFCUVoiceCell.h"
  15. #import "WFCULocationCell.h"
  16. #import "WFCUFileCell.h"
  17. #import "WFCUInformationCell.h"
  18. #import "WFCUCallSummaryCell.h"
  19. #import "WFCUStickerCell.h"
  20. #import "WFCUVideoCell.h"
  21. #import "WFCURecallCell.h"
  22. #import "WFCUConferenceInviteCell.h"
  23. #import "WFCUCardCell.h"
  24. #import "WFCUCompositeCell.h"
  25. #import "WFCUBrowserViewController.h"
  26. #import <WFChatClient/WFCChatClient.h>
  27. #import "WFCUProfileTableViewController.h"
  28. #import "WFCUMultiVideoViewController.h"
  29. #import "WFCUChatInputBar.h"
  30. #import "UIView+Toast.h"
  31. #import "WFCUConversationSettingViewController.h"
  32. #import "SDPhotoBrowser.h"
  33. #import "WFCULocationViewController.h"
  34. #import "WFCULocationPoint.h"
  35. #import "WFCUVideoViewController.h"
  36. #import "WFCUContactListViewController.h"
  37. #import "WFCUBrowserViewController.h"
  38. #import "MBProgressHUD.h"
  39. #import "WFCUMediaMessageDownloader.h"
  40. #import "VideoPlayerKit.h"
  41. #import "WFCUForwardViewController.h"
  42. #import <WFChatClient/WFCChatClient.h>
  43. #if WFCU_SUPPORT_VOIP
  44. #import <WFAVEngineKit/WFAVEngineKit.h>
  45. #endif
  46. #import "WFCUConfigManager.h"
  47. #import "WFCUSeletedUserViewController.h"
  48. #import "WFCUReceiptViewController.h"
  49. #import "UIColor+YH.h"
  50. #import "WFCUConversationTableViewController.h"
  51. #import "WFCUConversationSearchTableViewController.h"
  52. #import "WFCUMediaMessageGridViewController.h"
  53. #import "WFCUConferenceViewController.h"
  54. #import "WFCUGroupInfoViewController.h"
  55. #import "WFCUChannelProfileViewController.h"
  56. #import "WFCUQuoteViewController.h"
  57. #import "WFCUCompositeMessageViewController.h"
  58. @interface WFCUMessageListViewController () <UITextFieldDelegate, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UINavigationControllerDelegate, WFCUMessageCellDelegate, AVAudioPlayerDelegate, WFCUChatInputBarDelegate, SDPhotoBrowserDelegate, UIGestureRecognizerDelegate>
  59. @property (nonatomic, strong)NSMutableArray<WFCUMessageModel *> *modelList;
  60. @property (nonatomic, strong)NSMutableArray<WFCCMessage *> *mentionedMsgs;
  61. @property (nonatomic, strong)NSMutableDictionary<NSNumber *, Class> *cellContentDict;
  62. @property(nonatomic) AVAudioPlayer *player;
  63. @property(nonatomic) NSTimer *playTimer;
  64. @property(nonatomic, assign)long playingMessageId;
  65. @property(nonatomic, assign)BOOL loadingMore;
  66. @property(nonatomic, assign)BOOL hasMoreOld;
  67. @property(nonatomic, strong)WFCCUserInfo *targetUser;
  68. @property(nonatomic, strong)WFCCGroupInfo *targetGroup;
  69. @property(nonatomic, strong)WFCCChannelInfo *targetChannel;
  70. @property(nonatomic, strong)WFCCChatroomInfo *targetChatroom;
  71. @property(nonatomic, strong)WFCUChatInputBar *chatInputBar;
  72. @property(nonatomic, strong)VideoPlayerKit *videoPlayerViewController;
  73. @property (strong, nonatomic) UICollectionView *collectionView;
  74. @property (strong, nonatomic)NSArray<WFCCMessage *> *imageMsgs;
  75. @property (strong, nonatomic)NSString *orignalDraft;
  76. @property (nonatomic, strong)id<UIGestureRecognizerDelegate> scrollBackDelegate;
  77. @property (nonatomic, strong)UIView *backgroundView;
  78. @property (nonatomic, assign)BOOL showAlias;
  79. @property (nonatomic, strong)WFCUMessageCellBase *cell4Menu;
  80. @property (nonatomic, assign)BOOL firstAppear;
  81. @property (nonatomic, assign)BOOL hasNewMessage;
  82. @property (nonatomic, assign)BOOL loadingNew;
  83. @property (nonatomic, strong)UICollectionReusableView *headerView;
  84. @property (nonatomic, strong)UICollectionReusableView *footerView;
  85. @property (nonatomic, strong)UIActivityIndicatorView *headerActivityView;
  86. @property (nonatomic, strong)UIActivityIndicatorView *footerActivityView;
  87. @property (nonatomic, strong)NSTimer *showTypingTimer;
  88. @property (nonatomic, assign)BOOL isShowingKeyboard;
  89. @property (nonatomic, strong)NSMutableDictionary<NSString *, NSNumber *> *deliveryDict;
  90. @property (nonatomic, strong)NSMutableDictionary<NSString *, NSNumber *> *readDict;
  91. @property (nonatomic, strong)UIView *multiSelectPanel;
  92. @end
  93. @implementation WFCUMessageListViewController
  94. - (void)viewDidLoad {
  95. [super viewDidLoad];
  96. [self removeControllerStackIfNeed];
  97. self.cellContentDict = [[NSMutableDictionary alloc] init];
  98. [self initializedSubViews];
  99. self.firstAppear = YES;
  100. self.hasMoreOld = YES;
  101. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onResetKeyboard:)];
  102. [self.collectionView addGestureRecognizer:tap];
  103. [self reloadMessageList];
  104. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onReceiveMessages:) name:kReceiveMessages object:nil];
  105. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onRecallMessages:) name:kRecallMessages object:nil];
  106. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onDeleteMessages:) name:kDeleteMessages object:nil];
  107. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMessageDelivered:) name:kMessageDelivered object:nil];
  108. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMessageReaded:) name:kMessageReaded object:nil];
  109. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSendingMessage:) name:kSendingMessageStatusUpdated object:nil];
  110. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMessageListChanged:) name:kMessageListChanged object:self.conversation];
  111. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMenuHidden:) name:UIMenuControllerDidHideMenuNotification object:nil];
  112. #if WFCU_SUPPORT_VOIP
  113. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onCallStateChanged:) name:kCallStateUpdated object:nil];
  114. #endif
  115. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSettingUpdated:) name:kSettingUpdated object:nil];
  116. __weak typeof(self) ws = self;
  117. if(self.conversation.type == Single_Type) {
  118. [[NSNotificationCenter defaultCenter] addObserverForName:kUserInfoUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
  119. if ([ws.conversation.target isEqualToString:note.object]) {
  120. ws.targetUser = note.userInfo[@"userInfo"];
  121. }
  122. }];
  123. } else if(self.conversation.type == Group_Type) {
  124. [[NSNotificationCenter defaultCenter] addObserverForName:kGroupInfoUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
  125. if ([ws.conversation.target isEqualToString:note.object]) {
  126. ws.targetGroup = note.userInfo[@"groupInfo"];
  127. }
  128. }];
  129. [[NSNotificationCenter defaultCenter] addObserverForName:kGroupMemberUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
  130. if ([ws.conversation.target isEqualToString:note.object]) {
  131. ws.targetGroup = ws.targetGroup;
  132. }
  133. }];
  134. } else if(self.conversation.type == Channel_Type) {
  135. [[NSNotificationCenter defaultCenter] addObserverForName:kChannelInfoUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
  136. if ([ws.conversation.target isEqualToString:note.object]) {
  137. ws.targetChannel = note.userInfo[@"channelInfo"];
  138. }
  139. }];
  140. }
  141. [self setupNavigationItem];
  142. self.chatInputBar = [[WFCUChatInputBar alloc] initWithSuperView:self.backgroundView conversation:self.conversation delegate:self];
  143. self.orignalDraft = [[WFCCIMService sharedWFCIMService] getConversationInfo:self.conversation].draft;
  144. if (self.conversation.type == Chatroom_Type) {
  145. __block MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
  146. hud.label.text = WFCString(@"JoinChatroom");
  147. [hud showAnimated:YES];
  148. [[WFCCIMService sharedWFCIMService] joinChatroom:ws.conversation.target success:^{
  149. NSLog(@"join chatroom successs");
  150. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  151. [ws sendChatroomWelcomeMessage];
  152. });
  153. [hud hideAnimated:YES];
  154. } error:^(int error_code) {
  155. NSLog(@"join chatroom error");
  156. hud.mode = MBProgressHUDModeText;
  157. hud.label.text = WFCString(@"JoinChatroomFailure");
  158. // hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  159. [hud hideAnimated:YES afterDelay:1.f];
  160. hud.completionBlock = ^{
  161. [ws.navigationController popViewControllerAnimated:YES];
  162. };
  163. }];
  164. }
  165. WFCCConversationInfo *info = [[WFCCIMService sharedWFCIMService] getConversationInfo:self.conversation];
  166. self.chatInputBar.draft = info.draft;
  167. if (self.conversation.type == Group_Type) {
  168. dispatch_async(dispatch_get_main_queue(), ^{
  169. NSArray<WFCCGroupMember *> *groupMembers = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.conversation.target forceUpdate:NO];
  170. NSMutableArray *memberIds = [[NSMutableArray alloc] init];
  171. for (WFCCGroupMember *member in groupMembers) {
  172. [memberIds addObject:member.memberId];
  173. }
  174. [[WFCCIMService sharedWFCIMService] getUserInfos:memberIds inGroup:self.conversation.target];
  175. });
  176. }
  177. if (self.multiSelecting) {
  178. self.multiSelectPanel.hidden = NO;
  179. }
  180. }
  181. //The VC maybe pushed from search VC, so no need go back to search VC, need remove all the VC between current VC to WFCUConversationTableViewController
  182. - (void)removeControllerStackIfNeed {
  183. //highlightMessageId will be positive if the VC pushed from search VC
  184. if (self.highlightMessageId > 0) {
  185. if (self.navigationController.viewControllers.count < 3) {
  186. return;
  187. }
  188. NSMutableArray *controllers = [self.navigationController.viewControllers mutableCopy];
  189. BOOL foundParent = NO;
  190. NSMutableArray *tobeDeleteVCs = [[NSMutableArray alloc] init];
  191. for (int i = (int)controllers.count - 2; i >=0; i--) {
  192. UIViewController *controller = controllers[i];
  193. if ([controller isKindOfClass:[WFCUConversationTableViewController class]]) {
  194. foundParent = YES;
  195. break;
  196. } else {
  197. [tobeDeleteVCs addObject:controller];
  198. }
  199. }
  200. if (foundParent) {
  201. [controllers removeObjectsInArray:tobeDeleteVCs];
  202. self.navigationController.viewControllers = [controllers copy];
  203. }
  204. }
  205. }
  206. - (void)setupNavigationItem {
  207. if (self.multiSelecting) {
  208. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"search"] style:UIBarButtonItemStyleDone target:self action:@selector(onSearchBarBtn:)];
  209. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(onMultiSelectCancel:)];
  210. } else {
  211. if(self.conversation.type == Single_Type) {
  212. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"nav_chat_single"] style:UIBarButtonItemStyleDone target:self action:@selector(onRightBarBtn:)];
  213. } else if(self.conversation.type == Group_Type) {
  214. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"nav_chat_group"] style:UIBarButtonItemStyleDone target:self action:@selector(onRightBarBtn:)];
  215. } else if(self.conversation.type == Channel_Type) {
  216. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"nav_chat_channel"] style:UIBarButtonItemStyleDone target:self action:@selector(onRightBarBtn:)];
  217. }
  218. self.navigationItem.leftBarButtonItem = nil;
  219. }
  220. }
  221. - (void)onMultiSelectCancel:(id)sender {
  222. self.multiSelecting = !self.multiSelecting;
  223. }
  224. - (void)setLoadingMore:(BOOL)loadingMore {
  225. _loadingMore = loadingMore;
  226. if (_loadingMore) {
  227. [self.headerActivityView startAnimating];
  228. } else {
  229. [self.headerActivityView stopAnimating];
  230. }
  231. }
  232. - (UIActivityIndicatorView *)headerActivityView {
  233. if (!_headerActivityView) {
  234. _headerActivityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  235. }
  236. return _headerActivityView;
  237. }
  238. - (UIActivityIndicatorView *)footerActivityView {
  239. if (!_footerActivityView) {
  240. _footerActivityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  241. }
  242. return _footerActivityView;
  243. }
  244. - (void)setLoadingNew:(BOOL)loadingNew {
  245. _loadingNew = loadingNew;
  246. if (loadingNew) {
  247. [self.footerActivityView startAnimating];
  248. } else {
  249. [self.footerActivityView stopAnimating];
  250. }
  251. }
  252. - (void)setHasNewMessage:(BOOL)hasNewMessage {
  253. _hasNewMessage = hasNewMessage;
  254. UICollectionViewFlowLayout *_customFlowLayout = (UICollectionViewFlowLayout*)self.collectionView.collectionViewLayout;
  255. if (hasNewMessage) {
  256. _customFlowLayout.footerReferenceSize = CGSizeMake(320.0f, 20.0f);
  257. } else {
  258. _customFlowLayout.footerReferenceSize = CGSizeZero;
  259. }
  260. }
  261. - (void)loadMoreMessage:(BOOL)isHistory {
  262. __weak typeof(self) weakSelf = self;
  263. if (isHistory) {
  264. if (self.loadingMore) {
  265. return;
  266. }
  267. self.loadingMore = YES;
  268. long lastIndex = 0;
  269. if (weakSelf.modelList.count) {
  270. lastIndex = [weakSelf.modelList firstObject].message.messageId;
  271. }
  272. dispatch_async(dispatch_get_global_queue(0, DISPATCH_QUEUE_PRIORITY_DEFAULT), ^{
  273. NSArray *messageList = [[WFCCIMService sharedWFCIMService] getMessages:weakSelf.conversation contentTypes:nil from:lastIndex count:10 withUser:self.privateChatUser];
  274. if (!messageList.count) {
  275. long long lastUid = self.modelList.lastObject.message.messageUid;
  276. for (WFCUMessageModel *model in self.modelList) {
  277. if (model.message.messageUid > 0 && model.message.messageUid < lastUid) {
  278. lastUid = model.message.messageUid;
  279. }
  280. }
  281. [[WFCCIMService sharedWFCIMService] getRemoteMessages:weakSelf.conversation before:lastUid count:10 success:^(NSArray<WFCCMessage *> *messages) {
  282. NSMutableArray *reversedMsgs = [[NSMutableArray alloc] init];
  283. for (WFCCMessage *msg in messages) {
  284. [reversedMsgs insertObject:msg atIndex:0];
  285. }
  286. dispatch_async(dispatch_get_main_queue(), ^{
  287. if (!reversedMsgs.count) {
  288. weakSelf.hasMoreOld = NO;
  289. } else {
  290. [weakSelf appendMessages:reversedMsgs newMessage:NO highlightId:0 forceButtom:NO];
  291. }
  292. weakSelf.loadingMore = NO;
  293. });
  294. } error:^(int error_code) {
  295. dispatch_async(dispatch_get_main_queue(), ^{
  296. weakSelf.hasMoreOld = NO;
  297. weakSelf.loadingMore = NO;
  298. });
  299. }];
  300. } else {
  301. [NSThread sleepForTimeInterval:0.5];
  302. dispatch_async(dispatch_get_main_queue(), ^{
  303. [weakSelf appendMessages:messageList newMessage:NO highlightId:0 forceButtom:NO];
  304. weakSelf.loadingMore = NO;
  305. });
  306. }
  307. });
  308. } else {
  309. if (weakSelf.loadingNew || !weakSelf.hasNewMessage) {
  310. return;
  311. }
  312. weakSelf.loadingNew = YES;
  313. long lastIndex = 0;
  314. if (self.modelList.count) {
  315. lastIndex = [self.modelList lastObject].message.messageId;
  316. }
  317. dispatch_async(dispatch_get_global_queue(0, DISPATCH_QUEUE_PRIORITY_DEFAULT), ^{
  318. NSArray *messageList = [[WFCCIMService sharedWFCIMService] getMessages:self.conversation contentTypes:nil from:lastIndex count:-10 withUser:self.privateChatUser];
  319. if (!messageList.count || messageList.count < 10) {
  320. self.hasNewMessage = NO;
  321. }
  322. NSMutableArray *mutableMessages = [messageList mutableCopy];
  323. for (int i = 0; i < mutableMessages.count/2; i++) {
  324. int j = (int)mutableMessages.count - 1 - i;
  325. WFCCMessage *msg = [mutableMessages objectAtIndex:i];
  326. [mutableMessages insertObject:[mutableMessages objectAtIndex:j] atIndex:i];
  327. [mutableMessages removeObjectAtIndex:i+1];
  328. [mutableMessages insertObject:msg atIndex:j];
  329. [mutableMessages removeObjectAtIndex:j+1];
  330. }
  331. [NSThread sleepForTimeInterval:0.5];
  332. dispatch_async(dispatch_get_main_queue(), ^{
  333. [weakSelf appendMessages:mutableMessages newMessage:YES highlightId:0 forceButtom:NO];
  334. weakSelf.loadingNew = NO;
  335. });
  336. });
  337. }
  338. }
  339. - (void)sendChatroomWelcomeMessage {
  340. WFCCTipNotificationContent *tip = [[WFCCTipNotificationContent alloc] init];
  341. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[WFCCNetworkService sharedInstance].userId refresh:NO];
  342. tip.tip = [NSString stringWithFormat:WFCString(@"WelcomeJoinChatroomHint"), userInfo.displayName];
  343. [self sendMessage:tip];
  344. }
  345. - (void)sendChatroomLeaveMessage {
  346. __block WFCCConversation *strongConv = self.conversation;
  347. dispatch_async(dispatch_get_main_queue(), ^{
  348. WFCCTipNotificationContent *tip = [[WFCCTipNotificationContent alloc] init];
  349. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[WFCCNetworkService sharedInstance].userId refresh:NO];
  350. tip.tip = [NSString stringWithFormat:WFCString(@"LeaveChatroomHint"), userInfo.displayName];
  351. [[WFCCIMService sharedWFCIMService] send:strongConv content:tip success:^(long long messageUid, long long timestamp) {
  352. [[WFCCIMService sharedWFCIMService] quitChatroom:strongConv.target success:nil error:nil];
  353. } error:^(int error_code) {
  354. }];
  355. });
  356. }
  357. - (void)onLeftBtnPressed:(id)sender {
  358. [self.navigationController popViewControllerAnimated:YES];
  359. }
  360. - (void)didMoveToParentViewController:(UIViewController*)parent
  361. {
  362. [super didMoveToParentViewController:parent];
  363. if(!parent){
  364. [self leftMessageVC];
  365. }
  366. }
  367. - (void)leftMessageVC {
  368. if (self.conversation.type == Chatroom_Type) {
  369. [self sendChatroomLeaveMessage];
  370. }
  371. }
  372. - (void)onRightBarBtn:(UIBarButtonItem *)sender {
  373. WFCUConversationSettingViewController *gvc = [[WFCUConversationSettingViewController alloc] init];
  374. gvc.conversation = self.conversation;
  375. [self.navigationController pushViewController:gvc animated:YES];
  376. }
  377. - (void)onSearchBarBtn:(id)sender {
  378. if (self.multiSelecting) {
  379. for (WFCUMessageModel *model in self.modelList) {
  380. if (model.selected && ![self.selectedMessageIds containsObject:@(model.message.messageId)]) {
  381. [self.selectedMessageIds addObject:@(model.message.messageId)];
  382. }
  383. }
  384. WFCUConversationSearchTableViewController *mvc = [[WFCUConversationSearchTableViewController alloc] init];
  385. mvc.conversation = self.conversation;
  386. mvc.hidesBottomBarWhenPushed = YES;
  387. mvc.messageSelecting = YES;
  388. mvc.selectedMessageIds = self.selectedMessageIds;
  389. [self.navigationController pushViewController:mvc animated:YES];
  390. }
  391. }
  392. - (void)setTargetUser:(WFCCUserInfo *)targetUser {
  393. _targetUser = targetUser;
  394. if(targetUser.friendAlias.length) {
  395. self.title = targetUser.friendAlias;
  396. } else if(targetUser.displayName.length == 0) {
  397. self.title = [NSString stringWithFormat:@"%@<%@>", WFCString(@"User"), self.conversation.target];
  398. } else {
  399. self.title = targetUser.displayName;
  400. }
  401. self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] init];
  402. self.navigationItem.backBarButtonItem.title = self.title;
  403. }
  404. - (void)setTargetGroup:(WFCCGroupInfo *)targetGroup {
  405. _targetGroup = targetGroup;
  406. if(targetGroup.name.length == 0) {
  407. self.title = WFCString(@"GroupChat");
  408. self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] init];
  409. self.navigationItem.backBarButtonItem.title = WFCString(@"Message");
  410. } else {
  411. self.title = [NSString stringWithFormat:@"%@(%d)", targetGroup.name, (int)targetGroup.memberCount];
  412. self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] init];
  413. self.navigationItem.backBarButtonItem.title = targetGroup.name;
  414. }
  415. ChatInputBarStatus defaultStatus = ChatInputBarDefaultStatus;
  416. WFCCGroupMember *member = [[WFCCIMService sharedWFCIMService] getGroupMember:targetGroup.target memberId:[WFCCNetworkService sharedInstance].userId];
  417. if (targetGroup.mute || member.type == Member_Type_Muted) {
  418. if ([targetGroup.owner isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  419. self.chatInputBar.inputBarStatus = defaultStatus;
  420. } else if(targetGroup.mute && member.type == Member_Type_Allowed) {
  421. self.chatInputBar.inputBarStatus = defaultStatus;
  422. } else {
  423. WFCCGroupMember *gm = [[WFCCIMService sharedWFCIMService] getGroupMember:targetGroup.target memberId:[WFCCNetworkService sharedInstance].userId];
  424. if (gm.type == Member_Type_Manager) {
  425. self.chatInputBar.inputBarStatus = defaultStatus;
  426. } else {
  427. self.chatInputBar.inputBarStatus = ChatInputBarMuteStatus;
  428. }
  429. }
  430. } else {
  431. self.chatInputBar.inputBarStatus = defaultStatus;
  432. }
  433. }
  434. - (void)setTargetChannel:(WFCCChannelInfo *)targetChannel {
  435. _targetChannel = targetChannel;
  436. if(targetChannel.name.length == 0) {
  437. self.title = WFCString(@"Channel");
  438. self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] init];
  439. self.navigationItem.backBarButtonItem.title = WFCString(@"Message");
  440. } else {
  441. self.title = targetChannel.name;
  442. self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] init];
  443. self.navigationItem.backBarButtonItem.title = targetChannel.name;
  444. }
  445. }
  446. - (void)setTargetChatroom:(WFCCChatroomInfo *)targetChatroom {
  447. _targetChatroom = targetChatroom;
  448. if(targetChatroom.title.length == 0) {
  449. self.title = WFCString(@"Chatroom");
  450. self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] init];
  451. self.navigationItem.backBarButtonItem.title = WFCString(@"Message");
  452. } else {
  453. self.title = targetChatroom.title;
  454. self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] init];
  455. self.navigationItem.backBarButtonItem.title = targetChatroom.title;
  456. }
  457. }
  458. - (void)setShowAlias:(BOOL)showAlias {
  459. _showAlias = showAlias;
  460. if (self.modelList) {
  461. for (WFCUMessageModel *model in self.modelList) {
  462. if (showAlias && model.message.direction == MessageDirection_Receive) {
  463. model.showNameLabel = YES;
  464. } else {
  465. model.showNameLabel = NO;
  466. }
  467. }
  468. }
  469. }
  470. - (void)setMultiSelecting:(BOOL)multiSelecting {
  471. _multiSelecting = multiSelecting;
  472. if (multiSelecting) {
  473. for (WFCUMessageModel *model in self.modelList) {
  474. model.selecting = YES;
  475. model.selected = NO;
  476. }
  477. if (!self.selectedMessageIds) {
  478. self.selectedMessageIds = [[NSMutableArray alloc] init];
  479. }
  480. self.multiSelectPanel.hidden = NO;
  481. } else {
  482. for (WFCUMessageModel *model in self.modelList) {
  483. model.selecting = NO;
  484. model.selected = NO;
  485. }
  486. self.selectedMessageIds = nil;
  487. self.multiSelectPanel.hidden = YES;
  488. }
  489. [self setupNavigationItem];
  490. [self.collectionView reloadData];
  491. }
  492. - (UIView *)multiSelectPanel {
  493. if (!_multiSelectPanel) {
  494. if (!self.backgroundView) {
  495. return nil;
  496. }
  497. _multiSelectPanel = [[UIView alloc] initWithFrame:CGRectMake(0, self.backgroundView.bounds.size.height - CHAT_INPUT_BAR_HEIGHT, self.backgroundView.bounds.size.width, CHAT_INPUT_BAR_HEIGHT)];
  498. _multiSelectPanel.backgroundColor = [UIColor colorWithHexString:@"0xf7f7f7"];
  499. UIButton *deleteBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, _multiSelectPanel.bounds.size.width/2, _multiSelectPanel.bounds.size.height)];
  500. [deleteBtn setTitle:@"Delete" forState:UIControlStateNormal];
  501. [deleteBtn addTarget:self action:@selector(onDeleteMultiSelectedMessage:) forControlEvents:UIControlEventTouchDown];
  502. [deleteBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  503. [_multiSelectPanel addSubview:deleteBtn];
  504. UIButton *forwardBtn = [[UIButton alloc] initWithFrame:CGRectMake(_multiSelectPanel.bounds.size.width/2, 0, _multiSelectPanel.bounds.size.width/2, _multiSelectPanel.bounds.size.height)];
  505. [forwardBtn setTitle:@"转发" forState:UIControlStateNormal];
  506. [forwardBtn addTarget:self action:@selector(onForwardMultiSelectedMessage:) forControlEvents:UIControlEventTouchDown];
  507. [forwardBtn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
  508. [_multiSelectPanel addSubview:forwardBtn];
  509. [self.backgroundView addSubview:_multiSelectPanel];
  510. }
  511. return _multiSelectPanel;
  512. }
  513. - (void)onDeleteMultiSelectedMessage:(id)sender {
  514. NSMutableArray *deletedModels = [[NSMutableArray alloc] init];
  515. for (WFCUMessageModel *model in self.modelList) {
  516. if (model.selected) {
  517. [[WFCCIMService sharedWFCIMService] deleteMessage:model.message.messageId];
  518. [deletedModels addObject:model];
  519. [self.selectedMessageIds removeObject:@(model.message.messageId)];
  520. }
  521. }
  522. [self.modelList removeObjectsInArray:deletedModels];
  523. //有可能是经过多次搜索,选中了当前model列表中没有包含的
  524. for (NSNumber *IDS in self.selectedMessageIds) {
  525. [[WFCCIMService sharedWFCIMService] deleteMessage:[IDS longValue]];
  526. }
  527. self.multiSelecting = NO;
  528. }
  529. - (void)onForwardMultiSelectedMessage:(id)sender {
  530. NSMutableArray *messages = [[NSMutableArray alloc] init];
  531. for (WFCUMessageModel *model in self.modelList) {
  532. if (model.selected) {
  533. [messages addObject:model.message];
  534. }
  535. }
  536. [self.selectedMessageIds removeAllObjects];
  537. self.multiSelecting = NO;
  538. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  539. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:nil];
  540. UIAlertAction *oneByOneAction = [UIAlertAction actionWithTitle:WFCString(@"Fwd1By1") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  541. WFCUForwardViewController *controller = [[WFCUForwardViewController alloc] init];
  542. controller.messages = messages;
  543. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:controller];
  544. [self.navigationController presentViewController:navi animated:YES completion:nil];
  545. }];
  546. UIAlertAction *AllInOneAction = [UIAlertAction actionWithTitle:WFCString(@"FwdAllIn1") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  547. WFCCCompositeMessageContent *compositeContent = [[WFCCCompositeMessageContent alloc] init];
  548. compositeContent.targetName = self.title;
  549. compositeContent.messages = messages;
  550. WFCCMessage *msg = [[WFCCMessage alloc] init];
  551. msg.content = compositeContent;
  552. WFCUForwardViewController *controller = [[WFCUForwardViewController alloc] init];
  553. controller.message = msg;
  554. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:controller];
  555. [self.navigationController presentViewController:navi animated:YES completion:nil];
  556. }];
  557. [alertController addAction:cancelAction];
  558. [alertController addAction:oneByOneAction];
  559. [alertController addAction:AllInOneAction];
  560. [self presentViewController:alertController animated:YES completion:nil];
  561. }
  562. - (void)scrollToBottom:(BOOL)animated {
  563. NSUInteger rowCount = [self.collectionView numberOfItemsInSection:0];
  564. if (rowCount == 0) {
  565. return;
  566. }
  567. NSUInteger finalRow = rowCount - 1;
  568. for (int i = 0; i < self.modelList.count; i++) {
  569. if ([self.modelList objectAtIndex:i].highlighted) {
  570. finalRow = i;
  571. break;
  572. }
  573. }
  574. NSIndexPath *finalIndexPath = [NSIndexPath indexPathForItem:finalRow inSection:0];
  575. [self.collectionView scrollToItemAtIndexPath:finalIndexPath
  576. atScrollPosition:UICollectionViewScrollPositionBottom
  577. animated:animated];
  578. }
  579. - (void)initializedSubViews {
  580. UICollectionViewFlowLayout *_customFlowLayout = [[UICollectionViewFlowLayout alloc] init];
  581. _customFlowLayout.minimumLineSpacing = 0.0f;
  582. _customFlowLayout.sectionInset = UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f);
  583. _customFlowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
  584. _customFlowLayout.headerReferenceSize = CGSizeMake(320.0f, 20.0f);
  585. UIEdgeInsets insets = UIEdgeInsetsZero;
  586. if (@available(iOS 11.0, *)) {
  587. insets = self.view.safeAreaInsets;
  588. }
  589. CGRect frame = self.view.bounds;
  590. frame.origin.y += kStatusBarAndNavigationBarHeight;
  591. frame.size.height -= (kTabbarSafeBottomMargin + kStatusBarAndNavigationBarHeight);
  592. self.backgroundView = [[UIView alloc] initWithFrame:frame];
  593. [self.view addSubview:self.backgroundView];
  594. self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.backgroundView.bounds.size.width, self.backgroundView.bounds.size.height - CHAT_INPUT_BAR_HEIGHT) collectionViewLayout:_customFlowLayout];
  595. [self.backgroundView addSubview:self.collectionView];
  596. self.backgroundView.backgroundColor = [UIColor whiteColor];
  597. self.collectionView.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  598. self.collectionView.showsHorizontalScrollIndicator = NO;
  599. self.collectionView.showsVerticalScrollIndicator = NO;
  600. self.collectionView.alwaysBounceVertical = YES;
  601. self.view.backgroundColor = self.collectionView.backgroundColor;
  602. [self registerCell:[WFCUTextCell class] forContent:[WFCCTextMessageContent class]];
  603. [self registerCell:[WFCUTextCell class] forContent:[WFCCPTextMessageContent class]];
  604. [self registerCell:[WFCUImageCell class] forContent:[WFCCImageMessageContent class]];
  605. [self registerCell:[WFCUVoiceCell class] forContent:[WFCCSoundMessageContent class]];
  606. [self registerCell:[WFCUVideoCell class] forContent:[WFCCVideoMessageContent class]];
  607. [self registerCell:[WFCULocationCell class] forContent:[WFCCLocationMessageContent class]];
  608. [self registerCell:[WFCUFileCell class] forContent:[WFCCFileMessageContent class]];
  609. [self registerCell:[WFCUStickerCell class] forContent:[WFCCStickerMessageContent class]];
  610. [self registerCell:[WFCUInformationCell class] forContent:[WFCCCreateGroupNotificationContent class]];
  611. [self registerCell:[WFCUInformationCell class] forContent:[WFCCAddGroupeMemberNotificationContent class]];
  612. [self registerCell:[WFCUInformationCell class] forContent:[WFCCKickoffGroupMemberNotificaionContent class]];
  613. [self registerCell:[WFCUInformationCell class] forContent:[WFCCQuitGroupNotificationContent class]];
  614. [self registerCell:[WFCUInformationCell class] forContent:[WFCCDismissGroupNotificationContent class]];
  615. [self registerCell:[WFCUInformationCell class] forContent:[WFCCTransferGroupOwnerNotificationContent class]];
  616. [self registerCell:[WFCUInformationCell class] forContent:[WFCCModifyGroupAliasNotificationContent class]];
  617. [self registerCell:[WFCUInformationCell class] forContent:[WFCCChangeGroupNameNotificationContent class]];
  618. [self registerCell:[WFCUInformationCell class] forContent:[WFCCChangeGroupPortraitNotificationContent class]];
  619. [self registerCell:[WFCUInformationCell class] forContent:[WFCCFriendAddedMessageContent class]];
  620. [self registerCell:[WFCUInformationCell class] forContent:[WFCCFriendGreetingMessageContent class]];
  621. [self registerCell:[WFCUCallSummaryCell class] forContent:[WFCCCallStartMessageContent class]];
  622. [self registerCell:[WFCUInformationCell class] forContent:[WFCCTipNotificationContent class]];
  623. [self registerCell:[WFCUInformationCell class] forContent:[WFCCUnknownMessageContent class]];
  624. [self registerCell:[WFCURecallCell class] forContent:[WFCCRecallMessageContent class]];
  625. [self registerCell:[WFCUConferenceInviteCell class] forContent:[WFCCConferenceInviteMessageContent class]];
  626. [self registerCell:[WFCUCardCell class] forContent:[WFCCCardMessageContent class]];
  627. [self registerCell:[WFCUCompositeCell class] forContent:[WFCCCompositeMessageContent class]];
  628. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView"];
  629. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView"];
  630. self.collectionView.dataSource = self;
  631. self.collectionView.delegate = self;
  632. }
  633. - (void)registerCell:(Class)cellCls forContent:(Class)msgContentCls {
  634. [self.collectionView registerClass:cellCls
  635. forCellWithReuseIdentifier:[NSString stringWithFormat:@"%d", [msgContentCls getContentType]]];
  636. [self.cellContentDict setObject:cellCls forKey:@([msgContentCls getContentType])];
  637. }
  638. - (void)showTyping:(WFCCTypingType)typingType {
  639. if (self.showTypingTimer) {
  640. [self.showTypingTimer invalidate];
  641. }
  642. self.showTypingTimer = [NSTimer timerWithTimeInterval:TYPING_INTERVAL/2 target:self selector:@selector(stopShowTyping) userInfo:nil repeats:NO];
  643. [[NSRunLoop mainRunLoop] addTimer:self.showTypingTimer forMode:NSDefaultRunLoopMode];
  644. if (typingType == Typing_TEXT) {
  645. self.title = WFCString(@"TypingHint");
  646. } else if(typingType == Typing_VOICE) {
  647. self.title = WFCString(@"RecordingHint");
  648. } else if(typingType == Typing_CAMERA) {
  649. self.title = WFCString(@"PhotographingHint");
  650. } else if(typingType == Typing_LOCATION) {
  651. self.title = WFCString(@"GetLocationHint");
  652. } else if(typingType == Typing_FILE) {
  653. self.title = WFCString(@"SelectingFileHint");
  654. }
  655. }
  656. - (void)stopShowTyping {
  657. if(self.showTypingTimer != nil) {
  658. [self.showTypingTimer invalidate];
  659. self.showTypingTimer = nil;
  660. if (self.conversation.type == Single_Type) {
  661. self.targetUser = self.targetUser;
  662. } else if(self.conversation.type == Group_Type) {
  663. self.targetGroup = self.targetGroup;
  664. } else if(self.conversation.type == Channel_Type) {
  665. self.targetChannel = self.targetChannel;
  666. } else if(self.conversation.type == Group_Type) {
  667. self.targetGroup = self.targetGroup;
  668. }
  669. }
  670. }
  671. - (void)onResetKeyboard:(id)sender {
  672. [self.chatInputBar resetInputBarStatue];
  673. }
  674. - (void)didReceiveMemoryWarning {
  675. [super didReceiveMemoryWarning];
  676. }
  677. - (void)viewWillAppear:(BOOL)animated {
  678. [super viewWillAppear:animated];
  679. [self.chatInputBar willAppear];
  680. if(self.conversation.type == Single_Type) {
  681. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.conversation.target refresh:YES];
  682. self.targetUser = userInfo;
  683. } else if(self.conversation.type == Group_Type) {
  684. WFCCGroupInfo *groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:self.conversation.target refresh:YES];
  685. self.targetGroup = groupInfo;
  686. } else if (self.conversation.type == Channel_Type) {
  687. WFCCChannelInfo *channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:self.conversation.target refresh:YES];
  688. self.targetChannel = channelInfo;
  689. } else if(self.conversation.type == Chatroom_Type) {
  690. __weak typeof(self)ws = self;
  691. [[WFCCIMService sharedWFCIMService] getChatroomInfo:self.conversation.target upateDt:ws.targetChatroom.updateDt success:^(WFCCChatroomInfo *chatroomInfo) {
  692. ws.targetChatroom = chatroomInfo;
  693. } error:^(int error_code) {
  694. }];
  695. }
  696. self.tabBarController.tabBar.hidden = YES;
  697. [self.collectionView reloadData];
  698. if (self.navigationController.viewControllers.count > 1) { // 记录系统返回手势的代理
  699. _scrollBackDelegate = self.navigationController.interactivePopGestureRecognizer.delegate; // 设置系统返回手势的代理为当前控制器
  700. self.navigationController.interactivePopGestureRecognizer.delegate = self;
  701. }
  702. if (self.conversation.type == Group_Type) {
  703. self.showAlias = ![[WFCCIMService sharedWFCIMService] isHiddenGroupMemberName:self.targetGroup.target];
  704. }
  705. if (self.firstAppear) {
  706. self.firstAppear = NO;
  707. [self scrollToBottom:NO];
  708. }
  709. }
  710. - (void)viewDidAppear:(BOOL)animated {
  711. [super viewDidAppear:animated];
  712. }
  713. - (void)viewWillDisappear:(BOOL)animated {
  714. [super viewWillDisappear:animated];
  715. NSString *newDraft = self.chatInputBar.draft;
  716. if (![self.orignalDraft isEqualToString:newDraft]) {
  717. self.orignalDraft = newDraft;
  718. [[WFCCIMService sharedWFCIMService] setConversation:self.conversation draft:newDraft];
  719. }
  720. // 设置系统返回手势的代理为我们刚进入控制器的时候记录的系统的返回手势代理
  721. self.navigationController.interactivePopGestureRecognizer.delegate = _scrollBackDelegate;
  722. [self.chatInputBar resetInputBarStatue];
  723. }
  724. - (void)sendMessage:(WFCCMessageContent *)content {
  725. //发送消息时,client会发出"kSendingMessageStatusUpdated“的通知,消息界面收到通知后加入到列表中。
  726. __weak typeof(self) ws = self;
  727. NSMutableArray *tousers = nil;
  728. if (self.privateChatUser) {
  729. tousers = [[NSMutableArray alloc] init];
  730. [tousers addObject:self.privateChatUser];
  731. }
  732. [[WFCCIMService sharedWFCIMService] send:self.conversation content:content toUsers:tousers expireDuration:0 success:^(long long messageUid, long long timestamp) {
  733. NSLog(@"send message success");
  734. if ([content isKindOfClass:[WFCCStickerMessageContent class]]) {
  735. [ws saveStickerRemoteUrl:(WFCCStickerMessageContent *)content];
  736. }
  737. } error:^(int error_code) {
  738. NSLog(@"send message fail(%d)", error_code);
  739. }];
  740. }
  741. - (void)onReceiveMessages:(NSNotification *)notification {
  742. NSArray<WFCCMessage *> *messages = notification.object;
  743. [self appendMessages:messages newMessage:YES highlightId:0 forceButtom:NO];
  744. [[WFCCIMService sharedWFCIMService] clearUnreadStatus:self.conversation];
  745. }
  746. - (void)onRecallMessages:(NSNotification *)notification {
  747. long long messageUid = [notification.object longLongValue];
  748. WFCCMessage *msg = [[WFCCIMService sharedWFCIMService] getMessageByUid:messageUid];
  749. if (msg != nil) {
  750. for (int i = 0; i < self.modelList.count; i++) {
  751. WFCUMessageModel *model = [self.modelList objectAtIndex:i];
  752. if (model.message.messageUid == messageUid) {
  753. model.message = msg;
  754. [self.collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]]];
  755. break;
  756. }
  757. }
  758. }
  759. }
  760. - (void)onDeleteMessages:(NSNotification *)notification {
  761. long long messageUid = [notification.object longLongValue];
  762. for (int i = 0; i < self.modelList.count; i++) {
  763. WFCUMessageModel *model = [self.modelList objectAtIndex:i];
  764. if (model.message.messageUid == messageUid) {
  765. [self.modelList removeObject:model];
  766. [self.collectionView deleteItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]]];
  767. break;
  768. }
  769. }
  770. }
  771. - (void)onMessageDelivered:(NSNotification *)notification {
  772. if (self.conversation.type != Single_Type && self.conversation.type != Group_Type) {
  773. return;
  774. }
  775. NSArray<WFCCGroupMember *> *members = nil;
  776. if (self.conversation.type == Group_Type) {
  777. members = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.conversation.target forceUpdate:NO];
  778. }
  779. NSArray<WFCCDeliveryReport *> *delivereds = notification.object;
  780. __block BOOL refresh = NO;
  781. [delivereds enumerateObjectsUsingBlock:^(WFCCDeliveryReport * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  782. if (self.conversation.type == Single_Type) {
  783. if ([self.conversation.target isEqualToString:obj.userId]) {
  784. *stop = YES;
  785. refresh = YES;
  786. }
  787. }
  788. if (self.conversation.type == Group_Type) {
  789. for (WFCCGroupMember *member in members) {
  790. if ([member.memberId isEqualToString:obj.userId]) {
  791. *stop = YES;
  792. refresh = YES;
  793. }
  794. }
  795. }
  796. }];
  797. if (refresh) {
  798. self.deliveryDict = [[WFCCIMService sharedWFCIMService] getMessageDelivery:self.conversation];
  799. WFCCGroupInfo *groupInfo = nil;
  800. for (int i = 0; i < self.modelList.count; i++) {
  801. WFCUMessageModel *model = self.modelList[i];
  802. model.deliveryDict = self.deliveryDict;
  803. if (model.message.direction == MessageDirection_Receive || model.deliveryRate == 1.f) {
  804. continue;
  805. }
  806. if (self.conversation.type == Single_Type) {
  807. if (model.message.serverTime <= [[model.deliveryDict objectForKey:model.message.conversation.target] longLongValue]) {
  808. float rate = 1.f;
  809. if (rate != model.deliveryRate) {
  810. model.deliveryRate = rate;
  811. [self.collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]]];
  812. }
  813. }
  814. } else { //group
  815. long long messageTS = model.message.serverTime;
  816. __block int delieveriedCount = 0;
  817. [model.deliveryDict enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSNumber * _Nonnull obj, BOOL * _Nonnull stop) {
  818. if ([obj longLongValue] >= messageTS) {
  819. delieveriedCount++;
  820. }
  821. }];
  822. if (!groupInfo) {
  823. groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:model.message.conversation.target refresh:NO];
  824. }
  825. float rate = (float)delieveriedCount/(groupInfo.memberCount - 1);
  826. if (rate != model.deliveryRate) {
  827. model.deliveryRate = rate;
  828. [self.collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]]];
  829. }
  830. }
  831. }
  832. }
  833. }
  834. - (void)onMessageReaded:(NSNotification *)notification {
  835. if (self.conversation.type != Single_Type && self.conversation.type != Group_Type) {
  836. return;
  837. }
  838. NSArray<WFCCReadReport *> *readeds = notification.object;
  839. __block BOOL refresh = NO;
  840. [readeds enumerateObjectsUsingBlock:^(WFCCReadReport * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  841. if ([obj.conversation isEqual:self.conversation]) {
  842. *stop = YES;
  843. refresh = YES;
  844. }
  845. }];
  846. if (refresh) {
  847. self.readDict = [[WFCCIMService sharedWFCIMService] getConversationRead:self.conversation];
  848. WFCCGroupInfo *groupInfo = nil;
  849. for (int i = 0; i < self.modelList.count; i++) {
  850. WFCUMessageModel *model = self.modelList[i];
  851. model.readDict = self.readDict;
  852. if (model.message.direction == MessageDirection_Receive || model.readRate == 1.f) {
  853. continue;
  854. }
  855. if (self.conversation.type == Single_Type) {
  856. if (model.message.serverTime <= [[model.readDict objectForKey:model.message.conversation.target] longLongValue]) {
  857. float rate = 1.f;
  858. if (rate != model.readRate) {
  859. model.readRate = rate;
  860. [self.collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]]];
  861. }
  862. }
  863. } else { //group
  864. long long messageTS = model.message.serverTime;
  865. __block int delieveriedCount = 0;
  866. [model.readDict enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSNumber * _Nonnull obj, BOOL * _Nonnull stop) {
  867. if ([obj longLongValue] >= messageTS) {
  868. delieveriedCount++;
  869. }
  870. }];
  871. if (!groupInfo) {
  872. groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:model.message.conversation.target refresh:NO];
  873. }
  874. float rate = (float)delieveriedCount/(groupInfo.memberCount - 1);
  875. if (rate != model.readRate) {
  876. model.readRate = rate;
  877. [self.collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]]];
  878. }
  879. }
  880. }
  881. }
  882. }
  883. #if WFCU_SUPPORT_VOIP
  884. - (void)onCallStateChanged:(NSNotification *)notification {
  885. long long messageUid = [[notification.userInfo objectForKey:@"messageUid"] longLongValue];
  886. WFCCMessage *msg = [[WFCCIMService sharedWFCIMService] getMessageByUid:messageUid];
  887. for (int i = 0; i < self.modelList.count; i++) {
  888. WFCUMessageModel *model = [self.modelList objectAtIndex:i];
  889. if (model.message.messageUid == messageUid) {
  890. model.message.content = msg.content;
  891. [self.collectionView reloadData];
  892. break;
  893. }
  894. }
  895. if ([[notification.userInfo objectForKey:@"state"] intValue] == kWFAVEngineStateIncomming) {
  896. if ([[[UIDevice currentDevice] systemVersion] rangeOfString:@"10."].location == 0) {
  897. [self.chatInputBar resetInputBarStatue];
  898. }
  899. }
  900. }
  901. #endif
  902. - (void)onSendingMessage:(NSNotification *)notification {
  903. WFCCMessage *message = [notification.userInfo objectForKey:@"message"];
  904. WFCCMessageStatus status = [[notification.userInfo objectForKey:@"status"] integerValue];
  905. if (status == Message_Status_Sending) {
  906. if ([message.conversation isEqual:self.conversation]) {
  907. [self appendMessages:@[message] newMessage:YES highlightId:0 forceButtom:YES];
  908. }
  909. }
  910. }
  911. - (void)onMessageListChanged:(NSNotification *)notification {
  912. [self reloadMessageList];
  913. }
  914. - (void)onSettingUpdated:(NSNotification *)notification {
  915. [self reloadMessageList];
  916. }
  917. - (void)reloadMessageList {
  918. self.deliveryDict = [[WFCCIMService sharedWFCIMService] getMessageDelivery:self.conversation];
  919. self.readDict = [[WFCCIMService sharedWFCIMService] getConversationRead:self.conversation];
  920. NSArray *messageList;
  921. if (self.highlightMessageId > 0) {
  922. NSArray *messageListOld = [[WFCCIMService sharedWFCIMService] getMessages:self.conversation contentTypes:nil from:self.highlightMessageId+1 count:15 withUser:self.privateChatUser];
  923. NSArray *messageListNew = [[WFCCIMService sharedWFCIMService] getMessages:self.conversation contentTypes:nil from:self.highlightMessageId count:-15 withUser:self.privateChatUser];
  924. NSMutableArray *list = [[NSMutableArray alloc] init];
  925. [list addObjectsFromArray:messageListNew];
  926. [list addObjectsFromArray:messageListOld];
  927. messageList = [list copy];
  928. [[WFCCIMService sharedWFCIMService] clearUnreadStatus:self.conversation];
  929. if (messageListNew.count == 15) {
  930. self.hasNewMessage = YES;
  931. }
  932. } else {
  933. int count = (int)self.modelList.count;
  934. if (count > 50) {
  935. count = 50;
  936. } else if(count == 0) {
  937. count = 15;
  938. }
  939. messageList = [[WFCCIMService sharedWFCIMService] getMessages:self.conversation contentTypes:nil from:0 count:count withUser:self.privateChatUser];
  940. self.mentionedMsgs = [[[WFCCIMService sharedWFCIMService] getMessages:self.conversation messageStatus:@[@(Message_Status_Mentioned), @(Message_Status_AllMentioned)] from:0 count:100 withUser:self.privateChatUser] mutableCopy];
  941. [[WFCCIMService sharedWFCIMService] clearUnreadStatus:self.conversation];
  942. }
  943. self.modelList = [[NSMutableArray alloc] init];
  944. [self appendMessages:messageList newMessage:NO highlightId:self.highlightMessageId forceButtom:NO];
  945. self.highlightMessageId = 0;
  946. }
  947. - (void)appendMessages:(NSArray<WFCCMessage *> *)messages newMessage:(BOOL)newMessage highlightId:(long)highlightId forceButtom:(BOOL)forceButtom {
  948. if (messages.count == 0) {
  949. return;
  950. }
  951. int count = 0;
  952. NSMutableArray *modifiedAliasUsers = [[NSMutableArray alloc] init];
  953. for (int i = 0; i < messages.count; i++) {
  954. WFCCMessage *message = [messages objectAtIndex:i];
  955. if (![message.conversation isEqual:self.conversation]) {
  956. continue;
  957. }
  958. if ([message.content isKindOfClass:[WFCCTypingMessageContent class]] && message.direction == MessageDirection_Receive) {
  959. double now = [[NSDate date] timeIntervalSince1970];
  960. if (now - message.serverTime + [WFCCNetworkService sharedInstance].serverDeltaTime < TYPING_INTERVAL) {
  961. WFCCTypingMessageContent *content = (WFCCTypingMessageContent *)message.content;
  962. [self showTyping:content.type];
  963. }
  964. continue;
  965. }
  966. if (!([message.content.class getContentFlags] & 0x1)) {
  967. continue;
  968. }
  969. BOOL duplcated = NO;
  970. for (WFCUMessageModel *model in self.modelList) {
  971. if (model.message.messageUid !=0 && model.message.messageUid == message.messageUid) {
  972. duplcated = YES;
  973. break;
  974. }
  975. }
  976. if (duplcated) {
  977. continue;
  978. }
  979. count++;
  980. if (newMessage) {
  981. BOOL showTime = YES;
  982. if (self.modelList.count > 0 && (message.serverTime - (self.modelList[self.modelList.count - 1]).message.serverTime < 60 * 1000)) {
  983. showTime = NO;
  984. }
  985. WFCUMessageModel *model = [WFCUMessageModel modelOf:message showName:message.direction == MessageDirection_Receive && self.showAlias showTime:showTime];
  986. model.selecting = self.multiSelecting;
  987. model.selected = [self.selectedMessageIds containsObject:@(message.messageId)];
  988. model.deliveryDict = self.deliveryDict;
  989. model.readDict = self.readDict;
  990. [self.modelList addObject:model];
  991. if (messages.count == 1) {
  992. [self.collectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:self.modelList.count - 1 inSection:0]]];
  993. }
  994. if (self.conversation.type == Group_Type && [message.content isKindOfClass:[WFCCModifyGroupAliasNotificationContent class]]) {
  995. [modifiedAliasUsers addObject:message.fromUser];
  996. }
  997. } else {
  998. if (self.modelList.count > 0 && (self.modelList[0].message.serverTime - message.serverTime < 60 * 1000) && i != 0) {
  999. self.modelList[0].showTimeLabel = NO;
  1000. }
  1001. WFCUMessageModel *model = [WFCUMessageModel modelOf:message showName:message.direction == MessageDirection_Receive&&self.showAlias showTime:YES];
  1002. model.selecting = self.multiSelecting;
  1003. model.selected = [self.selectedMessageIds containsObject:@(message.messageId)];
  1004. model.deliveryDict = self.deliveryDict;
  1005. model.readDict = self.readDict;
  1006. [self.modelList insertObject:model atIndex:0];
  1007. }
  1008. }
  1009. if (count > 0) {
  1010. [self stopShowTyping];
  1011. }
  1012. BOOL isAtButtom = NO;
  1013. if (newMessage && !self.hasNewMessage) {
  1014. if (@available(iOS 12.0, *)) {
  1015. CGPoint offset = self.collectionView.contentOffset;
  1016. CGSize size = self.collectionView.contentSize;
  1017. CGSize visiableSize = CGSizeZero;
  1018. visiableSize = self.collectionView.visibleSize;
  1019. isAtButtom = (offset.y + visiableSize.height - size.height) > -100;
  1020. } else {
  1021. isAtButtom = YES;
  1022. }
  1023. }
  1024. if (newMessage && messages.count == 1) {
  1025. NSLog(@"alread reload the message");
  1026. } else {
  1027. [self.collectionView reloadData];
  1028. }
  1029. if (newMessage || self.modelList.count == messages.count) {
  1030. if(isAtButtom) {
  1031. forceButtom = true;
  1032. }
  1033. } else {
  1034. CGFloat offset = 0;
  1035. for (int i = 0; i < count; i++) {
  1036. CGSize size = [self collectionView:self.collectionView layout:self.collectionView.collectionViewLayout sizeForItemAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
  1037. offset += size.height;
  1038. }
  1039. self.collectionView.contentOffset = CGPointMake(0, offset);
  1040. [UIView animateWithDuration:0.2 animations:^{
  1041. self.collectionView.contentOffset = CGPointMake(0, offset - 20);
  1042. }];
  1043. }
  1044. if (highlightId > 0) {
  1045. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1046. int row = 0;
  1047. for (int i = 0; i < self.modelList.count; i++) {
  1048. WFCUMessageModel *model = self.modelList[i];
  1049. if (model.message.messageId == highlightId) {
  1050. row = i;
  1051. model.highlighted = YES;
  1052. break;
  1053. }
  1054. }
  1055. [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO];
  1056. });
  1057. } else if (forceButtom) {
  1058. [self scrollToBottom:YES];
  1059. }
  1060. if (modifiedAliasUsers.count) {
  1061. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1062. NSArray<NSIndexPath *> *visibleItems = self.collectionView.indexPathsForVisibleItems;
  1063. NSMutableArray *needUpdateItems = [[NSMutableArray alloc] init];
  1064. for (NSIndexPath *item in visibleItems) {
  1065. WFCUMessageModel *model = [self.modelList objectAtIndex:item.row];
  1066. if ([modifiedAliasUsers containsObject:model.message.fromUser]) {
  1067. [needUpdateItems addObject:item];
  1068. }
  1069. }
  1070. if (needUpdateItems.count) {
  1071. [self.collectionView reloadItemsAtIndexPaths:needUpdateItems];
  1072. }
  1073. });
  1074. }
  1075. }
  1076. - (WFCUMessageModel *)modelOfMessage:(long)messageId {
  1077. if (messageId <= 0) {
  1078. return nil;
  1079. }
  1080. for (WFCUMessageModel *model in self.modelList) {
  1081. if (model.message.messageId == messageId) {
  1082. return model;
  1083. }
  1084. }
  1085. return nil;
  1086. }
  1087. - (void)stopPlayer {
  1088. if (self.player && [self.player isPlaying]) {
  1089. [self.player stop];
  1090. if ([self.playTimer isValid]) {
  1091. [self.playTimer invalidate];
  1092. self.playTimer = nil;
  1093. }
  1094. }
  1095. [self modelOfMessage:self.playingMessageId].voicePlaying = NO;
  1096. self.playingMessageId = 0;
  1097. [[NSNotificationCenter defaultCenter] postNotificationName:kVoiceMessagePlayStoped object:nil];
  1098. }
  1099. -(void)prepardToPlay:(WFCUMessageModel *)model {
  1100. if (self.playingMessageId == model.message.messageId) {
  1101. [self stopPlayer];
  1102. } else {
  1103. [self stopPlayer];
  1104. self.playingMessageId = model.message.messageId;
  1105. WFCCSoundMessageContent *soundContent = (WFCCSoundMessageContent *)model.message.content;
  1106. if (soundContent.localPath.length == 0) {
  1107. __weak typeof(self) weakSelf = self;
  1108. BOOL isDownloading = [[WFCUMediaMessageDownloader sharedDownloader] tryDownload:model.message success:^(long long messageUid, NSString *localPath) {
  1109. model.mediaDownloading = NO;
  1110. [weakSelf startPlay:model];
  1111. } error:^(long long messageUid, int error_code) {
  1112. model.mediaDownloading = NO;
  1113. }];
  1114. if (isDownloading) {
  1115. model.mediaDownloading = YES;
  1116. }
  1117. } else {
  1118. [self startPlay:model];
  1119. }
  1120. }
  1121. }
  1122. -(void)startPlay:(WFCUMessageModel *)model {
  1123. if ([model.message.content isKindOfClass:[WFCCSoundMessageContent class]]) {
  1124. // Setup audio session
  1125. AVAudioSession *session = [AVAudioSession sharedInstance];
  1126. [session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];
  1127. [session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker
  1128. error:nil];
  1129. WFCCSoundMessageContent *snc = (WFCCSoundMessageContent *)model.message.content;
  1130. NSError *error = nil;
  1131. self.player = [[AVAudioPlayer alloc] initWithData:[snc getWavData] error:&error];
  1132. [self.player setDelegate:self];
  1133. [self.player prepareToPlay];
  1134. [self.player play];
  1135. model.voicePlaying = YES;
  1136. [[NSNotificationCenter defaultCenter] postNotificationName:kVoiceMessageStartPlaying object:@(self.playingMessageId)];
  1137. } else if([model.message.content isKindOfClass:[WFCCVideoMessageContent class]]) {
  1138. WFCCVideoMessageContent *videoMsg = (WFCCVideoMessageContent *)model.message.content;
  1139. NSURL *url = [NSURL fileURLWithPath:[videoMsg.localPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  1140. if (!url) {
  1141. [self.view makeToast:@"无法播放"];
  1142. return;
  1143. }
  1144. if (!self.videoPlayerViewController) {
  1145. self.videoPlayerViewController = [VideoPlayerKit videoPlayerWithContainingView:self.view optionalTopView:nil hideTopViewWithControls:YES];
  1146. self.videoPlayerViewController.allowPortraitFullscreen = YES;
  1147. } else {
  1148. [self.videoPlayerViewController.view removeFromSuperview];
  1149. }
  1150. [self.view addSubview:self.videoPlayerViewController.view];
  1151. [self.videoPlayerViewController playVideoWithTitle:@" " URL:url videoID:nil shareURL:nil isStreaming:NO playInFullScreen:YES];
  1152. }
  1153. }
  1154. #pragma mark - UICollectionViewDataSource
  1155. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  1156. return self.modelList.count;
  1157. }
  1158. // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
  1159. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  1160. WFCUMessageModel *model = self.modelList[indexPath.row];
  1161. NSString *objName = [NSString stringWithFormat:@"%d", [model.message.content.class getContentType]];
  1162. if (self.mentionedMsgs.count) {
  1163. for (WFCCMessage *msg in self.mentionedMsgs) {
  1164. if (msg.messageId == model.message.messageId) {
  1165. [self.mentionedMsgs removeObject:msg];
  1166. break;
  1167. }
  1168. }
  1169. }
  1170. WFCUMessageCellBase *cell = nil;
  1171. if(![self.cellContentDict objectForKey:@([model.message.content.class getContentType])]) {
  1172. cell = [collectionView dequeueReusableCellWithReuseIdentifier:[NSString stringWithFormat:@"%d", [WFCCUnknownMessageContent getContentType]] forIndexPath:indexPath];
  1173. } else {
  1174. cell = [collectionView dequeueReusableCellWithReuseIdentifier:objName forIndexPath:indexPath];
  1175. }
  1176. cell.delegate = self;
  1177. [[NSNotificationCenter defaultCenter] removeObserver:cell];
  1178. cell.model = model;
  1179. return cell;
  1180. }
  1181. - (UICollectionReusableView *) collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  1182. {
  1183. if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
  1184. if(!self.headerView) {
  1185. self.headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
  1186. self.headerActivityView.center = CGPointMake(self.headerView.bounds.size.width/2, self.headerView.bounds.size.height/2);
  1187. [self.headerView addSubview:self.headerActivityView];
  1188. }
  1189. return self.headerView;
  1190. } else {
  1191. if(!self.footerView) {
  1192. self.footerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"FooterView" forIndexPath:indexPath];
  1193. self.footerActivityView.center = CGPointMake(self.footerView.bounds.size.width/2, self.footerView.bounds.size.height/2);
  1194. [self.footerView addSubview:self.footerActivityView];
  1195. }
  1196. return self.footerView;
  1197. }
  1198. return nil;
  1199. }
  1200. #pragma mark - UICollectionViewDelegateFlowLayout
  1201. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  1202. WFCUMessageModel *model = self.modelList[indexPath.row];
  1203. Class cellCls = self.cellContentDict[@([[model.message.content class] getContentType])];
  1204. if (!cellCls) {
  1205. cellCls = self.cellContentDict[@([[WFCCUnknownMessageContent class] getContentType])];
  1206. }
  1207. return [cellCls sizeForCell:model withViewWidth:self.collectionView.frame.size.width];
  1208. }
  1209. #pragma mark - MessageCellDelegate
  1210. - (void)didTapMessageCell:(WFCUMessageCellBase *)cell withModel:(WFCUMessageModel *)model {
  1211. if ([model.message.content isKindOfClass:[WFCCImageMessageContent class]]) {
  1212. if (self.conversation.type == Chatroom_Type) {
  1213. NSMutableArray *imageMsgs = [[NSMutableArray alloc] init];
  1214. for (WFCUMessageModel *msgModle in self.modelList) {
  1215. if ([msgModle.message.content isKindOfClass:[WFCCImageMessageContent class]]) {
  1216. [imageMsgs addObject:msgModle.message];
  1217. }
  1218. }
  1219. self.imageMsgs = imageMsgs;
  1220. } else {
  1221. self.imageMsgs = [[WFCCIMService sharedWFCIMService] getMessages:self.conversation contentTypes:@[@(MESSAGE_CONTENT_TYPE_IMAGE)] from:0 count:100 withUser:self.privateChatUser];
  1222. }
  1223. SDPhotoBrowser *browser = [[SDPhotoBrowser alloc] init];
  1224. browser.sourceImagesContainerView = self.backgroundView;
  1225. browser.showAll = YES;
  1226. browser.imageCount = self.imageMsgs.count;
  1227. int i;
  1228. for (i = 0; i < self.imageMsgs.count; i++) {
  1229. if ([self.imageMsgs objectAtIndex:i].messageId == model.message.messageId) {
  1230. break;
  1231. }
  1232. }
  1233. if (i == self.imageMsgs.count) {
  1234. i = 0;
  1235. }
  1236. [self onResetKeyboard:nil];
  1237. browser.currentImageIndex = i;
  1238. browser.delegate = self;
  1239. [browser show]; // 展示图片浏览器
  1240. } else if([model.message.content isKindOfClass:[WFCCSoundMessageContent class]]) {
  1241. if (model.message.direction == MessageDirection_Receive && model.message.status != Message_Status_Played) {
  1242. [[WFCCIMService sharedWFCIMService] setMediaMessagePlayed:model.message.messageId];
  1243. model.message.status = Message_Status_Played;
  1244. [self.collectionView reloadItemsAtIndexPaths:@[[self.collectionView indexPathForCell:cell]]];
  1245. }
  1246. [self prepardToPlay:model];
  1247. } else if([model.message.content isKindOfClass:[WFCCLocationMessageContent class]]) {
  1248. WFCCLocationMessageContent *locContent = (WFCCLocationMessageContent *)model.message.content;
  1249. WFCULocationViewController *vc = [[WFCULocationViewController alloc] initWithLocationPoint:[[WFCULocationPoint alloc] initWithCoordinate:locContent.coordinate andTitle:locContent.title]];
  1250. [self.navigationController pushViewController:vc animated:YES];
  1251. } else if ([model.message.content isKindOfClass:[WFCCFileMessageContent class]]) {
  1252. WFCCFileMessageContent *fileContent = (WFCCFileMessageContent *)model.message.content;
  1253. __weak typeof(self)ws = self;
  1254. [[WFCCIMService sharedWFCIMService] getAuthorizedMediaUrl:model.message.messageUid mediaType:Media_Type_FILE mediaPath:fileContent.remoteUrl success:^(NSString *authorizedUrl) {
  1255. WFCUBrowserViewController *bvc = [[WFCUBrowserViewController alloc] init];
  1256. bvc.url = authorizedUrl;
  1257. [ws.navigationController pushViewController:bvc animated:YES];
  1258. } error:^(int error_code) {
  1259. WFCUBrowserViewController *bvc = [[WFCUBrowserViewController alloc] init];
  1260. bvc.url = fileContent.remoteUrl;
  1261. [ws.navigationController pushViewController:bvc animated:YES];
  1262. }];
  1263. } else if ([model.message.content isKindOfClass:[WFCCCallStartMessageContent class]]) {
  1264. WFCCCallStartMessageContent *callStartMsg = (WFCCCallStartMessageContent *)model.message.content;
  1265. #if WFCU_SUPPORT_VOIP
  1266. [self didTouchVideoBtn:callStartMsg.isAudioOnly];
  1267. #endif
  1268. } else if([model.message.content isKindOfClass:[WFCCVideoMessageContent class]]) {
  1269. WFCCVideoMessageContent *videoMsg = (WFCCVideoMessageContent *)model.message.content;
  1270. if (model.message.direction == MessageDirection_Receive && model.message.status != Message_Status_Played) {
  1271. [[WFCCIMService sharedWFCIMService] setMediaMessagePlayed:model.message.messageId];
  1272. model.message.status = Message_Status_Played;
  1273. [self.collectionView reloadItemsAtIndexPaths:@[[self.collectionView indexPathForCell:cell]]];
  1274. }
  1275. if (videoMsg.localPath.length == 0) {
  1276. model.mediaDownloading = YES;
  1277. __weak typeof(self) weakSelf = self;
  1278. [[WFCUMediaMessageDownloader sharedDownloader] tryDownload:model.message success:^(long long messageUid, NSString *localPath) {
  1279. model.mediaDownloading = NO;
  1280. [weakSelf startPlay:model];
  1281. } error:^(long long messageUid, int error_code) {
  1282. model.mediaDownloading = NO;
  1283. }];
  1284. } else {
  1285. [self startPlay:model];
  1286. }
  1287. } else if([model.message.content isKindOfClass:[WFCCConferenceInviteMessageContent class]]) {
  1288. if ([WFAVEngineKit sharedEngineKit].supportConference) {
  1289. WFCCConferenceInviteMessageContent *invite = (WFCCConferenceInviteMessageContent *)model.message.content;
  1290. WFCUConferenceViewController *vc = [[WFCUConferenceViewController alloc] initWithInvite:invite];
  1291. [[WFAVEngineKit sharedEngineKit] presentViewController:vc];
  1292. }
  1293. } else if([model.message.content isKindOfClass:[WFCCCardMessageContent class]]) {
  1294. WFCCCardMessageContent *card = (WFCCCardMessageContent *)model.message.content;
  1295. if (card.type == CardType_User) {
  1296. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:card.targetId refresh:NO];
  1297. if (!userInfo.deleted) {
  1298. WFCUProfileTableViewController *vc = [[WFCUProfileTableViewController alloc] init];
  1299. vc.userId = card.targetId;
  1300. vc.hidesBottomBarWhenPushed = YES;
  1301. [self.navigationController pushViewController:vc animated:YES];
  1302. }
  1303. } else if(card.type == CardType_Group) {
  1304. WFCUGroupInfoViewController *vc2 = [[WFCUGroupInfoViewController alloc] init];
  1305. vc2.groupId = card.targetId;
  1306. vc2.hidesBottomBarWhenPushed = YES;
  1307. [self.navigationController pushViewController:vc2 animated:YES];
  1308. } else if(card.type == CardType_Channel) {
  1309. WFCUChannelProfileViewController *pvc = [[WFCUChannelProfileViewController alloc] init];
  1310. pvc.channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:card.targetId refresh:NO];
  1311. if (pvc.channelInfo) {
  1312. pvc.hidesBottomBarWhenPushed = YES;
  1313. [self.navigationController pushViewController:pvc animated:YES];
  1314. }
  1315. }
  1316. } else if([model.message.content isKindOfClass:[WFCCCompositeMessageContent class]]) {
  1317. WFCUCompositeMessageViewController *vc = [[WFCUCompositeMessageViewController alloc] init];
  1318. vc.compositeContent = (WFCCCompositeMessageContent *)model.message.content;
  1319. [self.navigationController pushViewController:vc animated:YES];
  1320. }
  1321. }
  1322. - (void)didDoubleTapMessageCell:(WFCUMessageCellBase *)cell withModel:(WFCUMessageModel *)model {
  1323. if ([model.message.content isKindOfClass:[WFCCTextMessageContent class]]) {
  1324. WFCCTextMessageContent *txtMsgContent = (WFCCTextMessageContent *)model.message.content;
  1325. [self.chatInputBar resetInputBarStatue];
  1326. UIView *textContainer = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
  1327. textContainer.backgroundColor = self.view.backgroundColor;
  1328. UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, kStatusBarAndNavigationBarHeight, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - kStatusBarAndNavigationBarHeight - kTabbarSafeBottomMargin)];
  1329. textView.text = txtMsgContent.text;
  1330. textView.textAlignment = NSTextAlignmentCenter;
  1331. textView.font = [UIFont systemFontOfSize:28];
  1332. textView.editable = NO;
  1333. textView.backgroundColor = self.view.backgroundColor;
  1334. [textContainer addSubview:textView];
  1335. [textView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapTextMessageDetailView:)]];
  1336. [[UIApplication sharedApplication].keyWindow addSubview:textContainer];
  1337. }
  1338. }
  1339. - (void)didTapTextMessageDetailView:(id)sender {
  1340. if ([sender isKindOfClass:[UIGestureRecognizer class]]) {
  1341. UIGestureRecognizer *gesture = (UIGestureRecognizer *)sender;
  1342. [gesture.view.superview removeFromSuperview];
  1343. }
  1344. NSLog(@"close windows");
  1345. }
  1346. - (void)didTapMessagePortrait:(WFCUMessageCellBase *)cell withModel:(WFCUMessageModel *)model {
  1347. if(self.conversation.type == Group_Type) {
  1348. if (self.targetGroup.privateChat) {
  1349. if (![self.targetGroup.owner isEqualToString:model.message.fromUser] && ![self.targetGroup.owner isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  1350. WFCCGroupMember *gm = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
  1351. if (gm.type != Member_Type_Manager) {
  1352. WFCCGroupMember *gm = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:model.message.fromUser];
  1353. if (gm.type != Member_Type_Manager) {
  1354. [self.view makeToast:WFCString(@"NotAllowTemporarySession") duration:1 position:CSToastPositionCenter];
  1355. return;
  1356. }
  1357. }
  1358. }
  1359. }
  1360. }
  1361. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:model.message.fromUser refresh:NO];
  1362. if (!userInfo.deleted) {
  1363. WFCUProfileTableViewController *vc = [[WFCUProfileTableViewController alloc] init];
  1364. vc.userId = model.message.fromUser;
  1365. vc.fromConversation = self.conversation;
  1366. vc.hidesBottomBarWhenPushed = YES;
  1367. [self.navigationController pushViewController:vc animated:YES];
  1368. }
  1369. }
  1370. - (void)didLongPressMessageCell:(WFCUMessageCellBase *)cell withModel:(WFCUMessageModel *)model {
  1371. if ([cell isKindOfClass:[WFCUMessageCellBase class]]) {
  1372. // if (!self.isFirstResponder) {
  1373. // [self becomeFirstResponder];
  1374. // }
  1375. [self displayMenu:(WFCUMessageCellBase *)cell];
  1376. }
  1377. }
  1378. - (void)didLongPressMessagePortrait:(WFCUMessageCellBase *)cell withModel:(WFCUMessageModel *)model {
  1379. if (self.conversation.type == Group_Type) {
  1380. if (model.message.direction == MessageDirection_Receive) {
  1381. WFCCUserInfo *sender = [[WFCCIMService sharedWFCIMService] getUserInfo:model.message.fromUser refresh:NO];
  1382. [self.chatInputBar appendMention:model.message.fromUser name:sender.displayName];
  1383. }
  1384. } else if(self.conversation.type == Channel_Type) {
  1385. WFCCChannelInfo *channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:self.conversation.target refresh:NO];
  1386. if ([channelInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  1387. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  1388. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:nil];
  1389. UIAlertAction *okAction = [UIAlertAction actionWithTitle:WFCString(@"ChatWithSubscriber") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1390. if (model.message.direction == MessageDirection_Receive) {
  1391. WFCCChannelInfo *channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:self.conversation.target refresh:NO];
  1392. if ([channelInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  1393. WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
  1394. mvc.conversation = [WFCCConversation conversationWithType:self.conversation.type target:self.conversation.target line:self.conversation.line];
  1395. mvc.privateChatUser = model.message.fromUser;
  1396. [self.navigationController pushViewController:mvc animated:YES];
  1397. }
  1398. }
  1399. }];
  1400. [alertController addAction:cancelAction];
  1401. [alertController addAction:okAction];
  1402. [self presentViewController:alertController animated:YES completion:nil];
  1403. }
  1404. }
  1405. }
  1406. - (void)didTapResendBtn:(WFCUMessageModel *)model {
  1407. NSInteger index = [self.modelList indexOfObject:model];
  1408. if (index >= 0) {
  1409. NSIndexPath *path = [NSIndexPath indexPathForRow:index inSection:0];
  1410. [self.modelList removeObjectAtIndex:index];
  1411. [self.collectionView deleteItemsAtIndexPaths:@[path]];
  1412. [[WFCCIMService sharedWFCIMService] deleteMessage:model.message.messageId];
  1413. [self sendMessage:model.message.content];
  1414. }
  1415. }
  1416. - (void)didSelectUrl:(WFCUMessageCellBase *)cell withModel:(WFCUMessageModel *)model withUrl:(NSString *)urlString {
  1417. WFCUBrowserViewController *bvc = [[WFCUBrowserViewController alloc] init];
  1418. bvc.url = urlString;
  1419. [self.navigationController pushViewController:bvc animated:YES];
  1420. }
  1421. - (void)didSelectPhoneNumber:(WFCUMessageCellBase *)cell withModel:(WFCUMessageModel *)model withPhoneNumber:(NSString *)phoneNumber {
  1422. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:WFCString(@"PhoneNumberHint"), phoneNumber] message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  1423. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:nil];
  1424. UIAlertAction *callAction = [UIAlertAction actionWithTitle:WFCString(@"Call") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1425. NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"telprompt:%@", phoneNumber]];
  1426. [[UIApplication sharedApplication] openURL:url];
  1427. }];
  1428. UIAlertAction *copyAction = [UIAlertAction actionWithTitle:WFCString(@"CopyNumber") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1429. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1430. pasteboard.string = phoneNumber;
  1431. }];
  1432. [alertController addAction:cancelAction];
  1433. [alertController addAction:callAction];
  1434. [alertController addAction:copyAction];
  1435. // [alertController addAction:addContactAction];
  1436. [self presentViewController:alertController animated:YES completion:nil];
  1437. }
  1438. - (void)reeditRecalledMessage:(WFCUMessageCellBase *)cell withModel:(WFCUMessageModel *)model {
  1439. WFCCRecallMessageContent *recall = (WFCCRecallMessageContent *)model.message.content;
  1440. [self.chatInputBar appendText:recall.originalSearchableContent];
  1441. }
  1442. - (void)didTapReceiptView:(WFCUMessageCellBase *)cell withModel:(WFCUMessageModel *)model {
  1443. WFCUReceiptViewController *receipt = [[WFCUReceiptViewController alloc] init];
  1444. receipt.message = model.message;
  1445. [self.navigationController pushViewController:receipt animated:YES];
  1446. }
  1447. - (void)didTapQuoteLabel:(WFCUMessageCellBase *)cell withModel:(WFCUMessageModel *)model {
  1448. if ([model.message.content isKindOfClass:[WFCCTextMessageContent class]]) {
  1449. WFCCTextMessageContent *txtContent = (WFCCTextMessageContent *)model.message.content;
  1450. if (txtContent.quoteInfo) {
  1451. WFCCMessage *msg = [[WFCCIMService sharedWFCIMService] getMessageByUid:txtContent.quoteInfo.messageUid];
  1452. if (!msg || [msg.content isKindOfClass:[WFCCRecallMessageContent class]]) {
  1453. [self.view makeToast:@"消息不存在了!"];
  1454. NSLog(@"msg not exist");
  1455. return;
  1456. }
  1457. if ([msg.content isKindOfClass:[WFCCTextMessageContent class]]) {
  1458. WFCCTextMessageContent *txtContent = (WFCCTextMessageContent *)msg.content;
  1459. [self.chatInputBar resetInputBarStatue];
  1460. UIView *textContainer = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
  1461. textContainer.backgroundColor = self.view.backgroundColor;
  1462. UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, kStatusBarAndNavigationBarHeight, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - kStatusBarAndNavigationBarHeight - kTabbarSafeBottomMargin)];
  1463. textView.text = txtContent.text;
  1464. textView.textAlignment = NSTextAlignmentCenter;
  1465. textView.font = [UIFont systemFontOfSize:28];
  1466. textView.editable = NO;
  1467. textView.backgroundColor = self.view.backgroundColor;
  1468. [textContainer addSubview:textView];
  1469. [textView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapTextMessageDetailView:)]];
  1470. [[UIApplication sharedApplication].keyWindow addSubview:textContainer];
  1471. } else if ([msg.content isKindOfClass:[WFCCImageMessageContent class]]) {
  1472. self.imageMsgs = @[msg];
  1473. SDPhotoBrowser *browser = [[SDPhotoBrowser alloc] init];
  1474. browser.sourceImagesContainerView = self.backgroundView;
  1475. browser.showAll = NO;
  1476. browser.imageCount = self.imageMsgs.count;
  1477. [self onResetKeyboard:nil];
  1478. browser.currentImageIndex = 0;
  1479. browser.delegate = self;
  1480. [browser show]; // 展示图片浏览器
  1481. } else if ([msg.content isKindOfClass:[WFCCLocationMessageContent class]]) {
  1482. WFCCLocationMessageContent *locContent = (WFCCLocationMessageContent *)msg.content;
  1483. WFCULocationViewController *vc = [[WFCULocationViewController alloc] initWithLocationPoint:[[WFCULocationPoint alloc] initWithCoordinate:locContent.coordinate andTitle:locContent.title]];
  1484. [self.navigationController pushViewController:vc animated:YES];
  1485. } else if ([msg.content isKindOfClass:[WFCCFileMessageContent class]]) {
  1486. WFCCFileMessageContent *fileContent = (WFCCFileMessageContent *)msg.content;
  1487. __weak typeof(self)ws = self;
  1488. [[WFCCIMService sharedWFCIMService] getAuthorizedMediaUrl:msg.messageUid mediaType:Media_Type_FILE mediaPath:fileContent.remoteUrl success:^(NSString *authorizedUrl) {
  1489. WFCUBrowserViewController *bvc = [[WFCUBrowserViewController alloc] init];
  1490. bvc.url = authorizedUrl;
  1491. [ws.navigationController pushViewController:bvc animated:YES];
  1492. } error:^(int error_code) {
  1493. WFCUBrowserViewController *bvc = [[WFCUBrowserViewController alloc] init];
  1494. bvc.url = fileContent.remoteUrl;
  1495. [ws.navigationController pushViewController:bvc animated:YES];
  1496. }];
  1497. } else if ([msg.content isKindOfClass:[WFCCCardMessageContent class]]) {
  1498. WFCCCardMessageContent *card = (WFCCCardMessageContent *)msg.content;
  1499. if (card.type == CardType_User) {
  1500. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:card.targetId refresh:NO];
  1501. if (!userInfo.deleted) {
  1502. WFCUProfileTableViewController *vc = [[WFCUProfileTableViewController alloc] init];
  1503. vc.userId = card.targetId;
  1504. vc.hidesBottomBarWhenPushed = YES;
  1505. [self.navigationController pushViewController:vc animated:YES];
  1506. }
  1507. } else if(card.type == CardType_Group) {
  1508. WFCUGroupInfoViewController *vc2 = [[WFCUGroupInfoViewController alloc] init];
  1509. vc2.groupId = card.targetId;
  1510. vc2.hidesBottomBarWhenPushed = YES;
  1511. [self.navigationController pushViewController:vc2 animated:YES];
  1512. } else if(card.type == CardType_Channel) {
  1513. WFCUChannelProfileViewController *pvc = [[WFCUChannelProfileViewController alloc] init];
  1514. pvc.channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:card.targetId refresh:NO];
  1515. if (pvc.channelInfo) {
  1516. pvc.hidesBottomBarWhenPushed = YES;
  1517. [self.navigationController pushViewController:pvc animated:YES];
  1518. }
  1519. }
  1520. } else {
  1521. //有些消息内容不能在当前页面显示,跳转到新的页面显示
  1522. // if ([msg.content isKindOfClass:[WFCCSoundMessageContent class]])
  1523. // if ([msg.content isKindOfClass:[WFCCStickerMessageContent class]])
  1524. // if ([msg.content isKindOfClass:[WFCCVideoMessageContent class]])
  1525. WFCUQuoteViewController *vc = [[WFCUQuoteViewController alloc] init];
  1526. vc.messageUid = msg.messageUid;
  1527. [self.navigationController pushViewController:vc animated:YES];
  1528. }
  1529. }
  1530. }
  1531. }
  1532. #pragma mark - AVAudioPlayerDelegate
  1533. - (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
  1534. NSLog(@"player finished");
  1535. [self stopPlayer];
  1536. }
  1537. - (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error {
  1538. NSLog(@"player decode error");
  1539. [[[UIAlertView alloc] initWithTitle:WFCString(@"Warning") message:WFCString(@"NetworkError") delegate:nil cancelButtonTitle:WFCString(@"Ok") otherButtonTitles:nil, nil] show];
  1540. [self stopPlayer];
  1541. }
  1542. #pragma mark - UIScrollViewDelegate
  1543. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  1544. }
  1545. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  1546. [self.chatInputBar resetInputBarStatue];
  1547. }
  1548. - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
  1549. if (self.hasNewMessage && ceil(targetContentOffset->y)+1 >= ceil(scrollView.contentSize.height - scrollView.bounds.size.height)) {
  1550. [self loadMoreMessage:NO];
  1551. }
  1552. if (targetContentOffset->y == 0 && self.hasMoreOld) {
  1553. [self loadMoreMessage:YES];
  1554. }
  1555. }
  1556. - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
  1557. }
  1558. #pragma mark - ChatInputBarDelegate
  1559. - (void)imageDidCapture:(UIImage *)capturedImage {
  1560. if (!capturedImage) {
  1561. return;
  1562. }
  1563. WFCCImageMessageContent *imgContent = [WFCCImageMessageContent contentFrom:capturedImage];
  1564. [self sendMessage:imgContent];
  1565. }
  1566. -(void)gifDidCapture:(NSData *)gifData {
  1567. //save gif
  1568. UInt64 recordTime = [[NSDate date] timeIntervalSince1970]*1000;
  1569. NSString *filePath = [[WFCCUtilities getDocumentPathWithComponent:@"/IMG"] stringByAppendingPathComponent:[NSString stringWithFormat:@"gif%lld.jpg", recordTime]];
  1570. [gifData writeToFile:filePath atomically:YES];
  1571. WFCCStickerMessageContent *stickerContent = [WFCCStickerMessageContent contentFrom:filePath];
  1572. [self sendMessage:stickerContent];
  1573. }
  1574. - (void)videoDidCapture:(NSString *)videoPath thumbnail:(UIImage *)image duration:(long)duration {
  1575. WFCCVideoMessageContent *videoContent = [WFCCVideoMessageContent contentPath:videoPath thumbnail:image];
  1576. [self sendMessage:videoContent];
  1577. }
  1578. - (void)imageDataDidSelect:(NSArray<UIImage *> *)selectedImages isFullImage:(BOOL)fullImage {
  1579. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  1580. for (UIImage *image in selectedImages) {
  1581. WFCCImageMessageContent *imgContent = [WFCCImageMessageContent contentFrom:image];
  1582. dispatch_sync(dispatch_get_main_queue(), ^{
  1583. [self sendMessage:imgContent];
  1584. });
  1585. [NSThread sleepForTimeInterval:0.2];
  1586. }
  1587. });
  1588. }
  1589. - (void)didTouchSend:(NSString *)stringContent withMentionInfos:(NSMutableArray<WFCUMetionInfo *> *)mentionInfos withQuoteInfo:(WFCCQuoteInfo *)quoteInfo {
  1590. if (stringContent.length == 0) {
  1591. return;
  1592. }
  1593. WFCCTextMessageContent *txtContent = [[WFCCTextMessageContent alloc] init];
  1594. txtContent.text = stringContent;
  1595. NSMutableArray *mentionTargets = [[NSMutableArray alloc] init];
  1596. for (WFCUMetionInfo *mentionInfo in mentionInfos) {
  1597. if (mentionInfo.mentionType == 2) {
  1598. txtContent.mentionedType = 2;
  1599. mentionTargets = nil;
  1600. break;
  1601. } else if(mentionInfo.mentionType == 1) {
  1602. txtContent.mentionedType = 1;
  1603. [mentionTargets addObject:mentionInfo.target];
  1604. }
  1605. }
  1606. if (txtContent.mentionedType == 1) {
  1607. txtContent.mentionedTargets = [mentionTargets copy];
  1608. }
  1609. txtContent.quoteInfo = quoteInfo;
  1610. [self sendMessage:txtContent];
  1611. }
  1612. - (void)recordDidEnd:(NSString *)dataUri duration:(long)duration error:(NSError *)error {
  1613. [self sendMessage:[WFCCSoundMessageContent soundMessageContentForWav:dataUri duration:duration]];
  1614. }
  1615. - (void)willChangeFrame:(CGRect)newFrame withDuration:(CGFloat)duration keyboardShowing:(BOOL)keyboardShowing {
  1616. if (!self.isShowingKeyboard) {
  1617. self.isShowingKeyboard = YES;
  1618. [UIView animateWithDuration:duration animations:^{
  1619. CGRect frame = self.collectionView.frame;
  1620. CGFloat diff = MIN(frame.size.height, self.collectionView.contentSize.height) - newFrame.origin.y;
  1621. if(diff > 0) {
  1622. frame.origin.y = -diff;
  1623. self.collectionView.frame = frame;
  1624. } else {
  1625. self.collectionView.frame = CGRectMake(0, 0, self.backgroundView.bounds.size.width, newFrame.origin.y);
  1626. }
  1627. } completion:^(BOOL finished) {
  1628. self.collectionView.frame = CGRectMake(0, 0, self.backgroundView.bounds.size.width, newFrame.origin.y);
  1629. if (keyboardShowing) {
  1630. [self scrollToBottom:NO];
  1631. }
  1632. self.isShowingKeyboard = NO;
  1633. }];
  1634. } else {
  1635. if (self.collectionView.frame.size.height != newFrame.origin.y) {
  1636. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  1637. self.collectionView.frame = CGRectMake(0, 0, self.backgroundView.bounds.size.width, newFrame.origin.y);
  1638. [self scrollToBottom:YES];
  1639. });
  1640. }
  1641. }
  1642. }
  1643. - (UINavigationController *)requireNavi {
  1644. return self.navigationController;
  1645. }
  1646. - (void)locationDidSelect:(CLLocationCoordinate2D)location locationName:(NSString *)locationName mapScreenShot:(UIImage *)mapScreenShot {
  1647. WFCCLocationMessageContent *content = [WFCCLocationMessageContent contentWith:location title:locationName thumbnail:mapScreenShot];
  1648. [self sendMessage:content];
  1649. }
  1650. - (void)didSelectFiles:(NSArray *)files {
  1651. for (NSString *file in files) {
  1652. WFCCFileMessageContent *content = [WFCCFileMessageContent fileMessageContentFromPath:file];
  1653. [self sendMessage:content];
  1654. [NSThread sleepForTimeInterval:0.05];
  1655. }
  1656. }
  1657. - (void)saveStickerRemoteUrl:(WFCCStickerMessageContent *)stickerContent {
  1658. if (stickerContent.localPath.length && stickerContent.remoteUrl.length) {
  1659. [[NSUserDefaults standardUserDefaults] setObject:stickerContent.remoteUrl forKey:[NSString stringWithFormat:@"sticker_remote_for_%ld", stickerContent.localPath.hash]];
  1660. [[NSUserDefaults standardUserDefaults] synchronize];
  1661. }
  1662. }
  1663. - (void)didSelectSticker:(NSString *)stickerPath {
  1664. WFCCStickerMessageContent * content = [WFCCStickerMessageContent contentFrom:stickerPath];
  1665. NSString *remoteUrl = [[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"sticker_remote_for_%ld", stickerPath.hash]];
  1666. content.remoteUrl = remoteUrl;
  1667. [self sendMessage:content];
  1668. }
  1669. #if WFCU_SUPPORT_VOIP
  1670. - (void)didTouchVideoBtn:(BOOL)isAudioOnly {
  1671. if(self.conversation.type == Single_Type) {
  1672. WFCUVideoViewController *videoVC = [[WFCUVideoViewController alloc] initWithTargets:@[self.conversation.target] conversation:self.conversation audioOnly:isAudioOnly];
  1673. [[WFAVEngineKit sharedEngineKit] presentViewController:videoVC];
  1674. } else {
  1675. // WFCUContactListViewController *pvc = [[WFCUContactListViewController alloc] init];
  1676. // pvc.selectContact = YES;
  1677. // pvc.multiSelect = [WFAVEngineKit sharedEngineKit].supportMultiCall;
  1678. // if (pvc.multiSelect) {
  1679. // pvc.maxSelectCount = isAudioOnly ? [WFAVEngineKit sharedEngineKit].maxAudioCallCount : [WFAVEngineKit sharedEngineKit].maxVideoCallCount;
  1680. // pvc.maxSelectCount -= 1;
  1681. // }
  1682. WFCUSeletedUserViewController *vc = [[WFCUSeletedUserViewController alloc] init];
  1683. NSMutableArray *disabledUser = [[NSMutableArray alloc] init];
  1684. [disabledUser addObject:[WFCCNetworkService sharedInstance].userId];
  1685. vc.disableUserIds = disabledUser;
  1686. vc.maxSelectCount = isAudioOnly ? [WFAVEngineKit sharedEngineKit].maxAudioCallCount : [WFAVEngineKit sharedEngineKit].maxVideoCallCount;
  1687. vc.groupId = self.targetGroup.target;
  1688. // vc.maxSelectCount -= 1;
  1689. NSMutableArray *candidateUser = [[NSMutableArray alloc] init];
  1690. NSArray<WFCCGroupMember *> *members = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.conversation.target forceUpdate:NO];
  1691. for (WFCCGroupMember *member in members) {
  1692. [candidateUser addObject:member.memberId];
  1693. }
  1694. vc.candidateUsers = candidateUser;
  1695. vc.type = Vertical;
  1696. __weak typeof(self)ws = self;
  1697. vc.selectResult = ^(NSArray<NSString *> * _Nonnull contacts) {
  1698. UIViewController *videoVC;
  1699. if (ws.conversation.type == Group_Type && [WFAVEngineKit sharedEngineKit].supportMultiCall) {
  1700. videoVC = [[WFCUMultiVideoViewController alloc] initWithTargets:contacts conversation:ws.conversation audioOnly:isAudioOnly];
  1701. } else {
  1702. videoVC = [[WFCUVideoViewController alloc] initWithTargets:contacts conversation:ws.conversation audioOnly:isAudioOnly];
  1703. }
  1704. [[WFAVEngineKit sharedEngineKit] presentViewController:videoVC];
  1705. };
  1706. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:vc];
  1707. navi.modalPresentationStyle = UIModalPresentationFullScreen;
  1708. [self.navigationController presentViewController:navi animated:YES completion:nil];
  1709. }
  1710. }
  1711. #endif
  1712. - (void)onTyping:(WFCCTypingType)type {
  1713. if (self.conversation.type == Single_Type) {
  1714. [self sendMessage:[WFCCTypingMessageContent contentType:type]];
  1715. }
  1716. }
  1717. #pragma mark - SDPhotoBrowserDelegate
  1718. - (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index {
  1719. WFCCMessage *msg = [self.imageMsgs objectAtIndex:index];
  1720. if ([[msg.content class] getContentType] == MESSAGE_CONTENT_TYPE_IMAGE) {
  1721. WFCCImageMessageContent *imgContent = (WFCCImageMessageContent *)msg.content;
  1722. return imgContent.thumbnail;
  1723. }
  1724. return nil;
  1725. }
  1726. - (NSURL *)photoBrowser:(SDPhotoBrowser *)browser highQualityImageURLForIndex:(NSInteger)index {
  1727. WFCCMessage *msg = [self.imageMsgs objectAtIndex:index];
  1728. if ([[msg.content class] getContentType] == MESSAGE_CONTENT_TYPE_IMAGE) {
  1729. WFCCImageMessageContent *imgContent = (WFCCImageMessageContent *)msg.content;
  1730. return [NSURL URLWithString:[imgContent.remoteUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  1731. }
  1732. return nil;
  1733. }
  1734. - (void)photoBrowserDidDismiss:(SDPhotoBrowser *)browser {
  1735. self.imageMsgs = nil;
  1736. }
  1737. - (void)photoBrowserShowAllView {
  1738. WFCUMediaMessageGridViewController *vc = [[WFCUMediaMessageGridViewController alloc] init];
  1739. vc.conversation = self.conversation;
  1740. [self.navigationController pushViewController:vc animated:YES];
  1741. }
  1742. #pragma mark - UIGestureRecognizerDelegate
  1743. - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
  1744. return self.navigationController.childViewControllers.count > 1;
  1745. }
  1746. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  1747. return self.navigationController.viewControllers.count > 1;
  1748. }
  1749. #pragma mark - menu
  1750. - (void)displayMenu:(WFCUMessageCellBase *)baseCell {
  1751. UIMenuController *menu = [UIMenuController sharedMenuController];
  1752. UIMenuItem *deleteItem = [[UIMenuItem alloc]initWithTitle:WFCString(@"Delete") action:@selector(performDelete:)];
  1753. UIMenuItem *copyItem = [[UIMenuItem alloc]initWithTitle:WFCString(@"Copy") action:@selector(performCopy:)];
  1754. UIMenuItem *forwardItem = [[UIMenuItem alloc]initWithTitle:WFCString(@"Forward") action:@selector(performForward:)];
  1755. UIMenuItem *recallItem = [[UIMenuItem alloc]initWithTitle:WFCString(@"Recall") action:@selector(performRecall:)];
  1756. UIMenuItem *complainItem = [[UIMenuItem alloc]initWithTitle:WFCString(@"Complain") action:@selector(performComplain:)];
  1757. UIMenuItem *multiSelectItem = [[UIMenuItem alloc]initWithTitle:WFCString(@"MultiSelect") action:@selector(performMultiSelect:)];
  1758. UIMenuItem *quote = [[UIMenuItem alloc]initWithTitle:WFCString(@"Quote") action:@selector(performQuote:)];
  1759. CGRect menuPos;
  1760. if ([baseCell isKindOfClass:[WFCUMessageCell class]]) {
  1761. WFCUMessageCell *msgCell = (WFCUMessageCell *)baseCell;
  1762. menuPos = msgCell.bubbleView.frame;
  1763. } else {
  1764. menuPos = baseCell.frame;
  1765. }
  1766. [menu setTargetRect:menuPos inView:baseCell];
  1767. WFCCMessage *msg = baseCell.model.message;
  1768. NSMutableArray *items = [[NSMutableArray alloc] init];
  1769. [items addObject:deleteItem];
  1770. if ([msg.content isKindOfClass:[WFCCTextMessageContent class]]) {
  1771. [items addObject:copyItem];
  1772. }
  1773. if (baseCell.model.message.direction == MessageDirection_Receive) {
  1774. [items addObject:complainItem];
  1775. }
  1776. if ([msg.content isKindOfClass:[WFCCImageMessageContent class]] ||
  1777. [msg.content isKindOfClass:[WFCCTextMessageContent class]] ||
  1778. [msg.content isKindOfClass:[WFCCLocationMessageContent class]] ||
  1779. [msg.content isKindOfClass:[WFCCFileMessageContent class]] ||
  1780. [msg.content isKindOfClass:[WFCCVideoMessageContent class]] ||
  1781. [msg.content isKindOfClass:[WFCUConferenceInviteCell class]] ||
  1782. [msg.content isKindOfClass:[WFCUCardCell class]] ||
  1783. // [msg.content isKindOfClass:[WFCCSoundMessageContent class]] || //语音消息禁止转发,出于安全原因考虑,微信就禁止转发。如果您能确保安全,可以把这行注释打开
  1784. [msg.content isKindOfClass:[WFCCStickerMessageContent class]]) {
  1785. [items addObject:forwardItem];
  1786. }
  1787. BOOL canRecall = NO;
  1788. if ([baseCell isKindOfClass:[WFCUMessageCell class]] &&
  1789. msg.direction == MessageDirection_Send
  1790. ) {
  1791. NSDate *cur = [NSDate date];
  1792. if ([cur timeIntervalSince1970]*1000 - msg.serverTime < 60 * 1000) {
  1793. canRecall = YES;
  1794. }
  1795. }
  1796. if (!canRecall && self.conversation.type == Group_Type) {
  1797. WFCCGroupInfo *groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:self.conversation.target refresh:NO];
  1798. if([groupInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  1799. canRecall = YES;
  1800. if ([groupInfo.owner isEqualToString:msg.fromUser]) {
  1801. canRecall = NO;
  1802. }
  1803. } else {
  1804. __block BOOL isManager = false;
  1805. NSArray *memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.conversation.target forceUpdate:NO];
  1806. [memberList enumerateObjectsUsingBlock:^(WFCCGroupMember * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  1807. if ([obj.memberId isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  1808. if ((obj.type == Member_Type_Manager || obj.type == Member_Type_Owner) && ![msg.fromUser isEqualToString:obj.memberId]) {
  1809. isManager = YES;
  1810. }
  1811. *stop = YES;
  1812. }
  1813. }];
  1814. if(isManager && ![msg.fromUser isEqualToString:groupInfo.owner]) {
  1815. canRecall = YES;
  1816. }
  1817. }
  1818. }
  1819. if (canRecall) {
  1820. [items addObject:recallItem];
  1821. }
  1822. if ([baseCell isKindOfClass:[WFCUMessageCell class]]) {
  1823. [items addObject:multiSelectItem];
  1824. }
  1825. if (msg.messageUid > 0) {
  1826. if ([msg.content.class getContentFlags] & 0x2) {
  1827. [items addObject:quote];
  1828. }
  1829. }
  1830. [menu setMenuItems:items];
  1831. self.cell4Menu = baseCell;
  1832. [menu setMenuVisible:YES];
  1833. }
  1834. -(BOOL)canBecomeFirstResponder {
  1835. return YES;
  1836. }
  1837. -(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
  1838. if(self.cell4Menu) {
  1839. if (action == @selector(performDelete:) || action == @selector(performCopy:) || action == @selector(performForward:) || action == @selector(performRecall:) || action == @selector(performComplain:) || action == @selector(performMultiSelect:) || action == @selector(performQuote:)) {
  1840. return YES; //显示自定义的菜单项
  1841. } else {
  1842. return NO;
  1843. }
  1844. }
  1845. if (action == @selector(paste:)) {
  1846. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1847. return pasteboard.string != nil;
  1848. }
  1849. return NO;//[super canPerformAction:action withSender:sender];
  1850. }
  1851. - (void)paste:(id)sender {
  1852. [self.chatInputBar paste:sender];
  1853. }
  1854. - (void)deleteMessageUI:(WFCCMessage *)message {
  1855. for (int i = 0; i < self.modelList.count; i++) {
  1856. WFCUMessageModel *model = [self.modelList objectAtIndex:i];
  1857. if (model.message.messageUid == message.messageUid) {
  1858. [self.modelList removeObject:model];
  1859. [self.collectionView deleteItemsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]]];
  1860. break;
  1861. }
  1862. }
  1863. }
  1864. -(void)performDelete:(UIMenuController *)sender {
  1865. __weak typeof(self)ws = self;
  1866. WFCCMessage *message = self.cell4Menu.model.message;
  1867. [[WFCCIMService sharedWFCIMService] deleteMessage:message.messageId];
  1868. [ws deleteMessageUI:message];
  1869. }
  1870. -(void)performCopy:(UIMenuItem *)sender {
  1871. if (self.cell4Menu) {
  1872. if ([self.cell4Menu.model.message.content isKindOfClass:[WFCCTextMessageContent class]]) {
  1873. UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
  1874. pasteboard.string = ((WFCCTextMessageContent *)self.cell4Menu.model.message.content).text;
  1875. }
  1876. }
  1877. }
  1878. -(void)performForward:(UIMenuItem *)sender {
  1879. if (self.cell4Menu) {
  1880. WFCUForwardViewController *controller = [[WFCUForwardViewController alloc] init];
  1881. controller.message = self.cell4Menu.model.message;
  1882. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:controller];
  1883. [self.navigationController presentViewController:navi animated:YES completion:nil];
  1884. }
  1885. }
  1886. -(void)performRecall:(UIMenuItem *)sender {
  1887. if (self.cell4Menu.model.message) {
  1888. __block MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  1889. hud.label.text = WFCString(@"Recalling");
  1890. [hud showAnimated:YES];
  1891. __weak typeof(self) ws = self;
  1892. long messageId = self.cell4Menu.model.message.messageId;
  1893. WFCUMessageCellBase *cell = self.cell4Menu;
  1894. [[WFCCIMService sharedWFCIMService] recall:self.cell4Menu.model.message success:^{
  1895. dispatch_async(dispatch_get_main_queue(), ^{
  1896. [hud hideAnimated:YES];
  1897. if (cell.model.message.messageId == messageId) {
  1898. cell.model.message = [[WFCCIMService sharedWFCIMService] getMessage:messageId];
  1899. [ws.collectionView reloadItemsAtIndexPaths:@[[ws.collectionView indexPathForCell:cell]]];
  1900. }
  1901. });
  1902. } error:^(int error_code) {
  1903. dispatch_async(dispatch_get_main_queue(), ^{
  1904. hud.mode = MBProgressHUDModeText;
  1905. hud.label.text = WFCString(@"RecallFailure");
  1906. [hud hideAnimated:YES afterDelay:1.f];
  1907. });
  1908. }];
  1909. }
  1910. }
  1911. - (void)performComplain:(UIMenuItem *)sender {
  1912. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:WFCString(@"Complain") message:@"如果您发现有违反法律和道德的内容,或者您的合法权益受到侵犯,请截图之后发送给我们。我们会在24小时之内处理。处理办法包括不限于删除内容,对作者进行警告,冻结账号,甚至报警处理。举报请到\"设置->设置->举报\"联系我们!" preferredStyle:UIAlertControllerStyleAlert];
  1913. UIAlertAction *action = [UIAlertAction actionWithTitle:WFCString(WFCString(@"Ok")) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  1914. }];
  1915. [alertController addAction:action];
  1916. [self presentViewController:alertController animated:YES completion:nil];
  1917. }
  1918. - (void)performMultiSelect:(UIMenuItem *)sender {
  1919. self.multiSelecting = !self.multiSelecting;
  1920. }
  1921. - (void)performQuote:(UIMenuItem *)sender {
  1922. if (self.cell4Menu.model.message) {
  1923. [self.chatInputBar appendQuote:self.cell4Menu.model.message.messageUid];
  1924. }
  1925. }
  1926. - (void)onMenuHidden:(id)sender {
  1927. UIMenuController *menu = [UIMenuController sharedMenuController];
  1928. [menu setMenuItems:nil];
  1929. __weak typeof(self)ws = self;
  1930. dispatch_async(dispatch_get_main_queue(), ^{
  1931. ws.cell4Menu = nil;
  1932. });
  1933. }
  1934. - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
  1935. [super traitCollectionDidChange:previousTraitCollection];
  1936. if (@available(iOS 13.0, *)) {
  1937. if ([self.traitCollection hasDifferentColorAppearanceComparedToTraitCollection:previousTraitCollection]) {
  1938. [self.navigationController popViewControllerAnimated:NO];
  1939. }
  1940. }
  1941. }
  1942. - (void)dealloc {
  1943. [[NSNotificationCenter defaultCenter] removeObserver:self];
  1944. }
  1945. @end