JXDidPushObj.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. //
  2. // JXDidPushObj.m
  3. // shiku_im
  4. //
  5. // Created by p on 2019/5/14.
  6. // Copyright © 2019年 Reese. All rights reserved.
  7. //
  8. #import "JXDidPushObj.h"
  9. #import "WeiboViewControlle.h"
  10. #import "JXNewFriendViewController.h"
  11. #import "JXMsgViewController.h"
  12. #import "JXTransferNoticeVC.h"
  13. #import "JXChatViewController.h"
  14. #import "JXRoomPool.h"
  15. #import "JXFriendViewController.h"
  16. @implementation JXDidPushObj
  17. static JXDidPushObj *shared;
  18. +(JXDidPushObj*)sharedInstance{
  19. static dispatch_once_t onceToken;
  20. dispatch_once(&onceToken, ^{
  21. shared=[[JXDidPushObj alloc]init];
  22. });
  23. return shared;
  24. }
  25. - (instancetype)init {
  26. if ([super init]) {
  27. [g_notify addObserver:self selector:@selector(onLoginChanged:) name:kXmppLoginNotifaction object:nil];//登录状态变化了
  28. }
  29. return self;
  30. }
  31. -(void)onLoginChanged:(NSNotification *)notifacation{
  32. switch ([JXXMPP sharedInstance].isLogined){
  33. case login_status_ing:{
  34. }
  35. break;
  36. case login_status_no:{
  37. }
  38. break;
  39. case login_status_yes:{
  40. [self didReceiveRemoteNotif];
  41. }
  42. break;
  43. }
  44. }
  45. // 点击推送
  46. - (void)didReceiveRemoteNotif {
  47. NSDictionary *dict = [g_default objectForKey:kDidReceiveRemoteDic];
  48. if (!dict) {
  49. return;
  50. }
  51. [g_default setObject:nil forKey:kDidReceiveRemoteDic];
  52. [g_default synchronize];
  53. NSString *url = [dict objectForKey:@"url"];
  54. if (url.length > 0) {
  55. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
  56. return;
  57. }
  58. [g_navigation popToRootViewController];
  59. if ([[dict objectForKey:@"messageType"] intValue] == kWCMessageTypeWeiboPraise || [[dict objectForKey:@"messageType"] intValue] == kWCMessageTypeWeiboComment || [[dict objectForKey:@"messageType"] intValue] == kWCMessageTypeWeiboRemind) {
  60. [g_mainVC doSelected:2];
  61. WeiboViewControlle *weiboVC = [WeiboViewControlle alloc];
  62. weiboVC.user = g_server.myself;
  63. weiboVC = [weiboVC init];
  64. [g_navigation pushViewController:weiboVC animated:YES];
  65. return;
  66. }
  67. if ([[dict objectForKey:@"messageType"] intValue]/100==5) {
  68. [g_mainVC doSelected:1];
  69. // 清空角标
  70. JXMsgAndUserObject* newobj = [[JXMsgAndUserObject alloc]init];
  71. newobj.user = [[JXUserObject sharedInstance] getUserById:FRIEND_CENTER_USERID];
  72. newobj.message = [[JXMessageObject alloc] init];
  73. newobj.message.toUserId = FRIEND_CENTER_USERID;
  74. newobj.user.msgsNew = [NSNumber numberWithInt:0];
  75. [newobj.message updateNewMsgsTo0];
  76. NSArray *friends = [[JXFriendObject sharedInstance] fetchAllFriendsFromLocal];
  77. for (NSInteger i = 0; i < friends.count; i ++) {
  78. JXFriendObject *friend = friends[i];
  79. if ([friend.msgsNew integerValue] > 0) {
  80. [friend updateNewMsgUserId:friend.userId num:0];
  81. [friend updateNewFriendLastContent];
  82. }
  83. }
  84. [g_mainVC.friendVC showNewMsgCount:0];
  85. JXNewFriendViewController* vc = [[JXNewFriendViewController alloc]init];
  86. [g_navigation pushViewController:vc animated:YES];
  87. return;
  88. }
  89. [g_mainVC doSelected:0];
  90. // NSDictionary *dict = notif.object;
  91. NSString *userId = [dict objectForKey:@"from"];
  92. if ([dict objectForKey:@"roomJid"]) {
  93. userId = [dict objectForKey:@"roomJid"];
  94. }
  95. JXUserObject *user = [[JXUserObject sharedInstance] getUserById:userId];
  96. if (user) {
  97. [self jumpToChatViewVC:user];
  98. }else {
  99. if ([dict objectForKey:@"roomJid"]) {
  100. NSString *roomId = [dict objectForKey:@"roomId"];
  101. [g_server getRoom:roomId toView:self];
  102. }else {
  103. [g_server getUser:userId toView:self];
  104. }
  105. }
  106. }
  107. - (void)jumpToChatViewVC:(JXUserObject *)user {
  108. JXMessageObject *p=[[JXMessageObject alloc]init];
  109. // [p fromRs:rs];
  110. p.content = user.content;
  111. p.type = user.type;
  112. p.timeSend = user.timeSend;
  113. p.fromUserId = user.userId;
  114. p.toUserId = MY_USER_ID;
  115. // JXMsgAndUserObject *p=[array objectAtIndex:indexPath.row];
  116. if (![user.userId isEqualToString:FRIEND_CENTER_USERID]) {
  117. g_mainVC.msgVc.msgTotal -= [user.msgsNew intValue];
  118. }
  119. [UIApplication sharedApplication].applicationIconBadgeNumber = [UIApplication sharedApplication].applicationIconBadgeNumber - [user.msgsNew intValue];
  120. // [g_server userChangeMsgNum:[UIApplication sharedApplication].applicationIconBadgeNumber toView:self];
  121. if([user.userId isEqualToString:FRIEND_CENTER_USERID]){
  122. JXNewFriendViewController* vc = [[JXNewFriendViewController alloc]init];
  123. // [g_App.window addSubview:vc.view];
  124. [g_navigation pushViewController:vc animated:YES];
  125. return;
  126. }
  127. if ([user.userId intValue] == [SHIKU_TRANSFER intValue]) {
  128. JXTransferNoticeVC *noticeVC = [[JXTransferNoticeVC alloc] init];
  129. [g_navigation pushViewController:noticeVC animated:YES];
  130. user.msgsNew = [NSNumber numberWithInt:0];
  131. [p updateNewMsgsTo0];
  132. [g_mainVC.msgVc getTotalNewMsgCount];
  133. return;
  134. }
  135. JXChatViewController *sendView=[JXChatViewController alloc];
  136. // sendView.scrollLine = lineNum;
  137. sendView.title = user.remarkName.length > 0 ? user.remarkName : user.userNickname;
  138. if([user.roomFlag intValue] > 0 || user.roomId.length > 0){
  139. // if(g_xmpp.isLogined != 1){
  140. // // 掉线后点击title重连
  141. // [g_xmpp showXmppOfflineAlert];
  142. // return;
  143. // }
  144. sendView.roomJid = user.userId;
  145. sendView.roomId = user.roomId;
  146. sendView.groupStatus = user.groupStatus;
  147. if ([user.groupStatus intValue] == 0) {
  148. sendView.chatRoom = [[JXXMPP sharedInstance].roomPool joinRoom:user.userId title:user.userNickname lastDate:nil isNew:NO];
  149. }
  150. if (user.roomFlag || user.roomId.length > 0) {
  151. NSDictionary * groupDict = [user toDictionary];
  152. roomData * roomdata = [[roomData alloc] init];
  153. [roomdata getDataFromDict:groupDict];
  154. sendView.room = roomdata;
  155. sendView.newMsgCount = [user.msgsNew intValue];
  156. user.isAtMe = [NSNumber numberWithInt:0];
  157. [user updateIsAtMe];
  158. }
  159. }
  160. // sendView.rowIndex = indexPath.row;
  161. sendView.lastMsg = p;
  162. sendView.chatPerson = user;
  163. sendView = [sendView init];
  164. // [g_App.window addSubview:sendView.view];
  165. [g_navigation pushViewController:sendView animated:YES];
  166. sendView.view.hidden = NO;
  167. user.msgsNew = [NSNumber numberWithInt:0];
  168. [p updateNewMsgsTo0];
  169. [g_mainVC.msgVc cancelBtnAction];
  170. [g_mainVC.msgVc getTotalNewMsgCount];
  171. }
  172. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  173. if([aDownload.action isEqualToString:act_roomGet]){
  174. JXUserObject* user = [[JXUserObject alloc]init];
  175. user.userNickname = [dict objectForKey:@"name"];
  176. user.userId = [dict objectForKey:@"jid"];
  177. user.userDescription = [dict objectForKey:@"desc"];
  178. user.roomId = [dict objectForKey:@"id"];
  179. user.showRead = [dict objectForKey:@"showRead"];
  180. user.showMember = [dict objectForKey:@"showMember"];
  181. user.allowSendCard = [dict objectForKey:@"allowSendCard"];
  182. user.chatRecordTimeOut = [NSString stringWithFormat:@"%@", [dict objectForKey:@"chatRecordTimeOut"]];
  183. user.offlineNoPushMsg = [(NSDictionary *)[dict objectForKey:@"member"] objectForKey:@"offlineNoPushMsg"];
  184. user.talkTime = [dict objectForKey:@"talkTime"];
  185. user.allowInviteFriend = [dict objectForKey:@"allowInviteFriend"];
  186. user.allowUploadFile = [dict objectForKey:@"allowUploadFile"];
  187. user.allowConference = [dict objectForKey:@"allowConference"];
  188. user.allowSpeakCourse = [dict objectForKey:@"allowSpeakCourse"];
  189. user.category = [dict objectForKey:@"category"];
  190. user.createUserId = [dict objectForKey:@"userId"];
  191. user.timeCreate = [NSDate dateWithTimeIntervalSince1970:[[dict objectForKey:@"createTime"] longLongValue]];
  192. user.isNeedVerify = [dict objectForKey:@"isNeedVerify"];
  193. user.roomFlag= [NSNumber numberWithInt:1];
  194. user.companyId= [NSNumber numberWithInt:0];
  195. user.status= [NSNumber numberWithInt:2];
  196. user.offlineNoPushMsg = [NSNumber numberWithInt:0];
  197. user.isAtMe = [NSNumber numberWithInt:0];
  198. if(!user.timeCreate)
  199. user.timeCreate = [NSDate date];
  200. if(!user.timeSend)
  201. user.timeSend = [NSDate date];
  202. [self jumpToChatViewVC:user];
  203. }
  204. if( [aDownload.action isEqualToString:act_UserGet] ){
  205. JXUserObject* user = [[JXUserObject alloc]init];
  206. [user getDataFromDict:dict];
  207. [self jumpToChatViewVC:user];
  208. }
  209. }
  210. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  211. return hide_error;
  212. }
  213. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  214. return hide_error;
  215. }
  216. -(void) didServerConnectStart:(JXConnection*)aDownload{
  217. }
  218. @end