Add API param for reblog visibility
This commit is contained in:
parent
c6c8f63e39
commit
7161861d36
|
@ -67,8 +67,13 @@ public final class Status: StatusProtocol, Decodable {
|
||||||
return Request<Empty>(method: .delete, path: "/api/v1/statuses/\(status.id)")
|
return Request<Empty>(method: .delete, path: "/api/v1/statuses/\(status.id)")
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func reblog(_ statusID: String) -> Request<Status> {
|
public static func reblog(_ statusID: String, visibility: Visibility? = nil) -> Request<Status> {
|
||||||
return Request<Status>(method: .post, path: "/api/v1/statuses/\(statusID)/reblog")
|
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> {
|
public static func unreblog(_ statusID: String) -> Request<Status> {
|
||||||
|
|
|
@ -198,7 +198,12 @@ extension MenuActionProvider {
|
||||||
}
|
}
|
||||||
toggleableSection.insert(createAction(identifier: "reblog", title: reblogged ? "Unreblog" : "Reblog", image: reblogImage, handler: { [weak self] _ in
|
toggleableSection.insert(createAction(identifier: "reblog", title: reblogged ? "Unreblog" : "Reblog", image: reblogImage, handler: { [weak self] _ in
|
||||||
guard let self = self else { return }
|
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
|
self.mastodonController?.run(request, completion: { response in
|
||||||
switch response {
|
switch response {
|
||||||
case .success(let status, _):
|
case .success(let status, _):
|
||||||
|
|
|
@ -416,24 +416,29 @@ class BaseStatusTableViewCell: UITableViewCell {
|
||||||
let config = CustomAlertController.Configuration(title: "Are you sure you want to reblog this post?", content: preview, actions: [
|
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: "Cancel", style: .cancel, handler: nil),
|
||||||
CustomAlertController.Action(title: "Reblog", style: .default, handler: { [unowned self] in
|
CustomAlertController.Action(title: "Reblog", style: .default, handler: { [unowned self] in
|
||||||
self.toggleReblogInternal()
|
self.toggleReblogInternal(visibility: nil)
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
let alert = CustomAlertController(config: config)
|
let alert = CustomAlertController(config: config)
|
||||||
delegate?.present(alert, animated: true)
|
delegate?.present(alert, animated: true)
|
||||||
} else {
|
} 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!)") }
|
guard let status = mastodonController.persistentContainer.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") }
|
||||||
|
|
||||||
let oldValue = reblogged
|
let oldValue = reblogged
|
||||||
reblogged = !reblogged
|
reblogged = !reblogged
|
||||||
|
|
||||||
let realStatus = status.reblog ?? status
|
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
|
mastodonController.run(request) { response in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
if case let .success(newStatus, _) = response {
|
if case let .success(newStatus, _) = response {
|
||||||
|
|
|
@ -202,7 +202,7 @@ struct XCBActions {
|
||||||
}
|
}
|
||||||
|
|
||||||
static func reblogStatus(_ request: XCBRequest, _ session: XCBSession, _ silent: Bool?) {
|
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?) {
|
static func statusAction(request: @escaping (String) -> Request<Status>, alertTitle: String, _ url: XCBRequest, _ session: XCBSession, _ silent: Bool?) {
|
||||||
|
|
Loading…
Reference in New Issue