FriendRequestTableViewCell.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //
  2. // FriendRequestTableViewCell.m
  3. // NIMDemo
  4. //
  5. // Created by Fenix Wang on 2017/7/29.
  6. // Copyright © 2017年 Netease. All rights reserved.
  7. //
  8. #import "FriendRequestTableViewCell.h"
  9. #import "User.h"
  10. #import "UIView+NTES.h"
  11. #import "NIMAvatarImageView.h"
  12. @interface FriendRequestTableViewCell()
  13. @property (weak, nonatomic) IBOutlet UIView *avatarContainer;
  14. @property (weak, nonatomic) IBOutlet UILabel *nameLabel;
  15. @property (weak, nonatomic) IBOutlet UILabel *descLabel;
  16. @property (weak, nonatomic) IBOutlet UIButton *btn;
  17. @property (nonatomic, strong) NIMAvatarImageView *avatar;
  18. @property (nonatomic, strong) id data;
  19. @end
  20. @implementation FriendRequestTableViewCell
  21. - (void)awakeFromNib {
  22. [super awakeFromNib];
  23. // Initialization code
  24. _btn.layer.cornerRadius = 3;
  25. [self setData:_data];
  26. UILongPressGestureRecognizer *longPressGesture= [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longGesturePress:)];
  27. [self addGestureRecognizer:longPressGesture];
  28. }
  29. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  30. [super setSelected:selected animated:animated];
  31. // Configure the view for the selected state
  32. }
  33. - (void)setData:(id)data{
  34. _data = data;
  35. if(!_avatarContainer || !data)
  36. {
  37. return;
  38. }
  39. if(!_avatar)
  40. {
  41. _avatar = [[NIMAvatarImageView alloc] initWithFrame:CGRectMake(0, 0, _avatarContainer.width, _avatarContainer.height)];
  42. [_avatarContainer addSubview:_avatar];
  43. }
  44. __weak typeof(self) wself = self;
  45. if([data isKindOfClass:[FriendRequestData class]])
  46. {
  47. FriendRequestData *friendRequestData = data;
  48. NIMUser *user = [[NIMSDK sharedSDK].userManager userInfo:friendRequestData.userId];
  49. NSURL *url = user.userInfo.avatarUrl ? [NSURL URLWithString:user.userInfo.avatarUrl] : nil;
  50. [wself.avatar nim_setImageWithURL:url placeholderImage:User.defaultUserAvatar];
  51. wself.nameLabel.text = [[User sharedInfo] getUserName:user];
  52. _descLabel.text = friendRequestData.msg;
  53. _btn.hidden = NO;
  54. }
  55. // else if([data isKindOfClass:[NIMSystemNotification class]])
  56. // {
  57. // NIMSystemNotification *systemData = data;
  58. // NIMKitInfo *sourceMember = [[NIMKit sharedKit] infoByUser:systemData.sourceID option:nil];
  59. // NIMSystemNotificationType type = systemData.type;
  60. // NSString *avatarUrlString = sourceMember.avatarUrlString;
  61. // NSURL *url;
  62. // if (avatarUrlString.length) {
  63. // url = [NSURL URLWithString:avatarUrlString];
  64. // }
  65. // [self.avatar nim_setImageWithURL:url placeholderImage:User.defaultUserAvatar];
  66. //
  67. // NIMUser *nimUser = [[NIMSDK sharedSDK].userManager userInfo:systemData.sourceID];
  68. // wself.nameLabel.text = [[User sharedInfo] getUserName:nimUser];
  69. //
  70. // switch (type) {
  71. // case NIMSystemNotificationTypeTeamApply:
  72. // {
  73. // NIMTeam *team = [[NIMSDK sharedSDK].teamManager teamById:systemData.targetID];
  74. // self.descLabel.text = [NSString stringWithFormat:@"申请加入群 %@ %@", team.teamName, systemData.postscript ? systemData.postscript : @""];
  75. // _btn.hidden = NO;
  76. // }
  77. // break;
  78. // case NIMSystemNotificationTypeTeamApplyReject:
  79. // {
  80. // NIMTeam *team = [[NIMSDK sharedSDK].teamManager teamById:systemData.targetID];
  81. // self.descLabel.text = [NSString stringWithFormat:@"群 %@ 拒绝你加入", team.teamName];
  82. // _btn.hidden = YES;
  83. // }
  84. // break;
  85. // case NIMSystemNotificationTypeTeamInvite:
  86. // {
  87. // NIMTeam *team = [[NIMSDK sharedSDK].teamManager teamById:systemData.targetID];
  88. // self.descLabel.text = [NSString stringWithFormat:@"群 %@ 邀请你加入", team.teamName];
  89. // _btn.hidden = NO;
  90. // }
  91. // break;
  92. // case NIMSystemNotificationTypeTeamIviteReject:
  93. // {
  94. // NIMTeam *team = [[NIMSDK sharedSDK].teamManager teamById:systemData.targetID];
  95. // self.descLabel.text = [NSString stringWithFormat:@"拒绝了群 %@ 邀请", team.teamName];
  96. // _btn.hidden = YES;
  97. // }
  98. // break;
  99. // case NIMSystemNotificationTypeFriendAdd:
  100. // {
  101. // NSString *text = @"未知请求";
  102. // id object = systemData.attachment;
  103. // if ([object isKindOfClass:[NIMUserAddAttachment class]]) {
  104. // NIMUserOperation operation = [(NIMUserAddAttachment *)object operationType];
  105. // switch (operation) {
  106. // case NIMUserOperationAdd:
  107. // text = @"已添加你为好友";
  108. // break;
  109. // case NIMUserOperationRequest:
  110. // text = @"请求添加你为好友";
  111. // break;
  112. // case NIMUserOperationVerify:
  113. // text = @"通过了你的好友请求";
  114. // break;
  115. // case NIMUserOperationReject:
  116. // text = @"拒绝了你的好友请求";
  117. // break;
  118. // default:
  119. // break;
  120. // }
  121. // }
  122. // self.descLabel.text = text;
  123. // }
  124. // break;
  125. // default:
  126. // break;
  127. // }
  128. //
  129. // }
  130. }
  131. - (void)longGesturePress:(UIGestureRecognizer*)gestureRecognizer
  132. {
  133. if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] &&
  134. gestureRecognizer.state == UIGestureRecognizerStateBegan) {
  135. if (self.delegate && [self.delegate respondsToSelector:@selector(friendRequestDelete:)]) {
  136. [self.delegate friendRequestDelete:_data];
  137. }
  138. }
  139. }
  140. - (IBAction)onTouchAccept:(id)sender {
  141. if (self.delegate && [self.delegate respondsToSelector:@selector(friendRequestAccept:)]) {
  142. [self.delegate friendRequestAccept:_data];
  143. }
  144. }
  145. @end