mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 01:22:46 +02:00
Add loading view
This commit is contained in:
@@ -22,6 +22,7 @@ final class PollHistoryService: PollHistoryServiceProtocol {
|
||||
private let room: MXRoom
|
||||
private let pollsSubject: PassthroughSubject<TimelinePollDetails, Never> = .init()
|
||||
private let errorSubject: PassthroughSubject<Error, Never> = .init()
|
||||
private let isFetchingSubject: PassthroughSubject<Bool, Never> = .init()
|
||||
|
||||
private var listner: Any?
|
||||
private var timeline: MXEventTimeline?
|
||||
@@ -36,12 +37,16 @@ final class PollHistoryService: PollHistoryServiceProtocol {
|
||||
errorSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
var isFetching: AnyPublisher<Bool, Never> {
|
||||
isFetchingSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(room: MXRoom) {
|
||||
self.room = room
|
||||
self.targetTimestamp = Date().addingTimeInterval(-TimeInterval(Constants.daysToSync) * Constants.oneDayInSeconds)
|
||||
}
|
||||
|
||||
func startFetching() {
|
||||
func next() {
|
||||
guard timeline == nil else {
|
||||
paginate()
|
||||
return
|
||||
@@ -81,12 +86,14 @@ private extension PollHistoryService {
|
||||
return
|
||||
}
|
||||
|
||||
#warning("to be removed probably?")
|
||||
timeline.resetPagination()
|
||||
|
||||
isFetchingSubject.send(true)
|
||||
timeline.paginate(Constants.pageSize,
|
||||
direction: .backwards,
|
||||
onlyFromStore: false) { response in
|
||||
onlyFromStore: false) { [weak self] response in
|
||||
self?.isFetchingSubject.send(false)
|
||||
|
||||
switch response {
|
||||
case .success:
|
||||
#warning("Go on with pagination...")
|
||||
|
||||
@@ -27,11 +27,15 @@ final class MockPollHistoryService: PollHistoryServiceProtocol {
|
||||
Empty().eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
func startFetching() {
|
||||
func next() {
|
||||
for poll in activePollsData + pastPollsData {
|
||||
polls.send(poll)
|
||||
}
|
||||
}
|
||||
|
||||
var isFetching: AnyPublisher<Bool, Never> {
|
||||
Just(false).eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
var activePollsData: [TimelinePollDetails] = (1..<10)
|
||||
.map { index in
|
||||
|
||||
@@ -17,8 +17,17 @@
|
||||
import Combine
|
||||
|
||||
protocol PollHistoryServiceProtocol {
|
||||
/// Publishes poll data as soon they are found in the timeline.
|
||||
/// Updates are also published here, so clients needs to address duplicates.
|
||||
var pollHistory: AnyPublisher<TimelinePollDetails, Never> { get }
|
||||
|
||||
/// Publishes whatever errors produced during the sync.
|
||||
var error: AnyPublisher<Error, Never> { get }
|
||||
|
||||
func startFetching()
|
||||
/// Ask to fetch the next batch of polls.
|
||||
/// Concrete implementations can decide what a batch is.
|
||||
func next()
|
||||
|
||||
/// Inform the whenever a new batch of polls starts or ends.
|
||||
var isFetching: AnyPublisher<Bool, Never> { get }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user