MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / findTopics

Function findTopics

apps/web/services/threads/topics.ts:8–70  ·  view source on GitHub ↗
({
  channelId,
  accountId,
  sentAt = new Date(),
  direction = 'lt',
  anonymize,
}: {
  channelId: string;
  accountId: string;
  sentAt?: Date;
  direction?: 'lt' | 'gt';
  anonymize: AnonymizeType;
})

Source from the content-addressed store, hash-verified

6const limit = 30;
7
8export async function findTopics({
9 channelId,
10 accountId,
11 sentAt = new Date(),
12 direction = 'lt',
13 anonymize,
14}: {
15 channelId: string;
16 accountId: string;
17 sentAt?: Date;
18 direction?: 'lt' | 'gt';
19 anonymize: AnonymizeType;
20}): Promise<{
21 topics: SerializedTopic[];
22 threads: SerializedThread[];
23}> {
24 const messages = await prisma.messages.findMany({
25 take: limit,
26 select: {
27 id: true,
28 threadId: true,
29 sentAt: true,
30 usersId: true,
31 },
32 where: {
33 channel: { hidden: false, id: channelId, accountId },
34 threads: { hidden: false },
35 sentAt: { [direction]: sentAt },
36 },
37 orderBy: { sentAt: 'desc' },
38 });
39
40 const threads = await prisma.threads.findMany({
41 where: {
42 hidden: false,
43 id: { in: messages.map((m) => m.threadId!) },
44 },
45 include: {
46 messages: {
47 include: {
48 author: true,
49 mentions: {
50 include: {
51 users: true,
52 },
53 },
54 reactions: true,
55 attachments: true,
56 },
57 orderBy: { sentAt: 'asc' },
58 },
59 channel: true,
60 },
61 });
62
63 return {
64 topics: messages.map(serializeTopic),
65 threads: (anonymize !== AnonymizeType.NONE

Callers 2

topicGetServerSidePropsFunction · 0.90
findTopicsMethod · 0.90

Calls 2

anonymizeMessagesFunction · 0.90
mapMethod · 0.80

Tested by

no test coverage detected