From 6caa31ae5122ced8f6afc0a230cfe886a0c90da0 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Fri, 12 Dec 2025 12:03:39 -0500 Subject: [PATCH] Normalize comment thread video IDs --- js/ui/videoModalCommentController.js | 18 ++++++- tests/video-modal-comments.test.mjs | 81 ++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/js/ui/videoModalCommentController.js b/js/ui/videoModalCommentController.js index fb999dbb..d2b33c50 100644 --- a/js/ui/videoModalCommentController.js +++ b/js/ui/videoModalCommentController.js @@ -8,6 +8,10 @@ function normalizeString(value) { return typeof value === "string" ? value.trim() : ""; } +function normalizeVideoEventId(value) { + return typeof value === "string" ? value.trim().toLowerCase() : ""; +} + function normalizeRelay(value) { if (typeof value === "string") { return value.trim(); @@ -352,7 +356,12 @@ export default class VideoModalCommentController { return; } - if (snapshot.videoEventId !== this.modalCommentState.videoEventId) { + const snapshotVideoEventId = normalizeVideoEventId(snapshot.videoEventId); + const modalVideoEventId = normalizeVideoEventId( + this.modalCommentState.videoEventId, + ); + + if (!snapshotVideoEventId || snapshotVideoEventId !== modalVideoEventId) { return; } @@ -404,7 +413,12 @@ export default class VideoModalCommentController { return; } - if (payload.videoEventId !== this.modalCommentState.videoEventId) { + const payloadVideoEventId = normalizeVideoEventId(payload.videoEventId); + const modalVideoEventId = normalizeVideoEventId( + this.modalCommentState.videoEventId, + ); + + if (!payloadVideoEventId || payloadVideoEventId !== modalVideoEventId) { return; } diff --git a/tests/video-modal-comments.test.mjs b/tests/video-modal-comments.test.mjs index 883a8058..235c39c3 100644 --- a/tests/video-modal-comments.test.mjs +++ b/tests/video-modal-comments.test.mjs @@ -177,6 +177,87 @@ test( }, ); +test( + "VideoModalCommentController accepts mixed-case videoEventIds for snapshots", + async () => { + const renderedSnapshots = []; + const appended = []; + + const controller = new VideoModalCommentController({ + commentThreadService: { + setCallbacks: () => {}, + teardown: () => {}, + loadThread: () => Promise.resolve(), + processIncomingEvent: () => {}, + }, + videoModal: { + setCommentSectionCallbacks: () => {}, + hideCommentsDisabledMessage: () => {}, + showCommentsDisabledMessage: () => {}, + setCommentsVisibility: () => {}, + clearComments: () => {}, + resetCommentComposer: () => {}, + setCommentStatus: () => {}, + setCommentComposerState: () => {}, + renderComments: (snapshot) => renderedSnapshots.push(snapshot), + appendComment: (comment) => appended.push(comment), + }, + auth: { + isLoggedIn: () => true, + }, + utils: { + normalizeHexPubkey: (value) => value, + }, + }); + + controller.modalCommentState.videoEventId = "VideoCaseMixed"; + + const snapshot = { + videoEventId: "videocasemixed", + parentCommentId: null, + commentsById: new Map([ + [ + "comment-1", + { + id: "comment-1", + pubkey: "pk1", + kind: COMMENT_EVENT_KIND, + content: "First!", + tags: [], + }, + ], + ]), + childrenByParent: new Map([[null, ["comment-1"]]]), + profiles: new Map(), + }; + + controller.handleCommentThreadReady(snapshot); + + const payload = { + videoEventId: " VIDEOCASEMIXED ", + commentsById: new Map([ + [ + "comment-2", + { + id: "comment-2", + pubkey: "pk2", + kind: COMMENT_EVENT_KIND, + content: "Second!", + tags: [], + }, + ], + ]), + commentIds: ["comment-2"], + profiles: new Map(), + }; + + controller.handleCommentThreadAppend(payload); + + assert.equal(renderedSnapshots.length, 1, "snapshot should render despite casing"); + assert.equal(appended.length, 1, "append should accept trimmed, mixed-case IDs"); + }, +); + test("VideoModal comment composer updates messaging and dispatches events", async (t) => { const { window, document, modal, cleanup } = await setupModal(); t.after(cleanup);