From aee8bd44aefa2c8e3b265a82197e03771fbc200b Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Wed, 29 Oct 2025 22:38:49 -0400 Subject: [PATCH] Fix comment modal current video handling --- js/ui/videoModalCommentController.js | 3 +- tests/video-modal-comments.test.mjs | 56 ++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/js/ui/videoModalCommentController.js b/js/ui/videoModalCommentController.js index bc05c455..38d8662a 100644 --- a/js/ui/videoModalCommentController.js +++ b/js/ui/videoModalCommentController.js @@ -121,6 +121,7 @@ export default class VideoModalCommentController { return; } + this.dispose({ resetUi: false }); this.currentVideo = video; this.videoModal.setCommentSectionCallbacks?.({ @@ -132,8 +133,6 @@ export default class VideoModalCommentController { return; } - this.dispose({ resetUi: false }); - this.videoModal.hideCommentsDisabledMessage?.(); if (video.enableComments === false) { diff --git a/tests/video-modal-comments.test.mjs b/tests/video-modal-comments.test.mjs index e09659bd..58b22ff5 100644 --- a/tests/video-modal-comments.test.mjs +++ b/tests/video-modal-comments.test.mjs @@ -176,6 +176,62 @@ test("VideoModal comment composer updates messaging and dispatches events", asyn assert.strictEqual(submitDetail.triggerElement, modal.commentsSubmitButton); }); +test( + "VideoModalCommentController load preserves current video for submissions", + async () => { + const publishCalls = []; + + const controller = new VideoModalCommentController({ + commentThreadService: { + setCallbacks: () => {}, + teardown: () => {}, + defaultLimit: 10, + loadThread: () => Promise.resolve(), + processIncomingEvent: () => {}, + }, + videoModal: { + setCommentSectionCallbacks: () => {}, + hideCommentsDisabledMessage: () => {}, + showCommentsDisabledMessage: () => {}, + setCommentsVisibility: () => {}, + clearComments: () => {}, + resetCommentComposer: () => {}, + setCommentStatus: () => {}, + setCommentComposerState: () => {}, + }, + auth: { + isLoggedIn: () => true, + }, + services: { + publishComment: async (payload) => { + publishCalls.push(payload); + return { ok: true, event: { id: "comment", tags: [] } }; + }, + }, + utils: { + normalizeHexPubkey: (value) => value, + }, + }); + + const video = { + id: "video123", + pubkey: "AUTHORPK", + enableComments: true, + kind: 30078, + }; + + controller.load(video); + controller.submit({ text: "Nice" }); + + await controller.modalCommentPublishPromise; + + assert.equal(publishCalls.length, 1, "publishComment should be called once"); + const payload = publishCalls[0]; + assert.equal(payload.videoEventId, "video123"); + assert.equal(payload.videoAuthorPubkey, "AUTHORPK"); + }, +); + test( "VideoModalCommentController publishes comment using event id fallback", async () => {