From 70e71e444f0be8a5265e629ef927d2a33eee13e9 Mon Sep 17 00:00:00 2001 From: Michele Lizzit Date: Tue, 5 Dec 2023 00:47:23 +0100 Subject: [PATCH] Fix comment deletions --- src/comments.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/comments.ts b/src/comments.ts index cec8b83..38d7cec 100644 --- a/src/comments.ts +++ b/src/comments.ts @@ -253,7 +253,7 @@ export class IaCComments { thread.comments = thread.comments.filter(cmt => (cmt as NoteComment).id !== commentId); // Update global thread list - await this.updateThreadInLocalDb(thread); + await this.updateThreadInLocalDb(thread, false, true); if (thread.comments.length === 0) { // Delete from global thread list @@ -315,7 +315,7 @@ export class IaCComments { }); } - async updateThreadInLocalDb(thread: vscode.CommentThread, deleteEmptyThreads: boolean = true) { + async updateThreadInLocalDb(thread: vscode.CommentThread, deleteEmptyThreads: boolean = true, processDeletions: boolean = false) { // Add thread to global list console.log("[IaC Comments] Updating thread in local db"); if (!this.threadIdMap.has(thread)) { @@ -357,10 +357,14 @@ export class IaCComments { console.log("[IaC Comments] Inserting comment " + oComment.body + " by " + oComment.author.name + " into thread " + tid); } + if (!processDeletions) { + return; + } + // Get a list of all comment ids in the thread from the database let commentIds: string[] = await this.db.getCommentsForThread(tid); // Filter only comment ids that are not in the thread. - let newCommentIds = thread.comments.filter(comment => !commentIds.includes((comment as NoteComment).id)).map(comment => (comment as NoteComment).id); + let newCommentIds = commentIds.filter(cid => !thread.comments.map(comment => (comment as NoteComment).id).includes(cid)); // Delete comments that are not in the thread if (newCommentIds.length > 0) {