Add notification dismissal swipe action

#49
This commit is contained in:
Shadowfacts 2019-09-16 16:08:25 -04:00
parent 911e73c78f
commit d0c49144c4
2 changed files with 28 additions and 3 deletions

View File

@ -15,9 +15,9 @@ public class Notification: Decodable {
public let account: Account
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([
"id" => notification.id
"id" => notificationID
]))
}

View File

@ -140,7 +140,32 @@ class NotificationsTableViewController: EnhancedTableViewController {
}
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) {