XMGMainViewController.m 13 KB

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