TUIGroupInfoController.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. // Created by Tencent on 2023/06/09.
  2. // Copyright © 2023 Tencent. All rights reserved.
  3. #import "TUIGroupInfoController.h"
  4. #import <TIMCommon/TIMDefine.h>
  5. #import <TUICore/TUICore.h>
  6. #import <TUICore/TUILogin.h>
  7. #import <TUICore/TUIThemeManager.h>
  8. #import <TIMCommon/TIMGroupInfo+TUIDataProvider.h>
  9. #import "TUIGroupInfoDataProvider.h"
  10. #import <TIMCommon/TUICommonGroupInfoCellData.h>
  11. #import "TUIGroupNoticeCell.h"
  12. #import "TUIGroupNoticeController.h"
  13. #define ADD_TAG @"-1"
  14. #define DEL_TAG @"-2"
  15. @interface TUIGroupInfoController () <TUIModifyViewDelegate,TUIProfileCardDelegate, TUIGroupInfoDataProviderDelegate>
  16. @property(nonatomic, strong) TUIGroupInfoDataProvider *dataProvider;
  17. @property(nonatomic, strong) TUINaviBarIndicatorView *titleView;
  18. @property(nonatomic, strong) UIViewController *showContactSelectVC;
  19. @end
  20. @implementation TUIGroupInfoController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. [self setupViews];
  24. self.dataProvider = [[TUIGroupInfoDataProvider alloc] initWithGroupID:self.groupId];
  25. self.dataProvider.delegate = self;
  26. [self.dataProvider loadData];
  27. @weakify(self);
  28. [RACObserve(self.dataProvider, dataList) subscribeNext:^(id _Nullable x) {
  29. @strongify(self);
  30. [self.tableView reloadData];
  31. }];
  32. _titleView = [[TUINaviBarIndicatorView alloc] init];
  33. self.navigationItem.titleView = _titleView;
  34. self.navigationItem.title = @"";
  35. [_titleView setTitle:TIMCommonLocalizableString(ProfileDetails)];
  36. }
  37. - (void)setupViews {
  38. self.tableView.tableFooterView = [[UIView alloc] init];
  39. self.tableView.backgroundColor = TIMCommonDynamicColor(@"controller_bg_color", @"#F2F3F5");
  40. self.tableView.delaysContentTouches = NO;
  41. if (@available(iOS 15.0, *)) {
  42. self.tableView.sectionHeaderTopPadding = 0;
  43. }
  44. }
  45. - (void)updateData {
  46. [self.dataProvider loadData];
  47. }
  48. - (void)updateGroupInfo {
  49. [self.dataProvider updateGroupInfo];
  50. }
  51. #pragma mark - Table view data source
  52. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  53. return self.dataProvider.dataList.count;
  54. }
  55. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  56. UIView *view = [[UIView alloc] init];
  57. view.backgroundColor = [UIColor clearColor];
  58. return view;
  59. }
  60. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  61. return 10;
  62. }
  63. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  64. NSMutableArray *array = self.dataProvider.dataList[section];
  65. return array.count;
  66. }
  67. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  68. NSMutableArray *array = self.dataProvider.dataList[indexPath.section];
  69. NSObject *data = array[indexPath.row];
  70. if ([data isKindOfClass:[TUIProfileCardCellData class]]) {
  71. return [(TUIProfileCardCellData *)data heightOfWidth:Screen_Width];
  72. } else if ([data isKindOfClass:[TUIGroupMembersCellData class]]) {
  73. return [(TUIGroupMembersCellData *)data heightOfWidth:Screen_Width];
  74. } else if ([data isKindOfClass:[TUIButtonCellData class]]) {
  75. return [(TUIButtonCellData *)data heightOfWidth:Screen_Width];
  76. } else if ([data isKindOfClass:[TUICommonSwitchCellData class]]) {
  77. return [(TUICommonSwitchCellData *)data heightOfWidth:Screen_Width];
  78. } else if ([data isKindOfClass:TUIGroupNoticeCellData.class]) {
  79. return 72.0;
  80. }
  81. return 44;
  82. }
  83. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  84. NSMutableArray *array = self.dataProvider.dataList[indexPath.section];
  85. NSObject *data = array[indexPath.row];
  86. if ([data isKindOfClass:[TUIProfileCardCellData class]]) {
  87. TUIProfileCardCell *cell = [tableView dequeueReusableCellWithIdentifier:TGroupCommonCell_ReuseId];
  88. if (!cell) {
  89. cell = [[TUIProfileCardCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TGroupCommonCell_ReuseId];
  90. }
  91. cell.delegate = self;
  92. [cell fillWithData:(TUIProfileCardCellData *)data];
  93. return cell;
  94. } else if ([data isKindOfClass:[TUICommonTextCellData class]]) {
  95. TUICommonTextCell *cell = [tableView dequeueReusableCellWithIdentifier:TKeyValueCell_ReuseId];
  96. if (!cell) {
  97. cell = [[TUICommonTextCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TKeyValueCell_ReuseId];
  98. }
  99. [cell fillWithData:(TUICommonTextCellData *)data];
  100. return cell;
  101. } else if ([data isKindOfClass:[TUIGroupMembersCellData class]]) {
  102. TUICommonTableViewCell *cell = [[TUICommonTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TGroupMembersCell_ReuseId];
  103. NSDictionary *param = @{
  104. @"data": data ,
  105. @"pushVC": self.navigationController,
  106. @"groupID": self.groupId ? self.groupId : @"",
  107. @"membersData": self.dataProvider.membersData ,
  108. @"groupMembersCellData": self.dataProvider.groupMembersCellData,
  109. };
  110. [TUICore raiseExtension:TUICore_TUIChatExtension_GroupProfileMemberListExtension_ClassicExtensionID
  111. parentView:cell
  112. param:param];
  113. return cell;
  114. } else if ([data isKindOfClass:[TUICommonSwitchCellData class]]) {
  115. TUICommonSwitchCell *cell = [tableView dequeueReusableCellWithIdentifier:TSwitchCell_ReuseId];
  116. if (!cell) {
  117. cell = [[TUICommonSwitchCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TSwitchCell_ReuseId];
  118. }
  119. [cell fillWithData:(TUICommonSwitchCellData *)data];
  120. return cell;
  121. } else if ([data isKindOfClass:[TUIButtonCellData class]]) {
  122. TUIButtonCell *cell = [tableView dequeueReusableCellWithIdentifier:TButtonCell_ReuseId];
  123. if (!cell) {
  124. cell = [[TUIButtonCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TButtonCell_ReuseId];
  125. }
  126. [cell fillWithData:(TUIButtonCellData *)data];
  127. return cell;
  128. } else if ([data isKindOfClass:TUIGroupNoticeCellData.class]) {
  129. TUIGroupNoticeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TUIGroupNoticeCell"];
  130. if (cell == nil) {
  131. cell = [[TUIGroupNoticeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TUIGroupNoticeCell"];
  132. }
  133. cell.cellData = data;
  134. return cell;
  135. }
  136. return nil;
  137. }
  138. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  139. }
  140. - (void)leftBarButtonClick:(UIButton *)sender {
  141. [self.navigationController popViewControllerAnimated:YES];
  142. }
  143. #pragma mark TUIGroupInfoDataProviderDelegate
  144. - (void)groupProfileExtensionButtonClick:(TUICommonTextCell *)cell {
  145. TUIExtensionInfo *info = cell.data.tui_extValueObj;
  146. if (info == nil || ![info isKindOfClass:TUIExtensionInfo.class] || info.onClicked == nil) {
  147. return;
  148. }
  149. info.onClicked(@{});
  150. }
  151. - (void)didSelectMembers {
  152. NSMutableDictionary *param = [NSMutableDictionary dictionary];
  153. if (_groupId && _groupId.length >0) {
  154. param[@"groupID"] = _groupId;
  155. }
  156. if (self.dataProvider.groupInfo) {
  157. param[@"groupInfo"] = self.dataProvider.groupInfo;
  158. }
  159. UIViewController *vc = [TUICore createObject:TUICore_TUIContactObjectFactory
  160. key:TUICore_TUIContactObjectFactory_GetGroupMemberVCMethod
  161. param:param];
  162. if (vc && [vc isKindOfClass:UIViewController.class]) {
  163. [self.navigationController pushViewController:vc animated:YES];
  164. }
  165. }
  166. - (void)didSelectAddOption:(TUICommonTextCell *)cell {
  167. TUICommonTextCellData *data = cell.textData;
  168. BOOL isApprove = [data.key isEqualToString:TIMCommonLocalizableString(TUIKitGroupProfileInviteType)];
  169. __weak typeof(self) weakSelf = self;
  170. UIAlertController *ac = [UIAlertController
  171. alertControllerWithTitle:nil
  172. message:isApprove ? TIMCommonLocalizableString(TUIKitGroupProfileInviteType) : TIMCommonLocalizableString(TUIKitGroupProfileJoinType)
  173. preferredStyle:UIAlertControllerStyleActionSheet];
  174. NSArray *actionList = @[
  175. @{
  176. @(V2TIM_GROUP_ADD_FORBID) : isApprove ? TIMCommonLocalizableString(TUIKitGroupProfileInviteDisable)
  177. : TIMCommonLocalizableString(TUIKitGroupProfileJoinDisable)
  178. },
  179. @{@(V2TIM_GROUP_ADD_AUTH) : TIMCommonLocalizableString(TUIKitGroupProfileAdminApprove)},
  180. @{@(V2TIM_GROUP_ADD_ANY) : TIMCommonLocalizableString(TUIKitGroupProfileAutoApproval)}
  181. ];
  182. for (NSDictionary *map in actionList) {
  183. [ac tuitheme_addAction:[UIAlertAction actionWithTitle:map.allValues.firstObject
  184. style:UIAlertActionStyleDefault
  185. handler:^(UIAlertAction *_Nonnull action) {
  186. V2TIMGroupAddOpt opt = (V2TIMGroupAddOpt)[map.allKeys.firstObject intValue];
  187. if (isApprove) {
  188. [weakSelf.dataProvider setGroupApproveOpt:opt];
  189. } else {
  190. [weakSelf.dataProvider setGroupAddOpt:opt];
  191. }
  192. }]];
  193. }
  194. [ac tuitheme_addAction:[UIAlertAction actionWithTitle:TIMCommonLocalizableString(Cancel) style:UIAlertActionStyleCancel handler:nil]];
  195. [self presentViewController:ac animated:YES completion:nil];
  196. }
  197. - (void)didSelectGroupNick:(TUICommonTextCell *)cell {
  198. TUIModifyViewData *data = [[TUIModifyViewData alloc] init];
  199. data.title = TIMCommonLocalizableString(TUIKitGroupProfileEditAlias);
  200. data.content = self.dataProvider.selfInfo.nameCard;
  201. data.desc = TIMCommonLocalizableString(TUIKitGroupProfileEditAliasDesc);
  202. TUIModifyView *modify = [[TUIModifyView alloc] init];
  203. modify.tag = 2;
  204. modify.delegate = self;
  205. [modify setData:data];
  206. [modify showInWindow:self.view.window];
  207. }
  208. - (void)didSelectCommon {
  209. UIAlertController *ac = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  210. __weak typeof(self) weakSelf = self;
  211. if ([self.dataProvider.groupInfo isPrivate] || [TUIGroupInfoDataProvider isMeOwner:self.dataProvider.groupInfo]) {
  212. [ac tuitheme_addAction:[UIAlertAction actionWithTitle:TIMCommonLocalizableString(TUIKitGroupProfileEditGroupName)
  213. style:UIAlertActionStyleDefault
  214. handler:^(UIAlertAction *_Nonnull action) {
  215. TUIModifyViewData *data = [[TUIModifyViewData alloc] init];
  216. data.title = TIMCommonLocalizableString(TUIKitGroupProfileEditGroupName);
  217. data.content = weakSelf.dataProvider.groupInfo.groupName;
  218. data.desc = TIMCommonLocalizableString(TUIKitGroupProfileEditGroupName);
  219. TUIModifyView *modify = [[TUIModifyView alloc] init];
  220. modify.tag = 0;
  221. modify.delegate = weakSelf;
  222. [modify setData:data];
  223. [modify showInWindow:weakSelf.view.window];
  224. }]];
  225. }
  226. if ([TUIGroupInfoDataProvider isMeOwner:self.dataProvider.groupInfo]) {
  227. [ac tuitheme_addAction:[UIAlertAction actionWithTitle:TIMCommonLocalizableString(TUIKitGroupProfileEditAnnouncement)
  228. style:UIAlertActionStyleDefault
  229. handler:^(UIAlertAction *_Nonnull action) {
  230. TUIModifyViewData *data = [[TUIModifyViewData alloc] init];
  231. data.title = TIMCommonLocalizableString(TUIKitGroupProfileEditAnnouncement);
  232. TUIModifyView *modify = [[TUIModifyView alloc] init];
  233. modify.tag = 1;
  234. modify.delegate = weakSelf;
  235. [modify setData:data];
  236. [modify showInWindow:weakSelf.view.window];
  237. }]];
  238. }
  239. if ([TUIGroupInfoDataProvider isMeOwner:self.dataProvider.groupInfo]) {
  240. @weakify(self);
  241. [ac tuitheme_addAction:[UIAlertAction actionWithTitle:TIMCommonLocalizableString(TUIKitGroupProfileEditAvatar)
  242. style:UIAlertActionStyleDefault
  243. handler:^(UIAlertAction *_Nonnull action) {
  244. @strongify(self);
  245. TUISelectAvatarController *vc = [[TUISelectAvatarController alloc] init];
  246. vc.selectAvatarType = TUISelectAvatarTypeGroupAvatar;
  247. vc.profilFaceURL = self.dataProvider.groupInfo.faceURL;
  248. [self.navigationController pushViewController:vc animated:YES];
  249. vc.selectCallBack = ^(NSString *_Nonnull urlStr) {
  250. if (urlStr.length > 0) {
  251. V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
  252. info.groupID = self.groupId;
  253. info.faceURL = urlStr;
  254. [[V2TIMManager sharedInstance] setGroupInfo:info
  255. succ:^{
  256. [self updateGroupInfo];
  257. }
  258. fail:^(int code, NSString *msg) {
  259. [TUITool makeToastError:code msg:msg];
  260. }];
  261. }
  262. };
  263. }]];
  264. }
  265. [ac tuitheme_addAction:[UIAlertAction actionWithTitle:TIMCommonLocalizableString(Cancel) style:UIAlertActionStyleCancel handler:nil]];
  266. [self presentViewController:ac animated:YES completion:nil];
  267. }
  268. - (void)didSelectOnNotDisturb:(TUICommonSwitchCell *)cell {
  269. V2TIMReceiveMessageOpt opt;
  270. if (cell.switcher.on) {
  271. opt = V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE;
  272. } else {
  273. opt = V2TIM_RECEIVE_MESSAGE;
  274. }
  275. @weakify(self);
  276. [V2TIMManager.sharedInstance markConversation:@[ [NSString stringWithFormat:@"group_%@", self.groupId] ]
  277. markType:@(V2TIM_CONVERSATION_MARK_TYPE_FOLD)
  278. enableMark:NO
  279. succ:nil
  280. fail:nil];
  281. [self.dataProvider setGroupReceiveMessageOpt:opt
  282. Succ:^{
  283. @strongify(self);
  284. [self updateGroupInfo];
  285. }
  286. fail:^(int code, NSString *desc){
  287. }];
  288. }
  289. - (void)didSelectOnTop:(TUICommonSwitchCell *)cell {
  290. if (cell.switcher.on) {
  291. [[TUIConversationPin sharedInstance] addTopConversation:[NSString stringWithFormat:@"group_%@", _groupId]
  292. callback:^(BOOL success, NSString *_Nonnull errorMessage) {
  293. if (success) {
  294. return;
  295. }
  296. cell.switcher.on = !cell.switcher.isOn;
  297. [TUITool makeToast:errorMessage];
  298. }];
  299. } else {
  300. [[TUIConversationPin sharedInstance] removeTopConversation:[NSString stringWithFormat:@"group_%@", _groupId]
  301. callback:^(BOOL success, NSString *_Nonnull errorMessage) {
  302. if (success) {
  303. return;
  304. }
  305. cell.switcher.on = !cell.switcher.isOn;
  306. [TUITool makeToast:errorMessage];
  307. }];
  308. }
  309. }
  310. - (void)didDeleteGroup:(TUIButtonCell *)cell {
  311. UIAlertController *ac = [UIAlertController alertControllerWithTitle:nil
  312. message:TIMCommonLocalizableString(TUIKitGroupProfileDeleteGroupTips)
  313. preferredStyle:UIAlertControllerStyleActionSheet];
  314. @weakify(self);
  315. [ac tuitheme_addAction:[UIAlertAction
  316. actionWithTitle:TIMCommonLocalizableString(Confirm)
  317. style:UIAlertActionStyleDestructive
  318. handler:^(UIAlertAction *_Nonnull action) {
  319. @strongify(self);
  320. @weakify(self);
  321. if ([self.dataProvider.groupInfo canDismissGroup]) {
  322. [self.dataProvider
  323. dismissGroup:^{
  324. @strongify(self);
  325. @weakify(self);
  326. dispatch_async(dispatch_get_main_queue(), ^{
  327. @strongify(self);
  328. UIViewController *vc = [self findConversationListViewController];
  329. [[TUIConversationPin sharedInstance]
  330. removeTopConversation:[NSString stringWithFormat:@"group_%@", self.groupId]
  331. callback:nil];
  332. [V2TIMManager.sharedInstance markConversation:@[ [NSString stringWithFormat:@"group_%@", self.groupId] ]
  333. markType:@(V2TIM_CONVERSATION_MARK_TYPE_FOLD)
  334. enableMark:NO
  335. succ:^(NSArray<V2TIMConversationOperationResult *> *result) {
  336. [self.navigationController popToViewController:vc animated:YES];
  337. }
  338. fail:^(int code, NSString *desc) {
  339. [self.navigationController popToViewController:vc animated:YES];
  340. }];
  341. });
  342. }
  343. fail:^(int code, NSString *msg) {
  344. [TUITool makeToastError:code msg:msg];
  345. }];
  346. } else {
  347. [self.dataProvider
  348. quitGroup:^{
  349. @strongify(self);
  350. @weakify(self);
  351. dispatch_async(dispatch_get_main_queue(), ^{
  352. @strongify(self);
  353. UIViewController *vc = [self findConversationListViewController];
  354. [[TUIConversationPin sharedInstance]
  355. removeTopConversation:[NSString stringWithFormat:@"group_%@", self.groupId]
  356. callback:nil];
  357. [V2TIMManager.sharedInstance markConversation:@[ [NSString stringWithFormat:@"group_%@", self.groupId] ]
  358. markType:@(V2TIM_CONVERSATION_MARK_TYPE_FOLD)
  359. enableMark:NO
  360. succ:^(NSArray<V2TIMConversationOperationResult *> *result) {
  361. [self.navigationController popToViewController:vc animated:YES];
  362. }
  363. fail:^(int code, NSString *desc) {
  364. [self.navigationController popToViewController:vc animated:YES];
  365. }];
  366. });
  367. }
  368. fail:^(int code, NSString *msg) {
  369. [TUITool makeToastError:code msg:msg];
  370. }];
  371. }
  372. }]];
  373. [ac tuitheme_addAction:[UIAlertAction actionWithTitle:TIMCommonLocalizableString(Cancel) style:UIAlertActionStyleCancel handler:nil]];
  374. [self presentViewController:ac animated:YES completion:nil];
  375. }
  376. - (void)didReportGroup:(TUIButtonCell *)cell {
  377. NSURL *url = [NSURL URLWithString:@"https://cloud.tencent.com/act/event/report-platform"];
  378. [TUITool openLinkWithURL:url];
  379. }
  380. - (UIViewController *)findConversationListViewController {
  381. UIViewController *vc = self.navigationController.viewControllers[0];
  382. for (UIViewController *vc in self.navigationController.viewControllers) {
  383. if ([vc isKindOfClass:NSClassFromString(@"TUIFoldListViewController")]) {
  384. return vc;
  385. }
  386. }
  387. return vc;
  388. }
  389. - (void)didSelectOnFoldConversation:(TUICommonSwitchCell *)cell {
  390. BOOL enableMark = NO;
  391. if (cell.switcher.on) {
  392. enableMark = YES;
  393. }
  394. @weakify(self);
  395. [V2TIMManager.sharedInstance markConversation:@[ [NSString stringWithFormat:@"group_%@", self.groupId] ]
  396. markType:@(V2TIM_CONVERSATION_MARK_TYPE_FOLD)
  397. enableMark:enableMark
  398. succ : ^(NSArray<V2TIMConversationOperationResult *> *result) {
  399. cell.switchData.on = enableMark;
  400. [[TUIConversationPin sharedInstance] removeTopConversation:[NSString stringWithFormat:@"group_%@", self.groupId]
  401. callback:^(BOOL success, NSString *_Nonnull errorMessage) {
  402. @strongify(self);
  403. [self updateGroupInfo];
  404. }];
  405. } fail:nil];
  406. }
  407. - (void)didSelectOnChangeBackgroundImage:(TUICommonTextCell *)cell {
  408. @weakify(self);
  409. NSString *conversationID = [NSString stringWithFormat:@"group_%@", self.groupId];
  410. TUISelectAvatarController *vc = [[TUISelectAvatarController alloc] init];
  411. vc.selectAvatarType = TUISelectAvatarTypeConversationBackGroundCover;
  412. vc.profilFaceURL = [self getBackgroundImageUrlByConversationID:conversationID];
  413. [self.navigationController pushViewController:vc animated:YES];
  414. vc.selectCallBack = ^(NSString *_Nonnull urlStr) {
  415. @strongify(self);
  416. [self appendBackgroundImage:urlStr conversationID:conversationID];
  417. if (IS_NOT_EMPTY_NSSTRING(conversationID)) {
  418. [TUICore notifyEvent:TUICore_TUIContactNotify
  419. subKey:TUICore_TUIContactNotify_UpdateConversationBackgroundImageSubKey
  420. object:self
  421. param:@{TUICore_TUIContactNotify_UpdateConversationBackgroundImageSubKey_ConversationID : conversationID}];
  422. }
  423. };
  424. }
  425. - (NSString *)getBackgroundImageUrlByConversationID:(NSString *)targerConversationID {
  426. if (targerConversationID.length == 0) {
  427. return nil;
  428. }
  429. NSDictionary *dict = [NSUserDefaults.standardUserDefaults objectForKey:@"conversation_backgroundImage_map"];
  430. if (dict == nil) {
  431. dict = @{};
  432. }
  433. NSString *conversationID_UserID = [NSString stringWithFormat:@"%@_%@", targerConversationID, [TUILogin getUserID]];
  434. if (![dict isKindOfClass:NSDictionary.class] || ![dict.allKeys containsObject:conversationID_UserID]) {
  435. return nil;
  436. }
  437. return [dict objectForKey:conversationID_UserID];
  438. }
  439. - (void)appendBackgroundImage:(NSString *)imgUrl conversationID:(NSString *)conversationID {
  440. if (conversationID.length == 0) {
  441. return;
  442. }
  443. NSDictionary *dict = [NSUserDefaults.standardUserDefaults objectForKey:@"conversation_backgroundImage_map"];
  444. if (dict == nil) {
  445. dict = @{};
  446. }
  447. if (![dict isKindOfClass:NSDictionary.class]) {
  448. return;
  449. }
  450. NSString *conversationID_UserID = [NSString stringWithFormat:@"%@_%@", conversationID, [TUILogin getUserID]];
  451. NSMutableDictionary *originDataDict = [NSMutableDictionary dictionaryWithDictionary:dict];
  452. if (imgUrl.length == 0) {
  453. [originDataDict removeObjectForKey:conversationID_UserID];
  454. } else {
  455. [originDataDict setObject:imgUrl forKey:conversationID_UserID];
  456. }
  457. [NSUserDefaults.standardUserDefaults setObject:originDataDict forKey:@"conversation_backgroundImage_map"];
  458. [NSUserDefaults.standardUserDefaults synchronize];
  459. }
  460. - (void)didClearAllHistory:(TUIButtonCell *)cell {
  461. @weakify(self);
  462. UIAlertController *ac = [UIAlertController alertControllerWithTitle:nil
  463. message:TIMCommonLocalizableString(TUIKitClearAllChatHistoryTips)
  464. preferredStyle:UIAlertControllerStyleAlert];
  465. [ac tuitheme_addAction:[UIAlertAction actionWithTitle:TIMCommonLocalizableString(Confirm)
  466. style:UIAlertActionStyleDestructive
  467. handler:^(UIAlertAction *_Nonnull action) {
  468. @strongify(self);
  469. [self.dataProvider
  470. clearAllHistory:^{
  471. [TUICore notifyEvent:TUICore_TUIConversationNotify
  472. subKey:TUICore_TUIConversationNotify_ClearConversationUIHistorySubKey
  473. object:self
  474. param:nil];
  475. [TUITool makeToast:@"success"];
  476. }
  477. fail:^(int code, NSString *desc) {
  478. [TUITool makeToastError:code msg:desc];
  479. }];
  480. }]];
  481. [ac tuitheme_addAction:[UIAlertAction actionWithTitle:TIMCommonLocalizableString(Cancel) style:UIAlertActionStyleCancel handler:nil]];
  482. [self presentViewController:ac animated:YES completion:nil];
  483. }
  484. - (UINavigationController *)pushNavigationController {
  485. return self.navigationController;
  486. }
  487. - (void)didSelectGroupNotice {
  488. TUIGroupNoticeController *vc = [[TUIGroupNoticeController alloc] init];
  489. vc.groupID = self.groupId;
  490. __weak typeof(self) weakSelf = self;
  491. vc.onNoticeChanged = ^{
  492. [weakSelf updateGroupInfo];
  493. };
  494. [self.navigationController pushViewController:vc animated:YES];
  495. }
  496. #pragma mark TUIProfileCardDelegate
  497. - (void)didTapOnAvatar:(TUIProfileCardCell *)cell {
  498. TUISelectAvatarController *vc = [[TUISelectAvatarController alloc] init];
  499. vc.selectAvatarType = TUISelectAvatarTypeGroupAvatar;
  500. vc.profilFaceURL = self.dataProvider.groupInfo.faceURL;
  501. [self.navigationController pushViewController:vc animated:YES];
  502. @weakify(self);
  503. vc.selectCallBack = ^(NSString *_Nonnull urlStr) {
  504. @strongify(self);
  505. if (urlStr.length > 0) {
  506. V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
  507. info.groupID = self.groupId;
  508. info.faceURL = urlStr;
  509. [[V2TIMManager sharedInstance] setGroupInfo:info
  510. succ:^{
  511. [self updateGroupInfo];
  512. }
  513. fail:^(int code, NSString *msg) {
  514. [TUITool makeToastError:code msg:msg];
  515. }];
  516. }
  517. };
  518. }
  519. #pragma mark TUIModifyViewDelegate
  520. - (void)modifyView:(TUIModifyView *)modifyView didModiyContent:(NSString *)content {
  521. if (modifyView.tag == 0) {
  522. [self.dataProvider setGroupName:content];
  523. } else if (modifyView.tag == 1) {
  524. [self.dataProvider setGroupNotification:content];
  525. } else if (modifyView.tag == 2) {
  526. [self.dataProvider setGroupMemberNameCard:content];
  527. }
  528. }
  529. @end
  530. @interface IUGroupView : UIView
  531. @property(nonatomic, strong) UIView *view;
  532. @end
  533. @implementation IUGroupView
  534. - (instancetype)init {
  535. self = [super init];
  536. if (self) {
  537. self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
  538. [self addSubview:self.view];
  539. }
  540. return self;
  541. }
  542. @end