From 00aea4bd0081099aa26ad8f627115c9a5a6831d2 Mon Sep 17 00:00:00 2001 From: Aric Lasry Date: Tue, 7 Nov 2023 14:06:54 +0100 Subject: [PATCH] Start Slack sync workflow only for selected channels. (#2414) --- .../connectors/slack/temporal/activities.ts | 18 ++++++++++++++++++ .../src/connectors/slack/temporal/workflows.ts | 4 ++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/connectors/src/connectors/slack/temporal/activities.ts b/connectors/src/connectors/slack/temporal/activities.ts index 62a18071bc68..bdf04a14a9ab 100644 --- a/connectors/src/connectors/slack/temporal/activities.ts +++ b/connectors/src/connectors/slack/temporal/activities.ts @@ -98,6 +98,24 @@ export async function getChannels( return allChannels; } +export async function getChannelsToSync(connectorId: number) { + const [remoteChannels, localChannels] = await Promise.all([ + await getChannels(connectorId, true), + await SlackChannel.findAll({ + where: { + connectorId: connectorId, + permission: { + [Op.or]: ["read", "read_write"], + }, + }, + }), + ]); + const readAllowedChannels = new Set( + localChannels.map((c) => c.slackChannelId) + ); + return remoteChannels.filter((c) => c.id && readAllowedChannels.has(c.id)); +} + export async function getChannel( connectorId: ModelId, channelId: string diff --git a/connectors/src/connectors/slack/temporal/workflows.ts b/connectors/src/connectors/slack/temporal/workflows.ts index dc5fa794d44d..fcd1c9e3a170 100644 --- a/connectors/src/connectors/slack/temporal/workflows.ts +++ b/connectors/src/connectors/slack/temporal/workflows.ts @@ -18,7 +18,7 @@ import { const { getChannel, - getChannels, + getChannelsToSync, syncThread, syncNonThreaded, syncChannel, @@ -50,7 +50,7 @@ export async function workspaceFullSync( fromTs: number | null ): Promise { await fetchUsers(connectorId); - const channels = await getChannels(connectorId, true); + const channels = await getChannelsToSync(connectorId); let i = 0; for (const channel of channels) { if (!channel.id || !channel.name) {