WFCUProfileTableViewController.m 29 KB

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