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