JXSearchGroupVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. //
  2. // JXSearchGroupVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2019/4/1.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXSearchGroupVC.h"
  9. #import "JXCell.h"
  10. #import "JXRoomPool.h"
  11. #import "JXRoomObject.h"
  12. #import "JXRoomRemind.h"
  13. #import "JXChatViewController.h"
  14. @interface JXSearchGroupVC ()
  15. @property (nonatomic, strong) NSMutableArray *array;
  16. @property (nonatomic, strong) JXRoomObject *chatRoom;
  17. @property (assign,nonatomic) NSInteger sel;
  18. @property (nonatomic, copy) NSString *roomJid;
  19. @property (nonatomic, copy) NSString *roomUserId;
  20. @property (nonatomic, copy) NSString *roomUserName;
  21. @property (nonatomic, strong) JXInputRectView *inputRectView;
  22. @end
  23. @implementation JXSearchGroupVC
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. // Do any additional setup after loading the view.
  27. self.heightHeader = JX_SCREEN_TOP;
  28. self.heightFooter = 0;
  29. self.title = Localized(@"JX_ManyPerChat");
  30. //self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-JX_SCREEN_BOTTOM);
  31. self.isGotoBack = YES;
  32. [self createHeadAndFoot];
  33. _array = [NSMutableArray array];
  34. _page=0;
  35. [self getServerData];
  36. }
  37. -(void)getServerData{
  38. [g_server listRoom:_page roomName:self.searchName toView:self];
  39. }
  40. #pragma mark ---------tableView协议----------------
  41. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  42. {
  43. return 1;
  44. }
  45. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  46. {
  47. return _array.count;
  48. }
  49. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  50. {
  51. NSString* cellName = [NSString stringWithFormat:@"groupJXCell"];
  52. JXCell * cell = [tableView dequeueReusableCellWithIdentifier:cellName];
  53. NSDictionary *dataDict = _array[indexPath.row];
  54. if(cell==nil){
  55. cell = [[JXCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];;
  56. [_table addToPool:cell];
  57. }
  58. cell.delegate = self;
  59. // cell.didTouch = @selector(onHeadImage:);
  60. // [cell groupCellDataSet:dict indexPath:indexPath];
  61. NSTimeInterval t = [[dataDict objectForKey:@"createTime"] longLongValue];
  62. NSDate* d = [NSDate dateWithTimeIntervalSince1970:t];
  63. cell.index = (int)indexPath.row;
  64. // if (_selMenu == 0) {
  65. // cell.title = dataDict[@"name"];
  66. // }else
  67. cell.title = [NSString stringWithFormat:@"%@(%@%@)",dataDict[@"name"],dataDict[@"userSize"],Localized(@"JXLiveVC_countPeople")];
  68. // }
  69. cell.subtitle = [dataDict objectForKey:@"desc"];
  70. cell.bottomTitle = [TimeUtil formatDate:d format:@"MM-dd HH:mm"];
  71. cell.userId = [dataDict objectForKey:@"userId"];
  72. cell.headImageView.tag = (int)indexPath.row;
  73. cell.headImageView.delegate = self;
  74. // cell.headImageView.didTouch = @selector(onHeadImage:);
  75. [cell.lbTitle setText:cell.title];
  76. cell.lbTitle.tag = cell.index;
  77. [cell.lbSubTitle setText:cell.subtitle];
  78. [cell.timeLabel setText:cell.bottomTitle];
  79. cell.bageNumber.delegate = self;
  80. // bageNumber.didDragout = self.didDragout;
  81. cell.bage = cell.bage;
  82. NSString * roomIdStr = dataDict[@"id"];
  83. cell.roomId = roomIdStr;
  84. [cell headImageViewImageWithUserId:[dataDict objectForKey:@"roomId"] roomId:roomIdStr];
  85. cell.isSmall = NO;
  86. [self doAutoScroll:indexPath];
  87. return cell;
  88. }
  89. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  90. {
  91. [super tableView:tableView didSelectRowAtIndexPath:indexPath];
  92. if(g_xmpp.isLogined != 1){
  93. // 掉线后点击title重连
  94. // 判断XMPP是否在线 不在线重连
  95. [g_xmpp showXmppOfflineAlert];
  96. return;
  97. }
  98. _sel = indexPath.row;
  99. NSDictionary *dict = _array[indexPath.row];
  100. JXUserObject *user = [[JXUserObject sharedInstance] getUserById:[dict objectForKey:@"jid"]];
  101. if(user && [user.groupStatus intValue] == 0){
  102. _chatRoom = [[JXXMPP sharedInstance].roomPool joinRoom:[dict objectForKey:@"jid"] title:[dict objectForKey:@"name"] lastDate:nil isNew:YES];
  103. //老房间:
  104. [self showChatView];
  105. }else{
  106. BOOL isNeedVerify = [dict[@"isNeedVerify"] boolValue];
  107. long userId = [dict[@"userId"] longLongValue];
  108. if (isNeedVerify && userId != [g_myself.userId longLongValue]) {
  109. self.roomJid = [dict objectForKey:@"jid"];
  110. self.roomUserName = [dict objectForKey:@"nickname"];
  111. self.roomUserId = [dict objectForKey:@"userId"];
  112. self.inputRectView = [[JXInputRectView alloc] initWithFrame:self.view.bounds sureBtnTitle:Localized(@"JX_Send")];
  113. self.inputRectView.title = Localized(@"JX_GroupOwnersHaveEnabled");
  114. self.inputRectView.placeString = Localized(@"JX_PleaseEnterTheReason");
  115. self.inputRectView.delegate = self;
  116. self.inputRectView.onRelease = @selector(onInputHello);
  117. [g_window addSubview:self.inputRectView];
  118. }else {
  119. _chatRoom = [[JXXMPP sharedInstance].roomPool joinRoom:[dict objectForKey:@"jid"] title:[dict objectForKey:@"name"] lastDate:nil isNew:YES];
  120. [_wait start:Localized(@"JXAlert_AddRoomIng") delay:30];
  121. //新房间:
  122. _chatRoom.delegate = self;
  123. [_chatRoom joinRoom:YES];
  124. }
  125. }
  126. dict = nil;
  127. UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
  128. cell.selected = NO;
  129. }
  130. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  131. {
  132. return 68;
  133. }
  134. -(void)onInputHello{
  135. [self.inputRectView hide];
  136. JXMessageObject *msg = [[JXMessageObject alloc] init];
  137. msg.fromUserId = MY_USER_ID;
  138. msg.toUserId = [NSString stringWithFormat:@"%@", self.roomUserId];
  139. msg.fromUserName = MY_USER_NAME;
  140. msg.toUserName = self.roomUserName;
  141. msg.timeSend = [NSDate date];
  142. msg.type = [NSNumber numberWithInt:kRoomRemind_NeedVerify];
  143. msg.content = @"";
  144. NSString *userIds = g_myself.userId;
  145. NSString *userNames = g_myself.userNickname;
  146. NSDictionary *dict = @{
  147. @"userIds" : userIds,
  148. @"userNames" : userNames,
  149. @"roomJid" : self.roomJid,
  150. @"reason" : self.inputRectView.text,
  151. @"isInvite" : [NSNumber numberWithBool:YES]
  152. };
  153. NSError *error = nil;
  154. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
  155. NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  156. msg.objectId = jsonStr;
  157. [g_xmpp sendMessage:msg roomName:nil];
  158. // msg.fromUserId = self.roomJid;
  159. // msg.type = [NSNumber numberWithInt:kWCMessageTypeRemind];
  160. // msg.content = @"申请已发送给群主,请等待群主确认";
  161. // [msg insert:self.roomJid];
  162. // if ([self.delegate respondsToSelector:@selector(needVerify:)]) {
  163. // [self.delegate needVerify:msg];
  164. // }
  165. }
  166. -(void)xmppRoomDidJoin{
  167. NSDictionary *dict = _array[_sel];
  168. JXUserObject* user = [[JXUserObject alloc]init];
  169. user.userNickname = [dict objectForKey:@"name"];
  170. user.userId = [dict objectForKey:@"jid"];
  171. user.userDescription = [dict objectForKey:@"desc"];
  172. user.roomId = [dict objectForKey:@"id"];
  173. user.showRead = [dict objectForKey:@"showRead"];
  174. user.showMember = [dict objectForKey:@"showMember"];
  175. user.allowSendCard = [dict objectForKey:@"allowSendCard"];
  176. user.chatRecordTimeOut = [dict objectForKey:@"chatRecordTimeOut"];
  177. user.talkTime = [dict objectForKey:@"talkTime"];
  178. user.allowInviteFriend = [dict objectForKey:@"allowInviteFriend"];
  179. user.allowUploadFile = [dict objectForKey:@"allowUploadFile"];
  180. user.allowConference = [dict objectForKey:@"allowConference"];
  181. user.allowSpeakCourse = [dict objectForKey:@"allowSpeakCourse"];
  182. user.isNeedVerify = [dict objectForKey:@"isNeedVerify"];
  183. if (![user haveTheUser])
  184. [user insertRoom];
  185. // else
  186. // [user update];
  187. // [user release];
  188. // [g_server addRoomMember:[dict objectForKey:@"id"] userId:g_myself.userId nickName:g_myself.userNickname toView:self];
  189. [g_server roomJoin:[dict objectForKey:@"id"] userId:g_myself.userId nickName:g_myself.userNickname toView:self];
  190. dict = nil;
  191. _chatRoom.delegate = nil;
  192. [self showChatView];
  193. }
  194. -(void)startReconnect{
  195. for (int i = 0; i < [_array count]; i++) {
  196. NSDictionary *dict=_array[i];
  197. JXUserObject* user = [[JXUserObject alloc]init];
  198. user.userNickname = [dict objectForKey:@"name"];
  199. user.userId = [dict objectForKey:@"jid"];
  200. user.userDescription = [dict objectForKey:@"desc"];
  201. user.roomId = [dict objectForKey:@"id"];
  202. user.showRead = [dict objectForKey:@"showRead"];
  203. user.showMember = [dict objectForKey:@"showMember"];
  204. user.allowSendCard = [dict objectForKey:@"allowSendCard"];
  205. user.chatRecordTimeOut = [dict objectForKey:@"chatRecordTimeOut"];
  206. user.talkTime = [dict objectForKey:@"talkTime"];
  207. user.allowInviteFriend = [dict objectForKey:@"allowInviteFriend"];
  208. user.allowUploadFile = [dict objectForKey:@"allowUploadFile"];
  209. user.allowConference = [dict objectForKey:@"allowConference"];
  210. user.allowSpeakCourse = [dict objectForKey:@"allowSpeakCourse"];
  211. user.isNeedVerify = [dict objectForKey:@"isNeedVerify"];
  212. if (![user haveTheUser])
  213. [user insertRoom];
  214. else
  215. [user update];
  216. // [user release];
  217. [g_server addRoomMember:[dict objectForKey:@"id"] userId:g_myself.userId nickName:g_myself.userNickname toView:self];
  218. dict = nil;
  219. _chatRoom.delegate = nil;
  220. }
  221. }
  222. -(void)showChatView{
  223. [_wait stop];
  224. NSDictionary *dict = _array[_sel];
  225. roomData * roomdata = [[roomData alloc] init];
  226. [roomdata getDataFromDict:dict];
  227. JXChatViewController *sendView=[JXChatViewController alloc];
  228. sendView.title = [dict objectForKey:@"name"];
  229. sendView.roomJid = [dict objectForKey:@"jid"];
  230. sendView.roomId = [dict objectForKey:@"id"];
  231. sendView.chatRoom = _chatRoom;
  232. sendView.room = roomdata;
  233. JXUserObject * userObj = [[JXUserObject alloc]init];
  234. userObj.userId = [dict objectForKey:@"jid"];
  235. userObj.showRead = [dict objectForKey:@"showRead"];
  236. userObj.showMember = [dict objectForKey:@"showMember"];
  237. userObj.allowSendCard = [dict objectForKey:@"allowSendCard"];
  238. userObj.userNickname = [dict objectForKey:@"name"];
  239. userObj.chatRecordTimeOut = roomdata.chatRecordTimeOut;
  240. userObj.talkTime = [dict objectForKey:@"talkTime"];
  241. userObj.allowInviteFriend = [dict objectForKey:@"allowInviteFriend"];
  242. userObj.allowUploadFile = [dict objectForKey:@"allowUploadFile"];
  243. userObj.allowConference = [dict objectForKey:@"allowConference"];
  244. userObj.allowSpeakCourse = [dict objectForKey:@"allowSpeakCourse"];
  245. userObj.isNeedVerify = [dict objectForKey:@"isNeedVerify"];
  246. sendView.chatPerson = userObj;
  247. sendView = [sendView init];
  248. // [g_App.window addSubview:sendView.view];
  249. [g_navigation pushViewController:sendView animated:YES];
  250. dict = nil;
  251. }
  252. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  253. [_wait hide];
  254. [self stopLoading];
  255. if([aDownload.action isEqualToString:act_roomList]){
  256. self.isShowFooterPull = [array1 count]>=jx_page_size;
  257. if(_page == 0){
  258. [_array removeAllObjects];
  259. if([array1 count]>0)
  260. [_array addObjectsFromArray:array1];
  261. }
  262. [_table reloadData];
  263. }
  264. }
  265. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  266. [_wait hide];
  267. return show_error;
  268. }
  269. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  270. [_wait hide];
  271. return show_error;
  272. }
  273. -(void) didServerConnectStart:(JXConnection*)aDownload{
  274. [_wait start];
  275. }
  276. /*
  277. #pragma mark - Navigation
  278. // In a storyboard-based application, you will often want to do a little preparation before navigation
  279. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  280. // Get the new view controller using [segue destinationViewController].
  281. // Pass the selected object to the new view controller.
  282. }
  283. */
  284. @end