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)
|
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
|
toggleableSection.insert(createAction(identifier: "favorite", title: favorited ? "Unfavorite" : "Favorite", image: favImage, handler: { [weak self] _ in
|
||||||
guard let self = self else { return }
|
guard let self,
|
||||||
let request = (favorited ? Status.favourite : Status.unfavourite)(status.id)
|
let navigationDelegate = self.navigationDelegate else { return }
|
||||||
self.mastodonController?.run(request, completion: { response in
|
Task { @MainActor in
|
||||||
switch response {
|
await FavoriteService(status: status, mastodonController: mastodonController, presenter: navigationDelegate).toggleFavorite()
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}), at: 0)
|
}), at: 0)
|
||||||
|
|
||||||
let reblogged = status.reblogged
|
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)
|
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
|
toggleableSection.insert(createAction(identifier: "reblog", title: reblogged ? "Unreblog" : "Reblog", image: reblogImage, handler: { [weak self] _ in
|
||||||
guard let self = self else { return }
|
guard let self,
|
||||||
let request: Request<Status>
|
let navigationDelegate = self.navigationDelegate else { return }
|
||||||
if reblogged {
|
Task { @MainActor in
|
||||||
request = Status.reblog(status.id)
|
await ReblogService(status: status, mastodonController: mastodonController, presenter: navigationDelegate).toggleReblog()
|
||||||
} else {
|
|
||||||
request = Status.unreblog(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 \(reblogged ? "Unr" : "R")eblogging", in: toastable, retryAction: nil)
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
toastable.showToast(configuration: config, animated: true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}), at: 1)
|
}), 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?
|
let image: UIImage?
|
||||||
if let name = systemImageName {
|
if let name = systemImageName {
|
||||||
image = UIImage(systemName: name)
|
image = UIImage(systemName: name)
|
||||||
|
|
Loading…
Reference in New Issue