mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 09:41:00 +00:00
Reblogged by
This commit is contained in:
parent
a9e5bb7ef3
commit
6c32d51d30
5 changed files with 34 additions and 12 deletions
|
@ -5,6 +5,7 @@ import HTTP
|
|||
import Mastodon
|
||||
|
||||
public enum AccountsEndpoint {
|
||||
case statusRebloggedBy(id: String)
|
||||
case statusFavouritedBy(id: String)
|
||||
}
|
||||
|
||||
|
@ -13,13 +14,15 @@ extension AccountsEndpoint: Endpoint {
|
|||
|
||||
public var context: [String] {
|
||||
switch self {
|
||||
case .statusFavouritedBy:
|
||||
case .statusRebloggedBy, .statusFavouritedBy:
|
||||
return defaultContext + ["statuses"]
|
||||
}
|
||||
}
|
||||
|
||||
public var pathComponentsInContext: [String] {
|
||||
switch self {
|
||||
case let .statusRebloggedBy(id):
|
||||
return [id, "reblogged_by"]
|
||||
case let .statusFavouritedBy(id):
|
||||
return [id, "favourited_by"]
|
||||
}
|
||||
|
@ -27,7 +30,7 @@ extension AccountsEndpoint: Endpoint {
|
|||
|
||||
public var method: HTTPMethod {
|
||||
switch self {
|
||||
case .statusFavouritedBy:
|
||||
case .statusRebloggedBy, .statusFavouritedBy:
|
||||
return .get
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,14 @@ public struct AccountListService {
|
|||
private let requestClosure: (_ maxID: String?, _ minID: String?) -> AnyPublisher<Never, Error>
|
||||
}
|
||||
|
||||
public extension AccountListService {
|
||||
func request(maxID: String?, minID: String?) -> AnyPublisher<Never, Error> {
|
||||
requestClosure(maxID, minID)
|
||||
}
|
||||
}
|
||||
|
||||
extension AccountListService {
|
||||
init(favoritedByStatusID statusID: String, mastodonAPIClient: MastodonAPIClient, contentDatabase: ContentDatabase) {
|
||||
init(endpoint: AccountsEndpoint, mastodonAPIClient: MastodonAPIClient, contentDatabase: ContentDatabase) {
|
||||
let list = AccountList()
|
||||
let nextPageMaxIDsSubject = PassthroughSubject<String?, Never>()
|
||||
|
||||
|
@ -32,17 +38,10 @@ extension AccountListService {
|
|||
list: list,
|
||||
mastodonAPIClient: mastodonAPIClient,
|
||||
contentDatabase: contentDatabase) { maxID, minID -> AnyPublisher<Never, Error> in
|
||||
mastodonAPIClient.pagedRequest(
|
||||
AccountsEndpoint.statusFavouritedBy(id: statusID), maxID: maxID, minID: minID)
|
||||
mastodonAPIClient.pagedRequest(endpoint, maxID: maxID, minID: minID)
|
||||
.handleEvents(receiveOutput: { nextPageMaxIDsSubject.send($0.info.maxID) })
|
||||
.flatMap { contentDatabase.append(accounts: $0.result, toList: list) }
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public extension AccountListService {
|
||||
func request(maxID: String?, minID: String?) -> AnyPublisher<Never, Error> {
|
||||
requestClosure(maxID, minID)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,9 +32,16 @@ public extension StatusService {
|
|||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
func rebloggedByService() -> AccountListService {
|
||||
AccountListService(
|
||||
endpoint: .statusRebloggedBy(id: status.id),
|
||||
mastodonAPIClient: mastodonAPIClient,
|
||||
contentDatabase: contentDatabase)
|
||||
}
|
||||
|
||||
func favoritedByService() -> AccountListService {
|
||||
AccountListService(
|
||||
favoritedByStatusID: status.id,
|
||||
endpoint: .statusFavouritedBy(id: status.id),
|
||||
mastodonAPIClient: mastodonAPIClient,
|
||||
contentDatabase: contentDatabase)
|
||||
}
|
||||
|
|
|
@ -125,6 +125,15 @@ public extension StatusViewModel {
|
|||
.eraseToAnyPublisher())
|
||||
}
|
||||
|
||||
func rebloggedBySelected() {
|
||||
eventsSubject.send(
|
||||
Just(CollectionItemEvent.accountListNavigation(
|
||||
AccountListViewModel(
|
||||
accountListService: statusService.rebloggedByService())))
|
||||
.setFailureType(to: Error.self)
|
||||
.eraseToAnyPublisher())
|
||||
}
|
||||
|
||||
func favoritedBySelected() {
|
||||
eventsSubject.send(
|
||||
Just(CollectionItemEvent.accountListNavigation(
|
||||
|
|
|
@ -159,6 +159,10 @@ private extension StatusView {
|
|||
UIAction { [weak self] _ in self?.statusConfiguration.viewModel.shareStatus() },
|
||||
for: .touchUpInside)
|
||||
|
||||
contextParentRebloggedByButton.addAction(
|
||||
UIAction { [weak self] _ in self?.statusConfiguration.viewModel.rebloggedBySelected() },
|
||||
for: .touchUpInside)
|
||||
|
||||
contextParentFavoritedByButton.addAction(
|
||||
UIAction { [weak self] _ in self?.statusConfiguration.viewModel.favoritedBySelected() },
|
||||
for: .touchUpInside)
|
||||
|
|
Loading…
Reference in a new issue