提交 28c6612e 编写于 作者: T Tomas Vik

refactor: replace ad-hoc structure with GitLabComment class

The GitLabComment is going to be responsible for all comment-related
functionality like editing, deleting and reacting.
上级 fe16d729
......@@ -11,6 +11,7 @@ import {
} from '../../gitlab/gitlab_new_service';
import { handleError } from '../../log';
import { UserFriendlyError } from '../../errors/user_friendly_error';
import { GitLabComment } from '../../review/gitlab_comment';
const isTextDiffDiscussion = (discussion: GqlDiscussion): discussion is GqlTextDiffDiscussion => {
const firstNote = discussion.notes.nodes[0];
......@@ -90,14 +91,7 @@ export class MrItemModel extends ItemModel {
});
const discussionsOnDiff = discussions.filter(isTextDiffDiscussion);
const threads = discussionsOnDiff.map(({ notes }) => {
const comments = notes.nodes.map(({ body, author }) => ({
body,
mode: vscode.CommentMode.Preview,
author: {
name: author.name,
iconPath: author.avatarUrl !== null ? vscode.Uri.parse(author.avatarUrl) : undefined,
},
}));
const comments = notes.nodes.map(GitLabComment.fromGqlNote);
const { position } = notes.nodes[0];
const thread = commentController.createCommentThread(
this.uriFromPosition(position),
......
......@@ -100,6 +100,7 @@ interface GqlGenericDiscussion<T extends GqlBasePosition | null> {
notes: Node<GqlGenericNote<T>>;
}
export type GqlTextDiffNote = GqlGenericNote<GqlTextPosition>;
export type GqlTextDiffDiscussion = GqlGenericDiscussion<GqlTextPosition>;
export type GqlDiscussion =
......
import * as vscode from 'vscode';
import { GqlTextDiffNote } from '../gitlab/gitlab_new_service';
export class GitLabComment implements vscode.Comment {
protected constructor(readonly gqlNote: GqlTextDiffNote, public mode: vscode.CommentMode) {}
get author(): vscode.CommentAuthorInformation {
const { name, avatarUrl } = this.gqlNote.author;
return {
name,
iconPath: avatarUrl !== null ? vscode.Uri.parse(avatarUrl) : undefined,
};
}
get body(): string {
return this.gqlNote.body;
}
static fromGqlNote(gqlNote: GqlTextDiffNote): GitLabComment {
return new GitLabComment(gqlNote, vscode.CommentMode.Preview);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册