@@ -101,6 +101,7 @@ public struct MessageDisplayOptions {
101
101
public let messageLinkDisplayResolver : ( ChatMessage ) -> [ NSAttributedString . Key : Any ]
102
102
public let spacerWidth : ( CGFloat ) -> CGFloat
103
103
public let reactionsTopPadding : ( ChatMessage ) -> CGFloat
104
+ public let dateSeparator : ( ChatMessage , ChatMessage ) -> Date ?
104
105
105
106
public init (
106
107
showAvatars: Bool = true ,
@@ -118,7 +119,8 @@ public struct MessageDisplayOptions {
118
119
messageLinkDisplayResolver: @escaping ( ChatMessage ) -> [ NSAttributedString . Key : Any ] = MessageDisplayOptions
119
120
. defaultLinkDisplay,
120
121
spacerWidth: @escaping ( CGFloat ) -> CGFloat = MessageDisplayOptions . defaultSpacerWidth,
121
- reactionsTopPadding: @escaping ( ChatMessage ) -> CGFloat = MessageDisplayOptions . defaultReactionsTopPadding
122
+ reactionsTopPadding: @escaping ( ChatMessage ) -> CGFloat = MessageDisplayOptions . defaultReactionsTopPadding,
123
+ dateSeparator: @escaping ( ChatMessage , ChatMessage ) -> Date ? = MessageDisplayOptions . defaultDateSeparator
122
124
) {
123
125
self . showAvatars = showAvatars
124
126
self . showAuthorName = showAuthorName
@@ -135,11 +137,25 @@ public struct MessageDisplayOptions {
135
137
self . showAvatarsInGroups = showAvatarsInGroups ?? showAvatars
136
138
self . reactionsTopPadding = reactionsTopPadding
137
139
self . newMessagesSeparatorSize = newMessagesSeparatorSize
140
+ self . dateSeparator = dateSeparator
138
141
}
139
142
140
143
public func showAvatars( for channel: ChatChannel ) -> Bool {
141
144
channel. isDirectMessageChannel ? showAvatars : showAvatarsInGroups
142
145
}
146
+
147
+ public static func defaultDateSeparator( message: ChatMessage , previous: ChatMessage ) -> Date ? {
148
+ let isDifferentDay = !Calendar. current. isDate (
149
+ message. createdAt,
150
+ equalTo: previous. createdAt,
151
+ toGranularity: . day
152
+ )
153
+ if isDifferentDay {
154
+ return message. createdAt
155
+ } else {
156
+ return nil
157
+ }
158
+ }
143
159
144
160
public static var defaultLinkDisplay : ( ChatMessage ) -> [ NSAttributedString . Key : Any ] {
145
161
{ _ in
0 commit comments