123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- //
- // GroupSettingViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/24.
- //
- #import "GroupSettingViewController.h"
- #import "GroupSettingBodyView.h"
- #import "KSSearchViewController.h"
- #import "KSChatComplainController.h"
- #import "GroupListModel.h"
- #import "GroupMemberModel.h"
- #import "GroupMemberViewController.h"
- #import "GroupNoticeViewController.h"
- #import "GroupApplyViewController.h"
- #import "ModifyNameViewController.h"
- #import "KSPublicAlertView.h"
- #import <ImSDK_Plus/V2TIMManager+Group.h>
- #import "CustomNavViewController.h"
- #import "TenantChooseMemberViewController.h"
- #import "TenantStuModel.h"
- #import "GroupBanListViewController.h"
- @interface GroupSettingViewController ()
- @property (nonatomic, strong) GroupListModel *sourceModel;
- @property (nonatomic, strong) GroupSettingBodyView *bodyView;
- @property (nonatomic, strong) NSMutableArray *sourceArray;
- @property (nonatomic, assign) NSInteger applyCount;
- @property (nonatomic, strong) KSPublicAlertView *alertView;
- @property (nonatomic, strong) NSString *groupRoleType;
- @property (nonatomic, assign) BOOL isMute;
- @end
- @implementation GroupSettingViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self allocTitle:@"群设置"];
- [self configUI];
- }
- - (void)configUI {
- self.scrollView.frame = CGRectMake(0, 0, KPortraitWidth, KPortraitHeight - kNaviBarHeight - iPhoneXSafeBottomMargin);
- self.bodyView = [GroupSettingBodyView shareInstance];
- CGFloat viewHeight = [self.bodyView getViewHeight:self.groupRoleType];
- CGFloat height = KPortraitHeight - kNaviBarHeight - iPhoneXSafeBottomMargin > viewHeight ? KPortraitHeight - kNaviBarHeight - iPhoneXSafeBottomMargin : viewHeight;
- self.bodyView.groupRoleType = @"";
- [self.scrollView addSubview:self.bodyView];
- [self.bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.scrollView.mas_top);
- make.bottom.mas_equalTo(self.scrollView.mas_bottom);
- make.height.mas_equalTo(height);
- }];
- }
- - (void)rightBtnClick {
- // 分享
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self requestData];
- [self getGroupMessageNotiferStatus];
- [self requestApplyMember];
- }
- - (void)requestApplyMember {
- [KSNetworkingManager imGroupMemberAuditListRequest:KS_POST groupId:self.groupId success:^(NSDictionary * _Nonnull dic) {
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
- self.applyCount = sourceArray.count;
- self.bodyView.applyMember = self.applyCount;
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)evaluateMessge {
-
- self.bodyView.groupRoleType = self.groupRoleType;
- CGFloat viewHeight = [self.bodyView getViewHeight:self.groupRoleType];
- CGFloat height = kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin > viewHeight ? kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin : viewHeight;
- [self.bodyView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(height);
- }];
- NSMutableArray *memberArray = [NSMutableArray array];
- for (GroupMemberModel *model in self.sourceArray) {
- if (model.isAdmin) {
- [memberArray insertObject:model atIndex:0];
- }
- else {
- [memberArray addObject:model];
- }
- }
- self.sourceArray = [NSMutableArray arrayWithArray:memberArray];
- [self.bodyView evaluateStudentArray:self.sourceArray];
- }
- - (void)requestData {
- [KSNetworkingManager queryGroupDetail:KS_POST groupId:self.groupId success:^(NSDictionary * _Nonnull dic) {
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSDictionary *subDic = [dic ks_dictionaryValueForKey:@"data"];
- self.sourceModel = [[GroupListModel alloc] initWithDictionary:subDic];
- NSString *jsonString = [subDic ks_stringValueForKey:@"configJson"];
- if (![NSString isEmptyString:jsonString]) {
- NSData *jsonData = [jsonString mj_JSONData];
- NSDictionary *configJson = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
- self.isMute = [configJson ks_boolValueForKey:@"mute"];
- }
- else {
- self.isMute = NO;
- }
- [self refreshUI];
- }
- else if ([dic ks_integerValueForKey:@"code"] == 204) {
- [LOADING_MANAGER KSShowMsg:@"获取群信息失败" promptCompletion:^{
- [self backAction];
- }];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- [self getGroupStudent];
-
- } faliure:^(NSError * _Nonnull error) {
- [self getGroupStudent];
- }];
- }
- - (void)getGroupStudent {
- [self.sourceArray removeAllObjects];
- [KSNetworkingManager imGroupMemberAllRequest:KS_POST groupId:self.groupId success:^(NSDictionary * _Nonnull dic) {
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
- for (NSDictionary *parm in sourceArray) {
- GroupMemberModel *model = [[GroupMemberModel alloc] initWithDictionary:parm];
- if ([model.imUserId isEqualToString:UserDefault(IM_USERID)]) {
- self.groupRoleType = model.groupRoleType;
- }
- [self.sourceArray addObject:model];
- }
- [self evaluateMessge];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)getGroupMessageNotiferStatus {
- [[V2TIMManager sharedInstance] getGroupsInfo:@[self.groupId] succ:^(NSArray<V2TIMGroupInfoResult *> * groupResultList) {
- for (V2TIMGroupInfoResult *result in groupResultList) {
- V2TIMGroupInfo *info = result.info;
- NSLog(@"recvOpt, %d", (int)info.recvOpt);
- if (info.recvOpt == V2TIM_RECEIVE_MESSAGE) {
- self.bodyView.isOn = NO;
- }
- else {
- self.bodyView.isOn = YES;
- }
- }
- } fail:^(int code, NSString *desc) {
- NSLog(@"failure, code:%d, desc:%@", code, desc);
-
- }];
- }
- - (void)refreshUI {
- self.bodyView.isMute = self.isMute;
- MJWeakSelf;
- [self.bodyView configWithSource:self.sourceModel callback:^(GROUPSETTING type) {
- [weakSelf operationWithType:type];
- }];
- }
- - (void)operationWithType:(GROUPSETTING)type {
- switch (type) {
- case GROUPSETTING_PERSON: // 群成员列表
- {
- GroupMemberViewController *memberVC = [[GroupMemberViewController alloc] init];
- memberVC.groupId = self.groupId;
- [self.navigationController pushViewController:memberVC animated:YES];
- }
- break;
- case GROUPSETTING_APPLY: // 入群申请列表
- {
- GroupApplyViewController *applyCtrl = [[GroupApplyViewController alloc] init];
- applyCtrl.groupId = self.groupId;
- [self.navigationController pushViewController:applyCtrl animated:YES];
- }
- break;
- case GROUPSETTING_GROUP: // 修改群名称
- {
- ModifyNameViewController *modifyCtrl = [[ModifyNameViewController alloc] init];
- modifyCtrl.groupId = self.groupId;
- modifyCtrl.preNickName = self.sourceModel.name;
- [self.navigationController pushViewController:modifyCtrl animated:YES];
- }
- break;
- case GROUPSETTING_MESSAGESEARCH:
- {
- KSSearchViewController *vc = [[KSSearchViewController alloc] init];
- vc.groupId = self.groupId;
- CustomNavViewController *nav = [[CustomNavViewController alloc] initWithRootViewController:(UIViewController *)vc];
- nav.modalPresentationStyle = UIModalPresentationFullScreen;
-
- UIViewController *parentVC = self.navigationController;
- if (parentVC) {
- [parentVC presentViewController:nav animated:NO completion:nil];
- }
- }
- break;
- case GROUPSETTING_SETTING: // 消息提醒
- {
- [self messageSetting];
- }
- break;
- case GROUPSETTING_NOTICE: // 群公告
- {
- GroupNoticeViewController *noticeVC = [[GroupNoticeViewController alloc] init];
- noticeVC.groupId = self.groupId;
- noticeVC.canEdit = YES;
- [self.navigationController pushViewController:noticeVC animated:YES];
- }
- break;
- case GROUPSETTING_FEEDBACK: // 反馈
- {
- KSChatComplainController *ctrl = [[KSChatComplainController alloc] init];
- ctrl.fromGroup = YES;
- ctrl.targetId = self.groupId;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case GROUPSETTING_DISMISS: // 解散群聊
- {
- [self showDismissAlert];
- }
- break;
- case GROUPSETTING_ADDMENBER: // 添加群成员
- {
- NSMutableArray *memberArray = [NSMutableArray array];
- for (GroupMemberModel *model in self.sourceArray) {
- [memberArray addObject:model.imUserId];
- }
- TenantChooseMemberViewController *ctrl = [[TenantChooseMemberViewController alloc] init];
- ctrl.groupMemberIdArray = memberArray;
- MJWeakSelf;
- [ctrl chooseMemberCallback:^(NSMutableArray * _Nullable memberArray) {
- [weakSelf addMember:memberArray];
- }];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case GROUPSETTING_MUTE: // 禁言操作
- {
- if (self.sourceModel) {
- [self muteAction];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"您已不在当前群聊"];
- }
- }
- break;
- case GROUPSETTING_BANLIST: // 禁言列表
- {
- GroupBanListViewController *ctrl = [[GroupBanListViewController alloc] init];
- ctrl.groupId = self.groupId;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- default:
- break;
- }
- }
- - (void)muteAction {
- BOOL isMute = !self.isMute;
- [KSNetworkingManager imGroupMuteAllRequest:KS_POST groupId:self.groupId muteAll:isMute success:^(NSDictionary * _Nonnull dic) {
- if ([dic ks_integerValueForKey:@"code"] == 200) {
- [LOADING_MANAGER KSShowMsg:@"设置成功" promptCompletion:^{
- [self requestData];
- }];
- }
- else {
- self.bodyView.isMute = self.isMute;
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- self.bodyView.isMute = self.isMute;
- }];
- }
- - (void)addMember:(NSMutableArray *)array {
- if (array.count == 0) {
- return;
- }
- NSMutableArray *stuIdArray = [NSMutableArray array];
- for (TenantStuModel *model in array) {
- [stuIdArray addObject:model.imUserId];
- }
- [LOADING_MANAGER showHUD];
- [KSNetworkingManager tenantImGroupAddMemberRequest:KS_POST groupId:self.groupId studentIdArray:stuIdArray success:^(NSDictionary * _Nonnull dic) {
- [LOADING_MANAGER removeHUD];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- [self requestData];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- [LOADING_MANAGER removeHUD];
- }];
- }
- - (void)showDismissAlert {
- MJWeakSelf;
- self.alertView = [KSPublicAlertView shareInstanceWithTitle:@"提示" descMessage:@"确认解散群聊吗" leftTitle:@"取消" rightTitle:@"确定" cancelAction:^{
-
- } sureAction:^{
- [weakSelf dismissGroup];
- }];
- }
- - (void)dismissGroup {
-
- [KSNetworkingManager imGroupDismiss:KS_POST groupId:self.groupId success:^(NSDictionary * _Nonnull dic) {
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
-
- [LOADING_MANAGER KSShowMsg:@"群已解散" promptCompletion:^{
- [self removeCurrentConversation];
- [self.navigationController popToRootViewControllerAnimated:YES];
- }];
- }
- else {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)removeCurrentConversation {
- MJWeakSelf;
- NSString *conversationID = [NSString stringWithFormat:@"group_%@", self.groupId];
- [[V2TIMManager sharedInstance] deleteConversation:conversationID
- succ:^{
- [weakSelf.navigationController popViewControllerAnimated:YES];
- }
- fail:nil];
- }
- - (void)messageSetting {
- V2TIMReceiveMessageOpt type = self.bodyView.isOn ? V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE : V2TIM_RECEIVE_MESSAGE;
- [[V2TIMManager sharedInstance] setGroupReceiveMessageOpt:self.groupId opt:type succ:^{
- NSLog(@"success");
- } fail:^(int code, NSString *desc) {
- dispatch_main_async_safe(^{
- [LOADING_MANAGER KSShowMsg:@"设置失败" promptCompletion:^{
- self.bodyView.isOn = !self.bodyView.isOn;
- }];
- });
- }];
- }
- - (NSMutableArray *)sourceArray {
- if (!_sourceArray) {
- _sourceArray = [NSMutableArray array];
- }
- return _sourceArray;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|