Add API param for reblog visibility

This commit is contained in:
Shadowfacts 2022-09-18 00:26:37 -04:00
parent c6c8f63e39
commit 7161861d36
4 changed files with 23 additions and 8 deletions

View File

@ -67,8 +67,13 @@ public final class Status: StatusProtocol, Decodable {
return Request<Empty>(method: .delete, path: "/api/v1/statuses/\(status.id)")
}
public static func reblog(_ statusID: String) -> Request<Status> {
return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/reblog")
public static func reblog(_ statusID: String, visibility: Visibility? = nil) -> Request<Status> {
var params: [Parameter] = []
if let visibility {
assert([.public, .unlisted, .private].contains(visibility))
params.append("visibility" => visibility.rawValue)
}
return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/reblog", queryParameters: params)
}
public static func unreblog(_ statusID: String) -> Request<Status> {

View File

@ -198,7 +198,12 @@ extension MenuActionProvider {
}
toggleableSection.insert(createAction(identifier: "reblog", title: reblogged ? "Unreblog" : "Reblog", image: reblogImage, handler: { [weak self] _ in
guard let self = self else { return }
let request = (reblogged ? Status.reblog : Status.unreblog)(status.id)
let request: Request<Status>
if reblogged {
request = Status.reblog(status.id)
} else {
request = Status.unreblog(status.id)
}
self.mastodonController?.run(request, completion: { response in
switch response {
case .success(let status, _):

View File

@ -416,24 +416,29 @@ class BaseStatusTableViewCell: UITableViewCell {
let config = CustomAlertController.Configuration(title: "Are you sure you want to reblog this post?", content: preview, actions: [
CustomAlertController.Action(title: "Cancel", style: .cancel, handler: nil),
CustomAlertController.Action(title: "Reblog", style: .default, handler: { [unowned self] in
self.toggleReblogInternal()
self.toggleReblogInternal(visibility: nil)
}),
])
let alert = CustomAlertController(config: config)
delegate?.present(alert, animated: true)
} else {
toggleReblogInternal()
toggleReblogInternal(visibility: nil)
}
}
private func toggleReblogInternal() {
private func toggleReblogInternal(visibility: Status.Visibility?) {
guard let status = mastodonController.persistentContainer.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") }
let oldValue = reblogged
reblogged = !reblogged
let realStatus = status.reblog ?? status
let request = (reblogged ? Status.reblog : Status.unreblog)(realStatus.id)
let request: Request<Status>
if reblogged {
request = Status.reblog(realStatus.id, visibility: visibility)
} else {
request = Status.unreblog(realStatus.id)
}
mastodonController.run(request) { response in
DispatchQueue.main.async {
if case let .success(newStatus, _) = response {

View File

@ -202,7 +202,7 @@ struct XCBActions {
}
static func reblogStatus(_ request: XCBRequest, _ session: XCBSession, _ silent: Bool?) {
statusAction(request: Status.reblog, alertTitle: "Reblog status?", request, session, silent)
statusAction(request: { Status.reblog($0) }, alertTitle: "Reblog status?", request, session, silent)
}
static func statusAction(request: @escaping (String) -> Request<Status>, alertTitle: String, _ url: XCBRequest, _ session: XCBSession, _ silent: Bool?) {