Skip to content

Commit f904201

Browse files
authored
Fix showing the reply author on new threads (#6860)
Fixes microsoft/vscode#246088
1 parent 9dac004 commit f904201

3 files changed

Lines changed: 31 additions & 17 deletions

File tree

src/github/utils.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ export function threadRange(startLine: number, endLine: number, endCharacter?: n
9696
return new vscode.Range(startLine, 0, endLine, endCharacter);
9797
}
9898

99+
export async function setReplyAuthor(thread: vscode.CommentThread | vscode.CommentThread2, currentUser: IAccount, context: vscode.ExtensionContext) {
100+
if (currentUser.avatarUrl) {
101+
const thread2 = thread as vscode.CommentThread2;
102+
thread2.canReply = { name: currentUser.name ?? currentUser.login, iconPath: vscode.Uri.parse(currentUser.avatarUrl) };
103+
const uri = await DataUri.avatarCirclesAsImageDataUris(context, [currentUser], 28, 28);
104+
thread2.canReply = { name: currentUser.name ?? currentUser.login, iconPath: uri[0] };
105+
} else {
106+
thread.canReply = true;
107+
}
108+
}
109+
99110
export function createVSCodeCommentThreadForReviewThread(
100111
context: vscode.ExtensionContext,
101112
uri: vscode.Uri,
@@ -127,12 +138,7 @@ export function createVSCodeCommentThreadForReviewThread(
127138
updateCommentThreadLabel(vscodeThread as GHPRCommentThread);
128139
vscodeThread.collapsibleState = getCommentCollapsibleState(thread, undefined, currentUser.login);
129140

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-
}
141+
setReplyAuthor(vscodeThread, currentUser, context);
136142

137143
return vscodeThread as GHPRCommentThread;
138144
}

src/view/pullRequestCommentController.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { PullRequestOverviewPanel } from '../github/pullRequestOverview';
2121
import {
2222
CommentReactionHandler,
2323
createVSCodeCommentThreadForReviewThread,
24+
setReplyAuthor,
2425
threadRange,
2526
updateCommentReviewState,
2627
updateCommentThreadLabel,
@@ -337,14 +338,15 @@ export class PullRequestCommentController extends CommentControllerBase implemen
337338
const fileName = this._folderRepoManager.gitRelativeRootPath(thread.uri.path);
338339
const side = this.getCommentSide(thread);
339340
this._pendingCommentThreadAdds.push(thread);
340-
await this.pullRequestModel.createReviewThread(
341+
await Promise.all([this.pullRequestModel.createReviewThread(
341342
input,
342343
fileName,
343344
thread.range ? (thread.range.start.line + 1) : undefined,
344345
thread.range ? (thread.range.end.line + 1) : undefined,
345346
side,
346347
isSingleComment,
347-
);
348+
),
349+
setReplyAuthor(thread, await this._folderRepoManager.getCurrentUser(this.pullRequestModel.githubRepository), this._context)]);
348350
}
349351

350352
if (isSingleComment) {

src/view/reviewCommentController.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
createVSCodeCommentThreadForReviewThread,
2929
getRepositoryForFile,
3030
isFileInRepo,
31+
setReplyAuthor,
3132
threadRange,
3233
updateCommentReviewState,
3334
updateCommentThreadLabel,
@@ -682,7 +683,9 @@ export class ReviewCommentController extends CommentControllerBase implements Co
682683
endLine++;
683684
}
684685

685-
await this._folderRepoManager.activePullRequest!.createReviewThread(input, fileName, startLine, endLine, side);
686+
await Promise.all([this._folderRepoManager.activePullRequest!.createReviewThread(input, fileName, startLine, endLine, side),
687+
setReplyAuthor(thread, await this._folderRepoManager.getCurrentUser(this._folderRepoManager.activePullRequest!.githubRepository), this._context)
688+
]);
686689
} else {
687690
const comment = thread.comments[0];
688691
if (comment instanceof GHPRComment) {
@@ -787,14 +790,17 @@ export class ReviewCommentController extends CommentControllerBase implements Co
787790
startLine++;
788791
endLine++;
789792
}
790-
await this._folderRepoManager.activePullRequest.createReviewThread(
791-
input,
792-
fileName,
793-
startLine,
794-
endLine,
795-
side,
796-
isSingleComment,
797-
);
793+
await Promise.all([
794+
this._folderRepoManager.activePullRequest.createReviewThread(
795+
input,
796+
fileName,
797+
startLine,
798+
endLine,
799+
side,
800+
isSingleComment,
801+
),
802+
setReplyAuthor(thread, await this._folderRepoManager.getCurrentUser(this._folderRepoManager.activePullRequest.githubRepository), this._context)
803+
]);
798804
} else {
799805
const comment = thread.comments[0];
800806
if (comment instanceof GHPRComment) {

0 commit comments

Comments
 (0)