WFCUForwardMessageCell.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //
  2. // ForwardMessageCell.m
  3. // WildFireChat
  4. //
  5. // Created by heavyrain lee on 2018/9/27.
  6. // Copyright © 2018 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUForwardMessageCell.h"
  9. #import <SDWebImage/SDWebImage.h>
  10. #import "WFCUImage.h"
  11. @interface WFCUForwardMessageCell()
  12. @property (strong, nonatomic) UIImageView *portrait;
  13. @property (strong, nonatomic) UILabel *name;
  14. @end
  15. @implementation WFCUForwardMessageCell
  16. - (void)awakeFromNib {
  17. [super awakeFromNib];
  18. // Initialization code
  19. }
  20. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  21. [super setSelected:selected animated:animated];
  22. // Configure the view for the selected state
  23. }
  24. - (void)setConversation:(WFCCConversation *)conversation {
  25. _conversation = conversation;
  26. NSString *name;
  27. NSString *portrait;
  28. if (conversation.type == Single_Type) {
  29. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:conversation.target refresh:NO];
  30. if (userInfo) {
  31. name = userInfo.displayName;
  32. portrait = userInfo.portrait;
  33. } else {
  34. name = [NSString stringWithFormat:@"%@<%@>", WFCString(@"User"), conversation.target];
  35. }
  36. [self.portrait sd_setImageWithURL:[NSURL URLWithString:[portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[WFCUImage imageNamed:@"PersonalChat"]];
  37. } else if (conversation.type == Group_Type) {
  38. WFCCGroupInfo *groupInfo = [[WFCCIMService sharedWFCIMService] getGroupInfo:conversation.target refresh:NO];
  39. if (groupInfo) {
  40. name = groupInfo.displayName;
  41. if (groupInfo.portrait.length) {
  42. [self.portrait sd_setImageWithURL:[NSURL URLWithString:[groupInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[WFCUImage imageNamed:@"group_default_portrait"]];
  43. } else {
  44. NSString *path = [WFCCUtilities getGroupGridPortrait:groupInfo.target width:80 generateIfNotExist:YES defaultUserPortrait:^UIImage *(NSString *userId) {
  45. return [WFCUImage imageNamed:@"PersonalChat"];
  46. }];
  47. if (path) {
  48. [self.portrait sd_setImageWithURL:[NSURL fileURLWithPath:path] placeholderImage:[WFCUImage imageNamed:@"group_default_portrait"]];
  49. }
  50. }
  51. } else {
  52. name = WFCString(@"GroupChat");
  53. [self.portrait setImage:[WFCUImage imageNamed:@"group_default_portrait"]];
  54. }
  55. } else if (conversation.type == Channel_Type) {
  56. WFCCChannelInfo *channelInfo = [[WFCCIMService sharedWFCIMService] getChannelInfo:conversation.target refresh:NO];
  57. if (channelInfo) {
  58. name = channelInfo.name;
  59. portrait = channelInfo.portrait;
  60. } else {
  61. name = WFCString(@"Channel");
  62. }
  63. [self.portrait sd_setImageWithURL:[NSURL URLWithString:[portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[WFCUImage imageNamed:@"channel_default_portrait"]];
  64. } else if (conversation.type == SecretChat_Type) {
  65. NSString *userId = [[WFCCIMService sharedWFCIMService] getSecretChatInfo:conversation.target].userId;
  66. WFCCUserInfo *userInfo = [[WFCCIMService sharedWFCIMService] getUserInfo:userId refresh:NO];
  67. if (userInfo) {
  68. name = userInfo.displayName;
  69. portrait = userInfo.portrait;
  70. } else {
  71. name = [NSString stringWithFormat:@"%@<%@>", WFCString(@"User"), userId];
  72. }
  73. [self.portrait sd_setImageWithURL:[NSURL URLWithString:[portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[WFCUImage imageNamed:@"PersonalChat"]];
  74. }
  75. self.name.text = name;
  76. }
  77. - (UIImageView *)portrait {
  78. if (!_portrait) {
  79. _portrait = [[UIImageView alloc] initWithFrame:CGRectMake(8, 8, 40, 40)];
  80. [self.contentView addSubview:_portrait];
  81. }
  82. return _portrait;
  83. }
  84. - (UILabel *)name {
  85. if (!_name) {
  86. _name = [[UILabel alloc] initWithFrame:CGRectMake(56, 16, [UIScreen mainScreen].bounds.size.width - 64, 24)];
  87. [self.contentView addSubview:_name];
  88. }
  89. return _name;
  90. }
  91. @end