WFCUConversationSettingViewController.m 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. //
  2. // ConversationSettingViewController.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/11/2.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUConversationSettingViewController.h"
  9. #import "SDWebImage.h"
  10. #import <WFChatClient/WFCChatClient.h>
  11. #import "WFCUConversationSettingMemberCollectionViewLayout.h"
  12. #import "WFCUConversationSettingMemberCell.h"
  13. #import "WFCUContactListViewController.h"
  14. #import "WFCUMessageListViewController.h"
  15. #import "WFCUGeneralModifyViewController.h"
  16. #import "WFCUSwitchTableViewCell.h"
  17. #import "WFCUCreateGroupViewController.h"
  18. #import "WFCUProfileTableViewController.h"
  19. #import "WFCUCreateGroupViewController.h"
  20. #import "MBProgressHUD.h"
  21. #import "WFCUMyProfileTableViewController.h"
  22. #import "WFCUConversationSearchTableViewController.h"
  23. #import "WFCUChannelProfileViewController.h"
  24. @interface WFCUConversationSettingViewController () <UITableViewDataSource, UITableViewDelegate, UICollectionViewDelegate, UICollectionViewDataSource>
  25. @property (nonatomic, strong)UICollectionView *memberCollectionView;
  26. @property (nonatomic, strong)WFCUConversationSettingMemberCollectionViewLayout *memberCollectionViewLayout;
  27. @property (nonatomic, strong)UITableView *tableView;
  28. @property (nonatomic, strong)WFCCGroupInfo *groupInfo;
  29. @property (nonatomic, strong)WFCCUserInfo *userInfo;
  30. @property (nonatomic, strong)WFCCChannelInfo *channelInfo;
  31. @property (nonatomic, strong)NSArray<WFCCGroupMember *> *memberList;
  32. @property (nonatomic, strong)UIImageView *channelPortrait;
  33. @property (nonatomic, strong)UILabel *channelName;
  34. @property (nonatomic, strong)UILabel *channelDesc;
  35. @end
  36. #define Group_Member_Cell_Reuese_ID @"Group_Member_Cell_Reuese_ID"
  37. @implementation WFCUConversationSettingViewController
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. if (self.conversation.type == Single_Type) {
  41. self.userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.conversation.target refresh:YES];
  42. self.memberList = @[self.conversation.target];
  43. } else if(self.conversation.type == Group_Type){
  44. self.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:self.conversation.target refresh:YES];
  45. self.memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.conversation.target forceUpdate:YES];
  46. } else if(self.conversation.type == Channel_Type) {
  47. self.channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:self.conversation.target refresh:YES];
  48. self.memberList = @[self.conversation.target];
  49. }
  50. self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
  51. self.tableView.delegate = self;
  52. self.tableView.dataSource = self;
  53. if (self.conversation.type == Single_Type || self.conversation.type == Group_Type) {
  54. self.memberCollectionViewLayout = [[WFCUConversationSettingMemberCollectionViewLayout alloc] initWithItemMargin:5];
  55. int memberCollectionCount = 0;
  56. if (self.conversation.type == Single_Type) {
  57. memberCollectionCount = 2;
  58. } else if(self.conversation.type == Group_Type) {
  59. memberCollectionCount = [self isGroupManager] ? (int)self.memberList.count + 2 : (int)self.memberList.count + 1;
  60. } else if(self.conversation.type == Channel_Type) {
  61. memberCollectionCount = 1;
  62. }
  63. self.memberCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, [self.memberCollectionViewLayout getHeigthOfItemCount:memberCollectionCount]) collectionViewLayout:self.memberCollectionViewLayout];
  64. self.memberCollectionView.delegate = self;
  65. self.memberCollectionView.dataSource = self;
  66. self.memberCollectionView.backgroundColor = [UIColor whiteColor];
  67. [self.memberCollectionView registerClass:[WFCUConversationSettingMemberCell class] forCellWithReuseIdentifier:Group_Member_Cell_Reuese_ID];
  68. self.tableView.tableHeaderView = self.memberCollectionView;
  69. } else if(self.conversation.type == Channel_Type) {
  70. CGFloat portraitWidth = 80;
  71. CGFloat top = 40;
  72. CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
  73. self.channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:self.conversation.target refresh:YES];
  74. self.channelPortrait = [[UIImageView alloc] initWithFrame:CGRectMake((screenWidth - portraitWidth)/2, top, portraitWidth, portraitWidth)];
  75. [self.channelPortrait sd_setImageWithURL:[NSURL URLWithString:self.channelInfo.portrait] placeholderImage:[UIImage imageNamed:@"channel_default_portrait"]];
  76. self.channelPortrait.userInteractionEnabled = YES;
  77. [self.channelPortrait addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapChannelPortrait:)]];
  78. top += portraitWidth;
  79. top += 20;
  80. self.channelName = [[UILabel alloc] initWithFrame:CGRectMake(40, top, screenWidth - 40 - 40, 18)];
  81. self.channelName.font = [UIFont systemFontOfSize:18];
  82. self.channelName.textAlignment = NSTextAlignmentCenter;
  83. self.channelName.text = self.channelInfo.name;
  84. top += 18;
  85. top += 20;
  86. NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:self.channelInfo.desc];
  87. UIFont *font = [UIFont systemFontOfSize:14];
  88. [attributeString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, self.channelInfo.desc.length)];
  89. NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
  90. CGRect rect = [attributeString boundingRectWithSize:CGSizeMake(screenWidth - 80, CGFLOAT_MAX) options:options context:nil];
  91. self.channelDesc = [[UILabel alloc] initWithFrame:CGRectMake(40, top, screenWidth - 80, rect.size.height)];
  92. self.channelDesc.font = [UIFont systemFontOfSize:14];
  93. self.channelDesc.textAlignment = NSTextAlignmentCenter;
  94. self.channelDesc.text = self.channelInfo.desc;
  95. self.channelDesc.numberOfLines = 0;
  96. [self.channelDesc sizeToFit];
  97. top += rect.size.height;
  98. top += 20;
  99. UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, top)];
  100. [container addSubview:self.channelPortrait];
  101. [container addSubview:self.channelName];
  102. [container addSubview:self.channelDesc];
  103. self.tableView.tableHeaderView = container;
  104. }
  105. [self.view addSubview:self.tableView];
  106. }
  107. - (void)onTapChannelPortrait:(id)sender {
  108. WFCUChannelProfileViewController *pvc = [[WFCUChannelProfileViewController alloc] init];
  109. pvc.channelInfo = self.channelInfo;
  110. [self.navigationController pushViewController:pvc animated:YES];
  111. }
  112. - (void)didReceiveMemoryWarning {
  113. [super didReceiveMemoryWarning];
  114. }
  115. - (BOOL)isChannelOwner {
  116. if (self.conversation.type != Channel_Type) {
  117. return false;
  118. }
  119. return [self.channelInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId];
  120. }
  121. - (BOOL)isGroupOwner {
  122. if (self.conversation.type != Group_Type) {
  123. return false;
  124. }
  125. return [self.groupInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId];
  126. }
  127. - (BOOL)isGroupManager {
  128. if (self.conversation.type != Group_Type) {
  129. return false;
  130. }
  131. if ([self isGroupOwner]) {
  132. return YES;
  133. }
  134. __block BOOL isManager = false;
  135. [self.memberList enumerateObjectsUsingBlock:^(WFCCGroupMember * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  136. if ([obj.memberId isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
  137. if (obj.type != Member_Type_Normal) {
  138. isManager = YES;
  139. }
  140. *stop = YES;
  141. }
  142. }];
  143. return isManager;
  144. }
  145. - (void)onDeleteAndQuit:(id)sender {
  146. if(self.conversation.type == Group_Type) {
  147. if ([self isGroupOwner]) {
  148. __weak typeof(self) ws = self;
  149. [[WFCCIMService sharedWFCIMService] removeConversation:self.conversation clearMessage:YES];
  150. [[WFCCIMService sharedWFCIMService] dismissGroup:self.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
  151. dispatch_async(dispatch_get_main_queue(), ^{
  152. [ws.navigationController popToRootViewControllerAnimated:YES];
  153. });
  154. } error:^(int error_code) {
  155. }];
  156. } else {
  157. __weak typeof(self) ws = self;
  158. [[WFCCIMService sharedWFCIMService] quitGroup:self.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
  159. dispatch_async(dispatch_get_main_queue(), ^{
  160. [ws.navigationController popToRootViewControllerAnimated:YES];
  161. });
  162. } error:^(int error_code) {
  163. }];
  164. }
  165. } else {
  166. if ([self isChannelOwner]) {
  167. __weak typeof(self) ws = self;
  168. [[WFCCIMService sharedWFCIMService] destoryChannel:self.conversation.target success:^{
  169. [[WFCCIMService sharedWFCIMService] removeConversation:ws.conversation clearMessage:YES];
  170. dispatch_async(dispatch_get_main_queue(), ^{
  171. [ws.navigationController popToRootViewControllerAnimated:YES];
  172. });
  173. } error:^(int error_code) {
  174. }];
  175. } else {
  176. __weak typeof(self) ws = self;
  177. [[WFCCIMService sharedWFCIMService] listenChannel:self.conversation.target listen:NO success:^{
  178. [[WFCCIMService sharedWFCIMService] removeConversation:ws.conversation clearMessage:YES];
  179. dispatch_async(dispatch_get_main_queue(), ^{
  180. [ws.navigationController popToRootViewControllerAnimated:YES];
  181. });
  182. } error:^(int error_code) {
  183. }];
  184. }
  185. }
  186. }
  187. - (void)viewWillAppear:(BOOL)animated {
  188. [super viewWillAppear:animated];
  189. if (self.conversation.type == Single_Type) {
  190. self.userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.conversation.target refresh:NO];
  191. self.memberList = @[self.conversation.target];
  192. } else if(self.conversation.type == Group_Type) {
  193. self.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:self.conversation.target refresh:NO];
  194. self.memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.conversation.target forceUpdate:NO];
  195. } else if(self.conversation.type == Channel_Type) {
  196. self.channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:self.conversation.target refresh:NO];
  197. self.memberList = @[self.conversation.target];
  198. }
  199. [self.memberCollectionView reloadData];
  200. [self.tableView reloadData];
  201. }
  202. #pragma mark - UITableViewDataSource<NSObject>
  203. - (BOOL)isGroupNameCell:(NSIndexPath *)indexPath {
  204. if(self.conversation.type == Group_Type && indexPath.section == 0 && indexPath.row == 0) {
  205. return YES;
  206. }
  207. return NO;
  208. }
  209. - (BOOL)isGroupPortraitCell:(NSIndexPath *)indexPath {
  210. if(self.conversation.type == Group_Type && indexPath.section == 0 && indexPath.row == 1) {
  211. return YES;
  212. }
  213. return NO;
  214. }
  215. - (BOOL)isGroupManageCell:(NSIndexPath *)indexPath {
  216. if(self.conversation.type == Group_Type && indexPath.section == 0 && indexPath.row == 2) {
  217. return YES;
  218. }
  219. return NO;
  220. }
  221. - (BOOL)isSearchMessageCell:(NSIndexPath *)indexPath {
  222. if((self.conversation.type == Group_Type && indexPath.section == 1 && indexPath.row == 0)
  223. ||(self.conversation.type == Single_Type && indexPath.section == 0 && indexPath.row == 0)
  224. ||(self.conversation.type == Channel_Type && indexPath.section == 0 && indexPath.row == 0)) {
  225. return YES;
  226. }
  227. return NO;
  228. }
  229. - (BOOL)isMessageSilentCell:(NSIndexPath *)indexPath {
  230. if((self.conversation.type == Group_Type && indexPath.section == 2 && indexPath.row == 0)
  231. ||(self.conversation.type == Single_Type && indexPath.section == 1 && indexPath.row == 0)
  232. ||(self.conversation.type == Channel_Type && indexPath.section == 1 && indexPath.row == 0)) {
  233. return YES;
  234. }
  235. return NO;
  236. }
  237. - (BOOL)isSetTopCell:(NSIndexPath *)indexPath {
  238. if((self.conversation.type == Group_Type && indexPath.section == 2 && indexPath.row == 1)
  239. ||(self.conversation.type == Single_Type && indexPath.section == 1 && indexPath.row == 1)
  240. ||(self.conversation.type == Channel_Type && indexPath.section == 1 && indexPath.row == 1)) {
  241. return YES;
  242. }
  243. return NO;
  244. }
  245. - (BOOL)isSaveGroupCell:(NSIndexPath *)indexPath {
  246. if((self.conversation.type == Group_Type && indexPath.section == 2 && indexPath.row == 2)) {
  247. return YES;
  248. }
  249. return NO;
  250. }
  251. - (BOOL)isGroupNameCardCell:(NSIndexPath *)indexPath {
  252. if((self.conversation.type == Group_Type && indexPath.section == 3 && indexPath.row == 0)) {
  253. return YES;
  254. }
  255. return NO;
  256. }
  257. - (BOOL)isShowNameCardCell:(NSIndexPath *)indexPath {
  258. if((self.conversation.type == Group_Type && indexPath.section == 3 && indexPath.row == 1)) {
  259. return YES;
  260. }
  261. return NO;
  262. }
  263. - (BOOL)isClearMessageCell:(NSIndexPath *)indexPath {
  264. if((self.conversation.type == Group_Type && indexPath.section == 4 && indexPath.row == 0)
  265. || (self.conversation.type == Single_Type && indexPath.section == 2 && indexPath.row == 0)
  266. || (self.conversation.type == Channel_Type && indexPath.section == 2 && indexPath.row == 0)) {
  267. return YES;
  268. }
  269. return NO;
  270. }
  271. - (BOOL)isQuitGroup:(NSIndexPath *)indexPath {
  272. if(self.conversation.type == Group_Type && indexPath.section == 5 && indexPath.row == 0) {
  273. return YES;
  274. }
  275. return NO;
  276. }
  277. - (BOOL)isUnsubscribeChannel:(NSIndexPath *)indexPath {
  278. if (self.conversation.type == Channel_Type && indexPath.section == 3 && indexPath.row == 0) {
  279. return YES;
  280. }
  281. return NO;
  282. }
  283. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  284. if (self.conversation.type == Group_Type) {
  285. if (section == 0) {
  286. if ([self isGroupManager]) {
  287. return 3; //群名称,群头像,群管理
  288. } else {
  289. return 2; //群名称,群头像
  290. }
  291. } else if(section == 1) {
  292. return 1; //查找聊天内容
  293. } else if(section == 2) {
  294. return 3; //消息免打扰,置顶聊天,保存到通讯录
  295. } else if(section == 3) {
  296. return 2; //群昵称,显示群昵称
  297. } else if(section == 4) {
  298. return 1; //清空聊天记录
  299. } else if(section == 5) {
  300. return 1; //删除退群
  301. }
  302. } else if(self.conversation.type == Single_Type) {
  303. if(section == 0) {
  304. return 1; //查找聊天内容
  305. } else if(section == 1) {
  306. return 2; //消息免打扰,置顶聊天
  307. } else if(section == 2) {
  308. return 1; //清空聊天记录
  309. }
  310. } else if(self.conversation.type == Channel_Type) {
  311. if(section == 0) {
  312. return 1; //查找聊天内容
  313. } else if(section == 1) {
  314. return 2; //消息免打扰,置顶聊天
  315. } else if(section == 2) {
  316. return 1; //清空聊天记录
  317. } else if(section == 3) {
  318. return 1; //取消订阅/销毁订阅
  319. }
  320. }
  321. return 0;
  322. }
  323. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  324. return 48;
  325. }
  326. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  327. return [[UIView alloc] initWithFrame:CGRectZero];
  328. }
  329. - (UITableViewCell *)cellOfTable:(UITableView *)tableView WithTitle:(NSString *)title withDetailTitle:(NSString *)detailTitle withDisclosureIndicator:(BOOL)withDI withSwitch:(BOOL)withSwitch withSwitchType:(SwitchType)type {
  330. if (withSwitch) {
  331. WFCUSwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"styleSwitch"];
  332. if(cell == nil) {
  333. cell = [[WFCUSwitchTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"styleSwitch" conversation:self.conversation];
  334. }
  335. cell.detailTextLabel.text = nil;
  336. cell.accessoryType = UITableViewCellAccessoryNone;
  337. cell.accessoryView = nil;
  338. cell.textLabel.text = title;
  339. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  340. cell.type = type;
  341. return cell;
  342. } else {
  343. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"style1Cell"];
  344. if (cell == nil) {
  345. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"style1Cell"];
  346. }
  347. cell.textLabel.text = title;
  348. cell.detailTextLabel.text = detailTitle;
  349. cell.accessoryType = withDI ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
  350. cell.accessoryView = nil;
  351. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  352. return cell;
  353. }
  354. }
  355. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  356. if ([self isGroupNameCell:indexPath]) {
  357. return [self cellOfTable:tableView WithTitle:@"群聊名称" withDetailTitle:self.groupInfo.name withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  358. } else if ([self isGroupPortraitCell:indexPath]) {
  359. UITableViewCell *cell = [self cellOfTable:tableView WithTitle:@"更改头像" withDetailTitle:nil withDisclosureIndicator:NO withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  360. UIImageView *portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 56, 8, 40, 40)];
  361. [portraitView sd_setImageWithURL:[NSURL URLWithString:self.groupInfo.portrait] placeholderImage:[UIImage imageNamed:@"group_default_portrait"]];
  362. cell.accessoryView = portraitView;
  363. return cell;
  364. } else if ([self isGroupManageCell:indexPath]) {
  365. return [self cellOfTable:tableView WithTitle:@"群管理" withDetailTitle:nil withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  366. } else if ([self isSearchMessageCell:indexPath]) {
  367. return [self cellOfTable:tableView WithTitle:@"查找聊天内容" withDetailTitle:nil withDisclosureIndicator:NO withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  368. } else if ([self isMessageSilentCell:indexPath]) {
  369. return [self cellOfTable:tableView WithTitle:@"消息免打扰" withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Silent];
  370. } else if ([self isSetTopCell:indexPath]) {
  371. return [self cellOfTable:tableView WithTitle:@"置顶聊天" withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Top];
  372. } else if ([self isSaveGroupCell:indexPath]) {
  373. return [self cellOfTable:tableView WithTitle:@"保存到通讯录" withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Save_To_Contact];
  374. } else if ([self isGroupNameCardCell:indexPath]) {
  375. WFCCGroupMember *groupMember = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
  376. if (groupMember.alias.length) {
  377. return [self cellOfTable:tableView WithTitle:@"我在本群的昵称" withDetailTitle:groupMember.alias withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  378. } else {
  379. return [self cellOfTable:tableView WithTitle:@"我在本群的昵称" withDetailTitle:@"未设置" withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  380. }
  381. } else if([self isShowNameCardCell:indexPath]) {
  382. return [self cellOfTable:tableView WithTitle:@"显示群成员昵称" withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Show_Alias];
  383. } else if ([self isClearMessageCell:indexPath]) {
  384. return [self cellOfTable:tableView WithTitle:@"清空聊天记录" withDetailTitle:nil withDisclosureIndicator:NO withSwitch:NO withSwitchType:SwitchType_Conversation_None];
  385. } else if([self isQuitGroup:indexPath]) {
  386. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
  387. if (cell == nil) {
  388. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
  389. for (UIView *subView in cell.subviews) {
  390. [subView removeFromSuperview];
  391. }
  392. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 4, self.view.frame.size.width - 40, 40)];
  393. if ([self isGroupOwner]) {
  394. [btn setTitle:@"解散群组" forState:UIControlStateNormal];
  395. } else {
  396. [btn setTitle:@"退出群组" forState:UIControlStateNormal];
  397. }
  398. btn.layer.cornerRadius = 5.f;
  399. btn.layer.masksToBounds = YES;
  400. btn.backgroundColor = [UIColor redColor];
  401. [btn addTarget:self action:@selector(onDeleteAndQuit:) forControlEvents:UIControlEventTouchUpInside];
  402. [cell addSubview:btn];
  403. }
  404. return cell;
  405. } else if([self isUnsubscribeChannel:indexPath]) {
  406. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
  407. if (cell == nil) {
  408. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
  409. for (UIView *subView in cell.subviews) {
  410. [subView removeFromSuperview];
  411. }
  412. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 4, self.view.frame.size.width - 40, 40)];
  413. if ([self isChannelOwner]) {
  414. [btn setTitle:@"销毁频道" forState:UIControlStateNormal];
  415. } else {
  416. [btn setTitle:@"取消订阅频道" forState:UIControlStateNormal];
  417. }
  418. btn.layer.cornerRadius = 5.f;
  419. btn.layer.masksToBounds = YES;
  420. btn.backgroundColor = [UIColor redColor];
  421. [btn addTarget:self action:@selector(onDeleteAndQuit:) forControlEvents:UIControlEventTouchUpInside];
  422. [cell addSubview:btn];
  423. }
  424. return cell;
  425. }
  426. return nil;
  427. }
  428. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  429. if (self.conversation.type == Single_Type) {
  430. return 3;
  431. } else if(self.conversation.type == Group_Type) {
  432. return 6;
  433. } else if(self.conversation.type == Channel_Type) {
  434. return 4;
  435. }
  436. return 0;
  437. }
  438. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  439. __weak typeof(self)weakSelf = self;
  440. if ([self isGroupNameCell:indexPath]) {
  441. WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
  442. gmvc.defaultValue = self.groupInfo.name;
  443. gmvc.titleText = @"修改群名称";
  444. gmvc.canEmpty = NO;
  445. gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
  446. [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_Name newValue:newValue notifyLines:@[@(0)] notifyContent:nil success:^{
  447. result(YES);
  448. } error:^(int error_code) {
  449. result(NO);
  450. }];
  451. };
  452. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
  453. [self.navigationController presentViewController:nav animated:YES completion:nil];
  454. } else if ([self isGroupPortraitCell:indexPath]) {
  455. WFCUCreateGroupViewController *vc = [[WFCUCreateGroupViewController alloc] init];
  456. vc.isModifyPortrait = YES;
  457. vc.groupId = self.groupInfo.target;
  458. vc.memberIds = [[NSMutableArray alloc] init];
  459. for (WFCCGroupMember *member in self.memberList) {
  460. [vc.memberIds addObject:member.memberId];
  461. }
  462. [self.navigationController pushViewController:vc animated:YES];
  463. } else if ([self isGroupManageCell:indexPath]) {
  464. } else if ([self isSearchMessageCell:indexPath]) {
  465. WFCUConversationSearchTableViewController *mvc = [[WFCUConversationSearchTableViewController alloc] init];
  466. mvc.conversation = self.conversation;
  467. mvc.hidesBottomBarWhenPushed = YES;
  468. [self.navigationController pushViewController:mvc animated:YES];
  469. } else if ([self isMessageSilentCell:indexPath]) {
  470. } else if ([self isSetTopCell:indexPath]) {
  471. } else if ([self isSaveGroupCell:indexPath]) {
  472. } else if ([self isGroupNameCardCell:indexPath]) {
  473. WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
  474. WFCCGroupMember *groupMember = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
  475. gmvc.defaultValue = groupMember.alias;
  476. gmvc.titleText = @"修改我在群中的名片";
  477. gmvc.canEmpty = NO;
  478. gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
  479. [[WFCCIMService sharedWFCIMService] modifyGroupAlias:self.conversation.target alias:newValue notifyLines:@[@(0)] notifyContent:nil success:^{
  480. result(YES);
  481. } error:^(int error_code) {
  482. result(NO);
  483. }];
  484. };
  485. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
  486. [self.navigationController presentViewController:nav animated:YES completion:nil];
  487. } else if([self isShowNameCardCell:indexPath]) {
  488. } else if ([self isClearMessageCell:indexPath]) {
  489. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"确认删除" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  490. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  491. }];
  492. UIAlertAction *actionDelete = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  493. [[WFCCIMService sharedWFCIMService] clearMessages:self.conversation];
  494. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:weakSelf.view animated:NO];
  495. hud.label.text = @"删除成功";
  496. hud.mode = MBProgressHUDModeText;
  497. hud.removeFromSuperViewOnHide = YES;
  498. [hud hideAnimated:NO afterDelay:1.5];
  499. [[NSNotificationCenter defaultCenter] postNotificationName:kMessageListChanged object:weakSelf.conversation];
  500. }];
  501. //把action添加到actionSheet里
  502. [actionSheet addAction:actionDelete];
  503. [actionSheet addAction:actionCancel];
  504. //相当于之前的[actionSheet show];
  505. dispatch_async(dispatch_get_main_queue(), ^{
  506. [self presentViewController:actionSheet animated:YES completion:nil];
  507. });
  508. }
  509. }
  510. #pragma mark - UICollectionViewDataSource
  511. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  512. if (self.conversation.type == Group_Type) {
  513. if([self isGroupManager]) {
  514. return self.memberList.count + 2;
  515. } else {
  516. return self.memberList.count + 1;
  517. }
  518. } else if(self.conversation.type == Single_Type) {
  519. return self.memberList.count + 1;
  520. } else if(self.conversation.type == Channel_Type) {
  521. return self.memberList.count;
  522. }
  523. return 0;
  524. }
  525. // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
  526. - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  527. WFCUConversationSettingMemberCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:Group_Member_Cell_Reuese_ID forIndexPath:indexPath];
  528. if (indexPath.row < self.memberList.count) {
  529. WFCCGroupMember *member = self.memberList[indexPath.row];
  530. [cell setModel:member withType:self.conversation.type];
  531. } else {
  532. if (indexPath.row == self.memberList.count) {
  533. [cell.headerImageView setImage:[UIImage imageNamed:@"addmember"]];
  534. cell.nameLabel.text = nil;
  535. cell.nameLabel.hidden = YES;
  536. } else {
  537. [cell.headerImageView setImage:[UIImage imageNamed:@"removemember"]];
  538. cell.nameLabel.text = nil;
  539. cell.nameLabel.hidden = YES;
  540. }
  541. }
  542. return cell;
  543. }
  544. #pragma mark - UICollectionViewDelegate
  545. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  546. __weak typeof(self)ws = self;
  547. if (indexPath.row == self.memberList.count) {
  548. WFCUContactListViewController *pvc = [[WFCUContactListViewController alloc] init];
  549. pvc.selectContact = YES;
  550. pvc.multiSelect = YES;
  551. NSMutableArray *disabledUser = [[NSMutableArray alloc] init];
  552. if(self.conversation.type == Group_Type) {
  553. for (WFCCGroupMember *member in self.memberList) {
  554. [disabledUser addObject:member.memberId];
  555. }
  556. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  557. [[WFCCIMService sharedWFCIMService] addMembers:contacts toGroup:self.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
  558. [[WFCCIMService sharedWFCIMService] getGroupMembers:ws.conversation.target forceUpdate:YES];
  559. } error:^(int error_code) {
  560. }];
  561. };
  562. pvc.disableUsersSelected = YES;
  563. } else {
  564. [disabledUser addObject:self.conversation.target];
  565. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  566. WFCUCreateGroupViewController *vc = [[WFCUCreateGroupViewController alloc] init];
  567. vc.memberIds = [contacts mutableCopy];
  568. if(![vc.memberIds containsObject:self.conversation.target]) {
  569. [vc.memberIds insertObject:self.conversation.target atIndex:0];
  570. }
  571. vc.hidesBottomBarWhenPushed = YES;
  572. UINavigationController *nav = self.navigationController;
  573. [self.navigationController popToRootViewControllerAnimated:NO];
  574. [nav pushViewController:vc animated:YES];
  575. };
  576. pvc.disableUsersSelected = YES;
  577. }
  578. pvc.disableUsers = disabledUser;
  579. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:pvc];
  580. [self.navigationController presentViewController:navi animated:YES completion:nil];
  581. } else if(indexPath.row == self.memberList.count + 1) {
  582. WFCUContactListViewController *pvc = [[WFCUContactListViewController alloc] init];
  583. pvc.selectContact = YES;
  584. pvc.multiSelect = YES;
  585. pvc.selectResult = ^(NSArray<NSString *> *contacts) {
  586. [[WFCCIMService sharedWFCIMService] kickoffMembers:contacts fromGroup:self.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
  587. [[WFCCIMService sharedWFCIMService] getGroupMembers:ws.conversation.target forceUpdate:YES];
  588. dispatch_async(dispatch_get_main_queue(), ^{
  589. NSMutableArray *tmpArray = [self.memberList mutableCopy];
  590. NSMutableArray *removeArray = [[NSMutableArray alloc] init];
  591. [tmpArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  592. WFCCGroupMember *member = obj;
  593. if([contacts containsObject:member.memberId]) {
  594. [removeArray addObject:member];
  595. }
  596. }];
  597. [tmpArray removeObjectsInArray:removeArray];
  598. self.memberList = [tmpArray mutableCopy];
  599. [self.memberCollectionView reloadData];
  600. });
  601. } error:^(int error_code) {
  602. }];
  603. };
  604. NSMutableArray *candidateUsers = [[NSMutableArray alloc] init];
  605. for (WFCCGroupMember *member in self.memberList) {
  606. [candidateUsers addObject:member.memberId];
  607. }
  608. pvc.candidateUsers = candidateUsers;
  609. pvc.disableUsers = @[[WFCCNetworkService sharedInstance].userId];
  610. UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:pvc];
  611. [self.navigationController presentViewController:navi animated:YES completion:nil];
  612. } else {
  613. NSString *userId;
  614. if(self.conversation.type == Group_Type) {
  615. WFCCGroupMember *member = [self.memberList objectAtIndex:indexPath.row];
  616. userId = member.memberId;
  617. } else {
  618. userId = self.conversation.target;
  619. }
  620. if ([[WFCCNetworkService sharedInstance].userId isEqualToString:userId]) {
  621. WFCUMyProfileTableViewController *vc = [[WFCUMyProfileTableViewController alloc] init];
  622. vc.hidesBottomBarWhenPushed = YES;
  623. [self.navigationController pushViewController:vc animated:YES];
  624. } else {
  625. WFCUProfileTableViewController *vc = [[WFCUProfileTableViewController alloc] init];
  626. vc.userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:userId refresh:NO];
  627. vc.hidesBottomBarWhenPushed = YES;
  628. [self.navigationController pushViewController:vc animated:YES];
  629. }
  630. }
  631. }
  632. @end