forked from shadowfacts/Tusker
Fix non-mention notifications showing in Mentions tab on Pleroma
e0d97cd2a8
introduced a regression on Pleroma, because specifying the
allowed types of notifications in the Masto API was only added in 3.5
This commit is contained in:
parent
9f86158bb7
commit
1cb0f1ae56
|
@ -306,6 +306,14 @@ public class Client {
|
|||
return request
|
||||
}
|
||||
|
||||
public static func getNotifications(excludedTypes: [Notification.Kind], range: RequestRange = .default) -> Request<[Notification]> {
|
||||
var request = Request<[Notification]>(method: .get, path: "/api/v1/notifications", queryParameters:
|
||||
"exclude_types" => excludedTypes.map { $0.rawValue }
|
||||
)
|
||||
request.range = range
|
||||
return request
|
||||
}
|
||||
|
||||
public static func clearNotifications() -> Request<Empty> {
|
||||
return Request<Empty>(method: .post, path: "/api/v1/notifications/clear")
|
||||
}
|
||||
|
|
|
@ -93,6 +93,10 @@ struct InstanceFeatures {
|
|||
hasMastodonVersion(4, 0, 0)
|
||||
}
|
||||
|
||||
var notificationsAllowedTypes: Bool {
|
||||
hasMastodonVersion(3, 5, 0)
|
||||
}
|
||||
|
||||
mutating func update(instance: Instance, nodeInfo: NodeInfo?) {
|
||||
let ver = instance.version.lowercased()
|
||||
if ver.contains("glitch") {
|
||||
|
|
|
@ -57,6 +57,16 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController<
|
|||
tableView.register(UINib(nibName: "BasicTableViewCell", bundle: .main), forCellReuseIdentifier: unknownCell)
|
||||
}
|
||||
|
||||
private func request(range: RequestRange) -> Request<[Pachyderm.Notification]> {
|
||||
if mastodonController.instanceFeatures.notificationsAllowedTypes {
|
||||
return Client.getNotifications(allowedTypes: allowedTypes, range: range)
|
||||
} else {
|
||||
var types = Set(Notification.Kind.allCases)
|
||||
allowedTypes.forEach { types.remove($0) }
|
||||
return Client.getNotifications(excludedTypes: Array(types), range: range)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - DiffableTimelineLikeTableViewController
|
||||
|
||||
override func cellProvider(_ tableView: UITableView, _ indexPath: IndexPath, _ item: Item) -> UITableViewCell? {
|
||||
|
@ -140,8 +150,7 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController<
|
|||
}
|
||||
|
||||
override func loadInitialItems(completion: @escaping (LoadResult) -> Void) {
|
||||
let request = Client.getNotifications(allowedTypes: allowedTypes)
|
||||
mastodonController.run(request) { (response) in
|
||||
mastodonController.run(request(range: .default)) { (response) in
|
||||
switch response {
|
||||
case let .failure(error):
|
||||
completion(.failure(.client(error)))
|
||||
|
@ -171,8 +180,7 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController<
|
|||
return
|
||||
}
|
||||
|
||||
let request = Client.getNotifications(allowedTypes: allowedTypes, range: older)
|
||||
mastodonController.run(request) { (response) in
|
||||
mastodonController.run(request(range: older)) { (response) in
|
||||
switch response {
|
||||
case let .failure(error):
|
||||
completion(.failure(.client(error)))
|
||||
|
@ -203,8 +211,7 @@ class NotificationsTableViewController: DiffableTimelineLikeTableViewController<
|
|||
return
|
||||
}
|
||||
|
||||
let request = Client.getNotifications(allowedTypes: allowedTypes, range: newer)
|
||||
mastodonController.run(request) { (response) in
|
||||
mastodonController.run(request(range: newer)) { (response) in
|
||||
switch response {
|
||||
case let .failure(error):
|
||||
completion(.failure(.client(error)))
|
||||
|
|
Loading…
Reference in New Issue