YOUPAILZGuardAttachment.m 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // YOUPAILZGuardAttachment.m
  3. // TIANYAN
  4. //
  5. // Created by CY on 2021/4/13.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZGuardAttachment.h"
  9. @implementation YOUPAILZGuardAttachment
  10. - (NSString *)encodeAttachment
  11. {
  12. NSDictionary *dict = @{
  13. CMType : @(CustomOnGuard),
  14. CMData : @{
  15. CMGuardName: self.guard_name?self.guard_name:@"",
  16. CMGuardUrl: self.guard_url ?self.guard_url:@"",
  17. CMGuardCount: self.guard_count ?[NSNumber numberWithInteger:self.guard_count]:@0,
  18. CMFrom: self.from_uid?[NSNumber numberWithInteger:self.from_uid]:@0,
  19. CMTo: self.to_uid?[NSNumber numberWithInteger:self.to_uid]:@0,
  20. CMLink_type: self.link_type?[NSNumber numberWithInteger:self.link_type]:@0,
  21. CMLink_url: self.link_url?self.link_url:@"",
  22. CMMd5String: self.md5_string?self.md5_string:@"",
  23. CMGiftSvga: self.gift_svga?self.gift_svga:@"",
  24. CMGiftType: self.gift_type?@(self.gift_type):@0,
  25. CMFromNickname: self.from_nickname?self.from_nickname:@"",
  26. CMFromAvatar: self.from_avatar?self.from_avatar:@"",
  27. CMToNickname: self.to_nickname?self.to_nickname:@"",
  28. CMToAvatar: self.to_avatar?self.to_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 @"YOUPAILZGuardContentView";//让礼物和贴图一样的形势发送
  43. }
  44. - (CGSize)contentSize:(NIMMessageModel *)model cellWidth:(CGFloat)width{
  45. NSString* giftStr = [NSString stringWithFormat:@"收%@",self.guard_name];
  46. CGFloat nameWidth =[giftStr widthWithFont:LCFont(16) constrainedToHeight:48];
  47. return CGSizeMake(20+nameWidth+60+50, 48);
  48. }
  49. - (UIEdgeInsets)contentViewInsets:(NIMMessage *)message
  50. {
  51. return UIEdgeInsetsZero;
  52. // CGFloat bubblePaddingForImage = 3.f;
  53. // CGFloat bubbleArrowWidthForImage = 5.f;
  54. // if (message.isOutgoingMsg) {
  55. // return UIEdgeInsetsMake(bubblePaddingForImage,bubblePaddingForImage,bubblePaddingForImage,bubblePaddingForImage + bubbleArrowWidthForImage);
  56. // }else{
  57. // return UIEdgeInsetsMake(bubblePaddingForImage,bubblePaddingForImage + bubbleArrowWidthForImage, bubblePaddingForImage,bubblePaddingForImage);
  58. // }
  59. }
  60. @end