Add live synced days

This commit is contained in:
Alfonso Grillo
2023-01-25 15:12:19 +01:00
parent 1f953c8a93
commit 94ca5e3ccc
5 changed files with 41 additions and 11 deletions
@@ -29,7 +29,7 @@ final class PollHistoryService: PollHistoryServiceProtocol {
private var pollAggregators: [String: PollAggregator] = [:]
private var targetTimestamp: Date?
private var oldestEventDate: Date = .distantFuture
private var oldestEventDateSubject: CurrentValueSubject<Date, Never> = .init(Date.distantFuture)
private var currentBatchSubject: PassthroughSubject<TimelinePollDetails, Error>?
var updates: AnyPublisher<TimelinePollDetails, Never> {
@@ -54,6 +54,10 @@ final class PollHistoryService: PollHistoryServiceProtocol {
var hasNextBatch: Bool {
timeline.canPaginate(.backwards)
}
var fetchedUpTo: AnyPublisher<Date, Never> {
oldestEventDateSubject.eraseToAnyPublisher()
}
}
private extension PollHistoryService {
@@ -135,13 +139,20 @@ private extension PollHistoryService {
}
return oldestEventDate <= targetTimestamp
}
var oldestEventDate: Date {
get {
oldestEventDateSubject.value
}
set {
oldestEventDateSubject.send(newValue)
}
}
}
private extension Date {
private static let oneDayInSeconds: TimeInterval = 8.6 * 10e3
func subtractingDays(_ days: UInt) -> Date {
addingTimeInterval(-TimeInterval(days) * Self.oneDayInSeconds)
addingTimeInterval(-TimeInterval(days) * PollHistoryConstants.oneDayInSeconds)
}
}