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

Fetch subscription status and fix mutation #2291

Merged
merged 1 commit into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Classes/Notifications/NotificationModelController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
]
}

Expand Down