mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 01:22:46 +02:00
Add live synced days
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,11 @@ final class MockPollHistoryService: PollHistoryServiceProtocol {
|
||||
}
|
||||
|
||||
var hasNextBatch: Bool = true
|
||||
|
||||
var fetchedUpToPublisher: AnyPublisher<Date, Never> = Just(.init()).eraseToAnyPublisher()
|
||||
var fetchedUpTo: AnyPublisher<Date, Never> {
|
||||
fetchedUpToPublisher
|
||||
}
|
||||
}
|
||||
|
||||
private extension MockPollHistoryService {
|
||||
|
||||
@@ -31,4 +31,8 @@ protocol PollHistoryServiceProtocol {
|
||||
/// Returns true every time the service can fetch another batch.
|
||||
/// There is no guarantee the `nextBatch()` returned publisher will publish something anyway.
|
||||
var hasNextBatch: Bool { get }
|
||||
|
||||
/// Publishes the date up to the service is synced (in the past).
|
||||
/// This date doesn't need to be related with any poll event.
|
||||
var fetchedUpTo: AnyPublisher<Date, Never> { get }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user