forked from shadowfacts/Tusker
Fix favorite/reblog menu actions not working
This commit is contained in:
parent
68646c4b4d
commit
6bc4993d81
|
@ -185,21 +185,11 @@ extension MenuActionProvider {
|
|||
favImage = favImage.withTintColor(UIColor(displayP3Red: 1, green: 0.8, blue: 0, alpha: 1), renderingMode: .alwaysOriginal)
|
||||
}
|
||||
toggleableSection.insert(createAction(identifier: "favorite", title: favorited ? "Unfavorite" : "Favorite", image: favImage, handler: { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
let request = (favorited ? Status.favourite : Status.unfavourite)(status.id)
|
||||
self.mastodonController?.run(request, completion: { response in
|
||||
switch response {
|
||||
case .success(let status, _):
|
||||
self.mastodonController?.persistentContainer.addOrUpdate(status: status)
|
||||
case .failure(let error):
|
||||
if let toastable = self.toastableViewController {
|
||||
let config = ToastConfiguration(from: error, with: "Error \(favorited ? "Unf" : "F")avoriting", in: toastable, retryAction: nil)
|
||||
DispatchQueue.main.async {
|
||||
toastable.showToast(configuration: config, animated: true)
|
||||
guard let self,
|
||||
let navigationDelegate = self.navigationDelegate else { return }
|
||||
Task { @MainActor in
|
||||
await FavoriteService(status: status, mastodonController: mastodonController, presenter: navigationDelegate).toggleFavorite()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}), at: 0)
|
||||
|
||||
let reblogged = status.reblogged
|
||||
|
@ -208,26 +198,11 @@ extension MenuActionProvider {
|
|||
reblogImage = reblogImage.withTintColor(UIColor(displayP3Red: 1, green: 0.8, blue: 0, alpha: 1), renderingMode: .alwaysOriginal)
|
||||
}
|
||||
toggleableSection.insert(createAction(identifier: "reblog", title: reblogged ? "Unreblog" : "Reblog", image: reblogImage, handler: { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
let request: Request<Status>
|
||||
if reblogged {
|
||||
request = Status.reblog(status.id)
|
||||
} else {
|
||||
request = Status.unreblog(status.id)
|
||||
guard let self,
|
||||
let navigationDelegate = self.navigationDelegate else { return }
|
||||
Task { @MainActor in
|
||||
await ReblogService(status: status, mastodonController: mastodonController, presenter: navigationDelegate).toggleReblog()
|
||||
}
|
||||
self.mastodonController?.run(request, completion: { response in
|
||||
switch response {
|
||||
case .success(let status, _):
|
||||
self.mastodonController?.persistentContainer.addOrUpdate(status: status)
|
||||
case .failure(let error):
|
||||
if let toastable = self.toastableViewController {
|
||||
let config = ToastConfiguration(from: error, with: "Error \(reblogged ? "Unr" : "R")eblogging", in: toastable, retryAction: nil)
|
||||
DispatchQueue.main.async {
|
||||
toastable.showToast(configuration: config, animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}), at: 1)
|
||||
}
|
||||
|
||||
|
@ -362,7 +337,7 @@ extension MenuActionProvider {
|
|||
]
|
||||
}
|
||||
|
||||
private func createAction(identifier: String, title: String, systemImageName: String?, handler: @escaping UIActionHandler) -> UIAction {
|
||||
private func createAction(identifier: String, title: String, systemImageName: String?, handler: @escaping (UIAction) -> Void) -> UIAction {
|
||||
let image: UIImage?
|
||||
if let name = systemImageName {
|
||||
image = UIImage(systemName: name)
|
||||
|
|
Loading…
Reference in New Issue