-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow channels to be marked as personal
- Loading branch information
1 parent
e1245a0
commit d79b1ff
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const getChannelManagers = require("../utils/channelManagers"); | ||
|
||
/** | ||
* @param {{app: import('@slack/bolt').App}} param1 | ||
*/ | ||
module.exports = async function ({ app, prisma }) { | ||
app.command("/setpersonal", async ({ command, body, ack, respond }) => { | ||
await ack(); | ||
const channelId = body.channel_id; | ||
const channel = await app.client.conversations.info({ | ||
channel: body.channel_id, | ||
}); | ||
const user = await app.client.users.info({ | ||
user: command.user_id, | ||
}); | ||
const channelManagers = await getChannelManagers(body.channel_id); | ||
if (!channelManagers.includes(command.user_id) && !user.user.is_admin) | ||
return await respond( | ||
"Only channel managers and workspace admins can mark a channel as personal", | ||
); | ||
const channelRecord = await prisma.channel.findFirst({ | ||
where: { | ||
id: channelId, | ||
}, | ||
}); | ||
if (!channelRecord) | ||
await prisma.channel.create({ | ||
data: { | ||
id: channelId, | ||
personal: true, | ||
}, | ||
}); | ||
else if (channelRecord.locked && !user.user.is_admin) | ||
return await respond( | ||
"This channel cannot be modified as it is locked in the database. Usually, this is because it is a public, community-owned channel, i.e. #lounge, #code, etc.", | ||
); | ||
else if (channelRecord.personal) { | ||
await prisma.channel.update({ | ||
where: { | ||
id: channelId, | ||
}, | ||
data: { | ||
personal: false, | ||
}, | ||
}); | ||
return await respond( | ||
"Your channel has been marked as personal. Run the command again to unmark it.", | ||
); | ||
} | ||
|
||
else | ||
await prisma.channel.update({ | ||
where: { | ||
id: channelId, | ||
}, | ||
data: { | ||
personal: true | ||
}, | ||
}); | ||
await app.client.chat.postEphemeral({ | ||
channel: channel.channel.id, | ||
user: command.user_id, | ||
text: "This channel has been marked as regular. Run this command again to mark it as personal.", | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters