| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748 |
- // Created by Tencent on 2023/06/09.
- // Copyright © 2023 Tencent. All rights reserved.
- #import <TIMCommon/TIMCommonModel.h>
- #import <TIMCommon/TIMDefine.h>
- #import <TIMCommon/TIMGroupInfo+TUIDataProvider.h>
- #import "TUIGroupInfoDataProvider.h"
- #import <TIMCommon/TUICommonGroupInfoCellData.h>
- #import "TUIGroupNoticeCell.h"
- #import "TUIGroupConfig.h"
- #import <TUICore/TUICore.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;
- @property(nonatomic, assign) BOOL firstLoadData;
- @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;
- }
- self.firstLoadData = YES;
- 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) {
- [self makeToastError:code msg:msg];
- }];
- }
- - (void)makeToastError:(NSInteger)code msg:(NSString *)msg {
- if (!self.firstLoadData) {
- [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();
- }
- [self 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) {
- weakSelf.membersData = [NSMutableArray arrayWithCapacity:1];
- [self 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) {
- [self 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]) {
- NSMutableDictionary *param = [NSMutableDictionary dictionary];
- param[@"pushVC"] = self.delegate.pushNavigationController;
- param[@"groupID"] = self.groupID.length > 0 ? self.groupID : @"";
- NSArray<TUIExtensionInfo *> *extensionList = [TUICore getExtensionList:
- TUICore_TUIChatExtension_GroupProfileSettingsItemExtension_ClassicExtensionID
- param:param];
- for (TUIExtensionInfo *info in extensionList) {
- if (info.text && info.onClicked) {
- TUICommonTextCellData *manageData = [[TUICommonTextCellData alloc] init];
- manageData.key = info.text; //TIMCommonLocalizableString(TUIKitGroupProfileManage);
- manageData.value = @"";
- manageData.tui_extValueObj = info;
- manageData.showAccessory = YES;
- manageData.cselector = @selector(groupProfileExtensionButtonClick:);
- if (info.weight == 100 ) {
- if ([TUIGroupInfoDataProvider isMeOwner:self.groupInfo]) {
- [groupInfoArray addObject:manageData];
- }
- }
- else {
- [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 ([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]) {
- NSMutableDictionary *param = [NSMutableDictionary dictionary];
- param[@"pushVC"] = self.delegate.pushNavigationController;
- param[@"groupID"] = self.groupID.length > 0 ? self.groupID : @"";
- void (^updateGroupInfoCallback)(void) = ^{
- [self updateGroupInfo];
- };
- param[@"updateGroupInfoCallback"] = updateGroupInfoCallback;
- NSArray<TUIExtensionInfo *> *extensionList = [TUICore getExtensionList:
- TUICore_TUIChatExtension_GroupProfileBottomItemExtension_ClassicExtensionID
- param:param];
- for (TUIExtensionInfo *info in extensionList) {
- if (info.text && info.onClicked) {
- TUIButtonCellData *transferButton = [[TUIButtonCellData alloc] init];
- transferButton.title = info.text;
- transferButton.style = ButtonRedText;
- transferButton.tui_extValueObj = info;
- transferButton.cbuttonSelector = @selector(groupProfileExtensionButtonClick:);
- [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)groupProfileExtensionButtonClick:(TUICommonTextCell *)cell {
- //Implemented through self.delegate, because of TUIButtonCellData cbuttonSelector mechanism
- }
- - (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)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)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 = TUIContactCommonBundleImage(@"add");
- add.tag = 1;
- [tmpArray addObject:add];
- }
- if ([self.groupInfo canRemoveMember]) {
- TUIGroupMemberCellData *delete = [[TUIGroupMemberCellData alloc] init];
- delete.avatarImage = TUIContactCommonBundleImage(@"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) {
- [self 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) {
- [self 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) {
- [self 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) {
- [self 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) {
- [self 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
|