XMGMainViewController.m 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. //
  2. // XMGMainViewController.m
  3. // 备课-百思不得姐
  4. //
  5. // Created by MJ Lee on 15/6/15.
  6. // Copyright © 2015年 小码哥. All rights reserved.
  7. // 20200714
  8. #import "XMGMainViewController.h"
  9. #import "JXMsgViewController.h"
  10. #import "CYWebAddPointVC.h"
  11. #import "XMGNavigationViewController.h"
  12. #import "MJTabBar.h"
  13. #import "JXXMGMyVc.h"
  14. #import "JXBigReelVc.h"
  15. #import "JXWellBeingVc.h"
  16. #import "JXTabMenuView.h"
  17. #import "JXFriendViewController.h"
  18. #import "AppDelegate.h"
  19. #import "JXNewFriendViewController.h"
  20. #import "JXFriendObject.h"
  21. #import "PSMyViewController.h"
  22. #ifdef Live_Version
  23. #import "JXLiveViewController.h"
  24. #endif
  25. #import "JXProgressVC.h"
  26. #import "JXGroupViewController.h"
  27. #import "OrganizTreeViewController.h"
  28. #import "JXLabelObject.h"
  29. #import "JXBlogRemind.h"
  30. #import "JXRoomPool.h"
  31. #import "JXDeviceAuthController.h"
  32. #import "UIColor+Util.h"
  33. #import "UIColor+XQColor.h"
  34. #import "JXLabelObject.h"
  35. #import "JXDeviceAuthController.h"
  36. #import "JXProgressVC.h"
  37. #import "JXBlogRemind.h"
  38. #import "JXBigReelVc.h"
  39. #import "JXShowMainView.h"
  40. #import "JXNewRegisterVc.h"
  41. @interface XMGMainViewController ()
  42. @end
  43. @implementation XMGMainViewController
  44. -(instancetype)init{
  45. if (self=[super init]) {
  46. [g_notify addObserver:self selector:@selector(loginSynchronizeFriends:) name:kXmppClickLoginNotifaction object:nil];
  47. [g_notify addObserver:self selector:@selector(appDidEnterForeground) name:kApplicationWillEnterForeground object:nil];
  48. [g_notify addObserver:self selector:@selector(getUserInfo:) name:kXMPPMessageUpadteUserInfoNotification object:nil];
  49. [g_notify addObserver:self selector:@selector(getRoomSet:) name:kXMPPMessageUpadteGroupNotification object:nil];
  50. [g_notify addObserver:self selector:@selector(onXmppLoginChanged:) name:kXmppLoginNotifaction object:nil];
  51. [g_notify addObserver:self selector:@selector(hasLoginOther:) name:kXMPPLoginOtherNotification object:nil];
  52. [g_notify addObserver:self selector:@selector(showDeviceAuth:) name:kDeviceAuthNotification object:nil];
  53. }
  54. return self;
  55. }
  56. - (void)viewDidLoad {
  57. [super viewDidLoad];
  58. [self initViewControllers];
  59. self.tabBar.backgroundColor = [UIColor whiteColor];
  60. //NSLog(@"login_%@",g_server.myself.userId);
  61. // [g_server getUser:g_server.myself.userId toView:self];
  62. }
  63. - (void)viewDidAppear:(BOOL)animated {
  64. }
  65. - (void)didReceiveMemoryWarning {
  66. [super didReceiveMemoryWarning];
  67. }
  68. - (void)initViewControllers {
  69. JXMsgViewController *controller1 = [[JXMsgViewController alloc] init];
  70. XMGOpenGLNavVc *nav1 = [[XMGOpenGLNavVc alloc] initWithRootViewController:controller1];
  71. nav1.yp_tabItemTitle = @"主页";
  72. JXWellBeingVc *controller2 = [[JXWellBeingVc alloc] init];
  73. controller2.yp_tabItemTitle = @"福利";
  74. JXXMGMyVc *controller3 = [[JXXMGMyVc alloc] init];
  75. controller3.yp_tabItemTitle = @"我";
  76. self.viewControllers = [NSMutableArray arrayWithObjects:nav1, controller2, controller3, nil];
  77. }
  78. - (void)appEnterForegroundNotif:(NSNotification *)noti {
  79. [g_server offlineOperation:(g_server.lastOfflineTime *1000 + g_server.timeDifference)/1000 toView:self];
  80. }
  81. - (void)getUserInfo:(NSNotification *)noti {
  82. JXMessageObject *msg = noti.object;
  83. [g_server getUser:msg.toUserId toView:self];
  84. }
  85. - (void)getRoomSet:(NSNotification *)noti {
  86. JXMessageObject *msg = noti.object;
  87. [g_server getRoom:msg.toUserId toView:self];
  88. }
  89. -(void)dealloc{
  90. // [_psMyviewVC.view release];
  91. // [_msgVc.view release];
  92. [g_notify removeObserver:self name:kXmppLoginNotifaction object:nil];
  93. [g_notify removeObserver:self name:kSystemLoginNotifaction object:nil];
  94. [g_notify removeObserver:self name:kXmppClickLoginNotifaction object:nil];
  95. [g_notify removeObserver:self name:kXMPPLoginOtherNotification object:nil];
  96. [g_notify removeObserver:self name:kApplicationWillEnterForeground object:nil];
  97. [g_notify removeObserver:self name:kXMPPMessageUpadteUserInfoNotification object:nil];
  98. [g_notify removeObserver:self name:kDeviceAuthNotification object:nil];
  99. // [super dealloc];
  100. }
  101. - (void)appDidEnterForeground {
  102. // 获取服务器时间
  103. [g_server getCurrentTimeToView:self];
  104. }
  105. - (void)loginSynchronizeFriends:(NSNotification*)notification{
  106. //判断服务器好友数量是否与本地一致
  107. // _friendArray = [g_server.myself fetchAllFriendsOrNotFromLocal];
  108. // og(@"%d -------%ld",[g_server.myself.friendCount intValue] , [_friendArray count]);
  109. // if ([g_server.myself.friendCount intValue] > [_friendArray count] && [g_server.myself.friendCount intValue] >0) {
  110. // [g_App showAlert:Localized(@"JXAlert_SynchFirendOK") delegate:self];
  111. if (self.isLoadFriendAndGroup) {
  112. [g_server listAttention:0 userId:MY_USER_ID toView:self];
  113. }else{
  114. [[JXXMPP sharedInstance] performSelector:@selector(login) withObject:nil afterDelay:2];//2秒后执行xmpp登录
  115. }
  116. [[JXXMPP sharedInstance] performSelector:@selector(login) withObject:nil afterDelay:2];//2秒后执行xmpp登录
  117. // }
  118. }
  119. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
  120. if (alertView.tag == 10002) {
  121. [g_server performSelector:@selector(showLogin) withObject:nil afterDelay:0.5];
  122. return;
  123. }else if (buttonIndex == 1) {
  124. [g_server listAttention:0 userId:MY_USER_ID toView:self];
  125. }
  126. }
  127. -(void)buildTop{
  128. ///NSMutableArray *remindArray = [[JXBlogRemind sharedInstance] doFetchUnread];
  129. }
  130. -(void)actionSegment:(UIButton*)sender{
  131. //[self doSelected:(int)sender.tag];
  132. }
  133. -(void)onXmppLoginChanged:(NSNumber*)isLogin{
  134. if([JXXMPP sharedInstance].isLogined == login_status_yes){
  135. // 获取离线调用接口列表
  136. [g_server offlineOperation:(g_server.lastOfflineTime *1000 + g_server.timeDifference)/1000 toView:self];
  137. [self onAfterLogin];
  138. }
  139. }
  140. -(void)onAfterLogin{
  141. // [_msgVc scrollToPageUp];
  142. }
  143. -(void)hasLoginOther:(NSNotification *)notifcation{
  144. [g_App showAlert:Localized(@"JXXMPP_Other") delegate:self tag:10002 onlyConfirm:YES];
  145. }
  146. - (void)showDeviceAuth:(NSNotification *)notification{
  147. JXMessageObject *msg = notification.object;
  148. JXDeviceAuthController *authCon = [[JXDeviceAuthController alloc] initWithMsg:msg];
  149. UIViewController *lastVC = (UIViewController *)g_navigation.subViews.lastObject;
  150. [lastVC presentViewController:authCon animated:YES completion:nil];
  151. }
  152. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  153. //更新本地好友
  154. if ([aDownload.action isEqualToString:act_UserGet]) {
  155. NSString *memberAcc= dict[@"membershipAccount"];
  156. [[NSUserDefaults standardUserDefaults] setObject:memberAcc forKey:@"membershipAccount_ID"];
  157. [[NSUserDefaults standardUserDefaults] synchronize];
  158. }
  159. if ([aDownload.action isEqualToString:act_AttentionList]) {
  160. JXProgressVC * pv = [JXProgressVC alloc];
  161. pv.dataArray = array1;
  162. pv = [pv init];
  163. if (array1.count > 300) {
  164. [g_navigation pushViewController:pv animated:YES];
  165. }
  166. // [self.view addSubview:pv.view];
  167. }
  168. // 同步标签
  169. if ([aDownload.action isEqualToString:act_FriendGroupList]) {
  170. for (NSInteger i = 0; i < array1.count; i ++) {
  171. NSDictionary *dict = array1[i];
  172. JXLabelObject *labelObj = [[JXLabelObject alloc] init];
  173. labelObj.groupId = dict[@"groupId"];
  174. labelObj.groupName = dict[@"groupName"];
  175. labelObj.userId = dict[@"userId"];
  176. NSArray *userIdList = dict[@"userIdList"];
  177. NSString *userIdListStr = [userIdList componentsJoinedByString:@","];
  178. if (userIdListStr.length > 0) {
  179. labelObj.userIdList = [NSString stringWithFormat:@"%@", userIdListStr];
  180. }
  181. [labelObj insert];
  182. }
  183. // 删除服务器上已经删除的
  184. NSArray *arr = [[JXLabelObject sharedInstance] fetchAllLabelsFromLocal];
  185. for (NSInteger i = 0; i < arr.count; i ++) {
  186. JXLabelObject *locLabel = arr[i];
  187. BOOL flag = NO;
  188. for (NSInteger j = 0; j < array1.count; j ++) {
  189. NSDictionary * dict = array1[j];
  190. if ([locLabel.groupId isEqualToString:dict[@"groupId"]]) {
  191. flag = YES;
  192. break;
  193. }
  194. }
  195. if (!flag) {
  196. [locLabel delete];
  197. }
  198. }
  199. }
  200. if ([aDownload.action isEqualToString:act_offlineOperation]) {
  201. for (NSDictionary *dict in array1) {
  202. if ([[dict objectForKey:@"tag"] isEqualToString:@"label"]) {
  203. [g_notify postNotificationName:kOfflineOperationUpdateLabelList object:nil];
  204. }
  205. else if ([[dict objectForKey:@"tag"] isEqualToString:@"friend"]) {
  206. [g_server getUser:[dict objectForKey:@"friendId"] toView:self];
  207. }
  208. else if ([[dict objectForKey:@"tag"] isEqualToString:@"room"]) {
  209. [g_server getRoom:[dict objectForKey:@"friendId"] toView:self];
  210. }
  211. }
  212. }
  213. if ([aDownload.action isEqualToString:act_UserGet]) {
  214. JXUserObject *user = [[JXUserObject alloc] init];
  215. [user getDataFromDict:dict];
  216. NSString *gradeIndexcc= dict[@"gradeIndex"];
  217. [[NSUserDefaults standardUserDefaults] setObject:gradeIndexcc forKey:@"gradeIndexcc"];
  218. [[NSUserDefaults standardUserDefaults] synchronize];
  219. if ([user.userId intValue] == [MY_USER_ID intValue]) {
  220. [g_server doSaveUser:dict];
  221. user.bubbleFontId = [dict objectForKey:@"bubbleFontId"];
  222. user.gradeIndex = [dict objectForKey:@"gradeIndex"];
  223. // 保存自己
  224. [user insert];
  225. [user update];
  226. }else {
  227. JXUserObject *user1 = [[JXUserObject sharedInstance] getUserById:user.userId];
  228. user.content = user1.content;
  229. user.timeSend = user1.timeSend;
  230. [user update];
  231. }
  232. [g_notify postNotificationName:kOfflineOperationUpdateUserSet object:user];
  233. }
  234. if ([aDownload.action isEqualToString:act_roomGet]) {
  235. JXUserObject *user = [[JXUserObject alloc] init];
  236. [user getDataFromDict:dict];
  237. user.userId = [dict objectForKey:@"jid"];
  238. user.roomId = [dict objectForKey:@"id"];
  239. user.userNickname = [dict objectForKey:@"name"];
  240. if(![g_xmpp.roomPool getRoom:user.userId] || ![user haveTheUser]){
  241. user.userDescription = [dict objectForKey:@"desc"];
  242. user.showRead = [dict objectForKey:@"showRead"];
  243. user.showMember = [dict objectForKey:@"showMember"];
  244. user.allowSendCard = [dict objectForKey:@"allowSendCard"];
  245. user.chatRecordTimeOut = [dict objectForKey:@"chatRecordTimeOut"];
  246. user.talkTime = [dict objectForKey:@"talkTime"];
  247. user.allowInviteFriend = [dict objectForKey:@"allowInviteFriend"];
  248. user.allowUploadFile = [dict objectForKey:@"allowUploadFile"];
  249. user.allowConference = [dict objectForKey:@"allowConference"];
  250. user.allowSpeakCourse = [dict objectForKey:@"allowSpeakCourse"];
  251. user.offlineNoPushMsg = [(NSDictionary *)[dict objectForKey:@"member"] objectForKey:@"offlineNoPushMsg"];
  252. user.isNeedVerify = [dict objectForKey:@"isNeedVerify"];
  253. user.createUserId = [dict objectForKey:@"userId"];
  254. user.content = @" ";
  255. user.topTime = nil;
  256. [user insertRoom];
  257. // [g_xmpp.roomPool joinRoom:user.userId title:user.userNickname lastDate:nil isNew:NO];
  258. }else {
  259. NSDictionary * groupDict = [user toDictionary];
  260. roomData * roomdata = [[roomData alloc] init];
  261. [roomdata getDataFromDict:groupDict];
  262. [roomdata getDataFromDict:dict];
  263. JXUserObject *user1 = [[JXUserObject sharedInstance] getUserById:roomdata.roomJid];
  264. user.content = user1.content;
  265. user.status = user1.status;
  266. user.offlineNoPushMsg = [NSNumber numberWithBool:roomdata.offlineNoPushMsg];
  267. user.msgsNew = user1.msgsNew;
  268. [user update];
  269. }
  270. [g_notify postNotificationName:kOfflineOperationUpdateUserSet object:user];
  271. }
  272. }
  273. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  274. return hide_error;
  275. }
  276. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  277. return hide_error;
  278. }
  279. @end