parent
911e73c78f
commit
d0c49144c4
|
@ -15,9 +15,9 @@ public class Notification: Decodable {
|
||||||
public let account: Account
|
public let account: Account
|
||||||
public let status: Status?
|
public let status: Status?
|
||||||
|
|
||||||
public static func dismiss(_ notification: Notification) -> Request<Empty> {
|
public static func dismiss(id notificationID: String) -> Request<Empty> {
|
||||||
return Request<Empty>(method: .post, path: "/api/v1/notifications/dismiss", body: .parameters([
|
return Request<Empty>(method: .post, path: "/api/v1/notifications/dismiss", body: .parameters([
|
||||||
"id" => notification.id
|
"id" => notificationID
|
||||||
]))
|
]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,7 +140,32 @@ class NotificationsTableViewController: EnhancedTableViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
|
||||||
return (tableView.cellForRow(at: indexPath) as? TableViewSwipeActionProvider)?.trailingSwipeActionsConfiguration()
|
let dismissAction = UIContextualAction(style: .destructive, title: NSLocalizedString("Dismiss", comment: "dismiss notification swipe action title")) { (action, view, completion) in
|
||||||
|
let group = DispatchGroup()
|
||||||
|
self.groups[indexPath.row].notificationIDs
|
||||||
|
.map(Pachyderm.Notification.dismiss(id:))
|
||||||
|
.forEach { (request) in
|
||||||
|
group.enter()
|
||||||
|
MastodonController.client.run(request) { (response) in
|
||||||
|
group.leave()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
group.notify(queue: .main) {
|
||||||
|
self.groups.remove(at: indexPath.row)
|
||||||
|
self.tableView.deleteRows(at: [indexPath], with: .automatic)
|
||||||
|
completion(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dismissAction.image = UIImage(systemName: "clear.fill")
|
||||||
|
let cellConfiguration = (tableView.cellForRow(at: indexPath) as? TableViewSwipeActionProvider)?.trailingSwipeActionsConfiguration()
|
||||||
|
let config: UISwipeActionsConfiguration
|
||||||
|
if let cellConfiguration = cellConfiguration {
|
||||||
|
config = UISwipeActionsConfiguration(actions: [dismissAction] + cellConfiguration.actions)
|
||||||
|
} else {
|
||||||
|
config = UISwipeActionsConfiguration(actions: [dismissAction])
|
||||||
|
}
|
||||||
|
config.performsFirstActionWithFullSwipe = true
|
||||||
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func refreshNotifications(_ sender: Any) {
|
@objc func refreshNotifications(_ sender: Any) {
|
||||||
|
|
Loading…
Reference in New Issue