GroupSettingViewController.m 11 KB

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