mastodon-ios/Mastodon/Scene/Thread/RemoteThreadViewModel.swift

65 lines
1.8 KiB
Swift
Raw Normal View History

2021-04-13 13:46:42 +02:00
//
// RemoteThreadViewModel.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-4-12.
//
import UIKit
import CoreDataStack
2022-10-08 07:43:06 +02:00
import MastodonCore
2021-04-13 13:46:42 +02:00
import MastodonSDK
final class RemoteThreadViewModel: ThreadViewModel {
init(
context: AppContext,
authContext: AuthContext,
statusID: Mastodon.Entity.Status.ID
) {
super.init(
context: context,
authContext: authContext,
optionalRoot: nil
)
2021-04-13 13:46:42 +02:00
Task { @MainActor in
let domain = authContext.mastodonAuthenticationBox.domain
let response = try await context.apiService.status(
statusID: statusID,
authenticationBox: authContext.mastodonAuthenticationBox
)
2023-11-22 12:32:04 +01:00
let threadContext = StatusItem.Thread.Context(status: .fromEntity(response.value))
self.root = .root(context: threadContext)
} // end Task
2021-04-13 13:46:42 +02:00
}
init(
context: AppContext,
authContext: AuthContext,
notificationID: Mastodon.Entity.Notification.ID
) {
super.init(
context: context,
authContext: authContext,
optionalRoot: nil
)
Task { @MainActor in
let domain = authContext.mastodonAuthenticationBox.domain
let response = try await context.apiService.notification(
notificationID: notificationID,
authenticationBox: authContext.mastodonAuthenticationBox
)
2023-11-22 12:32:04 +01:00
guard let status = response.value.status else { return }
2023-11-22 12:32:04 +01:00
let threadContext = StatusItem.Thread.Context(status: .fromEntity(status))
self.root = .root(context: threadContext)
} // end Task
}
2021-04-13 13:46:42 +02:00
}