diff --git a/MastodonAPI/Sources/MastodonAPI/Endpoints/AccountsEndpoint.swift b/MastodonAPI/Sources/MastodonAPI/Endpoints/AccountsEndpoint.swift index 404d646..a592317 100644 --- a/MastodonAPI/Sources/MastodonAPI/Endpoints/AccountsEndpoint.swift +++ b/MastodonAPI/Sources/MastodonAPI/Endpoints/AccountsEndpoint.swift @@ -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 } } diff --git a/ServiceLayer/Sources/ServiceLayer/Services/AccountListService.swift b/ServiceLayer/Sources/ServiceLayer/Services/AccountListService.swift index 27709aa..54a5303 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/AccountListService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/AccountListService.swift @@ -17,8 +17,14 @@ public struct AccountListService { private let requestClosure: (_ maxID: String?, _ minID: String?) -> AnyPublisher } +public extension AccountListService { + func request(maxID: String?, minID: String?) -> AnyPublisher { + 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() @@ -32,17 +38,10 @@ extension AccountListService { list: list, mastodonAPIClient: mastodonAPIClient, contentDatabase: contentDatabase) { maxID, minID -> AnyPublisher 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 { - requestClosure(maxID, minID) - } -} diff --git a/ServiceLayer/Sources/ServiceLayer/Services/StatusService.swift b/ServiceLayer/Sources/ServiceLayer/Services/StatusService.swift index 58fac09..86d391d 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/StatusService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/StatusService.swift @@ -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) } diff --git a/ViewModels/Sources/ViewModels/StatusViewModel.swift b/ViewModels/Sources/ViewModels/StatusViewModel.swift index b8c55eb..2f10a4e 100644 --- a/ViewModels/Sources/ViewModels/StatusViewModel.swift +++ b/ViewModels/Sources/ViewModels/StatusViewModel.swift @@ -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( diff --git a/Views/Status/StatusView.swift b/Views/Status/StatusView.swift index 30c41b6..a8cb6ef 100644 --- a/Views/Status/StatusView.swift +++ b/Views/Status/StatusView.swift @@ -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)