123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- #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"
- @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;
- @end
- @implementation GroupSettingViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- [self allocTitle:@"群设置"];
- [self configUI];
- }
- - (void)configUI {
- self.scrollView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin);
- self.bodyView = [GroupSettingBodyView shareInstance];
- CGFloat height = kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin > 700 ? kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin : 700;
- self.bodyView.frame = CGRectMake(0, 0, kScreenWidth, height);
- [self.scrollView addSubview:self.bodyView];
- [self.scrollView setContentSize:CGSizeMake(kScreenWidth, 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 {
- 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];
- [self refreshUI];
- }
- 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];
- [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);
- [LOADING_MANAGER KSShowMsg:@"获取群信息失败" promptCompletion:^{
- [self backAction];
- }];
- }];
- }
- - (void)refreshUI {
- 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;
- default:
- break;
- }
- }
- - (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.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;
- }
- @end
|