diff --git a/Model/Applications/InvidiousAPI.swift b/Model/Applications/InvidiousAPI.swift index 65f18a82..205919f9 100644 --- a/Model/Applications/InvidiousAPI.swift +++ b/Model/Applications/InvidiousAPI.swift @@ -34,30 +34,7 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI { func setAccount(_ account: Account) { self.account = account - wipeResources() configure() - - if !account.anonymous { - validate() - } - } - - func validate() { - validateSID() - } - - func validateSID() { - guard signedIn, !(account.token?.isEmpty ?? true) else { - return - } - - feed? - .load() - .onFailure { _ in - self.updateToken(force: true) - } - - wipeResources() } func configure() { @@ -162,7 +139,11 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI { return CommentsPage(comments: comments, nextPage: nextPage, disabled: disabled) } - updateToken() + if account.token.isNil || account.token!.isEmpty { + updateToken() + } else { + FeedModel.shared.onAccountChange() + } } func updateToken(force: Bool = false) { diff --git a/Model/Applications/PipedAPI.swift b/Model/Applications/PipedAPI.swift index 2fcacb75..76993481 100644 --- a/Model/Applications/PipedAPI.swift +++ b/Model/Applications/PipedAPI.swift @@ -26,7 +26,6 @@ final class PipedAPI: Service, ObservableObject, VideosAPI { func setAccount(_ account: Account) { self.account = account - wipeResources() configure() } @@ -108,8 +107,10 @@ final class PipedAPI: Service, ObservableObject, VideosAPI { content.json.arrayValue.compactMap { self.extractUserPlaylist(from: $0) } } - if account.token.isNil { + if account.token.isNil || account.token!.isEmpty { updateToken() + } else { + FeedModel.shared.loadResources(force: true) } } diff --git a/Model/FeedModel.swift b/Model/FeedModel.swift index 98200ae1..41407ce4 100644 --- a/Model/FeedModel.swift +++ b/Model/FeedModel.swift @@ -106,6 +106,12 @@ final class FeedModel: ObservableObject, CacheModel { loadFeed(force: true, paginating: true) } + func onAccountChange() { + reset() + loadResources(force: true) + calculateUnwatchedFeed() + } + func calculateUnwatchedFeed() { guard let account = accounts.current, accounts.signedIn else { return } let feed = cacheModel.retrieveFeed(account: account) diff --git a/Shared/Subscriptions/FeedView.swift b/Shared/Subscriptions/FeedView.swift index ddcea0a5..15eac61d 100644 --- a/Shared/Subscriptions/FeedView.swift +++ b/Shared/Subscriptions/FeedView.swift @@ -22,10 +22,6 @@ struct FeedView: View { .onAppear { feed.loadResources() } - .onChange(of: accounts.current) { _ in - feed.reset() - feed.loadResources(force: true) - } #if os(iOS) .refreshControl { refreshControl in feed.loadResources(force: true) {