forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprComment.ts
More file actions
95 lines (82 loc) · 3.01 KB
/
Copy pathprComment.ts
File metadata and controls
95 lines (82 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { IComment } from '../common/comment';
export interface GHPRCommentThread {
threadId: string;
/**
* The uri of the document the thread has been created on.
*/
resource: vscode.Uri;
/**
* The range the comment thread is located within the document. The thread icon will be shown
* at the first line of the range.
*/
range: vscode.Range;
/**
* The ordered comments of the thread.
*/
comments: (GHPRComment | TemporaryComment)[];
/**
* Whether the thread should be collapsed or expanded when opening the document.
* Defaults to Collapsed.
*/
collapsibleState: vscode.CommentThreadCollapsibleState;
/**
* The optional human-readable label describing the [Comment Thread](#CommentThread)
*/
label?: string;
dispose: () => void;
}
export class TemporaryComment implements vscode.Comment {
public body: string | vscode.MarkdownString;
public mode: vscode.CommentMode;
public author: vscode.CommentAuthorInformation;
public label: string | undefined;
public contextValue: string;
public id: number;
public parent: GHPRCommentThread;
public originalBody?: string;
static idPool = 0;
constructor(parent: GHPRCommentThread, input: string, isDraft: boolean, currentUser: any, originalBody?: string) {
this.parent = parent;
this.body = new vscode.MarkdownString(input);
this.mode = vscode.CommentMode.Preview;
this.author = {
name: currentUser.login,
iconPath: vscode.Uri.parse(`${currentUser.avatar_url}&s=${64}`)
};
this.label = isDraft ? 'Pending' : undefined;
this.contextValue = 'canEdit';
this.originalBody = originalBody;
this.id = TemporaryComment.idPool++;
}
}
export class GHPRComment implements vscode.Comment {
body: string | vscode.MarkdownString;
mode: vscode.CommentMode;
author: vscode.CommentAuthorInformation;
label?: string | undefined;
commentReactions?: vscode.CommentReaction[] | undefined;
commentId: string;
_rawComment: IComment;
parent: GHPRCommentThread;
contextValue: string;
constructor(comment: IComment, parent: GHPRCommentThread) {
this._rawComment = comment;
this.commentId = comment.id.toString();
this.body = new vscode.MarkdownString(comment.body);
this.author = {
name: comment.user!.login,
iconPath: comment.user && comment.user.avatarUrl ? vscode.Uri.parse(comment.user.avatarUrl) : undefined
};
this.commentReactions = comment.reactions ? comment.reactions.map(reaction => {
return { label: reaction.label, hasReacted: reaction.viewerHasReacted, count: reaction.count, iconPath: reaction.icon };
}) : [];
this.label = comment.isDraft ? 'Pending' : undefined;
this.contextValue = comment.canEdit ? 'canEdit' : '';
this.parent = parent;
}
}