Ensure own status is added on top
This commit is contained in:
parent
6bbe352f7e
commit
b04ccc18fa
|
@ -7,6 +7,7 @@ import DesignSystem
|
|||
import Env
|
||||
|
||||
public struct TimelineView: View {
|
||||
@EnvironmentObject private var account: CurrentAccount
|
||||
@EnvironmentObject private var watcher: StreamWatcher
|
||||
@EnvironmentObject private var client: Client
|
||||
@StateObject private var viewModel = TimelineViewModel()
|
||||
|
@ -56,7 +57,7 @@ public struct TimelineView: View {
|
|||
}
|
||||
.onChange(of: watcher.latestEvent?.id) { id in
|
||||
if let latestEvent = watcher.latestEvent {
|
||||
viewModel.handleEvent(event: latestEvent)
|
||||
viewModel.handleEvent(event: latestEvent, currentAccount: account)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ import SwiftUI
|
|||
import Network
|
||||
import Models
|
||||
import Status
|
||||
import Env
|
||||
|
||||
@MainActor
|
||||
class TimelineViewModel: ObservableObject, StatusesFetcher {
|
||||
|
@ -85,10 +86,15 @@ class TimelineViewModel: ObservableObject, StatusesFetcher {
|
|||
} catch {}
|
||||
}
|
||||
|
||||
func handleEvent(event: any StreamEvent) {
|
||||
func handleEvent(event: any StreamEvent, currentAccount: CurrentAccount) {
|
||||
guard timeline == .home else { return }
|
||||
if let event = event as? StreamEventUpdate {
|
||||
if event.status.account.id == currentAccount.account?.id {
|
||||
statuses.insert(event.status, at: 0)
|
||||
statusesState = .display(statuses: statuses, nextPageState: .hasNextPage)
|
||||
} else {
|
||||
pendingStatuses.insert(event.status, at: 0)
|
||||
}
|
||||
} else if let event = event as? StreamEventDelete {
|
||||
statuses.removeAll(where: { $0.id == event.status })
|
||||
statusesState = .display(statuses: statuses, nextPageState: .hasNextPage)
|
||||
|
|
Loading…
Reference in New Issue