Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 22ab3fb

Browse files
authored
fetch subscription status and fix mutation (#2291)
1 parent c23945a commit 22ab3fb

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Classes/Notifications/NotificationModelController.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ final class NotificationModelController {
101101
return
102102
}
103103

104-
let content = "state comments{totalCount}"
104+
let content = "state comments{totalCount} viewerSubscription"
105105
let notificationQueries: String = notifications.compactMap {
106106
guard let alias = $0.stateAlias else { return nil }
107107
return """
@@ -124,10 +124,12 @@ final class NotificationModelController {
124124
let stateString = issueOrPullRequest["state"] as? String,
125125
let state = NotificationViewModel.State(rawValue: stateString),
126126
let commentsJSON = issueOrPullRequest["comments"] as? [String: Any],
127-
let commentCount = commentsJSON["totalCount"] as? Int {
127+
let commentCount = commentsJSON["totalCount"] as? Int,
128+
let subscription = issueOrPullRequest["viewerSubscription"] as? String {
128129
var newNotification = notification
129130
newNotification.state = state
130131
newNotification.comments = commentCount
132+
newNotification.watching = subscription != "IGNORED"
131133
updatedNotifications.append(newNotification)
132134
} else {
133135
updatedNotifications.append(notification)
@@ -186,7 +188,7 @@ final class NotificationModelController {
186188
model.watching = !notification.watching
187189
cache.set(value: model)
188190

189-
githubClient.client.send(V3SubscribeThreadRequest(id: model.v3id, ignore: model.watching)) { result in
191+
githubClient.client.send(V3SubscribeThreadRequest(id: model.v3id, ignore: !model.watching)) { result in
190192
switch result {
191193
case .success:
192194
Haptic.triggerSelection()

Local Pods/GitHubAPI/GitHubAPI/V3SubscribeThreadRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public struct V3SubscribeThreadRequest: V3Request {
1616
public var method: HTTPMethod { return .put }
1717
public var parameters: [String : Any]? {
1818
return [
19-
"ignored": ignore ? "true" : "false"
19+
"ignored": ignore ? true : false
2020
]
2121
}
2222

0 commit comments

Comments
 (0)