mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-25 01:31:04 +00:00
StatusDataController: update to fresh statuses data on user profile
This commit is contained in:
parent
43a4551d9b
commit
a9e935016f
4 changed files with 38 additions and 18 deletions
|
@ -65,7 +65,9 @@ public struct AccountDetailView: View {
|
|||
if viewModel.selectedTab == .statuses {
|
||||
pinnedPostsView
|
||||
}
|
||||
StatusesListView(fetcher: viewModel, client: client, routerPath: routerPath)
|
||||
StatusesListView(fetcher: viewModel,
|
||||
client: client,
|
||||
routerPath: routerPath)
|
||||
case .followedTags:
|
||||
tagsListView
|
||||
case .lists:
|
||||
|
|
|
@ -157,6 +157,7 @@ class AccountDetailViewModel: ObservableObject, StatusesFetcher {
|
|||
onlyMedia: selectedTab == .media ? true : nil,
|
||||
excludeReplies: selectedTab == .statuses && !isCurrentUser ? true : nil,
|
||||
pinned: nil))
|
||||
StatusDataControllerProvider.shared.updateDataControllers(for: statuses, client: client)
|
||||
if selectedTab == .statuses {
|
||||
pinned =
|
||||
try await client.get(endpoint: Accounts.statuses(id: accountId,
|
||||
|
@ -165,10 +166,13 @@ class AccountDetailViewModel: ObservableObject, StatusesFetcher {
|
|||
onlyMedia: nil,
|
||||
excludeReplies: nil,
|
||||
pinned: true))
|
||||
StatusDataControllerProvider.shared.updateDataControllers(for: pinned, client: client)
|
||||
}
|
||||
if isCurrentUser {
|
||||
(favorites, favoritesNextPage) = try await client.getWithLink(endpoint: Accounts.favorites(sinceId: nil))
|
||||
(bookmarks, bookmarksNextPage) = try await client.getWithLink(endpoint: Accounts.bookmarks(sinceId: nil))
|
||||
StatusDataControllerProvider.shared.updateDataControllers(for: favorites, client: client)
|
||||
StatusDataControllerProvider.shared.updateDataControllers(for: bookmarks, client: client)
|
||||
}
|
||||
reloadTabState()
|
||||
} catch {
|
||||
|
@ -191,6 +195,7 @@ class AccountDetailViewModel: ObservableObject, StatusesFetcher {
|
|||
excludeReplies: selectedTab == .statuses && !isCurrentUser ? true : nil,
|
||||
pinned: nil))
|
||||
statuses.append(contentsOf: newStatuses)
|
||||
StatusDataControllerProvider.shared.updateDataControllers(for: newStatuses, client: client)
|
||||
tabState = .statuses(statusesState: .display(statuses: statuses,
|
||||
nextPageState: newStatuses.count < 20 ? .none : .hasNextPage))
|
||||
case .favorites:
|
||||
|
@ -198,11 +203,13 @@ class AccountDetailViewModel: ObservableObject, StatusesFetcher {
|
|||
let newFavorites: [Status]
|
||||
(newFavorites, favoritesNextPage) = try await client.getWithLink(endpoint: Accounts.favorites(sinceId: nextPageId))
|
||||
favorites.append(contentsOf: newFavorites)
|
||||
StatusDataControllerProvider.shared.updateDataControllers(for: newFavorites, client: client)
|
||||
tabState = .statuses(statusesState: .display(statuses: favorites, nextPageState: .hasNextPage))
|
||||
case .bookmarks:
|
||||
guard let nextPageId = bookmarksNextPage?.maxId else { return }
|
||||
let newBookmarks: [Status]
|
||||
(newBookmarks, bookmarksNextPage) = try await client.getWithLink(endpoint: Accounts.bookmarks(sinceId: nextPageId))
|
||||
StatusDataControllerProvider.shared.updateDataControllers(for: newBookmarks, client: client)
|
||||
bookmarks.append(contentsOf: newBookmarks)
|
||||
tabState = .statuses(statusesState: .display(statuses: bookmarks, nextPageState: .hasNextPage))
|
||||
case .followedTags, .lists:
|
||||
|
|
|
@ -38,6 +38,14 @@ public final class StatusDataControllerProvider {
|
|||
cache[key] = controller
|
||||
return controller
|
||||
}
|
||||
|
||||
public func updateDataControllers(for statuses: [Status], client: Client) {
|
||||
for status in statuses {
|
||||
let realStatus: AnyStatus = status.reblog ?? status
|
||||
let controller = dataController(for: realStatus, client: client)
|
||||
controller.updateFrom(status: realStatus, publishUpdate: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
|
|
@ -13,7 +13,10 @@ public struct StatusesListView<Fetcher>: View where Fetcher: StatusesFetcher {
|
|||
private let routerPath: RouterPath
|
||||
private let client: Client
|
||||
|
||||
public init(fetcher: Fetcher, client: Client, routerPath: RouterPath, isRemote: Bool = false) {
|
||||
public init(fetcher: Fetcher,
|
||||
client: Client,
|
||||
routerPath: RouterPath,
|
||||
isRemote: Bool = false) {
|
||||
self.fetcher = fetcher
|
||||
self.isRemote = isRemote
|
||||
self.client = client
|
||||
|
|
Loading…
Reference in a new issue