2
0

WFCUStickerCell.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // ImageCell.m
  3. // WFChat UIKit
  4. //
  5. // Created by WF Chat on 2017/9/2.
  6. // Copyright © 2017年 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCUStickerCell.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import "WFCUMediaMessageDownloader.h"
  11. #import <SDWebImage/SDWebImage.h>
  12. @interface WFCUStickerCell ()
  13. @property (nonatomic, strong)UIImageView *thumbnailView;
  14. @end
  15. @implementation WFCUStickerCell
  16. + (CGSize)sizeForClientArea:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
  17. WFCCStickerMessageContent *imgContent = (WFCCStickerMessageContent *)msgModel.message.content;
  18. CGSize size = imgContent.size;
  19. if (size.height > width || size.width > width) {
  20. float scale = MIN(width/size.height, width/size.width);
  21. size = CGSizeMake(size.width * scale, size.height * scale);
  22. }
  23. return size;
  24. }
  25. - (void)setModel:(WFCUMessageModel *)model {
  26. [super setModel:model];
  27. WFCCStickerMessageContent *stickerMsg = (WFCCStickerMessageContent *)model.message.content;
  28. __weak typeof(self) weakSelf = self;
  29. if (!stickerMsg.localPath.length) {
  30. BOOL downloading = [[WFCUMediaMessageDownloader sharedDownloader] tryDownload:model.message success:^(long long messageUid, NSString *localPath) {
  31. if (messageUid == weakSelf.model.message.messageUid) {
  32. weakSelf.model.mediaDownloading = NO;
  33. stickerMsg.localPath = localPath;
  34. [weakSelf setModel:weakSelf.model];
  35. }
  36. } error:^(long long messageUid, int error_code) {
  37. if (messageUid == weakSelf.model.message.messageUid) {
  38. weakSelf.model.mediaDownloading = NO;
  39. }
  40. }];
  41. if (downloading) {
  42. model.mediaDownloading = YES;
  43. }
  44. }
  45. self.thumbnailView.frame = self.bubbleView.bounds;
  46. if (stickerMsg.localPath.length) {
  47. [self.thumbnailView sd_setImageWithURL:[NSURL fileURLWithPath:stickerMsg.localPath]];
  48. } else {
  49. self.thumbnailView.image = nil;
  50. }
  51. self.bubbleView.image = nil;
  52. }
  53. - (UIImageView *)thumbnailView {
  54. if (!_thumbnailView) {
  55. _thumbnailView = [[UIImageView alloc] init];
  56. [self.bubbleView addSubview:_thumbnailView];
  57. }
  58. return _thumbnailView;
  59. }
  60. @end