WFCUProfileTableViewController.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. //
  2. // WFCUProfileTableViewController.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/10/22.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUProfileTableViewController.h"
  9. #import "SDWebImage.h"
  10. #import <WFChatClient/WFCChatClient.h>
  11. #import "WFCUMessageListViewController.h"
  12. #import "MBProgressHUD.h"
  13. #import "WFCUMyPortraitViewController.h"
  14. #import "WFCUVerifyRequestViewController.h"
  15. #import "WFCUGeneralModifyViewController.h"
  16. #import "WFCUVideoViewController.h"
  17. #if WFCU_SUPPORT_VOIP
  18. #import <WFAVEngineKit/WFAVEngineKit.h>
  19. #endif
  20. #import "UIFont+YH.h"
  21. #import "UIColor+YH.h"
  22. #import "WFCUConfigManager.h"
  23. @interface WFCUProfileTableViewController () <UITableViewDelegate, UITableViewDataSource, UIActionSheetDelegate>
  24. @property (strong, nonatomic)UIImageView *portraitView;
  25. @property (strong, nonatomic)UILabel *aliasLabel;
  26. @property (strong, nonatomic)UILabel *displayNameLabel;
  27. @property (strong, nonatomic)UILabel *userNameLabel;
  28. @property (strong, nonatomic)UITableViewCell *headerCell;
  29. @property (strong, nonatomic)UILabel *mobileLabel;
  30. @property (strong, nonatomic)UILabel *emailLabel;
  31. @property (strong, nonatomic)UILabel *addressLabel;
  32. @property (strong, nonatomic)UILabel *companyLabel;
  33. @property (strong, nonatomic)UILabel *socialLabel;
  34. @property (strong, nonatomic)UITableViewCell *sendMessageCell;
  35. @property (strong, nonatomic)UITableViewCell *voipCallCell;
  36. @property (strong, nonatomic)UITableViewCell *addFriendCell;
  37. @property (strong, nonatomic)UITableViewCell *momentCell;
  38. @property (nonatomic, strong)UITableView *tableView;
  39. @property (nonatomic, strong)NSMutableArray<UITableViewCell *> *cells;
  40. @property (nonatomic, strong)NSMutableArray<UITableViewCell *> *headerCells;
  41. @property (nonatomic, strong)WFCCUserInfo *userInfo;
  42. @end
  43. @implementation WFCUProfileTableViewController
  44. - (void)viewDidLoad {
  45. [super viewDidLoad];
  46. self.title = WFCString(@"UserInfomation");
  47. __weak typeof(self)ws = self;
  48. [[NSNotificationCenter defaultCenter] addObserverForName:kUserInfoUpdated object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
  49. if ([ws.userId isEqualToString:note.object]) {
  50. WFCCUserInfo *userInfo = note.userInfo[@"userInfo"];
  51. ws.userInfo = userInfo;
  52. [ws loadData];
  53. NSLog(@"reload user info %@", ws.userInfo.userId);
  54. }
  55. }];
  56. self.userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:self.userId refresh:YES];
  57. self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
  58. [self.view addSubview:self.tableView];
  59. self.tableView.backgroundColor = [UIColor colorWithHexString:@"0xededed"];
  60. self.tableView.delegate = self;
  61. self.tableView.dataSource = self;
  62. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"..." style:UIBarButtonItemStyleDone target:self action:@selector(onRightBtn:)];
  63. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.1)];
  64. [self loadData];
  65. }
  66. - (void)viewWillAppear:(BOOL)animated {
  67. [super viewWillAppear:animated];
  68. UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
  69. keyWindow.tintAdjustmentMode = UIViewTintAdjustmentModeAutomatic;
  70. [keyWindow tintColorDidChange];
  71. self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
  72. }
  73. - (void)viewWillDisappear:(BOOL)animated {
  74. [super viewWillDisappear:animated];
  75. }
  76. - (void)onRightBtn:(id)sender {
  77. NSString *title;
  78. UIActionSheet *actionSheet;
  79. NSString *friendTitle;
  80. NSString *blacklistTitle;
  81. if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userId]) {
  82. friendTitle = WFCString(@"DeleteFriend");
  83. } else {
  84. friendTitle = WFCString(@"AddFriend");
  85. }
  86. if ([[WFCCIMService sharedWFCIMService] isBlackListed:self.userId]) {
  87. blacklistTitle = WFCString(@"RemoveFromBlacklist");
  88. } else {
  89. blacklistTitle = WFCString(@"Add2Blacklist");
  90. }
  91. actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:WFCString(@"Cancel") destructiveButtonTitle:friendTitle otherButtonTitles:blacklistTitle, WFCString(@"SetAlias"), nil];
  92. [actionSheet showInView:self.view];
  93. }
  94. - (void)loadData {
  95. self.cells = [[NSMutableArray alloc] init];
  96. self.headerCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
  97. for (UIView *subView in self.headerCell.subviews) {
  98. [subView removeFromSuperview];
  99. }
  100. CGFloat width = [UIScreen mainScreen].bounds.size.width;
  101. self.portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(16, 14, 58, 58)];
  102. self.portraitView.layer.cornerRadius = 10;
  103. self.portraitView.layer.masksToBounds = YES;
  104. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onViewPortrait:)];
  105. [self.portraitView addGestureRecognizer:tap];
  106. self.portraitView.userInteractionEnabled = YES;
  107. [self.portraitView sd_setImageWithURL:[NSURL URLWithString:[self.userInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage: [UIImage imageNamed:@"PersonalChat"]];
  108. NSString *alias = [[WFCCIMService sharedWFCIMService] getFriendAlias:self.userId];
  109. if (alias.length) {
  110. self.aliasLabel = [[UILabel alloc] initWithFrame:CGRectMake(94, 8, width - 64 - 8, 21)];
  111. self.aliasLabel.text = alias;
  112. self.displayNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(94, 32, width - 94 - 8, 21)];
  113. self.displayNameLabel.text = self.userInfo.displayName;
  114. self.userNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(94, 60, width - 94 - 8, 11)];
  115. self.userNameLabel.text = [NSString stringWithFormat:@"野火ID:%@", self.userInfo.name];
  116. self.userNameLabel.font = [UIFont systemFontOfSize:12];
  117. self.userNameLabel.textColor = [UIColor grayColor];
  118. } else {
  119. self.aliasLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  120. self.displayNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(94, 23, width - 94 - 8, 21)];
  121. self.displayNameLabel.text = self.userInfo.displayName;
  122. self.displayNameLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleMedium size:20];
  123. self.displayNameLabel.textColor = [UIColor colorWithHexString:@"0x1d1d1d"];
  124. self.userNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(94, 50, width - 94 - 8, 21)];
  125. self.userNameLabel.text = [NSString stringWithFormat:@"野火ID:%@", self.userInfo.name];
  126. self.userNameLabel.font = [UIFont systemFontOfSize:12];
  127. self.userNameLabel.textColor = [UIColor grayColor];
  128. }
  129. [self.headerCell addSubview:self.portraitView];
  130. [self.headerCell addSubview:self.displayNameLabel];
  131. [self.headerCell addSubview:self.userNameLabel];
  132. [self.headerCell addSubview:self.aliasLabel];
  133. self.headerCells = [NSMutableArray new];
  134. [self.headerCells addObject:self.headerCell];
  135. if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userId]) {
  136. UITableViewCell *alisaCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"setAlisa"];
  137. alisaCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  138. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(16, 0, self.view.frame.size.width - 16 - 60, 50)];
  139. [btn setTitle:WFCString(@"ModifyNickname") forState:UIControlStateNormal];
  140. [btn setTitleColor:[UIColor colorWithHexString:@"0x1d1d1d"] forState:UIControlStateNormal];
  141. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  142. [btn addTarget:self action:@selector(setFriendNote) forControlEvents:UIControlEventTouchUpInside];
  143. btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  144. [alisaCell addSubview:btn];
  145. [self showSeparatorLine:alisaCell];
  146. [self.headerCells addObject:alisaCell];
  147. // if (self.userInfo.mobile.length > 0) {
  148. // self.mobileLabel = [[UILabel alloc] initWithFrame:CGRectMake(92, 50, width - 94 - 8, 21)];
  149. // self.mobileLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:14];
  150. // self.mobileLabel.textColor = [UIColor colorWithHexString:@"0x828282"];
  151. // self.mobileLabel.text = [NSString stringWithFormat:@"%@: %@",WFCString(@"Mobile"),self.userInfo.mobile];
  152. // [self.headerCell addSubview:self.mobileLabel];
  153. //
  154. // }
  155. if (self.userInfo.email.length > 0) {
  156. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  157. cell.textLabel.text = self.userInfo.email;
  158. [self.cells addObject:cell];
  159. }
  160. if (self.userInfo.address.length) {
  161. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  162. cell.textLabel.text = self.userInfo.address;
  163. [self.cells addObject:cell];
  164. }
  165. if (self.userInfo.company.length) {
  166. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  167. cell.textLabel.text = self.userInfo.company;
  168. [self.cells addObject:cell];
  169. }
  170. if (self.userInfo.social.length) {
  171. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  172. cell.textLabel.text = self.userInfo.social;
  173. [self.cells addObject:cell];
  174. }
  175. }
  176. if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userId]) {
  177. self.sendMessageCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  178. for (UIView *subView in self.sendMessageCell.subviews) {
  179. [subView removeFromSuperview];
  180. }
  181. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, width, 50)];
  182. [btn setImage:[UIImage imageNamed:@"message"] forState:UIControlStateNormal];
  183. btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
  184. [btn setTitle:WFCString(@"SendMessage") forState:UIControlStateNormal];
  185. [btn setTitleColor:[UIColor colorWithHexString:@"0x5b6e8e"] forState:UIControlStateNormal];
  186. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleMedium size:16];
  187. [btn addTarget:self action:@selector(onSendMessageBtn:) forControlEvents:UIControlEventTouchDown];
  188. [self.sendMessageCell addSubview:btn];
  189. [self showSeparatorLine:self.sendMessageCell];
  190. self.momentCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"momentCell"];
  191. for (UIView *subView in self.momentCell.subviews) {
  192. [subView removeFromSuperview];
  193. }
  194. UIButton *momentButton = [[UIButton alloc] initWithFrame:CGRectMake(16, 0, self.view.frame.size.width - 100, 70)];
  195. [momentButton setTitle: @"朋友圈" forState:UIControlStateNormal];
  196. [momentButton setTitleColor:[UIColor colorWithHexString:@"0x1d1d1d"] forState:UIControlStateNormal];
  197. momentButton.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  198. momentButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  199. [momentButton addTarget:self action:@selector(momentClick) forControlEvents:UIControlEventTouchUpInside];
  200. [self.momentCell addSubview:momentButton];
  201. self.momentCell.selectionStyle = UITableViewCellSelectionStyleNone;
  202. self.momentCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  203. #if WFCU_SUPPORT_VOIP
  204. self.voipCallCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  205. for (UIView *subView in self.voipCallCell.subviews) {
  206. [subView removeFromSuperview];
  207. }
  208. btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, width, 50)];
  209. [btn setImage:[UIImage imageNamed:@"video"] forState:UIControlStateNormal];
  210. btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
  211. [btn setTitle:WFCString(@"VOIPCall") forState:UIControlStateNormal];
  212. [btn addTarget:self action:@selector(onVoipCallBtn:) forControlEvents:UIControlEventTouchDown];
  213. [btn setTitleColor:[UIColor colorWithHexString:@"0x5b6e8e"] forState:UIControlStateNormal];
  214. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleMedium size:16];
  215. [self.voipCallCell addSubview:btn];
  216. #endif
  217. } else if([[WFCCNetworkService sharedInstance].userId isEqualToString:self.userId]) {
  218. } else {
  219. self.addFriendCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  220. for (UIView *subView in self.addFriendCell.subviews) {
  221. [subView removeFromSuperview];
  222. }
  223. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 8, width - 40, 40)];
  224. [btn setTitle:WFCString(@"AddFriend") forState:UIControlStateNormal];
  225. [btn setBackgroundColor:[UIColor greenColor]];
  226. [btn addTarget:self action:@selector(onAddFriendBtn:) forControlEvents:UIControlEventTouchDown];
  227. btn.layer.cornerRadius = 5.f;
  228. btn.layer.masksToBounds = YES;
  229. [self.addFriendCell addSubview:btn];
  230. }
  231. [self.tableView reloadData];
  232. }
  233. - (UIEdgeInsets)hiddenSeparatorLine:(UITableViewCell *)cell {
  234. return cell.separatorInset = UIEdgeInsetsMake(self.view.frame.size.width, 0, 0, 0);
  235. }
  236. - (void)showSeparatorLine:(UITableViewCell *)cell {
  237. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  238. }
  239. - (void)onViewPortrait:(id)sender {
  240. WFCUMyPortraitViewController *pvc = [[WFCUMyPortraitViewController alloc] init];
  241. pvc.userId = self.userId;
  242. [self.navigationController pushViewController:pvc animated:YES];
  243. }
  244. - (void)momentClick {
  245. }
  246. - (void)onSendMessageBtn:(id)sender {
  247. WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
  248. mvc.conversation = [WFCCConversation conversationWithType:Single_Type target:self.userId line:0];
  249. for (UIViewController *vc in self.navigationController.viewControllers) {
  250. if ([vc isKindOfClass:[WFCUMessageListViewController class]]) {
  251. WFCUMessageListViewController *old = (WFCUMessageListViewController*)vc;
  252. if (old.conversation.type == Single_Type && [old.conversation.target isEqualToString:self.userId]) {
  253. [self.navigationController popToViewController:vc animated:YES];
  254. return;
  255. }
  256. }
  257. }
  258. UINavigationController *nav = self.navigationController;
  259. [self.navigationController popToRootViewControllerAnimated:NO];
  260. mvc.hidesBottomBarWhenPushed = YES;
  261. [nav pushViewController:mvc animated:YES];
  262. }
  263. - (void)onVoipCallBtn:(id)sender {
  264. #if WFCU_SUPPORT_VOIP
  265. __weak typeof(self)ws = self;
  266. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  267. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  268. }];
  269. UIAlertAction *actionVoice = [UIAlertAction actionWithTitle:WFCString(@"VoiceCall") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  270. WFCCConversation *conversation = [WFCCConversation conversationWithType:Single_Type target:ws.userInfo.userId line:0];
  271. WFCUVideoViewController *videoVC = [[WFCUVideoViewController alloc] initWithTargets:@[ws.userInfo.userId] conversation:conversation audioOnly:YES];
  272. [[WFAVEngineKit sharedEngineKit] presentViewController:videoVC];
  273. }];
  274. UIAlertAction *actionVideo = [UIAlertAction actionWithTitle:WFCString(@"VideoCall") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  275. WFCCConversation *conversation = [WFCCConversation conversationWithType:Single_Type target:ws.userInfo.userId line:0];
  276. WFCUVideoViewController *videoVC = [[WFCUVideoViewController alloc] initWithTargets:@[ws.userInfo.userId] conversation:conversation audioOnly:NO];
  277. [[WFAVEngineKit sharedEngineKit] presentViewController:videoVC];
  278. }];
  279. //把action添加到actionSheet里
  280. [actionSheet addAction:actionVoice];
  281. [actionSheet addAction:actionVideo];
  282. [actionSheet addAction:actionCancel];
  283. //相当于之前的[actionSheet show];
  284. [self presentViewController:actionSheet animated:YES completion:nil];
  285. #endif
  286. }
  287. - (void)onAddFriendBtn:(id)sender {
  288. WFCUVerifyRequestViewController *vc = [[WFCUVerifyRequestViewController alloc] init];
  289. vc.userId = self.userId;
  290. [self.navigationController pushViewController:vc animated:YES];
  291. }
  292. - (void)didReceiveMemoryWarning {
  293. [super didReceiveMemoryWarning];
  294. // Dispose of any resources that can be recreated.
  295. }
  296. #pragma mark - UITableViewDataSource<NSObject>
  297. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  298. if (section == 0) {
  299. return self.headerCells.count;
  300. } else if (section == 1) {
  301. if (self.momentCell) {
  302. return 1;
  303. } else {
  304. return 0;
  305. }
  306. } else if(section == 2) {
  307. return self.cells.count;
  308. } else {
  309. if (self.sendMessageCell) {
  310. return 2;
  311. } else {
  312. return 1;
  313. }
  314. }
  315. }
  316. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  317. NSLog(@"section:%ld",(long)indexPath.section);
  318. if (indexPath.section == 0) {
  319. return self.headerCells[indexPath.row];
  320. } else if (indexPath.section == 1) {
  321. return self.momentCell;
  322. } else if (indexPath.section == 1) {
  323. return self.cells[indexPath.row];
  324. } else {
  325. if (self.sendMessageCell) {
  326. if (indexPath.row == 0) {
  327. return self.sendMessageCell;
  328. } else {
  329. return self.voipCallCell;
  330. }
  331. } else {
  332. return self.addFriendCell;
  333. }
  334. }
  335. }
  336. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  337. if (self.sendMessageCell || self.voipCallCell || self.addFriendCell) {
  338. return 4;
  339. } else {
  340. return 2;
  341. }
  342. }
  343. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  344. if (section != 0) {
  345. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 10)];
  346. view.backgroundColor = [UIColor colorWithHexString:@"0xededed"];
  347. return view;
  348. } else {
  349. return nil;
  350. }
  351. }
  352. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  353. if (section == 0) {
  354. return 0;
  355. } else {
  356. return 10;
  357. }
  358. }
  359. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  360. return @" ";
  361. }
  362. #pragma mark - UITableViewDelegate
  363. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  364. if (indexPath.section == 0) {
  365. if (indexPath.row == 0) {
  366. return 100;
  367. } else {
  368. return 50;
  369. }
  370. } else if(indexPath.section == 1) {
  371. if (self.momentCell) {
  372. return 70;
  373. } else {
  374. return 0;
  375. }
  376. } else if(indexPath.section == 2) {
  377. return 50;
  378. } else {
  379. return 50;
  380. }
  381. }
  382. #pragma mark - UIActionSheetDelegate <NSObject>
  383. - (void)setFriendNote {
  384. WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
  385. NSString *previousAlias = [[WFCCIMService sharedWFCIMService] getFriendAlias:self.userId];
  386. gmvc.defaultValue = previousAlias;
  387. gmvc.titleText = @"设置备注";
  388. gmvc.canEmpty = YES;
  389. __weak typeof(self)ws = self;
  390. gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
  391. if (![newValue isEqualToString:previousAlias]) {
  392. [[WFCCIMService sharedWFCIMService] setFriend:self.userId alias:newValue success:^{
  393. result(YES);
  394. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  395. [ws loadData];
  396. });
  397. } error:^(int error_code) {
  398. result(NO);
  399. }];
  400. }
  401. };
  402. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
  403. [self.navigationController presentViewController:nav animated:YES completion:nil];
  404. }
  405. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
  406. if(buttonIndex == 0) {// friend
  407. if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userId]) {
  408. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  409. hud.label.text = @"处理中...";
  410. [hud showAnimated:YES];
  411. [[WFCCIMService sharedWFCIMService] deleteFriend:self.userId success:^{
  412. dispatch_async(dispatch_get_main_queue(), ^{
  413. [hud hideAnimated:YES];
  414. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  415. hud.mode = MBProgressHUDModeText;
  416. hud.label.text = @"处理成功";
  417. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  418. [hud hideAnimated:YES afterDelay:1.f];
  419. });
  420. } error:^(int error_code) {
  421. dispatch_async(dispatch_get_main_queue(), ^{
  422. [hud hideAnimated:YES];
  423. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  424. hud.mode = MBProgressHUDModeText;
  425. hud.label.text = @"处理失败";
  426. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  427. [hud hideAnimated:YES afterDelay:1.f];
  428. });
  429. }];
  430. } else {
  431. WFCUVerifyRequestViewController *vc = [[WFCUVerifyRequestViewController alloc] init];
  432. vc.userId = self.userId;
  433. [self.navigationController pushViewController:vc animated:YES];
  434. }
  435. } else if(buttonIndex == 1) {// blacklist
  436. if ([[WFCCIMService sharedWFCIMService] isBlackListed:self.userId]) {
  437. //0 取消屏蔽
  438. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  439. hud.label.text = @"处理中...";
  440. [hud showAnimated:YES];
  441. [[WFCCIMService sharedWFCIMService] setBlackList:self.userId isBlackListed:NO success:^{
  442. [hud hideAnimated:YES];
  443. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  444. hud.mode = MBProgressHUDModeText;
  445. hud.label.text = @"处理成功";
  446. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  447. [hud hideAnimated:YES afterDelay:1.f];
  448. } error:^(int error_code) {
  449. [hud hideAnimated:YES];
  450. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  451. hud.mode = MBProgressHUDModeText;
  452. hud.label.text = @"处理失败";
  453. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  454. [hud hideAnimated:YES afterDelay:1.f];
  455. }];
  456. } else {
  457. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  458. hud.label.text = @"处理中...";
  459. [hud showAnimated:YES];
  460. [[WFCCIMService sharedWFCIMService] setBlackList:self.userId isBlackListed:YES success:^{
  461. [hud hideAnimated:YES];
  462. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  463. hud.mode = MBProgressHUDModeText;
  464. hud.label.text = @"处理成功";
  465. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  466. [hud hideAnimated:YES afterDelay:1.f];
  467. } error:^(int error_code) {
  468. [hud hideAnimated:YES];
  469. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  470. hud.mode = MBProgressHUDModeText;
  471. hud.label.text = @"处理失败";
  472. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  473. [hud hideAnimated:YES afterDelay:1.f];
  474. }];
  475. }
  476. } else if(buttonIndex == 2) {// alias
  477. [self setFriendNote];
  478. }
  479. }
  480. - (void)dealloc {
  481. [[NSNotificationCenter defaultCenter] removeObserver:self];
  482. }
  483. @end