0.10.6
This commit is contained in:
commit
92660a4ba0
228 files changed
+24496
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import Foundation
|
||||
|
||||
/// A cached presentation row for the selected chat. Building day boundaries
|
||||
/// once per message mutation avoids walking the full history during every
|
||||
/// scroll-position or composer-state update.
|
||||
struct ChatTimelineEntry: Identifiable, Hashable, Sendable {
|
||||
let message: ChatMessage
|
||||
let startsNewDay: Bool
|
||||
|
||||
var id: String { message.id }
|
||||
|
||||
static func make(
|
||||
from messages: [ChatMessage],
|
||||
calendar: Calendar = .autoupdatingCurrent
|
||||
) -> [ChatTimelineEntry] {
|
||||
var previousTimestamp: Date?
|
||||
return messages.map { message in
|
||||
let startsNewDay = previousTimestamp.map {
|
||||
!calendar.isDate($0, inSameDayAs: message.timestamp)
|
||||
} ?? true
|
||||
previousTimestamp = message.timestamp
|
||||
return ChatTimelineEntry(
|
||||
message: message,
|
||||
startsNewDay: startsNewDay
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user