diff --git a/src/app/(home)/(activities)/comments/page.tsx b/src/app/(home)/(activities)/comments/page.tsx new file mode 100644 index 00000000..0e6ef84f --- /dev/null +++ b/src/app/(home)/(activities)/comments/page.tsx @@ -0,0 +1,12 @@ +import { Metadata } from "next" + +import { HomeFeed } from "~/components/home/HomeFeed" +import { APP_NAME } from "~/lib/env" + +export const metadata: Metadata = { + title: `Comments Activities - ${APP_NAME}`, +} + +export default async function FollowingActivities() { + return +} diff --git a/src/components/home/HomeActivitiesTabs.tsx b/src/components/home/HomeActivitiesTabs.tsx index 329cba12..4b7fce3c 100644 --- a/src/components/home/HomeActivitiesTabs.tsx +++ b/src/components/home/HomeActivitiesTabs.tsx @@ -41,6 +41,11 @@ export const HomeActivitiesTabs = () => { }, active: pathname === "/following", }, + { + text: "Comments", + href: "/comments", + active: pathname === "/comments", + }, ...topics.map((topic) => ({ text: t(topic.name), href: `/topic/${encodeURIComponent(topic.name)}`, diff --git a/src/models/home.model.ts b/src/models/home.model.ts index b672aaa0..f51842c2 100644 --- a/src/models/home.model.ts +++ b/src/models/home.model.ts @@ -15,6 +15,7 @@ export type FeedType = | "hottest" | "search" | "tag" + | "comments" export type SearchType = "latest" | "hottest" export async function getFeed({ @@ -92,6 +93,87 @@ export async function getFeed({ },` : "" } + ) { + characterId + noteId + character { + handle + characterId + metadata { + content + } + } + createdAt + metadata { + uri + content + } + } + }`, + { + filter: filter.latest, + }, + ) + .toPromise() + + const list = await Promise.all( + result?.data?.notes.map(async (page: any) => { + const expand = await expandCrossbellNote({ + note: page, + useScore: true, + useHTML, + }) + delete expand.metadata?.content.content + return expand + }), + ) + + return { + list, + cursor: list?.length + ? `${list[list.length - 1]?.characterId}_${list[list.length - 1] + ?.noteId}` + : undefined, + count: list?.length || 0, + } + } + case "comments": { + const result = await client + .query( + ` + query getNotes($filter: [Int!]) { + notes( + where: { + characterId: { + notIn: $filter + } + metadata: { + AND: [{ + content: { + path: "sources", + array_contains: "xlog" + } + }, { + content: { + path: "tags", + array_starts_with: "comment" + } + }] + }, + }, + orderBy: [{ createdAt: desc }], + take: ${limit}, + ${ + cursor + ? ` + cursor: { + note_characterId_noteId_unique: { + characterId: ${cursor.split("_")[0]}, + noteId: ${cursor.split("_")[1]} + }, + },` + : "" + } ) { characterId noteId @@ -133,19 +215,14 @@ export async function getFeed({ const list = await Promise.all( result?.data?.notes .filter((page: any) => { - return !( - page.metadata?.content?.tags?.includes("comment") && - page.toNote?.metadata?.content?.tags?.includes("comment") - ) + return !page.toNote?.metadata?.content?.tags?.includes("comment") }) .map(async (page: any) => { - const isComment = page.metadata?.content?.tags?.includes("comment") const expand = await expandCrossbellNote({ note: page, - useScore: !isComment, useHTML, }) - if (isComment && expand.toNote) { + if (expand.toNote) { expand.toNote = await expandCrossbellNote({ note: expand.toNote, useHTML, @@ -431,7 +508,7 @@ export async function getFeed({ metadata: { content: { path: "sources", array_contains: "xlog" }, AND: { content: { path: "tags", array_contains: "post" } } } }, orderBy: { stat: { viewDetailCount: desc } }, - take: 25, + take: 40, ) { stat { viewDetailCount @@ -476,13 +553,15 @@ export async function getFeed({ ) if (daysInterval) { - list = list.sort((a, b) => { - if (a.stat?.hotScore && b.stat?.hotScore) { - return b.stat.hotScore - a.stat.hotScore - } else { - return 0 - } - }) + list = list + .sort((a, b) => { + if (a.stat?.hotScore && b.stat?.hotScore) { + return b.stat.hotScore - a.stat.hotScore + } else { + return 0 + } + }) + .slice(0, 24) } return {