123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714 |
- //
- // ConversationSettingViewController.m
- // WFChat UIKit
- //
- // Created by WF Chat on 2017/11/2.
- // Copyright © 2017年 WildFireChat. All rights reserved.
- //
- #import "WFCUConversationSettingViewController.h"
- #import "SDWebImage.h"
- #import <WFChatClient/WFCChatClient.h>
- #import "WFCUConversationSettingMemberCollectionViewLayout.h"
- #import "WFCUConversationSettingMemberCell.h"
- #import "WFCUContactListViewController.h"
- #import "WFCUMessageListViewController.h"
- #import "WFCUGeneralModifyViewController.h"
- #import "WFCUSwitchTableViewCell.h"
- #import "WFCUCreateGroupViewController.h"
- #import "WFCUProfileTableViewController.h"
- #import "WFCUCreateGroupViewController.h"
- #import "MBProgressHUD.h"
- #import "WFCUMyProfileTableViewController.h"
- #import "WFCUConversationSearchTableViewController.h"
- #import "WFCUChannelProfileViewController.h"
- @interface WFCUConversationSettingViewController () <UITableViewDataSource, UITableViewDelegate, UICollectionViewDelegate, UICollectionViewDataSource>
- @property (nonatomic, strong)UICollectionView *memberCollectionView;
- @property (nonatomic, strong)WFCUConversationSettingMemberCollectionViewLayout *memberCollectionViewLayout;
- @property (nonatomic, strong)UITableView *tableView;
- @property (nonatomic, strong)WFCCGroupInfo *groupInfo;
- @property (nonatomic, strong)WFCCUserInfo *userInfo;
- @property (nonatomic, strong)WFCCChannelInfo *channelInfo;
- @property (nonatomic, strong)NSArray<WFCCGroupMember *> *memberList;
- @property (nonatomic, strong)UIImageView *channelPortrait;
- @property (nonatomic, strong)UILabel *channelName;
- @property (nonatomic, strong)UILabel *channelDesc;
- @end
- #define Group_Member_Cell_Reuese_ID @"Group_Member_Cell_Reuese_ID"
- @implementation WFCUConversationSettingViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- if (self.conversation.type == Single_Type) {
- self.userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.conversation.target refresh:YES];
- self.memberList = @[self.conversation.target];
- } else if(self.conversation.type == Group_Type){
- self.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:self.conversation.target refresh:YES];
- self.memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.conversation.target forceUpdate:YES];
- } else if(self.conversation.type == Channel_Type) {
- self.channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:self.conversation.target refresh:YES];
- self.memberList = @[self.conversation.target];
- }
-
- self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
-
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
-
- if (self.conversation.type == Single_Type || self.conversation.type == Group_Type) {
- self.memberCollectionViewLayout = [[WFCUConversationSettingMemberCollectionViewLayout alloc] initWithItemMargin:5];
- int memberCollectionCount = 0;
- if (self.conversation.type == Single_Type) {
- memberCollectionCount = 2;
- } else if(self.conversation.type == Group_Type) {
- memberCollectionCount = [self isGroupManager] ? (int)self.memberList.count + 2 : (int)self.memberList.count + 1;
- } else if(self.conversation.type == Channel_Type) {
- memberCollectionCount = 1;
- }
-
- self.memberCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, [self.memberCollectionViewLayout getHeigthOfItemCount:memberCollectionCount]) collectionViewLayout:self.memberCollectionViewLayout];
- self.memberCollectionView.delegate = self;
- self.memberCollectionView.dataSource = self;
-
-
-
- self.memberCollectionView.backgroundColor = [UIColor whiteColor];
-
- [self.memberCollectionView registerClass:[WFCUConversationSettingMemberCell class] forCellWithReuseIdentifier:Group_Member_Cell_Reuese_ID];
-
- self.tableView.tableHeaderView = self.memberCollectionView;
- } else if(self.conversation.type == Channel_Type) {
- CGFloat portraitWidth = 80;
- CGFloat top = 40;
- CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
- self.channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:self.conversation.target refresh:YES];
-
- self.channelPortrait = [[UIImageView alloc] initWithFrame:CGRectMake((screenWidth - portraitWidth)/2, top, portraitWidth, portraitWidth)];
- [self.channelPortrait sd_setImageWithURL:[NSURL URLWithString:self.channelInfo.portrait] placeholderImage:[UIImage imageNamed:@"channel_default_portrait"]];
- self.channelPortrait.userInteractionEnabled = YES;
- [self.channelPortrait addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapChannelPortrait:)]];
-
- top += portraitWidth;
- top += 20;
- self.channelName = [[UILabel alloc] initWithFrame:CGRectMake(40, top, screenWidth - 40 - 40, 18)];
- self.channelName.font = [UIFont systemFontOfSize:18];
- self.channelName.textAlignment = NSTextAlignmentCenter;
- self.channelName.text = self.channelInfo.name;
-
- top += 18;
- top += 20;
-
- NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:self.channelInfo.desc];
- UIFont *font = [UIFont systemFontOfSize:14];
- [attributeString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, self.channelInfo.desc.length)];
- NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading;
- CGRect rect = [attributeString boundingRectWithSize:CGSizeMake(screenWidth - 80, CGFLOAT_MAX) options:options context:nil];
-
- self.channelDesc = [[UILabel alloc] initWithFrame:CGRectMake(40, top, screenWidth - 80, rect.size.height)];
- self.channelDesc.font = [UIFont systemFontOfSize:14];
- self.channelDesc.textAlignment = NSTextAlignmentCenter;
- self.channelDesc.text = self.channelInfo.desc;
- self.channelDesc.numberOfLines = 0;
- [self.channelDesc sizeToFit];
-
- top += rect.size.height;
- top += 20;
- UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, top)];
- [container addSubview:self.channelPortrait];
- [container addSubview:self.channelName];
- [container addSubview:self.channelDesc];
- self.tableView.tableHeaderView = container;
- }
-
- [self.view addSubview:self.tableView];
- }
- - (void)onTapChannelPortrait:(id)sender {
- WFCUChannelProfileViewController *pvc = [[WFCUChannelProfileViewController alloc] init];
- pvc.channelInfo = self.channelInfo;
- [self.navigationController pushViewController:pvc animated:YES];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- - (BOOL)isChannelOwner {
- if (self.conversation.type != Channel_Type) {
- return false;
- }
-
- return [self.channelInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId];
- }
- - (BOOL)isGroupOwner {
- if (self.conversation.type != Group_Type) {
- return false;
- }
-
- return [self.groupInfo.owner isEqualToString:[WFCCNetworkService sharedInstance].userId];
- }
- - (BOOL)isGroupManager {
- if (self.conversation.type != Group_Type) {
- return false;
- }
- if ([self isGroupOwner]) {
- return YES;
- }
- __block BOOL isManager = false;
- [self.memberList enumerateObjectsUsingBlock:^(WFCCGroupMember * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if ([obj.memberId isEqualToString:[WFCCNetworkService sharedInstance].userId]) {
- if (obj.type != Member_Type_Normal) {
- isManager = YES;
- }
- *stop = YES;
- }
- }];
- return isManager;
- }
- - (void)onDeleteAndQuit:(id)sender {
- if(self.conversation.type == Group_Type) {
- if ([self isGroupOwner]) {
- __weak typeof(self) ws = self;
- [[WFCCIMService sharedWFCIMService] removeConversation:self.conversation clearMessage:YES];
- [[WFCCIMService sharedWFCIMService] dismissGroup:self.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
- dispatch_async(dispatch_get_main_queue(), ^{
- [ws.navigationController popToRootViewControllerAnimated:YES];
- });
- } error:^(int error_code) {
-
- }];
- } else {
- __weak typeof(self) ws = self;
- [[WFCCIMService sharedWFCIMService] quitGroup:self.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
- dispatch_async(dispatch_get_main_queue(), ^{
- [ws.navigationController popToRootViewControllerAnimated:YES];
- });
- } error:^(int error_code) {
-
- }];
- }
- } else {
- if ([self isChannelOwner]) {
- __weak typeof(self) ws = self;
- [[WFCCIMService sharedWFCIMService] destoryChannel:self.conversation.target success:^{
- [[WFCCIMService sharedWFCIMService] removeConversation:ws.conversation clearMessage:YES];
- dispatch_async(dispatch_get_main_queue(), ^{
- [ws.navigationController popToRootViewControllerAnimated:YES];
- });
- } error:^(int error_code) {
-
- }];
- } else {
- __weak typeof(self) ws = self;
- [[WFCCIMService sharedWFCIMService] listenChannel:self.conversation.target listen:NO success:^{
- [[WFCCIMService sharedWFCIMService] removeConversation:ws.conversation clearMessage:YES];
- dispatch_async(dispatch_get_main_queue(), ^{
- [ws.navigationController popToRootViewControllerAnimated:YES];
- });
- } error:^(int error_code) {
-
- }];
- }
- }
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- if (self.conversation.type == Single_Type) {
- self.userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.conversation.target refresh:NO];
- self.memberList = @[self.conversation.target];
- } else if(self.conversation.type == Group_Type) {
- self.groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:self.conversation.target refresh:NO];
- self.memberList = [[WFCCIMService sharedWFCIMService] getGroupMembers:self.conversation.target forceUpdate:NO];
- } else if(self.conversation.type == Channel_Type) {
- self.channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:self.conversation.target refresh:NO];
- self.memberList = @[self.conversation.target];
- }
-
- [self.memberCollectionView reloadData];
- [self.tableView reloadData];
- }
- #pragma mark - UITableViewDataSource<NSObject>
- - (BOOL)isGroupNameCell:(NSIndexPath *)indexPath {
- if(self.conversation.type == Group_Type && indexPath.section == 0 && indexPath.row == 0) {
- return YES;
- }
- return NO;
- }
- - (BOOL)isGroupPortraitCell:(NSIndexPath *)indexPath {
- if(self.conversation.type == Group_Type && indexPath.section == 0 && indexPath.row == 1) {
- return YES;
- }
- return NO;
- }
- - (BOOL)isGroupManageCell:(NSIndexPath *)indexPath {
- if(self.conversation.type == Group_Type && indexPath.section == 0 && indexPath.row == 2) {
- return YES;
- }
- return NO;
- }
- - (BOOL)isSearchMessageCell:(NSIndexPath *)indexPath {
- if((self.conversation.type == Group_Type && indexPath.section == 1 && indexPath.row == 0)
- ||(self.conversation.type == Single_Type && indexPath.section == 0 && indexPath.row == 0)
- ||(self.conversation.type == Channel_Type && indexPath.section == 0 && indexPath.row == 0)) {
- return YES;
- }
- return NO;
- }
- - (BOOL)isMessageSilentCell:(NSIndexPath *)indexPath {
- if((self.conversation.type == Group_Type && indexPath.section == 2 && indexPath.row == 0)
- ||(self.conversation.type == Single_Type && indexPath.section == 1 && indexPath.row == 0)
- ||(self.conversation.type == Channel_Type && indexPath.section == 1 && indexPath.row == 0)) {
- return YES;
- }
- return NO;
- }
- - (BOOL)isSetTopCell:(NSIndexPath *)indexPath {
- if((self.conversation.type == Group_Type && indexPath.section == 2 && indexPath.row == 1)
- ||(self.conversation.type == Single_Type && indexPath.section == 1 && indexPath.row == 1)
- ||(self.conversation.type == Channel_Type && indexPath.section == 1 && indexPath.row == 1)) {
- return YES;
- }
- return NO;
- }
- - (BOOL)isSaveGroupCell:(NSIndexPath *)indexPath {
- if((self.conversation.type == Group_Type && indexPath.section == 2 && indexPath.row == 2)) {
- return YES;
- }
- return NO;
- }
- - (BOOL)isGroupNameCardCell:(NSIndexPath *)indexPath {
- if((self.conversation.type == Group_Type && indexPath.section == 3 && indexPath.row == 0)) {
- return YES;
- }
- return NO;
- }
- - (BOOL)isShowNameCardCell:(NSIndexPath *)indexPath {
- if((self.conversation.type == Group_Type && indexPath.section == 3 && indexPath.row == 1)) {
- return YES;
- }
- return NO;
- }
- - (BOOL)isClearMessageCell:(NSIndexPath *)indexPath {
- if((self.conversation.type == Group_Type && indexPath.section == 4 && indexPath.row == 0)
- || (self.conversation.type == Single_Type && indexPath.section == 2 && indexPath.row == 0)
- || (self.conversation.type == Channel_Type && indexPath.section == 2 && indexPath.row == 0)) {
- return YES;
- }
- return NO;
- }
- - (BOOL)isQuitGroup:(NSIndexPath *)indexPath {
- if(self.conversation.type == Group_Type && indexPath.section == 5 && indexPath.row == 0) {
- return YES;
- }
- return NO;
- }
- - (BOOL)isUnsubscribeChannel:(NSIndexPath *)indexPath {
- if (self.conversation.type == Channel_Type && indexPath.section == 3 && indexPath.row == 0) {
- return YES;
- }
- return NO;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if (self.conversation.type == Group_Type) {
- if (section == 0) {
- if ([self isGroupManager]) {
- return 3; //群名称,群头像,群管理
- } else {
- return 2; //群名称,群头像
- }
-
- } else if(section == 1) {
- return 1; //查找聊天内容
- } else if(section == 2) {
- return 3; //消息免打扰,置顶聊天,保存到通讯录
- } else if(section == 3) {
- return 2; //群昵称,显示群昵称
- } else if(section == 4) {
- return 1; //清空聊天记录
- } else if(section == 5) {
- return 1; //删除退群
- }
- } else if(self.conversation.type == Single_Type) {
- if(section == 0) {
- return 1; //查找聊天内容
- } else if(section == 1) {
- return 2; //消息免打扰,置顶聊天
- } else if(section == 2) {
- return 1; //清空聊天记录
- }
- } else if(self.conversation.type == Channel_Type) {
- if(section == 0) {
- return 1; //查找聊天内容
- } else if(section == 1) {
- return 2; //消息免打扰,置顶聊天
- } else if(section == 2) {
- return 1; //清空聊天记录
- } else if(section == 3) {
- return 1; //取消订阅/销毁订阅
- }
- }
-
- return 0;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 48;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- return [[UIView alloc] initWithFrame:CGRectZero];
- }
- - (UITableViewCell *)cellOfTable:(UITableView *)tableView WithTitle:(NSString *)title withDetailTitle:(NSString *)detailTitle withDisclosureIndicator:(BOOL)withDI withSwitch:(BOOL)withSwitch withSwitchType:(SwitchType)type {
- if (withSwitch) {
- WFCUSwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"styleSwitch"];
- if(cell == nil) {
- cell = [[WFCUSwitchTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"styleSwitch" conversation:self.conversation];
- }
- cell.detailTextLabel.text = nil;
- cell.accessoryType = UITableViewCellAccessoryNone;
- cell.accessoryView = nil;
- cell.textLabel.text = title;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- cell.type = type;
-
- return cell;
- } else {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"style1Cell"];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"style1Cell"];
- }
- cell.textLabel.text = title;
- cell.detailTextLabel.text = detailTitle;
- cell.accessoryType = withDI ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
- cell.accessoryView = nil;
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
-
- return cell;
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- if ([self isGroupNameCell:indexPath]) {
- return [self cellOfTable:tableView WithTitle:@"群聊名称" withDetailTitle:self.groupInfo.name withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
- } else if ([self isGroupPortraitCell:indexPath]) {
- UITableViewCell *cell = [self cellOfTable:tableView WithTitle:@"更改头像" withDetailTitle:nil withDisclosureIndicator:NO withSwitch:NO withSwitchType:SwitchType_Conversation_None];
- UIImageView *portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 56, 8, 40, 40)];
- [portraitView sd_setImageWithURL:[NSURL URLWithString:self.groupInfo.portrait] placeholderImage:[UIImage imageNamed:@"group_default_portrait"]];
- cell.accessoryView = portraitView;
- return cell;
- } else if ([self isGroupManageCell:indexPath]) {
- return [self cellOfTable:tableView WithTitle:@"群管理" withDetailTitle:nil withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
- } else if ([self isSearchMessageCell:indexPath]) {
- return [self cellOfTable:tableView WithTitle:@"查找聊天内容" withDetailTitle:nil withDisclosureIndicator:NO withSwitch:NO withSwitchType:SwitchType_Conversation_None];
- } else if ([self isMessageSilentCell:indexPath]) {
- return [self cellOfTable:tableView WithTitle:@"消息免打扰" withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Silent];
- } else if ([self isSetTopCell:indexPath]) {
- return [self cellOfTable:tableView WithTitle:@"置顶聊天" withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Top];
- } else if ([self isSaveGroupCell:indexPath]) {
- return [self cellOfTable:tableView WithTitle:@"保存到通讯录" withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Save_To_Contact];
- } else if ([self isGroupNameCardCell:indexPath]) {
- WFCCGroupMember *groupMember = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
- if (groupMember.alias.length) {
- return [self cellOfTable:tableView WithTitle:@"我在本群的昵称" withDetailTitle:groupMember.alias withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
- } else {
- return [self cellOfTable:tableView WithTitle:@"我在本群的昵称" withDetailTitle:@"未设置" withDisclosureIndicator:YES withSwitch:NO withSwitchType:SwitchType_Conversation_None];
- }
-
- } else if([self isShowNameCardCell:indexPath]) {
- return [self cellOfTable:tableView WithTitle:@"显示群成员昵称" withDetailTitle:nil withDisclosureIndicator:NO withSwitch:YES withSwitchType:SwitchType_Conversation_Show_Alias];
- } else if ([self isClearMessageCell:indexPath]) {
- return [self cellOfTable:tableView WithTitle:@"清空聊天记录" withDetailTitle:nil withDisclosureIndicator:NO withSwitch:NO withSwitchType:SwitchType_Conversation_None];
- } else if([self isQuitGroup:indexPath]) {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
- for (UIView *subView in cell.subviews) {
- [subView removeFromSuperview];
- }
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 4, self.view.frame.size.width - 40, 40)];
- if ([self isGroupOwner]) {
- [btn setTitle:@"解散群组" forState:UIControlStateNormal];
- } else {
- [btn setTitle:@"退出群组" forState:UIControlStateNormal];
- }
-
- btn.layer.cornerRadius = 5.f;
- btn.layer.masksToBounds = YES;
-
- btn.backgroundColor = [UIColor redColor];
- [btn addTarget:self action:@selector(onDeleteAndQuit:) forControlEvents:UIControlEventTouchUpInside];
- [cell addSubview:btn];
- }
- return cell;
- } else if([self isUnsubscribeChannel:indexPath]) {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"buttonCell"];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"buttonCell"];
- for (UIView *subView in cell.subviews) {
- [subView removeFromSuperview];
- }
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 4, self.view.frame.size.width - 40, 40)];
- if ([self isChannelOwner]) {
- [btn setTitle:@"销毁频道" forState:UIControlStateNormal];
- } else {
- [btn setTitle:@"取消订阅频道" forState:UIControlStateNormal];
- }
-
- btn.layer.cornerRadius = 5.f;
- btn.layer.masksToBounds = YES;
-
- btn.backgroundColor = [UIColor redColor];
- [btn addTarget:self action:@selector(onDeleteAndQuit:) forControlEvents:UIControlEventTouchUpInside];
- [cell addSubview:btn];
- }
- return cell;
- }
- return nil;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- if (self.conversation.type == Single_Type) {
- return 3;
- } else if(self.conversation.type == Group_Type) {
- return 6;
- } else if(self.conversation.type == Channel_Type) {
- return 4;
- }
- return 0;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- __weak typeof(self)weakSelf = self;
- if ([self isGroupNameCell:indexPath]) {
- WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
- gmvc.defaultValue = self.groupInfo.name;
- gmvc.titleText = @"修改群名称";
- gmvc.canEmpty = NO;
- gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
- [[WFCCIMService sharedWFCIMService] modifyGroupInfo:self.groupInfo.target type:Modify_Group_Name newValue:newValue notifyLines:@[@(0)] notifyContent:nil success:^{
- result(YES);
- } error:^(int error_code) {
- result(NO);
- }];
- };
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
- [self.navigationController presentViewController:nav animated:YES completion:nil];
- } else if ([self isGroupPortraitCell:indexPath]) {
- WFCUCreateGroupViewController *vc = [[WFCUCreateGroupViewController alloc] init];
- vc.isModifyPortrait = YES;
- vc.groupId = self.groupInfo.target;
- vc.memberIds = [[NSMutableArray alloc] init];
- for (WFCCGroupMember *member in self.memberList) {
- [vc.memberIds addObject:member.memberId];
- }
-
- [self.navigationController pushViewController:vc animated:YES];
- } else if ([self isGroupManageCell:indexPath]) {
-
- } else if ([self isSearchMessageCell:indexPath]) {
- WFCUConversationSearchTableViewController *mvc = [[WFCUConversationSearchTableViewController alloc] init];
- mvc.conversation = self.conversation;
- mvc.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:mvc animated:YES];
- } else if ([self isMessageSilentCell:indexPath]) {
-
- } else if ([self isSetTopCell:indexPath]) {
-
- } else if ([self isSaveGroupCell:indexPath]) {
-
- } else if ([self isGroupNameCardCell:indexPath]) {
- WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
- WFCCGroupMember *groupMember = [[WFCCIMService sharedWFCIMService] getGroupMember:self.conversation.target memberId:[WFCCNetworkService sharedInstance].userId];
- gmvc.defaultValue = groupMember.alias;
- gmvc.titleText = @"修改我在群中的名片";
- gmvc.canEmpty = NO;
- gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
- [[WFCCIMService sharedWFCIMService] modifyGroupAlias:self.conversation.target alias:newValue notifyLines:@[@(0)] notifyContent:nil success:^{
- result(YES);
- } error:^(int error_code) {
- result(NO);
- }];
- };
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
- [self.navigationController presentViewController:nav animated:YES completion:nil];
- } else if([self isShowNameCardCell:indexPath]) {
-
- } else if ([self isClearMessageCell:indexPath]) {
- UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"确认删除" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
- UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- }];
- UIAlertAction *actionDelete = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
- [[WFCCIMService sharedWFCIMService] clearMessages:self.conversation];
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:weakSelf.view animated:NO];
- hud.label.text = @"删除成功";
- hud.mode = MBProgressHUDModeText;
- hud.removeFromSuperViewOnHide = YES;
- [hud hideAnimated:NO afterDelay:1.5];
-
- [[NSNotificationCenter defaultCenter] postNotificationName:kMessageListChanged object:weakSelf.conversation];
- }];
-
- //把action添加到actionSheet里
- [actionSheet addAction:actionDelete];
- [actionSheet addAction:actionCancel];
-
- //相当于之前的[actionSheet show];
- dispatch_async(dispatch_get_main_queue(), ^{
- [self presentViewController:actionSheet animated:YES completion:nil];
- });
- }
- }
- #pragma mark - UICollectionViewDataSource
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- if (self.conversation.type == Group_Type) {
- if([self isGroupManager]) {
- return self.memberList.count + 2;
- } else {
- return self.memberList.count + 1;
- }
- } else if(self.conversation.type == Single_Type) {
- return self.memberList.count + 1;
- } else if(self.conversation.type == Channel_Type) {
- return self.memberList.count;
- }
- return 0;
- }
- // The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- WFCUConversationSettingMemberCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:Group_Member_Cell_Reuese_ID forIndexPath:indexPath];
- if (indexPath.row < self.memberList.count) {
- WFCCGroupMember *member = self.memberList[indexPath.row];
- [cell setModel:member withType:self.conversation.type];
- } else {
- if (indexPath.row == self.memberList.count) {
- [cell.headerImageView setImage:[UIImage imageNamed:@"addmember"]];
- cell.nameLabel.text = nil;
- cell.nameLabel.hidden = YES;
- } else {
- [cell.headerImageView setImage:[UIImage imageNamed:@"removemember"]];
- cell.nameLabel.text = nil;
- cell.nameLabel.hidden = YES;
- }
- }
- return cell;
- }
- #pragma mark - UICollectionViewDelegate
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- __weak typeof(self)ws = self;
- if (indexPath.row == self.memberList.count) {
- WFCUContactListViewController *pvc = [[WFCUContactListViewController alloc] init];
- pvc.selectContact = YES;
- pvc.multiSelect = YES;
- NSMutableArray *disabledUser = [[NSMutableArray alloc] init];
- if(self.conversation.type == Group_Type) {
- for (WFCCGroupMember *member in self.memberList) {
- [disabledUser addObject:member.memberId];
- }
- pvc.selectResult = ^(NSArray<NSString *> *contacts) {
- [[WFCCIMService sharedWFCIMService] addMembers:contacts toGroup:self.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
- [[WFCCIMService sharedWFCIMService] getGroupMembers:ws.conversation.target forceUpdate:YES];
- } error:^(int error_code) {
-
- }];
- };
- pvc.disableUsersSelected = YES;
- } else {
- [disabledUser addObject:self.conversation.target];
- pvc.selectResult = ^(NSArray<NSString *> *contacts) {
- WFCUCreateGroupViewController *vc = [[WFCUCreateGroupViewController alloc] init];
- vc.memberIds = [contacts mutableCopy];
- if(![vc.memberIds containsObject:self.conversation.target]) {
- [vc.memberIds insertObject:self.conversation.target atIndex:0];
- }
- vc.hidesBottomBarWhenPushed = YES;
- UINavigationController *nav = self.navigationController;
- [self.navigationController popToRootViewControllerAnimated:NO];
- [nav pushViewController:vc animated:YES];
- };
- pvc.disableUsersSelected = YES;
- }
- pvc.disableUsers = disabledUser;
- UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:pvc];
- [self.navigationController presentViewController:navi animated:YES completion:nil];
- } else if(indexPath.row == self.memberList.count + 1) {
- WFCUContactListViewController *pvc = [[WFCUContactListViewController alloc] init];
- pvc.selectContact = YES;
- pvc.multiSelect = YES;
- pvc.selectResult = ^(NSArray<NSString *> *contacts) {
- [[WFCCIMService sharedWFCIMService] kickoffMembers:contacts fromGroup:self.conversation.target notifyLines:@[@(0)] notifyContent:nil success:^{
- [[WFCCIMService sharedWFCIMService] getGroupMembers:ws.conversation.target forceUpdate:YES];
- dispatch_async(dispatch_get_main_queue(), ^{
- NSMutableArray *tmpArray = [self.memberList mutableCopy];
- NSMutableArray *removeArray = [[NSMutableArray alloc] init];
- [tmpArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
- WFCCGroupMember *member = obj;
- if([contacts containsObject:member.memberId]) {
- [removeArray addObject:member];
- }
- }];
- [tmpArray removeObjectsInArray:removeArray];
- self.memberList = [tmpArray mutableCopy];
- [self.memberCollectionView reloadData];
- });
- } error:^(int error_code) {
-
- }];
- };
- NSMutableArray *candidateUsers = [[NSMutableArray alloc] init];
- for (WFCCGroupMember *member in self.memberList) {
- [candidateUsers addObject:member.memberId];
- }
- pvc.candidateUsers = candidateUsers;
- pvc.disableUsers = @[[WFCCNetworkService sharedInstance].userId];
- UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:pvc];
- [self.navigationController presentViewController:navi animated:YES completion:nil];
- } else {
- NSString *userId;
- if(self.conversation.type == Group_Type) {
- WFCCGroupMember *member = [self.memberList objectAtIndex:indexPath.row];
- userId = member.memberId;
- } else {
- userId = self.conversation.target;
- }
- if ([[WFCCNetworkService sharedInstance].userId isEqualToString:userId]) {
- WFCUMyProfileTableViewController *vc = [[WFCUMyProfileTableViewController alloc] init];
- vc.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:vc animated:YES];
- } else {
- WFCUProfileTableViewController *vc = [[WFCUProfileTableViewController alloc] init];
- vc.userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:userId refresh:NO];
- vc.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:vc animated:YES];
- }
- }
- }
- @end
|