WFCUContactTableViewCell.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // ContactTableViewCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/10/28.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUContactTableViewCell.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import "SDWebImage.h"
  11. @interface WFCUContactTableViewCell ()
  12. @end
  13. @implementation WFCUContactTableViewCell
  14. - (void)awakeFromNib {
  15. [super awakeFromNib];
  16. // Initialization code
  17. }
  18. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  19. [super setSelected:selected animated:animated];
  20. // Configure the view for the selected state
  21. }
  22. - (void)onUserInfoUpdated:(NSNotification *)notification {
  23. WFCCUserInfo *userInfo = notification.userInfo[@"userInfo"];
  24. if ([self.userId isEqualToString:userInfo.userId]) {
  25. [self updateUserInfo:userInfo];
  26. }
  27. }
  28. - (void)setUserId:(NSString *)userId {
  29. _userId = userId;
  30. [[NSNotificationCenter defaultCenter] removeObserver:self];
  31. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUserInfoUpdated:) name:kUserInfoUpdated object:userId];
  32. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:userId refresh:NO];
  33. if(userInfo.userId.length == 0) {
  34. userInfo = [[WFCCUserInfo alloc] init];
  35. userInfo.userId = userId;
  36. }
  37. [self updateUserInfo:userInfo];
  38. }
  39. - (void)updateUserInfo:(WFCCUserInfo *)userInfo {
  40. [self.portraitView sd_setImageWithURL:[NSURL URLWithString:userInfo.portrait] placeholderImage: [UIImage imageNamed:@"PersonalChat"]];
  41. if (self.alterName.length) {
  42. self.nameLabel.text = self.alterName;
  43. } else if(userInfo.displayName.length > 0) {
  44. self.nameLabel.text = userInfo.displayName;
  45. } else {
  46. self.nameLabel.text = [NSString stringWithFormat:@"user<%@>", userInfo.userId];
  47. }
  48. }
  49. - (UIImageView *)portraitView {
  50. if (!_portraitView) {
  51. if (self.isBig) {
  52. _portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(8, 8, 52, 52)];
  53. } else {
  54. _portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 36, 36)];
  55. }
  56. _portraitView.layer.masksToBounds = YES;
  57. _portraitView.layer.cornerRadius = 3.f;
  58. [self.contentView addSubview:_portraitView];
  59. }
  60. return _portraitView;
  61. }
  62. - (UILabel *)nameLabel {
  63. if (!_nameLabel) {
  64. if (self.isBig) {
  65. _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(72, 24, [UIScreen mainScreen].bounds.size.width - 64, 20)];
  66. _nameLabel.font = [UIFont systemFontOfSize:20];
  67. } else {
  68. _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(56, 19, [UIScreen mainScreen].bounds.size.width - 64, 16)];
  69. _nameLabel.font = [UIFont systemFontOfSize:16];
  70. }
  71. [self.contentView addSubview:_nameLabel];
  72. }
  73. return _nameLabel;
  74. }
  75. - (void)dealloc {
  76. [[NSNotificationCenter defaultCenter] removeObserver:self];
  77. }
  78. @end