fetch subscription status and fix mutation (#2291)

This commit is contained in:
Ryan Nystrom
2018-10-16 22:19:41 -04:00
committed by GitHub
parent c23945ac7d
commit 22ab3fbf19
2 changed files with 6 additions and 4 deletions

View File

@@ -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()

View File

@@ -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
]
}