2
0

WFCUConversationSettingViewController.m 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  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 "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. [cell addSubview:btn];
  579. }
  580. return cell;
  581. } else if([self isQuitGroup:indexPath]) {
  582. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
  583. if (cell == nil) {
  584. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
  585. for (UIView *subView in cell.subviews) {
  586. [subView removeFromSuperview];
  587. }
  588. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
  589. if ([self isGroupOwner]) {
  590. [btn setTitle:WFCString(@"DismissGroup") forState:UIControlStateNormal];
  591. } else {
  592. [btn setTitle:WFCString(@"QuitGroup") forState:UIControlStateNormal];
  593. }
  594. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  595. [btn setTitleColor:[UIColor colorWithHexString:@"0xf95569"] forState:UIControlStateNormal];
  596. [btn addTarget:self action:@selector(onDeleteAndQuit:) forControlEvents:UIControlEventTouchUpInside];
  597. [cell addSubview:btn];
  598. }
  599. return cell;
  600. } else if([self isUnsubscribeChannel:indexPath]) {
  601. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
  602. if (cell == nil) {
  603. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
  604. for (UIView *subView in cell.subviews) {
  605. [subView removeFromSuperview];
  606. }
  607. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 4, self.view.frame.size.width - 40, 40)];
  608. if ([self isChannelOwner]) {
  609. [btn setTitle:WFCString(@"DestroyChannel") forState:UIControlStateNormal];
  610. } else {
  611. [btn setTitle:WFCString(@"UnscribeChannel") forState:UIControlStateNormal];
  612. }
  613. btn.layer.cornerRadius = 5.f;
  614. btn.layer.masksToBounds = YES;
  615. btn.backgroundColor = [UIColor redColor];
  616. [btn addTarget:self action:@selector(onDeleteAndQuit:) forControlEvents:UIControlEventTouchUpInside];
  617. [cell addSubview:btn];
  618. }
  619. return cell;
  620. } else if([self isGroupFileCell:indexPath]) {
  621. return [self cellOfTable:tableView WithTitle:WFCString(@"GroupFiles") withDetailTitle:nil withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  622. }
  623. return nil;
  624. }
  625. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  626. if (self.conversation.type == Single_Type) {
  627. return 3;
  628. } else if(self.conversation.type == Group_Type) {
  629. return 5;
  630. } else if(self.conversation.type == Channel_Type) {
  631. return 4;
  632. }
  633. return 0;
  634. }
  635. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  636. __weak typeof(self)weakSelf = self;
  637. if ([self isGroupNameCell:indexPath]) {
  638. if (self.groupInfo.type == GroupType_Restricted && ![self isGroupManager]) {
  639. [self.view makeToast:WFCString(@"OnlyManangerCanChangeGroupNameHint") duration:1 position:CSToastPositionCenter];
  640. return;
  641. }
  642. WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
  643. gmvc.defaultValue = self.groupInfo.name;
  644. gmvc.titleText = WFCString(@"ModifyGroupName");
  645. gmvc.canEmpty = NO;
  646. gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
  647. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_Name newValue:newValue notifyLines:@[@(0)] notifyContent:nil success:^{
  648. result(YES);
  649. weakSelf.groupInfo.name = newValue;
  650. [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  651. } error:^(int error_code) {
  652. result(NO);
  653. }];
  654. };
  655. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
  656. [self.navigationController presentViewController:nav animated:YES completion:nil];
  657. } else if ([self isGroupPortraitCell:indexPath]) {
  658. #if !WFCU_GROUP_GRID_PORTRAIT
  659. if (self.groupInfo.type == GroupType_Restricted && ![self isGroupManager]) {
  660. [self.view makeToast:WFCString(@"OnlyManangerCanChangeGroupPortraitHint") duration:1 position:CSToastPositionCenter];
  661. return;
  662. }
  663. WFCUCreateGroupViewController *vc = [[WFCUCreateGroupViewController alloc] init];
  664. vc.isModifyPortrait = YES;
  665. vc.groupId = self.groupInfo.target;
  666. vc.memberIds = [[NSMutableArray alloc] init];
  667. for (WFCCGroupMember *member in self.memberList) {
  668. [vc.memberIds addObject:member.memberId];
  669. }
  670. [self.navigationController pushViewController:vc animated:YES];
  671. #endif
  672. } else if ([self isGroupManageCell:indexPath]) {
  673. GroupManageTableViewController *gmvc = [[GroupManageTableViewController alloc] init];
  674. gmvc.groupInfo = self.groupInfo;
  675. [self.navigationController pushViewController:gmvc animated:YES];
  676. } else if ([self isSearchMessageCell:indexPath]) {
  677. WFCUConversationSearchTableViewController *mvc = [[WFCUConversationSearchTableViewController alloc] init];
  678. mvc.conversation = self.conversation;
  679. mvc.hidesBottomBarWhenPushed = YES;
  680. [self.navigationController pushViewController:mvc animated:YES];
  681. } else if ([self isMessageSilentCell:indexPath]) {
  682. } else if ([self isSetTopCell:indexPath]) {
  683. } else if ([self isSaveGroupCell:indexPath]) {
  684. } else if ([self isGroupNameCardCell:indexPath]) {
  685. WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
  686. WFCCGroupMember *groupMember = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
  687. gmvc.defaultValue = groupMember.alias;
  688. gmvc.titleText = WFCString(@"ModifyMyGroupNameCard");
  689. gmvc.canEmpty = NO;
  690. gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
  691. [[WFCCIMService sharedWFCIMService] modifyGroupAlias:self.conversation.target alias:newValue notifyLines:@[@(0)] notifyContent:nil success:^{
  692. result(YES);
  693. [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
  694. } error:^(int error_code) {
  695. result(NO);
  696. }];
  697. };
  698. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
  699. [self.navigationController presentViewController:nav animated:YES completion:nil];
  700. } else if([self isShowNameCardCell:indexPath]) {
  701. } else if([self isGroupQrCodeCell:indexPath]) {
  702. if (gQrCodeDelegate) {
  703. [gQrCodeDelegate showQrCodeViewController:self.navigationController type:QRType_Group target:self.groupInfo.target];
  704. }
  705. } else if([self isGroupAnnouncementCell:indexPath]) {
  706. WFCUGroupAnnouncementViewController *vc = [[WFCUGroupAnnouncementViewController alloc] init];
  707. vc.announcement = self.groupAnnouncement;
  708. vc.isManager = [self isGroupManager];
  709. [self.navigationController pushViewController:vc animated:YES];
  710. } else if([self isGroupFileCell:indexPath]) {
  711. WFCUGroupFilesViewController *vc = [[WFCUGroupFilesViewController alloc] init];
  712. vc.conversation = self.conversation;
  713. [self.navigationController pushViewController:vc animated:YES];
  714. }
  715. }
  716. #pragma mark - UICollectionViewDataSource
  717. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  718. if (self.conversation.type == Group_Type || self.conversation.type == Single_Type) {
  719. return self.memberCollectionCount;
  720. } else if(self.conversation.type == Channel_Type) {
  721. return self.memberList.count;
  722. }
  723. return 0;
  724. }
  725. // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
  726. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  727. WFCUConversationSettingMemberCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:Group_Member_Cell_Reuese_ID forIndexPath:indexPath];
  728. if (indexPath.row < self.memberCollectionCount-self.extraBtnNumber) {
  729. WFCCGroupMember *member = self.memberList[indexPath.row];
  730. [cell setModel:member withType:self.conversation.type];
  731. } else {
  732. if (indexPath.row == self.memberCollectionCount-self.extraBtnNumber) {
  733. [cell.headerImageView setImage:[UIImage imageNamed:@"addmember"]];
  734. cell.nameLabel.text = nil;
  735. cell.nameLabel.hidden = YES;
  736. } else {
  737. [cell.headerImageView setImage:[UIImage imageNamed:@"removemember"]];
  738. cell.nameLabel.text = nil;
  739. cell.nameLabel.hidden = YES;
  740. }
  741. cell.headerImageView.layer.cornerRadius = 0;
  742. }
  743. return cell;
  744. }
  745. #pragma mark - UICollectionViewDelegate
  746. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  747. __weak typeof(self)ws = self;
  748. if (indexPath.row == self.memberCollectionCount-self.extraBtnNumber) {
  749. WFCUContactListViewController *pvc = [[WFCUContactListViewController alloc] init];
  750. pvc.selectContact = YES;
  751. pvc.multiSelect = YES;
  752. NSMutableArray *disabledUser = [[NSMutableArray alloc] init];
  753. if(self.conversation.type == Group_Type) {
  754. for (WFCCGroupMember *member in [[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupInfo.target forceUpdate:NO]) {
  755. [disabledUser addObject:member.memberId];
  756. }
  757. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  758. [[WFCCIMService sharedWFCIMService] addMembers:contacts toGroup:ws.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
  759. [[WFCCIMService sharedWFCIMService] getGroupMembers:ws.conversation.target forceUpdate:YES];
  760. } error:^(int error_code) {
  761. if (error_code == ERROR_CODE_GROUP_EXCEED_MAX_MEMBER_COUNT) {
  762. [ws.view makeToast:WFCString(@"ExceedGroupMaxMemberCount") duration:1 position:CSToastPositionCenter];
  763. } else {
  764. [ws.view makeToast:WFCString(@"NetworkError") duration:1 position:CSToastPositionCenter];
  765. }
  766. }];
  767. };
  768. pvc.disableUsersSelected = YES;
  769. } else {
  770. [disabledUser addObject:self.conversation.target];
  771. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  772. #if !WFCU_GROUP_GRID_PORTRAIT
  773. WFCUCreateGroupViewController *vc = [[WFCUCreateGroupViewController alloc] init];
  774. vc.memberIds = [contacts mutableCopy];
  775. if(![vc.memberIds containsObject:self.conversation.target]) {
  776. [vc.memberIds insertObject:self.conversation.target atIndex:0];
  777. }
  778. if(![vc.memberIds containsObject:[WFCCNetworkService sharedInstance].userId]) {
  779. [vc.memberIds insertObject:[WFCCNetworkService sharedInstance].userId atIndex:0];
  780. }
  781. vc.hidesBottomBarWhenPushed = YES;
  782. UINavigationController *nav = self.navigationController;
  783. [self.navigationController popToRootViewControllerAnimated:NO];
  784. [nav pushViewController:vc animated:YES];
  785. vc.onSuccess = ^(NSString *groupId) {
  786. WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
  787. mvc.conversation = [[WFCCConversation alloc] init];
  788. mvc.conversation.type = Group_Type;
  789. mvc.conversation.target = groupId;
  790. mvc.conversation.line = 0;
  791. mvc.hidesBottomBarWhenPushed = YES;
  792. [nav pushViewController:mvc animated:YES];
  793. };
  794. #else
  795. [self createGroup:contacts];
  796. #endif
  797. };
  798. pvc.disableUsersSelected = YES;
  799. }
  800. pvc.disableUsers = disabledUser;
  801. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:pvc];
  802. [self.navigationController presentViewController:navi animated:YES completion:nil];
  803. } else if(indexPath.row == self.memberCollectionCount-self.extraBtnNumber + 1) {
  804. WFCUContactListViewController *pvc = [[WFCUContactListViewController alloc] init];
  805. pvc.selectContact = YES;
  806. pvc.multiSelect = YES;
  807. __weak typeof(self)ws = self;
  808. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  809. [[WFCCIMService sharedWFCIMService] kickoffMembers:contacts fromGroup:self.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
  810. [[WFCCIMService sharedWFCIMService] getGroupMembers:ws.conversation.target forceUpdate:YES];
  811. dispatch_async(dispatch_get_main_queue(), ^{
  812. NSMutableArray *tmpArray = [ws.memberList mutableCopy];
  813. NSMutableArray *removeArray = [[NSMutableArray alloc] init];
  814. [tmpArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  815. WFCCGroupMember *member = obj;
  816. if([contacts containsObject:member.memberId]) {
  817. [removeArray addObject:member];
  818. }
  819. }];
  820. [tmpArray removeObjectsInArray:removeArray];
  821. ws.memberList = [tmpArray mutableCopy];
  822. [ws setupMemberCollectionView];
  823. [ws.memberCollectionView reloadData];
  824. });
  825. } error:^(int error_code) {
  826. }];
  827. };
  828. NSMutableArray *candidateUsers = [[NSMutableArray alloc] init];
  829. NSMutableArray *disableUsers = [[NSMutableArray alloc] init];
  830. BOOL isOwner = [self isGroupOwner];
  831. for (WFCCGroupMember *member in [[WFCCIMService sharedWFCIMService] getGroupMembers:self.groupInfo.target forceUpdate:NO]) {
  832. [candidateUsers addObject:member.memberId];
  833. if (!isOwner && (member.type == Member_Type_Manager || [self.groupInfo.owner isEqualToString:member.memberId])) {
  834. [disableUsers addObject:member.memberId];
  835. }
  836. }
  837. [disableUsers addObject:[WFCCNetworkService sharedInstance].userId];
  838. pvc.candidateUsers = candidateUsers;
  839. pvc.disableUsers = [disableUsers copy];
  840. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:pvc];
  841. [self.navigationController presentViewController:navi animated:YES completion:nil];
  842. } else {
  843. NSString *userId;
  844. if(self.conversation.type == Group_Type) {
  845. WFCCGroupMember *member = [self.memberList objectAtIndex:indexPath.row];
  846. userId = member.memberId;
  847. if (self.groupInfo.privateChat) {
  848. if (![self.groupInfo.owner isEqualToString:userId] && ![self.groupInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  849. WFCCGroupMember *gm = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
  850. if (gm.type != Member_Type_Manager) {
  851. WFCCGroupMember *gm = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:userId];
  852. if (gm.type != Member_Type_Manager) {
  853. [self.view makeToast:WFCString(@"NotAllowTemporarySession") duration:1 position:CSToastPositionCenter];
  854. return;
  855. }
  856. }
  857. }
  858. }
  859. } else {
  860. userId = self.conversation.target;
  861. }
  862. // if ([[WFCCNetworkService sharedInstance].userId isEqualToString:userId]) {
  863. // WFCUMyProfileTableViewController *vc = [[WFCUMyProfileTableViewController alloc] init];
  864. // vc.hidesBottomBarWhenPushed = YES;
  865. // [self.navigationController pushViewController:vc animated:YES];
  866. // } else {
  867. WFCUProfileTableViewController *vc = [[WFCUProfileTableViewController alloc] init];
  868. vc.userId = userId;
  869. vc.hidesBottomBarWhenPushed = YES;
  870. [self.navigationController pushViewController:vc animated:YES];
  871. // }
  872. }
  873. }
  874. #if WFCU_GROUP_GRID_PORTRAIT
  875. - (void)createGroup:(NSArray<NSString *> *)contacts {
  876. __weak typeof(self) ws = self;
  877. NSMutableArray<NSString *> *memberIds = [contacts mutableCopy];
  878. if(![memberIds containsObject:self.conversation.target]) {
  879. [memberIds insertObject:self.conversation.target atIndex:0];
  880. }
  881. if (![memberIds containsObject:[WFCCNetworkService sharedInstance].userId]) {
  882. [memberIds insertObject:[WFCCNetworkService sharedInstance].userId atIndex:0];
  883. }
  884. NSString *name;
  885. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[memberIds objectAtIndex:0] refresh:NO];
  886. name = userInfo.displayName;
  887. for (int i = 1; i < MIN(8, memberIds.count); i++) {
  888. userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:[memberIds objectAtIndex:i] refresh:NO];
  889. if (userInfo.displayName.length > 0) {
  890. if (name.length + userInfo.displayName.length + 1 > 16) {
  891. name = [name stringByAppendingString:WFCString(@"Etc")];
  892. break;
  893. }
  894. name = [name stringByAppendingFormat:@",%@", userInfo.displayName];
  895. }
  896. }
  897. if (name.length == 0) {
  898. name = WFCString(@"GroupChat");
  899. }
  900. [[WFCCIMService sharedWFCIMService] createGroup:nil name:name portrait:nil type:GroupType_Restricted members:memberIds notifyLines:@[@(0)] notifyContent:nil success:^(NSString *groupId) {
  901. NSLog(@"create group success");
  902. WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
  903. mvc.conversation = [[WFCCConversation alloc] init];
  904. mvc.conversation.type = Group_Type;
  905. mvc.conversation.target = groupId;
  906. mvc.conversation.line = 0;
  907. mvc.hidesBottomBarWhenPushed = YES;
  908. UINavigationController *nav = self.navigationController;
  909. [self.navigationController popToRootViewControllerAnimated:NO];
  910. [nav pushViewController:mvc animated:YES];
  911. } error:^(int error_code) {
  912. NSLog(@"create group failure");
  913. [ws.view makeToast:WFCString(@"CreateGroupFailure")
  914. duration:2
  915. position:CSToastPositionCenter];
  916. }];
  917. }
  918. #endif
  919. - (void)dealloc {
  920. [[NSNotificationCenter defaultCenter] removeObserver:self];
  921. }
  922. @end