NIMCellLayoutConfig.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // NIMSessionDefaultConfig.m
  3. // NIMKit
  4. //
  5. // Created by chris.
  6. // Copyright (c) 2015年 NetEase. All rights reserved.
  7. //
  8. #import "NIMCellLayoutConfig.h"
  9. #import "NIMSessionMessageContentView.h"
  10. #import "NIMSessionUnknowContentView.h"
  11. #import "M80AttributedLabel+NIMKit.h"
  12. #import "NIMKitUtil.h"
  13. #import "UIImage+NIMKit.h"
  14. #import "NIMMessageModel.h"
  15. #import "NIMBaseSessionContentConfig.h"
  16. #import "NIMKit.h"
  17. @interface NIMCellLayoutConfig()
  18. @end
  19. @implementation NIMCellLayoutConfig
  20. - (CGSize)contentSize:(NIMMessageModel *)model cellWidth:(CGFloat)cellWidth{
  21. id<NIMSessionContentConfig>config = [[NIMSessionContentConfigFactory sharedFacotry] configBy:model.message];
  22. return [config contentSize:cellWidth message:model.message];
  23. }
  24. - (NSString *)cellContent:(NIMMessageModel *)model{
  25. id<NIMSessionContentConfig>config = [[NIMSessionContentConfigFactory sharedFacotry] configBy:model.message];
  26. NSString *cellContent = [config cellContent:model.message];
  27. return cellContent.length ? cellContent : @"NIMSessionUnknowContentView";
  28. }
  29. - (UIEdgeInsets)contentViewInsets:(NIMMessageModel *)model{
  30. id<NIMSessionContentConfig>config = [[NIMSessionContentConfigFactory sharedFacotry] configBy:model.message];
  31. return [config contentViewInsets:model.message];
  32. }
  33. - (UIEdgeInsets)cellInsets:(NIMMessageModel *)model
  34. {
  35. if ([[self cellContent:model] isEqualToString:@"NIMSessionNotificationContentView"]) {
  36. return UIEdgeInsetsMake(0, 0, 10, 0);
  37. }
  38. CGFloat cellTopToBubbleTop = 3;
  39. CGFloat otherNickNameHeight = 20;
  40. CGFloat otherBubbleOriginX = [self shouldShowAvatar:model]? 55 : 0;
  41. CGFloat cellBubbleButtomToCellButtom = 13;
  42. if ([self shouldShowNickName:model])
  43. {
  44. //要显示名字
  45. return UIEdgeInsetsMake(cellTopToBubbleTop + otherNickNameHeight ,otherBubbleOriginX,cellBubbleButtomToCellButtom, 0);
  46. }
  47. else
  48. {
  49. return UIEdgeInsetsMake(cellTopToBubbleTop,otherBubbleOriginX,cellBubbleButtomToCellButtom, 0);
  50. }
  51. }
  52. - (BOOL)shouldShowAvatar:(NIMMessageModel *)model
  53. {
  54. return [[NIMKit sharedKit].config setting:model.message].showAvatar;
  55. }
  56. - (BOOL)shouldShowNickName:(NIMMessageModel *)model{
  57. NIMMessage *message = model.message;
  58. if (message.messageType == NIMMessageTypeNotification)
  59. {
  60. NIMNotificationType type = [(NIMNotificationObject *)message.messageObject notificationType];
  61. if (type == NIMNotificationTypeTeam) {
  62. return NO;
  63. }
  64. }
  65. if (message.messageType == NIMMessageTypeTip) {
  66. return NO;
  67. }
  68. return (!message.isOutgoingMsg && message.session.sessionType == NIMSessionTypeTeam);
  69. }
  70. - (BOOL)shouldShowLeft:(NIMMessageModel *)model
  71. {
  72. return !model.message.isOutgoingMsg;
  73. }
  74. - (CGPoint)avatarMargin:(NIMMessageModel *)model
  75. {
  76. return CGPointMake(8.f, 0.f);
  77. }
  78. - (CGSize)avatarSize:(NIMMessageModel *)model
  79. {
  80. return CGSizeMake(42, 42);
  81. }
  82. - (CGPoint)nickNameMargin:(NIMMessageModel *)model
  83. {
  84. return [self shouldShowAvatar:model] ? CGPointMake(57.f, -3.f) : CGPointMake(10.f, -3.f);
  85. }
  86. - (NSArray *)customViews:(NIMMessageModel *)model
  87. {
  88. return nil;
  89. }
  90. - (BOOL)disableRetryButton:(NIMMessageModel *)model
  91. {
  92. if (!model.message.isReceivedMsg)
  93. {
  94. return model.message.deliveryState != NIMMessageDeliveryStateFailed;
  95. }
  96. else
  97. {
  98. return model.message.attachmentDownloadState != NIMMessageAttachmentDownloadStateFailed;
  99. }
  100. }
  101. @end