WFCUProfileTableViewController.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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(NSClassFromString(@"SDTimeLineTableViewController")) {
  177. self.momentCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"momentCell"];
  178. for (UIView *subView in self.momentCell.subviews) {
  179. [subView removeFromSuperview];
  180. }
  181. UIButton *momentButton = [[UIButton alloc] initWithFrame:CGRectMake(16, 0, self.view.frame.size.width - 100, 70)];
  182. [momentButton setTitle: @"朋友圈" forState:UIControlStateNormal];
  183. [momentButton setTitleColor:[UIColor colorWithHexString:@"0x1d1d1d"] forState:UIControlStateNormal];
  184. momentButton.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleRegular size:16];
  185. momentButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  186. [momentButton addTarget:self action:@selector(momentClick) forControlEvents:UIControlEventTouchUpInside];
  187. [self.momentCell addSubview:momentButton];
  188. self.momentCell.selectionStyle = UITableViewCellSelectionStyleNone;
  189. self.momentCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  190. }
  191. if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userId]) {
  192. self.sendMessageCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  193. for (UIView *subView in self.sendMessageCell.subviews) {
  194. [subView removeFromSuperview];
  195. }
  196. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, width, 50)];
  197. [btn setImage:[UIImage imageNamed:@"message"] forState:UIControlStateNormal];
  198. btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
  199. [btn setTitle:WFCString(@"SendMessage") forState:UIControlStateNormal];
  200. [btn setTitleColor:[UIColor colorWithHexString:@"0x5b6e8e"] forState:UIControlStateNormal];
  201. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleMedium size:16];
  202. [btn addTarget:self action:@selector(onSendMessageBtn:) forControlEvents:UIControlEventTouchDown];
  203. [self.sendMessageCell addSubview:btn];
  204. [self showSeparatorLine:self.sendMessageCell];
  205. #if WFCU_SUPPORT_VOIP
  206. self.voipCallCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  207. for (UIView *subView in self.voipCallCell.subviews) {
  208. [subView removeFromSuperview];
  209. }
  210. btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, width, 50)];
  211. [btn setImage:[UIImage imageNamed:@"video"] forState:UIControlStateNormal];
  212. btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
  213. [btn setTitle:WFCString(@"VOIPCall") forState:UIControlStateNormal];
  214. [btn addTarget:self action:@selector(onVoipCallBtn:) forControlEvents:UIControlEventTouchDown];
  215. [btn setTitleColor:[UIColor colorWithHexString:@"0x5b6e8e"] forState:UIControlStateNormal];
  216. btn.titleLabel.font = [UIFont pingFangSCWithWeight:FontWeightStyleMedium size:16];
  217. [self.voipCallCell addSubview:btn];
  218. #endif
  219. } else if([[WFCCNetworkService sharedInstance].userId isEqualToString:self.userId]) {
  220. } else {
  221. self.addFriendCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
  222. for (UIView *subView in self.addFriendCell.subviews) {
  223. [subView removeFromSuperview];
  224. }
  225. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 8, width - 40, 40)];
  226. [btn setTitle:WFCString(@"AddFriend") forState:UIControlStateNormal];
  227. [btn setBackgroundColor:[UIColor greenColor]];
  228. [btn addTarget:self action:@selector(onAddFriendBtn:) forControlEvents:UIControlEventTouchDown];
  229. btn.layer.cornerRadius = 5.f;
  230. btn.layer.masksToBounds = YES;
  231. [self.addFriendCell addSubview:btn];
  232. }
  233. [self.tableView reloadData];
  234. }
  235. - (UIEdgeInsets)hiddenSeparatorLine:(UITableViewCell *)cell {
  236. return cell.separatorInset = UIEdgeInsetsMake(self.view.frame.size.width, 0, 0, 0);
  237. }
  238. - (void)showSeparatorLine:(UITableViewCell *)cell {
  239. cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  240. }
  241. - (void)onViewPortrait:(id)sender {
  242. WFCUMyPortraitViewController *pvc = [[WFCUMyPortraitViewController alloc] init];
  243. pvc.userId = self.userId;
  244. [self.navigationController pushViewController:pvc animated:YES];
  245. }
  246. - (void)momentClick {
  247. Class cls = NSClassFromString(@"SDTimeLineTableViewController");
  248. UIViewController *vc = [[cls alloc] init];
  249. [vc performSelector:@selector(setUserId:) withObject:self.userId];
  250. [self.navigationController pushViewController:vc animated:YES];
  251. }
  252. - (void)onSendMessageBtn:(id)sender {
  253. WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
  254. mvc.conversation = [WFCCConversation conversationWithType:Single_Type target:self.userId line:0];
  255. for (UIViewController *vc in self.navigationController.viewControllers) {
  256. if ([vc isKindOfClass:[WFCUMessageListViewController class]]) {
  257. WFCUMessageListViewController *old = (WFCUMessageListViewController*)vc;
  258. if (old.conversation.type == Single_Type && [old.conversation.target isEqualToString:self.userId]) {
  259. [self.navigationController popToViewController:vc animated:YES];
  260. return;
  261. }
  262. }
  263. }
  264. UINavigationController *nav = self.navigationController;
  265. [self.navigationController popToRootViewControllerAnimated:NO];
  266. mvc.hidesBottomBarWhenPushed = YES;
  267. [nav pushViewController:mvc animated:YES];
  268. }
  269. - (void)onVoipCallBtn:(id)sender {
  270. #if WFCU_SUPPORT_VOIP
  271. __weak typeof(self)ws = self;
  272. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  273. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:WFCString(@"Cancel") style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  274. }];
  275. UIAlertAction *actionVoice = [UIAlertAction actionWithTitle:WFCString(@"VoiceCall") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  276. WFCCConversation *conversation = [WFCCConversation conversationWithType:Single_Type target:ws.userInfo.userId line:0];
  277. WFCUVideoViewController *videoVC = [[WFCUVideoViewController alloc] initWithTargets:@[ws.userInfo.userId] conversation:conversation audioOnly:YES];
  278. [[WFAVEngineKit sharedEngineKit] presentViewController:videoVC];
  279. }];
  280. UIAlertAction *actionVideo = [UIAlertAction actionWithTitle:WFCString(@"VideoCall") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  281. WFCCConversation *conversation = [WFCCConversation conversationWithType:Single_Type target:ws.userInfo.userId line:0];
  282. WFCUVideoViewController *videoVC = [[WFCUVideoViewController alloc] initWithTargets:@[ws.userInfo.userId] conversation:conversation audioOnly:NO];
  283. [[WFAVEngineKit sharedEngineKit] presentViewController:videoVC];
  284. }];
  285. //把action添加到actionSheet里
  286. [actionSheet addAction:actionVoice];
  287. [actionSheet addAction:actionVideo];
  288. [actionSheet addAction:actionCancel];
  289. //相当于之前的[actionSheet show];
  290. [self presentViewController:actionSheet animated:YES completion:nil];
  291. #endif
  292. }
  293. - (void)onAddFriendBtn:(id)sender {
  294. WFCUVerifyRequestViewController *vc = [[WFCUVerifyRequestViewController alloc] init];
  295. vc.userId = self.userId;
  296. [self.navigationController pushViewController:vc animated:YES];
  297. }
  298. - (void)didReceiveMemoryWarning {
  299. [super didReceiveMemoryWarning];
  300. // Dispose of any resources that can be recreated.
  301. }
  302. #pragma mark - UITableViewDataSource<NSObject>
  303. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  304. if (section == 0) {
  305. return self.headerCells.count;
  306. } else if (section == 1) {
  307. if (self.momentCell) {
  308. return 1;
  309. } else {
  310. return 0;
  311. }
  312. } else if(section == 2) {
  313. return self.cells.count;
  314. } else {
  315. if (self.sendMessageCell) {
  316. return 2;
  317. } else {
  318. return 1;
  319. }
  320. }
  321. }
  322. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  323. NSLog(@"section:%ld",(long)indexPath.section);
  324. if (indexPath.section == 0) {
  325. return self.headerCells[indexPath.row];
  326. } else if (indexPath.section == 1) {
  327. return self.momentCell;
  328. } else if (indexPath.section == 1) {
  329. return self.cells[indexPath.row];
  330. } else {
  331. if (self.sendMessageCell) {
  332. if (indexPath.row == 0) {
  333. return self.sendMessageCell;
  334. } else {
  335. return self.voipCallCell;
  336. }
  337. } else {
  338. return self.addFriendCell;
  339. }
  340. }
  341. }
  342. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  343. if (self.sendMessageCell || self.voipCallCell || self.addFriendCell) {
  344. return 4;
  345. } else {
  346. return 2;
  347. }
  348. }
  349. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  350. if (section != 0) {
  351. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 10)];
  352. view.backgroundColor = [UIColor colorWithHexString:@"0xededed"];
  353. return view;
  354. } else {
  355. return nil;
  356. }
  357. }
  358. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  359. if (section == 0) {
  360. return 0;
  361. } else {
  362. return 10;
  363. }
  364. }
  365. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  366. return @" ";
  367. }
  368. #pragma mark - UITableViewDelegate
  369. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  370. if (indexPath.section == 0) {
  371. if (indexPath.row == 0) {
  372. return 100;
  373. } else {
  374. return 50;
  375. }
  376. } else if(indexPath.section == 1) {
  377. if (self.momentCell) {
  378. return 70;
  379. } else {
  380. return 0;
  381. }
  382. } else if(indexPath.section == 2) {
  383. return 50;
  384. } else {
  385. return 50;
  386. }
  387. }
  388. #pragma mark - UIActionSheetDelegate <NSObject>
  389. - (void)setFriendNote {
  390. WFCUGeneralModifyViewController *gmvc = [[WFCUGeneralModifyViewController alloc] init];
  391. NSString *previousAlias = [[WFCCIMService sharedWFCIMService] getFriendAlias:self.userId];
  392. gmvc.defaultValue = previousAlias;
  393. gmvc.titleText = @"设置备注";
  394. gmvc.canEmpty = YES;
  395. __weak typeof(self)ws = self;
  396. gmvc.tryModify = ^(NSString *newValue, void (^result)(BOOL success)) {
  397. if (![newValue isEqualToString:previousAlias]) {
  398. [[WFCCIMService sharedWFCIMService] setFriend:self.userId alias:newValue success:^{
  399. result(YES);
  400. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  401. [ws loadData];
  402. });
  403. } error:^(int error_code) {
  404. result(NO);
  405. }];
  406. }
  407. };
  408. UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:gmvc];
  409. [self.navigationController presentViewController:nav animated:YES completion:nil];
  410. }
  411. - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
  412. if(buttonIndex == 0) {// friend
  413. if ([[WFCCIMService sharedWFCIMService] isMyFriend:self.userId]) {
  414. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  415. hud.label.text = @"处理中...";
  416. [hud showAnimated:YES];
  417. [[WFCCIMService sharedWFCIMService] deleteFriend:self.userId success:^{
  418. dispatch_async(dispatch_get_main_queue(), ^{
  419. [hud hideAnimated:YES];
  420. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  421. hud.mode = MBProgressHUDModeText;
  422. hud.label.text = @"处理成功";
  423. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  424. [hud hideAnimated:YES afterDelay:1.f];
  425. });
  426. } error:^(int error_code) {
  427. dispatch_async(dispatch_get_main_queue(), ^{
  428. [hud hideAnimated:YES];
  429. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  430. hud.mode = MBProgressHUDModeText;
  431. hud.label.text = @"处理失败";
  432. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  433. [hud hideAnimated:YES afterDelay:1.f];
  434. });
  435. }];
  436. } else {
  437. WFCUVerifyRequestViewController *vc = [[WFCUVerifyRequestViewController alloc] init];
  438. vc.userId = self.userId;
  439. [self.navigationController pushViewController:vc animated:YES];
  440. }
  441. } else if(buttonIndex == 1) {// blacklist
  442. if ([[WFCCIMService sharedWFCIMService] isBlackListed:self.userId]) {
  443. //0 取消屏蔽
  444. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  445. hud.label.text = @"处理中...";
  446. [hud showAnimated:YES];
  447. [[WFCCIMService sharedWFCIMService] setBlackList:self.userId isBlackListed:NO success:^{
  448. [hud hideAnimated:YES];
  449. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  450. hud.mode = MBProgressHUDModeText;
  451. hud.label.text = @"处理成功";
  452. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  453. [hud hideAnimated:YES afterDelay:1.f];
  454. } error:^(int error_code) {
  455. [hud hideAnimated:YES];
  456. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  457. hud.mode = MBProgressHUDModeText;
  458. hud.label.text = @"处理失败";
  459. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  460. [hud hideAnimated:YES afterDelay:1.f];
  461. }];
  462. } else {
  463. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  464. hud.label.text = @"处理中...";
  465. [hud showAnimated:YES];
  466. [[WFCCIMService sharedWFCIMService] setBlackList:self.userId isBlackListed:YES success:^{
  467. [hud hideAnimated:YES];
  468. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  469. hud.mode = MBProgressHUDModeText;
  470. hud.label.text = @"处理成功";
  471. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  472. [hud hideAnimated:YES afterDelay:1.f];
  473. } error:^(int error_code) {
  474. [hud hideAnimated:YES];
  475. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  476. hud.mode = MBProgressHUDModeText;
  477. hud.label.text = @"处理失败";
  478. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  479. [hud hideAnimated:YES afterDelay:1.f];
  480. }];
  481. }
  482. } else if(buttonIndex == 2) {// alias
  483. [self setFriendNote];
  484. }
  485. }
  486. - (void)dealloc {
  487. [[NSNotificationCenter defaultCenter] removeObserver:self];
  488. }
  489. @end