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

Function getActiveThreads

apps/web/services/discord/threads.ts:17–67  ·  view source on GitHub ↗
({
  serverId,
  token,
  onboardingTimestamp,
  logger,
}: {
  serverId: string;
  token: string;
  onboardingTimestamp: Date;
  logger: Logger;
})

Source from the content-addressed store, hash-verified

15import ChannelsService from 'services/channels';
16
17export async function getActiveThreads({
18 serverId,
19 token,
20 onboardingTimestamp,
21 logger,
22}: {
23 serverId: string;
24 token: string;
25 onboardingTimestamp: Date;
26 logger: Logger;
27}) {
28 logger.log({ getActiveThreads: 'started' });
29
30 const [err, response] = await to(
31 DiscordApi.getActiveThreads({
32 serverId,
33 token,
34 })
35 );
36 if (err) {
37 logger.error({ getActiveThreads: err });
38 return;
39 }
40
41 logger.log({ 'threads found': response.threads.length });
42 for (const thread of response.threads) {
43 if (!thread.parent_id) {
44 logger.error({ 'thread without channel': thread });
45 continue;
46 }
47 if (
48 thread.thread_metadata?.create_timestamp &&
49 onboardingTimestamp > new Date(thread.thread_metadata.create_timestamp)
50 ) {
51 continue;
52 }
53 const channel = await ChannelsService.findByExternalId(thread.parent_id);
54 if (!channel) {
55 logger.error({ 'channel not found on linen db': thread });
56 continue;
57 }
58 await processThread({
59 thread,
60 onboardingTimestamp,
61 channel,
62 token,
63 logger,
64 });
65 }
66 logger.log({ getActiveThreads: 'finished' });
67}
68
69export async function getArchivedThreads({
70 channel,

Callers 1

syncJobFunction · 0.90

Calls 6

toFunction · 0.85
processThreadFunction · 0.85
getActiveThreadsMethod · 0.80
findByExternalIdMethod · 0.80
logMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected