NTESShareAttachment.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // NTESShareAttachment.m
  3. // NIMDemo
  4. //
  5. // Created by Fenix Wang on 2017/8/9.
  6. // Copyright © 2017年 Netease. All rights reserved.
  7. //
  8. #import "NTESShareAttachment.h"
  9. #import "UIView+NTES.h"
  10. @implementation NTESShareAttachment
  11. - (NSString *)encodeAttachment
  12. {
  13. NSDictionary *dict = @{CMType : @(CustomMessageTypeShare),
  14. CMData : @{CMValue:self.info,
  15. CMURL:self.thumb,
  16. @"tradeId":self.tradeId}};
  17. NSData *data = [NSJSONSerialization dataWithJSONObject:dict
  18. options:0
  19. error:nil];
  20. NSString *content = nil;
  21. if (data) {
  22. content = [[NSString alloc] initWithData:data
  23. encoding:NSUTF8StringEncoding];
  24. }
  25. return content;
  26. }
  27. - (NSString *)cellContent:(NIMMessage *)message{
  28. return @"NTESSessionShareContentView";
  29. }
  30. - (CGSize)contentSize:(NIMMessage *)message cellWidth:(CGFloat)width{
  31. float imageWidth = 80 + 5 * 2;
  32. self.showTextView.width = width - 80 - imageWidth;
  33. [self.showTextView sizeToFit];
  34. CGSize size = self.showTextView.contentSize;
  35. size.width += imageWidth;
  36. size.height = MAX(size.height, imageWidth);
  37. return size;
  38. }
  39. - (UIEdgeInsets)contentViewInsets:(NIMMessage *)message
  40. {
  41. if (message.session.sessionType == NIMSessionTypeChatroom)
  42. {
  43. CGFloat bubbleMarginTopForImage = 15.f;
  44. CGFloat bubbleMarginLeftForImage = 12.f;
  45. return UIEdgeInsetsMake(bubbleMarginTopForImage,bubbleMarginLeftForImage,0,0);
  46. }
  47. else
  48. {
  49. CGFloat bubbleMarginForImage = 3.f;
  50. CGFloat bubbleArrowWidthForImage = 5.f;
  51. if (message.isOutgoingMsg) {
  52. return UIEdgeInsetsMake(bubbleMarginForImage,bubbleMarginForImage,bubbleMarginForImage,bubbleMarginForImage + bubbleArrowWidthForImage);
  53. }else{
  54. return UIEdgeInsetsMake(bubbleMarginForImage,bubbleMarginForImage + bubbleArrowWidthForImage, bubbleMarginForImage,bubbleMarginForImage);
  55. }
  56. }
  57. }
  58. - (UITextView *)showTextView
  59. {
  60. if (_showTextView == nil)
  61. {
  62. _showTextView = [[UITextView alloc] init];
  63. _showTextView.font = [UIFont systemFontOfSize:15];
  64. _showTextView.text = self.info;
  65. }
  66. return _showTextView;
  67. }
  68. @end