diff --git a/MastodonAPI/Sources/MastodonAPI/Endpoints/StatusEndpoint.swift b/MastodonAPI/Sources/MastodonAPI/Endpoints/StatusEndpoint.swift index f555c65..30746fa 100644 --- a/MastodonAPI/Sources/MastodonAPI/Endpoints/StatusEndpoint.swift +++ b/MastodonAPI/Sources/MastodonAPI/Endpoints/StatusEndpoint.swift @@ -6,6 +6,8 @@ import Mastodon public enum StatusEndpoint { case status(id: Status.Id) + case reblog(id: Status.Id) + case unreblog(id: Status.Id) case favourite(id: Status.Id) case unfavourite(id: Status.Id) case bookmark(id: Status.Id) @@ -70,6 +72,10 @@ extension StatusEndpoint: Endpoint { switch self { case let .status(id): return [id] + case let .reblog(id): + return [id, "reblog"] + case let .unreblog(id): + return [id, "unreblog"] case let .favourite(id): return [id, "favourite"] case let .unfavourite(id): @@ -96,7 +102,7 @@ extension StatusEndpoint: Endpoint { switch self { case .status: return .get - case .favourite, .unfavourite, .bookmark, .unbookmark, .post: + case .reblog, .unreblog, .favourite, .unfavourite, .bookmark, .unbookmark, .post: return .post } } diff --git a/ServiceLayer/Sources/ServiceLayer/Services/StatusService.swift b/ServiceLayer/Sources/ServiceLayer/Services/StatusService.swift index 6455baf..f651b13 100644 --- a/ServiceLayer/Sources/ServiceLayer/Services/StatusService.swift +++ b/ServiceLayer/Sources/ServiceLayer/Services/StatusService.swift @@ -32,6 +32,14 @@ public extension StatusService { contentDatabase.toggleShowAttachments(id: status.displayStatus.id) } + func toggleReblogged() -> AnyPublisher { + 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 { mastodonAPIClient.request(status.displayStatus.favourited ? StatusEndpoint.unfavourite(id: status.displayStatus.id) diff --git a/ViewModels/Sources/ViewModels/StatusViewModel.swift b/ViewModels/Sources/ViewModels/StatusViewModel.swift index eaaca47..f52900f 100644 --- a/ViewModels/Sources/ViewModels/StatusViewModel.swift +++ b/ViewModels/Sources/ViewModels/StatusViewModel.swift @@ -200,6 +200,13 @@ public extension StatusViewModel { .eraseToAnyPublisher()) } + func toggleReblogged() { + eventsSubject.send( + statusService.toggleReblogged() + .map { _ in .ignorableOutput } + .eraseToAnyPublisher()) + } + func toggleFavorited() { eventsSubject.send( statusService.toggleFavorited() diff --git a/Views/Status/StatusView.swift b/Views/Status/StatusView.swift index 241fcab..f181e45 100644 --- a/Views/Status/StatusView.swift +++ b/Views/Status/StatusView.swift @@ -198,6 +198,10 @@ private extension StatusView { interactionsStackView.addArrangedSubview(favoritedByButton) interactionsStackView.distribution = .fillEqually + reblogButton.addAction( + UIAction { [weak self] _ in self?.statusConfiguration.viewModel.toggleReblogged() }, + for: .touchUpInside) + favoriteButton.addAction( UIAction { [weak self] _ in self?.statusConfiguration.viewModel.toggleFavorited() }, for: .touchUpInside)