FriendViewController.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. //
  2. // FriendTableViewController.m
  3. // NIMDemo
  4. //
  5. // Created by Fenix Wang on 2017/6/7.
  6. // Copyright © 2017年 Netease. All rights reserved.
  7. //
  8. #import "FriendViewController.h"
  9. #import "NTESSessionViewController.h"
  10. #import "NTESSessionPeekViewController.h"
  11. #import "UIView+NTES.h"
  12. #import "NTESBundleSetting.h"
  13. #import "NTESListHeader.h"
  14. #import "NTESClientsTableViewController.h"
  15. #import "NTESSnapchatAttachment.h"
  16. #import "NTESJanKenPonAttachment.h"
  17. #import "NTESChartletAttachment.h"
  18. #import "NTESWhiteboardAttachment.h"
  19. #import "NTESGiftAttachment.h"
  20. #import "NTESSessionUtil.h"
  21. #import "NTESPersonalCardViewController.h"
  22. #import "NTESContactViewController.h"
  23. #import "NTESContactAddFriendViewController.h"
  24. #import "User.h"
  25. #import "FriendListViewController.h"
  26. #import "NIMSessionListCell.h"
  27. #import "NIMAvatarImageView.h"
  28. #import "NTESShareAttachment.h"
  29. #import "HttpRequest.h"
  30. #import "NTESBadgeView.h"
  31. #define SessionListTitle @"谁说"
  32. @interface FriendViewController ()<NIMLoginManagerDelegate,NTESListHeaderDelegate,NIMEventSubscribeManagerDelegate,UIViewControllerPreviewingDelegate,UISearchBarDelegate>
  33. @property (nonatomic,strong) UILabel *titleLabel;
  34. @property (nonatomic,strong) NTESListHeader *header;
  35. @property (nonatomic,assign) BOOL supportsForceTouch;
  36. @property (nonatomic,strong) NSMutableDictionary *previews;
  37. @property (nonatomic, strong) NSMutableArray *searchArr;
  38. @property (nonatomic, strong) UISearchController *searchController;
  39. @property (nonatomic, strong) UIButton *contactBtn;
  40. @property (nonatomic, strong) NTESBadgeView *badgeView;
  41. @property (nonatomic, strong) NSMutableArray *requestArr;
  42. @end
  43. @implementation FriendViewController
  44. - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
  45. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  46. if (self) {
  47. _previews = [[NSMutableDictionary alloc] init];
  48. self.autoRemoveRemoteSession = [[NTESBundleSetting sharedConfig] autoRemoveRemoteSession];
  49. }
  50. return self;
  51. }
  52. - (void)dealloc{
  53. [[NIMSDK sharedSDK].loginManager removeDelegate:self];
  54. }
  55. - (void)viewDidLoad{
  56. [super viewDidLoad];
  57. self.view.backgroundColor = UIColor.whiteColor;
  58. self.supportsForceTouch = [self.traitCollection respondsToSelector:@selector(forceTouchCapability)] && self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable;
  59. [[NIMSDK sharedSDK].loginManager addDelegate:self];
  60. [[NIMSDK sharedSDK].subscribeManager addDelegate:self];
  61. self.header = [[NTESListHeader alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 0)];
  62. self.header.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  63. self.header.delegate = self;
  64. [self.view addSubview:self.header];
  65. self.emptyTipLabel = [[UILabel alloc] init];
  66. self.emptyTipLabel.text = @"还没有会话,在通讯录中找个人聊聊吧";
  67. [self.emptyTipLabel sizeToFit];
  68. self.emptyTipLabel.hidden = self.recentSessions.count;
  69. [self.view addSubview:self.emptyTipLabel];
  70. NSString *userID = [[[NIMSDK sharedSDK] loginManager] currentAccount];
  71. self.navigationItem.titleView = [self titleView:userID];
  72. __weak typeof(self) wself = self;
  73. [[User sharedInfo] requestChatStickList:^{
  74. [wself sort];
  75. [wself refresh:YES];
  76. }];
  77. _searchArr = [[NSMutableArray alloc] init];
  78. _searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
  79. //_searchController.searchBar.barTintColor = User.orangeColor;
  80. _searchController.hidesNavigationBarDuringPresentation = NO;
  81. _searchController.searchBar.tintColor = UIColor.whiteColor;
  82. //_searchController.delegate = self;
  83. _searchController.dimsBackgroundDuringPresentation = NO;
  84. _searchController.searchBar.delegate = self;
  85. [self.tableView setTableHeaderView:_searchController.searchBar];
  86. }
  87. - (void)viewWillAppear:(BOOL)animated{
  88. [super viewWillAppear:animated];
  89. UINavigationItem *navItem = self.parentViewController.navigationItem;
  90. [navItem setTitle:@"朋友"];
  91. UIButton *emptyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  92. [emptyBtn setTitle:@"" forState:UIControlStateNormal];
  93. [emptyBtn sizeToFit];
  94. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:emptyBtn];
  95. [navItem setLeftBarButtonItems:@[leftItem]];
  96. _contactBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  97. [_contactBtn setImage:[UIImage imageNamed:@"朋友_03"] forState:UIControlStateNormal];
  98. [_contactBtn addTarget:self action:@selector(showContact:) forControlEvents:UIControlEventTouchUpInside];
  99. [_contactBtn sizeToFit];
  100. UIBarButtonItem *contactItem = [[UIBarButtonItem alloc] initWithCustomView:_contactBtn];
  101. _badgeView = [NTESBadgeView viewWithBadgeTip:@""];
  102. _badgeView.right = 20;
  103. _badgeView.top = -10;
  104. [_contactBtn addSubview:_badgeView];
  105. UIButton *spaceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  106. spaceBtn.frame = CGRectMake(0, 2, 10, 10);
  107. UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithCustomView:spaceBtn];
  108. UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  109. [addBtn setImage:[UIImage imageNamed:@"创建群_07"] forState:UIControlStateNormal];
  110. [addBtn addTarget:self action:@selector(showAddFriend:) forControlEvents:UIControlEventTouchUpInside];
  111. [addBtn sizeToFit];
  112. UIBarButtonItem *addItem = [[UIBarButtonItem alloc] initWithCustomView:addBtn];
  113. [navItem setRightBarButtonItems:@[addItem, spaceItem, contactItem]];
  114. [[User sharedInfo] removeNotJoinTeamConversation];
  115. [super resetRecentSessions];
  116. __weak typeof(self) wself = self;
  117. [[HttpRequest shared] requestFriendList:^(NSMutableArray<FriendRequestData *> * _Nullable dataArr) {
  118. wself.requestArr = dataArr;
  119. NSInteger badge = dataArr.count;
  120. wself.badgeView.hidden = badge == 0;
  121. wself.badgeView.badgeValue = [NSString stringWithFormat:@"%ld", (long)badge];
  122. } failure:^{
  123. }];
  124. }
  125. - (void)viewWillDisappear:(BOOL)animated
  126. {
  127. [super viewWillDisappear:animated];
  128. [self.searchController setActive:NO];
  129. }
  130. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
  131. {
  132. NSLog(@"textDidChange %@ %@", searchBar.text, searchText);
  133. if(searchText.length > 0)
  134. {
  135. [self.searchArr removeAllObjects];
  136. for(int i=0; i<self.recentSessions.count; i++)
  137. {
  138. NIMRecentSession *recent = [self.recentSessions objectAtIndex:i];
  139. NSString *name = [[self nameForRecentSession:recent] lowercaseString];
  140. if([name containsString:[searchText lowercaseString]])
  141. {
  142. [_searchArr addObject:recent];
  143. }
  144. }
  145. }
  146. else
  147. {
  148. [self.searchArr removeAllObjects];
  149. }
  150. [self.tableView reloadData];
  151. }
  152. - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  153. {
  154. [self.searchArr removeAllObjects];
  155. [self.tableView reloadData];
  156. }
  157. - (void)refresh:(BOOL)reload{
  158. [super refresh:reload];
  159. self.emptyTipLabel.hidden = self.recentSessions.count;
  160. }
  161. - (void)onSelectedRecent:(NIMRecentSession *)recent atIndexPath:(NSIndexPath *)indexPath{
  162. NTESSessionViewController *vc = [[NTESSessionViewController alloc] initWithSession:recent.session];
  163. [self.navigationController pushViewController:vc animated:YES];
  164. }
  165. - (void)onSelectedAvatar:(NIMRecentSession *)recent
  166. atIndexPath:(NSIndexPath *)indexPath{
  167. if (recent.session.sessionType == NIMSessionTypeP2P) {
  168. [User showUserInfo:recent.session.sessionId viewController:self];
  169. }
  170. else
  171. {
  172. [User showTeamInfo:recent.session.sessionId viewController:self];
  173. }
  174. }
  175. - (void)onDeleteRecentAtIndexPath:(NIMRecentSession *)recent atIndexPath:(NSIndexPath *)indexPath{
  176. [super onDeleteRecentAtIndexPath:recent atIndexPath:indexPath];
  177. }
  178. - (void)viewDidLayoutSubviews{
  179. [super viewDidLayoutSubviews];
  180. [self refreshSubview];
  181. }
  182. - (NSString *)nameForRecentSession:(NIMRecentSession *)recent{
  183. if ([recent.session.sessionId isEqualToString:[[NIMSDK sharedSDK].loginManager currentAccount]]) {
  184. return @"我的电脑";
  185. }
  186. return [super nameForRecentSession:recent];
  187. }
  188. #pragma mark - SessionListHeaderDelegate
  189. - (void)didSelectRowType:(NTESListHeaderType)type{
  190. //多人登录
  191. switch (type) {
  192. case ListHeaderTypeLoginClients:{
  193. NTESClientsTableViewController *vc = [[NTESClientsTableViewController alloc] initWithNibName:nil bundle:nil];
  194. [self.navigationController pushViewController:vc animated:YES];
  195. break;
  196. }
  197. default:
  198. break;
  199. }
  200. }
  201. #pragma mark - NIMLoginManagerDelegate
  202. - (void)onLogin:(NIMLoginStep)step{
  203. [super onLogin:step];
  204. switch (step) {
  205. case NIMLoginStepLinkFailed:
  206. self.titleLabel.text = [SessionListTitle stringByAppendingString:@"(未连接)"];
  207. break;
  208. case NIMLoginStepLinking:
  209. self.titleLabel.text = [SessionListTitle stringByAppendingString:@"(连接中)"];
  210. break;
  211. case NIMLoginStepLinkOK:
  212. case NIMLoginStepSyncOK:
  213. self.titleLabel.text = SessionListTitle;
  214. break;
  215. case NIMLoginStepSyncing:
  216. self.titleLabel.text = [SessionListTitle stringByAppendingString:@"(同步数据)"];
  217. break;
  218. default:
  219. break;
  220. }
  221. [self.titleLabel sizeToFit];
  222. self.titleLabel.centerX = self.navigationItem.titleView.width * .5f;
  223. [self.header refreshWithType:ListHeaderTypeNetStauts value:@(step)];
  224. [self.view setNeedsLayout];
  225. }
  226. - (void)onMultiLoginClientsChanged
  227. {
  228. [self.header refreshWithType:ListHeaderTypeLoginClients value:[NIMSDK sharedSDK].loginManager.currentLoginClients];
  229. [self.view setNeedsLayout];
  230. }
  231. #pragma mark - UITableViewDelegate
  232. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  233. {
  234. if (self.supportsForceTouch) {
  235. id<UIViewControllerPreviewing> preview = [self registerForPreviewingWithDelegate:self sourceView:cell];
  236. [self.previews setObject:preview forKey:@(indexPath.row)];
  237. }
  238. }
  239. - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
  240. {
  241. if (self.supportsForceTouch) {
  242. id<UIViewControllerPreviewing> preview = [self.previews objectForKey:@(indexPath.row)];
  243. [self unregisterForPreviewingWithContext:preview];
  244. [self.previews removeObjectForKey:@(indexPath.row)];
  245. }
  246. }
  247. - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)context viewControllerForLocation:(CGPoint)point {
  248. UITableViewCell *touchCell = (UITableViewCell *)context.sourceView;
  249. if ([touchCell isKindOfClass:[UITableViewCell class]]) {
  250. NSIndexPath *indexPath = [self.tableView indexPathForCell:touchCell];
  251. NIMRecentSession *recent = self.recentSessions[indexPath.row];
  252. NTESSessionPeekNavigationViewController *nav = [NTESSessionPeekNavigationViewController instance:recent.session];
  253. return nav;
  254. }
  255. return nil;
  256. }
  257. - (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
  258. {
  259. UITableViewCell *touchCell = (UITableViewCell *)previewingContext.sourceView;
  260. if ([touchCell isKindOfClass:[UITableViewCell class]]) {
  261. NSIndexPath *indexPath = [self.tableView indexPathForCell:touchCell];
  262. NIMRecentSession *recent = self.recentSessions[indexPath.row];
  263. NTESSessionViewController *vc = [[NTESSessionViewController alloc] initWithSession:recent.session];
  264. [self.navigationController showViewController:vc sender:nil];
  265. }
  266. }
  267. #pragma mark - NIMEventSubscribeManagerDelegate
  268. - (void)onRecvSubscribeEvents:(NSArray *)events
  269. {
  270. NSMutableSet *ids = [[NSMutableSet alloc] init];
  271. for (NIMSubscribeEvent *event in events) {
  272. [ids addObject:event.from];
  273. }
  274. NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
  275. for (NSIndexPath *indexPath in self.tableView.indexPathsForVisibleRows) {
  276. NIMRecentSession *recent = self.recentSessions[indexPath.row];
  277. if (recent.session.sessionType == NIMSessionTypeP2P) {
  278. NSString *from = recent.session.sessionId;
  279. if ([ids containsObject:from]) {
  280. [indexPaths addObject:indexPath];
  281. }
  282. }
  283. }
  284. [self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
  285. }
  286. #pragma mark - UITableViewDataSource
  287. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  288. if(_searchArr.count)
  289. return _searchArr.count;
  290. return self.recentSessions.count;
  291. }
  292. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  293. NIMRecentSession *recent = nil;
  294. if(_searchArr.count)
  295. {
  296. recent = [_searchArr objectAtIndex:indexPath.row];
  297. }
  298. else
  299. {
  300. recent = self.recentSessions[indexPath.row];
  301. }
  302. static NSString * cellId = @"cellId";
  303. NIMSessionListCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];
  304. if (!cell) {
  305. cell = [[NIMSessionListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
  306. [cell.avatarImageView addTarget:self action:@selector(onTouchAvatar:) forControlEvents:UIControlEventTouchUpInside];
  307. }
  308. cell.nameLabel.text = [self nameForRecentSession:recent];
  309. if(recent.session.sessionType == NIMSessionTypeP2P)
  310. {
  311. [cell.avatarImageView setAvatarBySession:recent.session];
  312. }
  313. else if(recent.session.sessionType == NIMSessionTypeTeam)
  314. {
  315. NIMTeam *team = [[NIMSDK sharedSDK].teamManager teamById:recent.session.sessionId];
  316. NSURL *url = team.thumbAvatarUrl ? [NSURL URLWithString:team.thumbAvatarUrl] : nil;
  317. [cell.avatarImageView nim_setImageWithURL:url placeholderImage:[User defaultTeamAvatar:team]];
  318. }
  319. [cell.nameLabel sizeToFit];
  320. cell.messageLabel.attributedText = [self contentForRecentSession:recent];
  321. [cell.messageLabel sizeToFit];
  322. cell.timeLabel.text = [self timestampDescriptionForRecentSession:recent];
  323. [cell.timeLabel sizeToFit];
  324. [cell refresh:recent];
  325. return cell;
  326. }
  327. #pragma mark - Private
  328. - (void)refreshSubview{
  329. [self.titleLabel sizeToFit];
  330. self.titleLabel.centerX = self.navigationItem.titleView.width * .5f;
  331. self.tableView.top = self.header.height;
  332. self.tableView.height = self.view.height - self.tableView.top;
  333. self.header.bottom = self.tableView.top + self.tableView.contentInset.top;
  334. self.emptyTipLabel.centerX = self.view.width * .5f;
  335. self.emptyTipLabel.centerY = self.tableView.height * .5f;
  336. }
  337. - (UIView*)titleView:(NSString*)userID{
  338. self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  339. self.titleLabel.text = SessionListTitle;
  340. self.titleLabel.font = [UIFont boldSystemFontOfSize:15.f];
  341. [self.titleLabel sizeToFit];
  342. UILabel *subLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  343. subLabel.textColor = [UIColor grayColor];
  344. subLabel.font = [UIFont systemFontOfSize:12.f];
  345. subLabel.text = userID;
  346. subLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
  347. [subLabel sizeToFit];
  348. UIView *titleView = [[UIView alloc] init];
  349. titleView.width = subLabel.width;
  350. titleView.height = self.titleLabel.height + subLabel.height;
  351. subLabel.bottom = titleView.height;
  352. [titleView addSubview:self.titleLabel];
  353. [titleView addSubview:subLabel];
  354. return titleView;
  355. }
  356. - (NSAttributedString *)contentForRecentSession:(NIMRecentSession *)recent{
  357. NSAttributedString *content;
  358. if (recent.lastMessage.messageType == NIMMessageTypeCustom)
  359. {
  360. NIMCustomObject *object = recent.lastMessage.messageObject;
  361. NSString *text = @"";
  362. if ([object.attachment isKindOfClass:[NTESSnapchatAttachment class]]) {
  363. text = @"[阅后即焚]";
  364. }
  365. else if ([object.attachment isKindOfClass:[NTESJanKenPonAttachment class]]) {
  366. text = @"[猜拳]";
  367. }
  368. else if ([object.attachment isKindOfClass:[NTESChartletAttachment class]]) {
  369. text = @"[贴图]";
  370. }
  371. else if ([object.attachment isKindOfClass:[NTESWhiteboardAttachment class]]) {
  372. text = @"[白板]";
  373. }
  374. else if ([object.attachment isKindOfClass:[NTESGiftAttachment class]]) {
  375. text = @"[礼物]";
  376. }
  377. else if ([object.attachment isKindOfClass:[NTESShareAttachment class]]) {
  378. text = @"[分享]";
  379. }
  380. else{
  381. text = @"[未知消息]";
  382. }
  383. if (recent.session.sessionType != NIMSessionTypeP2P)
  384. {
  385. NSString *nickName = [NTESSessionUtil showNick:recent.lastMessage.from inSession:recent.lastMessage.session];
  386. text = nickName.length ? [nickName stringByAppendingFormat:@" : %@",text] : @"";
  387. }
  388. content = [[NSAttributedString alloc] initWithString:text];
  389. }
  390. else
  391. {
  392. content = [super contentForRecentSession:recent];
  393. }
  394. NSMutableAttributedString *attContent = [[NSMutableAttributedString alloc] initWithAttributedString:content];
  395. [self checkNeedAtTip:recent content:attContent];
  396. [self checkOnlineState:recent content:attContent];
  397. return attContent;
  398. }
  399. - (void)checkNeedAtTip:(NIMRecentSession *)recent content:(NSMutableAttributedString *)content
  400. {
  401. if ([NTESSessionUtil recentSessionIsAtMark:recent]) {
  402. NSAttributedString *atTip = [[NSAttributedString alloc] initWithString:@"[有人@你] " attributes:@{NSForegroundColorAttributeName:[UIColor redColor]}];
  403. [content insertAttributedString:atTip atIndex:0];
  404. }
  405. }
  406. - (void)checkOnlineState:(NIMRecentSession *)recent content:(NSMutableAttributedString *)content
  407. {
  408. if (recent.session.sessionType == NIMSessionTypeP2P) {
  409. NSString *state = [NTESSessionUtil onlineState:recent.session.sessionId detail:NO];
  410. if (state.length) {
  411. NSString *format = [NSString stringWithFormat:@"[%@] ",state];
  412. NSAttributedString *atTip = [[NSAttributedString alloc] initWithString:format attributes:nil];
  413. [content insertAttributedString:atTip atIndex:0];
  414. }
  415. }
  416. }
  417. - (void)showContact:(int)sender
  418. {
  419. UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
  420. FriendListViewController *vc = [board instantiateViewControllerWithIdentifier:@"FriendList"];
  421. vc.requestArr = _requestArr;
  422. [self.navigationController pushViewController:vc animated:YES];
  423. }
  424. - (void)showAddFriend:(int)sender
  425. {
  426. NTESContactAddFriendViewController *vc = [[NTESContactAddFriendViewController alloc] init];
  427. [self.navigationController pushViewController:vc animated:YES];
  428. }
  429. - (void)sort{
  430. [self.recentSessions sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
  431. NIMRecentSession *item1 = obj1;
  432. NIMRecentSession *item2 = obj2;
  433. NSComparisonResult result = [[User sharedInfo] compareChatStick:item1.session.sessionId chatIdB:item2.session.sessionId];
  434. if(result != NSOrderedSame)
  435. return result;
  436. if (item1.lastMessage.timestamp < item2.lastMessage.timestamp) {
  437. return NSOrderedDescending;
  438. }
  439. if (item1.lastMessage.timestamp > item2.lastMessage.timestamp) {
  440. return NSOrderedAscending;
  441. }
  442. return NSOrderedSame;
  443. }];
  444. }
  445. - (void)onTouchAvatar:(id)sender{
  446. UIView *view = [sender superview];
  447. while (![view isKindOfClass:[UITableViewCell class]]) {
  448. view = view.superview;
  449. }
  450. UITableViewCell *cell = (UITableViewCell *)view;
  451. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  452. NIMRecentSession *recent = self.recentSessions[indexPath.row];
  453. [self onSelectedAvatar:recent atIndexPath:indexPath];
  454. }
  455. @end