WFCUProfileTableViewController.m 28 KB

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