// // JXShowLabelVc.m // shiku_im // // Created by 123 on 2020/6/10. // Copyright © 2020 Reese. All rights reserved. // #import "JXShowLabelVc.h" #import "JXLabelObject.h" #import "JXNewLabelVC.h" @interface JXShowLabelVc () @property (nonatomic,strong) NSMutableArray *array; @property (nonatomic,weak) UIScrollView *scrollView; @property (nonatomic,strong) NSMutableArray *dataArr; @end @implementation JXShowLabelVc - (IBAction)gobackBtn:(id)sender { [g_navigation dismissViewController:self animated:YES]; } - (void)viewDidLoad { [super viewDidLoad]; _dataArr=[NSMutableArray array]; _array=[NSMutableArray array]; UIScrollView *scrollView=[[UIScrollView alloc]init]; scrollView.frame=CGRectMake(0, JX_SCREEN_TOP, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-JX_SCREEN_TOP); [self.view addSubview:scrollView]; self.scrollView=scrollView; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; //获取所有标签 [g_server friendGroupListToView:self]; } /* URL http://47.57.16.13:8092/friendGroup/list?language=zh&access_token=209d8948cf0e4d26b04a5c119041e085&salt=1591780308306&secret=6iQuBmisSNhnA%2Bov5fmStg%3D%3D URL http://47.57.16.13:8092/friendGroup/add?groupName=yupYY&language=zh&access_token=209d8948cf0e4d26b04a5c119041e085&salt=1591780359147&secret=PtEHqzeOt6d3FjgNIFRUag%3D%3D URL http://47.57.16.13:8092/friendGroup/list?language=zh&access_token=209d8948cf0e4d26b04a5c119041e085&salt=1591780308306&secret=6iQuBmisSNhnA%2Bov5fmStg%3D%3D */ //服务器返回数据 -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{ //更新本地好友 if ([aDownload.action isEqualToString:act_AttentionList]) { } // 同步标签 if ([aDownload.action isEqualToString:act_FriendGroupList]) { [self createButonUI:array1.mutableCopy]; //[_dataArr addObjectsFromArray:array1]; 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]; [_dataArr addObjectsFromArray:arr]; 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]; } } _array = [[JXLabelObject sharedInstance] fetchAllLabelsFromLocal]; for (JXLabelObject *labelObj in _array) { NSString *userIdStr = labelObj.userIdList; NSArray *userIds = [userIdStr componentsSeparatedByString:@","]; if (userIdStr.length <= 0) { userIds = nil; } NSMutableArray *newUserIds = [userIds mutableCopy]; for (NSInteger i = 0; i < userIds.count; i ++) { NSString *userId = userIds[i]; NSString *userName = [JXUserObject getUserNameWithUserId:userId]; if (!userName || userName.length <= 0) { [newUserIds removeObject:userId]; } } NSString *string = [newUserIds componentsJoinedByString:@","]; labelObj.userIdList = string; [labelObj update]; } } if ([aDownload.action isEqualToString:act_customerLinkList]){ } } - (void)createButonUI:(NSMutableArray *)array{ NSDictionary *tempDict=@{@"createTime":@"1589277624",@"groupId":@"5eba73b882e8f762eccdf702",@"groupName":@"+",@"userId":@"10000757",@"userIdList":@[]}; [array addObject:tempDict]; /* { "currentTime": 1591781851716, "data": [{ "createTime": 1589277624, "groupId": "5eba73b882e8f762eccdf702", "groupName": "家人", "userId": 10000757, "userIdList": [10000777] }, { "createTime": 1591781851, "groupId": "5ee0a9db82e8f728a6ce24c5", "groupName": "uuu", "userId": 10000757, "userIdList": [] }], "resultCode": 1 } */ for (int i=0; i