GroupSettingViewController.m 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. //
  2. // GroupSettingViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/24.
  6. //
  7. #import "GroupSettingViewController.h"
  8. #import "GroupSettingBodyView.h"
  9. #import "KSSearchViewController.h"
  10. #import "KSChatComplainController.h"
  11. #import "GroupListModel.h"
  12. #import "GroupMemberModel.h"
  13. #import "GroupMemberViewController.h"
  14. #import "GroupNoticeViewController.h"
  15. #import "GroupApplyViewController.h"
  16. #import "ModifyNameViewController.h"
  17. #import "KSPublicAlertView.h"
  18. #import <ImSDK_Plus/V2TIMManager+Group.h>
  19. #import "CustomNavViewController.h"
  20. @interface GroupSettingViewController ()
  21. @property (nonatomic, strong) GroupListModel *sourceModel;
  22. @property (nonatomic, strong) GroupSettingBodyView *bodyView;
  23. @property (nonatomic, strong) NSMutableArray *sourceArray;
  24. @property (nonatomic, assign) NSInteger applyCount;
  25. @property (nonatomic, strong) KSPublicAlertView *alertView;
  26. @end
  27. @implementation GroupSettingViewController
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. // Do any additional setup after loading the view.
  31. [self allocTitle:@"群设置"];
  32. [self configUI];
  33. }
  34. - (void)configUI {
  35. self.scrollView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin);
  36. self.bodyView = [GroupSettingBodyView shareInstance];
  37. CGFloat height = kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin > 700 ? kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin : 700;
  38. self.bodyView.frame = CGRectMake(0, 0, kScreenWidth, height);
  39. BOOL isCourseGroup = NO;
  40. if ([self.groupId containsString:@"COURSE"]) {
  41. isCourseGroup = YES;
  42. }
  43. else if ([self.groupId containsString:@"FAN"]) {
  44. isCourseGroup = NO;
  45. }
  46. self.bodyView.isCourseGroup = isCourseGroup;
  47. [self.scrollView addSubview:self.bodyView];
  48. [self.scrollView setContentSize:CGSizeMake(kScreenWidth, height)];
  49. }
  50. - (void)rightBtnClick {
  51. // 分享
  52. }
  53. - (void)viewWillAppear:(BOOL)animated {
  54. [super viewWillAppear:animated];
  55. [self requestData];
  56. [self getGroupStudent];
  57. [self getGroupMessageNotiferStatus];
  58. [self requestApplyMember];
  59. }
  60. - (void)requestApplyMember {
  61. [KSNetworkingManager imGroupMemberAuditListRequest:KS_POST groupId:self.groupId success:^(NSDictionary * _Nonnull dic) {
  62. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  63. NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
  64. self.applyCount = sourceArray.count;
  65. self.bodyView.applyMember = self.applyCount;
  66. }
  67. else {
  68. [self MBPShow:MESSAGEKEY];
  69. }
  70. } faliure:^(NSError * _Nonnull error) {
  71. }];
  72. }
  73. - (void)evaluateMessge {
  74. [self.bodyView evaluateStudentArray:self.sourceArray];
  75. }
  76. - (void)requestData {
  77. [KSNetworkingManager queryGroupDetail:KS_POST groupId:self.groupId success:^(NSDictionary * _Nonnull dic) {
  78. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  79. NSDictionary *subDic = [dic ks_dictionaryValueForKey:@"data"];
  80. self.sourceModel = [[GroupListModel alloc] initWithDictionary:subDic];
  81. [self refreshUI];
  82. }
  83. else {
  84. [self MBPShow:MESSAGEKEY];
  85. }
  86. } faliure:^(NSError * _Nonnull error) {
  87. }];
  88. }
  89. - (void)getGroupStudent {
  90. [self.sourceArray removeAllObjects];
  91. [KSNetworkingManager imGroupMemberAllRequest:KS_POST groupId:self.groupId success:^(NSDictionary * _Nonnull dic) {
  92. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  93. NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
  94. for (NSDictionary *parm in sourceArray) {
  95. GroupMemberModel *model = [[GroupMemberModel alloc] initWithDictionary:parm];
  96. [self.sourceArray addObject:model];
  97. }
  98. [self evaluateMessge];
  99. }
  100. else {
  101. [self MBPShow:MESSAGEKEY];
  102. }
  103. } faliure:^(NSError * _Nonnull error) {
  104. }];
  105. }
  106. - (void)getGroupMessageNotiferStatus {
  107. [[V2TIMManager sharedInstance] getGroupsInfo:@[self.groupId] succ:^(NSArray<V2TIMGroupInfoResult *> * groupResultList) {
  108. for (V2TIMGroupInfoResult *result in groupResultList){
  109. V2TIMGroupInfo *info = result.info;
  110. NSLog(@"recvOpt, %d", (int)info.recvOpt);
  111. if (info.recvOpt == V2TIM_RECEIVE_MESSAGE) {
  112. self.bodyView.isOn = NO;
  113. }
  114. else {
  115. self.bodyView.isOn = YES;
  116. }
  117. }
  118. } fail:^(int code, NSString *desc) {
  119. NSLog(@"failure, code:%d, desc:%@", code, desc);
  120. }];
  121. }
  122. - (void)refreshUI {
  123. MJWeakSelf;
  124. [self.bodyView configWithSource:self.sourceModel callback:^(GROUPSETTING type) {
  125. [weakSelf operationWithType:type];
  126. }];
  127. }
  128. - (void)operationWithType:(GROUPSETTING)type {
  129. switch (type) {
  130. case GROUPSETTING_PERSON: // 群成员列表
  131. {
  132. GroupMemberViewController *memberVC = [[GroupMemberViewController alloc] init];
  133. memberVC.groupId = self.groupId;
  134. [self.navigationController pushViewController:memberVC animated:YES];
  135. }
  136. break;
  137. case GROUPSETTING_APPLY: // 入群申请列表
  138. {
  139. GroupApplyViewController *applyCtrl = [[GroupApplyViewController alloc] init];
  140. applyCtrl.groupId = self.groupId;
  141. [self.navigationController pushViewController:applyCtrl animated:YES];
  142. }
  143. break;
  144. case GROUPSETTING_GROUP: // 修改群名称
  145. {
  146. ModifyNameViewController *modifyCtrl = [[ModifyNameViewController alloc] init];
  147. modifyCtrl.groupId = self.groupId;
  148. modifyCtrl.preNickName = self.sourceModel.name;
  149. [self.navigationController pushViewController:modifyCtrl animated:YES];
  150. }
  151. break;
  152. case GROUPSETTING_MESSAGESEARCH:
  153. {
  154. KSSearchViewController *vc = [[KSSearchViewController alloc] init];
  155. vc.groupId = self.groupId;
  156. CustomNavViewController *nav = [[CustomNavViewController alloc] initWithRootViewController:(UIViewController *)vc];
  157. nav.modalPresentationStyle = UIModalPresentationFullScreen;
  158. UIViewController *parentVC = self.navigationController;
  159. if (parentVC) {
  160. [parentVC presentViewController:nav animated:NO completion:nil];
  161. }
  162. }
  163. break;
  164. case GROUPSETTING_SETTING: // 消息提醒
  165. {
  166. [self messageSetting];
  167. }
  168. break;
  169. case GROUPSETTING_NOTICE: // 群公告
  170. {
  171. GroupNoticeViewController *noticeVC = [[GroupNoticeViewController alloc] init];
  172. noticeVC.groupId = self.groupId;
  173. noticeVC.canEdit = YES;
  174. [self.navigationController pushViewController:noticeVC animated:YES];
  175. }
  176. break;
  177. case GROUPSETTING_FEEDBACK: // 反馈
  178. {
  179. KSChatComplainController *ctrl = [[KSChatComplainController alloc] init];
  180. ctrl.fromGroup = YES;
  181. ctrl.targetId = self.groupId;
  182. [self.navigationController pushViewController:ctrl animated:YES];
  183. }
  184. break;
  185. case GROUPSETTING_DISMISS: // 解散群聊
  186. {
  187. [self showDismissAlert];
  188. }
  189. break;
  190. default:
  191. break;
  192. }
  193. }
  194. - (void)showDismissAlert {
  195. MJWeakSelf;
  196. self.alertView = [KSPublicAlertView shareInstanceWithTitle:@"提示" descMessage:@"确认解散群聊吗" leftTitle:@"取消" rightTitle:@"确定" cancelAction:^{
  197. } sureAction:^{
  198. [weakSelf dismissGroup];
  199. }];
  200. }
  201. - (void)dismissGroup {
  202. [KSNetworkingManager imGroupDismiss:KS_POST groupId:self.groupId success:^(NSDictionary * _Nonnull dic) {
  203. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  204. MJWeakSelf;
  205. [self KSShowMsg:@"群已解散" promptCompletion:^{
  206. [weakSelf.navigationController popToRootViewControllerAnimated:YES];
  207. }];
  208. }
  209. else {
  210. [self MBPShow:MESSAGEKEY];
  211. }
  212. } faliure:^(NSError * _Nonnull error) {
  213. }];
  214. }
  215. - (void)messageSetting {
  216. V2TIMReceiveMessageOpt type = self.bodyView.isOn ? V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE : V2TIM_RECEIVE_MESSAGE;
  217. [[V2TIMManager sharedInstance] setGroupReceiveMessageOpt:self.groupId opt:type succ:^{
  218. NSLog(@"success");
  219. } fail:^(int code, NSString *desc) {
  220. dispatch_main_async_safe(^{
  221. [LOADING_MANAGER KSShowMsg:@"设置失败" promptCompletion:^{
  222. self.bodyView.isOn = !self.bodyView.isOn;
  223. }];
  224. });
  225. }];
  226. }
  227. - (NSMutableArray *)sourceArray {
  228. if (!_sourceArray) {
  229. _sourceArray = [NSMutableArray array];
  230. }
  231. return _sourceArray;
  232. }
  233. /*
  234. #pragma mark - Navigation
  235. // In a storyboard-based application, you will often want to do a little preparation before navigation
  236. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  237. // Get the new view controller using [segue destinationViewController].
  238. // Pass the selected object to the new view controller.
  239. }
  240. */
  241. @end