Skip to content

Commit 5e7587f

Browse files
authored
Adopt author infor for comment thread canReply (#6775)
Part of microsoft/vscode#246088
1 parent 24f2b7e commit 5e7587f

7 files changed

+41
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"codeActionRanges",
1717
"commentingRangeHint",
1818
"commentReactor",
19+
"commentReplyAuthor",
1920
"commentReveal",
2021
"commentThreadApplicability",
2122
"contribAccessibilityHelpContent",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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/246088
9+
10+
export interface CommentThread2 {
11+
canReply: boolean | CommentAuthorInformation;
12+
13+
readonly uri: Uri;
14+
range: Range | undefined;
15+
comments: readonly Comment[];
16+
collapsibleState: CommentThreadCollapsibleState;
17+
contextValue?: string;
18+
label?: string;
19+
state?: CommentThreadState | { resolved?: CommentThreadState; applicability?: CommentThreadApplicability };
20+
dispose(): void;
21+
}
22+
}

src/@types/vscode.proposed.commentThreadApplicability.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ declare module 'vscode' {
3232
range: Range | undefined;
3333
comments: readonly Comment[];
3434
collapsibleState: CommentThreadCollapsibleState;
35-
canReply: boolean;
35+
canReply: boolean | CommentAuthorInformation;
3636
contextValue?: string;
3737
label?: string;
3838
dispose(): void;

src/github/prComment.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export interface GHPRCommentThread extends vscode.CommentThread2 {
4545
*/
4646
label?: string;
4747

48+
canReply: boolean | vscode.CommentAuthorInformation;
49+
4850
/**
4951
* Whether the thread has been marked as resolved.
5052
*/

src/github/utils.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Remote } from '../common/remote';
1818
import { Resource } from '../common/resources';
1919
import { GITHUB_ENTERPRISE, OVERRIDE_DEFAULT_BRANCH, PR_SETTINGS_NAMESPACE, URI } from '../common/settingKeys';
2020
import * as Common from '../common/timelineEvent';
21+
import { DataUri } from '../common/uri';
2122
import { gitHubLabelColor, uniqBy } from '../common/utils';
2223
import { OctokitCommon } from './common';
2324
import { FolderRepositoryManager, PullRequestDefaults } from './folderRepositoryManager';
@@ -101,7 +102,7 @@ export function createVSCodeCommentThreadForReviewThread(
101102
range: vscode.Range | undefined,
102103
thread: IReviewThread,
103104
commentController: vscode.CommentController,
104-
currentUser: string,
105+
currentUser: IAccount,
105106
githubRepositories?: GitHubRepository[]
106107
): GHPRCommentThread {
107108
const vscodeThread = commentController.createCommentThread(uri, range, []);
@@ -124,7 +125,14 @@ export function createVSCodeCommentThreadForReviewThread(
124125
vscodeThread.state = { resolved, applicability };
125126

126127
updateCommentThreadLabel(vscodeThread as GHPRCommentThread);
127-
vscodeThread.collapsibleState = getCommentCollapsibleState(thread, undefined, currentUser);
128+
vscodeThread.collapsibleState = getCommentCollapsibleState(thread, undefined, currentUser.login);
129+
130+
if (currentUser.avatarUrl) {
131+
vscodeThread.canReply = { name: currentUser.name ?? currentUser.login, iconPath: vscode.Uri.parse(currentUser.avatarUrl) };
132+
DataUri.avatarCirclesAsImageDataUris(context, [currentUser], 28, 28).then(uri => {
133+
vscodeThread.canReply = { name: currentUser.name ?? currentUser.login, iconPath: uri[0] };
134+
});
135+
}
128136

129137
return vscodeThread as GHPRCommentThread;
130138
}

src/view/pullRequestCommentController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export class PullRequestCommentController extends CommentControllerBase implemen
166166
range,
167167
thread,
168168
this._commentController,
169-
currentUser.login,
169+
currentUser,
170170
this._githubRepositories
171171
);
172172
});
@@ -260,7 +260,7 @@ export class PullRequestCommentController extends CommentControllerBase implemen
260260
range,
261261
thread,
262262
this._commentController,
263-
(await this._folderRepoManager.getCurrentUser()).login,
263+
(await this._folderRepoManager.getCurrentUser()),
264264
this._githubRepositories
265265
);
266266
}

src/view/reviewCommentController.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class ReviewCommentController extends CommentControllerBase implements Co
113113
);
114114

115115
const range = thread.subjectType === SubjectType.FILE ? undefined : threadRange(thread.originalStartLine - 1, thread.originalEndLine - 1);
116-
return createVSCodeCommentThreadForReviewThread(this._context, reviewUri, range, thread, this._commentController, (await this._folderRepoManager.getCurrentUser()).login, this.githubReposForPullRequest(this._folderRepoManager.activePullRequest));
116+
return createVSCodeCommentThreadForReviewThread(this._context, reviewUri, range, thread, this._commentController, (await this._folderRepoManager.getCurrentUser()), this.githubReposForPullRequest(this._folderRepoManager.activePullRequest));
117117
}
118118

119119
/**
@@ -146,7 +146,7 @@ export class ReviewCommentController extends CommentControllerBase implements Co
146146
}
147147
range = threadRange(adjustedStartLine, adjustedEndLine);
148148
}
149-
return createVSCodeCommentThreadForReviewThread(this._context, uri, range, thread, this._commentController, (await this._folderRepoManager.getCurrentUser()).login, this.githubReposForPullRequest(this._folderRepoManager.activePullRequest));
149+
return createVSCodeCommentThreadForReviewThread(this._context, uri, range, thread, this._commentController, (await this._folderRepoManager.getCurrentUser()), this.githubReposForPullRequest(this._folderRepoManager.activePullRequest));
150150
}
151151

152152
/**
@@ -172,7 +172,7 @@ export class ReviewCommentController extends CommentControllerBase implements Co
172172
);
173173

174174
const range = thread.subjectType === SubjectType.FILE ? undefined : threadRange(thread.startLine - 1, thread.endLine - 1);
175-
return createVSCodeCommentThreadForReviewThread(this._context, reviewUri, range, thread, this._commentController, (await this._folderRepoManager.getCurrentUser()).login, this.githubReposForPullRequest(this._folderRepoManager.activePullRequest));
175+
return createVSCodeCommentThreadForReviewThread(this._context, reviewUri, range, thread, this._commentController, (await this._folderRepoManager.getCurrentUser()), this.githubReposForPullRequest(this._folderRepoManager.activePullRequest));
176176
}
177177

178178
private async doInitializeCommentThreads(reviewThreads: IReviewThread[]): Promise<void> {

0 commit comments

Comments
 (0)