JXSearchListVC.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. //
  2. // JXSearchListVC.m
  3. // shiku_im
  4. //
  5. // Created by IMAC on 2019/8/9.
  6. // Copyright © 2019 Reese. All rights reserved.
  7. //
  8. #import "JXSearchListVC.h"
  9. #import "JXChatViewController.h"
  10. #import "JXSearchShowCell.h"
  11. #import "JXXMPP.h"
  12. #import "JXRoomPool.h"
  13. #define FINDSEARCH Localized(@"JX_Find")
  14. #define WHOSERECORD Localized(@"JX_Recording")
  15. @interface JXSearchListVC ()<UISearchBarDelegate,UITableViewDelegate,UITableViewDataSource>
  16. @property (nonatomic,strong)UIView *baseView;
  17. @property (nonatomic,strong)NSString *titleString;
  18. @property (nonatomic,strong)NSString *seachText;
  19. @property (nonatomic,strong)NSArray *userArray;
  20. @property (nonatomic,strong)NSDictionary *userDictionary;
  21. @property (nonatomic,strong)NSDictionary *groupDictionary;
  22. @property (nonatomic,strong)NSDictionary *msgDictionary;
  23. @property (nonatomic,assign)BOOL isChatRecord;//init时传入是否建立聊天记录tableview
  24. @property (nonatomic,assign)BOOL enterChatRecord;//是否直接从SearchVC进入指定聊天记录
  25. @property (nonatomic,assign)BOOL inChatRecord;//是否在聊天记录列表中进入指定聊天记录
  26. @property (nonatomic,strong)JXUserObject *chatUser;
  27. //@property (nonatomic,strong)UIButton *cancelBtn;
  28. @property (nonatomic,strong)NSMutableArray *lastUserArray;
  29. @property (nonatomic,strong)NSMutableDictionary *lastGroupDictonary;
  30. @property (nonatomic,strong)NSMutableDictionary *lastMsgDictionary;
  31. @property (nonatomic,assign)NSInteger num;
  32. @end
  33. @implementation JXSearchListVC
  34. - (instancetype)initWithLable:(NSString *)lable withSearchText:(NSString *)searchtext withUserArray:(nullable NSMutableArray *)array withGroupDictionary:(nullable NSMutableDictionary *)groupdic withMsgDictionary:(nullable NSMutableDictionary *)msgDic isChatRecord:(BOOL )isChatRecord enterChatRecord:(BOOL )enterChatRecord withPeople:(nullable JXUserObject *)people{
  35. self = [super init];
  36. if (self) {
  37. self.titleString = lable;
  38. self.seachText = searchtext;
  39. if (array) {
  40. self.userArray = [[NSArray alloc] initWithArray:array];
  41. self.lastUserArray = [[NSMutableArray alloc] initWithArray:array];
  42. }
  43. if (groupdic) {
  44. self.groupDictionary = [[NSDictionary alloc] initWithDictionary:groupdic];
  45. self.lastGroupDictonary = [[NSMutableDictionary alloc] initWithDictionary:groupdic];
  46. }
  47. if (msgDic) {
  48. self.msgDictionary = [[NSDictionary alloc] initWithDictionary:msgDic];
  49. self.lastMsgDictionary = [[NSMutableDictionary alloc] initWithDictionary:msgDic];
  50. }
  51. self.isChatRecord = isChatRecord;
  52. self.enterChatRecord = enterChatRecord;
  53. if (people) {
  54. self.chatUser = people;
  55. }
  56. }
  57. return self;
  58. }
  59. - (void)viewDidLoad {
  60. [super viewDidLoad];
  61. [self creatView];
  62. }
  63. - (void)viewDidAppear:(BOOL)animated{
  64. [super viewDidAppear:NO];
  65. if ([self.delegate respondsToSelector:@selector(listDidAppear:)]) {
  66. [self.delegate listDidAppear:_enterChatRecord];
  67. }
  68. }
  69. - (void)viewWillDisappear:(BOOL)animated{
  70. [super viewWillDisappear:NO];
  71. [self.searchbar resignFirstResponder];
  72. // [self.cancelBtn setEnabled:YES];
  73. if ([self.delegate respondsToSelector:@selector(listWillDisappear:)]) {
  74. [self.delegate listWillDisappear:_enterChatRecord];
  75. }
  76. }
  77. - (void)creatView{
  78. UIView *stastusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, SCREEN_BAR)];
  79. if (THESIMPLESTYLE) {
  80. stastusBarView.backgroundColor = [UIColor whiteColor];
  81. }else{
  82. stastusBarView.backgroundColor = [g_theme themeColor];
  83. }
  84. [self.view addSubview:stastusBarView];
  85. //基础view
  86. self.view.backgroundColor = [UIColor clearColor];
  87. self.baseView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_BAR, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-SCREEN_BAR)];
  88. self.baseView.backgroundColor = [UIColor clearColor];
  89. [self.view addSubview:self.baseView];
  90. //导航栏
  91. UINavigationBar *bar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 44)];
  92. if (THESIMPLESTYLE) {
  93. bar.barTintColor = [UIColor whiteColor];
  94. }else{
  95. bar.barTintColor = [g_theme themeColor];
  96. }
  97. [bar setShadowImage:[[UIImage alloc] init]];
  98. bar.translucent = NO;
  99. //搜索框
  100. // self.searchbar = [[UISearchBar alloc] initWithFrame:CGRectMake(10, 5, JX_SCREEN_WIDTH-20, 33)];
  101. self.searchbar = [[UISearchBar alloc] initWithFrame:CGRectMake(40, 5, JX_SCREEN_WIDTH-55, 33)];
  102. self.searchbar.delegate = self;
  103. self.searchbar.placeholder = [FINDSEARCH stringByAppendingString:self.titleString];
  104. // self.searchbar.showsCancelButton = YES;
  105. self.searchbar.text = self.seachText;
  106. //搜索框样式
  107. // UITextField *searchField = [self.searchbar valueForKey:@"_searchField"];
  108. NSString *version = [UIDevice currentDevice].systemVersion;
  109. UITextField *searchField;
  110.       if (version.doubleValue >= 13.0) {
  111.           // 这里是对 13.0 以上的iOS系统进行处理
  112.           NSUInteger Views = [self.searchbar.subviews count];
  113.           for(int i = 0; i < Views; i++) {
  114.             if([[self.searchbar.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) {
  115.                 searchField = [self.searchbar.subviews objectAtIndex:i];
  116.             }
  117.           }
  118.          //这里设置相关属性
  119.       } else {
  120.           // 这里是对 13.0 以下的iOS系统进行处理
  121.           searchField = [self.searchbar valueForKey:@"_searchField"];
  122.            //这里设置相关属性
  123.       }
  124. searchField.tintColor = [g_theme themeColor];
  125. searchField.backgroundColor = HEXCOLOR(0xf2f2f2);
  126. UIView *backView = [self subViewOfClassName:@"_UISearchBarSearchFieldBackgroundView" toView:self.searchbar];
  127. backView.layer.cornerRadius = 5;
  128. backView.layer.masksToBounds = YES;
  129. backView.backgroundColor = HEXCOLOR(0xf2f2f2);
  130. // //自定义取消按钮样式
  131. // self.cancelBtn = [self.searchbar valueForKey:@"_cancelButton"];
  132. // [self.cancelBtn setTitle:CANCEL forState:UIControlStateNormal];
  133. // if (THESIMPLESTYLE) {
  134. // [self.cancelBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  135. // }else{
  136. // [self.cancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  137. // }
  138. // [self.cancelBtn setEnabled:YES];
  139. [bar addSubview:self.searchbar];
  140. self.backbtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 11, 20, 20)];
  141. if (THESIMPLESTYLE) {
  142. [self.backbtn setBackgroundImage:[UIImage imageNamed:@"title_back_black"] forState:UIControlStateNormal];
  143. }else{
  144. [self.backbtn setBackgroundImage:[UIImage imageNamed:@"title_back"] forState:UIControlStateNormal];
  145. }
  146. [self.backbtn addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside];
  147. [bar addSubview:self.backbtn];
  148. [self.baseView addSubview:bar];
  149. if (!_enterChatRecord) {
  150. self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH, 44, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-SCREEN_VIEW)];
  151. self.tableview.tag = 1;
  152. self.tableview.dataSource = self;
  153. self.tableview.delegate = self;
  154. self.tableview.backgroundColor = HEXCOLOR(0xf2f2f2);
  155. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 0.1)];
  156. view.backgroundColor = HEXCOLOR(0xf2f2f2);
  157. self.tableview.tableFooterView = view;
  158. self.tableview.separatorColor = HEXCOLOR(0xd9d9d9);
  159. [self.baseView addSubview:self.tableview];
  160. }
  161. if (_isChatRecord) {
  162. self.recordtableview = [[UITableView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH, 44, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-SCREEN_VIEW)];
  163. self.recordtableview.tag = 2;
  164. self.recordtableview.dataSource = self;
  165. self.recordtableview.delegate = self;
  166. self.recordtableview.backgroundColor = HEXCOLOR(0xf2f2f2);
  167. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 0.1)];
  168. view.backgroundColor = HEXCOLOR(0xf2f2f2);
  169. self.recordtableview.tableFooterView = view;
  170. self.recordtableview.separatorColor = HEXCOLOR(0xd9d9d9);
  171. [self.baseView addSubview:self.recordtableview];
  172. }
  173. }
  174. - (UIView*)subViewOfClassName:(NSString*)className toView:(UIView *)view{
  175. for (UIView* subView in view.subviews) {
  176. if ([NSStringFromClass(subView.class) isEqualToString:className]) {
  177. return subView;
  178. }
  179. UIView* resultFound = [self subViewOfClassName:className toView:subView];
  180. if (resultFound) {
  181. return resultFound;
  182. }
  183. }
  184. return nil;
  185. }
  186. //更新查找的tableview中的内容
  187. - (void)updataSearchContent{
  188. [self.lastUserArray removeAllObjects];
  189. if ([self.titleString isEqualToString:CONTACT]) {
  190. for (JXUserObject *user in self.userArray) {
  191. if ([user.userNickname containsString:self.searchbar.text] && ![self.lastUserArray containsObject:user]) {
  192. [self.lastUserArray addObject:user];
  193. }
  194. if (![user.userNickname containsString:self.searchbar.text] && [user.userId containsString:self.searchbar.text] && ![self.lastUserArray containsObject:user]) {
  195. [self.lastUserArray addObject:user];
  196. }
  197. }
  198. }
  199. if ([self.titleString isEqualToString:GROUP]) {
  200. [self.lastGroupDictonary removeAllObjects];
  201. for (JXUserObject *user in self.userArray) {
  202. NSString *str = user.roomId;
  203. NSString *contain = [self.groupDictionary objectForKey:str];
  204. if ([user.userNickname localizedCaseInsensitiveContainsString:self.searchbar.text] && ![self.lastUserArray containsObject:user]) {
  205. [self.lastUserArray addObject:user];
  206. }
  207. if (![user.userNickname localizedCaseInsensitiveContainsString:self.searchbar.text] && [contain localizedCaseInsensitiveContainsString:self.searchbar.text] && ![self.lastUserArray containsObject:user]) {
  208. [self.lastUserArray addObject:user];
  209. [self.lastGroupDictonary setObject:contain forKey:str];
  210. }
  211. }
  212. }
  213. if ([self.titleString isEqualToString:PUBLIC]) {
  214. for (JXUserObject *user in self.userArray) {
  215. if ([user.userNickname localizedCaseInsensitiveContainsString:self.searchbar.text] && ![self.lastUserArray containsObject:user]) {
  216. [self.lastUserArray addObject:user];
  217. }
  218. }
  219. }
  220. if ([self.titleString isEqualToString:RECORD]) {
  221. for (JXUserObject *user in self.userArray) {
  222. NSMutableArray *array = [self.msgDictionary objectForKey:user.userId];
  223. NSMutableArray *array2 = [NSMutableArray array];
  224. for (JXMessageObject *msg in array) {
  225. if ([msg.content localizedCaseInsensitiveContainsString:self.searchbar.text]) {
  226. [array2 addObject:msg];
  227. }
  228. }
  229. [self.lastMsgDictionary setObject:array2 forKey:user.userId];
  230. if (array2.count != 0) {
  231. [self.lastUserArray addObject:user];
  232. }
  233. }
  234. }
  235. }
  236. //更新查找中的recordtableview的内容
  237. - (void)updateRecordContent{
  238. NSMutableArray *array = [self.msgDictionary objectForKey:self.chatUser.userId];
  239. NSMutableArray *array2 = [NSMutableArray array];
  240. for (JXMessageObject *msg in array) {
  241. NSString *message = msg.content;
  242. NSMutableArray *conArray = [NSMutableArray array];
  243. [self getMessageRange:message :conArray];
  244. NSMutableArray *contentArray = [NSMutableArray array];
  245. _num = 0;
  246. [self splicingString:conArray inArray:contentArray];
  247. for (NSString *object in contentArray) {
  248. if ([object hasSuffix:@"]"]&&[object hasPrefix:@"["]) {
  249. }else{
  250. if ([object localizedCaseInsensitiveContainsString:self.searchbar.text]) {
  251. [array2 addObject:msg];
  252. break;
  253. }
  254. }
  255. }
  256. }
  257. [self.lastMsgDictionary setObject:array2 forKey:self.chatUser.userId];
  258. }
  259. - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
  260. if (!_enterChatRecord) {
  261. if (!_inChatRecord) {
  262. if (self.searchbar.text.length == 0) {
  263. [self.lastUserArray removeAllObjects];
  264. [self.tableview reloadData];
  265. }else{
  266. [self updataSearchContent];
  267. [self.tableview reloadData];
  268. }
  269. }else{
  270. [self updateRecordContent];
  271. [self.recordtableview reloadData];
  272. }
  273. }else{
  274. [self updateRecordContent];
  275. [self.recordtableview reloadData];
  276. }
  277. }
  278. //排除表情包
  279. - (void)getMessageRange:(NSString*)message :(NSMutableArray*)array {
  280. NSRange range=[message rangeOfString: @"["];
  281. NSRange range1=[message rangeOfString: @"]"];
  282. // 动画过滤
  283. if ([message isEqualToString:[NSString stringWithFormat:@"[%@]",Localized(@"emojiVC_Emoji")]]) {
  284. [array addObject:message];
  285. return;
  286. }
  287. //判断当前字符串是否还有表情的标志。
  288. if (range.length>0 && range1.length>0 && range1.location > range.location) {
  289. if (range.location > 0) {
  290. NSString *str = [message substringToIndex:range.location];
  291. NSString *str1 = [message substringFromIndex:range.location];
  292. [array addObject:str];
  293. [self getMessageRange:str1 :array];
  294. }else {
  295. NSString *emojiString = [message substringWithRange:NSMakeRange(range.location + 1, range1.location - 1)];
  296. BOOL isEmoji = NO;
  297. NSString *str;
  298. NSString *str1;
  299. for (NSMutableDictionary *dic in g_constant.emojiArray) {
  300. NSString *emoji = [dic objectForKey:@"english"];
  301. if ([emoji isEqualToString:emojiString]) {
  302. isEmoji = YES;
  303. break;
  304. }
  305. }
  306. if (isEmoji) {
  307. str = [message substringWithRange:NSMakeRange(range.location, range1.location + 1)];
  308. str1 = [message substringFromIndex:range1.location + 1];
  309. [array addObject:str];
  310. }else{
  311. NSString *posString = [message substringWithRange:NSMakeRange(range.location + 1, range1.location)];
  312. NSRange posRange = [posString rangeOfString:@"["];
  313. if (posRange.location != NSNotFound) {
  314. str = [message substringToIndex:posRange.location + 1];
  315. str1 = [message substringFromIndex:posRange.location + 1];
  316. [array addObject:str];
  317. }else{
  318. str = [message substringToIndex:range.location + 1];
  319. str1 = [message substringFromIndex:range.location + 1];
  320. [array addObject:str];
  321. }
  322. }
  323. [self getMessageRange:str1 :array];
  324. }
  325. }else if (range.length>0 && range1.length>0 && range1.location < range.location){
  326. NSString *str = [message substringToIndex:range1.location + 1];
  327. NSString *str1 = [message substringFromIndex:range1.location + 1];
  328. [array addObject:str];
  329. [self getMessageRange:str1 :array];
  330. }else if (message != nil) {
  331. [array addObject:message];
  332. }
  333. }
  334. //拼接字符串
  335. - (void)splicingString:(NSMutableArray *)array inArray:(NSMutableArray *)contentArray{
  336. if (_num >= array.count) {
  337. return;
  338. }
  339. NSString *str = [NSString string];
  340. for (NSInteger i = _num; i < array.count; i++) {
  341. NSString *object = array[i];
  342. if ([object hasSuffix:@"]"]&&[object hasPrefix:@"["]) {
  343. [contentArray addObject:str];
  344. [contentArray addObject:object];
  345. _num = i + 1;
  346. break;
  347. }else{
  348. _num = i + 1;
  349. str = [str stringByAppendingString:object];
  350. if (_num >= array.count) {
  351. [contentArray addObject:str];
  352. return;
  353. }
  354. }
  355. }
  356. [self splicingString:array inArray:contentArray];
  357. }
  358. - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
  359. if ([self.delegate respondsToSelector:@selector(tapSearchCancelBtn)]) {
  360. [self dismissViewControllerAnimated:NO completion:nil];
  361. [self.delegate tapSearchCancelBtn];
  362. }
  363. }
  364. - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
  365. [self.searchbar resignFirstResponder];
  366. // [self.cancelBtn setEnabled:YES];
  367. }
  368. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
  369. [self.searchbar resignFirstResponder];
  370. // [self.cancelBtn setEnabled:YES];
  371. }
  372. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  373. return 1;
  374. }
  375. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  376. if (tableView.tag == 1) {
  377. if (self.lastUserArray.count == 0) {
  378. return 0;
  379. }else{
  380. return self.lastUserArray.count+1;
  381. }
  382. }
  383. if (self.searchbar.text.length == 0) {
  384. return 1;
  385. }
  386. NSArray *array = [self.lastMsgDictionary objectForKey:self.chatUser.userId];
  387. return array.count+1;
  388. }
  389. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  390. if (tableView.tag == 1) {
  391. if (indexPath.row == 0) {
  392. return 33;
  393. }
  394. return 60;
  395. }
  396. return 60;
  397. }
  398. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  399. if (tableView.tag == 1) {
  400. if (indexPath.row == 0) {
  401. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"sectionNameCell"];
  402. cell.textLabel.text = self.titleString;
  403. cell.textLabel.textColor = HEXCOLOR(0x999999);
  404. cell.textLabel.font = [UIFont systemFontOfSize:14];
  405. cell.userInteractionEnabled = NO;
  406. return cell;
  407. }else{
  408. JXUserObject *user = self.lastUserArray[indexPath.row-1];
  409. NSString *nickName = user.userNickname;
  410. NSString *userId = user.userId;
  411. JXSearchShowCell *cell = [[JXSearchShowCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"chatCell" withNewStyle:JXSearchShowCellStyleUser];
  412. if ([self.titleString isEqualToString:CONTACT]) {
  413. if ([nickName localizedCaseInsensitiveContainsString:self.searchbar.text]) {
  414. NSMutableAttributedString *string1 = [self showSearchTextColor:nickName];
  415. cell.aboveAttributedText = string1;
  416. }else{
  417. cell.aboveText = nickName;
  418. if ([userId localizedCaseInsensitiveContainsString:self.searchbar.text]) {
  419. NSMutableAttributedString *string2 = [self showSearchTextColor:userId];
  420. NSMutableAttributedString *string3 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@:",USERNUMBER]];
  421. [string3 appendAttributedString:string2];
  422. cell.belowAttributedText = string3;
  423. }
  424. }
  425. [g_server getHeadImageSmall:userId userName:nickName imageView:cell.headImgView];
  426. }
  427. if ([self.titleString isEqualToString:GROUP]) {
  428. NSString *str = user.roomId;
  429. if ([nickName localizedStandardContainsString:self.searchbar.text]) {
  430. NSMutableAttributedString *string1 = [self showSearchTextColor:nickName];
  431. cell.aboveAttributedText = string1;
  432. }else{
  433. cell.aboveText = nickName;
  434. NSString *containString = [self.lastGroupDictonary objectForKey:str];
  435. NSMutableAttributedString *string2 = [self showSearchTextColor:containString];
  436. NSMutableAttributedString *string3 = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@: ",CONTAIN]];
  437. [string3 appendAttributedString:string2];
  438. cell.belowAttributedText = string3;
  439. }
  440. [g_server getRoomHeadImageSmall:userId roomId:str imageView:cell.headImgView];
  441. }
  442. if ([self.titleString isEqualToString:PUBLIC]) {
  443. NSMutableAttributedString *string = [self showSearchTextColor:nickName];
  444. cell.textLabel.attributedText = string;
  445. [g_server getHeadImageSmall:userId userName:nickName imageView:cell.headImgView];
  446. }
  447. if ([self.titleString isEqualToString:RECORD]) {
  448. cell.aboveText = nickName;
  449. NSInteger i = [self getMsgCountWithUserId:userId];
  450. NSString *str = [NSString stringWithFormat:@"%ld%@",(long)i,RECORDNUMBERS];
  451. cell.belowText = str;
  452. if (user.roomId) {
  453. [g_server getRoomHeadImageSmall:userId roomId:user.roomId imageView:cell.headImgView];
  454. }else{
  455. [g_server getHeadImageSmall:userId userName:nickName imageView:cell.headImgView];
  456. }
  457. }
  458. return cell;
  459. }
  460. }
  461. if (tableView.tag == 2){
  462. NSString *nickName = self.chatUser.userNickname;
  463. NSString *userId = self.chatUser.userId;
  464. if (indexPath.row == 0) {
  465. JXSearchShowCell *cell = [[JXSearchShowCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"recordNameCell" withNewStyle:JXSearchShowCellStyleUser];
  466. [g_server getHeadImageSmall:userId userName:nickName imageView:cell.headImgView];
  467. cell.aboveText = [NSString stringWithFormat:@"\"%@\"%@",nickName,WHOSERECORD];
  468. [cell setUserInteractionEnabled:NO];
  469. [cell setSeparatorInset:UIEdgeInsetsZero];
  470. return cell;
  471. }else{
  472. JXSearchShowCell *cell = [tableView dequeueReusableCellWithIdentifier:@"searchRecordCell"];
  473. if (!cell) {
  474. cell = [[JXSearchShowCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"searchRecordCell" withNewStyle:JXSearchShowCellStyleRecord];
  475. }
  476. NSMutableArray *msgArray = [self.lastMsgDictionary objectForKey:userId];
  477. JXMessageObject *msg = msgArray[indexPath.row-1];
  478. NSString *from = msg.fromUserId;
  479. NSString *name = msg.fromUserName;
  480. NSString *content = msg.content;
  481. NSString *msgTime = [TimeUtil getTimeStrStyle1:[msg.timeSend timeIntervalSince1970]];
  482. [g_server getHeadImageSmall:from userName:name imageView:cell.headImgView];
  483. cell.aboveText = name;
  484. // NSMutableAttributedString *string = [self showSearchTextColor:content];
  485. // cell.belowAttributedText = string;
  486. cell.searchText = self.searchbar.text;
  487. cell.belowText = content;
  488. cell.rightText = msgTime;
  489. return cell;
  490. }
  491. }
  492. UITableViewCell *cell = [[UITableViewCell alloc] init];
  493. return cell;
  494. }
  495. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  496. if (tableView.tag == 1) {
  497. JXUserObject *user = self.lastUserArray[indexPath.row - 1];
  498. if ([self.titleString isEqualToString:CONTACT] || [self.titleString isEqualToString:PUBLIC]) {
  499. JXChatViewController *chatView = [[JXChatViewController alloc] init];
  500. chatView.chatPerson = user;
  501. [g_navigation pushViewController:chatView animated:YES];
  502. [self.tableview deselectRowAtIndexPath:indexPath animated:YES];
  503. }
  504. if ([self.titleString isEqualToString:GROUP]) {
  505. roomData * roomdata = [[roomData alloc] init];
  506. [roomdata getDataFromDict:[user toDictionary]];
  507. JXChatViewController *chatView = [JXChatViewController alloc];
  508. if ([user.groupStatus intValue] == 0) {
  509. chatView.chatRoom = [[JXXMPP sharedInstance].roomPool joinRoom:user.userId title:user.userNickname lastDate:nil isNew:NO];
  510. }
  511. chatView.title = user.userNickname;
  512. chatView.roomJid = user.userId;
  513. chatView.roomId = user.roomId;
  514. chatView.groupStatus = user.groupStatus;
  515. chatView.room = roomdata;
  516. chatView.chatPerson = user;
  517. chatView = [chatView init];
  518. [g_navigation pushViewController:chatView animated:YES];
  519. [self.tableview deselectRowAtIndexPath:indexPath animated:YES];
  520. }
  521. if ([self.titleString isEqualToString:RECORD]) {
  522. self.chatUser = user;
  523. [self.recordtableview reloadData];
  524. [UIView animateWithDuration:0.3 animations:^{
  525. self.recordtableview.frame = CGRectMake(0, 44, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-SCREEN_VIEW);
  526. }];
  527. _inChatRecord = YES;
  528. [self.tableview deselectRowAtIndexPath:indexPath animated:YES];
  529. }
  530. }
  531. if (tableView.tag == 2) {
  532. JXUserObject *user = self.chatUser;
  533. NSMutableArray *msgArray = [self.lastMsgDictionary objectForKey:user.userId];
  534. JXMessageObject *msg = msgArray[indexPath.row-1];
  535. [self.recordtableview deselectRowAtIndexPath:indexPath animated:YES];
  536. int lineNum = 0;
  537. lineNum = [msg getLineNumWithUserId:user.userId];
  538. JXChatViewController *chatView = [JXChatViewController alloc];
  539. chatView.scrollLine = lineNum;
  540. chatView.title = user.userNickname;
  541. if([user.roomFlag intValue] > 0 || user.roomId.length > 0){
  542. if(g_xmpp.isLogined != 1){
  543. [g_xmpp showXmppOfflineAlert];
  544. return;
  545. }
  546. chatView.roomJid = user.userId;
  547. chatView.roomId = user.roomId;
  548. chatView.groupStatus = user.groupStatus;
  549. if ([user.groupStatus intValue] == 0) {
  550. chatView.chatRoom = [[JXXMPP sharedInstance].roomPool joinRoom:user.userId title:user.userNickname lastDate:nil isNew:NO];
  551. }
  552. if (user.roomFlag) {
  553. NSDictionary * groupDict = [user toDictionary];
  554. roomData * roomdata = [[roomData alloc] init];
  555. [roomdata getDataFromDict:groupDict];
  556. chatView.room = roomdata;
  557. }
  558. }
  559. chatView.lastMsg = msg;
  560. chatView.chatPerson = user;
  561. chatView = [chatView init];
  562. [g_navigation pushViewController:chatView animated:YES];
  563. chatView.view.hidden = NO;
  564. }
  565. if ([self.delegate respondsToSelector:@selector(saveSearchRecord:)]) {
  566. [self.delegate saveSearchRecord:self.searchbar.text];
  567. }
  568. }
  569. //返回标记搜索查找的字符串
  570. - (NSMutableAttributedString *)showSearchTextColor:(NSString *)str{
  571. NSRange range = [str rangeOfString:self.searchbar.text options:NSCaseInsensitiveSearch];
  572. NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:str];
  573. if (range.location != NSNotFound) {
  574. [string addAttribute:NSForegroundColorAttributeName value:[g_theme themeColor] range:range];
  575. }
  576. return string;
  577. }
  578. - (NSInteger)getMsgCountWithUserId:(NSString *)userId{
  579. NSMutableArray *array = [self.lastMsgDictionary objectForKey:userId];
  580. return array.count;
  581. }
  582. - (void)dismissView{
  583. if (_inChatRecord) {
  584. _inChatRecord = NO;
  585. [self.recordtableview setContentOffset:CGPointMake(0,0) animated:NO];
  586. self.searchbar.text = self.seachText;
  587. [self.searchbar resignFirstResponder];
  588. // [self.cancelBtn setEnabled:YES];
  589. [UIView animateWithDuration:0.3 animations:^{
  590. self.recordtableview.frame = CGRectMake(JX_SCREEN_WIDTH, 44, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-SCREEN_VIEW);
  591. }];
  592. }else{
  593. if ([self.delegate respondsToSelector:@selector(tapBackBtn:)]) {
  594. [self.delegate tapBackBtn:_enterChatRecord];
  595. }
  596. }
  597. }
  598. @end