123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- //
- // ContactTableViewCell.m
- // WFChat UIKit
- //
- // Created by WF Chat on 2017/10/28.
- // Copyright © 2017年 WildFireChat. All rights reserved.
- //
- #import "WFCUContactTableViewCell.h"
- #import <WFChatClient/WFCChatClient.h>
- #import "SDWebImage.h"
- @interface WFCUContactTableViewCell ()
- @end
- @implementation WFCUContactTableViewCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (void)onUserInfoUpdated:(NSNotification *)notification {
- WFCCUserInfo *userInfo = notification.userInfo[@"userInfo"];
- if ([self.userId isEqualToString:userInfo.userId]) {
- [self updateUserInfo:userInfo];
- }
- }
- - (void)setUserId:(NSString *)userId {
- _userId = userId;
- [[NSNotificationCenter defaultCenter] removeObserver:self];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUserInfoUpdated:) name:kUserInfoUpdated object:userId];
-
- WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:userId refresh:NO];
- if(userInfo.userId.length == 0) {
- userInfo = [[WFCCUserInfo alloc] init];
- userInfo.userId = userId;
- }
- [self updateUserInfo:userInfo];
- }
- - (void)updateUserInfo:(WFCCUserInfo *)userInfo {
- [self.portraitView sd_setImageWithURL:[NSURL URLWithString:userInfo.portrait] placeholderImage: [UIImage imageNamed:@"PersonalChat"]];
-
- if (self.alterName.length) {
- self.nameLabel.text = self.alterName;
- } else if(userInfo.displayName.length > 0) {
- self.nameLabel.text = userInfo.displayName;
- } else {
- self.nameLabel.text = [NSString stringWithFormat:@"user<%@>", userInfo.userId];
- }
- }
- - (UIImageView *)portraitView {
- if (!_portraitView) {
- if (self.isBig) {
- _portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(8, 8, 52, 52)];
- } else {
- _portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 36, 36)];
- }
- _portraitView.layer.masksToBounds = YES;
- _portraitView.layer.cornerRadius = 3.f;
- [self.contentView addSubview:_portraitView];
- }
- return _portraitView;
- }
- - (UILabel *)nameLabel {
- if (!_nameLabel) {
- if (self.isBig) {
- _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(72, 24, [UIScreen mainScreen].bounds.size.width - 64, 20)];
- _nameLabel.font = [UIFont systemFontOfSize:20];
- } else {
- _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(56, 19, [UIScreen mainScreen].bounds.size.width - 64, 16)];
- _nameLabel.font = [UIFont systemFontOfSize:16];
- }
- [self.contentView addSubview:_nameLabel];
- }
- return _nameLabel;
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- @end
|