JXNewFriendViewController.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. //
  2. // JXNewFriendViewController.h.m
  3. //
  4. // Created by flyeagleTang on 14-4-3.
  5. // Copyright (c) 2014年 Reese. All rights reserved.
  6. //
  7. #import "JXNewFriendViewController.h"
  8. #import "JXChatViewController.h"
  9. #import "AppDelegate.h"
  10. #import "JXLabel.h"
  11. #import "JXImageView.h"
  12. #import "JXFriendCell.h"
  13. #import "JXRoomPool.h"
  14. #import "JXFriendObject.h"
  15. #import "UIFactory.h"
  16. #import "JXInputVC.h"
  17. #import "JXUserInfoVC.h"
  18. #import "JXSearchGroupVC.h"
  19. #import "JXCommonInputVC.h"
  20. #import "JXSearchUserVC.h"
  21. #import "JXNewFriendToSearVc.h"
  22. #import "JXFriendHeadView.h"
  23. #import "SaveOrReadArr.h"
  24. @interface JXNewFriendViewController ()<JXFriendCellDelegate,JXNewFriendToSearVcVCDelegate,UITextFieldDelegate>
  25. @property (nonatomic,strong) UITextField *searchfield;
  26. @property (nonatomic,strong) NSMutableArray *dataArr;
  27. @property (nonatomic,strong) NSMutableArray *dataArrTime;
  28. @end
  29. @implementation JXNewFriendViewController
  30. - (id)init
  31. {
  32. self = [super init];
  33. if (self) {
  34. _dataArr=[NSMutableArray array];
  35. _dataArrTime=[NSMutableArray array];
  36. self.heightHeader = 0;
  37. self.heightFooter = 0;
  38. self.isGotoBack = YES;
  39. self.title = Localized(@"JXNewFriendVC_NewFirend");
  40. //self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  41. [self createHeadAndFoot];
  42. self.isShowFooterPull = NO;
  43. self.tableView.backgroundColor = [UIColor whiteColor];// HEXCOLOR(0xF2F2F2);
  44. [self defineNavChatPush:@"新的朋友"];
  45. self.tableView.frame=CGRectMake(0, JX_SCREEN_TOP, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-JX_SCREEN_TOP);
  46. UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 50)];
  47. //[self.view addSubview:backView];
  48. backView.backgroundColor = HEXCOLOR(0xF2F2F2);
  49. _searchfield = [[UITextField alloc] initWithFrame:CGRectMake(15, 10, backView.frame.size.width - 30, 35)];
  50. _searchfield.placeholder = @"搜索(即信号或手机号)";//Localized(@"JX_Seach");
  51. _searchfield.backgroundColor = [UIColor whiteColor];/// HEXCOLOR(0xf0f0f0);
  52. _searchfield.textColor = [UIColor blackColor];
  53. [_searchfield setFont:SYSFONT(14)];
  54. // _seekTextField.backgroundColor = [UIColor whiteColor];
  55. UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"card_search"]];
  56. UIView *leftView = [[UIView alloc ]initWithFrame:CGRectMake(0, 0, 30, 30)];
  57. // imageView.center = CGPointMake(leftView.frame.size.width/2, leftView.frame.size.height/2);
  58. imageView.center = leftView.center;
  59. [leftView addSubview:imageView];
  60. _searchfield.leftView = leftView;
  61. _searchfield.clearButtonMode = UITextFieldViewModeWhileEditing;
  62. _searchfield.leftViewMode = UITextFieldViewModeAlways;
  63. _searchfield.borderStyle = UITextBorderStyleNone;
  64. _searchfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  65. _searchfield.layer.masksToBounds = YES;
  66. _searchfield.layer.cornerRadius = 5;
  67. _searchfield.delegate = self;
  68. _searchfield.returnKeyType = UIReturnKeyGoogle;
  69. [backView addSubview:_searchfield];
  70. [_searchfield addTarget:self action:@selector(onSearchRoom) forControlEvents:UIControlEventTouchUpInside];
  71. self.tableView.tableHeaderView=backView;
  72. [g_notify addObserver:self selector:@selector(newRequest:) name:kXMPPNewRequestNotifaction object:nil];
  73. [g_notify addObserver:self selector:@selector(newReceipt:) name:kXMPPReceiptNotifaction object:nil];
  74. [g_notify addObserver:self selector:@selector(onSendTimeout:) name:kXMPPSendTimeOutNotifaction object:nil];
  75. poolCell = [[NSMutableDictionary alloc]init];
  76. current_chat_userId = FRIEND_CENTER_USERID;
  77. [_wait stop];
  78. }
  79. return self;
  80. }
  81. /**
  82. * 跳转到 搜索页面
  83. */
  84. - (BOOL)textFieldShouldReturn:(UITextField *)textField{
  85. if (textField.text.length==0) {
  86. [_dataArr removeAllObjects];
  87. [self.tableView reloadData];
  88. return YES;
  89. }
  90. [textField resignFirstResponder];
  91. return YES;
  92. }
  93. //- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
  94. //
  95. // return YES;
  96. //
  97. //}
  98. - (BOOL)textFieldShouldClear:(UITextField *)textField{
  99. [_dataArr removeAllObjects];
  100. [self.tableView reloadData];
  101. return YES;
  102. }
  103. - (void)textFieldDidBeginEditing:(UITextField *)textField{
  104. [textField resignFirstResponder];
  105. JXSearchUserVC* vc = [JXSearchUserVC alloc];
  106. vc.delegate = self;
  107. vc.type = JXSearchTypeUser;
  108. vc = [vc init];
  109. [g_navigation pushViewController:vc animated:YES];
  110. }
  111. - (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
  112. [textField resignFirstResponder];
  113. if (textField.text.length==0) {
  114. [_dataArr removeAllObjects];
  115. [self.tableView reloadData];
  116. }
  117. NSString *userID=textField.text;
  118. NSLog(@"xxxx1 %@",userID );
  119. [_array enumerateObjectsUsingBlock:^(JXFriendObject * obj, NSUInteger idx, BOOL * _Nonnull stop) {
  120. NSString *userID2=obj.userId;
  121. NSLog(@"xxxx %@",userID2 );
  122. if ([userID isEqualToString:obj.userId]) {
  123. NSLog(@"xxxx %@",obj );
  124. [_dataArr addObject:obj];
  125. [self.tableView reloadData];
  126. }
  127. }];
  128. return YES;
  129. JXNewFriendToSearVc *vc = [[JXNewFriendToSearVc alloc] init];
  130. vc.delegate = self;
  131. vc.titleStr = [NSString stringWithFormat:@"%@%@",Localized(@"JX_Seach"),Localized(@"JXNewFriendVC_NewFirend")] ;
  132. vc.subTitle =Localized(@"JXNewFriendVC_NewFirend");
  133. vc.tip = Localized(@"JX_InputRoomName");
  134. vc.btnTitle = Localized(@"JX_Seach");
  135. [g_navigation pushViewController:vc animated:YES];
  136. return YES;
  137. // JXCommonInputVC *vc = [[JXCommonInputVC alloc] init];
  138. vc.delegate = self;
  139. vc.titleStr = Localized(@"JX_CommonGroupSearch");
  140. vc.subTitle = Localized(@"JX_ManyPerChat");
  141. vc.tip = Localized(@"JX_InputRoomName");
  142. vc.btnTitle = Localized(@"JX_Seach");
  143. [g_navigation pushViewController:vc animated:YES];
  144. }
  145. - (void)onSearchRoom{
  146. }
  147. - (void)commonInputVCBtnActionWithVC:(JXCommonInputVC *)commonInputVC {
  148. JXSearchGroupVC *vc = [[JXSearchGroupVC alloc] init];
  149. vc.searchName = commonInputVC.name.text;
  150. [g_navigation pushViewController:vc animated:YES];
  151. }
  152. - (void)dealloc {
  153. // NSLog(@"JXNewFriendViewController.dealloc");
  154. // [super dealloc];
  155. }
  156. -(void)free{
  157. current_chat_userId = nil;
  158. [_array removeAllObjects];
  159. // [_array release];
  160. [poolCell removeAllObjects];
  161. // [poolCell release];
  162. [g_notify removeObserver:self name:kXMPPNewRequestNotifaction object:nil];
  163. [g_notify removeObserver:self name:kXMPPSendTimeOutNotifaction object:nil];
  164. [g_notify removeObserver:self name:kXMPPReceiptNotifaction object:nil];
  165. }
  166. - (void)viewDidLoad
  167. {
  168. [super viewDidLoad];
  169. self.view.backgroundColor=[UIColor whiteColor];
  170. self.tableView.backgroundColor=[UIColor whiteColor];
  171. _array = [[NSMutableArray alloc]init];
  172. [self refresh];
  173. }
  174. - (void)viewWillAppear:(BOOL)animated
  175. {
  176. [super viewWillAppear:animated];
  177. [self.navigationController setNavigationBarHidden:YES];
  178. [_wait stop];
  179. }
  180. - (void)didReceiveMemoryWarning
  181. {
  182. [super didReceiveMemoryWarning];
  183. // Dispose of any resources that can be recreated.
  184. }
  185. #pragma mark ---------tableView协议----------------
  186. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  187. {
  188. if( _dataArrTime.count>0||_dataArrTime.count>0){
  189. return 1;
  190. }else if( _array.count>0&&_dataArrTime.count>0){
  191. return 2;
  192. }else{
  193. return 0;
  194. }
  195. }
  196. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  197. {
  198. if (section==0) {
  199. return _dataArrTime.count;
  200. }else{
  201. return _array.count;
  202. }
  203. }
  204. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
  205. static NSString *viewIdentfier = @"headView";
  206. JXFriendHeadView *headView=[tableView dequeueReusableHeaderFooterViewWithIdentifier:viewIdentfier];
  207. if(!headView){
  208. headView = [[JXFriendHeadView alloc] initWithReuseIdentifier:viewIdentfier];
  209. }
  210. if (section==0) {
  211. [headView setStrURL:@"近三天"];
  212. }else{
  213. [headView setStrURL:@"三天前"];
  214. }
  215. return headView;
  216. }
  217. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  218. return 30;
  219. }
  220. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  221. return 0.01;
  222. }
  223. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  224. {
  225. JXFriendCell *cell=nil;
  226. NSString* cellName = [NSString stringWithFormat:@"msg_%d_%ld",_refreshCount,indexPath.row];
  227. cell = [tableView dequeueReusableCellWithIdentifier:cellName];
  228. if (indexPath.section==0) {
  229. if(cell==nil){
  230. JXFriendObject *user=_dataArrTime[indexPath.row];
  231. cell = [JXFriendCell alloc];
  232. [_table addToPool:cell];
  233. cell.tag = indexPath.row;
  234. cell.delegate = self;
  235. cell.title = user.remarkName.length > 0 ? user.remarkName : user.userNickname;
  236. cell.subtitle = user.userId;
  237. cell.bottomTitle = [TimeUtil formatDate:user.timeCreate format:@"MM-dd HH:mm"];
  238. cell.user = user;
  239. cell.target = self;
  240. cell = [cell initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
  241. user = nil;
  242. }
  243. }else{
  244. if(cell==nil){
  245. if (_dataArr.count>0) { _array=_dataArr; }
  246. JXFriendObject *user=_array[indexPath.row];
  247. cell = [JXFriendCell alloc];
  248. [_table addToPool:cell];
  249. cell.delegate = self;
  250. cell.tag=indexPath.row;
  251. cell.title = user.remarkName.length > 0 ? user.remarkName : user.userNickname;
  252. cell.subtitle = user.userId;
  253. cell.bottomTitle = [TimeUtil formatDate:user.timeCreate format:@"MM-dd HH:mm"];
  254. cell.user = user;
  255. cell.target = self;
  256. cell = [cell initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
  257. user = nil;
  258. }
  259. }
  260. return cell;
  261. }
  262. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  263. {
  264. if (indexPath.section==0) {
  265. JXFriendObject *friend=_dataArrTime[indexPath.row];
  266. JXUserObject *user = [[JXUserObject alloc] init];
  267. user.userNickname = friend.userNickname;
  268. user.userId = friend.userId;
  269. JXChatViewC *sendView=[JXChatViewC alloc];
  270. sendView.isHiddenFooter = YES;
  271. sendView.title = friend.userNickname;
  272. sendView.chatPerson = user;
  273. sendView = [sendView init];
  274. [g_navigation pushViewController:sendView animated:YES];
  275. }else{
  276. JXFriendObject *friend=_array[indexPath.row];
  277. JXUserObject *user = [[JXUserObject alloc] init];
  278. user.userNickname = friend.userNickname;
  279. user.userId = friend.userId;
  280. JXChatViewC *sendView=[JXChatViewC alloc];
  281. sendView.isHiddenFooter = YES;
  282. sendView.title = friend.userNickname;
  283. sendView.chatPerson = user;
  284. sendView = [sendView init];
  285. [g_navigation pushViewController:sendView animated:YES];
  286. }
  287. }
  288. - (void)friendCell:(JXFriendCell *)friendCell headImageAction:(NSString *)userId {
  289. // [g_server getUser:userId toView:self];
  290. JXUserInfoVC* vc = [JXUserInfoVC alloc];
  291. vc.userId = userId;
  292. vc.fromAddType = 6;
  293. vc = [vc init];
  294. [g_navigation pushViewController:vc animated:YES];
  295. }
  296. -(void)refresh{
  297. [self stopLoading];
  298. _refreshCount++;
  299. // [_array release];
  300. _array=[[JXFriendObject sharedInstance] fetchAllFriendsFromLocal];
  301. NSArray *arr = [[_array reverseObjectEnumerator] allObjects];
  302. [_dataArrTime removeAllObjects];
  303. [arr enumerateObjectsUsingBlock:^(JXFriendObject *_Nonnull user, NSUInteger idx, BOOL * _Nonnull stop) {
  304. //status
  305. NSString *strtime = [TimeUtil formatDate:user.timeCreate format:@"yyyy-MM-dd"];
  306. NSString *endTime= [TimeUtil formatDate:[NSDate date] format:@"yyyy-MM-dd"];;
  307. NSString *chaDay=[self intervalFromLastDate:strtime toTheDate:endTime];
  308. if ([chaDay isEqualToString:@"0"]||[chaDay isEqualToString:@"1"]||[chaDay isEqualToString:@"2"]||[chaDay isEqualToString:@"3"]) {
  309. [_dataArrTime addObject:user];
  310. [_array removeObjectAtIndex:0];
  311. }else{
  312. *stop = YES;
  313. }
  314. }];
  315. [_wait stop];
  316. [_table reloadData];
  317. }
  318. - (NSString *)intervalFromLastDate: (NSString *) dateString1 toTheDate:(NSString *) dateString2
  319. {
  320. NSDateFormatter *date=[[NSDateFormatter alloc] init];
  321. [date setDateFormat:@"yyyy-MM-dd"];
  322. NSDate *d1=[date dateFromString:dateString1];
  323. NSTimeInterval late1=[d1 timeIntervalSince1970]*1;
  324. NSDate *d2=[date dateFromString:dateString2];
  325. NSTimeInterval late2=[d2 timeIntervalSince1970]*1;
  326. NSTimeInterval cha=late2-late1;
  327. NSString *timeString=@"";
  328. NSString *house=@"";
  329. NSString *min=@"";
  330. NSString *sen=@"";
  331. sen = [NSString stringWithFormat:@"%d", (int)cha%60];
  332. sen=[NSString stringWithFormat:@"%@", sen];
  333. min = [NSString stringWithFormat:@"%d", (int)cha/60%60];
  334. min=[NSString stringWithFormat:@"%@", min];
  335. house = [NSString stringWithFormat:@"%d", (int)cha/3600];
  336. house=[NSString stringWithFormat:@"%@", house];
  337. NSString *dayDD=[NSString stringWithFormat:@"%d", (int)cha/3600/24];
  338. timeString=[NSString stringWithFormat:@"差小时:%@-----分:%@------秒:%@",house,min,sen];
  339. return dayDD;
  340. }
  341. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  342. {
  343. return 84;
  344. }
  345. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
  346. return NO;
  347. }
  348. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  349. NSLog(@"%ld",indexPath.row);
  350. JXFriendObject *user = _array[indexPath.row];
  351. [_array removeObjectAtIndex:indexPath.row];
  352. [user delete];
  353. [_table reloadData];
  354. }
  355. -(void)scrollToPageUp{
  356. [self refresh];
  357. }
  358. -(void)onSendTimeout:(NSNotification *)notifacation//超时未收到回执
  359. {
  360. [_wait stop];
  361. JXMessageObject *msg = (JXMessageObject *)notifacation.object;
  362. if(msg==nil)
  363. return;
  364. JXFriendCell* cell = [poolCell objectForKey:msg.messageId];
  365. if(cell){
  366. // [g_App showAlert:Localized(@"JXAlert_SendFilad")];
  367. [JXMyTools showTipView:Localized(@"JXAlert_SendFilad")];
  368. [poolCell removeObjectForKey:msg.messageId];
  369. }
  370. }
  371. -(void)newRequest:(NSNotification *)notifacation{//新推送
  372. // NSLog(@"newRequest");
  373. JXFriendObject *user = (JXFriendObject *)notifacation.object;
  374. if(user == nil)
  375. return;
  376. // if(_wait.isShowing)//正在等待,就不刷新
  377. // return;
  378. for(int i=0;i<[_array count];i++){
  379. JXFriendObject* friend = [_array objectAtIndex:i];
  380. if([friend.userId isEqualToString:user.userId]){
  381. [friend loadFromObject:user];
  382. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
  383. JXFriendCell* cell = (JXFriendCell*)[_table cellForRowAtIndexPath:indexPath];
  384. [cell update];
  385. cell = nil;
  386. return;
  387. }
  388. friend = nil;
  389. }
  390. NSMutableArray *arrxx=[[NSMutableArray alloc]initWithArray:[SaveOrReadArr initNSKeyedFriendUnarchiver]];
  391. //本地存储
  392. [arrxx addObject:user];
  393. [SaveOrReadArr initSerializationFriendArray:arrxx];
  394. //加好友
  395. [_wait stop];
  396. // [g_notify postNotificationName:@"newFriend" object:nil userInfo:@{@"use":user}];
  397. [self refresh];
  398. [_wait stop];
  399. }
  400. -(void)onSayHello:(UIButton*)sender{//打招呼
  401. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:sender.tag inSection:0];
  402. _cell = (JXFriendCell*)[_table cellForRowAtIndexPath:indexPath];
  403. JXInputVC* vc = [JXInputVC alloc];
  404. vc.delegate = self;
  405. vc.didTouch = @selector(onInputHello:);
  406. vc.inputText = Localized(@"JXNewFriendVC_Iam");
  407. vc = [vc init];
  408. [g_window addSubview:vc.view];
  409. }
  410. -(void)onInputHello:(JXInputVC*)sender{
  411. NSString* messageId = [_cell.user doSendMsg:XMPP_TYPE_SAYHELLO content:sender.inputText];
  412. [poolCell setObject:_cell forKey:messageId];
  413. /// [_wait start:nil]; 修改了
  414. }
  415. -(void)onFeedback:(UIButton*)sender{//回话
  416. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:sender.tag inSection:0];
  417. _cell = (JXFriendCell*)[_table cellForRowAtIndexPath:indexPath];
  418. JXInputVC* vc = [JXInputVC alloc];
  419. vc.delegate = self;
  420. vc.didTouch = @selector(onInputReply:);
  421. vc.inputText = Localized(@"JXNewFriendVC_Who");
  422. vc = [vc init];
  423. [g_window addSubview:vc.view];
  424. }
  425. -(void)onInputReply:(JXInputVC*)sender{
  426. NSString* messageId = [_cell.user doSendMsg:XMPP_TYPE_FEEDBACK content:sender.inputText];
  427. [poolCell setObject:_cell forKey:messageId];
  428. [_wait start:nil];
  429. }
  430. -(void)onSeeHim:(UIButton*)sender{//关注他
  431. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:sender.tag inSection:0];
  432. JXFriendCell* cell = (JXFriendCell*)[_table cellForRowAtIndexPath:indexPath];
  433. NSString* messageId = [cell.user doSendMsg:XMPP_TYPE_NEWSEE content:nil];
  434. [poolCell setObject:cell forKey:messageId];
  435. [_wait start:nil];
  436. }
  437. /**
  438. * ti添加朋友
  439. */
  440. -(void)onAddFriend:(UIButton*)sender{//加好友
  441. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:sender.tag inSection:0];
  442. _cell = (JXFriendCell*)[_table cellForRowAtIndexPath:indexPath];
  443. _user = _cell.user;
  444. [g_server addAttention:_user.userId fromAddType:0 toView:self];
  445. }
  446. -(void)actionQuit{
  447. [self free];
  448. [super actionQuit];
  449. }
  450. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  451. [_wait stop];
  452. if([aDownload.action isEqualToString:act_AttentionAdd]){
  453. int n = [[dict objectForKey:@"type"] intValue];
  454. if( n==2 || n==4)
  455. _friendStatus = 2;
  456. // else
  457. // _friendStatus = 1;
  458. if(_friendStatus == 2){
  459. NSString* messageId = [_user doSendMsg:XMPP_TYPE_PASS content:nil];
  460. [poolCell setObject:_cell forKey:messageId];
  461. //[_wait start:nil]; 修改了
  462. messageId = nil;
  463. }
  464. }
  465. //点击好友头像响应
  466. if( [aDownload.action isEqualToString:act_UserGet] ){
  467. JXUserObject* user = [[JXUserObject alloc]init];
  468. [user getDataFromDict:dict];
  469. JXUserInfoVC* vc = [JXUserInfoVC alloc];
  470. vc.user = user;
  471. vc.fromAddType = 6;
  472. // vc.isJustShow = YES;
  473. vc = [vc init];
  474. // [g_window addSubview:vc.view];
  475. [g_navigation pushViewController:vc animated:YES];
  476. // [self cancelBtnAction];
  477. }
  478. }
  479. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  480. [_wait stop];
  481. return show_error;
  482. }
  483. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  484. [_wait stop];
  485. return show_error;
  486. }
  487. -(void) didServerConnectStart:(JXConnection*)aDownload{
  488. // [_wait start]; 修改了
  489. }
  490. -(void)newReceipt:(NSNotification *)notifacation{//新回执
  491. // NSLog(@"newReceipt");
  492. [_wait stop];
  493. JXMessageObject *msg = (JXMessageObject *)notifacation.object;
  494. if(msg == nil)
  495. return;
  496. if(![msg isAddFriendMsg])
  497. return;
  498. if(![msg.toUserId isEqualToString:_cell.user.userId])
  499. return;
  500. if([msg.type intValue] == XMPP_TYPE_PASS){//通过
  501. _friendStatus = friend_status_friend;
  502. _user.status = [NSNumber numberWithInt:_friendStatus];
  503. [_user update];
  504. JXMessageObject *msg=[[JXMessageObject alloc] init];
  505. msg.type = [NSNumber numberWithInt:kWCMessageTypeText];
  506. msg.toUserId = _user.userId;
  507. msg.fromUserId = MY_USER_ID;
  508. msg.fromUserName = g_server.myself.userNickname;
  509. msg.content = Localized(@"JXFriendObject_StartChat");
  510. msg.timeSend = [NSDate date];
  511. [msg insert:nil];
  512. [msg updateLastSend:UpdateLastSendType_None];
  513. [msg notifyNewMsg];
  514. }
  515. JXFriendCell* cell = [poolCell objectForKey:msg.messageId];
  516. if(cell){
  517. [cell.user loadFromMessageObj:msg];
  518. [cell update];
  519. [g_App showAlert:Localized(@"JXAlert_SendOK")];
  520. [poolCell removeObjectForKey:msg.messageId];
  521. }
  522. // [g_notify postNotificationName:@"newFriend" object:nil userInfo:@{@"use":_user}];
  523. }
  524. @end