增加换肤功能
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
|
||||
// Created by Tencent on 2023/06/09.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
#import <Foundation/Foundation.h>
|
||||
@import ImSDK_Plus;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface V2TIMGroupInfo (TUIDataProvider)
|
||||
|
||||
- (BOOL)isMeOwner;
|
||||
- (BOOL)isPrivate;
|
||||
- (BOOL)canInviteMember;
|
||||
- (BOOL)canRemoveMember;
|
||||
- (BOOL)canDismissGroup;
|
||||
- (BOOL)canSupportSetAdmain;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,46 @@
|
||||
|
||||
// Created by Tencent on 2023/06/09.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
|
||||
#import <TUICore/TUIGlobalization.h>
|
||||
#import "TIMGroupInfo+TUIDataProvider.h"
|
||||
|
||||
@implementation V2TIMGroupInfo (TUIDataProvider)
|
||||
|
||||
- (BOOL)isMeOwner {
|
||||
return [self.owner isEqualToString:[[V2TIMManager sharedInstance] getLoginUser]] || (self.role == V2TIM_GROUP_MEMBER_ROLE_ADMIN);
|
||||
}
|
||||
|
||||
- (BOOL)isPrivate {
|
||||
return [self.groupType isEqualToString:@"Work"];
|
||||
}
|
||||
|
||||
- (BOOL)canInviteMember {
|
||||
return self.groupApproveOpt != V2TIM_GROUP_ADD_FORBID;
|
||||
}
|
||||
|
||||
- (BOOL)canRemoveMember {
|
||||
return [self isMeOwner] && (self.memberCount > 1);
|
||||
}
|
||||
|
||||
- (BOOL)canDismissGroup {
|
||||
if ([self isPrivate]) {
|
||||
return NO;
|
||||
} else {
|
||||
if ([self.owner isEqualToString:[[V2TIMManager sharedInstance] getLoginUser]] || (self.role == V2TIM_GROUP_MEMBER_ROLE_SUPER)) {
|
||||
return YES;
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)canSupportSetAdmain {
|
||||
BOOL isMeSuper = [self.owner isEqualToString:[[V2TIMManager sharedInstance] getLoginUser]] || (self.role == V2TIM_GROUP_MEMBER_ROLE_SUPER);
|
||||
|
||||
BOOL isCurrentGroupTypeSupportSetAdmain = ([self.groupType isEqualToString:@"Public"] || [self.groupType isEqualToString:@"Meeting"] ||
|
||||
[self.groupType isEqualToString:@"Community"] || [self.groupType isEqualToString:@"Private"]);
|
||||
|
||||
return isMeSuper && isCurrentGroupTypeSupportSetAdmain && (self.memberCount > 1);
|
||||
}
|
||||
@end
|
||||
63
TUIKit/TUIGroup/BaseDataProvider/TUIGroupInfoDataProvider.h
Normal file
63
TUIKit/TUIGroup/BaseDataProvider/TUIGroupInfoDataProvider.h
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
// Created by Tencent on 2023/06/09.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
|
||||
|
||||
@import Foundation;
|
||||
@import UIKit;
|
||||
@import ImSDK_Plus;
|
||||
|
||||
@class TUICommonCellData;
|
||||
@class TUICommonTextCell;
|
||||
@class TUICommonSwitchCell;
|
||||
@class TUIButtonCell;
|
||||
@class TUIProfileCardCellData;
|
||||
@class TUIProfileCardCell;
|
||||
@class TUIGroupMemberCellData;
|
||||
@class TUIGroupMembersCellData;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol TUIGroupInfoDataProviderDelegate <NSObject>
|
||||
- (void)didSelectMembers;
|
||||
- (void)didSelectGroupNick:(TUICommonTextCell *)cell;
|
||||
- (void)didSelectAddOption:(UITableViewCell *)cell;
|
||||
- (void)didSelectCommon;
|
||||
- (void)didSelectOnNotDisturb:(TUICommonSwitchCell *)cell;
|
||||
- (void)didSelectOnTop:(TUICommonSwitchCell *)cell;
|
||||
- (void)didSelectOnFoldConversation:(TUICommonSwitchCell *)cell;
|
||||
- (void)didSelectOnChangeBackgroundImage:(TUICommonTextCell *)cell;
|
||||
- (void)didDeleteGroup:(TUIButtonCell *)cell;
|
||||
- (void)didClearAllHistory:(TUIButtonCell *)cell;
|
||||
- (void)didSelectGroupManage;
|
||||
- (void)didSelectGroupNotice;
|
||||
- (void)didTransferGroup:(TUIButtonCell *)cell;
|
||||
@end
|
||||
|
||||
@interface TUIGroupInfoDataProvider : NSObject
|
||||
@property(nonatomic, weak) id<TUIGroupInfoDataProviderDelegate> delegate;
|
||||
@property(nonatomic, strong) V2TIMGroupInfo *groupInfo;
|
||||
@property(nonatomic, strong) NSMutableArray *dataList;
|
||||
@property(nonatomic, strong) NSMutableArray<TUIGroupMemberCellData *> *membersData;
|
||||
@property(nonatomic, strong) TUIGroupMembersCellData *groupMembersCellData;
|
||||
@property(nonatomic, strong, readonly) V2TIMGroupMemberFullInfo *selfInfo;
|
||||
@property(nonatomic, strong, readonly) TUIProfileCardCellData *profileCellData;
|
||||
|
||||
- (instancetype)initWithGroupID:(NSString *)groupID;
|
||||
- (void)loadData;
|
||||
- (void)updateGroupInfo;
|
||||
- (void)setGroupAddOpt:(V2TIMGroupAddOpt)opt;
|
||||
- (void)setGroupApproveOpt:(V2TIMGroupAddOpt)opt;
|
||||
- (void)setGroupReceiveMessageOpt:(V2TIMReceiveMessageOpt)opt Succ:(V2TIMSucc)succ fail:(V2TIMFail)fail;
|
||||
- (void)setGroupName:(NSString *)groupName;
|
||||
- (void)setGroupNotification:(NSString *)notification;
|
||||
- (void)setGroupMemberNameCard:(NSString *)nameCard;
|
||||
- (void)dismissGroup:(V2TIMSucc)succ fail:(V2TIMFail)fail;
|
||||
- (void)quitGroup:(V2TIMSucc)succ fail:(V2TIMFail)fail;
|
||||
- (void)clearAllHistory:(V2TIMSucc)succ fail:(V2TIMFail)fail;
|
||||
- (void)updateGroupAvatar:(NSString *)url succ:(V2TIMSucc)succ fail:(V2TIMFail)fail;
|
||||
- (void)transferGroupOwner:(NSString *)groupID member:(NSString *)userID succ:(V2TIMSucc)succ fail:(V2TIMFail)fail;
|
||||
+ (BOOL)isMeOwner:(V2TIMGroupInfo *)groupInfo;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
720
TUIKit/TUIGroup/BaseDataProvider/TUIGroupInfoDataProvider.m
Normal file
720
TUIKit/TUIGroup/BaseDataProvider/TUIGroupInfoDataProvider.m
Normal file
@@ -0,0 +1,720 @@
|
||||
|
||||
// Created by Tencent on 2023/06/09.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
|
||||
#import <TIMCommon/TIMCommonModel.h>
|
||||
#import <TIMCommon/TIMDefine.h>
|
||||
#import "TIMGroupInfo+TUIDataProvider.h"
|
||||
#import "TUIGroupInfoDataProvider.h"
|
||||
#import "TUIGroupMemberCellData.h"
|
||||
#import "TUIGroupMembersCellData.h"
|
||||
#import "TUIGroupNoticeCell.h"
|
||||
#import "TUIGroupConfig.h"
|
||||
|
||||
@interface TUIGroupInfoDataProvider () <V2TIMGroupListener>
|
||||
@property(nonatomic, strong) TUICommonTextCellData *addOptionData;
|
||||
@property(nonatomic, strong) TUICommonTextCellData *inviteOptionData;
|
||||
@property(nonatomic, strong) TUICommonTextCellData *groupNickNameCellData;
|
||||
@property(nonatomic, strong, readwrite) TUIProfileCardCellData *profileCellData;
|
||||
@property(nonatomic, strong) V2TIMGroupMemberFullInfo *selfInfo;
|
||||
@property(nonatomic, strong) NSString *groupID;
|
||||
@end
|
||||
|
||||
@implementation TUIGroupInfoDataProvider
|
||||
|
||||
- (instancetype)initWithGroupID:(NSString *)groupID {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.groupID = groupID;
|
||||
[[V2TIMManager sharedInstance] addGroupListener:self];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark V2TIMGroupListener
|
||||
- (void)onMemberEnter:(NSString *)groupID memberList:(NSArray<V2TIMGroupMemberInfo *> *)memberList {
|
||||
[self loadData];
|
||||
}
|
||||
|
||||
- (void)onMemberLeave:(NSString *)groupID member:(V2TIMGroupMemberInfo *)member {
|
||||
[self loadData];
|
||||
}
|
||||
|
||||
- (void)onMemberInvited:(NSString *)groupID opUser:(V2TIMGroupMemberInfo *)opUser memberList:(NSArray<V2TIMGroupMemberInfo *> *)memberList {
|
||||
[self loadData];
|
||||
}
|
||||
|
||||
- (void)onMemberKicked:(NSString *)groupID opUser:(V2TIMGroupMemberInfo *)opUser memberList:(NSArray<V2TIMGroupMemberInfo *> *)memberList {
|
||||
[self loadData];
|
||||
}
|
||||
|
||||
- (void)onGroupInfoChanged:(NSString *)groupID changeInfoList:(NSArray<V2TIMGroupChangeInfo *> *)changeInfoList {
|
||||
if (![groupID isEqualToString:self.groupID]) {
|
||||
return;
|
||||
}
|
||||
|
||||
[self loadData];
|
||||
}
|
||||
|
||||
- (void)loadData {
|
||||
if (self.groupID.length == 0) {
|
||||
[TUITool makeToastError:ERR_INVALID_PARAMETERS msg:@"invalid groupID"];
|
||||
return;
|
||||
}
|
||||
dispatch_group_t group = dispatch_group_create();
|
||||
dispatch_group_enter(group);
|
||||
[self getGroupInfo:^{
|
||||
dispatch_group_leave(group);
|
||||
}];
|
||||
|
||||
dispatch_group_enter(group);
|
||||
[self getGroupMembers:^{
|
||||
dispatch_group_leave(group);
|
||||
}];
|
||||
|
||||
dispatch_group_enter(group);
|
||||
[self getSelfInfoInGroup:^{
|
||||
dispatch_group_leave(group);
|
||||
}];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
|
||||
[weakSelf setupData];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)updateGroupInfo {
|
||||
@weakify(self);
|
||||
[[V2TIMManager sharedInstance] getGroupsInfo:@[ self.groupID ]
|
||||
succ:^(NSArray<V2TIMGroupInfoResult *> *groupResultList) {
|
||||
@strongify(self);
|
||||
if (groupResultList.count == 1) {
|
||||
self.groupInfo = groupResultList[0].info;
|
||||
[self setupData];
|
||||
}
|
||||
}
|
||||
fail:^(int code, NSString *msg) {
|
||||
[TUITool makeToastError:code msg:msg];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)transferGroupOwner:(NSString *)groupID member:(NSString *)userID succ:(V2TIMSucc)succ fail:(V2TIMFail)fail {
|
||||
[V2TIMManager.sharedInstance transferGroupOwner:groupID
|
||||
member:userID
|
||||
succ:^{
|
||||
succ();
|
||||
}
|
||||
fail:^(int code, NSString *desc) {
|
||||
fail(code, desc);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)updateGroupAvatar:(NSString *)url succ:(V2TIMSucc)succ fail:(V2TIMFail)fail {
|
||||
V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
|
||||
info.groupID = self.groupID;
|
||||
info.faceURL = url;
|
||||
[V2TIMManager.sharedInstance setGroupInfo:info succ:succ fail:fail];
|
||||
}
|
||||
|
||||
- (void)getGroupInfo:(dispatch_block_t)callback {
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[[V2TIMManager sharedInstance] getGroupsInfo:@[ self.groupID ]
|
||||
succ:^(NSArray<V2TIMGroupInfoResult *> *groupResultList) {
|
||||
weakSelf.groupInfo = groupResultList.firstObject.info;
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
fail:^(int code, NSString *msg) {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
[TUITool makeToastError:code msg:msg];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)getGroupMembers:(dispatch_block_t)callback {
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[[V2TIMManager sharedInstance] getGroupMemberList:self.groupID
|
||||
filter:V2TIM_GROUP_MEMBER_FILTER_ALL
|
||||
nextSeq:0
|
||||
succ:^(uint64_t nextSeq, NSArray<V2TIMGroupMemberFullInfo *> *memberList) {
|
||||
NSMutableArray *membersData = [NSMutableArray array];
|
||||
for (V2TIMGroupMemberFullInfo *fullInfo in memberList) {
|
||||
TUIGroupMemberCellData *data = [[TUIGroupMemberCellData alloc] init];
|
||||
data.identifier = fullInfo.userID;
|
||||
data.name = fullInfo.userID;
|
||||
data.avatarUrl = fullInfo.faceURL;
|
||||
if (fullInfo.nameCard.length > 0) {
|
||||
data.name = fullInfo.nameCard;
|
||||
} else if (fullInfo.friendRemark.length > 0) {
|
||||
data.name = fullInfo.friendRemark;
|
||||
} else if (fullInfo.nickName.length > 0) {
|
||||
data.name = fullInfo.nickName;
|
||||
}
|
||||
[membersData addObject:data];
|
||||
}
|
||||
|
||||
|
||||
weakSelf.membersData = membersData;
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
fail:^(int code, NSString *msg) {
|
||||
[TUITool makeToastError:code msg:msg];
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)getSelfInfoInGroup:(dispatch_block_t)callback {
|
||||
NSString *loginUserID = [[V2TIMManager sharedInstance] getLoginUser];
|
||||
if (loginUserID.length == 0) {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
return;
|
||||
}
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[[V2TIMManager sharedInstance] getGroupMembersInfo:self.groupID
|
||||
memberList:@[ loginUserID ]
|
||||
succ:^(NSArray<V2TIMGroupMemberFullInfo *> *memberList) {
|
||||
for (V2TIMGroupMemberFullInfo *item in memberList) {
|
||||
if ([item.userID isEqualToString:loginUserID]) {
|
||||
weakSelf.selfInfo = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
fail:^(int code, NSString *desc) {
|
||||
[TUITool makeToastError:code msg:desc];
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setupData {
|
||||
NSMutableArray *dataList = [NSMutableArray array];
|
||||
if (self.groupInfo) {
|
||||
NSMutableArray *commonArray = [NSMutableArray array];
|
||||
TUIProfileCardCellData *commonData = [[TUIProfileCardCellData alloc] init];
|
||||
commonData.avatarImage = DefaultGroupAvatarImageByGroupType(self.groupInfo.groupType);
|
||||
commonData.avatarUrl = [NSURL URLWithString:self.groupInfo.faceURL];
|
||||
commonData.name = self.groupInfo.groupName;
|
||||
commonData.identifier = self.groupInfo.groupID;
|
||||
commonData.signature = self.groupInfo.notification;
|
||||
|
||||
if ([TUIGroupInfoDataProvider isMeOwner:self.groupInfo] || [self.groupInfo isPrivate]) {
|
||||
commonData.cselector = @selector(didSelectCommon);
|
||||
commonData.showAccessory = YES;
|
||||
}
|
||||
self.profileCellData = commonData;
|
||||
|
||||
[commonArray addObject:commonData];
|
||||
[dataList addObject:commonArray];
|
||||
|
||||
NSMutableArray *memberArray = [NSMutableArray array];
|
||||
if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Members]) {
|
||||
TUICommonTextCellData *countData = [[TUICommonTextCellData alloc] init];
|
||||
countData.key = TIMCommonLocalizableString(TUIKitGroupProfileMember);
|
||||
countData.value = [NSString stringWithFormat:TIMCommonLocalizableString(TUIKitGroupProfileMemberCount), self.groupInfo.memberCount];
|
||||
countData.cselector = @selector(didSelectMembers);
|
||||
countData.showAccessory = YES;
|
||||
[memberArray addObject:countData];
|
||||
|
||||
NSMutableArray *tmpArray = [self getShowMembers:self.membersData];
|
||||
TUIGroupMembersCellData *membersData = [[TUIGroupMembersCellData alloc] init];
|
||||
membersData.members = tmpArray;
|
||||
[memberArray addObject:membersData];
|
||||
self.groupMembersCellData = membersData;
|
||||
[dataList addObject:memberArray];
|
||||
}
|
||||
|
||||
// group info
|
||||
NSMutableArray *groupInfoArray = [NSMutableArray array];
|
||||
|
||||
if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Notice]) {
|
||||
TUIGroupNoticeCellData *notice = [[TUIGroupNoticeCellData alloc] init];
|
||||
notice.name = TIMCommonLocalizableString(TUIKitGroupNotice);
|
||||
notice.desc = self.groupInfo.notification ?: TIMCommonLocalizableString(TUIKitGroupNoticeNull);
|
||||
notice.target = self;
|
||||
notice.selector = @selector(didSelectNotice);
|
||||
[groupInfoArray addObject:notice];
|
||||
}
|
||||
|
||||
if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Members]) {
|
||||
TUICommonTextCellData *manageData = [[TUICommonTextCellData alloc] init];
|
||||
manageData.key = TIMCommonLocalizableString(TUIKitGroupProfileManage);
|
||||
manageData.value = @"";
|
||||
manageData.showAccessory = YES;
|
||||
manageData.cselector = @selector(didSelectGroupManage);
|
||||
if (([TUIGroupInfoDataProvider isMeOwner:self.groupInfo])) {
|
||||
[groupInfoArray addObject:manageData];
|
||||
}
|
||||
}
|
||||
if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Manage]) {
|
||||
TUICommonTextCellData *typeData = [[TUICommonTextCellData alloc] init];
|
||||
typeData.key = TIMCommonLocalizableString(TUIKitGroupProfileType);
|
||||
typeData.value = [TUIGroupInfoDataProvider getGroupTypeName:self.groupInfo];
|
||||
[groupInfoArray addObject:typeData];
|
||||
|
||||
TUICommonTextCellData *addOptionData = [[TUICommonTextCellData alloc] init];
|
||||
addOptionData.key = TIMCommonLocalizableString(TUIKitGroupProfileJoinType);
|
||||
|
||||
if ([self.groupInfo.groupType isEqualToString:@"Work"]) {
|
||||
addOptionData.value = TIMCommonLocalizableString(TUIKitGroupProfileInviteJoin);
|
||||
} else if ([self.groupInfo.groupType isEqualToString:@"Meeting"]) {
|
||||
addOptionData.value = TIMCommonLocalizableString(TUIKitGroupProfileAutoApproval);
|
||||
} else {
|
||||
if ([TUIGroupInfoDataProvider isMeOwner:self.groupInfo]) {
|
||||
addOptionData.cselector = @selector(didSelectAddOption:);
|
||||
addOptionData.showAccessory = YES;
|
||||
}
|
||||
addOptionData.value = [TUIGroupInfoDataProvider getAddOption:self.groupInfo];
|
||||
}
|
||||
[groupInfoArray addObject:addOptionData];
|
||||
self.addOptionData = addOptionData;
|
||||
|
||||
TUICommonTextCellData *inviteOptionData = [[TUICommonTextCellData alloc] init];
|
||||
inviteOptionData.key = TIMCommonLocalizableString(TUIKitGroupProfileInviteType);
|
||||
if ([TUIGroupInfoDataProvider isMeOwner:self.groupInfo]) {
|
||||
inviteOptionData.cselector = @selector(didSelectAddOption:);
|
||||
inviteOptionData.showAccessory = YES;
|
||||
}
|
||||
inviteOptionData.value = [TUIGroupInfoDataProvider getApproveOption:self.groupInfo];
|
||||
[groupInfoArray addObject:inviteOptionData];
|
||||
self.inviteOptionData = inviteOptionData;
|
||||
[dataList addObject:groupInfoArray];
|
||||
|
||||
}
|
||||
|
||||
// personal info
|
||||
if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Alias]) {
|
||||
TUICommonTextCellData *nickData = [[TUICommonTextCellData alloc] init];
|
||||
nickData.key = TIMCommonLocalizableString(TUIKitGroupProfileAlias);
|
||||
nickData.value = self.selfInfo.nameCard;
|
||||
nickData.cselector = @selector(didSelectGroupNick:);
|
||||
nickData.showAccessory = YES;
|
||||
self.groupNickNameCellData = nickData;
|
||||
[dataList addObject:@[ nickData ]];
|
||||
}
|
||||
|
||||
TUICommonSwitchCellData *markFold = [[TUICommonSwitchCellData alloc] init];
|
||||
TUICommonSwitchCellData *switchData = [[TUICommonSwitchCellData alloc] init];
|
||||
if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_MuteAndPin]) {
|
||||
NSMutableArray *personalArray = [NSMutableArray array];
|
||||
|
||||
TUICommonSwitchCellData *messageSwitchData = [[TUICommonSwitchCellData alloc] init];
|
||||
|
||||
if (![self.groupInfo.groupType isEqualToString:GroupType_Meeting]) {
|
||||
messageSwitchData.on = (self.groupInfo.recvOpt == V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE);
|
||||
messageSwitchData.title = TIMCommonLocalizableString(TUIKitGroupProfileMessageDoNotDisturb);
|
||||
messageSwitchData.cswitchSelector = @selector(didSelectOnNotDisturb:);
|
||||
[personalArray addObject:messageSwitchData];
|
||||
}
|
||||
|
||||
|
||||
|
||||
markFold.title = TIMCommonLocalizableString(TUIKitConversationMarkFold);
|
||||
|
||||
markFold.displaySeparatorLine = YES;
|
||||
|
||||
markFold.cswitchSelector = @selector(didSelectOnFoldConversation:);
|
||||
if (messageSwitchData.on) {
|
||||
[personalArray addObject:markFold];
|
||||
}
|
||||
|
||||
switchData.title = TIMCommonLocalizableString(TUIKitGroupProfileStickyOnTop);
|
||||
[personalArray addObject:switchData];
|
||||
|
||||
[dataList addObject:personalArray];
|
||||
}
|
||||
|
||||
if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Background]) {
|
||||
TUICommonTextCellData *changeBackgroundImageItem = [[TUICommonTextCellData alloc] init];
|
||||
changeBackgroundImageItem.key = TIMCommonLocalizableString(ProfileSetBackgroundImage);
|
||||
changeBackgroundImageItem.cselector = @selector(didSelectOnChangeBackgroundImage:);
|
||||
changeBackgroundImageItem.showAccessory = YES;
|
||||
[dataList addObject:@[ changeBackgroundImageItem ]];
|
||||
}
|
||||
|
||||
NSMutableArray *buttonArray = [NSMutableArray array];
|
||||
if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_ClearChatHistory]) {
|
||||
TUIButtonCellData *clearHistory = [[TUIButtonCellData alloc] init];
|
||||
clearHistory.title = TIMCommonLocalizableString(TUIKitClearAllChatHistory);
|
||||
clearHistory.style = ButtonRedText;
|
||||
clearHistory.cbuttonSelector = @selector(didClearAllHistory:);
|
||||
[buttonArray addObject:clearHistory];
|
||||
}
|
||||
|
||||
if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_DeleteAndLeave]) {
|
||||
TUIButtonCellData *quitButton = [[TUIButtonCellData alloc] init];
|
||||
quitButton.title = TIMCommonLocalizableString(TUIKitGroupProfileDeleteAndExit);
|
||||
quitButton.style = ButtonRedText;
|
||||
quitButton.cbuttonSelector = @selector(didDeleteGroup:);
|
||||
[buttonArray addObject:quitButton];
|
||||
}
|
||||
|
||||
if ([self.class isMeSuper:self.groupInfo] &&
|
||||
![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Transfer]) {
|
||||
TUIButtonCellData *transferButton = [[TUIButtonCellData alloc] init];
|
||||
transferButton.title = TIMCommonLocalizableString(TUIKitGroupTransferOwner);
|
||||
transferButton.style = ButtonRedText;
|
||||
transferButton.cbuttonSelector = @selector(didTransferGroup:);
|
||||
[buttonArray addObject:transferButton];
|
||||
}
|
||||
|
||||
if ([self.groupInfo canDismissGroup] &&
|
||||
![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Dismiss]) {
|
||||
TUIButtonCellData *deletebutton = [[TUIButtonCellData alloc] init];
|
||||
deletebutton.title = TIMCommonLocalizableString(TUIKitGroupProfileDissolve);
|
||||
deletebutton.style = ButtonRedText;
|
||||
deletebutton.cbuttonSelector = @selector(didDeleteGroup:);
|
||||
[buttonArray addObject:deletebutton];
|
||||
}
|
||||
|
||||
if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Report]) {
|
||||
TUIButtonCellData *reportButton = [[TUIButtonCellData alloc] init];
|
||||
reportButton.title = TIMCommonLocalizableString(TUIKitGroupProfileReport);
|
||||
reportButton.style = ButtonRedText;
|
||||
reportButton.cbuttonSelector = @selector(didReportGroup:);
|
||||
[buttonArray addObject:reportButton];
|
||||
}
|
||||
|
||||
TUIButtonCellData *lastCellData = [buttonArray lastObject];
|
||||
lastCellData.hideSeparatorLine = YES;
|
||||
[dataList addObject:buttonArray];
|
||||
|
||||
#ifndef SDKPlaceTop
|
||||
#define SDKPlaceTop
|
||||
#endif
|
||||
#ifdef SDKPlaceTop
|
||||
@weakify(self);
|
||||
[V2TIMManager.sharedInstance getConversation:[NSString stringWithFormat:@"group_%@", self.groupID]
|
||||
succ:^(V2TIMConversation *conv) {
|
||||
@strongify(self);
|
||||
|
||||
markFold.on = [self.class isMarkedByFoldType:conv.markList];
|
||||
|
||||
switchData.cswitchSelector = @selector(didSelectOnTop:);
|
||||
switchData.on = conv.isPinned;
|
||||
|
||||
if (markFold.on) {
|
||||
switchData.on = NO;
|
||||
switchData.disableChecked = YES;
|
||||
}
|
||||
|
||||
self.dataList = dataList;
|
||||
}
|
||||
fail:^(int code, NSString *desc) {
|
||||
NSLog(@"");
|
||||
}];
|
||||
#else
|
||||
if ([[[TUIConversationPin sharedInstance] topConversationList] containsObject:[NSString stringWithFormat:@"group_%@", self.groupID]]) {
|
||||
switchData.on = YES;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didSelectMembers {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectMembers)]) {
|
||||
[self.delegate didSelectMembers];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didSelectGroupNick:(TUICommonTextCell *)cell {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectGroupNick:)]) {
|
||||
[self.delegate didSelectGroupNick:cell];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didSelectAddOption:(UITableViewCell *)cell {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectAddOption:)]) {
|
||||
[self.delegate didSelectAddOption:cell];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didSelectCommon {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectCommon)]) {
|
||||
[self.delegate didSelectCommon];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didSelectOnNotDisturb:(TUICommonSwitchCell *)cell {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectOnNotDisturb:)]) {
|
||||
[self.delegate didSelectOnNotDisturb:cell];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didSelectOnTop:(TUICommonSwitchCell *)cell {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectOnTop:)]) {
|
||||
[self.delegate didSelectOnTop:cell];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didSelectOnFoldConversation:(TUICommonSwitchCell *)cell {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectOnFoldConversation:)]) {
|
||||
[self.delegate didSelectOnFoldConversation:cell];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didSelectOnChangeBackgroundImage:(TUICommonTextCell *)cell {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectOnChangeBackgroundImage:)]) {
|
||||
[self.delegate didSelectOnChangeBackgroundImage:cell];
|
||||
}
|
||||
}
|
||||
- (void)didTransferGroup:(TUIButtonCell *)cell {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(didTransferGroup:)]) {
|
||||
[self.delegate didTransferGroup:cell];
|
||||
}
|
||||
}
|
||||
- (void)didDeleteGroup:(TUIButtonCell *)cell {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(didDeleteGroup:)]) {
|
||||
[self.delegate didDeleteGroup:cell];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didClearAllHistory:(TUIButtonCell *)cell {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(didClearAllHistory:)]) {
|
||||
[self.delegate didClearAllHistory:cell];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didSelectGroupManage {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectGroupManage)]) {
|
||||
[self.delegate didSelectGroupManage];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didSelectNotice {
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectGroupNotice)]) {
|
||||
[self.delegate didSelectGroupNotice];
|
||||
}
|
||||
}
|
||||
- (void)didReportGroup:(TUIButtonCell *)cell {
|
||||
NSURL *url = [NSURL URLWithString:@"https://cloud.tencent.com/act/event/report-platform"];
|
||||
[TUITool openLinkWithURL:url];
|
||||
}
|
||||
|
||||
- (NSMutableArray *)getShowMembers:(NSMutableArray *)members {
|
||||
int maxCount = TGroupMembersCell_Column_Count * TGroupMembersCell_Row_Count;
|
||||
if ([self.groupInfo canInviteMember]) maxCount--;
|
||||
if ([self.groupInfo canRemoveMember]) maxCount--;
|
||||
NSMutableArray *tmpArray = [NSMutableArray array];
|
||||
|
||||
for (NSInteger i = 0; i < members.count && i < maxCount; ++i) {
|
||||
[tmpArray addObject:members[i]];
|
||||
}
|
||||
if ([self.groupInfo canInviteMember]) {
|
||||
TUIGroupMemberCellData *add = [[TUIGroupMemberCellData alloc] init];
|
||||
add.avatarImage = TUIGroupCommonBundleImage(@"add");
|
||||
add.tag = 1;
|
||||
[tmpArray addObject:add];
|
||||
}
|
||||
if ([self.groupInfo canRemoveMember]) {
|
||||
TUIGroupMemberCellData *delete = [[TUIGroupMemberCellData alloc] init];
|
||||
delete.avatarImage = TUIGroupCommonBundleImage(@"delete");
|
||||
delete.tag = 2;
|
||||
[tmpArray addObject:delete];
|
||||
}
|
||||
return tmpArray;
|
||||
}
|
||||
|
||||
- (void)setGroupAddOpt:(V2TIMGroupAddOpt)opt {
|
||||
@weakify(self);
|
||||
V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
|
||||
info.groupID = self.groupID;
|
||||
info.groupAddOpt = opt;
|
||||
|
||||
[[V2TIMManager sharedInstance] setGroupInfo:info
|
||||
succ:^{
|
||||
@strongify(self);
|
||||
self.groupInfo.groupAddOpt = opt;
|
||||
self.addOptionData.value = [TUIGroupInfoDataProvider getAddOptionWithV2AddOpt:opt];
|
||||
}
|
||||
fail:^(int code, NSString *desc) {
|
||||
[TUITool makeToastError:code msg:desc];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setGroupApproveOpt:(V2TIMGroupAddOpt)opt {
|
||||
@weakify(self);
|
||||
V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
|
||||
info.groupID = self.groupID;
|
||||
info.groupApproveOpt = opt;
|
||||
|
||||
[[V2TIMManager sharedInstance] setGroupInfo:info
|
||||
succ:^{
|
||||
@strongify(self);
|
||||
self.groupInfo.groupApproveOpt = opt;
|
||||
self.inviteOptionData.value = [TUIGroupInfoDataProvider getApproveOption:self.groupInfo];
|
||||
}
|
||||
fail:^(int code, NSString *desc) {
|
||||
[TUITool makeToastError:code msg:desc];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setGroupReceiveMessageOpt:(V2TIMReceiveMessageOpt)opt Succ:(V2TIMSucc)succ fail:(V2TIMFail)fail {
|
||||
[[V2TIMManager sharedInstance] setGroupReceiveMessageOpt:self.groupID opt:opt succ:succ fail:fail];
|
||||
}
|
||||
|
||||
- (void)setGroupName:(NSString *)groupName {
|
||||
V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
|
||||
info.groupID = self.groupID;
|
||||
info.groupName = groupName;
|
||||
@weakify(self);
|
||||
[[V2TIMManager sharedInstance] setGroupInfo:info
|
||||
succ:^{
|
||||
@strongify(self);
|
||||
self.profileCellData.name = groupName;
|
||||
}
|
||||
fail:^(int code, NSString *msg) {
|
||||
[TUITool makeToastError:code msg:msg];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setGroupNotification:(NSString *)notification {
|
||||
V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
|
||||
info.groupID = self.groupID;
|
||||
info.notification = notification;
|
||||
@weakify(self);
|
||||
[[V2TIMManager sharedInstance] setGroupInfo:info
|
||||
succ:^{
|
||||
@strongify(self);
|
||||
self.profileCellData.signature = notification;
|
||||
}
|
||||
fail:^(int code, NSString *msg) {
|
||||
[TUITool makeToastError:code msg:msg];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setGroupMemberNameCard:(NSString *)nameCard {
|
||||
NSString *userID = [V2TIMManager sharedInstance].getLoginUser;
|
||||
V2TIMGroupMemberFullInfo *info = [[V2TIMGroupMemberFullInfo alloc] init];
|
||||
info.userID = userID;
|
||||
info.nameCard = nameCard;
|
||||
@weakify(self);
|
||||
[[V2TIMManager sharedInstance] setGroupMemberInfo:self.groupID
|
||||
info:info
|
||||
succ:^{
|
||||
@strongify(self);
|
||||
self.groupNickNameCellData.value = nameCard;
|
||||
self.selfInfo.nameCard = nameCard;
|
||||
}
|
||||
fail:^(int code, NSString *msg) {
|
||||
[TUITool makeToastError:code msg:msg];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)dismissGroup:(V2TIMSucc)succ fail:(V2TIMFail)fail {
|
||||
[[V2TIMManager sharedInstance] dismissGroup:self.groupID succ:succ fail:fail];
|
||||
}
|
||||
|
||||
- (void)quitGroup:(V2TIMSucc)succ fail:(V2TIMFail)fail {
|
||||
[[V2TIMManager sharedInstance] quitGroup:self.groupID succ:succ fail:fail];
|
||||
}
|
||||
|
||||
- (void)clearAllHistory:(V2TIMSucc)succ fail:(V2TIMFail)fail {
|
||||
[V2TIMManager.sharedInstance clearGroupHistoryMessage:self.groupID succ:succ fail:fail];
|
||||
}
|
||||
|
||||
+ (NSString *)getGroupTypeName:(V2TIMGroupInfo *)groupInfo {
|
||||
if (groupInfo.groupType) {
|
||||
if ([groupInfo.groupType isEqualToString:@"Work"]) {
|
||||
return TIMCommonLocalizableString(TUIKitWorkGroup);
|
||||
} else if ([groupInfo.groupType isEqualToString:@"Public"]) {
|
||||
return TIMCommonLocalizableString(TUIKitPublicGroup);
|
||||
} else if ([groupInfo.groupType isEqualToString:@"Meeting"]) {
|
||||
return TIMCommonLocalizableString(TUIKitChatRoom);
|
||||
} else if ([groupInfo.groupType isEqualToString:@"Community"]) {
|
||||
return TIMCommonLocalizableString(TUIKitCommunity);
|
||||
}
|
||||
}
|
||||
|
||||
return @"";
|
||||
}
|
||||
|
||||
+ (NSString *)getAddOption:(V2TIMGroupInfo *)groupInfo {
|
||||
switch (groupInfo.groupAddOpt) {
|
||||
case V2TIM_GROUP_ADD_FORBID:
|
||||
return TIMCommonLocalizableString(TUIKitGroupProfileJoinDisable);
|
||||
break;
|
||||
case V2TIM_GROUP_ADD_AUTH:
|
||||
return TIMCommonLocalizableString(TUIKitGroupProfileAdminApprove);
|
||||
break;
|
||||
case V2TIM_GROUP_ADD_ANY:
|
||||
return TIMCommonLocalizableString(TUIKitGroupProfileAutoApproval);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return @"";
|
||||
}
|
||||
|
||||
+ (NSString *)getAddOptionWithV2AddOpt:(V2TIMGroupAddOpt)opt {
|
||||
switch (opt) {
|
||||
case V2TIM_GROUP_ADD_FORBID:
|
||||
return TIMCommonLocalizableString(TUIKitGroupProfileJoinDisable);
|
||||
break;
|
||||
case V2TIM_GROUP_ADD_AUTH:
|
||||
return TIMCommonLocalizableString(TUIKitGroupProfileAdminApprove);
|
||||
break;
|
||||
case V2TIM_GROUP_ADD_ANY:
|
||||
return TIMCommonLocalizableString(TUIKitGroupProfileAutoApproval);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return @"";
|
||||
}
|
||||
|
||||
+ (NSString *)getApproveOption:(V2TIMGroupInfo *)groupInfo {
|
||||
switch (groupInfo.groupApproveOpt) {
|
||||
case V2TIM_GROUP_ADD_FORBID:
|
||||
return TIMCommonLocalizableString(TUIKitGroupProfileInviteDisable);
|
||||
break;
|
||||
case V2TIM_GROUP_ADD_AUTH:
|
||||
return TIMCommonLocalizableString(TUIKitGroupProfileAdminApprove);
|
||||
break;
|
||||
case V2TIM_GROUP_ADD_ANY:
|
||||
return TIMCommonLocalizableString(TUIKitGroupProfileAutoApproval);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return @"";
|
||||
}
|
||||
|
||||
+ (BOOL)isMarkedByFoldType:(NSArray *)markList {
|
||||
for (NSNumber *num in markList) {
|
||||
if (num.unsignedLongValue == V2TIM_CONVERSATION_MARK_TYPE_FOLD) {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (BOOL)isMarkedByHideType:(NSArray *)markList {
|
||||
for (NSNumber *num in markList) {
|
||||
if (num.unsignedLongValue == V2TIM_CONVERSATION_MARK_TYPE_HIDE) {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (BOOL)isMeOwner:(V2TIMGroupInfo *)groupInfo {
|
||||
return [groupInfo.owner isEqualToString:[[V2TIMManager sharedInstance] getLoginUser]] || (groupInfo.role == V2TIM_GROUP_MEMBER_ROLE_ADMIN);
|
||||
}
|
||||
|
||||
+ (BOOL)isMeSuper:(V2TIMGroupInfo *)groupInfo {
|
||||
return [groupInfo.owner isEqualToString:[[V2TIMManager sharedInstance] getLoginUser]] && (groupInfo.role == V2TIM_GROUP_MEMBER_ROLE_SUPER);
|
||||
}
|
||||
@end
|
||||
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// TUIGroupManageDataProvider.h
|
||||
// TUIGroup
|
||||
//
|
||||
// Created by harvy on 2021/12/24.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
@class TUIUserModel;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol TUIGroupManageDataProviderDelegate <NSObject>
|
||||
|
||||
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
|
||||
- (void)reloadData;
|
||||
- (void)showCoverViewWhenMuteAll:(BOOL)show;
|
||||
|
||||
- (void)insertRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
|
||||
- (void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
|
||||
|
||||
- (void)onError:(int)code desc:(NSString *)desc operate:(NSString *)operate;
|
||||
|
||||
@end
|
||||
|
||||
@interface TUIGroupManageDataProvider : NSObject
|
||||
|
||||
@property(nonatomic, assign) BOOL muteAll;
|
||||
@property(nonatomic, copy) NSString *groupID;
|
||||
@property(nonatomic, assign) BOOL currentGroupTypeSupportSettingAdmin;
|
||||
@property(nonatomic, assign) BOOL currentGroupTypeSupportAddMemberOfBlocked;
|
||||
@property(nonatomic, weak) id<TUIGroupManageDataProviderDelegate> delegate;
|
||||
@property(nonatomic, strong, readonly) NSMutableArray *datas;
|
||||
|
||||
- (void)loadData;
|
||||
|
||||
- (void)mutedAll:(BOOL)mute completion:(void (^)(int, NSString *))completion;
|
||||
- (void)mute:(BOOL)mute user:(TUIUserModel *)user;
|
||||
|
||||
- (void)updateMuteMembersFilterAdmins;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
285
TUIKit/TUIGroup/BaseDataProvider/TUIGroupManageDataProvider.m
Normal file
285
TUIKit/TUIGroup/BaseDataProvider/TUIGroupManageDataProvider.m
Normal file
@@ -0,0 +1,285 @@
|
||||
//
|
||||
// TUIGroupManageDataProvider.m
|
||||
// TUIGroup
|
||||
//
|
||||
// Created by harvy on 2021/12/24.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TUIGroupManageDataProvider.h"
|
||||
#import <ImSDK_Plus/ImSDK_Plus.h>
|
||||
#import <TUICore/TUIGlobalization.h>
|
||||
#import "TUIMemberInfoCellData.h"
|
||||
#import "TUISelectGroupMemberCell.h"
|
||||
|
||||
@interface TUIGroupManageDataProvider ()
|
||||
|
||||
@property(nonatomic, strong) NSMutableArray *datas;
|
||||
|
||||
@property(nonatomic, strong) NSMutableArray *groupInfoDatasArray;
|
||||
@property(nonatomic, strong) NSMutableArray *muteMembersDataArray;
|
||||
|
||||
@property(nonatomic, strong) V2TIMGroupInfo *groupInfo;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TUIGroupManageDataProvider
|
||||
|
||||
- (void)mutedAll:(BOOL)mute completion:(void (^)(int, NSString *))completion {
|
||||
__weak typeof(self) weakSelf = self;
|
||||
V2TIMGroupInfo *groupInfo = [[V2TIMGroupInfo alloc] init];
|
||||
groupInfo.groupID = self.groupID;
|
||||
groupInfo.allMuted = mute;
|
||||
[V2TIMManager.sharedInstance setGroupInfo:groupInfo
|
||||
succ:^{
|
||||
weakSelf.muteAll = mute;
|
||||
weakSelf.groupInfo.allMuted = mute;
|
||||
[weakSelf setupGroupInfo:weakSelf.groupInfo];
|
||||
if (completion) {
|
||||
completion(0, nil);
|
||||
}
|
||||
}
|
||||
fail:^(int code, NSString *desc) {
|
||||
weakSelf.muteAll = !mute;
|
||||
if (completion) {
|
||||
completion(code, desc);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)mute:(BOOL)mute user:(TUIUserModel *)user {
|
||||
if (!NSThread.isMainThread) {
|
||||
@weakify(self);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
@strongify(self);
|
||||
[self mute:mute user:user];
|
||||
});
|
||||
return;
|
||||
}
|
||||
__weak typeof(self) weakSelf = self;
|
||||
void (^callback)(int, NSString *, BOOL) = ^(int code, NSString *desc, BOOL mute) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
TUIMemberInfoCellData *existData = nil;
|
||||
for (TUIMemberInfoCellData *data in weakSelf.muteMembersDataArray) {
|
||||
if ([data.identifier isEqualToString:user.userId]) {
|
||||
existData = data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (code == 0 && mute) {
|
||||
// mute succ
|
||||
if (!existData) {
|
||||
TUIMemberInfoCellData *cellData = [[TUIMemberInfoCellData alloc] init];
|
||||
cellData.identifier = user.userId;
|
||||
cellData.name = user.name ?: user.userId;
|
||||
cellData.avatarUrl = user.avatar;
|
||||
[weakSelf.muteMembersDataArray addObject:cellData];
|
||||
}
|
||||
} else if (code == 0 && !mute) {
|
||||
// unmute succ
|
||||
if (existData) {
|
||||
[weakSelf.muteMembersDataArray removeObject:existData];
|
||||
}
|
||||
} else {
|
||||
// fail
|
||||
if ([weakSelf.delegate respondsToSelector:@selector(onError:desc:operate:)]) {
|
||||
[weakSelf.delegate onError:code
|
||||
desc:desc
|
||||
operate:mute ?
|
||||
TIMCommonLocalizableString(TUIKitGroupShutupOption) :
|
||||
TIMCommonLocalizableString(TUIKitGroupDisShutupOption)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if ([weakSelf.delegate respondsToSelector:@selector(reloadData)]) {
|
||||
[weakSelf.delegate reloadData];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
[V2TIMManager.sharedInstance muteGroupMember:self.groupID
|
||||
member:user.userId
|
||||
muteTime:mute ? 365 * 24 * 3600 : 0
|
||||
succ:^{
|
||||
callback(0, nil, mute);
|
||||
}
|
||||
fail:^(int code, NSString *desc) {
|
||||
callback(code, desc, mute);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)loadData {
|
||||
self.groupInfoDatasArray = [NSMutableArray array];
|
||||
self.muteMembersDataArray = [NSMutableArray array];
|
||||
self.datas = [NSMutableArray arrayWithArray:@[ self.groupInfoDatasArray, self.muteMembersDataArray ]];
|
||||
|
||||
@weakify(self);
|
||||
[V2TIMManager.sharedInstance getGroupsInfo:@[ self.groupID ?: @"" ]
|
||||
succ:^(NSArray<V2TIMGroupInfoResult *> *groupResultList) {
|
||||
@strongify(self);
|
||||
V2TIMGroupInfoResult *result = groupResultList.firstObject;
|
||||
if (result == nil || result.resultCode != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
V2TIMGroupInfo *groupInfo = result.info;
|
||||
self.groupInfo = groupInfo;
|
||||
[self setupGroupInfo:groupInfo];
|
||||
self.muteAll = groupInfo.allMuted;
|
||||
self.currentGroupTypeSupportSettingAdmin = [self canSupportSettingAdminAtThisGroupType:groupInfo.groupType];
|
||||
self.currentGroupTypeSupportAddMemberOfBlocked = [self canSupportAddMemberOfBlockedAtThisGroupType:groupInfo.groupType];
|
||||
}
|
||||
fail:^(int code, NSString *desc) {
|
||||
@strongify(self);
|
||||
[self setupGroupInfo:nil];
|
||||
}];
|
||||
|
||||
[self loadMuteMembers];
|
||||
}
|
||||
|
||||
- (void)loadMuteMembers {
|
||||
if (!NSThread.isMainThread) {
|
||||
@weakify(self);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
@strongify(self);
|
||||
[self loadMuteMembers];
|
||||
});
|
||||
}
|
||||
|
||||
[self.muteMembersDataArray removeAllObjects];
|
||||
if ([self.delegate respondsToSelector:@selector(reloadData)]) {
|
||||
[self.delegate reloadData];
|
||||
}
|
||||
|
||||
TUIMemberInfoCellData *add = [[TUIMemberInfoCellData alloc] init];
|
||||
add.avatar = TUIGroupCommonBundleImage(@"icon_add");
|
||||
add.name = TIMCommonLocalizableString(TUIKitGroupAddShutupMember);
|
||||
add.style = TUIMemberInfoCellStyleAdd;
|
||||
[self.muteMembersDataArray addObject:add];
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(insertRowsAtIndexPaths:withRowAnimation:)]) {
|
||||
[self.delegate insertRowsAtIndexPaths:@[ [NSIndexPath indexPathForRow:0 inSection:1] ] withRowAnimation:UITableViewRowAnimationNone];
|
||||
}
|
||||
|
||||
[self setupGroupMembers:0 first:YES];
|
||||
}
|
||||
|
||||
- (void)setupGroupMembers:(uint64_t)seq first:(uint64_t)first {
|
||||
if (seq == 0 && !first) {
|
||||
return;
|
||||
}
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[V2TIMManager.sharedInstance
|
||||
getGroupMemberList:self.groupID
|
||||
filter:V2TIM_GROUP_MEMBER_FILTER_ALL
|
||||
nextSeq:0
|
||||
succ:^(uint64_t nextSeq, NSArray<V2TIMGroupMemberFullInfo *> *memberList) {
|
||||
NSMutableArray *indexPaths = [NSMutableArray array];
|
||||
for (V2TIMGroupMemberFullInfo *info in memberList) {
|
||||
if (info.muteUntil && info.muteUntil > [NSDate.new timeIntervalSince1970]) {
|
||||
TUIMemberInfoCellData *member = [[TUIMemberInfoCellData alloc] init];
|
||||
member.avatarUrl = info.faceURL;
|
||||
member.name = (info.nameCard ?: info.nickName) ?: info.userID;
|
||||
member.identifier = info.userID;
|
||||
BOOL exist = NO;
|
||||
for (TUIMemberInfoCellData *data in weakSelf.muteMembersDataArray) {
|
||||
if ([data.identifier isEqualToString:info.userID]) {
|
||||
exist = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL isSuper = (info.role == V2TIM_GROUP_MEMBER_ROLE_SUPER);
|
||||
BOOL isAdMin = (info.role == V2TIM_GROUP_MEMBER_ROLE_ADMIN);
|
||||
BOOL allowShowInMuteList = YES;
|
||||
if (isSuper || isAdMin) {
|
||||
allowShowInMuteList = NO;
|
||||
}
|
||||
if (!exist && allowShowInMuteList) {
|
||||
[weakSelf.muteMembersDataArray addObject:member];
|
||||
[indexPaths addObject:[NSIndexPath indexPathForRow:[weakSelf.muteMembersDataArray indexOfObject:member] inSection:1]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (indexPaths.count) {
|
||||
if ([weakSelf.delegate respondsToSelector:@selector(insertRowsAtIndexPaths:withRowAnimation:)]) {
|
||||
[weakSelf.delegate insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
|
||||
}
|
||||
}
|
||||
|
||||
[weakSelf setupGroupMembers:nextSeq first:NO];
|
||||
}
|
||||
fail:^(int code, NSString *desc){
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setupGroupInfo:(V2TIMGroupInfo *)groupInfo {
|
||||
if (!NSThread.isMainThread) {
|
||||
@weakify(self);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
@strongify(self);
|
||||
[self setupGroupInfo:groupInfo];
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (groupInfo == nil) {
|
||||
return;
|
||||
}
|
||||
[self.groupInfoDatasArray removeAllObjects];
|
||||
|
||||
TUICommonTextCellData *adminSetting = [[TUICommonTextCellData alloc] init];
|
||||
adminSetting.key = TIMCommonLocalizableString(TUIKitGroupManageAdminSetting);
|
||||
adminSetting.value = @"";
|
||||
adminSetting.showAccessory = YES;
|
||||
adminSetting.cselector = @selector(onSettingAdmin:);
|
||||
[self.groupInfoDatasArray addObject:adminSetting];
|
||||
|
||||
TUICommonSwitchCellData *shutupAll = [[TUICommonSwitchCellData alloc] init];
|
||||
shutupAll.title = TIMCommonLocalizableString(TUIKitGroupManageShutAll);
|
||||
shutupAll.on = groupInfo.allMuted;
|
||||
shutupAll.cswitchSelector = @selector(onMutedAll:);
|
||||
[self.groupInfoDatasArray addObject:shutupAll];
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(reloadData)]) {
|
||||
[self.delegate reloadData];
|
||||
}
|
||||
}
|
||||
|
||||
//- (void)onMutedAll:(TUICommonSwitchCellData *)switchData
|
||||
//{
|
||||
// if ([self.delegate respondsToSelector:@selector(onMutedAll:)]) {
|
||||
// [self.delegate onMutedAll:switchData.isOn];
|
||||
// }
|
||||
//}
|
||||
|
||||
- (void)updateMuteMembersFilterAdmins {
|
||||
[self loadMuteMembers];
|
||||
}
|
||||
- (NSMutableArray *)datas {
|
||||
if (_datas == nil) {
|
||||
_datas = [NSMutableArray array];
|
||||
}
|
||||
return _datas;
|
||||
}
|
||||
|
||||
- (BOOL)canSupportSettingAdminAtThisGroupType:(NSString *)grouptype {
|
||||
if ([grouptype isEqualToString:@"Work"] || [grouptype isEqualToString:@"AVChatRoom"]) {
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)canSupportAddMemberOfBlockedAtThisGroupType:(NSString *)grouptype {
|
||||
if ([grouptype isEqualToString:@"Work"]) {
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// TUIGroupMemberDataProvider.h
|
||||
// TXIMSDK_TUIKit_iOS
|
||||
//
|
||||
// Created by xiangzhang on 2021/7/2.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@import ImSDK_Plus;
|
||||
@class TUIGroupMemberCellData;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TUIGroupMemberDataProvider : NSObject
|
||||
@property(nonatomic, strong) V2TIMGroupInfo *groupInfo;
|
||||
@property(nonatomic, assign) BOOL isNoMoreData;
|
||||
|
||||
- (instancetype)initWithGroupID:(NSString *)groupID;
|
||||
- (void)loadDatas:(void (^)(BOOL success, NSString *err, NSArray *datas))completion;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// TUIGroupMemberDataProvider.m
|
||||
// TXIMSDK_TUIKit_iOS
|
||||
//
|
||||
// Created by xiangzhang on 2021/7/2.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TUIGroupMemberDataProvider.h"
|
||||
#import <TIMCommon/TIMDefine.h>
|
||||
#import "TUIMemberInfoCellData.h"
|
||||
|
||||
@interface TUIGroupMemberDataProvider ()
|
||||
@property(nonatomic, strong) NSString *groupID;
|
||||
@property(nonatomic, assign) NSUInteger index;
|
||||
@end
|
||||
|
||||
@implementation TUIGroupMemberDataProvider
|
||||
- (instancetype)initWithGroupID:(NSString *)groupID {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.groupID = groupID;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)loadDatas:(void (^)(BOOL success, NSString *err, NSArray *datas))completion {
|
||||
@weakify(self);
|
||||
[[V2TIMManager sharedInstance] getGroupMemberList:self.groupID
|
||||
filter:V2TIM_GROUP_MEMBER_FILTER_ALL
|
||||
nextSeq:self.index
|
||||
succ:^(uint64_t nextSeq, NSArray<V2TIMGroupMemberFullInfo *> *memberList) {
|
||||
@strongify(self);
|
||||
self.index = nextSeq;
|
||||
self.isNoMoreData = (nextSeq == 0);
|
||||
NSMutableArray *arrayM = [NSMutableArray array];
|
||||
NSMutableArray *ids = [NSMutableArray array];
|
||||
NSMutableDictionary *map = [NSMutableDictionary dictionary];
|
||||
for (V2TIMGroupMemberFullInfo *member in memberList) {
|
||||
TUIMemberInfoCellData *user = [[TUIMemberInfoCellData alloc] init];
|
||||
user.identifier = member.userID;
|
||||
user.role = member.role;
|
||||
if (member.nameCard.length > 0) {
|
||||
user.name = member.nameCard;
|
||||
} else if (member.friendRemark.length > 0) {
|
||||
user.name = member.friendRemark;
|
||||
} else if (member.nickName.length > 0) {
|
||||
user.name = member.nickName;
|
||||
} else {
|
||||
user.name = member.userID;
|
||||
}
|
||||
[arrayM addObject:user];
|
||||
[ids addObject:user.identifier];
|
||||
if (user.identifier && user) {
|
||||
map[user.identifier] = user;
|
||||
}
|
||||
}
|
||||
|
||||
[[V2TIMManager sharedInstance] getUsersInfo:ids
|
||||
succ:^(NSArray<V2TIMUserFullInfo *> *infoList) {
|
||||
NSArray *userIDs = map.allKeys;
|
||||
for (V2TIMUserFullInfo *info in infoList) {
|
||||
if (![userIDs containsObject:info.userID]) {
|
||||
continue;
|
||||
}
|
||||
TUIMemberInfoCellData *user = map[info.userID];
|
||||
user.avatarUrl = info.faceURL;
|
||||
}
|
||||
if (completion) {
|
||||
completion(YES, @"", arrayM);
|
||||
}
|
||||
}
|
||||
fail:^(int code, NSString *desc) {
|
||||
if (completion) {
|
||||
completion(NO, desc, @[]);
|
||||
}
|
||||
}];
|
||||
}
|
||||
fail:^(int code, NSString *msg) {
|
||||
if (completion) {
|
||||
completion(NO, msg, @[]);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// TUIGroupNoticeDataProvider.h
|
||||
// TUIGroup
|
||||
//
|
||||
// Created by harvy on 2022/1/12.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <ImSDK_Plus/ImSDK_Plus.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TUIGroupNoticeDataProvider : NSObject
|
||||
|
||||
@property(nonatomic, strong, readonly) V2TIMGroupInfo *groupInfo;
|
||||
@property(nonatomic, copy) NSString *groupID;
|
||||
|
||||
- (void)getGroupInfo:(dispatch_block_t)callback;
|
||||
- (BOOL)canEditNotice;
|
||||
- (void)updateNotice:(NSString *)notice callback:(void (^)(int, NSString *))callback;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// TUIGroupNoticeDataProvider.m
|
||||
// TUIGroup
|
||||
//
|
||||
// Created by harvy on 2022/1/12.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TUIGroupNoticeDataProvider.h"
|
||||
|
||||
@interface TUIGroupNoticeDataProvider ()
|
||||
|
||||
@property(nonatomic, strong) V2TIMGroupInfo *groupInfo;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TUIGroupNoticeDataProvider
|
||||
|
||||
- (void)getGroupInfo:(dispatch_block_t)callback {
|
||||
if (self.groupInfo && [self.groupInfo.groupID isEqual:self.groupID]) {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[V2TIMManager.sharedInstance getGroupsInfo:@[ self.groupID ?: @"" ]
|
||||
succ:^(NSArray<V2TIMGroupInfoResult *> *groupResultList) {
|
||||
V2TIMGroupInfoResult *result = groupResultList.firstObject;
|
||||
if (result && result.resultCode == 0) {
|
||||
weakSelf.groupInfo = result.info;
|
||||
}
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
fail:^(int code, NSString *desc) {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (BOOL)canEditNotice {
|
||||
return self.groupInfo.role == V2TIM_GROUP_MEMBER_ROLE_ADMIN || self.groupInfo.role == V2TIM_GROUP_MEMBER_ROLE_SUPER;
|
||||
}
|
||||
|
||||
- (void)updateNotice:(NSString *)notice callback:(void (^)(int, NSString *))callback {
|
||||
V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
|
||||
info.groupID = self.groupID;
|
||||
info.notification = notice;
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[V2TIMManager.sharedInstance setGroupInfo:info
|
||||
succ:^{
|
||||
if (callback) {
|
||||
callback(0, nil);
|
||||
}
|
||||
|
||||
[weakSelf sendNoticeMessage:notice];
|
||||
}
|
||||
fail:^(int code, NSString *desc) {
|
||||
if (callback) {
|
||||
callback(code, desc);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)sendNoticeMessage:(NSString *)notice {
|
||||
if (notice.length == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// TUISettingAdminDataProvider.h
|
||||
// TUIGroup
|
||||
//
|
||||
// Created by harvy on 2021/12/28.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
@class TUIUserModel;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TUISettingAdminDataProvider : NSObject
|
||||
|
||||
@property(nonatomic, copy) NSString *groupID;
|
||||
|
||||
@property(nonatomic, strong, readonly) NSMutableArray *datas;
|
||||
@property(nonatomic, strong, readonly) NSMutableArray *owners;
|
||||
@property(nonatomic, strong, readonly) NSMutableArray *admins;
|
||||
|
||||
- (void)loadData:(void (^)(int, NSString *))callback;
|
||||
|
||||
- (void)removeAdmin:(NSString *)userID callback:(void (^)(int, NSString *))callback;
|
||||
- (void)settingAdmins:(NSArray<TUIUserModel *> *)userModels callback:(void (^)(int, NSString *))callback;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
212
TUIKit/TUIGroup/BaseDataProvider/TUISettingAdminDataProvider.m
Normal file
212
TUIKit/TUIGroup/BaseDataProvider/TUISettingAdminDataProvider.m
Normal file
@@ -0,0 +1,212 @@
|
||||
//
|
||||
// TUISettingAdminDataProvider.m
|
||||
// TUIGroup
|
||||
//
|
||||
// Created by harvy on 2021/12/28.
|
||||
// Copyright © 2023 Tencent. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TUISettingAdminDataProvider.h"
|
||||
#import <ImSDK_Plus/ImSDK_Plus.h>
|
||||
#import <TIMCommon/TIMDefine.h>
|
||||
#import "TUIMemberInfoCellData.h"
|
||||
|
||||
@interface TUISettingAdminDataProvider ()
|
||||
|
||||
@property(nonatomic, strong) NSMutableArray *datas;
|
||||
|
||||
@property(nonatomic, strong) NSMutableArray *owners;
|
||||
@property(nonatomic, strong) NSMutableArray *admins;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TUISettingAdminDataProvider
|
||||
|
||||
- (void)removeAdmin:(NSString *)userID callback:(void (^)(int, NSString *))callback {
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[V2TIMManager.sharedInstance setGroupMemberRole:self.groupID
|
||||
member:userID
|
||||
newRole:V2TIM_GROUP_MEMBER_ROLE_MEMBER
|
||||
succ:^{
|
||||
TUIMemberInfoCellData *exist = [self existAdmin:userID];
|
||||
if (exist) {
|
||||
[weakSelf.admins removeObject:exist];
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(0, nil);
|
||||
}
|
||||
}
|
||||
fail:^(int code, NSString *desc) {
|
||||
if (callback) {
|
||||
callback(code, desc);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)settingAdmins:(NSArray<TUIUserModel *> *)userModels callback:(void (^)(int, NSString *))callback;
|
||||
{
|
||||
NSMutableArray *validUsers = [NSMutableArray array];
|
||||
for (TUIUserModel *user in userModels) {
|
||||
TUIMemberInfoCellData *exist = [self existAdmin:user.userId];
|
||||
if (!exist) {
|
||||
TUIMemberInfoCellData *data = [[TUIMemberInfoCellData alloc] init];
|
||||
data.identifier = user.userId;
|
||||
data.name = user.name;
|
||||
data.avatarUrl = user.avatar;
|
||||
[validUsers addObject:data];
|
||||
}
|
||||
}
|
||||
|
||||
if (validUsers.count == 0) {
|
||||
if (callback) {
|
||||
callback(0, nil);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.admins.count + validUsers.count > 11) {
|
||||
if (callback) {
|
||||
callback(-1, @"The number of administrator must be less than ten");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
__block int errorCode = 0;
|
||||
__block NSString *errorMsg = nil;
|
||||
NSMutableArray *results = [NSMutableArray array];
|
||||
|
||||
dispatch_group_t group = dispatch_group_create();
|
||||
for (TUIMemberInfoCellData *data in validUsers) {
|
||||
dispatch_group_enter(group);
|
||||
[V2TIMManager.sharedInstance setGroupMemberRole:self.groupID
|
||||
member:data.identifier
|
||||
newRole:V2TIM_GROUP_MEMBER_ROLE_ADMIN
|
||||
succ:^{
|
||||
[results addObject:data];
|
||||
dispatch_group_leave(group);
|
||||
}
|
||||
fail:^(int code, NSString *desc) {
|
||||
if (errorCode == 0) {
|
||||
errorCode = code;
|
||||
errorMsg = desc;
|
||||
}
|
||||
dispatch_group_leave(group);
|
||||
}];
|
||||
}
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
|
||||
[weakSelf.admins addObjectsFromArray:results];
|
||||
if (callback) {
|
||||
callback(errorCode, errorMsg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)loadData:(void (^)(int, NSString *))callback {
|
||||
{
|
||||
TUIMemberInfoCellData *add = [[TUIMemberInfoCellData alloc] init];
|
||||
add.style = TUIMemberInfoCellStyleAdd;
|
||||
add.name = TIMCommonLocalizableString(TUIKitGroupAddAdmins);
|
||||
add.avatar = TUIGroupCommonBundleImage(@"icon_add");
|
||||
[self.admins addObject:add];
|
||||
}
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
|
||||
__block int errorCode = 0;
|
||||
__block NSString *errorMsg = nil;
|
||||
|
||||
dispatch_group_t group = dispatch_group_create();
|
||||
dispatch_group_enter(group);
|
||||
[V2TIMManager.sharedInstance getGroupMemberList:self.groupID
|
||||
filter:V2TIM_GROUP_MEMBER_FILTER_OWNER
|
||||
nextSeq:0
|
||||
succ:^(uint64_t nextSeq, NSArray<V2TIMGroupMemberFullInfo *> *memberList) {
|
||||
for (V2TIMGroupMemberFullInfo *info in memberList) {
|
||||
TUIMemberInfoCellData *cellData = [[TUIMemberInfoCellData alloc] init];
|
||||
cellData.identifier = info.userID;
|
||||
cellData.name = (info.nameCard ?: info.nickName) ?: info.userID;
|
||||
cellData.avatarUrl = info.faceURL;
|
||||
if (info.role == V2TIM_GROUP_MEMBER_ROLE_SUPER) {
|
||||
[weakSelf.owners addObject:cellData];
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_group_leave(group);
|
||||
}
|
||||
fail:^(int code, NSString *desc) {
|
||||
if (errorCode == 0) {
|
||||
errorCode = code;
|
||||
errorMsg = desc;
|
||||
}
|
||||
dispatch_group_leave(group);
|
||||
}];
|
||||
|
||||
dispatch_group_enter(group);
|
||||
[V2TIMManager.sharedInstance getGroupMemberList:self.groupID
|
||||
filter:V2TIM_GROUP_MEMBER_FILTER_ADMIN
|
||||
nextSeq:0
|
||||
succ:^(uint64_t nextSeq, NSArray<V2TIMGroupMemberFullInfo *> *memberList) {
|
||||
for (V2TIMGroupMemberFullInfo *info in memberList) {
|
||||
TUIMemberInfoCellData *cellData = [[TUIMemberInfoCellData alloc] init];
|
||||
cellData.identifier = info.userID;
|
||||
cellData.name = (info.nameCard ?: info.nickName) ?: info.userID;
|
||||
cellData.avatarUrl = info.faceURL;
|
||||
if (info.role == V2TIM_GROUP_MEMBER_ROLE_ADMIN) {
|
||||
[weakSelf.admins addObject:cellData];
|
||||
}
|
||||
}
|
||||
dispatch_group_leave(group);
|
||||
}
|
||||
fail:^(int code, NSString *desc) {
|
||||
if (errorCode == 0) {
|
||||
errorCode = code;
|
||||
errorMsg = desc;
|
||||
}
|
||||
dispatch_group_leave(group);
|
||||
}];
|
||||
|
||||
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
|
||||
weakSelf.datas = [NSMutableArray arrayWithArray:@[ weakSelf.owners, weakSelf.admins ]];
|
||||
if (callback) {
|
||||
callback(errorCode, errorMsg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (TUIMemberInfoCellData *)existAdmin:(NSString *)userID {
|
||||
TUIMemberInfoCellData *exist = nil;
|
||||
for (TUIMemberInfoCellData *data in self.admins) {
|
||||
if ([data.identifier isEqual:userID]) {
|
||||
exist = data;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return exist;
|
||||
}
|
||||
|
||||
- (NSMutableArray *)datas {
|
||||
if (_datas == nil) {
|
||||
_datas = [NSMutableArray array];
|
||||
}
|
||||
return _datas;
|
||||
}
|
||||
|
||||
- (NSMutableArray *)owners {
|
||||
if (_owners == nil) {
|
||||
_owners = [NSMutableArray array];
|
||||
}
|
||||
return _owners;
|
||||
}
|
||||
|
||||
- (NSMutableArray *)admins {
|
||||
if (_admins == nil) {
|
||||
_admins = [NSMutableArray array];
|
||||
}
|
||||
return _admins;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user