@@ -101,6 +101,7 @@ public struct MessageDisplayOptions {
101101 public let messageLinkDisplayResolver : ( ChatMessage ) -> [ NSAttributedString . Key : Any ]
102102 public let spacerWidth : ( CGFloat ) -> CGFloat
103103 public let reactionsTopPadding : ( ChatMessage ) -> CGFloat
104+ public let dateSeparator : ( ChatMessage , ChatMessage ) -> Date ?
104105
105106 public init (
106107 showAvatars: Bool = true ,
@@ -118,7 +119,8 @@ public struct MessageDisplayOptions {
118119 messageLinkDisplayResolver: @escaping ( ChatMessage ) -> [ NSAttributedString . Key : Any ] = MessageDisplayOptions
119120 . defaultLinkDisplay,
120121 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
122124 ) {
123125 self . showAvatars = showAvatars
124126 self . showAuthorName = showAuthorName
@@ -135,11 +137,25 @@ public struct MessageDisplayOptions {
135137 self . showAvatarsInGroups = showAvatarsInGroups ?? showAvatars
136138 self . reactionsTopPadding = reactionsTopPadding
137139 self . newMessagesSeparatorSize = newMessagesSeparatorSize
140+ self . dateSeparator = dateSeparator
138141 }
139142
140143 public func showAvatars( for channel: ChatChannel ) -> Bool {
141144 channel. isDirectMessageChannel ? showAvatars : showAvatarsInGroups
142145 }
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+ }
143159
144160 public static var defaultLinkDisplay : ( ChatMessage ) -> [ NSAttributedString . Key : Any ] {
145161 { _ in
0 commit comments