GroupSettingViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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 "KSPublicAlertView.h"
  17. #import <ImSDK_Plus/V2TIMManager+Group.h>
  18. #import "CustomNavViewController.h"
  19. #import "GroupQuitAlert.h"
  20. #import "GroupIntroduceViewController.h"
  21. @interface GroupSettingViewController ()
  22. @property (nonatomic, strong) GroupListModel *sourceModel;
  23. @property (nonatomic, strong) GroupSettingBodyView *bodyView;
  24. @property (nonatomic, strong) NSMutableArray *sourceArray;
  25. @property (nonatomic, assign) NSInteger applyCount;
  26. @property (nonatomic, strong) GroupQuitAlert *alertView;
  27. @end
  28. @implementation GroupSettingViewController
  29. - (void)viewDidLoad {
  30. [super viewDidLoad];
  31. // Do any additional setup after loading the view.
  32. [self allocTitle:@"群设置"];
  33. [self configUI];
  34. }
  35. - (void)configUI {
  36. self.scrollView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin);
  37. self.bodyView = [GroupSettingBodyView shareInstance];
  38. CGFloat height = kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin > 700 ? kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin : 700;
  39. self.bodyView.frame = CGRectMake(0, 0, kScreenWidth, height);
  40. BOOL isCourseGroup = NO;
  41. if ([self.groupId containsString:@"COURSE"]) {
  42. isCourseGroup = YES;
  43. }
  44. else if ([self.groupId containsString:@"FAN"]) {
  45. isCourseGroup = NO;
  46. }
  47. self.bodyView.isCourseGroup = isCourseGroup;
  48. [self.scrollView addSubview:self.bodyView];
  49. [self.scrollView setContentSize:CGSizeMake(kScreenWidth, height)];
  50. }
  51. - (void)viewWillAppear:(BOOL)animated {
  52. [super viewWillAppear:animated];
  53. [self requestData];
  54. [self getGroupStudent];
  55. [self getGroupMessageNotiferStatus];
  56. }
  57. - (void)evaluateMessge {
  58. NSMutableArray *memberArray = [NSMutableArray array];
  59. for (GroupMemberModel *model in self.sourceArray) {
  60. if (model.isAdmin) {
  61. [memberArray insertObject:model atIndex:0];
  62. }
  63. else {
  64. [memberArray addObject:model];
  65. }
  66. }
  67. self.sourceArray = [NSMutableArray arrayWithArray:memberArray];
  68. [self.bodyView evaluateStudentArray:self.sourceArray];
  69. }
  70. - (void)requestData {
  71. [KSNetworkingManager queryGroupDetail:KS_POST groupId:self.groupId success:^(NSDictionary * _Nonnull dic) {
  72. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  73. NSDictionary *subDic = [dic ks_dictionaryValueForKey:@"data"];
  74. self.sourceModel = [[GroupListModel alloc] initWithDictionary:subDic];
  75. }
  76. else if ([dic ks_integerValueForKey:@"code"] == 204) {
  77. [LOADING_MANAGER KSShowMsg:@"获取群信息失败" promptCompletion:^{
  78. [self backAction];
  79. }];
  80. }
  81. else {
  82. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  83. }
  84. [self refreshUI];
  85. } faliure:^(NSError * _Nonnull error) {
  86. [self refreshUI];
  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. [LOADING_MANAGER MBShowAUTOHidingInWindow: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. }
  140. break;
  141. case GROUPSETTING_GROUP: // 修改群名称
  142. {
  143. }
  144. break;
  145. case GROUPSETTING_MESSAGESEARCH:
  146. {
  147. KSSearchViewController *vc = [[KSSearchViewController alloc] init];
  148. vc.groupId = self.groupId;
  149. CustomNavViewController *nav = [[CustomNavViewController alloc] initWithRootViewController:(UIViewController *)vc];
  150. nav.modalPresentationStyle = UIModalPresentationFullScreen;
  151. UIViewController *parentVC = self.navigationController;
  152. if (parentVC) {
  153. [parentVC presentViewController:nav animated:NO completion:nil];
  154. }
  155. }
  156. break;
  157. case GROUPSETTING_SETTING: // 消息提醒
  158. {
  159. [self messageSetting];
  160. }
  161. break;
  162. case GROUPSETTING_NOTICE: // 群公告
  163. {
  164. GroupNoticeViewController *noticeVC = [[GroupNoticeViewController alloc] init];
  165. noticeVC.groupId = self.groupId;
  166. noticeVC.canEdit = NO;
  167. [self.navigationController pushViewController:noticeVC animated:YES];
  168. }
  169. break;
  170. case GROUPSETTING_FEEDBACK: // 反馈
  171. {
  172. KSChatComplainController *ctrl = [[KSChatComplainController alloc] init];
  173. ctrl.fromGroup = YES;
  174. ctrl.targetId = self.groupId;
  175. [self.navigationController pushViewController:ctrl animated:YES];
  176. }
  177. break;
  178. case GROUPSETTING_DISMISS: // 发消息
  179. {
  180. if (self.sourceModel) {
  181. [self dismissGroup];
  182. }
  183. else {
  184. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"您已不在当前群聊"];
  185. }
  186. // [self backAction];
  187. }
  188. break;
  189. case GROUPSETTING_GOURPINTRO:
  190. {
  191. if ([NSString isEmptyString:self.sourceModel.introduce]) {
  192. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"暂无群介绍"];
  193. return;
  194. }
  195. GroupIntroduceViewController *ctrl = [[GroupIntroduceViewController alloc] init];
  196. ctrl.groupId = self.groupId;
  197. ctrl.groupIntroduce = self.sourceModel.introduce;
  198. ctrl.canModify = NO;
  199. [self.navigationController pushViewController:ctrl animated:YES];
  200. }
  201. break;
  202. default:
  203. break;
  204. }
  205. }
  206. - (void)dismissGroup {
  207. MJWeakSelf;
  208. self.alertView = [GroupQuitAlert shareInstance];
  209. [self.alertView configTitle:@"退出群聊" desc:@"请确认是否要退出群聊?" callback:^(BOOL isSure) {
  210. if (isSure) {
  211. [weakSelf quitGroup];
  212. }
  213. }];
  214. [self.alertView showAlert];
  215. }
  216. - (void)quitGroup {
  217. [LOADING_MANAGER showCustomLoading:@"加载中..."];
  218. [KSNetworkingManager quitImGroupRequest:KS_POST groupId:self.groupId success:^(NSDictionary * _Nonnull dic) {
  219. [LOADING_MANAGER removeCustomLoading];
  220. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  221. [LOADING_MANAGER KSShowMsg:@"你已退出该群聊" promptCompletion:^{
  222. [self quitIMGroup];
  223. }];
  224. }
  225. else {
  226. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  227. }
  228. } faliure:^(NSError * _Nonnull error) {
  229. [LOADING_MANAGER removeCustomLoading];
  230. }];
  231. }
  232. - (void)backRootView {
  233. [self.navigationController popToRootViewControllerAnimated:YES];
  234. }
  235. - (void)quitIMGroup {
  236. [[V2TIMManager sharedInstance] quitGroup:self.groupId succ:^{
  237. [self clearConversation];
  238. [self backRootView];
  239. } fail:^(int code, NSString *desc) {
  240. [self clearConversation];
  241. [self backRootView];
  242. }];
  243. }
  244. - (void)clearConversation {
  245. MJWeakSelf;
  246. NSString *conversationID = [NSString stringWithFormat:@"group_%@", self.groupId];
  247. [[V2TIMManager sharedInstance] deleteConversation:conversationID
  248. succ:^{
  249. [weakSelf.navigationController popViewControllerAnimated:YES];
  250. }
  251. fail:nil];
  252. }
  253. - (void)messageSetting {
  254. V2TIMReceiveMessageOpt type = self.bodyView.isOn ? V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE : V2TIM_RECEIVE_MESSAGE;
  255. [[V2TIMManager sharedInstance] setGroupReceiveMessageOpt:self.groupId opt:type succ:^{
  256. NSLog(@"success");
  257. } fail:^(int code, NSString *desc) {
  258. dispatch_main_async_safe(^{
  259. [LOADING_MANAGER KSShowMsg:@"设置失败" promptCompletion:^{
  260. self.bodyView.isOn = !self.bodyView.isOn;
  261. }];
  262. });
  263. }];
  264. }
  265. - (NSMutableArray *)sourceArray {
  266. if (!_sourceArray) {
  267. _sourceArray = [NSMutableArray array];
  268. }
  269. return _sourceArray;
  270. }
  271. /*
  272. #pragma mark - Navigation
  273. // In a storyboard-based application, you will often want to do a little preparation before navigation
  274. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  275. // Get the new view controller using [segue destinationViewController].
  276. // Pass the selected object to the new view controller.
  277. }
  278. */
  279. @end