123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- //
- // 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
|