Skip to content

Commit

Permalink
Start Slack sync workflow only for selected channels. (#2414)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasryaric authored Nov 7, 2023
1 parent 8c5a5b6 commit 00aea4b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 18 additions & 0 deletions connectors/src/connectors/slack/temporal/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions connectors/src/connectors/slack/temporal/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {

const {
getChannel,
getChannels,
getChannelsToSync,
syncThread,
syncNonThreaded,
syncChannel,
Expand Down Expand Up @@ -50,7 +50,7 @@ export async function workspaceFullSync(
fromTs: number | null
): Promise<void> {
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) {
Expand Down

0 comments on commit 00aea4b

Please sign in to comment.