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

Function getThreads

apps/web/server/routers/ssr/channels.ts:99–152  ·  view source on GitHub ↗
({
  channelId,
  anonymizeUsers,
  anonymize,
  page,
}: {
  channelId: string;
  anonymizeUsers: boolean;
  anonymize: AnonymizeType;
  page?: string;
})

Source from the content-addressed store, hash-verified

97);
98
99async function getThreads({
100 channelId,
101 anonymizeUsers,
102 anonymize,
103 page,
104}: {
105 channelId: string;
106 anonymizeUsers: boolean;
107 anonymize: AnonymizeType;
108 page?: string;
109}) {
110 if (!!page) {
111 const threads = (
112 await findThreadsByCursor({
113 channelIds: [channelId],
114 page: parsePage(page),
115 anonymize,
116 anonymizeUsers,
117 })
118 ).sort(sortBySentAtAsc);
119
120 return {
121 nextCursor: {
122 next: null,
123 prev: null,
124 },
125 threads,
126 };
127 }
128
129 const { sort, direction, sentAt } = decodeCursor(undefined);
130
131 const threads = (
132 await findThreadsByCursor({
133 channelIds: [channelId],
134 sentAt,
135 sort,
136 direction,
137 anonymize,
138 anonymizeUsers,
139 })
140 ).sort(sortBySentAtAsc);
141
142 const nextCursor = await buildCursor({
143 sort,
144 direction,
145 sentAt,
146 pathCursor: page,
147 total: threads.length,
148 prevDate: threads[0].sentAt,
149 nextDate: threads[threads.length - 1].sentAt,
150 });
151 return { nextCursor, threads };
152}
153
154function parsePage(page: string): number | undefined {
155 try {

Callers 1

channels.tsFile · 0.70

Calls 4

findThreadsByCursorFunction · 0.90
decodeCursorFunction · 0.90
buildCursorFunction · 0.90
parsePageFunction · 0.70

Tested by

no test coverage detected