2020-10-30 07:11:24 +00:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import Combine
|
|
|
|
import Foundation
|
|
|
|
import Mastodon
|
|
|
|
import ServiceLayer
|
|
|
|
|
|
|
|
public final class NotificationViewModel: CollectionItemViewModel, ObservableObject {
|
|
|
|
public let accountViewModel: AccountViewModel
|
2020-10-31 00:29:43 +00:00
|
|
|
public let statusViewModel: StatusViewModel?
|
2020-10-30 07:11:24 +00:00
|
|
|
public let events: AnyPublisher<AnyPublisher<CollectionItemEvent, Error>, Never>
|
|
|
|
|
|
|
|
private let notificationService: NotificationService
|
|
|
|
private let identification: Identification
|
|
|
|
private let eventsSubject = PassthroughSubject<AnyPublisher<CollectionItemEvent, Error>, Never>()
|
|
|
|
|
|
|
|
init(notificationService: NotificationService, identification: Identification) {
|
|
|
|
self.notificationService = notificationService
|
|
|
|
self.identification = identification
|
|
|
|
self.accountViewModel = AccountViewModel(
|
|
|
|
accountService: notificationService.navigationService.accountService(
|
|
|
|
account: notificationService.notification.account),
|
|
|
|
identification: identification)
|
2020-10-31 00:29:43 +00:00
|
|
|
|
|
|
|
if let status = notificationService.notification.status {
|
|
|
|
statusViewModel = StatusViewModel(
|
|
|
|
statusService: notificationService.navigationService.statusService(status: status),
|
|
|
|
identification: identification)
|
|
|
|
} else {
|
|
|
|
statusViewModel = nil
|
|
|
|
}
|
|
|
|
|
2020-10-30 07:11:24 +00:00
|
|
|
self.events = eventsSubject.eraseToAnyPublisher()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public extension NotificationViewModel {
|
|
|
|
var type: MastodonNotification.NotificationType {
|
|
|
|
notificationService.notification.type
|
|
|
|
}
|
2020-10-31 00:29:43 +00:00
|
|
|
|
|
|
|
func accountSelected() {
|
|
|
|
eventsSubject.send(
|
|
|
|
Just(.navigation(
|
|
|
|
.profile(
|
|
|
|
notificationService.navigationService.profileService(
|
|
|
|
account: notificationService.notification.account))))
|
|
|
|
.setFailureType(to: Error.self)
|
|
|
|
.eraseToAnyPublisher())
|
|
|
|
}
|
2020-10-30 07:11:24 +00:00
|
|
|
}
|