From eec134688508dfa9c0b2c2031918e3dcbbc55b0d Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Sun, 14 Oct 2018 15:56:04 -0400 Subject: [PATCH] fetch subscription status and fix mutation --- Classes/Notifications/NotificationModelController.swift | 8 +++++--- .../GitHubAPI/GitHubAPI/V3SubscribeThreadRequest.swift | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Classes/Notifications/NotificationModelController.swift b/Classes/Notifications/NotificationModelController.swift index d21143525..6a76b8993 100644 --- a/Classes/Notifications/NotificationModelController.swift +++ b/Classes/Notifications/NotificationModelController.swift @@ -101,7 +101,7 @@ final class NotificationModelController { return } - let content = "state comments{totalCount}" + let content = "state comments{totalCount} viewerSubscription" let notificationQueries: String = notifications.compactMap { guard let alias = $0.stateAlias else { return nil } return """ @@ -124,10 +124,12 @@ final class NotificationModelController { let stateString = issueOrPullRequest["state"] as? String, let state = NotificationViewModel.State(rawValue: stateString), let commentsJSON = issueOrPullRequest["comments"] as? [String: Any], - let commentCount = commentsJSON["totalCount"] as? Int { + let commentCount = commentsJSON["totalCount"] as? Int, + let subscription = issueOrPullRequest["viewerSubscription"] as? String { var newNotification = notification newNotification.state = state newNotification.comments = commentCount + newNotification.watching = subscription != "IGNORED" updatedNotifications.append(newNotification) } else { updatedNotifications.append(notification) @@ -186,7 +188,7 @@ final class NotificationModelController { model.watching = !notification.watching cache.set(value: model) - githubClient.client.send(V3SubscribeThreadRequest(id: model.v3id, ignore: model.watching)) { result in + githubClient.client.send(V3SubscribeThreadRequest(id: model.v3id, ignore: !model.watching)) { result in switch result { case .success: Haptic.triggerSelection() diff --git a/Local Pods/GitHubAPI/GitHubAPI/V3SubscribeThreadRequest.swift b/Local Pods/GitHubAPI/GitHubAPI/V3SubscribeThreadRequest.swift index c30082710..57f1c8d7c 100644 --- a/Local Pods/GitHubAPI/GitHubAPI/V3SubscribeThreadRequest.swift +++ b/Local Pods/GitHubAPI/GitHubAPI/V3SubscribeThreadRequest.swift @@ -16,7 +16,7 @@ public struct V3SubscribeThreadRequest: V3Request { public var method: HTTPMethod { return .put } public var parameters: [String : Any]? { return [ - "ignored": ignore ? "true" : "false" + "ignored": ignore ? true : false ] }