123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638 |
- //
- // WFCUProfileTableViewController.m
- // WFChat UIKit
- //
- // Created by WF Chat on 2017/10/22.
- // Copyright © 2017年 WildFireChat. All rights reserved.
- //
- #import "WFCUProfileTableViewController.h"
- #import <SDWebImage/SDWebImage.h>
- #import <WFChatClient/WFCChatClient.h>
- #import "WFCUMessageListViewController.h"
- #import "MBProgressHUD.h"
- #import "WFCUMyPortraitViewController.h"
- #import "WFCUVerifyRequestViewController.h"
- #import "WFCUGeneralModifyViewController.h"
- #import "WFCUVideoViewController.h"
- #if WFCU_SUPPORT_VOIP
- #import <WFAVEngineKit/WFAVEngineKit.h>
- #endif
- #import "UIFont+YH.h"
- #import "UIColor+YH.h"
- #import "WFCUConfigManager.h"
- #import "WFCUUserMessageListViewController.h"
- @interface WFCUProfileTableViewController () <UITableViewDelegate, UITableViewDataSource, UIActionSheetDelegate>
- @property (strong, nonatomic)UIImageView *portraitView;
- @property (strong, nonatomic)UILabel *aliasLabel;
- @property (strong, nonatomic)UILabel *displayNameLabel;
- @property (strong, nonatomic)UILabel *userNameLabel;
- @property (strong, nonatomic)UILabel *starLabel;
- @property (strong, nonatomic)UITableViewCell *headerCell;
- @property (strong, nonatomic)UILabel *mobileLabel;
- @property (strong, nonatomic)UILabel *emailLabel;
- @property (strong, nonatomic)UILabel *addressLabel;
- @property (strong, nonatomic)UILabel *companyLabel;
- @property (strong, nonatomic)UILabel *socialLabel;
- @property (strong, nonatomic)UITableViewCell *sendMessageCell;
- @property (strong, nonatomic)UITableViewCell *voipCallCell;
- @property (strong, nonatomic)UITableViewCell *addFriendCell;
- @property (strong, nonatomic)UITableViewCell *momentCell;
- @property (nonatomic, strong)UITableViewCell *userMessagesCell;
- @property (nonatomic, strong)UITableView *tableView;
- @property (nonatomic, strong)NSMutableArray<UITableViewCell *> *cells;
- @property (nonatomic, strong)NSMutableArray<UITableViewCell *> *headerCells;
- @property (nonatomic, strong)WFCCUserInfo *userInfo;
- @end
- @implementation WFCUProfileTableViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.title = WFCString(@"UserInfomation");
- __weak typeof(self)ws = self;
- [[NSNotificationCenter defaultCenter] addObserverForName:kUserInfoUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
- if ([ws.userId isEqualToString:note.object]) {
- WFCCUserInfo *userInfo = note.userInfo[@"userInfo"];
- ws.userInfo = userInfo;
- [ws loadData];
- NSLog(@"reload user info %@", ws.userInfo.userId);
- }
- }];
-
- self.userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.userId refresh:YES];
-
- self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
- [self.view addSubview:self.tableView];
- self.tableView.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
-
- self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"..." style:UIBarButtonItemStyleDone target:self action:@selector(onRightBtn:)];
-
- self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.1)];
- [self loadData];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
- keyWindow.tintAdjustmentMode = UIViewTintAdjustmentModeAutomatic;
- [keyWindow tintColorDidChange];
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- }
- - (void)onRightBtn:(id)sender {
- NSString *title;
- UIActionSheet *actionSheet;
-
- NSString *friendTitle;
- NSString *blacklistTitle;
- NSString *favTitle;
- if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userId]) {
- friendTitle = WFCString(@"DeleteFriend");
- if ([[WFCCIMService sharedWFCIMService] isFavUser:self.userId]) {
- favTitle = @"取消星标好友";
- } else {
- favTitle = @"设置星标好友";
- }
- } else {
- friendTitle = WFCString(@"AddFriend");
-
- }
-
- if ([[WFCCIMService sharedWFCIMService] isBlackListed:self.userId]) {
- blacklistTitle = WFCString(@"RemoveFromBlacklist");
- } else {
- blacklistTitle = WFCString(@"Add2Blacklist");
- }
-
- if (favTitle) {
- actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:WFCString(@"Cancel") destructiveButtonTitle:friendTitle otherButtonTitles:blacklistTitle, WFCString(@"SetAlias"), favTitle, nil];
- } else {
- actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:WFCString(@"Cancel") destructiveButtonTitle:friendTitle otherButtonTitles:blacklistTitle, WFCString(@"SetAlias"), nil];
- }
-
- [actionSheet showInView:self.view];
- }
- - (void)loadData {
- self.cells = [[NSMutableArray alloc] init];
-
- self.headerCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
- for (UIView *subView in self.headerCell.subviews) {
- [subView removeFromSuperview];
- }
- CGFloat width = [UIScreen mainScreen].bounds.size.width;
-
- self.portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(16, 14, 58, 58)];
-
- self.portraitView.layer.cornerRadius = 10;
- self.portraitView.layer.masksToBounds = YES;
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onViewPortrait:)];
- [self.portraitView addGestureRecognizer:tap];
- self.portraitView.userInteractionEnabled = YES;
-
-
- [self.portraitView sd_setImageWithURL:[NSURL URLWithString:[self.userInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage: [UIImage imageNamed:@"PersonalChat"]];
-
- NSString *alias = [[WFCCIMService sharedWFCIMService] getFriendAlias:self.userId];
- if (alias.length) {
- self.aliasLabel = [[UILabel alloc] initWithFrame:CGRectMake(94, 8, width - 64 - 8, 21)];
- self.aliasLabel.text = alias;
-
- self.displayNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(94, 32, width - 94 - 8, 21)];
- self.displayNameLabel.text = self.userInfo.displayName;
-
- self.userNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(94, 60, width - 94 - 8, 11)];
- self.userNameLabel.text = [NSString stringWithFormat:@"野火ID:%@", self.userInfo.name];
- self.userNameLabel.font = [UIFont systemFontOfSize:12];
- self.userNameLabel.textColor = [UIColor grayColor];
- } else {
- self.aliasLabel = [[UILabel alloc] initWithFrame:CGRectZero];
- self.displayNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(94, 23, width - 94 - 8, 21)];
- self.displayNameLabel.text = self.userInfo.displayName;
- self.displayNameLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleMedium size:20];
-
- self.userNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(94, 50, width - 94 - 8, 21)];
- self.userNameLabel.text = [NSString stringWithFormat:@"野火ID:%@", self.userInfo.name];
- self.userNameLabel.font = [UIFont systemFontOfSize:12];
- self.userNameLabel.textColor = [UIColor grayColor];
- }
-
- if ([[WFCCIMService sharedWFCIMService] isFavUser:self.userId]) {
- self.starLabel = [[UILabel alloc] initWithFrame:CGRectMake(width - 16 - 20, self.displayNameLabel.frame.origin.y, 20, 20)];
- self.starLabel.text = @"☆";
- self.starLabel.font = [UIFont systemFontOfSize:18];
- self.starLabel.textColor = [UIColor yellowColor];
-
- [self.headerCell addSubview:self.starLabel];
- }
-
- [self.headerCell addSubview:self.portraitView];
- [self.headerCell addSubview:self.displayNameLabel];
- [self.headerCell addSubview:self.userNameLabel];
- [self.headerCell addSubview:self.aliasLabel];
- self.headerCells = [NSMutableArray new];
- [self.headerCells addObject:self.headerCell];
- if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userId]) {
- UITableViewCell *alisaCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"setAlisa"];
- alisaCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(16, 0, self.view.frame.size.width - 16 - 60, 50)];
- [btn setTitle:WFCString(@"ModifyNickname") forState:UIControlStateNormal];
- [btn setTitleColor:[WFCUConfigManager globalManager].textColor forState:UIControlStateNormal];
- btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
- [btn addTarget:self action:@selector(setFriendNote) forControlEvents:UIControlEventTouchUpInside];
- btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- [alisaCell.contentView addSubview:btn];
- [self showSeparatorLine:alisaCell];
- [self.headerCells addObject:alisaCell];
- // if (self.userInfo.mobile.length > 0) {
- // self.mobileLabel = [[UILabel alloc] initWithFrame:CGRectMake(92, 50, width - 94 - 8, 21)];
- // self.mobileLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:14];
- // self.mobileLabel.textColor = [UIColor colorWithHexString:@"0x828282"];
- // self.mobileLabel.text = [NSString stringWithFormat:@"%@: %@",WFCString(@"Mobile"),self.userInfo.mobile];
- // [self.headerCell addSubview:self.mobileLabel];
- //
- // }
-
- if (self.userInfo.email.length > 0) {
- UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
- cell.textLabel.text = self.userInfo.email;
- [self.cells addObject:cell];
- }
-
- if (self.userInfo.address.length) {
- UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
- cell.textLabel.text = self.userInfo.address;
- [self.cells addObject:cell];
- }
-
- if (self.userInfo.company.length) {
- UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
- cell.textLabel.text = self.userInfo.company;
- [self.cells addObject:cell];
- }
-
- if (self.userInfo.social.length) {
- UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
- cell.textLabel.text = self.userInfo.social;
- [self.cells addObject:cell];
- }
- }
-
- if (self.fromConversation.type == Group_Type) {
- self.userMessagesCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
- self.userMessagesCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- self.userMessagesCell.textLabel.text = @"查看他(她)的消息";
- [self.cells addObject:self.userMessagesCell];
- }
-
- if(NSClassFromString(@"SDTimeLineTableViewController")) {
- self.momentCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"momentCell"];
- for (UIView *subView in self.momentCell.subviews) {
- [subView removeFromSuperview];
- }
-
- UIButton *momentButton = [[UIButton alloc] initWithFrame:CGRectMake(16, 0, self.view.frame.size.width - 100, 70)];
- [momentButton setTitle: @"朋友圈" forState:UIControlStateNormal];
- [momentButton setTitleColor:[WFCUConfigManager globalManager].textColor forState:UIControlStateNormal];
- momentButton.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
- momentButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- [momentButton addTarget:self action:@selector(momentClick) forControlEvents:UIControlEventTouchUpInside];
- [self.momentCell.contentView addSubview:momentButton];
- self.momentCell.selectionStyle = UITableViewCellSelectionStyleNone;
- self.momentCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- }
-
- if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userId]) {
- self.sendMessageCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
- for (UIView *subView in self.sendMessageCell.subviews) {
- [subView removeFromSuperview];
- }
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, width, 50)];
- [btn setImage:[UIImage imageNamed:@"message"] forState:UIControlStateNormal];
- btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
- [btn setTitle:WFCString(@"SendMessage") forState:UIControlStateNormal];
- [btn setTitleColor:[WFCUConfigManager globalManager].textColor forState:UIControlStateNormal];
- btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleMedium size:16];
- [btn addTarget:self action:@selector(onSendMessageBtn:) forControlEvents:UIControlEventTouchDown];
- [self.sendMessageCell.contentView addSubview:btn];
- [self showSeparatorLine:self.sendMessageCell];
-
- #if WFCU_SUPPORT_VOIP
- self.voipCallCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
- for (UIView *subView in self.voipCallCell.subviews) {
- [subView removeFromSuperview];
- }
- btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, width, 50)];
- [btn setImage:[UIImage imageNamed:@"video"] forState:UIControlStateNormal];
- btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
- [btn setTitle:WFCString(@"VOIPCall") forState:UIControlStateNormal];
- [btn addTarget:self action:@selector(onVoipCallBtn:) forControlEvents:UIControlEventTouchDown];
- [btn setTitleColor:[UIColor colorWithHexString:@"0x5b6e8e"] forState:UIControlStateNormal];
- btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleMedium size:16];
- [self.voipCallCell.contentView addSubview:btn];
- #endif
- } else if([[WFCCNetworkService sharedInstance].userId isEqualToString:self.userId]) {
-
- } else {
- self.addFriendCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
- for (UIView *subView in self.addFriendCell.subviews) {
- [subView removeFromSuperview];
- }
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 8, width - 40, 40)];
- [btn setTitle:WFCString(@"AddFriend") forState:UIControlStateNormal];
- [btn setBackgroundColor:[UIColor greenColor]];
- [btn addTarget:self action:@selector(onAddFriendBtn:) forControlEvents:UIControlEventTouchDown];
- btn.layer.cornerRadius = 5.f;
- btn.layer.masksToBounds = YES;
- [self.addFriendCell.contentView addSubview:btn];
-
- }
- [self.tableView reloadData];
- }
- - (UIEdgeInsets)hiddenSeparatorLine:(UITableViewCell *)cell {
- return cell.separatorInset = UIEdgeInsetsMake(self.view.frame.size.width, 0, 0, 0);
- }
- - (void)showSeparatorLine:(UITableViewCell *)cell {
- cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
- }
- - (void)onViewPortrait:(id)sender {
- WFCUMyPortraitViewController *pvc = [[WFCUMyPortraitViewController alloc] init];
- pvc.userId = self.userId;
- [self.navigationController pushViewController:pvc animated:YES];
- }
- - (void)momentClick {
- Class cls = NSClassFromString(@"SDTimeLineTableViewController");
- UIViewController *vc = [[cls alloc] init];
- [vc performSelector:@selector(setUserId:) withObject:self.userId];
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)onSendMessageBtn:(id)sender {
- WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
- mvc.conversation = [WFCCConversation conversationWithType:Single_Type target:self.userId line:0];
- for (UIViewController *vc in self.navigationController.viewControllers) {
- if ([vc isKindOfClass:[WFCUMessageListViewController class]]) {
- WFCUMessageListViewController *old = (WFCUMessageListViewController*)vc;
- if (old.conversation.type == Single_Type && [old.conversation.target isEqualToString:self.userId]) {
- [self.navigationController popToViewController:vc animated:YES];
- return;
- }
- }
- }
- UINavigationController *nav = self.navigationController;
- [self.navigationController popToRootViewControllerAnimated:NO];
- mvc.hidesBottomBarWhenPushed = YES;
- [nav pushViewController:mvc animated:YES];
- }
- - (void)onVoipCallBtn:(id)sender {
- #if WFCU_SUPPORT_VOIP
- __weak typeof(self)ws = self;
- UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
-
- UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- UIAlertAction *actionVoice = [UIAlertAction actionWithTitle:WFCString(@"VoiceCall") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- WFCCConversation *conversation = [WFCCConversation conversationWithType:Single_Type target:ws.userInfo.userId line:0];
- WFCUVideoViewController *videoVC = [[WFCUVideoViewController alloc] initWithTargets:@[ws.userInfo.userId] conversation:conversation audioOnly:YES];
- [[WFAVEngineKit sharedEngineKit] presentViewController:videoVC];
- }];
-
- UIAlertAction *actionVideo = [UIAlertAction actionWithTitle:WFCString(@"VideoCall") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- WFCCConversation *conversation = [WFCCConversation conversationWithType:Single_Type target:ws.userInfo.userId line:0];
- WFCUVideoViewController *videoVC = [[WFCUVideoViewController alloc] initWithTargets:@[ws.userInfo.userId] conversation:conversation audioOnly:NO];
- [[WFAVEngineKit sharedEngineKit] presentViewController:videoVC];
- }];
-
- //把action添加到actionSheet里
- [actionSheet addAction:actionVoice];
- [actionSheet addAction:actionVideo];
- [actionSheet addAction:actionCancel];
-
-
- //相当于之前的[actionSheet show];
- [self presentViewController:actionSheet animated:YES completion:nil];
- #endif
- }
- - (void)onAddFriendBtn:(id)sender {
- WFCUVerifyRequestViewController *vc = [[WFCUVerifyRequestViewController alloc] init];
- vc.userId = self.userId;
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - UITableViewDataSource<NSObject>
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if (section == 0) {
- return self.headerCells.count;
- } else if (section == 1) {
- if (self.momentCell) {
- return 1;
- } else {
- return 0;
- }
- } else if(section == 2) {
- return self.cells.count;
- } else {
- if (self.sendMessageCell) {
- return 2;
- } else {
- return 1;
- }
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- NSLog(@"section:%ld",(long)indexPath.section);
- if (indexPath.section == 0) {
- return self.headerCells[indexPath.row];
- } else if (indexPath.section == 1) {
- return self.momentCell;
- } else if (indexPath.section == 2) {
- return self.cells[indexPath.row];
- } else {
- if (self.sendMessageCell) {
- if (indexPath.row == 0) {
- return self.sendMessageCell;
- } else {
- return self.voipCallCell;
- }
- } else {
- return self.addFriendCell;
- }
- }
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- if (self.sendMessageCell || self.voipCallCell || self.addFriendCell) {
- return 4;
- } else {
- return 2;
- }
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- if (section != 0) {
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 10)];
- view.backgroundColor = [WFCUConfigManager globalManager].backgroudColor;
- return view;
- } else {
- return nil;
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- if (section == 0) {
- return 0;
- } else {
- return 10;
- }
- }
- - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- return @" ";
- }
- -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- if([tableView cellForRowAtIndexPath:indexPath] == self.userMessagesCell) {
- WFCUUserMessageListViewController *vc = [[WFCUUserMessageListViewController alloc] init];
- vc.userId = self.userId;
- vc.conversation = self.fromConversation;
- [self.navigationController pushViewController:vc animated:YES];
- }
- }
- #pragma mark - UITableViewDelegate
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 0) {
- if (indexPath.row == 0) {
- return 100;
- } else {
- return 50;
- }
- } else if(indexPath.section == 1) {
- if (self.momentCell) {
- return 70;
- } else {
- return 0;
- }
- } else if(indexPath.section == 2) {
- return 50;
- } else {
- return 50;
- }
- }
- #pragma mark - UIActionSheetDelegate <NSObject>
- - (void)setFriendNote {
- WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
- NSString *previousAlias = [[WFCCIMService sharedWFCIMService] getFriendAlias:self.userId];
- gmvc.defaultValue = previousAlias;
- gmvc.titleText = @"设置备注";
- gmvc.canEmpty = YES;
- __weak typeof(self)ws = self;
- gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
- if (![newValue isEqualToString:previousAlias]) {
- [[WFCCIMService sharedWFCIMService] setFriend:self.userId alias:newValue success:^{
- result(YES);
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [ws loadData];
- });
- } error:^(int error_code) {
- result(NO);
- }];
- }
- };
- UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
- [self.navigationController presentViewController:nav animated:YES completion:nil];
- }
- - (void)setFavUser {
- BOOL isFav = [[WFCCIMService sharedWFCIMService] isFavUser:self.userId];
-
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- hud.label.text = @"处理中...";
- [hud showAnimated:YES];
- __weak typeof(self)ws = self;
- [[WFCCIMService sharedWFCIMService] setFavUser:self.userId fav:!isFav success:^{
- dispatch_async(dispatch_get_main_queue(), ^{
- [hud hideAnimated:YES];
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- hud.mode = MBProgressHUDModeText;
- hud.label.text = @"处理成功";
- hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
- [hud hideAnimated:YES afterDelay:1.f];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [ws loadData];
- });
- });
- } error:^(int errorCode) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [hud hideAnimated:YES];
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- hud.mode = MBProgressHUDModeText;
- hud.label.text = @"处理失败";
- hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
- [hud hideAnimated:YES afterDelay:1.f];
- });
- }];
- }
- - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
- if(buttonIndex == 0) {// friend
- if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userId]) {
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- hud.label.text = @"处理中...";
- [hud showAnimated:YES];
-
- [[WFCCIMService sharedWFCIMService] deleteFriend:self.userId success:^{
- dispatch_async(dispatch_get_main_queue(), ^{
- [hud hideAnimated:YES];
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- hud.mode = MBProgressHUDModeText;
- hud.label.text = @"处理成功";
- hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
- [hud hideAnimated:YES afterDelay:1.f];
- });
- } error:^(int error_code) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [hud hideAnimated:YES];
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- hud.mode = MBProgressHUDModeText;
- hud.label.text = @"处理失败";
- hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
- [hud hideAnimated:YES afterDelay:1.f];
- });
- }];
- } else {
- WFCUVerifyRequestViewController *vc = [[WFCUVerifyRequestViewController alloc] init];
- vc.userId = self.userId;
- [self.navigationController pushViewController:vc animated:YES];
- }
- } else if(buttonIndex == 1) {// blacklist
- if ([[WFCCIMService sharedWFCIMService] isBlackListed:self.userId]) {
- //0 取消屏蔽
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- hud.label.text = @"处理中...";
- [hud showAnimated:YES];
-
- [[WFCCIMService sharedWFCIMService] setBlackList:self.userId isBlackListed:NO success:^{
- [hud hideAnimated:YES];
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- hud.mode = MBProgressHUDModeText;
- hud.label.text = @"处理成功";
- hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
- [hud hideAnimated:YES afterDelay:1.f];
- } error:^(int error_code) {
- [hud hideAnimated:YES];
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- hud.mode = MBProgressHUDModeText;
- hud.label.text = @"处理失败";
- hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
- [hud hideAnimated:YES afterDelay:1.f];
- }];
- } else {
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- hud.label.text = @"处理中...";
- [hud showAnimated:YES];
-
- [[WFCCIMService sharedWFCIMService] setBlackList:self.userId isBlackListed:YES success:^{
- [hud hideAnimated:YES];
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- hud.mode = MBProgressHUDModeText;
- hud.label.text = @"处理成功";
- hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
- [hud hideAnimated:YES afterDelay:1.f];
- } error:^(int error_code) {
- [hud hideAnimated:YES];
- MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- hud.mode = MBProgressHUDModeText;
- hud.label.text = @"处理失败";
- hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
- [hud hideAnimated:YES afterDelay:1.f];
- }];
- }
- } else if(buttonIndex == 2) {// alias
- [self setFriendNote];
- } else if(buttonIndex == 3) {// fav
- [self setFavUser];
- }
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- @end
|