metatext-app-ios-iphone-ipad/ViewModels/Sources/ViewModels/AccountViewModel.swift

47 lines
1.5 KiB
Swift
Raw Normal View History

2020-09-23 03:00:56 +02:00
// Copyright © 2020 Metabolist. All rights reserved.
import Combine
import Foundation
import Mastodon
import ServiceLayer
2020-10-05 08:36:22 +02:00
public struct AccountViewModel: CollectionItemViewModel {
2020-09-25 07:39:06 +02:00
public let events: AnyPublisher<AnyPublisher<CollectionItemEvent, Error>, Never>
2020-10-15 09:44:01 +02:00
public let identification: Identification
2020-09-25 07:39:06 +02:00
2020-09-23 03:00:56 +02:00
private let accountService: AccountService
2020-09-25 07:39:06 +02:00
private let eventsSubject = PassthroughSubject<AnyPublisher<CollectionItemEvent, Error>, Never>()
2020-09-23 03:00:56 +02:00
2020-10-15 09:44:01 +02:00
init(accountService: AccountService, identification: Identification) {
2020-09-23 03:00:56 +02:00
self.accountService = accountService
2020-10-15 09:44:01 +02:00
self.identification = identification
2020-09-25 07:39:06 +02:00
events = eventsSubject.eraseToAnyPublisher()
2020-09-23 03:00:56 +02:00
}
}
public extension AccountViewModel {
2020-09-26 02:52:59 +02:00
var avatarURL: URL { accountService.account.avatar }
2020-09-23 03:00:56 +02:00
2020-10-15 09:44:01 +02:00
var avatarStaticURL: URL { accountService.account.avatarStatic }
2020-09-26 09:13:50 +02:00
var headerURL: URL { accountService.account.header }
2020-10-15 09:44:01 +02:00
var headerStaticURL: URL { accountService.account.headerStatic }
2020-09-26 02:52:59 +02:00
var displayName: String { accountService.account.displayName }
var accountName: String { "@".appending(accountService.account.acct) }
var note: NSAttributedString { accountService.account.note.attributed }
var emoji: [Emoji] { accountService.account.emojis }
2020-09-26 02:57:35 +02:00
func urlSelected(_ url: URL) {
eventsSubject.send(
accountService.navigationService.item(url: url)
.map { CollectionItemEvent.navigation($0) }
.setFailureType(to: Error.self)
.eraseToAnyPublisher())
}
2020-09-23 03:00:56 +02:00
}