mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 16:02:26 +00:00
Merge pull request #1049 from PR0M3TH3AN/codex/normalize-videoeventid-for-comparison
Normalize comment thread video IDs
This commit is contained in:
2 files changed
+97
-2
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user