2020-10-30 07:11:24 +00:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
|
|
|
import Combine
|
|
|
|
import Foundation
|
|
|
|
import Mastodon
|
|
|
|
import ServiceLayer
|
|
|
|
|
2021-02-04 22:24:27 +00:00
|
|
|
public final class NotificationViewModel: ObservableObject {
|
2020-10-30 07:11:24 +00:00
|
|
|
public let accountViewModel: AccountViewModel
|
2020-10-31 00:29:43 +00:00
|
|
|
public let statusViewModel: StatusViewModel?
|
2021-01-26 00:45:18 +00:00
|
|
|
public let identityContext: IdentityContext
|
2020-10-30 07:11:24 +00:00
|
|
|
|
|
|
|
private let notificationService: NotificationService
|
2021-02-04 22:24:27 +00:00
|
|
|
private let eventsSubject: PassthroughSubject<AnyPublisher<CollectionItemEvent, Error>, Never>
|
2020-10-30 07:11:24 +00:00
|
|
|
|
2021-02-04 22:24:27 +00:00
|
|
|
init(notificationService: NotificationService,
|
|
|
|
identityContext: IdentityContext,
|
|
|
|
eventsSubject: PassthroughSubject<AnyPublisher<CollectionItemEvent, Error>, Never>) {
|
2020-10-30 07:11:24 +00:00
|
|
|
self.notificationService = notificationService
|
2021-01-26 00:06:35 +00:00
|
|
|
self.identityContext = identityContext
|
2021-02-04 22:24:27 +00:00
|
|
|
self.eventsSubject = eventsSubject
|
2020-10-30 07:11:24 +00:00
|
|
|
self.accountViewModel = AccountViewModel(
|
|
|
|
accountService: notificationService.navigationService.accountService(
|
|
|
|
account: notificationService.notification.account),
|
2021-02-04 22:24:27 +00:00
|
|
|
identityContext: identityContext,
|
|
|
|
eventsSubject: eventsSubject)
|
2020-10-31 00:29:43 +00:00
|
|
|
|
|
|
|
if let status = notificationService.notification.status {
|
|
|
|
statusViewModel = StatusViewModel(
|
|
|
|
statusService: notificationService.navigationService.statusService(status: status),
|
2021-02-04 22:24:27 +00:00
|
|
|
identityContext: identityContext,
|
|
|
|
eventsSubject: eventsSubject)
|
2020-10-31 00:29:43 +00:00
|
|
|
} else {
|
|
|
|
statusViewModel = nil
|
|
|
|
}
|
2020-10-30 07:11:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public extension NotificationViewModel {
|
|
|
|
var type: MastodonNotification.NotificationType {
|
|
|
|
notificationService.notification.type
|
|
|
|
}
|
2020-10-31 00:29:43 +00:00
|
|
|
|
2021-01-27 02:31:00 +00:00
|
|
|
var time: String? { notificationService.notification.createdAt.timeAgo }
|
|
|
|
|
2021-02-02 21:04:11 +00:00
|
|
|
var accessibilityTime: String? {
|
|
|
|
notificationService.notification.createdAt.accessibilityTimeAgo
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|