Differ between local and following-timeline (IOS-235)

This commit is contained in:
Nathan Mattes 2024-03-27 15:42:13 +01:00
parent 4eed7df729
commit 5e1bb2cfaa
3 changed files with 38 additions and 14 deletions

View File

@ -88,10 +88,20 @@ extension HomeTimelineViewModel.LoadLatestState {
do { do {
await AuthenticationServiceProvider.shared.fetchAccounts(apiService: viewModel.context.apiService) await AuthenticationServiceProvider.shared.fetchAccounts(apiService: viewModel.context.apiService)
let response = try await viewModel.context.apiService.homeTimeline( let response: Mastodon.Response.Content<[Mastodon.Entity.Status]>
authenticationBox: viewModel.authContext.mastodonAuthenticationBox
) switch viewModel.timelineContext {
case .following:
response = try await viewModel.context.apiService.homeTimeline(
authenticationBox: viewModel.authContext.mastodonAuthenticationBox
)
case .community:
response = try await viewModel.context.apiService.publicTimeline(
query: .init(local: true),
authenticationBox: viewModel.authContext.mastodonAuthenticationBox
)
}
await enter(state: Idle.self) await enter(state: Idle.self)
viewModel.homeTimelineNavigationBarTitleViewModel.receiveLoadingStateCompletion(.finished) viewModel.homeTimelineNavigationBarTitleViewModel.receiveLoadingStateCompletion(.finished)

View File

@ -53,9 +53,7 @@ extension HomeTimelineViewModel.LoadOldestState {
} }
Task { Task {
let _maxID = lastFeedRecord.status?.id guard let maxID = lastFeedRecord.status?.id else {
guard let maxID = _maxID else {
await self.enter(state: Fail.self) await self.enter(state: Fail.self)
return return
} }
@ -63,11 +61,21 @@ extension HomeTimelineViewModel.LoadOldestState {
do { do {
await AuthenticationServiceProvider.shared.fetchAccounts(apiService: viewModel.context.apiService) await AuthenticationServiceProvider.shared.fetchAccounts(apiService: viewModel.context.apiService)
let response = try await viewModel.context.apiService.homeTimeline( let response: Mastodon.Response.Content<[Mastodon.Entity.Status]>
maxID: maxID,
authenticationBox: viewModel.authContext.mastodonAuthenticationBox switch viewModel.timelineContext {
) case .following:
response = try await viewModel.context.apiService.homeTimeline(
maxID: maxID,
authenticationBox: viewModel.authContext.mastodonAuthenticationBox
)
case .community:
response = try await viewModel.context.apiService.publicTimeline(
query: .init(local: true, maxID: maxID),
authenticationBox: viewModel.authContext.mastodonAuthenticationBox
)
}
let statuses = response.value let statuses = response.value
// enter no more state when no new statuses // enter no more state when no new statuses
if statuses.isEmpty || (statuses.count == 1 && statuses[0].id == maxID) { if statuses.isEmpty || (statuses.count == 1 && statuses[0].id == maxID) {

View File

@ -18,7 +18,12 @@ import MastodonUI
import MastodonSDK import MastodonSDK
final class HomeTimelineViewModel: NSObject { final class HomeTimelineViewModel: NSObject {
enum TimelineContext {
case following
case community
}
var disposeBag = Set<AnyCancellable>() var disposeBag = Set<AnyCancellable>()
var observations = Set<NSKeyValueObservation>() var observations = Set<NSKeyValueObservation>()
@ -35,7 +40,8 @@ final class HomeTimelineViewModel: NSObject {
@Published var scrollPositionRecord: ScrollPositionRecord? = nil @Published var scrollPositionRecord: ScrollPositionRecord? = nil
@Published var displaySettingBarButtonItem = true @Published var displaySettingBarButtonItem = true
@Published var hasPendingStatusEditReload = false @Published var hasPendingStatusEditReload = false
var timelineContext: TimelineContext = .following
weak var tableView: UITableView? weak var tableView: UITableView?
weak var timelineMiddleLoaderTableViewCellDelegate: TimelineMiddleLoaderTableViewCellDelegate? weak var timelineMiddleLoaderTableViewCellDelegate: TimelineMiddleLoaderTableViewCellDelegate?