NIMNotificationContentConfig.m 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // NIMNotificationContentConfig.m
  3. // NIMKit
  4. //
  5. // Created by amao on 9/15/15.
  6. // Copyright (c) 2015 NetEase. All rights reserved.
  7. //
  8. #import "NIMNotificationContentConfig.h"
  9. #import "M80AttributedLabel+NIMKit.h"
  10. #import "NIMKitUtil.h"
  11. #import "NIMUnsupportContentConfig.h"
  12. #import "NIMKit.h"
  13. @implementation NIMNotificationContentConfig
  14. - (CGSize)contentSize:(CGFloat)cellWidth message:(NIMMessage *)message
  15. {
  16. NIMNotificationObject *object = (NIMNotificationObject*)message.messageObject;
  17. NSAssert([object isKindOfClass:[NIMNotificationObject class]], @"message should be notification");
  18. CGSize contentSize = CGSizeZero;
  19. switch (object.notificationType) {
  20. case NIMNotificationTypeTeam:
  21. case NIMNotificationTypeChatroom:
  22. {
  23. CGFloat TeamNotificationMessageWidth = cellWidth;
  24. UILabel *label = [[UILabel alloc] init];
  25. label.text = [NIMKitUtil messageTipContent:message];
  26. label.font = [[NIMKit sharedKit].config setting:message].font;
  27. label.numberOfLines = 0;
  28. CGFloat padding = [NIMKit sharedKit].config.maxNotificationTipPadding;
  29. CGSize size = [label sizeThatFits:CGSizeMake(cellWidth - 2 * padding, CGFLOAT_MAX)];
  30. CGFloat cellPadding = 11.f;
  31. contentSize = CGSizeMake(TeamNotificationMessageWidth, size.height + 2 * cellPadding);
  32. break;
  33. }
  34. case NIMNotificationTypeNetCall:{
  35. M80AttributedLabel *label = [[M80AttributedLabel alloc] initWithFrame:CGRectZero];
  36. label.autoDetectLinks = NO;
  37. label.font = [[NIMKit sharedKit].config setting:message].font;
  38. NSString *text = [NIMKitUtil messageTipContent:message];
  39. [label nim_setText:text];
  40. CGFloat msgBubbleMaxWidth = (cellWidth - 130);
  41. CGFloat bubbleLeftToContent = 14;
  42. CGFloat contentRightToBubble = 14;
  43. CGFloat msgContentMaxWidth = (msgBubbleMaxWidth - contentRightToBubble - bubbleLeftToContent);
  44. contentSize = [label sizeThatFits:CGSizeMake(msgContentMaxWidth, CGFLOAT_MAX)];
  45. break;
  46. }
  47. default:
  48. {
  49. NIMUnsupportContentConfig *config = [[NIMUnsupportContentConfig alloc] init];
  50. contentSize = [config contentSize:cellWidth message:message];
  51. NSAssert(0, @"not supported notification type %zd",object.notificationType);
  52. }
  53. break;
  54. }
  55. return contentSize;
  56. }
  57. - (NSString *)cellContent:(NIMMessage *)message
  58. {
  59. NIMNotificationObject *object = (NIMNotificationObject*)message.messageObject;
  60. NSAssert([object isKindOfClass:[NIMNotificationObject class]], @"message should be notification");
  61. switch (object.notificationType) {
  62. case NIMNotificationTypeTeam:
  63. case NIMNotificationTypeChatroom:
  64. return @"NIMSessionNotificationContentView";
  65. case NIMNotificationTypeNetCall:
  66. return @"NIMSessionNetChatNotifyContentView";
  67. case NIMNotificationTypeUnsupport:
  68. return @"NIMSessionUnknowContentView";
  69. default:
  70. break;
  71. }
  72. //modify by leo v1.0.7 云信新sdk
  73. return @"NIMSessionUnknowContentView";
  74. }
  75. - (UIEdgeInsets)contentViewInsets:(NIMMessage *)message
  76. {
  77. return [[NIMKit sharedKit].config setting:message].contentInsets;
  78. }
  79. @end