WFCUConversationSettingViewController.m 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  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 "WFCUCreateGroupViewController.h"
  18. #import "WFCUProfileTableViewController.h"
  19. #import "GroupManageTableViewController.h"
  20. #import "WFCUGroupMemberCollectionViewController.h"
  21. #import "WFCUGroupFilesViewController.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 = [WFCUConfigManager globalManager].backgroudColor;
  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 = [WFCUConfigManager globalManager].backgroudColor;
  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_Manager || obj.type == Member_Type_Owner) {
  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)isGroupFileCell:(NSIndexPath *)indexPath {
  412. if (self.conversation.type == Group_Type && indexPath.section == 1 && indexPath.row == 1) {
  413. return YES;
  414. }
  415. return NO;
  416. }
  417. - (BOOL)isUnsubscribeChannel:(NSIndexPath *)indexPath {
  418. if (self.conversation.type == Channel_Type && indexPath.section == 3 && indexPath.row == 0) {
  419. return YES;
  420. }
  421. return NO;
  422. }
  423. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  424. if (self.conversation.type == Group_Type) {
  425. if (section == 0) {
  426. if ([self isGroupManager] && self.groupInfo.type == GroupType_Restricted) {
  427. return 5; //群名称,群头像,群二维码,群管理,群公告
  428. } else {
  429. return 4; //群名称,群头像,群二维码,群公告
  430. }
  431. } else if(section == 1) {
  432. if ([[WFCCIMService sharedWFCIMService] isCommercialServer]) {
  433. return 2; //查找聊天内容, 群文件
  434. }
  435. return 1; //查找聊天内容
  436. } else if(section == 2) {
  437. return 3; //消息免打扰,置顶聊天,保存到通讯录
  438. } else if(section == 3) {
  439. return 2; //群昵称,显示群昵称
  440. } else if(section == 4) {
  441. return 2; //清空聊天记录,删除退群
  442. }
  443. } else if(self.conversation.type == Single_Type) {
  444. if(section == 0) {
  445. return 1; //查找聊天内容
  446. } else if(section == 1) {
  447. return 2; //消息免打扰,置顶聊天
  448. } else if(section == 2) {
  449. return 1; //清空聊天记录
  450. }
  451. } else if(self.conversation.type == Channel_Type) {
  452. if(section == 0) {
  453. return 1; //查找聊天内容
  454. } else if(section == 1) {
  455. return 2; //消息免打扰,置顶聊天
  456. } else if(section == 2) {
  457. return 1; //清空聊天记录
  458. } else if(section == 3) {
  459. return 1; //取消订阅/销毁订阅
  460. }
  461. }
  462. return 0;
  463. }
  464. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  465. return 9;
  466. }
  467. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  468. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,9)];
  469. view.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
  470. return view;
  471. }
  472. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  473. if ([self isGroupAnnouncementCell:indexPath]) {
  474. float height = [WFCUUtilities getTextDrawingSize:self.groupAnnouncement.text font:[UIFont pingFangSCWithWeight:FontWeightStyleRegular size:12] constrainedSize:CGSizeMake(self.view.bounds.size.width - 48, 1000)].height;
  475. if (height > 12 * 3.2) {
  476. height = 12 * 3.2;
  477. }
  478. return height + 50;
  479. }
  480. return 50;
  481. }
  482. - (UITableViewCell *)cellOfTable:(UITableView *)tableView WithTitle:(NSString *)title withDetailTitle:(NSString *)detailTitle withDisclosureIndicator:(BOOL)withDI withSwitch:(BOOL)withSwitch withSwitchType:(SwitchType)type {
  483. if (withSwitch) {
  484. WFCUSwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"styleSwitch"];
  485. if(cell == nil) {
  486. cell = [[WFCUSwitchTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"styleSwitch" conversation:self.conversation];
  487. }
  488. cell.textLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  489. cell.textLabel.textColor = [WFCUConfigManager globalManager].textColor;
  490. cell.detailTextLabel.text = nil;
  491. cell.accessoryType = UITableViewCellAccessoryNone;
  492. cell.accessoryView = nil;
  493. cell.textLabel.text = title;
  494. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  495. cell.type = type;
  496. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0 );
  497. return cell;
  498. } else {
  499. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"style1Cell"];
  500. if (cell == nil) {
  501. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"style1Cell"];
  502. }
  503. cell.textLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  504. cell.textLabel.text = title;
  505. cell.detailTextLabel.text = detailTitle;
  506. cell.detailTextLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:15];
  507. cell.accessoryType = withDI ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
  508. cell.accessoryView = nil;
  509. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  510. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0 );
  511. return cell;
  512. }
  513. }
  514. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  515. if ([self isGroupNameCell:indexPath]) {
  516. return [self cellOfTable:tableView WithTitle:WFCString(@"GroupName") withDetailTitle:self.groupInfo.name withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  517. } else if ([self isGroupPortraitCell:indexPath]) {
  518. UITableViewCell *cell = [self cellOfTable:tableView WithTitle:WFCString(@"ChangePortrait") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  519. UIImageView *portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 56, 8, 40, 40)];
  520. [portraitView sd_setImageWithURL:[NSURL URLWithString:[self.groupInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[UIImage imageNamed:@"group_default_portrait"]];
  521. cell.accessoryView = portraitView;
  522. return cell;
  523. } else if([self isGroupQrCodeCell:indexPath]) {
  524. UITableViewCell *cell = [self cellOfTable:tableView WithTitle:WFCString(@"GroupQRCode") withDetailTitle:nil withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  525. CGFloat width = [UIScreen mainScreen].bounds.size.width;
  526. UIImage *qrcode = [UIImage imageNamed:@"qrcode"];
  527. UIImageView *qrview = [[UIImageView alloc] initWithFrame:CGRectMake(width - 60, (50 - 22) / 2.0, 22, 22)];
  528. qrview.image = qrcode;
  529. [cell addSubview:qrview];
  530. return cell;
  531. } else if ([self isGroupManageCell:indexPath]) {
  532. return [self cellOfTable:tableView WithTitle:WFCString(@"GroupManage") withDetailTitle:nil withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  533. } else if([self isGroupAnnouncementCell:indexPath]) {
  534. // return [self cellOfTable:tableView WithTitle:@"群公告" withDetailTitle:nil withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  535. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"announcementCell"];
  536. if (cell == nil) {
  537. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"announcementCell"];
  538. }
  539. cell.textLabel.text = WFCString(@"GroupAnnouncement");
  540. cell.textLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  541. cell.detailTextLabel.text = self.groupAnnouncement.text;
  542. cell.detailTextLabel.numberOfLines = 3;
  543. cell.detailTextLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:12];
  544. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  545. cell.accessoryView = nil;
  546. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  547. return cell;
  548. } else if ([self isSearchMessageCell:indexPath]) {
  549. return [self cellOfTable:tableView WithTitle:WFCString(@"SearchMessageContent") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  550. } else if ([self isMessageSilentCell:indexPath]) {
  551. return [self cellOfTable:tableView WithTitle:WFCString(@"Silent") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Silent];
  552. } else if ([self isSetTopCell:indexPath]) {
  553. return [self cellOfTable:tableView WithTitle:WFCString(@"PinChat") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Top];
  554. } else if ([self isSaveGroupCell:indexPath]) {
  555. return [self cellOfTable:tableView WithTitle:WFCString(@"SaveToContact") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Save_To_Contact];
  556. } else if ([self isGroupNameCardCell:indexPath]) {
  557. WFCCGroupMember *groupMember = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
  558. if (groupMember.alias.length) {
  559. return [self cellOfTable:tableView WithTitle:WFCString(@"NicknameInGroup") withDetailTitle:groupMember.alias withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  560. } else {
  561. return [self cellOfTable:tableView WithTitle:WFCString(@"NicknameInGroup") withDetailTitle:WFCString(@"Unset") withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  562. }
  563. } else if([self isShowNameCardCell:indexPath]) {
  564. return [self cellOfTable:tableView WithTitle:WFCString(@"ShowMemberNickname") withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Show_Alias];
  565. } else if ([self isClearMessageCell:indexPath]) {
  566. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
  567. if (cell == nil) {
  568. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
  569. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  570. for (UIView *subView in cell.subviews) {
  571. [subView removeFromSuperview];
  572. }
  573. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
  574. [btn setTitle:WFCString(@"ClearChatHistory") forState:UIControlStateNormal];
  575. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  576. [btn setTitleColor:[UIColor colorWithHexString:@"0xf95569"] forState:UIControlStateNormal];
  577. [btn addTarget:self action:@selector(clearMessageAction) forControlEvents:UIControlEventTouchUpInside];
  578. if (@available(iOS 14, *)) {
  579. [cell.contentView addSubview:btn];
  580. } else {
  581. [cell addSubview:btn];
  582. }
  583. }
  584. return cell;
  585. } else if([self isQuitGroup:indexPath]) {
  586. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
  587. if (cell == nil) {
  588. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
  589. for (UIView *subView in cell.subviews) {
  590. [subView removeFromSuperview];
  591. }
  592. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
  593. if ([self isGroupOwner]) {
  594. [btn setTitle:WFCString(@"DismissGroup") forState:UIControlStateNormal];
  595. } else {
  596. [btn setTitle:WFCString(@"QuitGroup") forState:UIControlStateNormal];
  597. }
  598. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  599. [btn setTitleColor:[UIColor colorWithHexString:@"0xf95569"] forState:UIControlStateNormal];
  600. [btn addTarget:self action:@selector(onDeleteAndQuit:) forControlEvents:UIControlEventTouchUpInside];
  601. if (@available(iOS 14, *)) {
  602. [cell.contentView addSubview:btn];
  603. } else {
  604. [cell addSubview:btn];
  605. }
  606. }
  607. return cell;
  608. } else if([self isUnsubscribeChannel:indexPath]) {
  609. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
  610. if (cell == nil) {
  611. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
  612. for (UIView *subView in cell.subviews) {
  613. [subView removeFromSuperview];
  614. }
  615. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 4, self.view.frame.size.width - 40, 40)];
  616. if ([self isChannelOwner]) {
  617. [btn setTitle:WFCString(@"DestroyChannel") forState:UIControlStateNormal];
  618. } else {
  619. [btn setTitle:WFCString(@"UnscribeChannel") forState:UIControlStateNormal];
  620. }
  621. btn.layer.cornerRadius = 5.f;
  622. btn.layer.masksToBounds = YES;
  623. btn.backgroundColor = [UIColor redColor];
  624. [btn addTarget:self action:@selector(onDeleteAndQuit:) forControlEvents:UIControlEventTouchUpInside];
  625. if (@available(iOS 14, *)) {
  626. [cell.contentView addSubview:btn];
  627. } else {
  628. [cell addSubview:btn];
  629. }
  630. }
  631. return cell;
  632. } else if([self isGroupFileCell:indexPath]) {
  633. return [self cellOfTable:tableView WithTitle:WFCString(@"GroupFiles") withDetailTitle:nil withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  634. }
  635. return nil;
  636. }
  637. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  638. if (self.conversation.type == Single_Type) {
  639. return 3;
  640. } else if(self.conversation.type == Group_Type) {
  641. return 5;
  642. } else if(self.conversation.type == Channel_Type) {
  643. return 4;
  644. }
  645. return 0;
  646. }
  647. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  648. __weak typeof(self)weakSelf = self;
  649. if ([self isGroupNameCell:indexPath]) {
  650. if (self.groupInfo.type == GroupType_Restricted && ![self isGroupManager]) {
  651. [self.view makeToast:WFCString(@"OnlyManangerCanChangeGroupNameHint") duration:1 position:CSToastPositionCenter];
  652. return;
  653. }
  654. WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
  655. gmvc.defaultValue = self.groupInfo.name;
  656. gmvc.titleText = WFCString(@"ModifyGroupName");
  657. gmvc.canEmpty = NO;
  658. gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
  659. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_Name newValue:newValue notifyLines:@[@(0)] notifyContent:nil success:^{
  660. result(YES);
  661. weakSelf.groupInfo.name = newValue;
  662. [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  663. } error:^(int error_code) {
  664. result(NO);
  665. }];
  666. };
  667. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
  668. [self.navigationController presentViewController:nav animated:YES completion:nil];
  669. } else if ([self isGroupPortraitCell:indexPath]) {
  670. #if !WFCU_GROUP_GRID_PORTRAIT
  671. if (self.groupInfo.type == GroupType_Restricted && ![self isGroupManager]) {
  672. [self.view makeToast:WFCString(@"OnlyManangerCanChangeGroupPortraitHint") duration:1 position:CSToastPositionCenter];
  673. return;
  674. }
  675. WFCUCreateGroupViewController *vc = [[WFCUCreateGroupViewController alloc] init];
  676. vc.isModifyPortrait = YES;
  677. vc.groupId = self.groupInfo.target;
  678. vc.memberIds = [[NSMutableArray alloc] init];
  679. for (WFCCGroupMember *member in self.memberList) {
  680. [vc.memberIds addObject:member.memberId];
  681. }
  682. [self.navigationController pushViewController:vc animated:YES];
  683. #endif
  684. } else if ([self isGroupManageCell:indexPath]) {
  685. GroupManageTableViewController *gmvc = [[GroupManageTableViewController alloc] init];
  686. gmvc.groupInfo = self.groupInfo;
  687. [self.navigationController pushViewController:gmvc animated:YES];
  688. } else if ([self isSearchMessageCell:indexPath]) {
  689. WFCUConversationSearchTableViewController *mvc = [[WFCUConversationSearchTableViewController alloc] init];
  690. mvc.conversation = self.conversation;
  691. mvc.hidesBottomBarWhenPushed = YES;
  692. [self.navigationController pushViewController:mvc animated:YES];
  693. } else if ([self isMessageSilentCell:indexPath]) {
  694. } else if ([self isSetTopCell:indexPath]) {
  695. } else if ([self isSaveGroupCell:indexPath]) {
  696. } else if ([self isGroupNameCardCell:indexPath]) {
  697. WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
  698. WFCCGroupMember *groupMember = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
  699. gmvc.defaultValue = groupMember.alias;
  700. gmvc.titleText = WFCString(@"ModifyMyGroupNameCard");
  701. gmvc.canEmpty = NO;
  702. gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
  703. [[WFCCIMService sharedWFCIMService] modifyGroupAlias:self.conversation.target alias:newValue notifyLines:@[@(0)] notifyContent:nil success:^{
  704. result(YES);
  705. [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  706. } error:^(int error_code) {
  707. result(NO);
  708. }];
  709. };
  710. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
  711. [self.navigationController presentViewController:nav animated:YES completion:nil];
  712. } else if([self isShowNameCardCell:indexPath]) {
  713. } else if([self isGroupQrCodeCell:indexPath]) {
  714. if (gQrCodeDelegate) {
  715. [gQrCodeDelegate showQrCodeViewController:self.navigationController type:QRType_Group target:self.groupInfo.target];
  716. }
  717. } else if([self isGroupAnnouncementCell:indexPath]) {
  718. WFCUGroupAnnouncementViewController *vc = [[WFCUGroupAnnouncementViewController alloc] init];
  719. vc.announcement = self.groupAnnouncement;
  720. vc.isManager = [self isGroupManager];
  721. [self.navigationController pushViewController:vc animated:YES];
  722. } else if([self isGroupFileCell:indexPath]) {
  723. WFCUGroupFilesViewController *vc = [[WFCUGroupFilesViewController alloc] init];
  724. vc.conversation = self.conversation;
  725. [self.navigationController pushViewController:vc animated:YES];
  726. }
  727. }
  728. #pragma mark - UICollectionViewDataSource
  729. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  730. if (self.conversation.type == Group_Type || self.conversation.type == Single_Type) {
  731. return self.memberCollectionCount;
  732. } else if(self.conversation.type == Channel_Type) {
  733. return self.memberList.count;
  734. }
  735. return 0;
  736. }
  737. // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
  738. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  739. WFCUConversationSettingMemberCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:Group_Member_Cell_Reuese_ID forIndexPath:indexPath];
  740. if (indexPath.row < self.memberCollectionCount-self.extraBtnNumber) {
  741. WFCCGroupMember *member = self.memberList[indexPath.row];
  742. [cell setModel:member withType:self.conversation.type];
  743. } else {
  744. if (indexPath.row == self.memberCollectionCount-self.extraBtnNumber) {
  745. [cell.headerImageView setImage:[UIImage imageNamed:@"addmember"]];
  746. cell.nameLabel.text = nil;
  747. cell.nameLabel.hidden = YES;
  748. } else {
  749. [cell.headerImageView setImage:[UIImage imageNamed:@"removemember"]];
  750. cell.nameLabel.text = nil;
  751. cell.nameLabel.hidden = YES;
  752. }
  753. cell.headerImageView.layer.cornerRadius = 0;
  754. }
  755. return cell;
  756. }
  757. #pragma mark - UICollectionViewDelegate
  758. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  759. __weak typeof(self)ws = self;
  760. if (indexPath.row == self.memberCollectionCount-self.extraBtnNumber) {
  761. WFCUContactListViewController *pvc = [[WFCUContactListViewController alloc] init];
  762. pvc.selectContact = YES;
  763. pvc.multiSelect = YES;
  764. NSMutableArray *disabledUser = [[NSMutableArray alloc] init];
  765. if(self.conversation.type == Group_Type) {
  766. for (WFCCGroupMember *member in [[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupInfo.target forceUpdate:NO]) {
  767. [disabledUser addObject:member.memberId];
  768. }
  769. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  770. [[WFCCIMService sharedWFCIMService] addMembers:contacts toGroup:ws.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
  771. [[WFCCIMService sharedWFCIMService] getGroupMembers:ws.conversation.target forceUpdate:YES];
  772. } error:^(int error_code) {
  773. if (error_code == ERROR_CODE_GROUP_EXCEED_MAX_MEMBER_COUNT) {
  774. [ws.view makeToast:WFCString(@"ExceedGroupMaxMemberCount") duration:1 position:CSToastPositionCenter];
  775. } else {
  776. [ws.view makeToast:WFCString(@"NetworkError") duration:1 position:CSToastPositionCenter];
  777. }
  778. }];
  779. };
  780. pvc.disableUsersSelected = YES;
  781. } else {
  782. [disabledUser addObject:self.conversation.target];
  783. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  784. #if !WFCU_GROUP_GRID_PORTRAIT
  785. WFCUCreateGroupViewController *vc = [[WFCUCreateGroupViewController alloc] init];
  786. vc.memberIds = [contacts mutableCopy];
  787. if(![vc.memberIds containsObject:self.conversation.target]) {
  788. [vc.memberIds insertObject:self.conversation.target atIndex:0];
  789. }
  790. if(![vc.memberIds containsObject:[WFCCNetworkService sharedInstance].userId]) {
  791. [vc.memberIds insertObject:[WFCCNetworkService sharedInstance].userId atIndex:0];
  792. }
  793. vc.hidesBottomBarWhenPushed = YES;
  794. UINavigationController *nav = self.navigationController;
  795. [self.navigationController popToRootViewControllerAnimated:NO];
  796. [nav pushViewController:vc animated:YES];
  797. vc.onSuccess = ^(NSString *groupId) {
  798. WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
  799. mvc.conversation = [[WFCCConversation alloc] init];
  800. mvc.conversation.type = Group_Type;
  801. mvc.conversation.target = groupId;
  802. mvc.conversation.line = 0;
  803. mvc.hidesBottomBarWhenPushed = YES;
  804. [nav pushViewController:mvc animated:YES];
  805. };
  806. #else
  807. [self createGroup:contacts];
  808. #endif
  809. };
  810. pvc.disableUsersSelected = YES;
  811. }
  812. pvc.disableUsers = disabledUser;
  813. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:pvc];
  814. [self.navigationController presentViewController:navi animated:YES completion:nil];
  815. } else if(indexPath.row == self.memberCollectionCount-self.extraBtnNumber + 1) {
  816. WFCUContactListViewController *pvc = [[WFCUContactListViewController alloc] init];
  817. pvc.selectContact = YES;
  818. pvc.multiSelect = YES;
  819. __weak typeof(self)ws = self;
  820. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  821. [[WFCCIMService sharedWFCIMService] kickoffMembers:contacts fromGroup:self.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
  822. [[WFCCIMService sharedWFCIMService] getGroupMembers:ws.conversation.target forceUpdate:YES];
  823. dispatch_async(dispatch_get_main_queue(), ^{
  824. NSMutableArray *tmpArray = [ws.memberList mutableCopy];
  825. NSMutableArray *removeArray = [[NSMutableArray alloc] init];
  826. [tmpArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  827. WFCCGroupMember *member = obj;
  828. if([contacts containsObject:member.memberId]) {
  829. [removeArray addObject:member];
  830. }
  831. }];
  832. [tmpArray removeObjectsInArray:removeArray];
  833. ws.memberList = [tmpArray mutableCopy];
  834. [ws setupMemberCollectionView];
  835. [ws.memberCollectionView reloadData];
  836. });
  837. } error:^(int error_code) {
  838. }];
  839. };
  840. NSMutableArray *candidateUsers = [[NSMutableArray alloc] init];
  841. NSMutableArray *disableUsers = [[NSMutableArray alloc] init];
  842. BOOL isOwner = [self isGroupOwner];
  843. for (WFCCGroupMember *member in [[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupInfo.target forceUpdate:NO]) {
  844. [candidateUsers addObject:member.memberId];
  845. if (!isOwner && (member.type == Member_Type_Manager || [self.groupInfo.owner isEqualToString:member.memberId])) {
  846. [disableUsers addObject:member.memberId];
  847. }
  848. }
  849. [disableUsers addObject:[WFCCNetworkService sharedInstance].userId];
  850. pvc.candidateUsers = candidateUsers;
  851. pvc.disableUsers = [disableUsers copy];
  852. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:pvc];
  853. [self.navigationController presentViewController:navi animated:YES completion:nil];
  854. } else {
  855. NSString *userId;
  856. if(self.conversation.type == Group_Type) {
  857. WFCCGroupMember *member = [self.memberList objectAtIndex:indexPath.row];
  858. userId = member.memberId;
  859. if (self.groupInfo.privateChat) {
  860. if (![self.groupInfo.owner isEqualToString:userId] && ![self.groupInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  861. WFCCGroupMember *gm = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
  862. if (gm.type != Member_Type_Manager) {
  863. WFCCGroupMember *gm = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:userId];
  864. if (gm.type != Member_Type_Manager) {
  865. [self.view makeToast:WFCString(@"NotAllowTemporarySession") duration:1 position:CSToastPositionCenter];
  866. return;
  867. }
  868. }
  869. }
  870. }
  871. } else {
  872. userId = self.conversation.target;
  873. }
  874. // if ([[WFCCNetworkService sharedInstance].userId isEqualToString:userId]) {
  875. // WFCUMyProfileTableViewController *vc = [[WFCUMyProfileTableViewController alloc] init];
  876. // vc.hidesBottomBarWhenPushed = YES;
  877. // [self.navigationController pushViewController:vc animated:YES];
  878. // } else {
  879. WFCUProfileTableViewController *vc = [[WFCUProfileTableViewController alloc] init];
  880. vc.userId = userId;
  881. vc.hidesBottomBarWhenPushed = YES;
  882. [self.navigationController pushViewController:vc animated:YES];
  883. // }
  884. }
  885. }
  886. #if WFCU_GROUP_GRID_PORTRAIT
  887. - (void)createGroup:(NSArray<NSString *> *)contacts {
  888. __weak typeof(self) ws = self;
  889. NSMutableArray<NSString *> *memberIds = [contacts mutableCopy];
  890. if(![memberIds containsObject:self.conversation.target]) {
  891. [memberIds insertObject:self.conversation.target atIndex:0];
  892. }
  893. if (![memberIds containsObject:[WFCCNetworkService sharedInstance].userId]) {
  894. [memberIds insertObject:[WFCCNetworkService sharedInstance].userId atIndex:0];
  895. }
  896. NSString *name;
  897. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[memberIds objectAtIndex:0] refresh:NO];
  898. name = userInfo.displayName;
  899. for (int i = 1; i < MIN(8, memberIds.count); i++) {
  900. userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[memberIds objectAtIndex:i] refresh:NO];
  901. if (userInfo.displayName.length > 0) {
  902. if (name.length + userInfo.displayName.length + 1 > 16) {
  903. name = [name stringByAppendingString:WFCString(@"Etc")];
  904. break;
  905. }
  906. name = [name stringByAppendingFormat:@",%@", userInfo.displayName];
  907. }
  908. }
  909. if (name.length == 0) {
  910. name = WFCString(@"GroupChat");
  911. }
  912. [[WFCCIMService sharedWFCIMService] createGroup:nil name:name portrait:nil type:GroupType_Restricted members:memberIds notifyLines:@[@(0)] notifyContent:nil success:^(NSString *groupId) {
  913. NSLog(@"create group success");
  914. WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
  915. mvc.conversation = [[WFCCConversation alloc] init];
  916. mvc.conversation.type = Group_Type;
  917. mvc.conversation.target = groupId;
  918. mvc.conversation.line = 0;
  919. mvc.hidesBottomBarWhenPushed = YES;
  920. UINavigationController *nav = self.navigationController;
  921. [self.navigationController popToRootViewControllerAnimated:NO];
  922. [nav pushViewController:mvc animated:YES];
  923. } error:^(int error_code) {
  924. NSLog(@"create group failure");
  925. [ws.view makeToast:WFCString(@"CreateGroupFailure")
  926. duration:2
  927. position:CSToastPositionCenter];
  928. }];
  929. }
  930. #endif
  931. - (void)dealloc {
  932. [[NSNotificationCenter defaultCenter] removeObserver:self];
  933. }
  934. @end