MCPcopy Create free account
hub / github.com/CatMuse/HiNote / addComment

Method addComment

src/services/comment/CommentService.ts:84–123  ·  view source on GitHub ↗

* 添加评论

(highlight: HighlightInfo, content: string)

Source from the content-addressed store, hash-verified

82 * 添加评论
83 */
84 async addComment(highlight: HighlightInfo, content: string): Promise<void> {
85 const file = await this.getFileForHighlight(highlight);
86 if (!file) {
87 new Notice(t("No corresponding file found."));
88 return;
89 }
90
91 // 确保高亮有 ID
92 if (!highlight.id) {
93 highlight.id = IdGenerator.generateHighlightId(
94 file.path,
95 highlight.position || 0,
96 highlight.text
97 );
98 }
99
100 if (!highlight.comments) {
101 highlight.comments = [];
102 }
103
104 const newComment: CommentItem = {
105 id: IdGenerator.generateCommentId(),
106 content,
107 createdAt: Date.now(),
108 updatedAt: Date.now()
109 };
110
111 highlight.comments.push(newComment);
112 highlight.updatedAt = Date.now();
113
114 await this.highlightManager.addHighlight(file, highlight);
115
116 // 只更新单个卡片,而不是刷新整个视图
117 if (this.onCardUpdate) {
118 this.onCardUpdate(highlight);
119 } else if (this.onRefreshView) {
120 // 降级方案:如果没有 onCardUpdate,则刷新整个视图
121 await this.onRefreshView();
122 }
123 }
124
125 /**
126 * 更新评论

Callers 2

configureMethod · 0.80
addAICommentMethod · 0.80

Calls 5

getFileForHighlightMethod · 0.95
tFunction · 0.90
generateHighlightIdMethod · 0.80
generateCommentIdMethod · 0.80
addHighlightMethod · 0.80

Tested by

no test coverage detected