// // XMGMainViewController.m // 备课-百思不得姐 // // Created by MJ Lee on 15/6/15. // Copyright © 2015年 小码哥. All rights reserved. // 20200714 #import "XMGMainViewController.h" #import "JXMsgViewController.h" #import "CYWebAddPointVC.h" #import "XMGNavigationViewController.h" #import "MJTabBar.h" #import "JXXMGMyVc.h" #import "JXBigReelVc.h" #import "JXWellBeingVc.h" #import "JXTabMenuView.h" #import "JXFriendViewController.h" #import "AppDelegate.h" #import "JXNewFriendViewController.h" #import "JXFriendObject.h" #import "PSMyViewController.h" #ifdef Live_Version #import "JXLiveViewController.h" #endif #import "JXProgressVC.h" #import "JXGroupViewController.h" #import "OrganizTreeViewController.h" #import "JXLabelObject.h" #import "JXBlogRemind.h" #import "JXRoomPool.h" #import "JXDeviceAuthController.h" #import "UIColor+Util.h" #import "UIColor+XQColor.h" #import "JXLabelObject.h" #import "JXDeviceAuthController.h" #import "JXProgressVC.h" #import "JXBlogRemind.h" #import "JXBigReelVc.h" #import "JXShowMainView.h" #import "JXNewRegisterVc.h" @interface XMGMainViewController () @end @implementation XMGMainViewController -(instancetype)init{ if (self=[super init]) { [g_notify addObserver:self selector:@selector(loginSynchronizeFriends:) name:kXmppClickLoginNotifaction object:nil]; [g_notify addObserver:self selector:@selector(appDidEnterForeground) name:kApplicationWillEnterForeground object:nil]; [g_notify addObserver:self selector:@selector(getUserInfo:) name:kXMPPMessageUpadteUserInfoNotification object:nil]; [g_notify addObserver:self selector:@selector(getRoomSet:) name:kXMPPMessageUpadteGroupNotification object:nil]; [g_notify addObserver:self selector:@selector(onXmppLoginChanged:) name:kXmppLoginNotifaction object:nil]; [g_notify addObserver:self selector:@selector(hasLoginOther:) name:kXMPPLoginOtherNotification object:nil]; [g_notify addObserver:self selector:@selector(showDeviceAuth:) name:kDeviceAuthNotification object:nil]; } return self; } - (void)viewDidLoad { [super viewDidLoad]; [self initViewControllers]; self.tabBar.backgroundColor = [UIColor whiteColor]; //NSLog(@"login_%@",g_server.myself.userId); // [g_server getUser:g_server.myself.userId toView:self]; } - (void)viewDidAppear:(BOOL)animated { } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (void)initViewControllers { JXMsgViewController *controller1 = [[JXMsgViewController alloc] init]; XMGOpenGLNavVc *nav1 = [[XMGOpenGLNavVc alloc] initWithRootViewController:controller1]; nav1.yp_tabItemTitle = @"主页"; JXWellBeingVc *controller2 = [[JXWellBeingVc alloc] init]; controller2.yp_tabItemTitle = @"福利"; JXXMGMyVc *controller3 = [[JXXMGMyVc alloc] init]; controller3.yp_tabItemTitle = @"我"; self.viewControllers = [NSMutableArray arrayWithObjects:nav1, controller2, controller3, nil]; } - (void)appEnterForegroundNotif:(NSNotification *)noti { [g_server offlineOperation:(g_server.lastOfflineTime *1000 + g_server.timeDifference)/1000 toView:self]; } - (void)getUserInfo:(NSNotification *)noti { JXMessageObject *msg = noti.object; [g_server getUser:msg.toUserId toView:self]; } - (void)getRoomSet:(NSNotification *)noti { JXMessageObject *msg = noti.object; [g_server getRoom:msg.toUserId toView:self]; } -(void)dealloc{ // [_psMyviewVC.view release]; // [_msgVc.view release]; [g_notify removeObserver:self name:kXmppLoginNotifaction object:nil]; [g_notify removeObserver:self name:kSystemLoginNotifaction object:nil]; [g_notify removeObserver:self name:kXmppClickLoginNotifaction object:nil]; [g_notify removeObserver:self name:kXMPPLoginOtherNotification object:nil]; [g_notify removeObserver:self name:kApplicationWillEnterForeground object:nil]; [g_notify removeObserver:self name:kXMPPMessageUpadteUserInfoNotification object:nil]; [g_notify removeObserver:self name:kDeviceAuthNotification object:nil]; // [super dealloc]; } - (void)appDidEnterForeground { // 获取服务器时间 [g_server getCurrentTimeToView:self]; } - (void)loginSynchronizeFriends:(NSNotification*)notification{ //判断服务器好友数量是否与本地一致 // _friendArray = [g_server.myself fetchAllFriendsOrNotFromLocal]; // og(@"%d -------%ld",[g_server.myself.friendCount intValue] , [_friendArray count]); // if ([g_server.myself.friendCount intValue] > [_friendArray count] && [g_server.myself.friendCount intValue] >0) { // [g_App showAlert:Localized(@"JXAlert_SynchFirendOK") delegate:self]; if (self.isLoadFriendAndGroup) { [g_server listAttention:0 userId:MY_USER_ID toView:self]; }else{ [[JXXMPP sharedInstance] performSelector:@selector(login) withObject:nil afterDelay:2];//2秒后执行xmpp登录 } [[JXXMPP sharedInstance] performSelector:@selector(login) withObject:nil afterDelay:2];//2秒后执行xmpp登录 // } } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ if (alertView.tag == 10002) { [g_server performSelector:@selector(showLogin) withObject:nil afterDelay:0.5]; return; }else if (buttonIndex == 1) { [g_server listAttention:0 userId:MY_USER_ID toView:self]; } } -(void)buildTop{ ///NSMutableArray *remindArray = [[JXBlogRemind sharedInstance] doFetchUnread]; } -(void)actionSegment:(UIButton*)sender{ //[self doSelected:(int)sender.tag]; } -(void)onXmppLoginChanged:(NSNumber*)isLogin{ if([JXXMPP sharedInstance].isLogined == login_status_yes){ // 获取离线调用接口列表 [g_server offlineOperation:(g_server.lastOfflineTime *1000 + g_server.timeDifference)/1000 toView:self]; [self onAfterLogin]; } } -(void)onAfterLogin{ // [_msgVc scrollToPageUp]; } -(void)hasLoginOther:(NSNotification *)notifcation{ [g_App showAlert:Localized(@"JXXMPP_Other") delegate:self tag:10002 onlyConfirm:YES]; } - (void)showDeviceAuth:(NSNotification *)notification{ JXMessageObject *msg = notification.object; JXDeviceAuthController *authCon = [[JXDeviceAuthController alloc] initWithMsg:msg]; UIViewController *lastVC = (UIViewController *)g_navigation.subViews.lastObject; [lastVC presentViewController:authCon animated:YES completion:nil]; } -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{ //更新本地好友 if ([aDownload.action isEqualToString:act_UserGet]) { NSString *memberAcc= dict[@"membershipAccount"]; [[NSUserDefaults standardUserDefaults] setObject:memberAcc forKey:@"membershipAccount_ID"]; [[NSUserDefaults standardUserDefaults] synchronize]; } if ([aDownload.action isEqualToString:act_AttentionList]) { JXProgressVC * pv = [JXProgressVC alloc]; pv.dataArray = array1; pv = [pv init]; if (array1.count > 300) { [g_navigation pushViewController:pv animated:YES]; } // [self.view addSubview:pv.view]; } // 同步标签 if ([aDownload.action isEqualToString:act_FriendGroupList]) { for (NSInteger i = 0; i < array1.count; i ++) { NSDictionary *dict = array1[i]; JXLabelObject *labelObj = [[JXLabelObject alloc] init]; labelObj.groupId = dict[@"groupId"]; labelObj.groupName = dict[@"groupName"]; labelObj.userId = dict[@"userId"]; NSArray *userIdList = dict[@"userIdList"]; NSString *userIdListStr = [userIdList componentsJoinedByString:@","]; if (userIdListStr.length > 0) { labelObj.userIdList = [NSString stringWithFormat:@"%@", userIdListStr]; } [labelObj insert]; } // 删除服务器上已经删除的 NSArray *arr = [[JXLabelObject sharedInstance] fetchAllLabelsFromLocal]; for (NSInteger i = 0; i < arr.count; i ++) { JXLabelObject *locLabel = arr[i]; BOOL flag = NO; for (NSInteger j = 0; j < array1.count; j ++) { NSDictionary * dict = array1[j]; if ([locLabel.groupId isEqualToString:dict[@"groupId"]]) { flag = YES; break; } } if (!flag) { [locLabel delete]; } } } if ([aDownload.action isEqualToString:act_offlineOperation]) { for (NSDictionary *dict in array1) { if ([[dict objectForKey:@"tag"] isEqualToString:@"label"]) { [g_notify postNotificationName:kOfflineOperationUpdateLabelList object:nil]; } else if ([[dict objectForKey:@"tag"] isEqualToString:@"friend"]) { [g_server getUser:[dict objectForKey:@"friendId"] toView:self]; } else if ([[dict objectForKey:@"tag"] isEqualToString:@"room"]) { [g_server getRoom:[dict objectForKey:@"friendId"] toView:self]; } } } if ([aDownload.action isEqualToString:act_UserGet]) { JXUserObject *user = [[JXUserObject alloc] init]; [user getDataFromDict:dict]; NSString *gradeIndexcc= dict[@"gradeIndex"]; [[NSUserDefaults standardUserDefaults] setObject:gradeIndexcc forKey:@"gradeIndexcc"]; [[NSUserDefaults standardUserDefaults] synchronize]; if ([user.userId intValue] == [MY_USER_ID intValue]) { [g_server doSaveUser:dict]; user.bubbleFontId = [dict objectForKey:@"bubbleFontId"]; user.gradeIndex = [dict objectForKey:@"gradeIndex"]; // 保存自己 [user insert]; [user update]; }else { JXUserObject *user1 = [[JXUserObject sharedInstance] getUserById:user.userId]; user.content = user1.content; user.timeSend = user1.timeSend; [user update]; } [g_notify postNotificationName:kOfflineOperationUpdateUserSet object:user]; } if ([aDownload.action isEqualToString:act_roomGet]) { JXUserObject *user = [[JXUserObject alloc] init]; [user getDataFromDict:dict]; user.userId = [dict objectForKey:@"jid"]; user.roomId = [dict objectForKey:@"id"]; user.userNickname = [dict objectForKey:@"name"]; if(![g_xmpp.roomPool getRoom:user.userId] || ![user haveTheUser]){ user.userDescription = [dict objectForKey:@"desc"]; user.showRead = [dict objectForKey:@"showRead"]; user.showMember = [dict objectForKey:@"showMember"]; user.allowSendCard = [dict objectForKey:@"allowSendCard"]; user.chatRecordTimeOut = [dict objectForKey:@"chatRecordTimeOut"]; user.talkTime = [dict objectForKey:@"talkTime"]; user.allowInviteFriend = [dict objectForKey:@"allowInviteFriend"]; user.allowUploadFile = [dict objectForKey:@"allowUploadFile"]; user.allowConference = [dict objectForKey:@"allowConference"]; user.allowSpeakCourse = [dict objectForKey:@"allowSpeakCourse"]; user.offlineNoPushMsg = [(NSDictionary *)[dict objectForKey:@"member"] objectForKey:@"offlineNoPushMsg"]; user.isNeedVerify = [dict objectForKey:@"isNeedVerify"]; user.createUserId = [dict objectForKey:@"userId"]; user.content = @" "; user.topTime = nil; [user insertRoom]; // [g_xmpp.roomPool joinRoom:user.userId title:user.userNickname lastDate:nil isNew:NO]; }else { NSDictionary * groupDict = [user toDictionary]; roomData * roomdata = [[roomData alloc] init]; [roomdata getDataFromDict:groupDict]; [roomdata getDataFromDict:dict]; JXUserObject *user1 = [[JXUserObject sharedInstance] getUserById:roomdata.roomJid]; user.content = user1.content; user.status = user1.status; user.offlineNoPushMsg = [NSNumber numberWithBool:roomdata.offlineNoPushMsg]; user.msgsNew = user1.msgsNew; [user update]; } [g_notify postNotificationName:kOfflineOperationUpdateUserSet object:user]; } } -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{ return hide_error; } -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时 return hide_error; } @end