mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-26 02:01:00 +00:00
Use account view model
This commit is contained in:
parent
eab12976cd
commit
07521837a9
5 changed files with 19 additions and 15 deletions
|
@ -19,8 +19,11 @@ public struct AccountStatusesService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension AccountStatusesService {
|
public extension AccountStatusesService {
|
||||||
func accountObservation() -> AnyPublisher<Account?, Error> {
|
func accountService() -> AnyPublisher<AccountService, Error> {
|
||||||
contentDatabase.accountObservation(id: accountID)
|
contentDatabase.accountObservation(id: accountID)
|
||||||
|
.compactMap { $0 }
|
||||||
|
.map { AccountService(account: $0, mastodonAPIClient: mastodonAPIClient, contentDatabase: contentDatabase) }
|
||||||
|
.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
||||||
func statusListService(
|
func statusListService(
|
||||||
|
|
|
@ -167,7 +167,10 @@ private extension CollectionViewController {
|
||||||
origin: .zero,
|
origin: .zero,
|
||||||
size: .init(width: 100, height: 100)))
|
size: .init(width: 100, height: 100)))
|
||||||
accountHeaderView.viewModel = accountsStatusesViewModel
|
accountHeaderView.viewModel = accountsStatusesViewModel
|
||||||
accountsStatusesViewModel.$account.dropFirst().receive(on: DispatchQueue.main).sink { [weak self] _ in
|
accountsStatusesViewModel.$accountViewModel
|
||||||
|
.dropFirst()
|
||||||
|
.receive(on: DispatchQueue.main)
|
||||||
|
.sink { [weak self] _ in
|
||||||
accountHeaderView.viewModel = accountsStatusesViewModel
|
accountHeaderView.viewModel = accountsStatusesViewModel
|
||||||
self?.sizeTableHeaderFooterViews()
|
self?.sizeTableHeaderFooterViews()
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import Mastodon
|
||||||
import ServiceLayer
|
import ServiceLayer
|
||||||
|
|
||||||
public class AccountStatusesViewModel: StatusListViewModel {
|
public class AccountStatusesViewModel: StatusListViewModel {
|
||||||
@Published public private(set) var account: Account?
|
@Published public private(set) var accountViewModel: AccountViewModel?
|
||||||
@Published public var collection = AccountStatusCollection.statuses
|
@Published public var collection = AccountStatusCollection.statuses
|
||||||
private let accountStatusesService: AccountStatusesService
|
private let accountStatusesService: AccountStatusesService
|
||||||
private var cancellables = Set<AnyCancellable>()
|
private var cancellables = Set<AnyCancellable>()
|
||||||
|
@ -22,9 +22,10 @@ public class AccountStatusesViewModel: StatusListViewModel {
|
||||||
|
|
||||||
$collection.sink(receiveValue: collectionSubject.send).store(in: &cancellables)
|
$collection.sink(receiveValue: collectionSubject.send).store(in: &cancellables)
|
||||||
|
|
||||||
accountStatusesService.accountObservation()
|
accountStatusesService.accountService()
|
||||||
|
.map(AccountViewModel.init(accountService:))
|
||||||
.assignErrorsToAlertItem(to: \.alertItem, on: self)
|
.assignErrorsToAlertItem(to: \.alertItem, on: self)
|
||||||
.assign(to: &$account)
|
.assign(to: &$accountViewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func request(maxID: String? = nil, minID: String? = nil) {
|
public override func request(maxID: String? = nil, minID: String? = nil) {
|
||||||
|
@ -43,12 +44,7 @@ public class AccountStatusesViewModel: StatusListViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override var title: AnyPublisher<String?, Never> {
|
public override var title: AnyPublisher<String?, Never> {
|
||||||
$account.map {
|
$accountViewModel.map { $0?.accountName }.eraseToAnyPublisher()
|
||||||
guard let acct = $0?.acct else { return nil }
|
|
||||||
|
|
||||||
return "@".appending(acct)
|
|
||||||
}
|
|
||||||
.eraseToAnyPublisher()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ public class AccountViewModel: ObservableObject {
|
||||||
public extension AccountViewModel {
|
public extension AccountViewModel {
|
||||||
var avatarURL: URL { accountService.account.avatar }
|
var avatarURL: URL { accountService.account.avatar }
|
||||||
|
|
||||||
|
var headerURL: URL { accountService.account.header }
|
||||||
|
|
||||||
var displayName: String { accountService.account.displayName }
|
var displayName: String { accountService.account.displayName }
|
||||||
|
|
||||||
var accountName: String { "@".appending(accountService.account.acct) }
|
var accountName: String { "@".appending(accountService.account.acct) }
|
||||||
|
|
|
@ -11,18 +11,18 @@ class AccountHeaderView: UIView {
|
||||||
|
|
||||||
var viewModel: AccountStatusesViewModel? {
|
var viewModel: AccountStatusesViewModel? {
|
||||||
didSet {
|
didSet {
|
||||||
if let account = viewModel?.account {
|
if let accountViewModel = viewModel?.accountViewModel {
|
||||||
headerImageView.kf.setImage(with: account.header)
|
headerImageView.kf.setImage(with: accountViewModel.headerURL)
|
||||||
|
|
||||||
let noteFont = UIFont.preferredFont(forTextStyle: .callout)
|
let noteFont = UIFont.preferredFont(forTextStyle: .callout)
|
||||||
let mutableNote = NSMutableAttributedString(attributedString: account.note.attributed)
|
let mutableNote = NSMutableAttributedString(attributedString: accountViewModel.note)
|
||||||
let noteRange = NSRange(location: 0, length: mutableNote.length)
|
let noteRange = NSRange(location: 0, length: mutableNote.length)
|
||||||
mutableNote.removeAttribute(.font, range: noteRange)
|
mutableNote.removeAttribute(.font, range: noteRange)
|
||||||
mutableNote.addAttributes(
|
mutableNote.addAttributes(
|
||||||
[.font: noteFont as Any,
|
[.font: noteFont as Any,
|
||||||
.foregroundColor: UIColor.label],
|
.foregroundColor: UIColor.label],
|
||||||
range: noteRange)
|
range: noteRange)
|
||||||
mutableNote.insert(emoji: account.emojis, view: noteTextView)
|
mutableNote.insert(emoji: accountViewModel.emoji, view: noteTextView)
|
||||||
mutableNote.resizeAttachments(toLineHeight: noteFont.lineHeight)
|
mutableNote.resizeAttachments(toLineHeight: noteFont.lineHeight)
|
||||||
noteTextView.attributedText = mutableNote
|
noteTextView.attributedText = mutableNote
|
||||||
noteTextView.isHidden = false
|
noteTextView.isHidden = false
|
||||||
|
|
Loading…
Reference in a new issue