Skip to content

Commit 646bb51

Browse files
authored
Add comment reactors to comment reactions (#201132)
Add comment reactors proposal Part of #201131
1 parent 60017c3 commit 646bb51

File tree

6 files changed

+57
-17
lines changed

6 files changed

+57
-17
lines changed

src/vs/editor/common/languages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,7 @@ export interface CommentReaction {
17781778
readonly count?: number;
17791779
readonly hasReacted?: boolean;
17801780
readonly canEdit?: boolean;
1781+
readonly reactors?: readonly string[];
17811782
}
17821783

17831784
/**

src/vs/workbench/api/common/extHostComments.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,10 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
673673
checkProposedApiEnabled(extension, 'commentsDraftState');
674674
}
675675

676+
if (vscodeComment.reactions?.some(reaction => reaction.reactors !== undefined)) {
677+
checkProposedApiEnabled(extension, 'commentReactor');
678+
}
679+
676680
return {
677681
mode: vscodeComment.mode,
678682
contextValue: vscodeComment.contextValue,
@@ -693,6 +697,7 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
693697
iconPath: reaction.iconPath ? extHostTypeConverter.pathOrURIToURI(reaction.iconPath) : undefined,
694698
count: reaction.count,
695699
hasReacted: reaction.authorHasReacted,
700+
reactors: reaction.reactors
696701
};
697702
}
698703

@@ -701,7 +706,8 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
701706
label: reaction.label || '',
702707
count: reaction.count || 0,
703708
iconPath: reaction.iconPath ? URI.revive(reaction.iconPath) : '',
704-
authorHasReacted: reaction.hasReacted || false
709+
authorHasReacted: reaction.hasReacted || false,
710+
reactors: reaction.reactors
705711
};
706712
}
707713

src/vs/workbench/contrib/comments/browser/commentNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ export class CommentNode<T extends IRange | ICellRange> extends Disposable {
459459
}
460460
this.notificationService.error(error);
461461
}
462-
}, reaction.iconPath, reaction.count);
462+
}, reaction.reactors, reaction.iconPath, reaction.count);
463463

464464
this._reactionsActionBar?.push(action, { label: true, icon: true });
465465
});

src/vs/workbench/contrib/comments/browser/reactionsAction.ts

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,46 @@ export class ReactionActionViewItem extends ActionViewItem {
6666
'This is a tooltip for an emoji button so that the current user can toggle their reaction to a comment.',
6767
'The first arg is localized message "Toggle reaction" or empty if the user doesn\'t have permission to toggle the reaction, the second is the name of the reaction.']
6868
}, "{0}{1} reaction", toggleMessage, action.label);
69-
} else if (action.count === 1) {
70-
return nls.localize({
71-
key: 'comment.reactionLabelOne', comment: [
72-
'This is a tooltip for an emoji that is a "reaction" to a comment where the count of the reactions is 1.',
73-
'The emoji is also a button so that the current user can also toggle their own emoji reaction.',
74-
'The first arg is localized message "Toggle reaction" or empty if the user doesn\'t have permission to toggle the reaction, the second is the name of the reaction.']
75-
}, "{0}1 reaction with {1}", toggleMessage, action.label);
76-
} else if (action.count > 1) {
77-
return nls.localize({
78-
key: 'comment.reactionLabelMany', comment: [
79-
'This is a tooltip for an emoji that is a "reaction" to a comment where the count of the reactions is greater than 1.',
80-
'The emoji is also a button so that the current user can also toggle their own emoji reaction.',
81-
'The first arg is localized message "Toggle reaction" or empty if the user doesn\'t have permission to toggle the reaction, the second is number of users who have reacted with that reaction, and the third is the name of the reaction.']
82-
}, "{0}{1} reactions with {2}", toggleMessage, action.count, action.label);
69+
} else if (action.reactors === undefined || action.reactors.length === 0) {
70+
if (action.count === 1) {
71+
return nls.localize({
72+
key: 'comment.reactionLabelOne', comment: [
73+
'This is a tooltip for an emoji that is a "reaction" to a comment where the count of the reactions is 1.',
74+
'The emoji is also a button so that the current user can also toggle their own emoji reaction.',
75+
'The first arg is localized message "Toggle reaction" or empty if the user doesn\'t have permission to toggle the reaction, the second is the name of the reaction.']
76+
}, "{0}1 reaction with {1}", toggleMessage, action.label);
77+
} else if (action.count > 1) {
78+
return nls.localize({
79+
key: 'comment.reactionLabelMany', comment: [
80+
'This is a tooltip for an emoji that is a "reaction" to a comment where the count of the reactions is greater than 1.',
81+
'The emoji is also a button so that the current user can also toggle their own emoji reaction.',
82+
'The first arg is localized message "Toggle reaction" or empty if the user doesn\'t have permission to toggle the reaction, the second is number of users who have reacted with that reaction, and the third is the name of the reaction.']
83+
}, "{0}{1} reactions with {2}", toggleMessage, action.count, action.label);
84+
}
85+
} else {
86+
if (action.reactors.length <= 10 && action.reactors.length === action.count) {
87+
return nls.localize({
88+
key: 'comment.reactionLessThanTen', comment: [
89+
'This is a tooltip for an emoji that is a "reaction" to a comment where the count of the reactions is less than or equal to 10.',
90+
'The emoji is also a button so that the current user can also toggle their own emoji reaction.',
91+
'The first arg is localized message "Toggle reaction" or empty if the user doesn\'t have permission to toggle the reaction, the second iis a list of the reactors, and the third is the name of the reaction.']
92+
}, "{0}{1} reacted with {2}", toggleMessage, action.reactors.join(', '), action.label);
93+
} else if (action.count > 1) {
94+
const displayedReactors = action.reactors.slice(0, 10);
95+
return nls.localize({
96+
key: 'comment.reactionMoreThanTen', comment: [
97+
'This is a tooltip for an emoji that is a "reaction" to a comment where the count of the reactions is less than or equal to 10.',
98+
'The emoji is also a button so that the current user can also toggle their own emoji reaction.',
99+
'The first arg is localized message "Toggle reaction" or empty if the user doesn\'t have permission to toggle the reaction, the second iis a list of the reactors, and the third is the name of the reaction.']
100+
}, "{0}{1} and {2} more reacted with {3}", toggleMessage, displayedReactors.join(', '), action.count - displayedReactors.length, action.label);
101+
}
83102
}
84103
return undefined;
85104
}
86105
}
87106
export class ReactionAction extends Action {
88107
static readonly ID = 'toolbar.toggle.reaction';
89-
constructor(id: string, label: string = '', cssClass: string = '', enabled: boolean = true, actionCallback?: (event?: any) => Promise<any>, public icon?: UriComponents, public count?: number) {
108+
constructor(id: string, label: string = '', cssClass: string = '', enabled: boolean = true, actionCallback?: (event?: any) => Promise<any>, public readonly reactors?: readonly string[], public icon?: UriComponents, public count?: number) {
90109
super(ReactionAction.ID, label, cssClass, enabled, actionCallback);
91110
}
92111
}

src/vs/workbench/services/extensions/common/extensionsApiProposals.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const allApiProposals = Object.freeze({
1919
chatVariables: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.chatVariables.d.ts',
2020
codeActionAI: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.codeActionAI.d.ts',
2121
codiconDecoration: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.codiconDecoration.d.ts',
22+
commentReactor: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.commentReactor.d.ts',
2223
commentsDraftState: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.commentsDraftState.d.ts',
2324
contribCommentEditorActionsMenu: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribCommentEditorActionsMenu.d.ts',
2425
contribCommentPeekContext: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribCommentPeekContext.d.ts',
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
declare module 'vscode' {
7+
8+
// @alexr00 https://github.com/microsoft/vscode/issues/201131
9+
10+
export interface CommentReaction {
11+
readonly reactors?: readonly string[];
12+
}
13+
}

0 commit comments

Comments
 (0)