Add menu action to hide/show reblogs

Closes #206
This commit is contained in:
Shadowfacts 2023-01-26 18:50:05 -05:00
parent 9f1d3804d9
commit e11784904b
2 changed files with 26 additions and 1 deletions

View File

@ -109,6 +109,12 @@ public final class Account: AccountProtocol, Decodable {
return Request<Relationship>(method: .post, path: "/api/v1/accounts/\(accountID)/follow") return Request<Relationship>(method: .post, path: "/api/v1/accounts/\(accountID)/follow")
} }
public static func setShowReblogs(_ accountID: String, showReblogs: Bool) -> Request<Relationship> {
return Request(method: .post, path: "/api/v1/accounts/\(accountID)/follow", body: ParametersBody([
"reblogs" => showReblogs
]))
}
public static func unfollow(_ accountID: String) -> Request<Relationship> { public static func unfollow(_ accountID: String) -> Request<Relationship> {
return Request<Relationship>(method: .post, path: "/api/v1/accounts/\(accountID)/unfollow") return Request<Relationship>(method: .post, path: "/api/v1/accounts/\(accountID)/unfollow")
} }

View File

@ -97,8 +97,9 @@ extension MenuActionProvider {
})) }))
elementHandler([UIMenu(title: "Add to List", image: UIImage(systemName: "list.bullet"), children: listActions)]) elementHandler([UIMenu(title: "Add to List", image: UIImage(systemName: "list.bullet"), children: listActions)])
})) }))
suppressSection.append(relationshipAction(fetchRelationship, accountID: accountID, mastodonController: mastodonController, builder: { [unowned self] in self.blockAction(for: $0, mastodonController: $1) })) suppressSection.append(relationshipAction(fetchRelationship, accountID: accountID, mastodonController: mastodonController, builder: { [unowned self] in self.hideReblogsAction(for: $0, mastodonController: $1) }))
suppressSection.append(relationshipAction(fetchRelationship, accountID: accountID, mastodonController: mastodonController, builder: { [unowned self] in self.muteAction(for: $0, mastodonController: $1) })) suppressSection.append(relationshipAction(fetchRelationship, accountID: accountID, mastodonController: mastodonController, builder: { [unowned self] in self.muteAction(for: $0, mastodonController: $1) }))
suppressSection.append(relationshipAction(fetchRelationship, accountID: accountID, mastodonController: mastodonController, builder: { [unowned self] in self.blockAction(for: $0, mastodonController: $1) }))
suppressSection.append(createAction(identifier: "report", title: "Report", systemImageName: "flag", handler: { [unowned self] _ in suppressSection.append(createAction(identifier: "report", title: "Report", systemImageName: "flag", handler: { [unowned self] _ in
let view = ReportView(report: EditedReport(accountID: accountID), mastodonController: mastodonController) let view = ReportView(report: EditedReport(accountID: accountID), mastodonController: mastodonController)
let host = UIHostingController(rootView: view) let host = UIHostingController(rootView: view)
@ -538,6 +539,24 @@ extension MenuActionProvider {
} }
} }
@MainActor
private func hideReblogsAction(for relationship: RelationshipMO, mastodonController: MastodonController) -> UIMenuElement {
let title = relationship.showingReblogs ? "Hide Reblogs" : "Show Reblogs"
// todo: need alternate repeat icon to use here
return UIAction(title: title, image: nil) { [weak self] _ in
let req = Account.setShowReblogs(relationship.accountID, showReblogs: !relationship.showingReblogs)
mastodonController.run(req) { response in
switch response {
case .failure(let error):
self?.handleError(error, title: "Error \(relationship.showingReblogs ? "Hiding" : "Showing") Reblogs")
case .success(let relationship, _):
mastodonController.persistentContainer.addOrUpdate(relationship: relationship)
self?.handleSuccess(title: relationship.showingReblogs ? "Reblogs Shown" : "Reblogs Hidden")
}
}
}
}
} }
private func fetchRelationship(accountID: String, mastodonController: MastodonController) async -> RelationshipMO? { private func fetchRelationship(accountID: String, mastodonController: MastodonController) async -> RelationshipMO? {