Fix information about amount of statuses
This commit is contained in:
parent
28df8b940e
commit
6c3bf3a0fc
|
@ -47,8 +47,8 @@ Things that should be implemented in version 2.0:
|
|||
|
||||
- [ ] Use auto generated resources (Color/Images) instead static extensions (how to do this in separete Swift Packages?)
|
||||
- [x] Move to xcstring (new Xcode transaction system)
|
||||
- [ ] Move to new Observable macro (iOS 17)
|
||||
- [ ] Migrate to SwiftData (iOS 17)
|
||||
- [x] Move to new Observable macro (iOS 17)
|
||||
- [x] Migrate to SwiftData (iOS 17)
|
||||
- [ ] Use ViewModels
|
||||
- [ ] Add tips (new TipKit framework in iOS 17)
|
||||
- [ ] Enable swiftlint (https://github.com/realm/SwiftLint/issues/5053)
|
||||
|
|
|
@ -106,6 +106,21 @@ public class HomeTimelineService {
|
|||
return visibleStatuses
|
||||
}
|
||||
|
||||
public func update(lastSeenStatusId: String?, lastLoadedStatusId: String?, applicationState: ApplicationState, modelContext: ModelContext) throws {
|
||||
guard let accountId = applicationState.account?.id else {
|
||||
return
|
||||
}
|
||||
|
||||
try AccountDataHandler.shared.update(lastSeenStatusId: lastSeenStatusId,
|
||||
lastLoadedStatusId: lastLoadedStatusId,
|
||||
accountId: accountId,
|
||||
modelContext: modelContext)
|
||||
|
||||
if (applicationState.lastSeenStatusId ?? "0") < (lastSeenStatusId ?? "0") {
|
||||
applicationState.lastSeenStatusId = lastSeenStatusId
|
||||
}
|
||||
}
|
||||
|
||||
private func hasBeenAlreadyOnTimeline(accountId: String, status: Status, modelContext: ModelContext) -> Bool {
|
||||
return ViewedStatusHandler.shared.hasBeenAlreadyOnTimeline(accountId: accountId, status: status, modelContext: modelContext)
|
||||
}
|
||||
|
|
|
@ -194,7 +194,10 @@ struct HomeTimelineView: View {
|
|||
modelContext: modelContext)
|
||||
|
||||
// Remeber first status returned by API in user context (when it's newer then remembered).
|
||||
try AccountDataHandler.shared.update(lastSeenStatusId: nil, lastLoadedStatusId: statuses.first?.id, accountId: accountId, modelContext: modelContext)
|
||||
try HomeTimelineService.shared.update(lastSeenStatusId: nil,
|
||||
lastLoadedStatusId: statuses.first?.id,
|
||||
applicationState: self.applicationState,
|
||||
modelContext: modelContext)
|
||||
|
||||
// Append statuses to viewed.
|
||||
try ViewedStatusHandler.shared.append(contentsOf: statuses, accountId: accountId, modelContext: modelContext)
|
||||
|
@ -268,7 +271,10 @@ struct HomeTimelineView: View {
|
|||
modelContext: modelContext)
|
||||
|
||||
// Remeber first status returned by API in user context (when it's newer then remembered).
|
||||
try AccountDataHandler.shared.update(lastSeenStatusId: self.statusViewModels.first?.id, lastLoadedStatusId: statuses.first?.id, accountId: accountId, modelContext: modelContext)
|
||||
try HomeTimelineService.shared.update(lastSeenStatusId: self.statusViewModels.first?.id,
|
||||
lastLoadedStatusId: statuses.first?.id,
|
||||
applicationState: self.applicationState,
|
||||
modelContext: modelContext)
|
||||
|
||||
// Append statuses to viewed.
|
||||
try ViewedStatusHandler.shared.append(contentsOf: statuses, accountId: accountId, modelContext: modelContext)
|
||||
|
@ -281,6 +287,9 @@ struct HomeTimelineView: View {
|
|||
|
||||
// Replace old collection with new one.
|
||||
self.statusViewModels = statusModels
|
||||
|
||||
// Set that all statuses has been downloaded.
|
||||
self.applicationState.amountOfNewStatuses = 0
|
||||
}
|
||||
|
||||
private func loadFromApi(maxId: String? = nil, sinceId: String? = nil, minId: String? = nil) async throws -> [Status] {
|
||||
|
|
|
@ -196,7 +196,10 @@ struct StatusesView: View {
|
|||
|
||||
if self.listType == .home {
|
||||
// Remeber first status returned by API in user context (when it's newer then remembered).
|
||||
try AccountDataHandler.shared.update(lastSeenStatusId: nil, lastLoadedStatusId: statuses.first?.id, accountId: accountId, modelContext: modelContext)
|
||||
try HomeTimelineService.shared.update(lastSeenStatusId: nil,
|
||||
lastLoadedStatusId: statuses.first?.id,
|
||||
applicationState: self.applicationState,
|
||||
modelContext: modelContext)
|
||||
|
||||
// Append statuses to viewed.
|
||||
try ViewedStatusHandler.shared.append(contentsOf: statuses, accountId: accountId, modelContext: modelContext)
|
||||
|
@ -271,7 +274,10 @@ struct StatusesView: View {
|
|||
|
||||
if self.listType == .home {
|
||||
// Remeber first status returned by API in user context (when it's newer then remembered).
|
||||
try AccountDataHandler.shared.update(lastSeenStatusId: self.statusViewModels.first?.id, lastLoadedStatusId: statuses.first?.id, accountId: accountId, modelContext: modelContext)
|
||||
try HomeTimelineService.shared.update(lastSeenStatusId: self.statusViewModels.first?.id,
|
||||
lastLoadedStatusId: statuses.first?.id,
|
||||
applicationState: self.applicationState,
|
||||
modelContext: modelContext)
|
||||
|
||||
// Append statuses to viewed.
|
||||
try ViewedStatusHandler.shared.append(contentsOf: statuses, accountId: accountId, modelContext: modelContext)
|
||||
|
|
Loading…
Reference in New Issue