reactions handler

This commit is contained in:
Peng Lyu
2019-06-05 21:08:41 -07:00
parent a03caec78b
commit cae0668a0e
8 changed files with 126 additions and 37 deletions

View File

@@ -284,6 +284,9 @@ export class MainThreadCommentController {
private readonly _threads: Map<number, MainThreadCommentThread> = new Map<number, MainThreadCommentThread>();
public activeCommentThread?: MainThreadCommentThread;
get features(): CommentProviderFeatures {
return this._features;
}
constructor(
private readonly _proxy: ExtHostCommentsShape,

View File

@@ -131,6 +131,7 @@ export interface CommentProviderFeatures {
finishDraftLabel?: string;
reactionGroup?: modes.CommentReaction[];
commentThreadTemplate?: CommentThreadTemplate;
reactionHandler?: boolean;
}
export interface MainThreadCommentsShape extends IDisposable {

View File

@@ -210,7 +210,7 @@ export class ExtHostComments implements ExtHostCommentsShape {
const document = this._documents.getDocument(URI.revive(uri));
const commentController = this._commentControllers.get(commentControllerHandle);
if (!commentController || !commentController.reactionProvider || !commentController.reactionProvider.toggleReaction) {
if (!commentController || !((commentController.reactionProvider && commentController.reactionProvider.toggleReaction) || commentController.reactionHandler)) {
return Promise.resolve(undefined);
}
@@ -219,9 +219,16 @@ export class ExtHostComments implements ExtHostCommentsShape {
if (commentThread) {
const vscodeComment = commentThread.getComment(comment.commentId);
if (commentController !== undefined && commentController.reactionProvider && commentController.reactionProvider.toggleReaction && vscodeComment) {
return commentController.reactionProvider.toggleReaction(document, vscodeComment, convertFromReaction(reaction));
if (commentController !== undefined && vscodeComment) {
if (commentController.reactionHandler) {
return commentController.reactionHandler(vscodeComment, convertFromReaction(reaction));
}
if (commentController.reactionProvider && commentController.reactionProvider.toggleReaction) {
return commentController.reactionProvider.toggleReaction(document, vscodeComment, convertFromReaction(reaction));
}
}
}
return Promise.resolve(undefined);
@@ -635,7 +642,7 @@ export class ExtHostCommentThread implements vscode.CommentThread {
}
getComment(commentId: string): vscode.Comment | undefined {
const comments = this._comments.filter(comment => comment.commentId === commentId);
const comments = this._comments.filter(comment => (comment.commentId === commentId || comment.id === commentId));
if (comments && comments.length) {
return comments[0];
@@ -707,6 +714,9 @@ export class ExtHostCommentInputBox implements vscode.CommentInputBox {
this._value = input;
}
}
type ReactionHandler = (comment: vscode.Comment, reaction: vscode.CommentReaction) => Promise<void>;
class ExtHostCommentController implements vscode.CommentController {
get id(): string {
return this._id;
@@ -740,6 +750,18 @@ class ExtHostCommentController implements vscode.CommentController {
}
}
private _reactionHandler?: ReactionHandler;
get reactionHandler(): ReactionHandler | undefined {
return this._reactionHandler;
}
set reactionHandler(handler: ReactionHandler | undefined) {
this._reactionHandler = handler;
this._proxy.$updateCommentControllerFeatures(this.handle, { reactionHandler: !!handler });
}
constructor(
_extension: IExtensionDescription,
private _handle: number,
@@ -861,9 +883,12 @@ function convertFromComment(comment: modes.Comment): vscode.Comment {
isDraft: comment.isDraft,
commentReactions: comment.commentReactions ? comment.commentReactions.map(reaction => {
return {
label: reaction.label,
count: reaction.count,
hasReacted: reaction.hasReacted
label: reaction.label || '',
count: reaction.count || 0,
iconPath: reaction.iconPath ? URI.revive(reaction.iconPath) : '',
hasReacted: reaction.hasReacted,
authorHasReacted: reaction.hasReacted || false
};
}) : undefined,
mode: comment.mode ? comment.mode : modes.CommentMode.Preview
@@ -878,6 +903,7 @@ function convertToModeComment2(thread: ExtHostCommentThread, commentController:
}
const iconPath = vscodeComment.author && vscodeComment.author.iconPath ? vscodeComment.author.iconPath.toString() : undefined;
const reactions = vscodeComment.reactions || vscodeComment.commentReactions;
return {
commentId: vscodeComment.id || vscodeComment.commentId,
@@ -892,7 +918,7 @@ function convertToModeComment2(thread: ExtHostCommentThread, commentController:
editCommand: vscodeComment.editCommand ? commandsConverter.toInternal(vscodeComment.editCommand) : undefined,
deleteCommand: vscodeComment.deleteCommand ? commandsConverter.toInternal(vscodeComment.deleteCommand) : undefined,
label: vscodeComment.label,
commentReactions: vscodeComment.commentReactions ? vscodeComment.commentReactions.map(reaction => convertToReaction2(commentController.reactionProvider, reaction)) : undefined
commentReactions: reactions ? reactions.map(reaction => convertToReaction2(commentController.reactionProvider, reaction)) : undefined
};
}
@@ -939,9 +965,11 @@ function convertToReaction2(provider: vscode.CommentReactionProvider | undefined
function convertFromReaction(reaction: modes.CommentReaction): vscode.CommentReaction {
return {
label: reaction.label,
count: reaction.count,
hasReacted: reaction.hasReacted
label: reaction.label || '',
count: reaction.count || 0,
iconPath: reaction.iconPath ? URI.revive(reaction.iconPath) : '',
hasReacted: reaction.hasReacted,
authorHasReacted: reaction.hasReacted || false
};
}