From bbaa7f3030437c777f596186f5a956cef320d1f0 Mon Sep 17 00:00:00 2001 From: Austin Lee Date: Wed, 21 Feb 2024 10:46:43 +0800 Subject: [PATCH] chore: add reply user field (#2121) --- packages/server/src/controller/comment.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/server/src/controller/comment.js b/packages/server/src/controller/comment.js index abcba330669..5d7a25e6159 100644 --- a/packages/server/src/controller/comment.js +++ b/packages/server/src/controller/comment.js @@ -568,6 +568,21 @@ module.exports = class extends BaseRest { .reverse(), ); + const childCommentsMap = new Map(); + + childCommentsMap.set(cmt.objectId, cmt); + cmt.children.forEach((c) => childCommentsMap.set(c.objectId, c)); + + cmt.children.forEach((c) => { + const parent = childCommentsMap.get(c.pid); + + c.reply_user = { + nick: parent.nick, + link: parent.link, + avatar: parent.avatar, + }; + }); + return cmt; }), ),