YOUPAILCMessageTxtAttachment.m 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // YOUPAILCMessageTxtAttachment.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/9/22.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCMessageTxtAttachment.h"
  9. @implementation YOUPAILCMessageTxtAttachment
  10. - (NSString *)encodeAttachment
  11. {
  12. NSDictionary *dict = @{
  13. CMType : @(CustomMessageTxt),
  14. CMData : @{
  15. CMTitle: self.title ?self.title:@"",
  16. CMDate: self.date ?self.date:@"",
  17. CMTxt1: self.txt1 ?self.txt1:@"",
  18. CMfields: self.fields?self.fields:@[],
  19. CMTxt2: self.txt2 ?self.txt2:@"",
  20. CMLink_url: self.link_url ?self.link_url:@"",
  21. CMLink_type: self.link_type ?[NSNumber numberWithInteger:self.link_type]:@0,
  22. }
  23. };
  24. NSData *data = [NSJSONSerialization dataWithJSONObject:dict
  25. options:0
  26. error:nil];
  27. NSString *content = nil;
  28. if (data) {
  29. content = [[NSString alloc] initWithData:data
  30. encoding:NSUTF8StringEncoding];
  31. }
  32. return content;
  33. }
  34. - (NSString *)cellContent:(NIMMessage *)message{
  35. return @"YOUPAILCMessageTxtContentView";//让礼物和贴图一样的形势发送
  36. }
  37. - (CGSize)contentSize:(NIMMessageModel *)model cellWidth:(CGFloat)width{
  38. CGFloat topTitleHeight =[self.title heightWithFont:LCFont(14.0f) padding:3.0 constrainedToWidth:243.0f - 24.0f];
  39. CGFloat currentY = topTitleHeight+10.0f;
  40. if (![self.txt1 isEqualToString:@""]) {
  41. CGFloat txtOneHeight =[self.txt1 heightWithFont:LCFont(11.0f) padding:3.0 constrainedToWidth:243.0f - 24.0f];
  42. currentY +=txtOneHeight;
  43. }
  44. if ([self.fields isKindOfClass:[NSArray class]] && self.fields.count>0) {
  45. // currentY += 5.0f;
  46. for (NSDictionary* dict in self.fields) {
  47. NSString* name = [dict objectForKey:@"n"];
  48. NSString* value = [dict objectForKey:@"v"];
  49. NSString* dataStr = [NSString stringWithFormat:@"%@: %@",name,value];
  50. CGFloat dataLabelHeight =[dataStr heightWithFont:LCFont(11.0f) padding:3.0 constrainedToWidth:243.0f - 24.0f];
  51. currentY +=dataLabelHeight+5;
  52. }
  53. }
  54. if (![self.txt2 isEqualToString:@""]) {
  55. CGFloat txtTwoHeight =[self.txt2 heightWithFont:LCFont(11.0f) padding:3.0 constrainedToWidth:243.0f - 24.0f];
  56. currentY += txtTwoHeight + 5.0f;
  57. }
  58. currentY+=10;
  59. if (self.link_type!=0) {
  60. currentY +=32.0f;
  61. }
  62. return CGSizeMake(KScreenWidth, currentY);
  63. }
  64. - (UIEdgeInsets)contentViewInsets:(NIMMessage *)message
  65. {
  66. return UIEdgeInsetsZero;
  67. // CGFloat bubblePaddingForImage = 3.f;
  68. // CGFloat bubbleArrowWidthForImage = 5.f;
  69. // if (message.isOutgoingMsg) {
  70. // return UIEdgeInsetsMake(bubblePaddingForImage,bubblePaddingForImage,bubblePaddingForImage,bubblePaddingForImage + bubbleArrowWidthForImage);
  71. // }else{
  72. // return UIEdgeInsetsMake(bubblePaddingForImage,bubblePaddingForImage + bubbleArrowWidthForImage, bubblePaddingForImage,bubblePaddingForImage);
  73. // }
  74. }
  75. @end