GroupController.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. //
  2. // GroupController.m
  3. // AIIM
  4. //
  5. // Created by gan on 2025/4/21.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import "GroupController.h"
  9. #import "GroupNetApi.h"
  10. #import <SDWebImage/UIImageView+WebCache.h>
  11. #import "ChatController.h"
  12. #import "ChatListStore.h"
  13. #import "config.h"
  14. #import "UDManager.h"
  15. #import "GroupEditController.h"
  16. #import "GroupGonggaoController.h"
  17. #import "ChatHistoryController.h"
  18. #import "NewGroupController.h"
  19. #import "FriendNetApi.h"
  20. @interface GroupController()<UITableViewDelegate,UITableViewDataSource,UICollectionViewDelegate,UICollectionViewDataSource>
  21. @property (weak, nonatomic) IBOutlet UICollectionView *collView;
  22. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  23. @property (weak, nonatomic) IBOutlet UIScrollView *ctScrollView;
  24. @property (weak, nonatomic) IBOutlet UILabel *bartitleLb;
  25. @property (weak, nonatomic) IBOutlet UIButton *rightBt;
  26. @property (nonatomic,strong) NSMutableArray *cellDatas;
  27. @property (nonatomic,strong) NSMutableArray *collDatas;
  28. @property (nonatomic,strong) NSString *master;
  29. @property (nonatomic) BOOL ismaster;
  30. @property (nonatomic) BOOL reloadMsg;
  31. @property (nonatomic, strong) NSDictionary * noDisturbDict;
  32. @end
  33. @implementation GroupController
  34. -(void)viewDidLoad{
  35. [super viewDidLoad];
  36. [self.navigationController setNavigationBarHidden:YES animated:NO];
  37. _bartitleLb.text = @"";
  38. _reloadMsg=NO;
  39. _cellDatas = [[NSMutableArray alloc] init];
  40. _collDatas = [[NSMutableArray alloc] init];
  41. _rightBt.alpha = 0;
  42. if(self.groupMsg){
  43. [self initData];
  44. [self getNoDiturbSettingData];
  45. }
  46. else{
  47. if(self.groupId){
  48. [self getNetGroupMsg];
  49. }
  50. }
  51. [self initSubView];
  52. }
  53. -(void)viewWillAppear:(BOOL)animated{
  54. [super viewWillAppear:YES];
  55. if(_reloadMsg){
  56. [self getNetGroupMsg];
  57. }
  58. }
  59. -(void)viewDidDisappear:(BOOL)animated{
  60. [super viewDidDisappear:YES];
  61. _reloadMsg=YES;
  62. }
  63. -(void)initData{
  64. _ismaster=NO;
  65. if (self.groupMsg) {
  66. _master = self.groupMsg[@"master"]?:@"";
  67. _groupId =self.groupMsg[@"id"];
  68. NSDictionary *userInfo = [UDManager.shareInstance getDDManager:dkuserinfo];
  69. if ([_master isEqualToString:userInfo[@"id"]]) {
  70. _ismaster=YES;
  71. _rightBt.alpha = 1;
  72. }
  73. }
  74. _bartitleLb.text = self.groupMsg[@"name"];
  75. NSDictionary *d1 =@{
  76. @"name":@"GroupCtr-xiaoximdr",
  77. @"image":@"noDisturb_chat_icon",
  78. };
  79. NSDictionary *d2 =@{
  80. @"name":@"GroupCtr-ruquanshe",
  81. @"image":@"check_group_icon",
  82. };
  83. NSDictionary *d3 =@{
  84. @"name":@"GroupCtr-zhuanrangq",
  85. @"image":@"transfer_group_icon",
  86. };
  87. NSDictionary *d4 =@{
  88. @"name":@"GroupCtr-liaotianjl",
  89. @"image":@"record_chat_icon",
  90. };
  91. NSDictionary *d5 =@{
  92. @"name":@"GroupCtr-gonggao",
  93. @"image":@"announce_group_icon",
  94. };
  95. NSDictionary *d6 =@{
  96. @"name":@"GroupCtr-liaotian",
  97. @"image":@"wzhuxiaozz",
  98. };
  99. NSString *d7name = @"GroupCtr-tuichuql";
  100. if(_ismaster){
  101. d7name = @"GroupCtr-jiesanquz";
  102. }
  103. NSDictionary *d7 =@{
  104. @"name":d7name,
  105. @"image":@"wzhuxiaozz",
  106. };
  107. [_cellDatas removeAllObjects];
  108. if(_ismaster){
  109. [_cellDatas addObject:d2];
  110. [_cellDatas addObject:d3];
  111. }
  112. [_cellDatas addObject:d4];
  113. [_cellDatas addObject:d5];
  114. [_cellDatas addObject:d1];
  115. [_cellDatas addObject:d6];
  116. [_cellDatas addObject:d7];
  117. [self getGroupUsers];
  118. }
  119. -(void)getNetGroupMsg{
  120. [GroupNetApi getGroupInfo:self.groupId succ:^(int code, NSDictionary * res) {
  121. NSLog(@"res:%@",res);
  122. self.groupMsg = [self replaceNullsWithEmptyStringInDictionary:res[@"data"]];
  123. [self initData];
  124. [self getNoDiturbSettingData];
  125. [self.tableView reloadData];
  126. } fail:^(NSError * _Nonnull error) {
  127. }];
  128. }
  129. -(void)getNoDiturbSettingData{
  130. [FriendNetApi getNoDisturbSetting:self.groupMsg[@"id"] succ:^(int code, NSDictionary * _Nullable result) {
  131. NSLog(@"noDisturbSetting:-----%@",result);
  132. NSArray * dataArray = result[@"data"];
  133. if (dataArray.count!=0) {
  134. self.noDisturbDict = dataArray[0];
  135. }
  136. [self.tableView reloadData];
  137. } fail:^(NSError * _Nonnull error) {
  138. }];
  139. }
  140. - (void)saveNoDisturbSetting{
  141. NSDictionary * param = @{
  142. @"userId":self.groupMsg[@"id"],
  143. @"chatId":self.groupMsg[@"id"]
  144. };
  145. [FriendNetApi saveNoDisturbSetting:param succ:^(int code, NSDictionary * _Nullable result) {
  146. [MBProgressHUD showWithText:result[@"msg"]];
  147. } fail:^(NSError * _Nonnull error) {
  148. }];
  149. }
  150. - (void)cancelNoDisturbSetting{
  151. [FriendNetApi cancelNoDisturbSettingWithUserId:self.groupMsg[@"id"] chatId:self.groupMsg[@"id"] succ:^(int code, NSDictionary * _Nullable result) {
  152. [MBProgressHUD showWithText:result[@"msg"]];
  153. } fail:^(NSError * _Nonnull error) {
  154. }];
  155. }
  156. -(void)initSubView{
  157. [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellT"];
  158. [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellTT"];
  159. [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellTT3"];
  160. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  161. _tableView.backgroundColor = [UIColor clearColor];
  162. _tableView.delegate = self;
  163. _tableView.dataSource = self;
  164. _tableView.scrollEnabled = NO;
  165. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  166. layout.scrollDirection = UICollectionViewScrollDirectionVertical; // 设置垂直流布局
  167. CGFloat width = _collView.frame.size.width;
  168. width=(width-20)/3;
  169. layout.itemSize = CGSizeMake(width, width); // 设置每个item的大小
  170. layout.minimumInteritemSpacing = 5; // 设置单元格之间的间距
  171. [_collView setCollectionViewLayout:layout];
  172. [_collView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"collT"];
  173. [_collView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"collTT"];
  174. _collView.dataSource = self;
  175. _collView.delegate = self;
  176. _collView.backgroundColor = [UIColor clearColor];
  177. _ctScrollView.showsVerticalScrollIndicator =NO;
  178. _ctScrollView.backgroundColor = [UIColor clearColor];
  179. }
  180. -(void)resetframe{
  181. NSLog(@"_ismaster");
  182. CGFloat tableH = _cellDatas.count*62;
  183. NSInteger row =_collDatas.count/3;
  184. if(_ismaster){
  185. NSLog(@"_ismaster11-----");
  186. row =(_collDatas.count+2)/3;
  187. if((_collDatas.count+2)>row*3) {
  188. row=row+1;
  189. }
  190. }
  191. else{
  192. NSString *openInvite = self.groupMsg[@"openInvite"];
  193. if(openInvite.intValue==1){
  194. row =(_collDatas.count+1)/3;
  195. if((_collDatas.count+1)>row*3) {
  196. row=row+1;
  197. }
  198. }
  199. else{
  200. row =_collDatas.count/3;
  201. if(_collDatas.count>row*3) {
  202. row=row+1;
  203. }
  204. }
  205. }
  206. CGFloat width = _collView.frame.size.width;
  207. width=(width-20)/3;
  208. CGFloat collVH = row*(width+10);
  209. CGRect r = _collView.frame;
  210. r.origin.x =0.0f;
  211. r.origin.y = 0.0f;
  212. r.size.height = collVH;
  213. _collView.frame = r;
  214. CGRect t = _tableView.frame;
  215. t.origin.x =0.0f;
  216. t.origin.y = collVH +10.0f;
  217. t.size.height = tableH;
  218. _tableView.frame = t;
  219. _ctScrollView.contentSize = CGSizeMake(_ctScrollView.frame.size.width, tableH+collVH+20);
  220. [_collView reloadData];
  221. [_tableView reloadData];
  222. }
  223. - (IBAction)gotoBack:(id)sender {
  224. [self dismissViewControllerAnimated:YES completion:nil];
  225. }
  226. - (IBAction)rightBt:(id)sender {
  227. UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  228. NewGroupController *groupctr = [board instantiateViewControllerWithIdentifier:@"NewGroupController"];
  229. groupctr.groupMsg = self.groupMsg;
  230. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:groupctr];
  231. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  232. [self presentViewController :uiNavC animated:YES completion:nil];
  233. }
  234. - (void)switchAction:(id)sender {
  235. UISwitch *switchButton = (UISwitch*)sender;
  236. BOOL isButtonOn = [switchButton isOn];
  237. if (isButtonOn) {
  238. // 处理开关打开的情况
  239. NSLog(@"isButtonOn");
  240. [self saveNoDisturbSetting];
  241. } else {
  242. // 处理开关关闭的情况
  243. NSLog(@"isButtonOff");
  244. [self cancelNoDisturbSetting];
  245. }
  246. }
  247. #pragma mark UICollectionViewDelegate
  248. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  249. return 1;
  250. }
  251. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  252. if(_ismaster){
  253. return self.collDatas.count +2;
  254. }
  255. else{
  256. NSString *openInvite = self.groupMsg[@"openInvite"];
  257. if(openInvite.intValue==1){
  258. return self.collDatas.count +1;
  259. }
  260. else{
  261. return self.collDatas.count;
  262. }
  263. }
  264. }
  265. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  266. // 配置cell的内容
  267. if(indexPath.row==self.collDatas.count){
  268. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collTT" forIndexPath:indexPath];
  269. CGFloat width = cell.frame.size.width;
  270. UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"jiaqun"]];
  271. [cell addSubview:img];
  272. img.contentMode = UIViewContentModeScaleAspectFill;
  273. img.frame = CGRectMake(20, 0, width-40, width-40);
  274. img.layer.cornerRadius = (width-40)/2;
  275. img.layer.masksToBounds = YES;
  276. img.backgroundColor=[UIColor lightGrayColor];
  277. cell.backgroundColor=[UIColor clearColor];
  278. return cell;
  279. }
  280. else if(indexPath.row==self.collDatas.count+1){
  281. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collTT" forIndexPath:indexPath];
  282. CGFloat width = cell.frame.size.width;
  283. UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tichuqun"]];
  284. [cell addSubview:img];
  285. img.contentMode = UIViewContentModeScaleAspectFill;
  286. img.frame = CGRectMake(20, 0, width-40, width-40);
  287. img.layer.cornerRadius = (width-40)/2;
  288. img.layer.masksToBounds = YES;
  289. img.backgroundColor=[UIColor lightGrayColor];
  290. cell.backgroundColor=[UIColor clearColor];
  291. return cell;
  292. }
  293. else{
  294. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collT" forIndexPath:indexPath];
  295. NSArray *array = cell.contentView.subviews;
  296. for (id sbv in array) {
  297. [sbv removeFromSuperview];
  298. }
  299. NSDictionary *dic = self.collDatas[indexPath.row];
  300. CGFloat width = cell.frame.size.width;
  301. UIImageView *img = [[UIImageView alloc] init];
  302. [cell.contentView addSubview:img];
  303. [img sd_setImageWithURL:[NSURL URLWithString:dic[@"avatar"]] placeholderImage:[UIImage imageNamed:@"Avatar"]];
  304. img.contentMode = UIViewContentModeScaleAspectFill;
  305. img.frame = CGRectMake(20, 0, width-40, width-40);
  306. img.layer.cornerRadius = (width-40)/2;
  307. img.layer.masksToBounds = YES;
  308. img.backgroundColor=[UIColor lightGrayColor];
  309. UILabel *name = [[UILabel alloc] init];
  310. name.text = dic[@"name"];
  311. [cell.contentView addSubview:name];
  312. name.frame = CGRectMake(0, width-40, width, 30.0f);
  313. name.textAlignment = NSTextAlignmentCenter;
  314. if([_master isEqualToString:dic[@"id"]]){
  315. name.textColor = globalColor(GCTypeOrangeR);
  316. name.font = [UIFont systemFontOfSize:15.0f];
  317. }
  318. else{
  319. name.textColor = [UIColor whiteColor];
  320. name.font = [UIFont systemFontOfSize:14.0f];
  321. }
  322. cell.backgroundColor=[UIColor clearColor];
  323. return cell;
  324. }
  325. return nil;
  326. }
  327. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  328. if(indexPath.row==self.collDatas.count){//邀请加入群
  329. UIStoryboard *board = [UIStoryboard storyboardWithName:@"groupstory" bundle:[NSBundle mainBundle]];
  330. GroupEditController *chatctr = [board instantiateViewControllerWithIdentifier:@"GroupEditController"];
  331. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:chatctr];
  332. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  333. chatctr.editType = 3;
  334. chatctr.groupId = self.groupMsg[@"id"];
  335. [self presentViewController :uiNavC animated:YES completion:nil];
  336. }else if(indexPath.row==self.collDatas.count+1){//踢出群
  337. UIStoryboard *board = [UIStoryboard storyboardWithName:@"groupstory" bundle:[NSBundle mainBundle]];
  338. GroupEditController *chatctr = [board instantiateViewControllerWithIdentifier:@"GroupEditController"];
  339. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:chatctr];
  340. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  341. chatctr.editType = 4;
  342. chatctr.groupId = self.groupMsg[@"id"];
  343. [self presentViewController :uiNavC animated:YES completion:nil];
  344. }
  345. NSLog(@"");
  346. }
  347. #pragma mark UITableViewDelegate
  348. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  349. NSInteger section =indexPath.section;
  350. NSDictionary *time =_cellDatas[section];
  351. NSString *cellT =@"cellT";
  352. if(section>_cellDatas.count-3){
  353. cellT =@"cellTT";
  354. UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellT forIndexPath:indexPath];
  355. if(cell==nil){
  356. cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellT];
  357. }
  358. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  359. cell.backgroundColor = [UIColor clearColor];
  360. cell.contentView.layer.borderWidth = 0.5f;
  361. cell.contentView.layer.borderColor = [UIColor lightGrayColor].CGColor; //globalColor(GCTypeGreen);
  362. cell.contentView.layer.cornerRadius = 8.0f; // 可选,设置圆角
  363. if(section==_cellDatas.count-1){
  364. cell.contentView.backgroundColor = globalColor(GCTypeOrangeR);
  365. }
  366. else{
  367. cell.contentView.backgroundColor = globalColor(GCTypeGreen);
  368. }
  369. cell.textLabel.text =NSLocalizedString(time[@"name"], @"");
  370. cell.textLabel.textAlignment = NSTextAlignmentCenter;
  371. return cell;
  372. }
  373. else if(indexPath.section == self.cellDatas.count-3){
  374. cellT =@"cellTT3";
  375. UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellT forIndexPath:indexPath];
  376. if(cell==nil){
  377. cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellT];
  378. }
  379. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  380. cell.backgroundColor = [UIColor clearColor];
  381. NSString *title = NSLocalizedString(time[@"name"], @"");
  382. cell.imageView.image = [UIImage imageNamed:time[@"image"]];
  383. cell.textLabel.text =title;
  384. cell.textLabel.textColor = [UIColor whiteColor];
  385. CGRect ctfrm = cell.contentView.frame;
  386. UISwitch * stateSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(ctfrm.size.width-66, 10, 20, 10)];
  387. stateSwitch.onImage = kImageMake(@"switch_on");
  388. stateSwitch.offImage = kImageMake(@"switch_off");
  389. if (self.noDisturbDict && [self.noDisturbDict jk_hasKey:@"id"]) {
  390. [stateSwitch setOn:YES];
  391. }else{
  392. [stateSwitch setOn:NO];
  393. }
  394. [stateSwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
  395. [cell.contentView addSubview:stateSwitch];
  396. cell.contentView.layer.borderWidth = 0.5f;
  397. cell.contentView.layer.borderColor = [UIColor lightGrayColor].CGColor; //globalColor(GCTypeGreen);
  398. cell.contentView.layer.cornerRadius = 8.0f; // 可选,设置圆角
  399. return cell;
  400. }
  401. else{
  402. UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:cellT forIndexPath:indexPath];
  403. if(cell==nil){
  404. cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellT];
  405. }
  406. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  407. cell.backgroundColor = [UIColor clearColor];
  408. NSString *title = NSLocalizedString(time[@"name"], @"");
  409. cell.imageView.image = [UIImage imageNamed:time[@"image"]];
  410. cell.textLabel.text =title;
  411. cell.textLabel.textColor = [UIColor whiteColor];
  412. CGRect ctfrm = cell.contentView.frame;
  413. UIImageView *right = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow-right"]];
  414. right.frame = CGRectMake(ctfrm.size.width-30, 21, 20, 20);
  415. [cell.contentView addSubview:right];
  416. cell.contentView.layer.borderWidth = 0.5f;
  417. cell.contentView.layer.borderColor = [UIColor lightGrayColor].CGColor; //globalColor(GCTypeGreen);
  418. cell.contentView.layer.cornerRadius = 8.0f; // 可选,设置圆角
  419. return cell;
  420. }
  421. }
  422. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  423. if(_ismaster){//群主
  424. if(indexPath.section == 0){
  425. [self gotoRuqunshenhe];
  426. }
  427. if(indexPath.section == 1){
  428. [self zhuanrangqun];
  429. }
  430. if(indexPath.section == 2){
  431. [self gotoLiaotianjilu];
  432. }
  433. if(indexPath.section == 3){
  434. [self gotoGonggao];
  435. }
  436. if(indexPath.section == 5){
  437. [self gotoChart];
  438. }
  439. if(indexPath.section == 6){
  440. [self jiesanqun];
  441. }
  442. }
  443. else{//非群主
  444. if(indexPath.section == 0){
  445. [self gotoLiaotianjilu];
  446. }
  447. if(indexPath.section == 1){
  448. [self gotoGonggao];
  449. }
  450. if(indexPath.section == 3){
  451. [self gotoChart];
  452. }
  453. if(indexPath.section == 4){
  454. [self tuichuqun];
  455. }
  456. }
  457. }
  458. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  459. return 1;
  460. }
  461. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  462. return _cellDatas.count;
  463. }
  464. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  465. return 52.0;
  466. }
  467. -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  468. CGFloat height =10.0;
  469. if(section==0){
  470. height =0.0;
  471. }
  472. return height;
  473. }
  474. -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
  475. CGFloat height =10.0;
  476. if(section==0){
  477. height =0.0;
  478. }
  479. UIView *view =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, height)];
  480. view.backgroundColor = [UIColor clearColor];
  481. return view;
  482. }
  483. -(void)getGroupUsers{
  484. NSLog(@"self.groupMsg:%@",self.groupMsg);
  485. if (self.groupMsg) {
  486. [GroupNetApi getGroupUserList:self.groupMsg[@"id"] succ:^(int code, NSDictionary *res) {
  487. NSLog(@"res:%@",res);
  488. self.collDatas = [NSMutableArray arrayWithArray:[self replaceNullsWithEmptyStringInArray:res[@"data"]]];
  489. [self resetframe];
  490. } fail:^(NSError * _Nonnull error) {
  491. NSLog(@"errer");
  492. }];
  493. }
  494. }
  495. #pragma mark 入群审核
  496. -(void)gotoRuqunshenhe{
  497. UIStoryboard *board = [UIStoryboard storyboardWithName:@"groupstory" bundle:[NSBundle mainBundle]];
  498. GroupEditController *chatctr = [board instantiateViewControllerWithIdentifier:@"GroupEditController"];
  499. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:chatctr];
  500. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  501. chatctr.editType = 1;
  502. chatctr.groupId = self.groupMsg[@"id"];
  503. [self presentViewController :uiNavC animated:YES completion:nil];
  504. }
  505. #pragma mark 转让群
  506. -(void)zhuanrangqun{
  507. UIStoryboard *board = [UIStoryboard storyboardWithName:@"groupstory" bundle:[NSBundle mainBundle]];
  508. GroupEditController *chatctr = [board instantiateViewControllerWithIdentifier:@"GroupEditController"];
  509. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:chatctr];
  510. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  511. chatctr.editType = 2;
  512. chatctr.groupId = self.groupMsg[@"id"];
  513. [self presentViewController :uiNavC animated:YES completion:nil];
  514. }
  515. #pragma mark 聊天记录
  516. -(void)gotoLiaotianjilu{
  517. UIStoryboard *board = [UIStoryboard storyboardWithName:@"ChatHistory" bundle:[NSBundle mainBundle]];
  518. ChatHistoryController *chatctr = [board instantiateViewControllerWithIdentifier:@"ChatHistoryController"];
  519. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:chatctr];
  520. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  521. chatctr.chatId = self.groupMsg[@"id"];
  522. chatctr.type = 1;
  523. chatctr.titlename = self.groupMsg[@"name"];
  524. chatctr.avatar = self.groupMsg[@"avatar"];
  525. [self presentViewController :uiNavC animated:YES completion:nil];
  526. }
  527. #pragma mark 公告
  528. -(void)gotoGonggao{
  529. UIStoryboard *board = [UIStoryboard storyboardWithName:@"groupstory" bundle:[NSBundle mainBundle]];
  530. GroupGonggaoController *chatctr = [board instantiateViewControllerWithIdentifier:@"GroupGonggaoController"];
  531. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:chatctr];
  532. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  533. chatctr.groupId = self.groupMsg[@"id"];
  534. chatctr.gonggao =self.groupMsg[@"announcement"];
  535. if(_ismaster){
  536. chatctr.editType = 1;
  537. }
  538. else{
  539. chatctr.editType = 2;
  540. }
  541. [self presentViewController :uiNavC animated:YES completion:nil];
  542. }
  543. #pragma mark 消息免打扰
  544. -(void)changeXiaoximdr{
  545. }
  546. #pragma mark 聊天
  547. -(void)gotoChart{
  548. UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  549. ChatController *chatctr = [board instantiateViewControllerWithIdentifier:@"ChatController"];
  550. UINavigationController *uiNavC = [[UINavigationController alloc] initWithRootViewController:chatctr];
  551. uiNavC.modalPresentationStyle = UIModalPresentationFullScreen;
  552. chatctr.chatId = self.groupMsg[@"id"];
  553. chatctr.type = 1;
  554. ChatListStore.shareInstance.chatId =self.groupMsg[@"id"];
  555. chatctr.titlename = self.groupMsg[@"name"];
  556. chatctr.avatar = self.groupMsg[@"avatar"];
  557. [self presentViewController :uiNavC animated:YES completion:nil];
  558. }
  559. #pragma mark 退出群
  560. -(void)tuichuqun{
  561. // 创建弹框询问
  562. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"
  563. message:@"是否确认退出群?"
  564. preferredStyle:UIAlertControllerStyleAlert];
  565. // 创建取消按钮和确定按钮,并添加到弹框中
  566. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  567. NSLog(@"用户点击了取消");
  568. }];
  569. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  570. NSLog(@"用户点击了确定");
  571. [GroupNetApi exitGroup:self.groupId succ:^(int code, NSDictionary * res) {
  572. NSString *coder = res[@"code"];
  573. if(coder.intValue==200){
  574. [self dismissViewControllerAnimated:YES completion:nil];
  575. }
  576. } fail:^(NSError * _Nonnull error) {
  577. }];
  578. }];
  579. [alert addAction:cancelAction];
  580. [alert addAction:okAction];
  581. // 显示弹框
  582. [self presentViewController:alert animated:YES completion:nil];
  583. }
  584. #pragma mark 解散群
  585. -(void)jiesanqun{
  586. // 创建弹框询问
  587. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"
  588. message:@"是否确认解散群?"
  589. preferredStyle:UIAlertControllerStyleAlert];
  590. // 创建取消按钮和确定按钮,并添加到弹框中
  591. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  592. NSLog(@"用户点击了取消");
  593. }];
  594. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  595. NSLog(@"用户点击了确定");
  596. [GroupNetApi deleteGroup:self.groupId succ:^(int code, NSDictionary * res) {
  597. NSString *coder = res[@"code"];
  598. if(coder.intValue==200){
  599. [self dismissViewControllerAnimated:YES completion:nil];
  600. }
  601. } fail:^(NSError * _Nonnull error) {
  602. }];
  603. }];
  604. [alert addAction:cancelAction];
  605. [alert addAction:okAction];
  606. // 显示弹框
  607. [self presentViewController:alert animated:YES completion:nil];
  608. }
  609. #pragma mark statusBar
  610. - (UIStatusBarStyle)preferredStatusBarStyle{
  611. return UIStatusBarStyleLightContent;
  612. }
  613. #pragma mark 工具
  614. // 递归替换字典中的 NSNull 为 @""
  615. - (NSDictionary *)replaceNullsWithEmptyStringInDictionary:(NSDictionary *)dictionary {
  616. NSMutableDictionary *mutableDict = [NSMutableDictionary dictionaryWithDictionary:dictionary];
  617. for (id key in [mutableDict allKeys]) {
  618. id value = [mutableDict objectForKey:key];
  619. if ([value isKindOfClass:[NSNull class]]) {
  620. [mutableDict setObject:@"" forKey:key];
  621. } else if ([value isKindOfClass:[NSDictionary class]]) {
  622. // 递归处理子字典
  623. [mutableDict setObject:[self replaceNullsWithEmptyStringInDictionary:value] forKey:key];
  624. } else if ([value isKindOfClass:[NSArray class]]) {
  625. // 递归处理数组
  626. [mutableDict setObject:[self replaceNullsWithEmptyStringInArray:value] forKey:key];
  627. }
  628. }
  629. return [NSDictionary dictionaryWithDictionary:mutableDict];
  630. }
  631. // 递归替换数组中的 NSNull 为 @""
  632. - (NSArray *)replaceNullsWithEmptyStringInArray:(NSArray *)array {
  633. NSMutableArray *mutableArray = [NSMutableArray arrayWithArray:array];
  634. for (NSInteger i = 0; i < [mutableArray count]; i++) {
  635. id value = [mutableArray objectAtIndex:i];
  636. if ([value isKindOfClass:[NSNull class]]) {
  637. [mutableArray replaceObjectAtIndex:i withObject:@""];
  638. } else if ([value isKindOfClass:[NSDictionary class]]) {
  639. // 递归处理子字典
  640. [mutableArray replaceObjectAtIndex:i withObject:[self replaceNullsWithEmptyStringInDictionary:value]];
  641. } else if ([value isKindOfClass:[NSArray class]]) {
  642. // 递归处理子数组
  643. [mutableArray replaceObjectAtIndex:i withObject:[self replaceNullsWithEmptyStringInArray:value]];
  644. }
  645. }
  646. return [NSArray arrayWithArray:mutableArray];
  647. }
  648. @end