diff --git a/packages/next-common/components/comment/item.js b/packages/next-common/components/comment/item.js
index 2f57e3c9e9..c6ac0a5149 100644
--- a/packages/next-common/components/comment/item.js
+++ b/packages/next-common/components/comment/item.js
@@ -18,6 +18,7 @@ import Tooltip from "../tooltip";
import CommentItemTemplate from "./itemTemplate";
import { useIsUniversalPostComments } from "next-common/hooks/usePostComments";
import { CommentProvider, useComment } from "./context";
+import PolkassemblyCommentItem from "./polkassemblyCommentItem";
function jumpToAnchor(anchorId) {
var anchorElement = document.getElementById(anchorId);
@@ -174,18 +175,22 @@ function CommentItemImpl({
setIsEdit={setIsEdit}
/>
}
- renderReplyItem={(reply) => (
-
- )}
+ renderReplyItem={(reply) =>
+ reply.comment_source === "polkassembly" ? (
+
+ ) : (
+
+ )
+ }
/>
);
}
diff --git a/packages/next-common/hooks/usePostComments.js b/packages/next-common/hooks/usePostComments.js
index 4db69093bb..d48cc2090f 100644
--- a/packages/next-common/hooks/usePostComments.js
+++ b/packages/next-common/hooks/usePostComments.js
@@ -7,11 +7,38 @@ import dayjs from "dayjs";
import { useDetailType } from "next-common/context/page";
import { detailPageCategory } from "next-common/utils/consts/business/category";
import { PolkassemblyChains } from "next-common/utils/polkassembly";
+import { cloneDeep } from "lodash-es";
function getShouldReadPolkassemblyComments(chain) {
return PolkassemblyChains.includes(chain);
}
+function mergeComments(polkassemblyComments, subsquareComments) {
+ const filteredPolkassemblyComments = [];
+ const newSubsquareComments = cloneDeep(subsquareComments);
+ for (const polkaItem of polkassemblyComments ?? []) {
+ const subsquareItem = newSubsquareComments.find(
+ (item) => item._id === polkaItem.id,
+ );
+ if (subsquareItem) {
+ subsquareItem.replies = subsquareItem.replies || [];
+ subsquareItem.replies.push(
+ ...polkaItem.replies.map((r) => ({
+ ...r,
+ comment_source: "polkassembly",
+ })),
+ );
+ } else {
+ filteredPolkassemblyComments.push(polkaItem);
+ }
+ }
+
+ return [
+ ...(filteredPolkassemblyComments ?? []),
+ ...(newSubsquareComments ?? []),
+ ].sort((a, b) => dayjs(a.createdAt).unix() - dayjs(b.createdAt).unix());
+}
+
export function usePostCommentsData() {
const comments = useComments();
const chain = useChain();
@@ -27,10 +54,10 @@ export function usePostCommentsData() {
if (!polkassemblyPostData.loadingComments) {
const data = { ...comments };
- data.items = [
- ...(polkassemblyPostData.comments ?? []),
- ...(comments.items ?? []),
- ].sort((a, b) => dayjs(a.createdAt).unix() - dayjs(b.createdAt).unix());
+ data.items = mergeComments(
+ polkassemblyPostData.comments,
+ comments.items,
+ );
setCommentsData(data);
}