Skip to content

Commit

Permalink
Add comment reactors to comment reaction (microsoft#5567)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexr00 authored Dec 19, 2023
1 parent 418162e commit cd395de
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"tokenInformation",
"contribShareMenu",
"fileComments",
"commentReactor",
"contribCommentPeekContext",
"contribCommentThreadAdditionalMenu",
"codiconDecoration",
Expand Down
10 changes: 10 additions & 0 deletions src/@types/vscode.proposed.commentReactor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

declare module 'vscode' {
export interface CommentReaction {
readonly reactors?: readonly string[];
}
}
1 change: 1 addition & 0 deletions src/common/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface Reaction {
count: number;
icon?: vscode.Uri;
viewerHasReacted: boolean;
reactors: readonly string[];
}

export enum SubjectType {
Expand Down
5 changes: 4 additions & 1 deletion src/github/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ export interface IssueComment extends AbbreviatedIssueComment {
export interface ReactionGroup {
content: string;
viewerHasReacted: boolean;
users: {
reactors: {
nodes: {
login: string;
}[]
totalCount: number;
};
}
Expand Down
15 changes: 7 additions & 8 deletions src/github/queriesShared.gql
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@ fragment Reactable on Reactable {
reactionGroups {
content
viewerHasReacted
users {
reactors(first: 10) {
nodes {
... on User {
login
}
}
totalCount
}
}
Expand Down Expand Up @@ -399,13 +404,7 @@ fragment ReviewComment on PullRequestReviewComment {
originalCommit {
oid
}
reactionGroups {
content
viewerHasReacted
users {
totalCount
}
}
...Reactable
viewerCanUpdate
viewerCanDelete
}
Expand Down
6 changes: 4 additions & 2 deletions src/github/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export function updateCommentReactions(comment: vscode.Comment, reactions: React
authorHasReacted: matchedReaction.viewerHasReacted,
count: matchedReaction.count,
iconPath: reaction.icon || '',
reactors: matchedReaction.reactors
};
} else {
newReaction = { label: reaction.label, authorHasReacted: false, count: 0, iconPath: reaction.icon || '' };
Expand Down Expand Up @@ -511,13 +512,14 @@ export function parseGraphQLReaction(reactionGroups: GraphQL.ReactionGroup[]): R
}, {} as { [key: string]: { title: string; label: string; icon?: vscode.Uri } });

const reactions = reactionGroups
.filter(group => group.users.totalCount > 0)
.filter(group => group.reactors.totalCount > 0)
.map(group => {
const reaction: Reaction = {
label: reactionContentEmojiMapping[group.content].label,
count: group.users.totalCount,
count: group.reactors.totalCount,
icon: reactionContentEmojiMapping[group.content].icon,
viewerHasReacted: group.viewerHasReacted,
reactors: group.reactors.nodes.map(node => node.login)
};

return reaction;
Expand Down

0 comments on commit cd395de

Please sign in to comment.