diff --git a/Tusker/TimelineLikeController.swift b/Tusker/TimelineLikeController.swift index be89f61d35..1bd558c226 100644 --- a/Tusker/TimelineLikeController.swift +++ b/Tusker/TimelineLikeController.swift @@ -29,7 +29,7 @@ actor TimelineLikeController { unowned var delegate: any TimelineLikeControllerDelegate - private(set) var state = State.idle { + private(set) var state = State.notLoadedInitial { willSet { precondition(state.canTransition(to: newValue)) logger.debug("State: \(self.state.debugDescription, privacy: .public) -> \(newValue.debugDescription, privacy: .public)") @@ -41,7 +41,7 @@ actor TimelineLikeController { } func loadInitial() async { - guard state == .idle else { + guard state == .notLoadedInitial else { return } let token = LoadAttemptToken() @@ -120,6 +120,7 @@ actor TimelineLikeController { } enum State: Equatable, CustomDebugStringConvertible { + case notLoadedInitial case idle case loadingInitial(LoadAttemptToken, hasAddedLoadingIndicator: Bool) case loadingNewer(LoadAttemptToken) @@ -128,6 +129,8 @@ actor TimelineLikeController { var debugDescription: String { switch self { + case .notLoadedInitial: + return "notLoadedInitial" case .idle: return "idle" case .loadingInitial(let token, let hasAddedLoadingIndicator): @@ -143,9 +146,16 @@ actor TimelineLikeController { func canTransition(to: State) -> Bool { switch self { + case .notLoadedInitial: + switch to { + case .loadingInitial(_, hasAddedLoadingIndicator: _): + return true + default: + return false + } case .idle: switch to { - case .loadingInitial(_, _), .loadingNewer(_)/*, .waitingForLoadOlderPermission*/, .loadingOlder(_, _): + case .loadingNewer(_)/*, .waitingForLoadOlderPermission*/, .loadingOlder(_, _): return true default: return false