NTESChartletAttachment.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // NTESChartletAttachment.h
  3. // NIM
  4. //
  5. // Created by chris on 15/7/10.
  6. // Copyright © 2015年 Netease. All rights reserved.
  7. //
  8. #import "NTESChartletAttachment.h"
  9. #import "UIImage+NTES.h"
  10. #import "NTESSessionUtil.h"
  11. @implementation NTESChartletAttachment
  12. - (NSString *)encodeAttachment
  13. {
  14. NSDictionary *dict = @{
  15. CMType : @( CustomMessageTypeChartlet),
  16. CMData : @{ CMCatalog : self.chartletCatalog? self.chartletCatalog : @"",
  17. CMChartlet : self.chartletId?self.chartletId : @""
  18. }
  19. };
  20. NSData *data = [NSJSONSerialization dataWithJSONObject:dict
  21. options:0
  22. error:nil];
  23. NSString *content = nil;
  24. if (data) {
  25. content = [[NSString alloc] initWithData:data
  26. encoding:NSUTF8StringEncoding];
  27. }
  28. return content;
  29. }
  30. - (NSString *)cellContent:(NIMMessage *)message{
  31. return @"NTESSessionChartletContentView";
  32. }
  33. - (CGSize)contentSize:(NIMMessageModel *)model cellWidth:(CGFloat)width{
  34. if (!self.showCoverImage) {
  35. UIImage *image = [UIImage fetchChartlet:self.chartletId chartletId:self.chartletCatalog];
  36. self.showCoverImage = image;
  37. }
  38. return self.showCoverImage.size;
  39. }
  40. - (UIEdgeInsets)contentViewInsets:(NIMMessage *)message
  41. {
  42. CGFloat bubblePaddingForImage = 3.f;
  43. CGFloat bubbleArrowWidthForImage = 5.f;
  44. if (message.isOutgoingMsg) {
  45. return UIEdgeInsetsMake(bubblePaddingForImage,bubblePaddingForImage,bubblePaddingForImage,bubblePaddingForImage + bubbleArrowWidthForImage);
  46. }else{
  47. return UIEdgeInsetsMake(bubblePaddingForImage,bubblePaddingForImage + bubbleArrowWidthForImage, bubblePaddingForImage,bubblePaddingForImage);
  48. }
  49. }
  50. - (BOOL)canBeRevoked
  51. {
  52. return YES;
  53. }
  54. - (BOOL)canBeForwarded
  55. {
  56. return YES;
  57. }
  58. @end