({
serverId,
token,
onboardingTimestamp,
logger,
}: {
serverId: string;
token: string;
onboardingTimestamp: Date;
logger: Logger;
})
| 15 | import ChannelsService from 'services/channels'; |
| 16 | |
| 17 | export 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 | |
| 69 | export async function getArchivedThreads({ |
| 70 | channel, |
no test coverage detected