NTESWhiteboardAttachment.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // NTESWhiteboardAttachment.m
  3. // NIM
  4. //
  5. // Created by 高峰 on 15/7/28.
  6. // Copyright (c) 2015年 Netease. All rights reserved.
  7. //
  8. #import "NTESWhiteboardAttachment.h"
  9. #import "M80AttributedLabel.h"
  10. #import "NTESSessionUtil.h"
  11. @implementation NTESWhiteboardAttachment
  12. - (NSString *)encodeAttachment
  13. {
  14. NSDictionary *dict = @{CMType : @(CustomMessageTypeWhiteboard),
  15. CMData : @{CMFlag:@(self.flag)}};
  16. NSData *data = [NSJSONSerialization dataWithJSONObject:dict
  17. options:0
  18. error:nil];
  19. NSString *content = nil;
  20. if (data) {
  21. content = [[NSString alloc] initWithData:data
  22. encoding:NSUTF8StringEncoding];
  23. }
  24. return content;
  25. }
  26. - (NSString *)formatedMessage{
  27. NSString *msg = @"";
  28. switch (self.flag) {
  29. case CustomWhiteboardFlagInvite:
  30. msg = @"我发起了白板演示";
  31. break;
  32. case CustomWhiteboardFlagClose:
  33. msg = @"白板演示已结束";
  34. default:
  35. break;
  36. }
  37. return msg;
  38. }
  39. - (NSString *)cellContent:(NIMMessage *)message{
  40. NSString *content;
  41. switch (self.flag) {
  42. case CustomWhiteboardFlagInvite:
  43. content = @"NTESSessionWhiteBoardContentView";
  44. break;
  45. case CustomWhiteboardFlagClose:
  46. content = @"NTESSessionTipContentView";
  47. break;
  48. default:
  49. break;
  50. }
  51. return content;
  52. }
  53. - (BOOL)shouldShowAvatar
  54. {
  55. switch (self.flag) {
  56. case CustomWhiteboardFlagInvite:
  57. return YES;
  58. case CustomWhiteboardFlagClose:
  59. return NO;
  60. default:
  61. break;
  62. }
  63. return NO;
  64. }
  65. - (CGSize)contentSize:(NIMMessage *)message cellWidth:(CGFloat)width{
  66. CGSize contentSize;
  67. switch (self.flag) {
  68. case CustomWhiteboardFlagInvite:{
  69. M80AttributedLabel *label = [[M80AttributedLabel alloc] initWithFrame:CGRectZero];
  70. label.autoDetectLinks = NO;
  71. label.font = [UIFont systemFontOfSize:Message_Font_Size];
  72. [label setText:self.formatedMessage];
  73. UIImage *image = [UIImage imageNamed:@"icon_whiteboard_session_msg"];
  74. CGFloat msgBubbleMaxWidth = (UIScreenWidth - 130);
  75. CGFloat bubbleLeftToContent = 14;
  76. CGFloat contentRightToBubble = 14;
  77. CGFloat msgContentMaxWidth = (msgBubbleMaxWidth - contentRightToBubble - bubbleLeftToContent);
  78. CGFloat customWhiteBorardMessageImageRightToText = 10.f;
  79. CGSize labelSize = [label sizeThatFits:CGSizeMake(msgContentMaxWidth, CGFLOAT_MAX)];
  80. contentSize = CGSizeMake(labelSize.width + image.size.width + customWhiteBorardMessageImageRightToText, labelSize.height);
  81. break;
  82. }
  83. case CustomWhiteboardFlagClose:{
  84. CGFloat messageWidth = width;
  85. CGFloat messageHeight = 40;
  86. contentSize = CGSizeMake(messageWidth, messageHeight);
  87. break;
  88. }
  89. default:
  90. break;
  91. }
  92. return contentSize;
  93. }
  94. - (UIEdgeInsets)contentViewInsets:(NIMMessage *)message
  95. {
  96. if (self.flag == CustomWhiteboardFlagClose) {
  97. return UIEdgeInsetsZero;
  98. }else{
  99. CGFloat selfBubbleTopToContentForBoard = 11.f;
  100. CGFloat selfBubbleLeftToContentForBoard = 11.f;
  101. CGFloat selfContentButtomToBubbleForBoard = 9.f;
  102. CGFloat selfBubbleRightToContentForBoard = 15.f;
  103. CGFloat otherBubbleTopToContentForBoard = 11.f;
  104. CGFloat otherBubbleLeftToContentForBoard = 15.f;
  105. CGFloat otherContentButtomToBubbleForBoard = 9.f;
  106. CGFloat otherContentRightToBubbleForBoard = 9.f;
  107. return message.isOutgoingMsg ? UIEdgeInsetsMake(selfBubbleTopToContentForBoard,
  108. selfBubbleLeftToContentForBoard,
  109. selfContentButtomToBubbleForBoard,
  110. selfBubbleRightToContentForBoard):
  111. UIEdgeInsetsMake(otherBubbleTopToContentForBoard,
  112. otherBubbleLeftToContentForBoard,
  113. otherContentButtomToBubbleForBoard,
  114. otherContentRightToBubbleForBoard);
  115. }
  116. }
  117. - (BOOL)canBeForwarded
  118. {
  119. return NO;
  120. }
  121. - (BOOL)canBeRevoked
  122. {
  123. return NO;
  124. }
  125. @end