Fix handling feed

This commit is contained in:
Arkadiusz Fal 2022-12-14 17:23:04 +01:00
parent 2812ea0301
commit b55c6f8619
4 changed files with 14 additions and 30 deletions

View File

@ -34,30 +34,7 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
func setAccount(_ account: Account) { func setAccount(_ account: Account) {
self.account = account self.account = account
wipeResources()
configure() 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() { func configure() {
@ -162,7 +139,11 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
return CommentsPage(comments: comments, nextPage: nextPage, disabled: disabled) return CommentsPage(comments: comments, nextPage: nextPage, disabled: disabled)
} }
if account.token.isNil || account.token!.isEmpty {
updateToken() updateToken()
} else {
FeedModel.shared.onAccountChange()
}
} }
func updateToken(force: Bool = false) { func updateToken(force: Bool = false) {

View File

@ -26,7 +26,6 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
func setAccount(_ account: Account) { func setAccount(_ account: Account) {
self.account = account self.account = account
wipeResources()
configure() configure()
} }
@ -108,8 +107,10 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
content.json.arrayValue.compactMap { self.extractUserPlaylist(from: $0) } content.json.arrayValue.compactMap { self.extractUserPlaylist(from: $0) }
} }
if account.token.isNil { if account.token.isNil || account.token!.isEmpty {
updateToken() updateToken()
} else {
FeedModel.shared.loadResources(force: true)
} }
} }

View File

@ -106,6 +106,12 @@ final class FeedModel: ObservableObject, CacheModel {
loadFeed(force: true, paginating: true) loadFeed(force: true, paginating: true)
} }
func onAccountChange() {
reset()
loadResources(force: true)
calculateUnwatchedFeed()
}
func calculateUnwatchedFeed() { func calculateUnwatchedFeed() {
guard let account = accounts.current, accounts.signedIn else { return } guard let account = accounts.current, accounts.signedIn else { return }
let feed = cacheModel.retrieveFeed(account: account) let feed = cacheModel.retrieveFeed(account: account)

View File

@ -22,10 +22,6 @@ struct FeedView: View {
.onAppear { .onAppear {
feed.loadResources() feed.loadResources()
} }
.onChange(of: accounts.current) { _ in
feed.reset()
feed.loadResources(force: true)
}
#if os(iOS) #if os(iOS)
.refreshControl { refreshControl in .refreshControl { refreshControl in
feed.loadResources(force: true) { feed.loadResources(force: true) {