From a6dcc44c12abbac1d89346856604b0b1c6b76506 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Fri, 12 Dec 2025 10:29:33 -0500 Subject: [PATCH] Normalize comment cache keys --- js/services/commentThreadService.js | 6 ++++- tests/comment-thread-service.test.mjs | 35 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/js/services/commentThreadService.js b/js/services/commentThreadService.js index ecec9c85..7a915bc4 100644 --- a/js/services/commentThreadService.js +++ b/js/services/commentThreadService.js @@ -324,7 +324,11 @@ export default class CommentThreadService { getCommentCacheKey(videoEventId) { const normalized = normalizeString(videoEventId); - return normalized ? `${COMMENT_CACHE_PREFIX}${normalized}` : ""; + if (!normalized) { + return ""; + } + + return `${COMMENT_CACHE_PREFIX}${normalized.toLowerCase()}`; } getCachedComments(videoEventId) { diff --git a/tests/comment-thread-service.test.mjs b/tests/comment-thread-service.test.mjs index bf276403..63cf3022 100644 --- a/tests/comment-thread-service.test.mjs +++ b/tests/comment-thread-service.test.mjs @@ -88,6 +88,41 @@ test.after(() => { } }); +test("CommentThreadService caches mixed-case video ids consistently", () => { + const videoEventId = "VideoMixed123"; + const service = new CommentThreadService(); + + const comments = [ + { + id: "comment-1", + pubkey: "authorpk", + content: "Cached comment", + created_at: 1700000000, + tags: [], + }, + ]; + + service.cacheComments(videoEventId, comments); + + const cachedKeys = []; + for (let index = 0; index < localStorage.length; index += 1) { + cachedKeys.push(localStorage.key(index)); + } + + assert.deepEqual( + cachedKeys, + ["bitvid:comments:videomixed123"], + "cache key should normalize mixed-case ids", + ); + + const cached = service.getCachedComments(videoEventId.toLowerCase()); + assert.deepEqual( + cached, + comments, + "mixed-case ids should retrieve cached entries", + ); +}); + test( "listVideoComments accepts builder events without parent ids and filters replies", async () => {