2
0

WFCUConversationSettingViewController.m 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368
  1. //
  2. // ConversationSettingViewController.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/11/2.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUConversationSettingViewController.h"
  9. #import <SDWebImage/SDWebImage.h>
  10. #import <WFChatClient/WFCChatClient.h>
  11. #import "WFCUConversationSettingMemberCollectionViewLayout.h"
  12. #import "WFCUConversationSettingMemberCell.h"
  13. #import "WFCUContactListViewController.h"
  14. #import "WFCUMessageListViewController.h"
  15. #import "WFCUGeneralModifyViewController.h"
  16. #import "WFCUSwitchTableViewCell.h"
  17. #import "WFCUProfileTableViewController.h"
  18. #import "GroupManageTableViewController.h"
  19. #import "WFCUGroupMemberCollectionViewController.h"
  20. #import "WFCUFilesViewController.h"
  21. #import "WFCUSeletedUserViewController.h"
  22. #import "MBProgressHUD.h"
  23. #import "WFCUMyProfileTableViewController.h"
  24. #import "WFCUConversationSearchTableViewController.h"
  25. #import "WFCUChannelProfileViewController.h"
  26. #import "QrCodeHelper.h"
  27. #import "UIView+Toast.h"
  28. #import "WFCUConfigManager.h"
  29. #import "WFCUUtilities.h"
  30. #import "WFCUGroupAnnouncementViewController.h"
  31. #import "UIFont+YH.h"
  32. #import "UIColor+YH.h"
  33. #import "WFCUEnum.h"
  34. #import "WFCUImage.h"
  35. @interface WFCUConversationSettingViewController () <UITableViewDataSource, UITableViewDelegate, UICollectionViewDelegate, UICollectionViewDataSource>
  36. @property (nonatomic, strong)UICollectionView *memberCollectionView;
  37. @property (nonatomic, strong)WFCUConversationSettingMemberCollectionViewLayout *memberCollectionViewLayout;
  38. @property (nonatomic, strong)UITableView *tableView;
  39. @property (nonatomic, strong)WFCCGroupInfo *groupInfo;
  40. @property (nonatomic, strong)WFCCUserInfo *userInfo;
  41. @property (nonatomic, strong)WFCCChannelInfo *channelInfo;
  42. @property (nonatomic, strong)NSArray<WFCCGroupMember *> *memberList;
  43. @property (nonatomic, strong)UIImageView *channelPortrait;
  44. @property (nonatomic, strong)UILabel *channelName;
  45. @property (nonatomic, strong)UILabel *channelDesc;
  46. @property (nonatomic, strong)WFCUGroupAnnouncement *groupAnnouncement;
  47. @property (nonatomic, assign)BOOL showMoreMember;
  48. @property (nonatomic, assign)int extraBtnNumber;
  49. @property (nonatomic, assign)int memberCollectionCount;
  50. @end
  51. #define Group_Member_Cell_Reuese_ID @"Group_Member_Cell_Reuese_ID"
  52. #define Group_Member_Visible_Lines 9
  53. @implementation WFCUConversationSettingViewController
  54. - (void)viewDidLoad {
  55. [super viewDidLoad];
  56. if (self.conversation.type == Channel_Type) {
  57. self.title = WFCString(@"ChannelDesc");
  58. } else {
  59. self.title = WFCString(@"ConversationDetail");
  60. }
  61. if (self.conversation.type == Single_Type) {
  62. self.userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.conversation.target refresh:YES];
  63. self.memberList = @[self.conversation.target];
  64. } else if(self.conversation.type == Group_Type){
  65. self.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:self.conversation.target refresh:YES];
  66. self.memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.conversation.target forceUpdate:YES];
  67. } else if(self.conversation.type == Channel_Type) {
  68. self.channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:self.conversation.target refresh:YES];
  69. self.memberList = @[self.conversation.target];
  70. } else if(self.conversation.type == SecretChat_Type) {
  71. WFCCSecretChatInfo *secretChatInfo = [[WFCCIMService sharedWFCIMService] getSecretChatInfo:self.conversation.target];
  72. if(!secretChatInfo) {
  73. [self.navigationController popViewControllerAnimated:YES];
  74. }
  75. NSString *userId = [[WFCCIMService sharedWFCIMService] getSecretChatInfo:self.conversation.target].userId;
  76. self.userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:userId refresh:YES];
  77. self.memberList = @[userId];
  78. }
  79. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
  80. if (@available(iOS 15, *)) {
  81. self.tableView.sectionHeaderTopPadding = 0;
  82. }
  83. self.tableView.delegate = self;
  84. self.tableView.dataSource = self;
  85. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 146)];
  86. footerView.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  87. self.tableView.tableFooterView = footerView;
  88. if (self.conversation.type != Group_Type) {
  89. footerView.frame = CGRectMake(0, 0, 0, 0);
  90. }
  91. [self.view addSubview:self.tableView];
  92. if(self.conversation.type == Group_Type) {
  93. __weak typeof(self)ws = self;
  94. [[NSNotificationCenter defaultCenter] addObserverForName:kGroupMemberUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
  95. if ([ws.conversation.target isEqualToString:note.object]) {
  96. ws.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:ws.conversation.target refresh:NO];
  97. ws.memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:ws.conversation.target forceUpdate:NO];
  98. [ws setupMemberCollectionView];
  99. [ws.memberCollectionView reloadData];
  100. [ws.tableView reloadData];
  101. }
  102. }];
  103. [[NSNotificationCenter defaultCenter] addObserverForName:kGroupInfoUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
  104. NSArray<WFCCGroupInfo *> *updateGroupInfos = [note.userInfo objectForKey:@"groupInfoList"];
  105. [updateGroupInfos enumerateObjectsUsingBlock:^(WFCCGroupInfo * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  106. if ([ws.conversation.target isEqualToString:obj.target]) {
  107. ws.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:ws.conversation.target refresh:NO];
  108. ws.memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:ws.conversation.target forceUpdate:NO];
  109. [ws setupMemberCollectionView];
  110. [ws.memberCollectionView reloadData];
  111. [ws.tableView reloadData];
  112. }
  113. }];
  114. }];
  115. [[WFCUConfigManager globalManager].appServiceProvider getGroupAnnouncement:self.conversation.target success:^(WFCUGroupAnnouncement *announcement) {
  116. dispatch_async(dispatch_get_main_queue(), ^{
  117. ws.groupAnnouncement = announcement;
  118. [ws.tableView reloadData];
  119. });
  120. } error:^(int error_code) {
  121. }];
  122. } else if(self.conversation.type == Channel_Type) {
  123. CGFloat portraitWidth = 80;
  124. CGFloat top = 40;
  125. CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
  126. self.channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:self.conversation.target refresh:YES];
  127. self.channelPortrait = [[UIImageView alloc] initWithFrame:CGRectMake((screenWidth - portraitWidth)/2, top, portraitWidth, portraitWidth)];
  128. [self.channelPortrait sd_setImageWithURL:[NSURL URLWithString:[self.channelInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[WFCUImage imageNamed:@"channel_default_portrait"]];
  129. self.channelPortrait.userInteractionEnabled = YES;
  130. [self.channelPortrait addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapChannelPortrait:)]];
  131. top += portraitWidth;
  132. top += 20;
  133. self.channelName = [[UILabel alloc] initWithFrame:CGRectMake(40, top, screenWidth - 40 - 40, 18)];
  134. self.channelName.font = [UIFont systemFontOfSize:18];
  135. self.channelName.textAlignment = NSTextAlignmentCenter;
  136. self.channelName.text = self.channelInfo.name;
  137. top += 18;
  138. top += 20;
  139. if (self.channelInfo.desc) {
  140. NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:self.channelInfo.desc];
  141. UIFont *font = [UIFont systemFontOfSize:14];
  142. [attributeString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, self.channelInfo.desc.length)];
  143. NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
  144. CGRect rect = [attributeString boundingRectWithSize:CGSizeMake(screenWidth - 80, CGFLOAT_MAX) options:options context:nil];
  145. self.channelDesc = [[UILabel alloc] initWithFrame:CGRectMake(40, top, screenWidth - 80, rect.size.height)];
  146. self.channelDesc.font = [UIFont systemFontOfSize:14];
  147. self.channelDesc.textAlignment = NSTextAlignmentCenter;
  148. self.channelDesc.text = self.channelInfo.desc;
  149. self.channelDesc.numberOfLines = 0;
  150. [self.channelDesc sizeToFit];
  151. top += rect.size.height;
  152. top += 20;
  153. }
  154. UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, top)];
  155. [container addSubview:self.channelPortrait];
  156. [container addSubview:self.channelName];
  157. [container addSubview:self.channelDesc];
  158. self.tableView.tableHeaderView = container;
  159. }
  160. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onReceiveMessages:) name:kReceiveMessages object:nil];
  161. }
  162. - (void)setupMemberCollectionView {
  163. if (self.conversation.type == Single_Type || self.conversation.type == Group_Type) {
  164. self.memberCollectionViewLayout = [[WFCUConversationSettingMemberCollectionViewLayout alloc] initWithItemMargin:8];
  165. if (self.conversation.type == Single_Type) {
  166. self.extraBtnNumber = 1;
  167. self.memberCollectionCount = 2;
  168. } else if(self.conversation.type == Group_Type) {
  169. if(self.groupInfo.type == GroupType_Organization) {
  170. self.extraBtnNumber = 0;
  171. self.memberCollectionCount = (int)self.memberList.count + self.extraBtnNumber;
  172. } else if ([self isGroupManager]) {
  173. self.extraBtnNumber = 2;
  174. self.memberCollectionCount = (int)self.memberList.count + self.extraBtnNumber;
  175. } else if(self.groupInfo.type == GroupType_Restricted) {
  176. if (self.groupInfo.joinType == 1 || self.groupInfo.joinType == 0) {
  177. self.extraBtnNumber = 1;
  178. self.memberCollectionCount = (int)self.memberList.count + self.extraBtnNumber;
  179. } else {
  180. self.memberCollectionCount = (int)self.memberList.count;
  181. }
  182. } else {
  183. self.extraBtnNumber = 1;
  184. self.memberCollectionCount = (int)self.memberList.count + self.extraBtnNumber;
  185. }
  186. if (self.memberCollectionCount > Group_Member_Visible_Lines * 5) {
  187. self.memberCollectionCount = Group_Member_Visible_Lines * 5;
  188. self.showMoreMember = YES;
  189. }
  190. } else if(self.conversation.type == Channel_Type) {
  191. self.memberCollectionCount = 1;
  192. } else if(self.conversation.type == SecretChat_Type) {
  193. self.memberCollectionCount = 0;
  194. self.extraBtnNumber = 0;
  195. }
  196. self.memberCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, [self.memberCollectionViewLayout getHeigthOfItemCount:self.memberCollectionCount]) collectionViewLayout:self.memberCollectionViewLayout];
  197. self.memberCollectionView.delegate = self;
  198. self.memberCollectionView.dataSource = self;
  199. self.memberCollectionView.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  200. [self.memberCollectionView registerClass:[WFCUConversationSettingMemberCell class] forCellWithReuseIdentifier:Group_Member_Cell_Reuese_ID];
  201. if (self.showMoreMember) {
  202. UIView *head = [[UIView alloc] init];
  203. CGRect frame = self.memberCollectionView.frame;
  204. frame.size.height += 36;
  205. head.frame = frame;
  206. [head addSubview:self.memberCollectionView];
  207. UIButton *moreBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, frame.size.height - 40, frame.size.width, 36)];
  208. [moreBtn setTitle:WFCString(@"ShowAllMembers") forState:UIControlStateNormal];
  209. moreBtn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:17];
  210. [moreBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  211. moreBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  212. [moreBtn addTarget:self action:@selector(onViewAllMember:) forControlEvents:UIControlEventTouchDown];
  213. [head addSubview:moreBtn];
  214. head.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  215. self.tableView.tableHeaderView = head;
  216. } else {
  217. self.tableView.tableHeaderView = self.memberCollectionView;
  218. }
  219. }
  220. }
  221. - (void)onReceiveMessages:(NSNotification *)notification {
  222. if(self.conversation.type == Group_Type) {
  223. NSArray<WFCCMessage *> *messages = notification.object;
  224. __block BOOL reload = NO;
  225. [messages enumerateObjectsUsingBlock:^(WFCCMessage * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  226. if([obj.content isKindOfClass:WFCCGroupSettingsNotificationContent.class]) {
  227. WFCCGroupSettingsNotificationContent *notiContent = (WFCCGroupSettingsNotificationContent *)obj.content;
  228. if([notiContent.groupId isEqualToString:self.conversation.target]) {
  229. reload = YES;
  230. *stop = YES;
  231. }
  232. }
  233. }];
  234. if(reload) {
  235. __weak typeof(self)ws = self;
  236. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  237. ws.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:ws.conversation.target refresh:NO];
  238. [ws.tableView reloadData];
  239. });
  240. }
  241. }
  242. }
  243. - (void)onViewAllMember:(id)sender {
  244. WFCUGroupMemberCollectionViewController *vc = [[WFCUGroupMemberCollectionViewController alloc] init];
  245. vc.groupId = self.groupInfo.target;
  246. [self.navigationController pushViewController:vc animated:YES];
  247. }
  248. - (void)onTapChannelPortrait:(id)sender {
  249. WFCUChannelProfileViewController *pvc = [[WFCUChannelProfileViewController alloc] init];
  250. pvc.channelInfo = self.channelInfo;
  251. [self.navigationController pushViewController:pvc animated:YES];
  252. }
  253. - (void)didReceiveMemoryWarning {
  254. [super didReceiveMemoryWarning];
  255. }
  256. - (BOOL)isChannelOwner {
  257. if (self.conversation.type != Channel_Type) {
  258. return false;
  259. }
  260. return [self.channelInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId];
  261. }
  262. - (BOOL)isGroupOwner {
  263. if (self.conversation.type != Group_Type) {
  264. return false;
  265. }
  266. return [self.groupInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId];
  267. }
  268. - (BOOL)isGroupManager {
  269. if (self.conversation.type != Group_Type) {
  270. return false;
  271. }
  272. if ([self isGroupOwner]) {
  273. return YES;
  274. }
  275. __block BOOL isManager = false;
  276. [self.memberList enumerateObjectsUsingBlock:^(WFCCGroupMember * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  277. if ([obj.memberId isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  278. if (obj.type == Member_Type_Manager || obj.type == Member_Type_Owner) {
  279. isManager = YES;
  280. }
  281. *stop = YES;
  282. }
  283. }];
  284. return isManager;
  285. }
  286. - (void)onDestroySecretChat:(id)sender {
  287. __weak typeof(self) ws = self;
  288. [[WFCCIMService sharedWFCIMService] destroySecretChat:self.conversation.target success:^{
  289. [ws.navigationController popToRootViewControllerAnimated:YES];
  290. } error:^(int error_code) {
  291. [ws.navigationController popToRootViewControllerAnimated:YES];
  292. }];
  293. }
  294. - (void)onTransferGroup:(id)sender {
  295. if ([self isGroupOwner]) {
  296. WFCUContactListViewController *pvc = [[WFCUContactListViewController alloc] init];
  297. pvc.selectContact = YES;
  298. pvc.multiSelect = NO;
  299. __weak typeof(self)ws = self;
  300. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  301. if (contacts.count == 1) {
  302. WFCCUserInfo *newOwnerUserInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[contacts objectAtIndex:0] inGroup:ws.groupInfo.target refresh:NO];
  303. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:[NSString stringWithFormat:@"请确认是否把群组转让给 %@", newOwnerUserInfo.readableName] preferredStyle:UIAlertControllerStyleAlert];
  304. UIAlertAction *actionDismiss = [UIAlertAction actionWithTitle:@"转让" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  305. __block MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:ws.view animated:YES];
  306. hud.label.text = WFCString(@"Transfering");
  307. [hud showAnimated:YES];
  308. [[WFCCIMService sharedWFCIMService] transferGroup:ws.conversation.target to:[contacts objectAtIndex:0] notifyLines:nil notifyContent:nil success:^{
  309. NSLog(@"Transfer success");
  310. [hud hideAnimated:NO];
  311. hud = [MBProgressHUD showHUDAddedTo:ws.view animated:NO];
  312. hud.label.text = WFCString(@"Transfered");
  313. hud.mode = MBProgressHUDModeText;
  314. hud.removeFromSuperViewOnHide = YES;
  315. [hud hideAnimated:NO afterDelay:1.5];
  316. } error:^(int error_code) {
  317. NSLog(@"Transfer error");
  318. [hud hideAnimated:NO];
  319. hud = [MBProgressHUD showHUDAddedTo:ws.view animated:NO];
  320. hud.label.text = WFCString(@"TransferFailed");
  321. hud.mode = MBProgressHUDModeText;
  322. hud.removeFromSuperViewOnHide = YES;
  323. [hud hideAnimated:NO afterDelay:1.5];
  324. }];
  325. }];
  326. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  327. }];
  328. [alert addAction:actionCancel];
  329. [alert addAction:actionDismiss];
  330. dispatch_async(dispatch_get_main_queue(), ^{
  331. [ws presentViewController:alert animated:YES completion:nil];
  332. });
  333. }
  334. };
  335. NSMutableArray *candidateUsers = [[NSMutableArray alloc] init];
  336. NSMutableArray *disableUsers = [[NSMutableArray alloc] init];
  337. BOOL isOwner = [self isGroupOwner];
  338. for (WFCCGroupMember *member in [[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupInfo.target forceUpdate:NO]) {
  339. [candidateUsers addObject:member.memberId];
  340. }
  341. [disableUsers addObject:[WFCCNetworkService sharedInstance].userId];
  342. pvc.candidateUsers = candidateUsers;
  343. pvc.disableUsers = [disableUsers copy];
  344. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:pvc];
  345. [self.navigationController presentViewController:navi animated:YES completion:nil];
  346. }
  347. }
  348. - (void)onDeleteAndQuit:(id)sender {
  349. if(self.conversation.type == Group_Type) {
  350. if ([self isGroupOwner]) {
  351. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:@"请确认是否解散群组" preferredStyle:UIAlertControllerStyleAlert];
  352. __weak typeof(self) ws = self;
  353. UIAlertAction *actionDismiss = [UIAlertAction actionWithTitle:@"解散" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  354. [[WFCCIMService sharedWFCIMService] removeConversation:self.conversation clearMessage:YES];
  355. [[WFCCIMService sharedWFCIMService] dismissGroup:self.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
  356. [ws.navigationController popToRootViewControllerAnimated:YES];
  357. } error:^(int error_code) {
  358. }];
  359. }];
  360. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  361. }];
  362. [alert addAction:actionCancel];
  363. [alert addAction:actionDismiss];
  364. [self presentViewController:alert animated:YES completion:nil];
  365. } else {
  366. __weak typeof(self) ws = self;
  367. //可以提示是否清空消息,如果保留消息keepMessage就为YES
  368. [[WFCCIMService sharedWFCIMService] quitGroup:self.conversation.target keepMessage:NO notifyLines:@[@(0)] notifyContent:nil success:^{
  369. [ws.navigationController popToRootViewControllerAnimated:YES];
  370. } error:^(int error_code) {
  371. }];
  372. }
  373. } else {
  374. if ([self isChannelOwner]) {
  375. __weak typeof(self) ws = self;
  376. [[WFCCIMService sharedWFCIMService] destoryChannel:self.conversation.target success:^{
  377. [[WFCCIMService sharedWFCIMService] removeConversation:ws.conversation clearMessage:YES];
  378. dispatch_async(dispatch_get_main_queue(), ^{
  379. [ws.navigationController popToRootViewControllerAnimated:YES];
  380. });
  381. } error:^(int error_code) {
  382. }];
  383. } else {
  384. __weak typeof(self) ws = self;
  385. [[WFCCIMService sharedWFCIMService] listenChannel:self.conversation.target listen:NO success:^{
  386. [[WFCCIMService sharedWFCIMService] removeConversation:ws.conversation clearMessage:YES];
  387. dispatch_async(dispatch_get_main_queue(), ^{
  388. [ws.navigationController popToRootViewControllerAnimated:YES];
  389. });
  390. } error:^(int error_code) {
  391. }];
  392. }
  393. }
  394. }
  395. - (void)clearMessageAction {
  396. __weak typeof(self)weakSelf = self;
  397. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:WFCString(@"ConfirmDelete") message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  398. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  399. }];
  400. UIAlertAction *actionLocalDelete = [UIAlertAction actionWithTitle:WFCString(@"DeleteLocalMsg") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  401. [[WFCCIMService sharedWFCIMService] clearMessages:self.conversation];
  402. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:weakSelf.view animated:NO];
  403. hud.label.text = WFCString(@"Deleted");
  404. hud.mode = MBProgressHUDModeText;
  405. hud.removeFromSuperViewOnHide = YES;
  406. [hud hideAnimated:NO afterDelay:1.5];
  407. [[NSNotificationCenter defaultCenter] postNotificationName:kMessageListChanged object:weakSelf.conversation];
  408. }];
  409. UIAlertAction *actionRemoteDelete = [UIAlertAction actionWithTitle:WFCString(@"DeleteRemoteMsg") style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  410. __block MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:weakSelf.view animated:YES];
  411. hud.label.text = WFCString(@"Deleting");
  412. [hud showAnimated:YES];
  413. [[WFCCIMService sharedWFCIMService] clearRemoteConversationMessage:weakSelf.conversation success:^{
  414. [hud hideAnimated:NO];
  415. hud = [MBProgressHUD showHUDAddedTo:weakSelf.view animated:NO];
  416. hud.label.text = WFCString(@"Deleted");
  417. hud.mode = MBProgressHUDModeText;
  418. hud.removeFromSuperViewOnHide = YES;
  419. [hud hideAnimated:NO afterDelay:1.5];
  420. [[NSNotificationCenter defaultCenter] postNotificationName:kMessageListChanged object:weakSelf.conversation];
  421. } error:^(int error_code) {
  422. [hud hideAnimated:NO];
  423. hud = [MBProgressHUD showHUDAddedTo:weakSelf.view animated:NO];
  424. hud.label.text = WFCString(@"DeleteFailed");
  425. hud.mode = MBProgressHUDModeText;
  426. hud.removeFromSuperViewOnHide = YES;
  427. [hud hideAnimated:NO afterDelay:1.5];
  428. }];
  429. }];
  430. //把action添加到actionSheet里
  431. [actionSheet addAction:actionLocalDelete];
  432. if(self.conversation.type != SecretChat_Type && !(self.conversation.type == Group_Type && self.groupInfo.superGroup)) {
  433. [actionSheet addAction:actionRemoteDelete];
  434. }
  435. [actionSheet addAction:actionCancel];
  436. //相当于之前的[actionSheet show];
  437. dispatch_async(dispatch_get_main_queue(), ^{
  438. [self presentViewController:actionSheet animated:YES completion:nil];
  439. });
  440. }
  441. - (void)setBurnTime:(int)ms {
  442. [[WFCCIMService sharedWFCIMService] setSecretChat:self.conversation.target burnTime:ms];
  443. [self.tableView reloadData];
  444. }
  445. - (void)onBurnTimeAction {
  446. __weak typeof(self)weakSelf = self;
  447. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"设置销毁时间" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  448. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  449. }];
  450. UIAlertAction *actionNoBurn = [UIAlertAction actionWithTitle:@"不销毁" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  451. [weakSelf setBurnTime:0];
  452. }];
  453. UIAlertAction *action3s = [UIAlertAction actionWithTitle:@"3秒钟" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  454. [weakSelf setBurnTime:3000];
  455. }];
  456. UIAlertAction *action10s = [UIAlertAction actionWithTitle:@"10秒钟" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  457. [weakSelf setBurnTime:10000];
  458. }];
  459. UIAlertAction *action30s = [UIAlertAction actionWithTitle:@"30秒钟" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  460. [weakSelf setBurnTime:30000];
  461. }];
  462. UIAlertAction *action60s = [UIAlertAction actionWithTitle:@"1分钟" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  463. [weakSelf setBurnTime:60000];
  464. }];
  465. UIAlertAction *action600s = [UIAlertAction actionWithTitle:@"10分钟" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  466. [weakSelf setBurnTime:600000];
  467. }];
  468. //把action添加到actionSheet里
  469. [actionSheet addAction:actionNoBurn];
  470. [actionSheet addAction:action3s];
  471. [actionSheet addAction:action10s];
  472. [actionSheet addAction:action30s];
  473. [actionSheet addAction:action60s];
  474. [actionSheet addAction:action600s];
  475. [actionSheet addAction:actionCancel];
  476. //相当于之前的[actionSheet show];
  477. [self presentViewController:actionSheet animated:YES completion:nil];
  478. }
  479. - (void)viewWillAppear:(BOOL)animated {
  480. [super viewWillAppear:animated];
  481. if (self.conversation.type == Single_Type) {
  482. self.userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.conversation.target refresh:NO];
  483. self.memberList = @[self.conversation.target];
  484. } else if(self.conversation.type == Group_Type) {
  485. self.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:self.conversation.target refresh:NO];
  486. self.memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.conversation.target forceUpdate:NO];
  487. } else if(self.conversation.type == Channel_Type) {
  488. self.channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:self.conversation.target refresh:NO];
  489. self.memberList = @[self.conversation.target];
  490. } else if(self.conversation.type == SecretChat_Type) {
  491. NSString *userId = [[WFCCIMService sharedWFCIMService] getSecretChatInfo:self.conversation.target].userId;
  492. self.userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:userId refresh:NO];
  493. self.memberList = @[userId];
  494. }
  495. [self setupMemberCollectionView];
  496. [self.memberCollectionView reloadData];
  497. [self.tableView reloadData];
  498. }
  499. #pragma mark - UITableViewDataSource<NSObject>
  500. - (BOOL)isGroupNameCell:(NSIndexPath *)indexPath {
  501. if(self.conversation.type == Group_Type && indexPath.section == 0 && indexPath.row == 0) {
  502. return YES;
  503. }
  504. return NO;
  505. }
  506. //
  507. //- (BOOL)isGroupPortraitCell:(NSIndexPath *)indexPath {
  508. // if(self.conversation.type == Group_Type && indexPath.section == 0 && indexPath.row == 1) {
  509. // return YES;
  510. // }
  511. // return NO;
  512. //}
  513. - (BOOL)isGroupQrCodeCell:(NSIndexPath *)indexPath {
  514. if(self.conversation.type == Group_Type && indexPath.section == 0 && indexPath.row == 1) {
  515. return YES;
  516. }
  517. return NO;
  518. }
  519. - (BOOL)isGroupManageCell:(NSIndexPath *)indexPath {
  520. if(self.conversation.type == Group_Type && indexPath.section == 0 && indexPath.row == 2) {
  521. if ([self isGroupManager] && self.groupInfo.type == GroupType_Restricted) {
  522. return YES;
  523. } else {
  524. return NO;
  525. }
  526. }
  527. return NO;
  528. }
  529. - (BOOL)isGroupAnnouncementCell:(NSIndexPath *)indexPath {
  530. if(self.conversation.type == Group_Type && indexPath.section == 0) {
  531. if ([self isGroupManager] && self.groupInfo.type == GroupType_Restricted) {
  532. if (indexPath.row == 3) {
  533. return YES;
  534. }
  535. } else {
  536. if (indexPath.row == 2) {
  537. return YES;
  538. }
  539. }
  540. }
  541. return NO;
  542. }
  543. - (BOOL)isGroupRemarkCell:(NSIndexPath *)indexPath {
  544. if(self.conversation.type == Group_Type && indexPath.section == 0) {
  545. if ([self isGroupManager] && self.groupInfo.type == GroupType_Restricted) {
  546. if (indexPath.row == 4) {
  547. return YES;
  548. }
  549. } else {
  550. if (indexPath.row == 3) {
  551. return YES;
  552. }
  553. }
  554. }
  555. return NO;
  556. }
  557. - (BOOL)isSearchMessageCell:(NSIndexPath *)indexPath {
  558. if((self.conversation.type == Group_Type && indexPath.section == 1 && indexPath.row == 0)
  559. ||(self.conversation.type == Single_Type && indexPath.section == 0 && indexPath.row == 0)
  560. ||(self.conversation.type == SecretChat_Type && indexPath.section == 0 && indexPath.row == 0)
  561. ||(self.conversation.type == Channel_Type && indexPath.section == 0 && indexPath.row == 0)) {
  562. return YES;
  563. }
  564. return NO;
  565. }
  566. - (BOOL)isMessageSilentCell:(NSIndexPath *)indexPath {
  567. if((self.conversation.type == Group_Type && indexPath.section == 2 && indexPath.row == 0)
  568. ||(self.conversation.type == Single_Type && indexPath.section == 1 && indexPath.row == 0)
  569. ||(self.conversation.type == SecretChat_Type && indexPath.section == 1 && indexPath.row == 0)
  570. ||(self.conversation.type == Channel_Type && indexPath.section == 1 && indexPath.row == 0)) {
  571. return YES;
  572. }
  573. return NO;
  574. }
  575. - (BOOL)isSetTopCell:(NSIndexPath *)indexPath {
  576. if((self.conversation.type == Group_Type && indexPath.section == 2 && indexPath.row == 1)
  577. ||(self.conversation.type == Single_Type && indexPath.section == 1 && indexPath.row == 1)
  578. ||(self.conversation.type == SecretChat_Type && indexPath.section == 1 && indexPath.row == 1)
  579. ||(self.conversation.type == Channel_Type && indexPath.section == 1 && indexPath.row == 1)) {
  580. return YES;
  581. }
  582. return NO;
  583. }
  584. - (BOOL)isSaveGroupCell:(NSIndexPath *)indexPath {
  585. if((self.conversation.type == Group_Type && indexPath.section == 2 && indexPath.row == 2)) {
  586. return YES;
  587. }
  588. return NO;
  589. }
  590. - (BOOL)isGroupNameCardCell:(NSIndexPath *)indexPath {
  591. if((self.conversation.type == Group_Type && indexPath.section == 3 && indexPath.row == 0)) {
  592. return YES;
  593. }
  594. return NO;
  595. }
  596. - (BOOL)isShowNameCardCell:(NSIndexPath *)indexPath {
  597. if((self.conversation.type == Group_Type && indexPath.section == 3 && indexPath.row == 1)) {
  598. return YES;
  599. }
  600. return NO;
  601. }
  602. - (BOOL)isClearMessageCell:(NSIndexPath *)indexPath {
  603. if((self.conversation.type == Group_Type && indexPath.section == 4 && indexPath.row == 0)
  604. || (self.conversation.type == Single_Type && indexPath.section == 2 && indexPath.row == 0)
  605. || (self.conversation.type == SecretChat_Type && indexPath.section == 3 && indexPath.row == 0)
  606. || (self.conversation.type == Channel_Type && indexPath.section == 2 && indexPath.row == 0)) {
  607. return YES;
  608. }
  609. return NO;
  610. }
  611. - (BOOL)isQuitGroup:(NSIndexPath *)indexPath {
  612. if(self.conversation.type == Group_Type && indexPath.section == 4 && indexPath.row == 1) {
  613. return YES;
  614. }
  615. return NO;
  616. }
  617. - (BOOL)isTransferGroup:(NSIndexPath *)indexPath {
  618. if(self.conversation.type == Group_Type && indexPath.section == 4 && indexPath.row == 2) {
  619. return YES;
  620. }
  621. return NO;
  622. }
  623. - (BOOL)isFilesCell:(NSIndexPath *)indexPath {
  624. if (self.conversation.type == Group_Type && indexPath.section == 1 && indexPath.row == 1) {
  625. return YES;
  626. } else if (self.conversation.type == Single_Type && indexPath.section == 0 && indexPath.row == 1) {
  627. return YES;
  628. }
  629. return NO;
  630. }
  631. - (BOOL)isDestroySecretChatCell:(NSIndexPath *)indexPath {
  632. if (self.conversation.type == SecretChat_Type && indexPath.section == 3 && indexPath.row == 1) {
  633. return YES;
  634. }
  635. return NO;
  636. }
  637. - (BOOL)isBurnTimeCell:(NSIndexPath *)indexPath {
  638. if (self.conversation.type == SecretChat_Type && indexPath.section == 2 && indexPath.row == 0) {
  639. return YES;
  640. }
  641. return NO;
  642. }
  643. - (BOOL)isUnsubscribeChannel:(NSIndexPath *)indexPath {
  644. if (self.conversation.type == Channel_Type && indexPath.section == 3 && indexPath.row == 0) {
  645. return YES;
  646. }
  647. return NO;
  648. }
  649. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  650. if (self.conversation.type == Group_Type) {
  651. if (section == 0) {
  652. if ([self isGroupManager] && self.groupInfo.type == GroupType_Restricted) {
  653. return 5; //群名称,群二维码,群管理,群公告,群备注
  654. } else {
  655. return 4; //群名称,群二维码,群公告,群备注
  656. }
  657. } else if(section == 1) {
  658. if ([[WFCCIMService sharedWFCIMService] isCommercialServer]) {
  659. return 2; //查找聊天内容, 群文件
  660. }
  661. return 1; //查找聊天内容
  662. } else if(section == 2) {
  663. return 3; //消息免打扰,置顶聊天,保存到通讯录
  664. } else if(section == 3) {
  665. return 2; //群昵称,显示群昵称
  666. } else if(section == 4) {
  667. if(self.groupInfo.type == GroupType_Organization)
  668. return 1; //清空聊天记录,删除退群
  669. else {
  670. if([self isGroupOwner]) {
  671. return 3;
  672. } else {
  673. return 2; //清空聊天记录,删除退群
  674. }
  675. }
  676. }
  677. } else if(self.conversation.type == Single_Type) {
  678. if(section == 0) {
  679. if ([[WFCCIMService sharedWFCIMService] isCommercialServer]) {
  680. return 2; //查找聊天内容, 群文件
  681. }
  682. return 1; //查找聊天内容
  683. } else if(section == 1) {
  684. return 2; //消息免打扰,置顶聊天
  685. } else if(section == 2) {
  686. return 1; //清空聊天记录
  687. }
  688. } else if(self.conversation.type == Channel_Type) {
  689. if(section == 0) {
  690. return 1; //查找聊天内容
  691. } else if(section == 1) {
  692. return 2; //消息免打扰,置顶聊天
  693. } else if(section == 2) {
  694. return 1; //清空聊天记录
  695. } else if(section == 3) {
  696. return 1; //取消订阅/销毁订阅
  697. }
  698. } else if(self.conversation.type == SecretChat_Type) {
  699. if(section == 0) {
  700. return 1; //查找聊天内容
  701. } else if(section == 1) {
  702. return 2; //消息免打扰,置顶聊天
  703. } else if(section == 2) {
  704. return 1; //清空聊天记录,删除密聊
  705. } else if(section == 3) {
  706. return 2; //清空聊天记录,删除密聊
  707. }
  708. }
  709. return 0;
  710. }
  711. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  712. return 9;
  713. }
  714. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  715. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,9)];
  716. view.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  717. return view;
  718. }
  719. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  720. if ([self isGroupAnnouncementCell:indexPath]) {
  721. float height = [WFCUUtilities getTextDrawingSize:self.groupAnnouncement.text font:[UIFont pingFangSCWithWeight:FontWeightStyleRegular size:12] constrainedSize:CGSizeMake(self.view.bounds.size.width - 48, 1000)].height;
  722. if (height > 12 * 3.2) {
  723. height = 12 * 3.2;
  724. }
  725. return height + 50;
  726. }
  727. return 50;
  728. }
  729. - (UITableViewCell *)cellOfTable:(UITableView *)tableView WithTitle:(NSString *)title withDetailTitle:(NSString *)detailTitle withDisclosureIndicator:(BOOL)withDI withSwitch:(BOOL)withSwitch withSwitchType:(SwitchType)type {
  730. if (withSwitch) {
  731. WFCUSwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"styleSwitch"];
  732. if(cell == nil) {
  733. cell = [[WFCUSwitchTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"styleSwitch" conversation:self.conversation];
  734. }
  735. cell.textLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  736. cell.textLabel.textColor = [WFCUConfigManager globalManager].textColor;
  737. cell.detailTextLabel.text = nil;
  738. cell.accessoryType = UITableViewCellAccessoryNone;
  739. cell.accessoryView = nil;
  740. cell.textLabel.text = title;
  741. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  742. cell.type = type;
  743. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0 );
  744. return cell;
  745. } else {
  746. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"style1Cell"];
  747. if (cell == nil) {
  748. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"style1Cell"];
  749. }
  750. cell.textLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  751. cell.textLabel.text = title;
  752. cell.detailTextLabel.text = detailTitle;
  753. cell.detailTextLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:15];
  754. cell.accessoryType = withDI ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
  755. cell.accessoryView = nil;
  756. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  757. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0 );
  758. return cell;
  759. }
  760. }
  761. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  762. if ([self isGroupNameCell:indexPath]) {
  763. return [self cellOfTable:tableView WithTitle:WFCString(@"GroupName") withDetailTitle:self.groupInfo.name withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  764. } else if([self isGroupQrCodeCell:indexPath]) {
  765. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QrCell"];
  766. if (cell == nil) {
  767. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"QrCell"];
  768. } else {
  769. cell.textLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  770. cell.textLabel.text = WFCString(@"GroupQRCode");
  771. cell.detailTextLabel.text = nil;
  772. cell.detailTextLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:15];
  773. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  774. cell.accessoryView = nil;
  775. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  776. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0 );
  777. CGFloat width = [UIScreen mainScreen].bounds.size.width;
  778. UIImage *qrcode = [WFCUImage imageNamed:@"qrcode"];
  779. UIImageView *qrview = [[UIImageView alloc] initWithFrame:CGRectMake(width - 60, (50 - 22) / 2.0, 22, 22)];
  780. qrview.image = qrcode;
  781. [cell addSubview:qrview];
  782. }
  783. return cell;
  784. } else if ([self isGroupManageCell:indexPath]) {
  785. return [self cellOfTable:tableView WithTitle:WFCString(@"GroupManage") withDetailTitle:nil withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  786. } else if ([self isGroupRemarkCell:indexPath]) {
  787. return [self cellOfTable:tableView WithTitle:WFCString(@"GroupRemark") withDetailTitle:self.groupInfo.remark withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  788. } else if([self isGroupAnnouncementCell:indexPath]) {
  789. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"announcementCell"];
  790. if (cell == nil) {
  791. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"announcementCell"];
  792. }
  793. cell.textLabel.text = WFCString(@"GroupAnnouncement");
  794. cell.textLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  795. cell.detailTextLabel.text = self.groupAnnouncement.text;
  796. cell.detailTextLabel.numberOfLines = 3;
  797. cell.detailTextLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:12];
  798. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  799. cell.accessoryView = nil;
  800. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  801. return cell;
  802. } else if ([self isSearchMessageCell:indexPath]) {
  803. return [self cellOfTable:tableView WithTitle:WFCString(@"SearchMessageContent") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  804. } else if ([self isMessageSilentCell:indexPath]) {
  805. return [self cellOfTable:tableView WithTitle:WFCString(@"Silent") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Silent];
  806. } else if ([self isSetTopCell:indexPath]) {
  807. return [self cellOfTable:tableView WithTitle:WFCString(@"PinChat") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Top];
  808. } else if ([self isSaveGroupCell:indexPath]) {
  809. return [self cellOfTable:tableView WithTitle:WFCString(@"SaveToContact") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Save_To_Contact];
  810. } else if ([self isGroupNameCardCell:indexPath]) {
  811. WFCCGroupMember *groupMember = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
  812. if (groupMember.alias.length) {
  813. return [self cellOfTable:tableView WithTitle:WFCString(@"NicknameInGroup") withDetailTitle:groupMember.alias withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  814. } else {
  815. return [self cellOfTable:tableView WithTitle:WFCString(@"NicknameInGroup") withDetailTitle:WFCString(@"Unset") withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  816. }
  817. } else if([self isShowNameCardCell:indexPath]) {
  818. return [self cellOfTable:tableView WithTitle:WFCString(@"ShowMemberNickname") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Show_Alias];
  819. } else if ([self isClearMessageCell:indexPath]) {
  820. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
  821. if (cell == nil) {
  822. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
  823. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  824. for (UIView *subView in cell.subviews) {
  825. [subView removeFromSuperview];
  826. }
  827. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
  828. [btn setTitle:WFCString(@"ClearChatHistory") forState:UIControlStateNormal];
  829. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  830. [btn setTitleColor:[UIColor colorWithHexString:@"0xf95569"] forState:UIControlStateNormal];
  831. [btn addTarget:self action:@selector(clearMessageAction) forControlEvents:UIControlEventTouchUpInside];
  832. if (@available(iOS 14, *)) {
  833. [cell.contentView addSubview:btn];
  834. } else {
  835. [cell addSubview:btn];
  836. }
  837. }
  838. return cell;
  839. } else if([self isQuitGroup:indexPath]) {
  840. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
  841. if (cell == nil) {
  842. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
  843. for (UIView *subView in cell.subviews) {
  844. [subView removeFromSuperview];
  845. }
  846. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
  847. if ([self isGroupOwner]) {
  848. [btn setTitle:WFCString(@"DismissGroup") forState:UIControlStateNormal];
  849. } else {
  850. [btn setTitle:WFCString(@"QuitGroup") forState:UIControlStateNormal];
  851. }
  852. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  853. [btn setTitleColor:[UIColor colorWithHexString:@"0xf95569"] forState:UIControlStateNormal];
  854. [btn addTarget:self action:@selector(onDeleteAndQuit:) forControlEvents:UIControlEventTouchUpInside];
  855. if (@available(iOS 14, *)) {
  856. [cell.contentView addSubview:btn];
  857. } else {
  858. [cell addSubview:btn];
  859. }
  860. }
  861. return cell;
  862. } else if([self isTransferGroup:indexPath]) {
  863. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
  864. if (cell == nil) {
  865. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
  866. for (UIView *subView in cell.subviews) {
  867. [subView removeFromSuperview];
  868. }
  869. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
  870. [btn setTitle:WFCString(@"TransferGroup") forState:UIControlStateNormal];
  871. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  872. [btn setTitleColor:[UIColor colorWithHexString:@"0xf95569"] forState:UIControlStateNormal];
  873. [btn addTarget:self action:@selector(onTransferGroup:) forControlEvents:UIControlEventTouchUpInside];
  874. if (@available(iOS 14, *)) {
  875. [cell.contentView addSubview:btn];
  876. } else {
  877. [cell addSubview:btn];
  878. }
  879. }
  880. return cell;
  881. } else if([self isUnsubscribeChannel:indexPath]) {
  882. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
  883. if (cell == nil) {
  884. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
  885. for (UIView *subView in cell.subviews) {
  886. [subView removeFromSuperview];
  887. }
  888. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 4, self.view.frame.size.width - 40, 40)];
  889. if ([self isChannelOwner]) {
  890. [btn setTitle:WFCString(@"DestroyChannel") forState:UIControlStateNormal];
  891. } else {
  892. [btn setTitle:WFCString(@"UnscribeChannel") forState:UIControlStateNormal];
  893. }
  894. btn.layer.cornerRadius = 5.f;
  895. btn.layer.masksToBounds = YES;
  896. btn.backgroundColor = [UIColor redColor];
  897. [btn addTarget:self action:@selector(onDeleteAndQuit:) forControlEvents:UIControlEventTouchUpInside];
  898. if (@available(iOS 14, *)) {
  899. [cell.contentView addSubview:btn];
  900. } else {
  901. [cell addSubview:btn];
  902. }
  903. }
  904. return cell;
  905. } else if([self isFilesCell:indexPath]) {
  906. return [self cellOfTable:tableView WithTitle:WFCString(@"ConvFiles") withDetailTitle:nil withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  907. } else if([self isDestroySecretChatCell:indexPath]) {
  908. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"destroySecretChatCell"];
  909. if (cell == nil) {
  910. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"destroySecretChatCell"];
  911. for (UIView *subView in cell.subviews) {
  912. [subView removeFromSuperview];
  913. }
  914. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
  915. [btn setTitle:WFCString(@"DestroySecretChat") forState:UIControlStateNormal];
  916. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  917. [btn setTitleColor:[UIColor colorWithHexString:@"0xf95569"] forState:UIControlStateNormal];
  918. [btn addTarget:self action:@selector(onDestroySecretChat:) forControlEvents:UIControlEventTouchUpInside];
  919. if (@available(iOS 14, *)) {
  920. [cell.contentView addSubview:btn];
  921. } else {
  922. [cell addSubview:btn];
  923. }
  924. }
  925. return cell;
  926. } else if([self isBurnTimeCell:indexPath]) {
  927. NSString *subTitle = WFCString(@"Close");
  928. WFCCSecretChatInfo *info = [[WFCCIMService sharedWFCIMService] getSecretChatInfo:self.conversation.target];
  929. if(info.burnTime) {
  930. subTitle = [NSString stringWithFormat:@"%d秒", info.burnTime/1000];
  931. }
  932. return [self cellOfTable:tableView WithTitle:@"设置密聊焚毁时间" withDetailTitle:subTitle withDisclosureIndicator:NO withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  933. }
  934. return nil;
  935. }
  936. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  937. if (self.conversation.type == Single_Type) {
  938. return 3;
  939. } else if(self.conversation.type == Group_Type) {
  940. return 5;
  941. } else if(self.conversation.type == Channel_Type) {
  942. return 4;
  943. } else if (self.conversation.type == SecretChat_Type) {
  944. return 4;
  945. }
  946. return 0;
  947. }
  948. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  949. __weak typeof(self)weakSelf = self;
  950. if ([self isGroupNameCell:indexPath]) {
  951. if (self.groupInfo.type == GroupType_Restricted && ![self isGroupManager]) {
  952. [self.view makeToast:WFCString(@"OnlyManangerCanChangeGroupNameHint") duration:1 position:CSToastPositionCenter];
  953. return;
  954. }
  955. WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
  956. gmvc.defaultValue = self.groupInfo.name;
  957. gmvc.titleText = WFCString(@"ModifyGroupName");
  958. gmvc.canEmpty = NO;
  959. gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
  960. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_Name newValue:newValue notifyLines:@[@(0)] notifyContent:nil success:^{
  961. result(YES);
  962. weakSelf.groupInfo.name = newValue;
  963. [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  964. } error:^(int error_code) {
  965. result(NO);
  966. }];
  967. };
  968. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
  969. [self.navigationController presentViewController:nav animated:YES completion:nil];
  970. } else if ([self isGroupManageCell:indexPath]) {
  971. GroupManageTableViewController *gmvc = [[GroupManageTableViewController alloc] init];
  972. gmvc.groupInfo = self.groupInfo;
  973. [self.navigationController pushViewController:gmvc animated:YES];
  974. } else if ([self isSearchMessageCell:indexPath]) {
  975. WFCUConversationSearchTableViewController *mvc = [[WFCUConversationSearchTableViewController alloc] init];
  976. mvc.conversation = self.conversation;
  977. mvc.hidesBottomBarWhenPushed = YES;
  978. [self.navigationController pushViewController:mvc animated:YES];
  979. } else if ([self isMessageSilentCell:indexPath]) {
  980. } else if ([self isSetTopCell:indexPath]) {
  981. } else if ([self isSaveGroupCell:indexPath]) {
  982. } else if ([self isGroupNameCardCell:indexPath]) {
  983. WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
  984. WFCCGroupMember *groupMember = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
  985. gmvc.defaultValue = groupMember.alias;
  986. gmvc.titleText = WFCString(@"ModifyMyGroupNameCard");
  987. gmvc.canEmpty = NO;
  988. gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
  989. [[WFCCIMService sharedWFCIMService] modifyGroupAlias:self.conversation.target alias:newValue notifyLines:@[@(0)] notifyContent:nil success:^{
  990. result(YES);
  991. [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  992. } error:^(int error_code) {
  993. result(NO);
  994. }];
  995. };
  996. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
  997. [self.navigationController presentViewController:nav animated:YES completion:nil];
  998. } else if([self isShowNameCardCell:indexPath]) {
  999. } else if([self isGroupQrCodeCell:indexPath]) {
  1000. if (gQrCodeDelegate) {
  1001. [gQrCodeDelegate showQrCodeViewController:self.navigationController type:QRType_Group target:self.groupInfo.target];
  1002. }
  1003. } else if([self isGroupAnnouncementCell:indexPath]) {
  1004. WFCUGroupAnnouncementViewController *vc = [[WFCUGroupAnnouncementViewController alloc] init];
  1005. vc.announcement = self.groupAnnouncement;
  1006. vc.isManager = [self isGroupManager];
  1007. [self.navigationController pushViewController:vc animated:YES];
  1008. } else if([self isFilesCell:indexPath]) {
  1009. WFCUFilesViewController *vc = [[WFCUFilesViewController alloc] init];
  1010. vc.conversation = self.conversation;
  1011. [self.navigationController pushViewController:vc animated:YES];
  1012. } else if([self isBurnTimeCell:indexPath]) {
  1013. [self onBurnTimeAction];
  1014. } else if([self isGroupRemarkCell:indexPath]) {
  1015. WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
  1016. gmvc.defaultValue = self.groupInfo.remark;
  1017. gmvc.titleText = WFCString(@"ModifyGroupRemark");
  1018. gmvc.canEmpty = YES;
  1019. gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
  1020. [[WFCCIMService sharedWFCIMService] setGroup:self.conversation.target remark:newValue success:^{
  1021. result(YES);
  1022. weakSelf.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:weakSelf.conversation.target refresh:NO];
  1023. [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  1024. } error:^(int error_code) {
  1025. result(NO);
  1026. }];
  1027. };
  1028. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
  1029. [self.navigationController presentViewController:nav animated:YES completion:nil];
  1030. }
  1031. }
  1032. #pragma mark - UICollectionViewDataSource
  1033. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  1034. if (self.conversation.type == Group_Type || self.conversation.type == Single_Type) {
  1035. return self.memberCollectionCount;
  1036. } else if(self.conversation.type == Channel_Type) {
  1037. return self.memberList.count;
  1038. }
  1039. return 0;
  1040. }
  1041. // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
  1042. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  1043. WFCUConversationSettingMemberCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:Group_Member_Cell_Reuese_ID forIndexPath:indexPath];
  1044. if (indexPath.row < self.memberCollectionCount-self.extraBtnNumber) {
  1045. WFCCGroupMember *member = self.memberList[indexPath.row];
  1046. [cell setModel:member withType:self.conversation.type];
  1047. } else {
  1048. if (indexPath.row == self.memberCollectionCount-self.extraBtnNumber) {
  1049. [cell.headerImageView setImage:[WFCUImage imageNamed:@"addmember"]];
  1050. cell.nameLabel.text = nil;
  1051. cell.nameLabel.hidden = YES;
  1052. } else {
  1053. [cell.headerImageView setImage:[WFCUImage imageNamed:@"removemember"]];
  1054. cell.nameLabel.text = nil;
  1055. cell.nameLabel.hidden = YES;
  1056. }
  1057. cell.headerImageView.layer.cornerRadius = 0;
  1058. }
  1059. return cell;
  1060. }
  1061. #pragma mark - UICollectionViewDelegate
  1062. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  1063. __weak typeof(self)ws = self;
  1064. if (indexPath.row == self.memberCollectionCount-self.extraBtnNumber) {
  1065. WFCUSeletedUserViewController *pvc = [[WFCUSeletedUserViewController alloc] init];
  1066. NSMutableArray *disabledUser = [[NSMutableArray alloc] init];
  1067. if(self.conversation.type == Group_Type) {
  1068. for (WFCCGroupMember *member in [[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupInfo.target forceUpdate:NO]) {
  1069. [disabledUser addObject:member.memberId];
  1070. }
  1071. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  1072. NSString *memberExtra = [WFCCUtilities getGroupMemberExtra:GroupMemberSource_Invite sourceTargetId:[WFCCNetworkService sharedInstance].userId];
  1073. [[WFCCIMService sharedWFCIMService] addMembers:contacts toGroup:ws.conversation.target memberExtra:memberExtra notifyLines:@[@(0)] notifyContent:nil success:^{
  1074. [[WFCCIMService sharedWFCIMService] getGroupMembers:ws.conversation.target forceUpdate:YES];
  1075. } error:^(int error_code) {
  1076. if (error_code == ERROR_CODE_GROUP_EXCEED_MAX_MEMBER_COUNT) {
  1077. [ws.view makeToast:WFCString(@"ExceedGroupMaxMemberCount") duration:1 position:CSToastPositionCenter];
  1078. } else {
  1079. [ws.view makeToast:WFCString(@"NetworkError") duration:1 position:CSToastPositionCenter];
  1080. }
  1081. }];
  1082. };
  1083. } else {
  1084. [disabledUser addObject:self.conversation.target];
  1085. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  1086. [self createGroup:contacts];
  1087. };
  1088. }
  1089. pvc.disableUserIds = disabledUser;
  1090. pvc.disabledUserNotSelected = YES;
  1091. pvc.type = Horizontal;
  1092. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:pvc];
  1093. navi.modalPresentationStyle = UIModalPresentationFullScreen;
  1094. [self.navigationController presentViewController:navi animated:YES completion:nil];
  1095. } else if(indexPath.row == self.memberCollectionCount-self.extraBtnNumber + 1) {
  1096. WFCUContactListViewController *pvc = [[WFCUContactListViewController alloc] init];
  1097. pvc.selectContact = YES;
  1098. pvc.multiSelect = YES;
  1099. __weak typeof(self)ws = self;
  1100. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  1101. [[WFCCIMService sharedWFCIMService] kickoffMembers:contacts fromGroup:self.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
  1102. [[WFCCIMService sharedWFCIMService] getGroupMembers:ws.conversation.target forceUpdate:YES];
  1103. dispatch_async(dispatch_get_main_queue(), ^{
  1104. NSMutableArray *tmpArray = [ws.memberList mutableCopy];
  1105. NSMutableArray *removeArray = [[NSMutableArray alloc] init];
  1106. [tmpArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  1107. WFCCGroupMember *member = obj;
  1108. if([contacts containsObject:member.memberId]) {
  1109. [removeArray addObject:member];
  1110. }
  1111. }];
  1112. [tmpArray removeObjectsInArray:removeArray];
  1113. ws.memberList = [tmpArray mutableCopy];
  1114. [ws setupMemberCollectionView];
  1115. [ws.memberCollectionView reloadData];
  1116. });
  1117. } error:^(int error_code) {
  1118. }];
  1119. };
  1120. NSMutableArray *candidateUsers = [[NSMutableArray alloc] init];
  1121. NSMutableArray *disableUsers = [[NSMutableArray alloc] init];
  1122. BOOL isOwner = [self isGroupOwner];
  1123. for (WFCCGroupMember *member in [[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupInfo.target forceUpdate:NO]) {
  1124. [candidateUsers addObject:member.memberId];
  1125. if (!isOwner && (member.type == Member_Type_Manager || [self.groupInfo.owner isEqualToString:member.memberId])) {
  1126. [disableUsers addObject:member.memberId];
  1127. }
  1128. }
  1129. [disableUsers addObject:[WFCCNetworkService sharedInstance].userId];
  1130. pvc.candidateUsers = candidateUsers;
  1131. pvc.disableUsers = [disableUsers copy];
  1132. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:pvc];
  1133. [self.navigationController presentViewController:navi animated:YES completion:nil];
  1134. } else {
  1135. NSString *userId;
  1136. if(self.conversation.type == Group_Type) {
  1137. WFCCGroupMember *member = [self.memberList objectAtIndex:indexPath.row];
  1138. userId = member.memberId;
  1139. if (self.groupInfo.privateChat) {
  1140. if (![self.groupInfo.owner isEqualToString:userId] && ![self.groupInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  1141. WFCCGroupMember *gm = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
  1142. if (gm.type != Member_Type_Manager) {
  1143. WFCCGroupMember *gm = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:userId];
  1144. if (gm.type != Member_Type_Manager) {
  1145. [self.view makeToast:WFCString(@"NotAllowTemporarySession") duration:1 position:CSToastPositionCenter];
  1146. return;
  1147. }
  1148. }
  1149. }
  1150. }
  1151. } else {
  1152. userId = self.conversation.target;
  1153. }
  1154. // if ([[WFCCNetworkService sharedInstance].userId isEqualToString:userId]) {
  1155. // WFCUMyProfileTableViewController *vc = [[WFCUMyProfileTableViewController alloc] init];
  1156. // vc.hidesBottomBarWhenPushed = YES;
  1157. // [self.navigationController pushViewController:vc animated:YES];
  1158. // } else {
  1159. WFCUProfileTableViewController *vc = [[WFCUProfileTableViewController alloc] init];
  1160. vc.userId = userId;
  1161. vc.fromConversation = self.conversation;
  1162. vc.hidesBottomBarWhenPushed = YES;
  1163. [self.navigationController pushViewController:vc animated:YES];
  1164. // }
  1165. }
  1166. }
  1167. - (void)createGroup:(NSArray<NSString *> *)contacts {
  1168. __weak typeof(self) ws = self;
  1169. NSMutableArray<NSString *> *memberIds = [contacts mutableCopy];
  1170. if(![memberIds containsObject:self.conversation.target]) {
  1171. [memberIds insertObject:self.conversation.target atIndex:0];
  1172. }
  1173. if (![memberIds containsObject:[WFCCNetworkService sharedInstance].userId]) {
  1174. [memberIds insertObject:[WFCCNetworkService sharedInstance].userId atIndex:0];
  1175. }
  1176. NSString *name;
  1177. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[memberIds objectAtIndex:0] refresh:NO];
  1178. name = userInfo.displayName;
  1179. for (int i = 1; i < MIN(8, memberIds.count); i++) {
  1180. userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[memberIds objectAtIndex:i] refresh:NO];
  1181. if (userInfo.displayName.length > 0) {
  1182. if (name.length + userInfo.displayName.length + 1 > 16) {
  1183. name = [name stringByAppendingString:WFCString(@"Etc")];
  1184. break;
  1185. }
  1186. name = [name stringByAppendingFormat:@",%@", userInfo.displayName];
  1187. }
  1188. }
  1189. if (name.length == 0) {
  1190. name = WFCString(@"GroupChat");
  1191. }
  1192. NSString *extraStr = [WFCCUtilities getGroupMemberExtra:GroupMemberSource_Invite sourceTargetId:[WFCCNetworkService sharedInstance].userId];
  1193. [[WFCCIMService sharedWFCIMService] createGroup:nil name:name portrait:nil type:GroupType_Restricted groupExtra:nil members:memberIds memberExtra:extraStr notifyLines:@[@(0)] notifyContent:nil success:^(NSString *groupId) {
  1194. NSLog(@"create group success");
  1195. WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
  1196. mvc.conversation = [[WFCCConversation alloc] init];
  1197. mvc.conversation.type = Group_Type;
  1198. mvc.conversation.target = groupId;
  1199. mvc.conversation.line = 0;
  1200. mvc.hidesBottomBarWhenPushed = YES;
  1201. UINavigationController *nav = self.navigationController;
  1202. [self.navigationController popToRootViewControllerAnimated:NO];
  1203. [nav pushViewController:mvc animated:YES];
  1204. } error:^(int error_code) {
  1205. NSLog(@"create group failure");
  1206. [ws.view makeToast:WFCString(@"CreateGroupFailure")
  1207. duration:2
  1208. position:CSToastPositionCenter];
  1209. }];
  1210. }
  1211. - (void)dealloc {
  1212. [[NSNotificationCenter defaultCenter] removeObserver:self];
  1213. }
  1214. @end