diff --git a/ServiceLayer/Sources/ServiceLayer/Services/StatusListService.swift b/ServiceLayer/Sources/ServiceLayer/Services/StatusListService.swift index 795ebf4..deb6b14 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/StatusListService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/StatusListService.swift @@ -10,7 +10,7 @@ public struct StatusListService { public let statusSections: AnyPublisher<[[Status]], Error> public let paginates: Bool public let contextParentID: String? - public var title: String? + public let title: String? private let filterContext: Filter.Context private let mastodonAPIClient: MastodonAPIClient @@ -59,7 +59,7 @@ extension StatusListService { .eraseToAnyPublisher(), paginates: true, contextParentID: nil, - title: "turn this into a closure or publisher", + title: nil, filterContext: .account, mastodonAPIClient: mastodonAPIClient, contentDatabase: contentDatabase) { maxID, minID in diff --git a/View Controllers/CollectionViewController.swift b/View Controllers/CollectionViewController.swift index c981b3a..4aebf14 100644 --- a/View Controllers/CollectionViewController.swift +++ b/View Controllers/CollectionViewController.swift @@ -57,7 +57,7 @@ class CollectionViewController: UITableViewController { tableView.cellLayoutMarginsFollowReadableWidth = true tableView.tableFooterView = UIView() -// navigationItem.title = viewModel.title + viewModel.title.sink { [weak self] in self?.navigationItem.title = $0 }.store(in: &cancellables) viewModel.collectionItems .sink { [weak self] in self?.update(items: $0) } diff --git a/ViewModels/Sources/ViewModels/AccountStatusesViewModel.swift b/ViewModels/Sources/ViewModels/AccountStatusesViewModel.swift index e370bf9..21cfa63 100644 --- a/ViewModels/Sources/ViewModels/AccountStatusesViewModel.swift +++ b/ViewModels/Sources/ViewModels/AccountStatusesViewModel.swift @@ -41,6 +41,15 @@ public class AccountStatusesViewModel: StatusListViewModel { override func isPinned(status: Status) -> Bool { collection == .statuses && items.first?.contains(CollectionItem(id: status.id, kind: .status)) ?? false } + + public override var title: AnyPublisher { + $account.map { + guard let acct = $0?.acct else { return nil } + + return "@".appending(acct) + } + .eraseToAnyPublisher() + } } public extension AccountStatusesViewModel { diff --git a/ViewModels/Sources/ViewModels/CollectionViewModel.swift b/ViewModels/Sources/ViewModels/CollectionViewModel.swift index bb838d1..5465e70 100644 --- a/ViewModels/Sources/ViewModels/CollectionViewModel.swift +++ b/ViewModels/Sources/ViewModels/CollectionViewModel.swift @@ -5,6 +5,7 @@ import Foundation public protocol CollectionViewModel { var collectionItems: AnyPublisher<[[CollectionItem]], Never> { get } + var title: AnyPublisher { get } var alertItems: AnyPublisher { get } var loading: AnyPublisher { get } var navigationEvents: AnyPublisher { get } diff --git a/ViewModels/Sources/ViewModels/StatusListViewModel.swift b/ViewModels/Sources/ViewModels/StatusListViewModel.swift index bd83eae..b1b21ae 100644 --- a/ViewModels/Sources/ViewModels/StatusListViewModel.swift +++ b/ViewModels/Sources/ViewModels/StatusListViewModel.swift @@ -38,6 +38,8 @@ public class StatusListViewModel: ObservableObject { .assign(to: &$items) } + public var title: AnyPublisher { Just(statusListService.title).eraseToAnyPublisher() } + public func request(maxID: String? = nil, minID: String? = nil) { statusListService.request(maxID: maxID, minID: minID) .receive(on: DispatchQueue.main) @@ -94,8 +96,6 @@ extension StatusListViewModel: CollectionViewModel { } public extension StatusListViewModel { - var title: String? { statusListService.title } - var paginates: Bool { statusListService.paginates } var contextParentID: String? { statusListService.contextParentID }