({
account,
decodeBotToken,
fullSync,
logger,
}: {
account: accounts & {
discordAuthorizations: discordAuthorizations[];
};
decodeBotToken: (accessToken: string) => string;
logger: Logger;
fullSync?: boolean;
})
| 10 | import { Logger } from '@linen/types'; |
| 11 | |
| 12 | async function syncJob({ |
| 13 | account, |
| 14 | decodeBotToken, |
| 15 | fullSync, |
| 16 | logger, |
| 17 | }: { |
| 18 | account: accounts & { |
| 19 | discordAuthorizations: discordAuthorizations[]; |
| 20 | }; |
| 21 | decodeBotToken: (accessToken: string) => string; |
| 22 | logger: Logger; |
| 23 | fullSync?: boolean; |
| 24 | }) { |
| 25 | logger.log({ sync: 'stared' }); |
| 26 | |
| 27 | if (!account.discordServerId) { |
| 28 | throw new Error('discord server id not found'); |
| 29 | } |
| 30 | if (!account.discordAuthorizations || !account.discordAuthorizations.length) { |
| 31 | throw new Error('discord authorization not found'); |
| 32 | } |
| 33 | |
| 34 | const discordAuthorizations = account.discordAuthorizations.find(Boolean); |
| 35 | const onboardingTimestamp = discordAuthorizations?.syncFrom || new Date(0); |
| 36 | |
| 37 | logger.log({ onboardingTimestamp }); |
| 38 | |
| 39 | const token = discordAuthorizations?.customBot |
| 40 | ? decodeBotToken(discordAuthorizations.accessToken) |
| 41 | : botV1().PRIVATE_TOKEN; |
| 42 | |
| 43 | await crawlUsers({ |
| 44 | accountId: account.id, |
| 45 | serverId: account.discordServerId, |
| 46 | token, |
| 47 | logger, |
| 48 | }); |
| 49 | |
| 50 | const hideChannels = account.newChannelsConfig === 'HIDDEN'; |
| 51 | |
| 52 | const channels = await listChannelsAndPersist({ |
| 53 | serverId: account.discordServerId, |
| 54 | accountId: account.id, |
| 55 | token, |
| 56 | logger, |
| 57 | hideChannels, |
| 58 | }); |
| 59 | |
| 60 | if (fullSync) { |
| 61 | await ChannelsService.setCursorNull({ accountId: account.id }); |
| 62 | } |
| 63 | |
| 64 | // active threads are global (not channel specific) |
| 65 | await getActiveThreads({ |
| 66 | serverId: account.discordServerId, |
| 67 | token, |
| 68 | onboardingTimestamp, |
| 69 | logger, |
no test coverage detected