2
2
mirror of https://github.com/mastodon/mastodon-ios synced 2025-04-11 22:58:02 +02:00
mastodon-ios/Mastodon/Scene/Thread/RemoteThreadViewModel.swift
shannon c4442fe8a9 Fix crash on launch due to infinite loop
And more honestly about singletons.
2024-11-15 12:25:58 -05:00

63 lines
1.7 KiB
Swift

//
// RemoteThreadViewModel.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-4-12.
//
import UIKit
import CoreDataStack
import MastodonCore
import MastodonSDK
final class RemoteThreadViewModel: ThreadViewModel {
init(
context: AppContext,
authenticationBox: MastodonAuthenticationBox,
statusID: Mastodon.Entity.Status.ID
) {
super.init(
context: context,
authenticationBox: authenticationBox,
optionalRoot: nil
)
Task { @MainActor in
let response = try await APIService.shared.status(
statusID: statusID,
authenticationBox: authenticationBox
)
let threadContext = StatusItem.Thread.Context(status: .fromEntity(response.value))
self.root = .root(context: threadContext)
} // end Task
}
init(
context: AppContext,
authenticationBox: MastodonAuthenticationBox,
notificationID: Mastodon.Entity.Notification.ID
) {
super.init(
context: context,
authenticationBox: authenticationBox,
optionalRoot: nil
)
Task { @MainActor in
let response = try await APIService.shared.notification(
notificationID: notificationID,
authenticationBox: authenticationBox
)
guard let status = response.value.status else { return }
let threadContext = StatusItem.Thread.Context(status: .fromEntity(status))
self.root = .root(context: threadContext)
} // end Task
}
}