YOUPAILCGiftAttachment.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // YOUPAILCGiftAttachment.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/9/22.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCGiftAttachment.h"
  9. @implementation YOUPAILCGiftAttachment
  10. - (NSString *)encodeAttachment
  11. {
  12. NSDictionary *dict = @{
  13. CMType : @(CustomGift),
  14. CMData : @{
  15. CMGiftId: self.gift_id ?[NSNumber numberWithInteger:self.gift_id]:@0,
  16. CMGiftName: self.gift_name?self.gift_name:@"",
  17. CMGiftUrl: self.gift_url ?self.gift_url:@"",
  18. CMGiftCount: self.gift_count ?[NSNumber numberWithInteger:self.gift_count]:@0,
  19. CMFrom: self.from_uid?[NSNumber numberWithInteger:self.from_uid]:@0,
  20. CMTo: self.to_uid?[NSNumber numberWithInteger:self.to_uid]:@0,
  21. CMLink_type: self.link_type?[NSNumber numberWithInteger:self.link_type]:@0,
  22. CMLink_url: self.link_url?self.link_url:@"",
  23. CMMd5String:self.md5_string ?self.md5_string:@"",
  24. CMGiftSvga:self.gift_svga ?self.gift_svga:@"",
  25. CMGiftType:self.gift_type?[NSNumber numberWithInteger:self.gift_type]:@0,
  26. CMFromNickname:self.from_nickname ?self.from_nickname:@"",
  27. CMSendGiftHide:self.send_gift_hide ?@(self.send_gift_hide):@0,
  28. CMFromAvatar:self.from_avatar ?self.from_avatar:@"",
  29. }
  30. };
  31. NSData *data = [NSJSONSerialization dataWithJSONObject:dict
  32. options:0
  33. error:nil];
  34. NSString *content = nil;
  35. if (data) {
  36. content = [[NSString alloc] initWithData:data
  37. encoding:NSUTF8StringEncoding];
  38. }
  39. return content;
  40. }
  41. - (NSString *)cellContent:(NIMMessage *)message{
  42. return @"YOUPAILCGiftContentView";//让礼物和贴图一样的形势发送
  43. }
  44. - (CGSize)contentSize:(NIMMessageModel *)model cellWidth:(CGFloat)width{
  45. CGFloat height = 77.0f;
  46. CGFloat space = 8.0f;
  47. NSString *giftStr = [NSString stringWithFormat:@"%@x%@",self.gift_name,@(self.gift_count)];
  48. NSString *titleStr = [NSString stringWithFormat:@"%@礼物",self.from_uid == [[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id integerValue] ? @"送出" : @"收到"];
  49. CGFloat titleWidth = [titleStr widthWithFont:LCBoldFont(14) constrainedToHeight:height];
  50. CGFloat giftWidth = [giftStr widthWithFont:LCFont(11) constrainedToHeight:height];
  51. CGFloat textWidth = giftWidth >= titleWidth ? giftWidth : titleWidth;
  52. CGFloat giftBgWidth = 88.0f;
  53. return CGSizeMake(textWidth + space + giftBgWidth, height);
  54. }
  55. - (UIEdgeInsets)contentViewInsets:(NIMMessage *)message
  56. {
  57. return UIEdgeInsetsZero;
  58. // CGFloat bubblePaddingForImage = 3.f;
  59. // CGFloat bubbleArrowWidthForImage = 5.f;
  60. // if (message.isOutgoingMsg) {
  61. // return UIEdgeInsetsMake(bubblePaddingForImage,bubblePaddingForImage,bubblePaddingForImage,bubblePaddingForImage + bubbleArrowWidthForImage);
  62. // }else{
  63. // return UIEdgeInsetsMake(bubblePaddingForImage,bubblePaddingForImage + bubbleArrowWidthForImage, bubblePaddingForImage,bubblePaddingForImage);
  64. // }
  65. }
  66. @end