TUIGroupInfoDataProvider.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. // Created by Tencent on 2023/06/09.
  2. // Copyright © 2023 Tencent. All rights reserved.
  3. #import <TIMCommon/TIMCommonModel.h>
  4. #import <TIMCommon/TIMDefine.h>
  5. #import <TIMCommon/TIMGroupInfo+TUIDataProvider.h>
  6. #import "TUIGroupInfoDataProvider.h"
  7. #import <TIMCommon/TUICommonGroupInfoCellData.h>
  8. #import "TUIGroupNoticeCell.h"
  9. #import "TUIGroupConfig.h"
  10. #import <TUICore/TUICore.h>
  11. @interface TUIGroupInfoDataProvider () <V2TIMGroupListener>
  12. @property(nonatomic, strong) TUICommonTextCellData *addOptionData;
  13. @property(nonatomic, strong) TUICommonTextCellData *inviteOptionData;
  14. @property(nonatomic, strong) TUICommonTextCellData *groupNickNameCellData;
  15. @property(nonatomic, strong, readwrite) TUIProfileCardCellData *profileCellData;
  16. @property(nonatomic, strong) V2TIMGroupMemberFullInfo *selfInfo;
  17. @property(nonatomic, strong) NSString *groupID;
  18. @property(nonatomic, assign) BOOL firstLoadData;
  19. @end
  20. @implementation TUIGroupInfoDataProvider
  21. - (instancetype)initWithGroupID:(NSString *)groupID {
  22. self = [super init];
  23. if (self) {
  24. self.groupID = groupID;
  25. [[V2TIMManager sharedInstance] addGroupListener:self];
  26. }
  27. return self;
  28. }
  29. #pragma mark V2TIMGroupListener
  30. - (void)onMemberEnter:(NSString *)groupID memberList:(NSArray<V2TIMGroupMemberInfo *> *)memberList {
  31. [self loadData];
  32. }
  33. - (void)onMemberLeave:(NSString *)groupID member:(V2TIMGroupMemberInfo *)member {
  34. [self loadData];
  35. }
  36. - (void)onMemberInvited:(NSString *)groupID opUser:(V2TIMGroupMemberInfo *)opUser memberList:(NSArray<V2TIMGroupMemberInfo *> *)memberList {
  37. [self loadData];
  38. }
  39. - (void)onMemberKicked:(NSString *)groupID opUser:(V2TIMGroupMemberInfo *)opUser memberList:(NSArray<V2TIMGroupMemberInfo *> *)memberList {
  40. [self loadData];
  41. }
  42. - (void)onGroupInfoChanged:(NSString *)groupID changeInfoList:(NSArray<V2TIMGroupChangeInfo *> *)changeInfoList {
  43. if (![groupID isEqualToString:self.groupID]) {
  44. return;
  45. }
  46. [self loadData];
  47. }
  48. - (void)loadData {
  49. if (self.groupID.length == 0) {
  50. [TUITool makeToastError:ERR_INVALID_PARAMETERS msg:@"invalid groupID"];
  51. return;
  52. }
  53. self.firstLoadData = YES;
  54. dispatch_group_t group = dispatch_group_create();
  55. dispatch_group_enter(group);
  56. [self getGroupInfo:^{
  57. dispatch_group_leave(group);
  58. }];
  59. dispatch_group_enter(group);
  60. [self getGroupMembers:^{
  61. dispatch_group_leave(group);
  62. }];
  63. dispatch_group_enter(group);
  64. [self getSelfInfoInGroup:^{
  65. dispatch_group_leave(group);
  66. }];
  67. __weak typeof(self) weakSelf = self;
  68. dispatch_group_notify(group, dispatch_get_main_queue(), ^{
  69. [weakSelf setupData];
  70. });
  71. }
  72. - (void)updateGroupInfo {
  73. @weakify(self);
  74. [[V2TIMManager sharedInstance] getGroupsInfo:@[ self.groupID ]
  75. succ:^(NSArray<V2TIMGroupInfoResult *> *groupResultList) {
  76. @strongify(self);
  77. if (groupResultList.count == 1) {
  78. self.groupInfo = groupResultList[0].info;
  79. [self setupData];
  80. }
  81. }
  82. fail:^(int code, NSString *msg) {
  83. [self makeToastError:code msg:msg];
  84. }];
  85. }
  86. - (void)makeToastError:(NSInteger)code msg:(NSString *)msg {
  87. if (!self.firstLoadData) {
  88. [TUITool makeToastError:code msg:msg];
  89. }
  90. }
  91. - (void)transferGroupOwner:(NSString *)groupID member:(NSString *)userID succ:(V2TIMSucc)succ fail:(V2TIMFail)fail {
  92. [V2TIMManager.sharedInstance transferGroupOwner:groupID
  93. member:userID
  94. succ:^{
  95. succ();
  96. }
  97. fail:^(int code, NSString *desc) {
  98. fail(code, desc);
  99. }];
  100. }
  101. - (void)updateGroupAvatar:(NSString *)url succ:(V2TIMSucc)succ fail:(V2TIMFail)fail {
  102. V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
  103. info.groupID = self.groupID;
  104. info.faceURL = url;
  105. [V2TIMManager.sharedInstance setGroupInfo:info succ:succ fail:fail];
  106. }
  107. - (void)getGroupInfo:(dispatch_block_t)callback {
  108. __weak typeof(self) weakSelf = self;
  109. [[V2TIMManager sharedInstance] getGroupsInfo:@[ self.groupID ]
  110. succ:^(NSArray<V2TIMGroupInfoResult *> *groupResultList) {
  111. weakSelf.groupInfo = groupResultList.firstObject.info;
  112. if (callback) {
  113. callback();
  114. }
  115. }
  116. fail:^(int code, NSString *msg) {
  117. if (callback) {
  118. callback();
  119. }
  120. [self makeToastError:code msg:msg];
  121. }];
  122. }
  123. - (void)getGroupMembers:(dispatch_block_t)callback {
  124. __weak typeof(self) weakSelf = self;
  125. [[V2TIMManager sharedInstance] getGroupMemberList:self.groupID
  126. filter:V2TIM_GROUP_MEMBER_FILTER_ALL
  127. nextSeq:0
  128. succ:^(uint64_t nextSeq, NSArray<V2TIMGroupMemberFullInfo *> *memberList) {
  129. NSMutableArray *membersData = [NSMutableArray array];
  130. for (V2TIMGroupMemberFullInfo *fullInfo in memberList) {
  131. TUIGroupMemberCellData *data = [[TUIGroupMemberCellData alloc] init];
  132. data.identifier = fullInfo.userID;
  133. data.name = fullInfo.userID;
  134. data.avatarUrl = fullInfo.faceURL;
  135. if (fullInfo.nameCard.length > 0) {
  136. data.name = fullInfo.nameCard;
  137. } else if (fullInfo.friendRemark.length > 0) {
  138. data.name = fullInfo.friendRemark;
  139. } else if (fullInfo.nickName.length > 0) {
  140. data.name = fullInfo.nickName;
  141. }
  142. [membersData addObject:data];
  143. }
  144. weakSelf.membersData = membersData;
  145. if (callback) {
  146. callback();
  147. }
  148. }
  149. fail:^(int code, NSString *msg) {
  150. weakSelf.membersData = [NSMutableArray arrayWithCapacity:1];
  151. [self makeToastError:code msg:msg];
  152. if (callback) {
  153. callback();
  154. }
  155. }];
  156. }
  157. - (void)getSelfInfoInGroup:(dispatch_block_t)callback {
  158. NSString *loginUserID = [[V2TIMManager sharedInstance] getLoginUser];
  159. if (loginUserID.length == 0) {
  160. if (callback) {
  161. callback();
  162. }
  163. return;
  164. }
  165. __weak typeof(self) weakSelf = self;
  166. [[V2TIMManager sharedInstance] getGroupMembersInfo:self.groupID
  167. memberList:@[ loginUserID ]
  168. succ:^(NSArray<V2TIMGroupMemberFullInfo *> *memberList) {
  169. for (V2TIMGroupMemberFullInfo *item in memberList) {
  170. if ([item.userID isEqualToString:loginUserID]) {
  171. weakSelf.selfInfo = item;
  172. break;
  173. }
  174. }
  175. if (callback) {
  176. callback();
  177. }
  178. }
  179. fail:^(int code, NSString *desc) {
  180. [self makeToastError:code msg:desc];
  181. if (callback) {
  182. callback();
  183. }
  184. }];
  185. }
  186. - (void)setupData {
  187. NSMutableArray *dataList = [NSMutableArray array];
  188. if (self.groupInfo) {
  189. NSMutableArray *commonArray = [NSMutableArray array];
  190. TUIProfileCardCellData *commonData = [[TUIProfileCardCellData alloc] init];
  191. commonData.avatarImage = DefaultGroupAvatarImageByGroupType(self.groupInfo.groupType);
  192. commonData.avatarUrl = [NSURL URLWithString:self.groupInfo.faceURL];
  193. commonData.name = self.groupInfo.groupName;
  194. commonData.identifier = self.groupInfo.groupID;
  195. commonData.signature = self.groupInfo.notification;
  196. if ([TUIGroupInfoDataProvider isMeOwner:self.groupInfo] || [self.groupInfo isPrivate]) {
  197. commonData.cselector = @selector(didSelectCommon);
  198. commonData.showAccessory = YES;
  199. }
  200. self.profileCellData = commonData;
  201. [commonArray addObject:commonData];
  202. [dataList addObject:commonArray];
  203. NSMutableArray *memberArray = [NSMutableArray array];
  204. if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Members]) {
  205. TUICommonTextCellData *countData = [[TUICommonTextCellData alloc] init];
  206. countData.key = TIMCommonLocalizableString(TUIKitGroupProfileMember);
  207. countData.value = [NSString stringWithFormat:TIMCommonLocalizableString(TUIKitGroupProfileMemberCount), self.groupInfo.memberCount];
  208. countData.cselector = @selector(didSelectMembers);
  209. countData.showAccessory = YES;
  210. [memberArray addObject:countData];
  211. NSMutableArray *tmpArray = [self getShowMembers:self.membersData];
  212. TUIGroupMembersCellData *membersData = [[TUIGroupMembersCellData alloc] init];
  213. membersData.members = tmpArray;
  214. [memberArray addObject:membersData];
  215. self.groupMembersCellData = membersData;
  216. [dataList addObject:memberArray];
  217. }
  218. // group info
  219. NSMutableArray *groupInfoArray = [NSMutableArray array];
  220. if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Notice]) {
  221. TUIGroupNoticeCellData *notice = [[TUIGroupNoticeCellData alloc] init];
  222. notice.name = TIMCommonLocalizableString(TUIKitGroupNotice);
  223. notice.desc = self.groupInfo.notification ?: TIMCommonLocalizableString(TUIKitGroupNoticeNull);
  224. notice.target = self;
  225. notice.selector = @selector(didSelectNotice);
  226. [groupInfoArray addObject:notice];
  227. }
  228. if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Members]) {
  229. NSMutableDictionary *param = [NSMutableDictionary dictionary];
  230. param[@"pushVC"] = self.delegate.pushNavigationController;
  231. param[@"groupID"] = self.groupID.length > 0 ? self.groupID : @"";
  232. NSArray<TUIExtensionInfo *> *extensionList = [TUICore getExtensionList:
  233. TUICore_TUIChatExtension_GroupProfileSettingsItemExtension_ClassicExtensionID
  234. param:param];
  235. for (TUIExtensionInfo *info in extensionList) {
  236. if (info.text && info.onClicked) {
  237. TUICommonTextCellData *manageData = [[TUICommonTextCellData alloc] init];
  238. manageData.key = info.text; //TIMCommonLocalizableString(TUIKitGroupProfileManage);
  239. manageData.value = @"";
  240. manageData.tui_extValueObj = info;
  241. manageData.showAccessory = YES;
  242. manageData.cselector = @selector(groupProfileExtensionButtonClick:);
  243. if (info.weight == 100 ) {
  244. if ([TUIGroupInfoDataProvider isMeOwner:self.groupInfo]) {
  245. [groupInfoArray addObject:manageData];
  246. }
  247. }
  248. else {
  249. [groupInfoArray addObject:manageData];
  250. }
  251. }
  252. }
  253. }
  254. if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Manage]) {
  255. TUICommonTextCellData *typeData = [[TUICommonTextCellData alloc] init];
  256. typeData.key = TIMCommonLocalizableString(TUIKitGroupProfileType);
  257. typeData.value = [TUIGroupInfoDataProvider getGroupTypeName:self.groupInfo];
  258. [groupInfoArray addObject:typeData];
  259. TUICommonTextCellData *addOptionData = [[TUICommonTextCellData alloc] init];
  260. addOptionData.key = TIMCommonLocalizableString(TUIKitGroupProfileJoinType);
  261. if ([TUIGroupInfoDataProvider isMeOwner:self.groupInfo]) {
  262. addOptionData.cselector = @selector(didSelectAddOption:);
  263. addOptionData.showAccessory = YES;
  264. }
  265. addOptionData.value = [TUIGroupInfoDataProvider getAddOption:self.groupInfo];
  266. [groupInfoArray addObject:addOptionData];
  267. self.addOptionData = addOptionData;
  268. TUICommonTextCellData *inviteOptionData = [[TUICommonTextCellData alloc] init];
  269. inviteOptionData.key = TIMCommonLocalizableString(TUIKitGroupProfileInviteType);
  270. if ([TUIGroupInfoDataProvider isMeOwner:self.groupInfo]) {
  271. inviteOptionData.cselector = @selector(didSelectAddOption:);
  272. inviteOptionData.showAccessory = YES;
  273. }
  274. inviteOptionData.value = [TUIGroupInfoDataProvider getApproveOption:self.groupInfo];
  275. [groupInfoArray addObject:inviteOptionData];
  276. self.inviteOptionData = inviteOptionData;
  277. [dataList addObject:groupInfoArray];
  278. }
  279. // personal info
  280. if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Alias]) {
  281. TUICommonTextCellData *nickData = [[TUICommonTextCellData alloc] init];
  282. nickData.key = TIMCommonLocalizableString(TUIKitGroupProfileAlias);
  283. nickData.value = self.selfInfo.nameCard;
  284. nickData.cselector = @selector(didSelectGroupNick:);
  285. nickData.showAccessory = YES;
  286. self.groupNickNameCellData = nickData;
  287. [dataList addObject:@[ nickData ]];
  288. }
  289. TUICommonSwitchCellData *markFold = [[TUICommonSwitchCellData alloc] init];
  290. TUICommonSwitchCellData *switchData = [[TUICommonSwitchCellData alloc] init];
  291. if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_MuteAndPin]) {
  292. NSMutableArray *personalArray = [NSMutableArray array];
  293. TUICommonSwitchCellData *messageSwitchData = [[TUICommonSwitchCellData alloc] init];
  294. if (![self.groupInfo.groupType isEqualToString:GroupType_Meeting]) {
  295. messageSwitchData.on = (self.groupInfo.recvOpt == V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE);
  296. messageSwitchData.title = TIMCommonLocalizableString(TUIKitGroupProfileMessageDoNotDisturb);
  297. messageSwitchData.cswitchSelector = @selector(didSelectOnNotDisturb:);
  298. [personalArray addObject:messageSwitchData];
  299. }
  300. markFold.title = TIMCommonLocalizableString(TUIKitConversationMarkFold);
  301. markFold.displaySeparatorLine = YES;
  302. markFold.cswitchSelector = @selector(didSelectOnFoldConversation:);
  303. if (messageSwitchData.on) {
  304. [personalArray addObject:markFold];
  305. }
  306. switchData.title = TIMCommonLocalizableString(TUIKitGroupProfileStickyOnTop);
  307. [personalArray addObject:switchData];
  308. [dataList addObject:personalArray];
  309. }
  310. if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Background]) {
  311. TUICommonTextCellData *changeBackgroundImageItem = [[TUICommonTextCellData alloc] init];
  312. changeBackgroundImageItem.key = TIMCommonLocalizableString(ProfileSetBackgroundImage);
  313. changeBackgroundImageItem.cselector = @selector(didSelectOnChangeBackgroundImage:);
  314. changeBackgroundImageItem.showAccessory = YES;
  315. [dataList addObject:@[ changeBackgroundImageItem ]];
  316. }
  317. NSMutableArray *buttonArray = [NSMutableArray array];
  318. if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_ClearChatHistory]) {
  319. TUIButtonCellData *clearHistory = [[TUIButtonCellData alloc] init];
  320. clearHistory.title = TIMCommonLocalizableString(TUIKitClearAllChatHistory);
  321. clearHistory.style = ButtonRedText;
  322. clearHistory.cbuttonSelector = @selector(didClearAllHistory:);
  323. [buttonArray addObject:clearHistory];
  324. }
  325. if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_DeleteAndLeave]) {
  326. TUIButtonCellData *quitButton = [[TUIButtonCellData alloc] init];
  327. quitButton.title = TIMCommonLocalizableString(TUIKitGroupProfileDeleteAndExit);
  328. quitButton.style = ButtonRedText;
  329. quitButton.cbuttonSelector = @selector(didDeleteGroup:);
  330. [buttonArray addObject:quitButton];
  331. }
  332. if ([self.class isMeSuper:self.groupInfo] &&
  333. ![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Transfer]) {
  334. NSMutableDictionary *param = [NSMutableDictionary dictionary];
  335. param[@"pushVC"] = self.delegate.pushNavigationController;
  336. param[@"groupID"] = self.groupID.length > 0 ? self.groupID : @"";
  337. void (^updateGroupInfoCallback)(void) = ^{
  338. [self updateGroupInfo];
  339. };
  340. param[@"updateGroupInfoCallback"] = updateGroupInfoCallback;
  341. NSArray<TUIExtensionInfo *> *extensionList = [TUICore getExtensionList:
  342. TUICore_TUIChatExtension_GroupProfileBottomItemExtension_ClassicExtensionID
  343. param:param];
  344. for (TUIExtensionInfo *info in extensionList) {
  345. if (info.text && info.onClicked) {
  346. TUIButtonCellData *transferButton = [[TUIButtonCellData alloc] init];
  347. transferButton.title = info.text;
  348. transferButton.style = ButtonRedText;
  349. transferButton.tui_extValueObj = info;
  350. transferButton.cbuttonSelector = @selector(groupProfileExtensionButtonClick:);
  351. [buttonArray addObject:transferButton];
  352. }
  353. }
  354. }
  355. if ([self.groupInfo canDismissGroup] &&
  356. ![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Dismiss]) {
  357. TUIButtonCellData *deletebutton = [[TUIButtonCellData alloc] init];
  358. deletebutton.title = TIMCommonLocalizableString(TUIKitGroupProfileDissolve);
  359. deletebutton.style = ButtonRedText;
  360. deletebutton.cbuttonSelector = @selector(didDeleteGroup:);
  361. [buttonArray addObject:deletebutton];
  362. }
  363. if (![TUIGroupConfig.sharedConfig isItemHiddenInGroupConfig:TUIGroupConfigItem_Report]) {
  364. TUIButtonCellData *reportButton = [[TUIButtonCellData alloc] init];
  365. reportButton.title = TIMCommonLocalizableString(TUIKitGroupProfileReport);
  366. reportButton.style = ButtonRedText;
  367. reportButton.cbuttonSelector = @selector(didReportGroup:);
  368. [buttonArray addObject:reportButton];
  369. }
  370. TUIButtonCellData *lastCellData = [buttonArray lastObject];
  371. lastCellData.hideSeparatorLine = YES;
  372. [dataList addObject:buttonArray];
  373. #ifndef SDKPlaceTop
  374. #define SDKPlaceTop
  375. #endif
  376. #ifdef SDKPlaceTop
  377. @weakify(self);
  378. [V2TIMManager.sharedInstance getConversation:[NSString stringWithFormat:@"group_%@", self.groupID]
  379. succ:^(V2TIMConversation *conv) {
  380. @strongify(self);
  381. markFold.on = [self.class isMarkedByFoldType:conv.markList];
  382. switchData.cswitchSelector = @selector(didSelectOnTop:);
  383. switchData.on = conv.isPinned;
  384. if (markFold.on) {
  385. switchData.on = NO;
  386. switchData.disableChecked = YES;
  387. }
  388. self.dataList = dataList;
  389. }
  390. fail:^(int code, NSString *desc) {
  391. NSLog(@"");
  392. }];
  393. #else
  394. if ([[[TUIConversationPin sharedInstance] topConversationList] containsObject:[NSString stringWithFormat:@"group_%@", self.groupID]]) {
  395. switchData.on = YES;
  396. }
  397. #endif
  398. }
  399. }
  400. - (void)groupProfileExtensionButtonClick:(TUICommonTextCell *)cell {
  401. //Implemented through self.delegate, because of TUIButtonCellData cbuttonSelector mechanism
  402. }
  403. - (void)didSelectMembers {
  404. if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectMembers)]) {
  405. [self.delegate didSelectMembers];
  406. }
  407. }
  408. - (void)didSelectGroupNick:(TUICommonTextCell *)cell {
  409. if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectGroupNick:)]) {
  410. [self.delegate didSelectGroupNick:cell];
  411. }
  412. }
  413. - (void)didSelectAddOption:(UITableViewCell *)cell {
  414. if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectAddOption:)]) {
  415. [self.delegate didSelectAddOption:cell];
  416. }
  417. }
  418. - (void)didSelectCommon {
  419. if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectCommon)]) {
  420. [self.delegate didSelectCommon];
  421. }
  422. }
  423. - (void)didSelectOnNotDisturb:(TUICommonSwitchCell *)cell {
  424. if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectOnNotDisturb:)]) {
  425. [self.delegate didSelectOnNotDisturb:cell];
  426. }
  427. }
  428. - (void)didSelectOnTop:(TUICommonSwitchCell *)cell {
  429. if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectOnTop:)]) {
  430. [self.delegate didSelectOnTop:cell];
  431. }
  432. }
  433. - (void)didSelectOnFoldConversation:(TUICommonSwitchCell *)cell {
  434. if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectOnFoldConversation:)]) {
  435. [self.delegate didSelectOnFoldConversation:cell];
  436. }
  437. }
  438. - (void)didSelectOnChangeBackgroundImage:(TUICommonTextCell *)cell {
  439. if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectOnChangeBackgroundImage:)]) {
  440. [self.delegate didSelectOnChangeBackgroundImage:cell];
  441. }
  442. }
  443. - (void)didDeleteGroup:(TUIButtonCell *)cell {
  444. if (self.delegate && [self.delegate respondsToSelector:@selector(didDeleteGroup:)]) {
  445. [self.delegate didDeleteGroup:cell];
  446. }
  447. }
  448. - (void)didClearAllHistory:(TUIButtonCell *)cell {
  449. if (self.delegate && [self.delegate respondsToSelector:@selector(didClearAllHistory:)]) {
  450. [self.delegate didClearAllHistory:cell];
  451. }
  452. }
  453. - (void)didSelectNotice {
  454. if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectGroupNotice)]) {
  455. [self.delegate didSelectGroupNotice];
  456. }
  457. }
  458. - (void)didReportGroup:(TUIButtonCell *)cell {
  459. NSURL *url = [NSURL URLWithString:@"https://cloud.tencent.com/act/event/report-platform"];
  460. [TUITool openLinkWithURL:url];
  461. }
  462. - (NSMutableArray *)getShowMembers:(NSMutableArray *)members {
  463. int maxCount = TGroupMembersCell_Column_Count * TGroupMembersCell_Row_Count;
  464. if ([self.groupInfo canInviteMember]) maxCount--;
  465. if ([self.groupInfo canRemoveMember]) maxCount--;
  466. NSMutableArray *tmpArray = [NSMutableArray array];
  467. for (NSInteger i = 0; i < members.count && i < maxCount; ++i) {
  468. [tmpArray addObject:members[i]];
  469. }
  470. if ([self.groupInfo canInviteMember]) {
  471. TUIGroupMemberCellData *add = [[TUIGroupMemberCellData alloc] init];
  472. add.avatarImage = TUIContactCommonBundleImage(@"add");
  473. add.tag = 1;
  474. [tmpArray addObject:add];
  475. }
  476. if ([self.groupInfo canRemoveMember]) {
  477. TUIGroupMemberCellData *delete = [[TUIGroupMemberCellData alloc] init];
  478. delete.avatarImage = TUIContactCommonBundleImage(@"delete");
  479. delete.tag = 2;
  480. [tmpArray addObject:delete];
  481. }
  482. return tmpArray;
  483. }
  484. - (void)setGroupAddOpt:(V2TIMGroupAddOpt)opt {
  485. @weakify(self);
  486. V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
  487. info.groupID = self.groupID;
  488. info.groupAddOpt = opt;
  489. [[V2TIMManager sharedInstance] setGroupInfo:info
  490. succ:^{
  491. @strongify(self);
  492. self.groupInfo.groupAddOpt = opt;
  493. self.addOptionData.value = [TUIGroupInfoDataProvider getAddOptionWithV2AddOpt:opt];
  494. }
  495. fail:^(int code, NSString *desc) {
  496. [self makeToastError:code msg:desc];
  497. }];
  498. }
  499. - (void)setGroupApproveOpt:(V2TIMGroupAddOpt)opt {
  500. @weakify(self);
  501. V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
  502. info.groupID = self.groupID;
  503. info.groupApproveOpt = opt;
  504. [[V2TIMManager sharedInstance] setGroupInfo:info
  505. succ:^{
  506. @strongify(self);
  507. self.groupInfo.groupApproveOpt = opt;
  508. self.inviteOptionData.value = [TUIGroupInfoDataProvider getApproveOption:self.groupInfo];
  509. }
  510. fail:^(int code, NSString *desc) {
  511. [self makeToastError:code msg:desc];
  512. }];
  513. }
  514. - (void)setGroupReceiveMessageOpt:(V2TIMReceiveMessageOpt)opt Succ:(V2TIMSucc)succ fail:(V2TIMFail)fail {
  515. [[V2TIMManager sharedInstance] setGroupReceiveMessageOpt:self.groupID opt:opt succ:succ fail:fail];
  516. }
  517. - (void)setGroupName:(NSString *)groupName {
  518. V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
  519. info.groupID = self.groupID;
  520. info.groupName = groupName;
  521. @weakify(self);
  522. [[V2TIMManager sharedInstance] setGroupInfo:info
  523. succ:^{
  524. @strongify(self);
  525. self.profileCellData.name = groupName;
  526. }
  527. fail:^(int code, NSString *msg) {
  528. [self makeToastError:code msg:msg];
  529. }];
  530. }
  531. - (void)setGroupNotification:(NSString *)notification {
  532. V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
  533. info.groupID = self.groupID;
  534. info.notification = notification;
  535. @weakify(self);
  536. [[V2TIMManager sharedInstance] setGroupInfo:info
  537. succ:^{
  538. @strongify(self);
  539. self.profileCellData.signature = notification;
  540. }
  541. fail:^(int code, NSString *msg) {
  542. [self makeToastError:code msg:msg];
  543. }];
  544. }
  545. - (void)setGroupMemberNameCard:(NSString *)nameCard {
  546. NSString *userID = [V2TIMManager sharedInstance].getLoginUser;
  547. V2TIMGroupMemberFullInfo *info = [[V2TIMGroupMemberFullInfo alloc] init];
  548. info.userID = userID;
  549. info.nameCard = nameCard;
  550. @weakify(self);
  551. [[V2TIMManager sharedInstance] setGroupMemberInfo:self.groupID
  552. info:info
  553. succ:^{
  554. @strongify(self);
  555. self.groupNickNameCellData.value = nameCard;
  556. self.selfInfo.nameCard = nameCard;
  557. }
  558. fail:^(int code, NSString *msg) {
  559. [self makeToastError:code msg:msg];
  560. }];
  561. }
  562. - (void)dismissGroup:(V2TIMSucc)succ fail:(V2TIMFail)fail {
  563. [[V2TIMManager sharedInstance] dismissGroup:self.groupID succ:succ fail:fail];
  564. }
  565. - (void)quitGroup:(V2TIMSucc)succ fail:(V2TIMFail)fail {
  566. [[V2TIMManager sharedInstance] quitGroup:self.groupID succ:succ fail:fail];
  567. }
  568. - (void)clearAllHistory:(V2TIMSucc)succ fail:(V2TIMFail)fail {
  569. [V2TIMManager.sharedInstance clearGroupHistoryMessage:self.groupID succ:succ fail:fail];
  570. }
  571. + (NSString *)getGroupTypeName:(V2TIMGroupInfo *)groupInfo {
  572. if (groupInfo.groupType) {
  573. if ([groupInfo.groupType isEqualToString:@"Work"]) {
  574. return TIMCommonLocalizableString(TUIKitWorkGroup);
  575. } else if ([groupInfo.groupType isEqualToString:@"Public"]) {
  576. return TIMCommonLocalizableString(TUIKitPublicGroup);
  577. } else if ([groupInfo.groupType isEqualToString:@"Meeting"]) {
  578. return TIMCommonLocalizableString(TUIKitChatRoom);
  579. } else if ([groupInfo.groupType isEqualToString:@"Community"]) {
  580. return TIMCommonLocalizableString(TUIKitCommunity);
  581. }
  582. }
  583. return @"";
  584. }
  585. + (NSString *)getAddOption:(V2TIMGroupInfo *)groupInfo {
  586. switch (groupInfo.groupAddOpt) {
  587. case V2TIM_GROUP_ADD_FORBID:
  588. return TIMCommonLocalizableString(TUIKitGroupProfileJoinDisable);
  589. break;
  590. case V2TIM_GROUP_ADD_AUTH:
  591. return TIMCommonLocalizableString(TUIKitGroupProfileAdminApprove);
  592. break;
  593. case V2TIM_GROUP_ADD_ANY:
  594. return TIMCommonLocalizableString(TUIKitGroupProfileAutoApproval);
  595. break;
  596. default:
  597. break;
  598. }
  599. return @"";
  600. }
  601. + (NSString *)getAddOptionWithV2AddOpt:(V2TIMGroupAddOpt)opt {
  602. switch (opt) {
  603. case V2TIM_GROUP_ADD_FORBID:
  604. return TIMCommonLocalizableString(TUIKitGroupProfileJoinDisable);
  605. break;
  606. case V2TIM_GROUP_ADD_AUTH:
  607. return TIMCommonLocalizableString(TUIKitGroupProfileAdminApprove);
  608. break;
  609. case V2TIM_GROUP_ADD_ANY:
  610. return TIMCommonLocalizableString(TUIKitGroupProfileAutoApproval);
  611. break;
  612. default:
  613. break;
  614. }
  615. return @"";
  616. }
  617. + (NSString *)getApproveOption:(V2TIMGroupInfo *)groupInfo {
  618. switch (groupInfo.groupApproveOpt) {
  619. case V2TIM_GROUP_ADD_FORBID:
  620. return TIMCommonLocalizableString(TUIKitGroupProfileInviteDisable);
  621. break;
  622. case V2TIM_GROUP_ADD_AUTH:
  623. return TIMCommonLocalizableString(TUIKitGroupProfileAdminApprove);
  624. break;
  625. case V2TIM_GROUP_ADD_ANY:
  626. return TIMCommonLocalizableString(TUIKitGroupProfileAutoApproval);
  627. break;
  628. default:
  629. break;
  630. }
  631. return @"";
  632. }
  633. + (BOOL)isMarkedByFoldType:(NSArray *)markList {
  634. for (NSNumber *num in markList) {
  635. if (num.unsignedLongValue == V2TIM_CONVERSATION_MARK_TYPE_FOLD) {
  636. return YES;
  637. }
  638. }
  639. return NO;
  640. }
  641. + (BOOL)isMarkedByHideType:(NSArray *)markList {
  642. for (NSNumber *num in markList) {
  643. if (num.unsignedLongValue == V2TIM_CONVERSATION_MARK_TYPE_HIDE) {
  644. return YES;
  645. }
  646. }
  647. return NO;
  648. }
  649. + (BOOL)isMeOwner:(V2TIMGroupInfo *)groupInfo {
  650. return [groupInfo.owner isEqualToString:[[V2TIMManager sharedInstance] getLoginUser]] || (groupInfo.role == V2TIM_GROUP_MEMBER_ROLE_ADMIN);
  651. }
  652. + (BOOL)isMeSuper:(V2TIMGroupInfo *)groupInfo {
  653. return [groupInfo.owner isEqualToString:[[V2TIMManager sharedInstance] getLoginUser]] && (groupInfo.role == V2TIM_GROUP_MEMBER_ROLE_SUPER);
  654. }
  655. @end