2
0

WFCUConversationSettingViewController.m 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  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.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 "WFCUCreateGroupViewController.h"
  18. #import "WFCUProfileTableViewController.h"
  19. #import "WFCUCreateGroupViewController.h"
  20. #import "GroupManageTableViewController.h"
  21. #import "WFCUGroupMemberCollectionViewController.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. @interface WFCUConversationSettingViewController () <UITableViewDataSource, UITableViewDelegate, UICollectionViewDelegate, UICollectionViewDataSource>
  34. @property (nonatomic, strong)UICollectionView *memberCollectionView;
  35. @property (nonatomic, strong)WFCUConversationSettingMemberCollectionViewLayout *memberCollectionViewLayout;
  36. @property (nonatomic, strong)UITableView *tableView;
  37. @property (nonatomic, strong)WFCCGroupInfo *groupInfo;
  38. @property (nonatomic, strong)WFCCUserInfo *userInfo;
  39. @property (nonatomic, strong)WFCCChannelInfo *channelInfo;
  40. @property (nonatomic, strong)NSArray<WFCCGroupMember *> *memberList;
  41. @property (nonatomic, strong)UIImageView *channelPortrait;
  42. @property (nonatomic, strong)UILabel *channelName;
  43. @property (nonatomic, strong)UILabel *channelDesc;
  44. @property (nonatomic, strong)WFCUGroupAnnouncement *groupAnnouncement;
  45. @property (nonatomic, assign)BOOL showMoreMember;
  46. @property (nonatomic, assign)int extraBtnNumber;
  47. @property (nonatomic, assign)int memberCollectionCount;
  48. @end
  49. #define Group_Member_Cell_Reuese_ID @"Group_Member_Cell_Reuese_ID"
  50. #define Group_Member_Visible_Lines 9
  51. @implementation WFCUConversationSettingViewController
  52. - (void)viewDidLoad {
  53. [super viewDidLoad];
  54. self.title = @"会话详情";
  55. if (self.conversation.type == Single_Type) {
  56. self.userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.conversation.target refresh:YES];
  57. self.memberList = @[self.conversation.target];
  58. } else if(self.conversation.type == Group_Type){
  59. self.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:self.conversation.target refresh:YES];
  60. self.memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.conversation.target forceUpdate:YES];
  61. } else if(self.conversation.type == Channel_Type) {
  62. self.channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:self.conversation.target refresh:YES];
  63. self.memberList = @[self.conversation.target];
  64. }
  65. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
  66. self.tableView.delegate = self;
  67. self.tableView.dataSource = self;
  68. UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 146)];
  69. footerView.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  70. self.tableView.tableFooterView = footerView;
  71. if (self.conversation.type != Group_Type) {
  72. footerView.frame = CGRectMake(0, 0, 0, 0);
  73. }
  74. [self.view addSubview:self.tableView];
  75. if(self.conversation.type == Group_Type) {
  76. __weak typeof(self)ws = self;
  77. [[NSNotificationCenter defaultCenter] addObserverForName:kGroupMemberUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
  78. if ([ws.conversation.target isEqualToString:note.object]) {
  79. ws.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:ws.conversation.target refresh:NO];
  80. ws.memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:ws.conversation.target forceUpdate:NO];
  81. [ws setupMemberCollectionView];
  82. [ws.memberCollectionView reloadData];
  83. }
  84. }];
  85. [[WFCUConfigManager globalManager].appServiceProvider getGroupAnnouncement:self.groupInfo.target success:^(WFCUGroupAnnouncement *announcement) {
  86. dispatch_async(dispatch_get_main_queue(), ^{
  87. self.groupAnnouncement = announcement;
  88. if ([self isGroupManager] && self.groupInfo.type == GroupType_Restricted) {
  89. [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:4 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
  90. } else {
  91. [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:3 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
  92. }
  93. });
  94. } error:^(int error_code) {
  95. }];
  96. }
  97. if(self.conversation.type == Channel_Type) {
  98. CGFloat portraitWidth = 80;
  99. CGFloat top = 40;
  100. CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
  101. self.channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:self.conversation.target refresh:YES];
  102. self.channelPortrait = [[UIImageView alloc] initWithFrame:CGRectMake((screenWidth - portraitWidth)/2, top, portraitWidth, portraitWidth)];
  103. [self.channelPortrait sd_setImageWithURL:[NSURL URLWithString:[self.channelInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[UIImage imageNamed:@"channel_default_portrait"]];
  104. self.channelPortrait.userInteractionEnabled = YES;
  105. [self.channelPortrait addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapChannelPortrait:)]];
  106. top += portraitWidth;
  107. top += 20;
  108. self.channelName = [[UILabel alloc] initWithFrame:CGRectMake(40, top, screenWidth - 40 - 40, 18)];
  109. self.channelName.font = [UIFont systemFontOfSize:18];
  110. self.channelName.textAlignment = NSTextAlignmentCenter;
  111. self.channelName.text = self.channelInfo.name;
  112. top += 18;
  113. top += 20;
  114. if (self.channelInfo.desc) {
  115. NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:self.channelInfo.desc];
  116. UIFont *font = [UIFont systemFontOfSize:14];
  117. [attributeString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, self.channelInfo.desc.length)];
  118. NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
  119. CGRect rect = [attributeString boundingRectWithSize:CGSizeMake(screenWidth - 80, CGFLOAT_MAX) options:options context:nil];
  120. self.channelDesc = [[UILabel alloc] initWithFrame:CGRectMake(40, top, screenWidth - 80, rect.size.height)];
  121. self.channelDesc.font = [UIFont systemFontOfSize:14];
  122. self.channelDesc.textAlignment = NSTextAlignmentCenter;
  123. self.channelDesc.text = self.channelInfo.desc;
  124. self.channelDesc.numberOfLines = 0;
  125. [self.channelDesc sizeToFit];
  126. top += rect.size.height;
  127. top += 20;
  128. }
  129. UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, top)];
  130. [container addSubview:self.channelPortrait];
  131. [container addSubview:self.channelName];
  132. [container addSubview:self.channelDesc];
  133. self.tableView.tableHeaderView = container;
  134. }
  135. }
  136. - (void)setupMemberCollectionView {
  137. if (self.conversation.type == Single_Type || self.conversation.type == Group_Type) {
  138. self.memberCollectionViewLayout = [[WFCUConversationSettingMemberCollectionViewLayout alloc] initWithItemMargin:8];
  139. if (self.conversation.type == Single_Type) {
  140. self.extraBtnNumber = 1;
  141. self.memberCollectionCount = 2;
  142. } else if(self.conversation.type == Group_Type) {
  143. if ([self isGroupManager]) {
  144. self.extraBtnNumber = 2;
  145. self.memberCollectionCount = (int)self.memberList.count + self.extraBtnNumber;
  146. } else if(self.groupInfo.type == GroupType_Restricted) {
  147. if (self.groupInfo.joinType == 1 || self.groupInfo.joinType == 0) {
  148. self.extraBtnNumber = 1;
  149. self.memberCollectionCount = (int)self.memberList.count + self.extraBtnNumber;
  150. } else {
  151. self.memberCollectionCount = (int)self.memberList.count;
  152. }
  153. } else {
  154. self.extraBtnNumber = 1;
  155. self.memberCollectionCount = (int)self.memberList.count + self.extraBtnNumber;
  156. }
  157. if (self.memberCollectionCount > Group_Member_Visible_Lines * 5) {
  158. self.memberCollectionCount = Group_Member_Visible_Lines * 5;
  159. self.showMoreMember = YES;
  160. }
  161. } else if(self.conversation.type == Channel_Type) {
  162. self.memberCollectionCount = 1;
  163. }
  164. self.memberCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, [self.memberCollectionViewLayout getHeigthOfItemCount:self.memberCollectionCount]) collectionViewLayout:self.memberCollectionViewLayout];
  165. self.memberCollectionView.delegate = self;
  166. self.memberCollectionView.dataSource = self;
  167. self.memberCollectionView.backgroundColor = [UIColor whiteColor];
  168. [self.memberCollectionView registerClass:[WFCUConversationSettingMemberCell class] forCellWithReuseIdentifier:Group_Member_Cell_Reuese_ID];
  169. if (self.showMoreMember) {
  170. UIView *head = [[UIView alloc] init];
  171. CGRect frame = self.memberCollectionView.frame;
  172. frame.size.height += 36;
  173. head.frame = frame;
  174. [head addSubview:self.memberCollectionView];
  175. UIButton *moreBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, frame.size.height - 40, frame.size.width, 36)];
  176. [moreBtn setTitle:WFCString(@"ShowAllMembers") forState:UIControlStateNormal];
  177. moreBtn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:17];
  178. [moreBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  179. moreBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
  180. [moreBtn addTarget:self action:@selector(onViewAllMember:) forControlEvents:UIControlEventTouchDown];
  181. [head addSubview:moreBtn];
  182. head.backgroundColor = [UIColor whiteColor];
  183. self.tableView.tableHeaderView = head;
  184. } else {
  185. self.tableView.tableHeaderView = self.memberCollectionView;
  186. }
  187. }
  188. }
  189. - (void)onViewAllMember:(id)sender {
  190. WFCUGroupMemberCollectionViewController *vc = [[WFCUGroupMemberCollectionViewController alloc] init];
  191. vc.groupId = self.groupInfo.target;
  192. [self.navigationController pushViewController:vc animated:YES];
  193. }
  194. - (void)onTapChannelPortrait:(id)sender {
  195. WFCUChannelProfileViewController *pvc = [[WFCUChannelProfileViewController alloc] init];
  196. pvc.channelInfo = self.channelInfo;
  197. [self.navigationController pushViewController:pvc animated:YES];
  198. }
  199. - (void)didReceiveMemoryWarning {
  200. [super didReceiveMemoryWarning];
  201. }
  202. - (BOOL)isChannelOwner {
  203. if (self.conversation.type != Channel_Type) {
  204. return false;
  205. }
  206. return [self.channelInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId];
  207. }
  208. - (BOOL)isGroupOwner {
  209. if (self.conversation.type != Group_Type) {
  210. return false;
  211. }
  212. return [self.groupInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId];
  213. }
  214. - (BOOL)isGroupManager {
  215. if (self.conversation.type != Group_Type) {
  216. return false;
  217. }
  218. if ([self isGroupOwner]) {
  219. return YES;
  220. }
  221. __block BOOL isManager = false;
  222. [self.memberList enumerateObjectsUsingBlock:^(WFCCGroupMember * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  223. if ([obj.memberId isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  224. if (obj.type != Member_Type_Normal) {
  225. isManager = YES;
  226. }
  227. *stop = YES;
  228. }
  229. }];
  230. return isManager;
  231. }
  232. - (void)onDeleteAndQuit:(id)sender {
  233. if(self.conversation.type == Group_Type) {
  234. if ([self isGroupOwner]) {
  235. __weak typeof(self) ws = self;
  236. [[WFCCIMService sharedWFCIMService] removeConversation:self.conversation clearMessage:YES];
  237. [[WFCCIMService sharedWFCIMService] dismissGroup:self.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
  238. dispatch_async(dispatch_get_main_queue(), ^{
  239. [ws.navigationController popToRootViewControllerAnimated:YES];
  240. });
  241. } error:^(int error_code) {
  242. }];
  243. } else {
  244. __weak typeof(self) ws = self;
  245. [[WFCCIMService sharedWFCIMService] quitGroup:self.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
  246. dispatch_async(dispatch_get_main_queue(), ^{
  247. [ws.navigationController popToRootViewControllerAnimated:YES];
  248. });
  249. } error:^(int error_code) {
  250. }];
  251. }
  252. } else {
  253. if ([self isChannelOwner]) {
  254. __weak typeof(self) ws = self;
  255. [[WFCCIMService sharedWFCIMService] destoryChannel:self.conversation.target success:^{
  256. [[WFCCIMService sharedWFCIMService] removeConversation:ws.conversation clearMessage:YES];
  257. dispatch_async(dispatch_get_main_queue(), ^{
  258. [ws.navigationController popToRootViewControllerAnimated:YES];
  259. });
  260. } error:^(int error_code) {
  261. }];
  262. } else {
  263. __weak typeof(self) ws = self;
  264. [[WFCCIMService sharedWFCIMService] listenChannel:self.conversation.target listen:NO success:^{
  265. [[WFCCIMService sharedWFCIMService] removeConversation:ws.conversation clearMessage:YES];
  266. dispatch_async(dispatch_get_main_queue(), ^{
  267. [ws.navigationController popToRootViewControllerAnimated:YES];
  268. });
  269. } error:^(int error_code) {
  270. }];
  271. }
  272. }
  273. }
  274. - (void)clearMessageAction {
  275. __weak typeof(self)weakSelf = self;
  276. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:WFCString(@"ConfirmDelete") message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  277. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  278. }];
  279. UIAlertAction *actionDelete = [UIAlertAction actionWithTitle:WFCString(@"Delete") style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  280. [[WFCCIMService sharedWFCIMService] clearMessages:self.conversation];
  281. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:weakSelf.view animated:NO];
  282. hud.label.text = WFCString(@"Deleted");
  283. hud.mode = MBProgressHUDModeText;
  284. hud.removeFromSuperViewOnHide = YES;
  285. [hud hideAnimated:NO afterDelay:1.5];
  286. [[NSNotificationCenter defaultCenter] postNotificationName:kMessageListChanged object:weakSelf.conversation];
  287. }];
  288. //把action添加到actionSheet里
  289. [actionSheet addAction:actionDelete];
  290. [actionSheet addAction:actionCancel];
  291. //相当于之前的[actionSheet show];
  292. dispatch_async(dispatch_get_main_queue(), ^{
  293. [self presentViewController:actionSheet animated:YES completion:nil];
  294. });
  295. }
  296. - (void)viewWillAppear:(BOOL)animated {
  297. [super viewWillAppear:animated];
  298. if (self.conversation.type == Single_Type) {
  299. self.userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.conversation.target refresh:NO];
  300. self.memberList = @[self.conversation.target];
  301. } else if(self.conversation.type == Group_Type) {
  302. self.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:self.conversation.target refresh:NO];
  303. self.memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.conversation.target forceUpdate:NO];
  304. } else if(self.conversation.type == Channel_Type) {
  305. self.channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:self.conversation.target refresh:NO];
  306. self.memberList = @[self.conversation.target];
  307. }
  308. [self setupMemberCollectionView];
  309. [self.memberCollectionView reloadData];
  310. [self.tableView reloadData];
  311. }
  312. #pragma mark - UITableViewDataSource<NSObject>
  313. - (BOOL)isGroupNameCell:(NSIndexPath *)indexPath {
  314. if(self.conversation.type == Group_Type && indexPath.section == 0 && indexPath.row == 0) {
  315. return YES;
  316. }
  317. return NO;
  318. }
  319. - (BOOL)isGroupPortraitCell:(NSIndexPath *)indexPath {
  320. if(self.conversation.type == Group_Type && indexPath.section == 0 && indexPath.row == 1) {
  321. return YES;
  322. }
  323. return NO;
  324. }
  325. - (BOOL)isGroupQrCodeCell:(NSIndexPath *)indexPath {
  326. if(self.conversation.type == Group_Type && indexPath.section == 0 && indexPath.row == 2) {
  327. return YES;
  328. }
  329. return NO;
  330. }
  331. - (BOOL)isGroupManageCell:(NSIndexPath *)indexPath {
  332. if(self.conversation.type == Group_Type && indexPath.section == 0 && indexPath.row == 3) {
  333. if ([self isGroupManager] && self.groupInfo.type == GroupType_Restricted) {
  334. return YES;
  335. } else {
  336. return NO;
  337. }
  338. }
  339. return NO;
  340. }
  341. - (BOOL)isGroupAnnouncementCell:(NSIndexPath *)indexPath {
  342. if(self.conversation.type == Group_Type && indexPath.section == 0) {
  343. if ([self isGroupManager] && self.groupInfo.type == GroupType_Restricted) {
  344. if (indexPath.row == 4) {
  345. return YES;
  346. }
  347. } else {
  348. if (indexPath.row == 3) {
  349. return YES;
  350. }
  351. }
  352. }
  353. return NO;
  354. }
  355. - (BOOL)isSearchMessageCell:(NSIndexPath *)indexPath {
  356. if((self.conversation.type == Group_Type && indexPath.section == 1 && indexPath.row == 0)
  357. ||(self.conversation.type == Single_Type && indexPath.section == 0 && indexPath.row == 0)
  358. ||(self.conversation.type == Channel_Type && indexPath.section == 0 && indexPath.row == 0)) {
  359. return YES;
  360. }
  361. return NO;
  362. }
  363. - (BOOL)isMessageSilentCell:(NSIndexPath *)indexPath {
  364. if((self.conversation.type == Group_Type && indexPath.section == 2 && indexPath.row == 0)
  365. ||(self.conversation.type == Single_Type && indexPath.section == 1 && indexPath.row == 0)
  366. ||(self.conversation.type == Channel_Type && indexPath.section == 1 && indexPath.row == 0)) {
  367. return YES;
  368. }
  369. return NO;
  370. }
  371. - (BOOL)isSetTopCell:(NSIndexPath *)indexPath {
  372. if((self.conversation.type == Group_Type && indexPath.section == 2 && indexPath.row == 1)
  373. ||(self.conversation.type == Single_Type && indexPath.section == 1 && indexPath.row == 1)
  374. ||(self.conversation.type == Channel_Type && indexPath.section == 1 && indexPath.row == 1)) {
  375. return YES;
  376. }
  377. return NO;
  378. }
  379. - (BOOL)isSaveGroupCell:(NSIndexPath *)indexPath {
  380. if((self.conversation.type == Group_Type && indexPath.section == 2 && indexPath.row == 2)) {
  381. return YES;
  382. }
  383. return NO;
  384. }
  385. - (BOOL)isGroupNameCardCell:(NSIndexPath *)indexPath {
  386. if((self.conversation.type == Group_Type && indexPath.section == 3 && indexPath.row == 0)) {
  387. return YES;
  388. }
  389. return NO;
  390. }
  391. - (BOOL)isShowNameCardCell:(NSIndexPath *)indexPath {
  392. if((self.conversation.type == Group_Type && indexPath.section == 3 && indexPath.row == 1)) {
  393. return YES;
  394. }
  395. return NO;
  396. }
  397. - (BOOL)isClearMessageCell:(NSIndexPath *)indexPath {
  398. if((self.conversation.type == Group_Type && indexPath.section == 4 && indexPath.row == 0)
  399. || (self.conversation.type == Single_Type && indexPath.section == 2 && indexPath.row == 0)
  400. || (self.conversation.type == Channel_Type && indexPath.section == 2 && indexPath.row == 0)) {
  401. return YES;
  402. }
  403. return NO;
  404. }
  405. - (BOOL)isQuitGroup:(NSIndexPath *)indexPath {
  406. if(self.conversation.type == Group_Type && indexPath.section == 4 && indexPath.row == 1) {
  407. return YES;
  408. }
  409. return NO;
  410. }
  411. - (BOOL)isUnsubscribeChannel:(NSIndexPath *)indexPath {
  412. if (self.conversation.type == Channel_Type && indexPath.section == 3 && indexPath.row == 0) {
  413. return YES;
  414. }
  415. return NO;
  416. }
  417. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  418. if (self.conversation.type == Group_Type) {
  419. if (section == 0) {
  420. if ([self isGroupManager] && self.groupInfo.type == GroupType_Restricted) {
  421. return 5; //群名称,群头像,群二维码,群管理,群公告
  422. } else {
  423. return 4; //群名称,群头像,群二维码,群公告
  424. }
  425. } else if(section == 1) {
  426. return 1; //查找聊天内容
  427. } else if(section == 2) {
  428. return 3; //消息免打扰,置顶聊天,保存到通讯录
  429. } else if(section == 3) {
  430. return 2; //群昵称,显示群昵称
  431. } else if(section == 4) {
  432. return 2; //清空聊天记录,删除退群
  433. }
  434. } else if(self.conversation.type == Single_Type) {
  435. if(section == 0) {
  436. return 1; //查找聊天内容
  437. } else if(section == 1) {
  438. return 2; //消息免打扰,置顶聊天
  439. } else if(section == 2) {
  440. return 1; //清空聊天记录
  441. }
  442. } else if(self.conversation.type == Channel_Type) {
  443. if(section == 0) {
  444. return 1; //查找聊天内容
  445. } else if(section == 1) {
  446. return 2; //消息免打扰,置顶聊天
  447. } else if(section == 2) {
  448. return 1; //清空聊天记录
  449. } else if(section == 3) {
  450. return 1; //取消订阅/销毁订阅
  451. }
  452. }
  453. return 0;
  454. }
  455. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  456. return 9;
  457. }
  458. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  459. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,9)];
  460. view.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  461. return view;
  462. }
  463. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  464. if ([self isGroupAnnouncementCell:indexPath]) {
  465. float height = [WFCUUtilities getTextDrawingSize:self.groupAnnouncement.text font:[UIFont pingFangSCWithWeight:FontWeightStyleRegular size:12] constrainedSize:CGSizeMake(self.view.bounds.size.width - 48, 1000)].height;
  466. if (height > 12 * 3.2) {
  467. height = 12 * 3.2;
  468. }
  469. return height + 50;
  470. }
  471. return 50;
  472. }
  473. - (UITableViewCell *)cellOfTable:(UITableView *)tableView WithTitle:(NSString *)title withDetailTitle:(NSString *)detailTitle withDisclosureIndicator:(BOOL)withDI withSwitch:(BOOL)withSwitch withSwitchType:(SwitchType)type {
  474. if (withSwitch) {
  475. WFCUSwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"styleSwitch"];
  476. if(cell == nil) {
  477. cell = [[WFCUSwitchTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"styleSwitch" conversation:self.conversation];
  478. }
  479. cell.textLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  480. cell.textLabel.textColor = [UIColor colorWithHexString:@"0x1d1d1d"];
  481. cell.detailTextLabel.text = nil;
  482. cell.accessoryType = UITableViewCellAccessoryNone;
  483. cell.accessoryView = nil;
  484. cell.textLabel.text = title;
  485. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  486. cell.type = type;
  487. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0 );
  488. return cell;
  489. } else {
  490. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"style1Cell"];
  491. if (cell == nil) {
  492. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"style1Cell"];
  493. }
  494. cell.textLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  495. cell.textLabel.textColor = [UIColor colorWithHexString:@"0x1d1d1d"];
  496. cell.textLabel.text = title;
  497. cell.detailTextLabel.text = detailTitle;
  498. cell.detailTextLabel.textColor = [UIColor colorWithHexString:@"0x9b9a9a"];
  499. cell.detailTextLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:15];
  500. cell.accessoryType = withDI ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
  501. cell.accessoryView = nil;
  502. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  503. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0 );
  504. return cell;
  505. }
  506. }
  507. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  508. if ([self isGroupNameCell:indexPath]) {
  509. return [self cellOfTable:tableView WithTitle:WFCString(@"GroupName") withDetailTitle:self.groupInfo.name withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  510. } else if ([self isGroupPortraitCell:indexPath]) {
  511. UITableViewCell *cell = [self cellOfTable:tableView WithTitle:WFCString(@"ChangePortrait") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  512. UIImageView *portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 56, 8, 40, 40)];
  513. [portraitView sd_setImageWithURL:[NSURL URLWithString:[self.groupInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[UIImage imageNamed:@"group_default_portrait"]];
  514. cell.accessoryView = portraitView;
  515. return cell;
  516. } else if([self isGroupQrCodeCell:indexPath]) {
  517. UITableViewCell *cell = [self cellOfTable:tableView WithTitle:WFCString(@"GroupQRCode") withDetailTitle:nil withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  518. CGFloat width = [UIScreen mainScreen].bounds.size.width;
  519. UIImage *qrcode = [UIImage imageNamed:@"qrcode"];
  520. UIImageView *qrview = [[UIImageView alloc] initWithFrame:CGRectMake(width - 60, (50 - 22) / 2.0, 22, 22)];
  521. qrview.image = qrcode;
  522. [cell addSubview:qrview];
  523. return cell;
  524. } else if ([self isGroupManageCell:indexPath]) {
  525. return [self cellOfTable:tableView WithTitle:WFCString(@"GroupManage") withDetailTitle:nil withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  526. } else if([self isGroupAnnouncementCell:indexPath]) {
  527. // return [self cellOfTable:tableView WithTitle:@"群公告" withDetailTitle:nil withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  528. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"announcementCell"];
  529. if (cell == nil) {
  530. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"announcementCell"];
  531. }
  532. cell.textLabel.text = @"群公告";
  533. cell.textLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  534. cell.textLabel.textColor = [UIColor colorWithHexString:@"0x1d1d1d"];
  535. cell.detailTextLabel.text = self.groupAnnouncement.text;
  536. cell.detailTextLabel.numberOfLines = 3;
  537. // cell.detailTextLabel.numberOfLines = 10;
  538. cell.detailTextLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:12];
  539. cell.detailTextLabel.textColor = [UIColor colorWithHexString:@"0x9b9a9a"];
  540. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  541. cell.accessoryView = nil;
  542. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  543. return cell;
  544. } else if ([self isSearchMessageCell:indexPath]) {
  545. return [self cellOfTable:tableView WithTitle:WFCString(@"SearchMessageContent") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  546. } else if ([self isMessageSilentCell:indexPath]) {
  547. return [self cellOfTable:tableView WithTitle:WFCString(@"Silent") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Silent];
  548. } else if ([self isSetTopCell:indexPath]) {
  549. return [self cellOfTable:tableView WithTitle:WFCString(@"PinChat") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Top];
  550. } else if ([self isSaveGroupCell:indexPath]) {
  551. return [self cellOfTable:tableView WithTitle:WFCString(@"SaveToContact") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Save_To_Contact];
  552. } else if ([self isGroupNameCardCell:indexPath]) {
  553. WFCCGroupMember *groupMember = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
  554. if (groupMember.alias.length) {
  555. return [self cellOfTable:tableView WithTitle:WFCString(@"NicknameInGroup") withDetailTitle:groupMember.alias withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  556. } else {
  557. return [self cellOfTable:tableView WithTitle:WFCString(@"NicknameInGroup") withDetailTitle:WFCString(@"Unset") withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  558. }
  559. } else if([self isShowNameCardCell:indexPath]) {
  560. return [self cellOfTable:tableView WithTitle:WFCString(@"ShowMemberNickname") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Show_Alias];
  561. } else if ([self isClearMessageCell:indexPath]) {
  562. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
  563. if (cell == nil) {
  564. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
  565. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  566. for (UIView *subView in cell.subviews) {
  567. [subView removeFromSuperview];
  568. }
  569. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
  570. [btn setTitle:WFCString(@"ClearChatHistory") forState:UIControlStateNormal];
  571. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  572. [btn setTitleColor:[UIColor colorWithHexString:@"0xf95569"] forState:UIControlStateNormal];
  573. [btn addTarget:self action:@selector(clearMessageAction) forControlEvents:UIControlEventTouchUpInside];
  574. [cell addSubview:btn];
  575. }
  576. return cell;
  577. } else if([self isQuitGroup:indexPath]) {
  578. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
  579. if (cell == nil) {
  580. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
  581. for (UIView *subView in cell.subviews) {
  582. [subView removeFromSuperview];
  583. }
  584. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
  585. if ([self isGroupOwner]) {
  586. [btn setTitle:WFCString(@"DismissGroup") forState:UIControlStateNormal];
  587. } else {
  588. [btn setTitle:WFCString(@"QuitGroup") forState:UIControlStateNormal];
  589. }
  590. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  591. [btn setTitleColor:[UIColor colorWithHexString:@"0xf95569"] forState:UIControlStateNormal];
  592. [btn addTarget:self action:@selector(onDeleteAndQuit:) forControlEvents:UIControlEventTouchUpInside];
  593. [cell addSubview:btn];
  594. }
  595. return cell;
  596. } else if([self isUnsubscribeChannel:indexPath]) {
  597. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
  598. if (cell == nil) {
  599. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
  600. for (UIView *subView in cell.subviews) {
  601. [subView removeFromSuperview];
  602. }
  603. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 4, self.view.frame.size.width - 40, 40)];
  604. if ([self isChannelOwner]) {
  605. [btn setTitle:WFCString(@"DestroyChannel") forState:UIControlStateNormal];
  606. } else {
  607. [btn setTitle:WFCString(@"UnscribeChannel") forState:UIControlStateNormal];
  608. }
  609. btn.layer.cornerRadius = 5.f;
  610. btn.layer.masksToBounds = YES;
  611. btn.backgroundColor = [UIColor redColor];
  612. [btn addTarget:self action:@selector(onDeleteAndQuit:) forControlEvents:UIControlEventTouchUpInside];
  613. [cell addSubview:btn];
  614. }
  615. return cell;
  616. }
  617. return nil;
  618. }
  619. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  620. if (self.conversation.type == Single_Type) {
  621. return 3;
  622. } else if(self.conversation.type == Group_Type) {
  623. return 5;
  624. } else if(self.conversation.type == Channel_Type) {
  625. return 4;
  626. }
  627. return 0;
  628. }
  629. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  630. __weak typeof(self)weakSelf = self;
  631. if ([self isGroupNameCell:indexPath]) {
  632. if (self.groupInfo.type == GroupType_Restricted && ![self isGroupManager]) {
  633. [self.view makeToast:WFCString(@"OnlyManangerCanChangeGroupNameHint") duration:1 position:CSToastPositionCenter];
  634. return;
  635. }
  636. WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
  637. gmvc.defaultValue = self.groupInfo.name;
  638. gmvc.titleText = WFCString(@"ModifyGroupName");
  639. gmvc.canEmpty = NO;
  640. gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
  641. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_Name newValue:newValue notifyLines:@[@(0)] notifyContent:nil success:^{
  642. result(YES);
  643. } error:^(int error_code) {
  644. result(NO);
  645. }];
  646. };
  647. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
  648. [self.navigationController presentViewController:nav animated:YES completion:nil];
  649. } else if ([self isGroupPortraitCell:indexPath]) {
  650. if (self.groupInfo.type == GroupType_Restricted && ![self isGroupManager]) {
  651. [self.view makeToast:WFCString(@"OnlyManangerCanChangeGroupPortraitHint") duration:1 position:CSToastPositionCenter];
  652. return;
  653. }
  654. WFCUCreateGroupViewController *vc = [[WFCUCreateGroupViewController alloc] init];
  655. vc.isModifyPortrait = YES;
  656. vc.groupId = self.groupInfo.target;
  657. vc.memberIds = [[NSMutableArray alloc] init];
  658. for (WFCCGroupMember *member in self.memberList) {
  659. [vc.memberIds addObject:member.memberId];
  660. }
  661. [self.navigationController pushViewController:vc animated:YES];
  662. } else if ([self isGroupManageCell:indexPath]) {
  663. GroupManageTableViewController *gmvc = [[GroupManageTableViewController alloc] init];
  664. gmvc.groupInfo = self.groupInfo;
  665. [self.navigationController pushViewController:gmvc animated:YES];
  666. } else if ([self isSearchMessageCell:indexPath]) {
  667. WFCUConversationSearchTableViewController *mvc = [[WFCUConversationSearchTableViewController alloc] init];
  668. mvc.conversation = self.conversation;
  669. mvc.hidesBottomBarWhenPushed = YES;
  670. [self.navigationController pushViewController:mvc animated:YES];
  671. } else if ([self isMessageSilentCell:indexPath]) {
  672. } else if ([self isSetTopCell:indexPath]) {
  673. } else if ([self isSaveGroupCell:indexPath]) {
  674. } else if ([self isGroupNameCardCell:indexPath]) {
  675. WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
  676. WFCCGroupMember *groupMember = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
  677. gmvc.defaultValue = groupMember.alias;
  678. gmvc.titleText = WFCString(@"ModifyMyGroupNameCard");
  679. gmvc.canEmpty = NO;
  680. gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
  681. [[WFCCIMService sharedWFCIMService] modifyGroupAlias:self.conversation.target alias:newValue notifyLines:@[@(0)] notifyContent:nil success:^{
  682. result(YES);
  683. } error:^(int error_code) {
  684. result(NO);
  685. }];
  686. };
  687. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
  688. [self.navigationController presentViewController:nav animated:YES completion:nil];
  689. } else if([self isShowNameCardCell:indexPath]) {
  690. } else if([self isGroupQrCodeCell:indexPath]) {
  691. if (gQrCodeDelegate) {
  692. [gQrCodeDelegate showQrCodeViewController:self.navigationController type:QRType_Group target:self.groupInfo.target];
  693. }
  694. } else if([self isGroupAnnouncementCell:indexPath]) {
  695. WFCUGroupAnnouncementViewController *vc = [[WFCUGroupAnnouncementViewController alloc] init];
  696. vc.announcement = self.groupAnnouncement;
  697. vc.isManager = [self isGroupManager];
  698. [self.navigationController pushViewController:vc animated:YES];
  699. }
  700. }
  701. #pragma mark - UICollectionViewDataSource
  702. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  703. if (self.conversation.type == Group_Type || self.conversation.type == Single_Type) {
  704. return self.memberCollectionCount;
  705. } else if(self.conversation.type == Channel_Type) {
  706. return self.memberList.count;
  707. }
  708. return 0;
  709. }
  710. // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
  711. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  712. WFCUConversationSettingMemberCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:Group_Member_Cell_Reuese_ID forIndexPath:indexPath];
  713. if (indexPath.row < self.memberCollectionCount-self.extraBtnNumber) {
  714. WFCCGroupMember *member = self.memberList[indexPath.row];
  715. [cell setModel:member withType:self.conversation.type];
  716. } else {
  717. if (indexPath.row == self.memberCollectionCount-self.extraBtnNumber) {
  718. [cell.headerImageView setImage:[UIImage imageNamed:@"addmember"]];
  719. cell.nameLabel.text = nil;
  720. cell.nameLabel.hidden = YES;
  721. } else {
  722. [cell.headerImageView setImage:[UIImage imageNamed:@"removemember"]];
  723. cell.nameLabel.text = nil;
  724. cell.nameLabel.hidden = YES;
  725. }
  726. cell.headerImageView.layer.cornerRadius = 0;
  727. }
  728. return cell;
  729. }
  730. #pragma mark - UICollectionViewDelegate
  731. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  732. __weak typeof(self)ws = self;
  733. if (indexPath.row == self.memberCollectionCount-self.extraBtnNumber) {
  734. WFCUContactListViewController *pvc = [[WFCUContactListViewController alloc] init];
  735. pvc.selectContact = YES;
  736. pvc.multiSelect = YES;
  737. NSMutableArray *disabledUser = [[NSMutableArray alloc] init];
  738. if(self.conversation.type == Group_Type) {
  739. for (WFCCGroupMember *member in [[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupInfo.target forceUpdate:NO]) {
  740. [disabledUser addObject:member.memberId];
  741. }
  742. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  743. [[WFCCIMService sharedWFCIMService] addMembers:contacts toGroup:ws.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
  744. [[WFCCIMService sharedWFCIMService] getGroupMembers:ws.conversation.target forceUpdate:YES];
  745. } error:^(int error_code) {
  746. }];
  747. };
  748. pvc.disableUsersSelected = YES;
  749. } else {
  750. [disabledUser addObject:self.conversation.target];
  751. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  752. WFCUCreateGroupViewController *vc = [[WFCUCreateGroupViewController alloc] init];
  753. vc.memberIds = [contacts mutableCopy];
  754. if(![vc.memberIds containsObject:self.conversation.target]) {
  755. [vc.memberIds insertObject:self.conversation.target atIndex:0];
  756. }
  757. if(![vc.memberIds containsObject:[WFCCNetworkService sharedInstance].userId]) {
  758. [vc.memberIds insertObject:[WFCCNetworkService sharedInstance].userId atIndex:0];
  759. }
  760. vc.hidesBottomBarWhenPushed = YES;
  761. UINavigationController *nav = self.navigationController;
  762. [self.navigationController popToRootViewControllerAnimated:NO];
  763. [nav pushViewController:vc animated:YES];
  764. vc.onSuccess = ^(NSString *groupId) {
  765. WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
  766. mvc.conversation = [[WFCCConversation alloc] init];
  767. mvc.conversation.type = Group_Type;
  768. mvc.conversation.target = groupId;
  769. mvc.conversation.line = 0;
  770. mvc.hidesBottomBarWhenPushed = YES;
  771. [nav pushViewController:mvc animated:YES];
  772. };
  773. };
  774. pvc.disableUsersSelected = YES;
  775. }
  776. pvc.disableUsers = disabledUser;
  777. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:pvc];
  778. [self.navigationController presentViewController:navi animated:YES completion:nil];
  779. } else if(indexPath.row == self.memberCollectionCount-self.extraBtnNumber + 1) {
  780. WFCUContactListViewController *pvc = [[WFCUContactListViewController alloc] init];
  781. pvc.selectContact = YES;
  782. pvc.multiSelect = YES;
  783. __weak typeof(self)ws = self;
  784. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  785. [[WFCCIMService sharedWFCIMService] kickoffMembers:contacts fromGroup:self.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
  786. [[WFCCIMService sharedWFCIMService] getGroupMembers:ws.conversation.target forceUpdate:YES];
  787. dispatch_async(dispatch_get_main_queue(), ^{
  788. NSMutableArray *tmpArray = [ws.memberList mutableCopy];
  789. NSMutableArray *removeArray = [[NSMutableArray alloc] init];
  790. [tmpArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  791. WFCCGroupMember *member = obj;
  792. if([contacts containsObject:member.memberId]) {
  793. [removeArray addObject:member];
  794. }
  795. }];
  796. [tmpArray removeObjectsInArray:removeArray];
  797. ws.memberList = [tmpArray mutableCopy];
  798. [ws setupMemberCollectionView];
  799. [ws.memberCollectionView reloadData];
  800. });
  801. } error:^(int error_code) {
  802. }];
  803. };
  804. NSMutableArray *candidateUsers = [[NSMutableArray alloc] init];
  805. NSMutableArray *disableUsers = [[NSMutableArray alloc] init];
  806. BOOL isOwner = [self isGroupOwner];
  807. for (WFCCGroupMember *member in [[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupInfo.target forceUpdate:NO]) {
  808. [candidateUsers addObject:member.memberId];
  809. if (!isOwner && (member.type == Member_Type_Manager || [self.groupInfo.owner isEqualToString:member.memberId])) {
  810. [disableUsers addObject:member.memberId];
  811. }
  812. }
  813. [disableUsers addObject:[WFCCNetworkService sharedInstance].userId];
  814. pvc.candidateUsers = candidateUsers;
  815. pvc.disableUsers = [disableUsers copy];
  816. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:pvc];
  817. [self.navigationController presentViewController:navi animated:YES completion:nil];
  818. } else {
  819. NSString *userId;
  820. if(self.conversation.type == Group_Type) {
  821. WFCCGroupMember *member = [self.memberList objectAtIndex:indexPath.row];
  822. userId = member.memberId;
  823. if (self.groupInfo.privateChat) {
  824. if (![self.groupInfo.owner isEqualToString:userId] && ![self.groupInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  825. WFCCGroupMember *gm = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
  826. if (gm.type != Member_Type_Manager) {
  827. WFCCGroupMember *gm = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:userId];
  828. if (gm.type != Member_Type_Manager) {
  829. [self.view makeToast:WFCString(@"NotAllowTemporarySession") duration:1 position:CSToastPositionCenter];
  830. return;
  831. }
  832. }
  833. }
  834. }
  835. } else {
  836. userId = self.conversation.target;
  837. }
  838. // if ([[WFCCNetworkService sharedInstance].userId isEqualToString:userId]) {
  839. // WFCUMyProfileTableViewController *vc = [[WFCUMyProfileTableViewController alloc] init];
  840. // vc.hidesBottomBarWhenPushed = YES;
  841. // [self.navigationController pushViewController:vc animated:YES];
  842. // } else {
  843. WFCUProfileTableViewController *vc = [[WFCUProfileTableViewController alloc] init];
  844. vc.userId = userId;
  845. vc.hidesBottomBarWhenPushed = YES;
  846. [self.navigationController pushViewController:vc animated:YES];
  847. // }
  848. }
  849. }
  850. - (void)dealloc {
  851. [[NSNotificationCenter defaultCenter] removeObserver:self];
  852. }
  853. @end