This repository was archived by the owner on Sep 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 387
Subscribe/Unsubscribe #2482
Open
Huddie
wants to merge
7
commits into
GitHawkApp:master
Choose a base branch
from
Huddie:sub-unsub
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Subscribe/Unsubscribe #2482
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ab5e531
Subscribe/Unsubscribe
Huddie aa61bca
Working on mutation
Huddie bbda2d3
Fixed mutation
Huddie 5f1f379
Fixed code logic
Huddie 35758ba
Fixing merge
Huddie 9124e6d
Fixed test
Huddie 7cbe77a
Switched ignored to unsubscribed
Huddie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,7 +168,8 @@ extension GithubClient { | |
viewerCanAdminister: canAdmin, | ||
defaultBranch: repository.defaultBranchRef?.name ?? "master", | ||
fileChanges: issueType.fileChanges, | ||
mergeModel: issueType.mergeModel(availableTypes: availableMergeTypes) | ||
mergeModel: issueType.mergeModel(availableTypes: availableMergeTypes), | ||
subscriptionState: issueType.subscriptionState | ||
) | ||
|
||
DispatchQueue.main.async { | ||
|
@@ -297,6 +298,37 @@ extension GithubClient { | |
} | ||
} | ||
|
||
func setSubscription( | ||
previous: IssueResult, | ||
subscribe: Bool, | ||
completion: ((Result<SubscriptionState?>) -> Void)? = nil | ||
) { | ||
|
||
let state: SubscriptionState = subscribe | ||
? .subscribed | ||
: .unsubscribed | ||
|
||
let optimisticResult = previous.updated(subscriptionState: state) | ||
|
||
let cache = self.cache | ||
cache.set(value: optimisticResult) | ||
|
||
let mutation = UpdateSubscriptionMutation(subscribable_Id: previous.id, subscription_state: state) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we change these parameters to |
||
|
||
client.mutate(mutation, result: { data in | ||
data.updateSubscription?.subscribable | ||
}, completion: { result in | ||
switch result { | ||
case .success(let subscribable): | ||
completion?(.success(subscribable.viewerSubscription)) | ||
case .failure(let error): | ||
cache.set(value: previous) | ||
completion?(.error(error)) | ||
Squawk.show(error: error) | ||
} | ||
}) | ||
} | ||
|
||
enum CollaboratorPermission: String { | ||
case admin | ||
case write | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,10 +84,12 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate { | |
case lock | ||
case reopen | ||
case close | ||
case subscribe | ||
case unsubscribe | ||
} | ||
|
||
var actions: [Action] { | ||
if case .none = permissions { return [] } | ||
|
||
guard let result = self.result else { return [] } | ||
|
||
var actions = [Action]() | ||
|
@@ -97,21 +99,30 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate { | |
if result.pullRequest { | ||
actions.append(.reviewers) | ||
} | ||
} | ||
|
||
if result.subscriptionState == .subscribed { | ||
actions.append(.unsubscribe) | ||
} else { | ||
actions.append(.subscribe) | ||
} | ||
|
||
if case .collaborator = permissions { | ||
if result.labels.locked { | ||
actions.append(.unlock) | ||
} else { | ||
actions.append(.lock) | ||
} | ||
} | ||
|
||
switch result.labels.status.status { | ||
case .closed: | ||
actions.append(.reopen) | ||
case .open: | ||
actions.append(.close) | ||
case .merged: break | ||
if permissions == .collaborator || permissions == .author { | ||
switch result.labels.status.status { | ||
case .closed: | ||
actions.append(.reopen) | ||
case .open: | ||
actions.append(.close) | ||
case .merged: break | ||
} | ||
} | ||
|
||
return actions | ||
} | ||
|
||
|
@@ -144,13 +155,19 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate { | |
case .close: | ||
title = Constants.Strings.close | ||
iconName = "x" | ||
case .subscribe: | ||
title = Constants.Strings.subscribe | ||
iconName = "unmute" | ||
case .unsubscribe: | ||
title = Constants.Strings.unsubscribe | ||
iconName = "mute" | ||
} | ||
|
||
// Lock always has the divider above it assuming you're a collaborator. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should update this comment. |
||
// If you aren't a collaborator (Lock does not show), close has the divider above it. | ||
let separator: Bool | ||
switch action { | ||
case .lock, .unlock: separator = true | ||
case .subscribe, .unsubscribe: separator = true | ||
case .reopen, .close: separator = permissions != .collaborator | ||
default: separator = false | ||
} | ||
|
@@ -186,6 +203,8 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate { | |
case .lock: strongSelf.lock(true) | ||
case .reopen: strongSelf.close(false) | ||
case .close: strongSelf.close(true) | ||
case .subscribe: strongSelf.subscribe(true) | ||
case .unsubscribe: strongSelf.subscribe(false) | ||
} | ||
} | ||
} | ||
|
@@ -271,6 +290,12 @@ final class IssueManagingContextController: NSObject, ContextMenuDelegate { | |
) | ||
} | ||
|
||
func subscribe(_ doSubscribe: Bool) { | ||
guard let previous = result else { return } | ||
delegate?.willMutateModel(from: self) | ||
client.setSubscription(previous: previous, subscribe: doSubscribe) | ||
Haptic.triggerNotification(.success) | ||
} | ||
func close(_ doClose: Bool) { | ||
guard let previous = result else { return } | ||
delegate?.willMutateModel(from: self) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,9 +114,7 @@ class SplitViewTests: XCTestCase { | |
client: GithubClient(userSession: nil), | ||
repo: RepositoryDetails( | ||
owner: "Foo", | ||
name: "Bar", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was this changed? 🤔 |
||
defaultBranch: "Baz", | ||
hasIssuesEnabled: false | ||
name: "Bar" | ||
)) | ||
|
||
let detail2 = IssuesViewController( | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mutation UpdateSubscription($subscribable_Id: ID!, $subscription_state: SubscriptionState!) { | ||
updateSubscription(input:{subscribableId: $subscribable_Id, state: $subscription_state}) { | ||
subscribable{ | ||
...subscribableFields | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, what would it mean if the
state
isnil
? Would that be an actual success?