Reblog button

This commit is contained in:
Justin Mazzocchi 2021-01-03 17:51:52 -08:00
parent 01efe1714f
commit 9b0f7e67be
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
4 changed files with 26 additions and 1 deletions

View file

@ -6,6 +6,8 @@ import Mastodon
public enum StatusEndpoint { public enum StatusEndpoint {
case status(id: Status.Id) case status(id: Status.Id)
case reblog(id: Status.Id)
case unreblog(id: Status.Id)
case favourite(id: Status.Id) case favourite(id: Status.Id)
case unfavourite(id: Status.Id) case unfavourite(id: Status.Id)
case bookmark(id: Status.Id) case bookmark(id: Status.Id)
@ -70,6 +72,10 @@ extension StatusEndpoint: Endpoint {
switch self { switch self {
case let .status(id): case let .status(id):
return [id] return [id]
case let .reblog(id):
return [id, "reblog"]
case let .unreblog(id):
return [id, "unreblog"]
case let .favourite(id): case let .favourite(id):
return [id, "favourite"] return [id, "favourite"]
case let .unfavourite(id): case let .unfavourite(id):
@ -96,7 +102,7 @@ extension StatusEndpoint: Endpoint {
switch self { switch self {
case .status: case .status:
return .get return .get
case .favourite, .unfavourite, .bookmark, .unbookmark, .post: case .reblog, .unreblog, .favourite, .unfavourite, .bookmark, .unbookmark, .post:
return .post return .post
} }
} }

View file

@ -32,6 +32,14 @@ public extension StatusService {
contentDatabase.toggleShowAttachments(id: status.displayStatus.id) contentDatabase.toggleShowAttachments(id: status.displayStatus.id)
} }
func toggleReblogged() -> AnyPublisher<Never, Error> {
mastodonAPIClient.request(status.displayStatus.reblogged
? StatusEndpoint.unreblog(id: status.displayStatus.id)
: StatusEndpoint.reblog(id: status.displayStatus.id))
.flatMap(contentDatabase.insert(status:))
.eraseToAnyPublisher()
}
func toggleFavorited() -> AnyPublisher<Never, Error> { func toggleFavorited() -> AnyPublisher<Never, Error> {
mastodonAPIClient.request(status.displayStatus.favourited mastodonAPIClient.request(status.displayStatus.favourited
? StatusEndpoint.unfavourite(id: status.displayStatus.id) ? StatusEndpoint.unfavourite(id: status.displayStatus.id)

View file

@ -200,6 +200,13 @@ public extension StatusViewModel {
.eraseToAnyPublisher()) .eraseToAnyPublisher())
} }
func toggleReblogged() {
eventsSubject.send(
statusService.toggleReblogged()
.map { _ in .ignorableOutput }
.eraseToAnyPublisher())
}
func toggleFavorited() { func toggleFavorited() {
eventsSubject.send( eventsSubject.send(
statusService.toggleFavorited() statusService.toggleFavorited()

View file

@ -198,6 +198,10 @@ private extension StatusView {
interactionsStackView.addArrangedSubview(favoritedByButton) interactionsStackView.addArrangedSubview(favoritedByButton)
interactionsStackView.distribution = .fillEqually interactionsStackView.distribution = .fillEqually
reblogButton.addAction(
UIAction { [weak self] _ in self?.statusConfiguration.viewModel.toggleReblogged() },
for: .touchUpInside)
favoriteButton.addAction( favoriteButton.addAction(
UIAction { [weak self] _ in self?.statusConfiguration.viewModel.toggleFavorited() }, UIAction { [weak self] _ in self?.statusConfiguration.viewModel.toggleFavorited() },
for: .touchUpInside) for: .touchUpInside)