NTESJanKenPonAttachment.m 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // NTESJanKenPonAttachment.m
  3. // NIM
  4. //
  5. // Created by amao on 7/2/15.
  6. // Copyright (c) 2015 Netease. All rights reserved.
  7. //
  8. #import "NTESJanKenPonAttachment.h"
  9. #import "NTESSessionUtil.h"
  10. @implementation NTESJanKenPonAttachment
  11. - (NSString *)encodeAttachment
  12. {
  13. NSDictionary *dict = @{CMType : @(CustomMessageTypeJanKenPon),
  14. CMData : @{CMValue:@(self.value)}};
  15. NSData *data = [NSJSONSerialization dataWithJSONObject:dict
  16. options:0
  17. error:nil];
  18. NSString *content = nil;
  19. if (data) {
  20. content = [[NSString alloc] initWithData:data
  21. encoding:NSUTF8StringEncoding];
  22. }
  23. return content;
  24. }
  25. - (NSString *)cellContent:(NIMMessage *)message{
  26. return @"NTESSessionJankenponContentView";
  27. }
  28. - (CGSize)contentSize:(NIMMessage *)message cellWidth:(CGFloat)width{
  29. return self.showCoverImage.size;
  30. }
  31. - (UIEdgeInsets)contentViewInsets:(NIMMessage *)message
  32. {
  33. if (message.session.sessionType == NIMSessionTypeChatroom)
  34. {
  35. CGFloat bubbleMarginTopForImage = 15.f;
  36. CGFloat bubbleMarginLeftForImage = 12.f;
  37. return UIEdgeInsetsMake(bubbleMarginTopForImage,bubbleMarginLeftForImage,0,0);
  38. }
  39. else
  40. {
  41. CGFloat bubbleMarginForImage = 3.f;
  42. CGFloat bubbleArrowWidthForImage = 5.f;
  43. if (message.isOutgoingMsg) {
  44. return UIEdgeInsetsMake(bubbleMarginForImage,bubbleMarginForImage,bubbleMarginForImage,bubbleMarginForImage + bubbleArrowWidthForImage);
  45. }else{
  46. return UIEdgeInsetsMake(bubbleMarginForImage,bubbleMarginForImage + bubbleArrowWidthForImage, bubbleMarginForImage,bubbleMarginForImage);
  47. }
  48. }
  49. }
  50. - (UIImage *)showCoverImage
  51. {
  52. if (_showCoverImage == nil)
  53. {
  54. UIImage *image;
  55. switch (self.value) {
  56. case CustomJanKenPonValueJan:
  57. image = [UIImage imageNamed:@"custom_msg_jan"];
  58. break;
  59. case CustomJanKenPonValueKen:
  60. image = [UIImage imageNamed:@"custom_msg_ken"];
  61. break;
  62. case CustomJanKenPonValuePon:
  63. image = [UIImage imageNamed:@"custom_msg_pon"];
  64. break;
  65. default:
  66. break;
  67. }
  68. _showCoverImage = image;
  69. }
  70. return _showCoverImage;
  71. }
  72. - (BOOL)canBeRevoked
  73. {
  74. return YES;
  75. }
  76. - (BOOL)canBeForwarded
  77. {
  78. return YES;
  79. }
  80. @end