Merge pull request #1116 from PR0M3TH3AN/codex/refactor-comment-handling-in-video-modal

Rebuild comment tree on append to correctly place replies
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-01-06 22:32:52 -05:00
commit 5dbeb6bce7
1 file changed
+54
+54
View File
@@ -433,6 +433,9 @@ export default class VideoModalCommentController {
}
const comments = this.createMapFromInput(payload.commentsById);
const childrenByParent = this.createChildrenMapFromInput(
payload.childrenByParent,
);
const profiles = this.createMapFromInput(payload.profiles, {
normalizeKey: this.utils.normalizeHexPubkey,
});
@@ -453,6 +456,57 @@ export default class VideoModalCommentController {
? payload.commentIds
: [];
if (
this.modalCommentState.parentCommentId &&
comments.has(this.modalCommentState.parentCommentId)
) {
const parentEvent = comments.get(this.modalCommentState.parentCommentId);
const eventKind = normalizeKind(parentEvent?.kind);
if (eventKind) {
this.modalCommentState.parentCommentKind = eventKind;
}
const eventPubkey = normalizeHexPubkey(parentEvent?.pubkey);
if (eventPubkey) {
this.modalCommentState.parentCommentPubkey = eventPubkey;
}
}
const parentByChild = new Map();
childrenByParent.forEach((ids, parentId) => {
ids.forEach((id) => {
if (!parentByChild.has(id)) {
parentByChild.set(id, parentId);
}
});
});
let requiresFullRender = false;
for (const commentId of commentIds) {
if (!comments.has(commentId)) {
requiresFullRender = true;
break;
}
if (!parentByChild.has(commentId)) {
requiresFullRender = true;
break;
}
const parentId = parentByChild.get(commentId);
if (parentId) {
requiresFullRender = true;
break;
}
}
if (requiresFullRender) {
const snapshot = this.buildModalCommentSnapshot({
...payload,
commentsById: comments,
childrenByParent,
});
this.videoModal.renderComments?.(snapshot);
return;
}
commentIds.forEach((commentId) => {
if (!comments.has(commentId)) {
return;