mirror of
https://github.com/wassname/talk.git
synced 2026-07-12 01:57:58 +08:00
[CORL-846] Restructure the slack comment message format (#2794)
* Restructure the slack comment message format CORL-846 * feat: removed all comments Co-authored-by: Wyatt Johnson <accounts+github@wyattjoh.ca>
This commit is contained in:
@@ -151,93 +151,63 @@ const SlackChannel: FunctionComponent<Props> = ({
|
||||
<Label>Receive notifications in this Slack channel for</Label>
|
||||
</Localized>
|
||||
</div>
|
||||
<Field
|
||||
name={`${channel}.triggers.allComments`}
|
||||
subscription={{ value: true }}
|
||||
>
|
||||
{({ input: { value: allCommentsValue } }) => (
|
||||
<div className={styles.notificationToggles}>
|
||||
<Field
|
||||
name={`${channel}.triggers.allComments`}
|
||||
type="checkbox"
|
||||
parse={parseBool}
|
||||
|
||||
<div className={styles.notificationToggles}>
|
||||
<Field
|
||||
name={`${channel}.triggers.reportedComments`}
|
||||
type="checkbox"
|
||||
parse={parseBool}
|
||||
>
|
||||
{({ input }) => (
|
||||
<CheckBox
|
||||
id={`configure-slack-channel-triggers-reportedComments-${input.name}`}
|
||||
disabled={disabled || !channelEnabled}
|
||||
className={styles.trigger}
|
||||
{...input}
|
||||
>
|
||||
{({ input }) => (
|
||||
<CheckBox
|
||||
id={`configure-slack-channel-triggers-allComments-${input.name}`}
|
||||
disabled={disabled || !channelEnabled}
|
||||
className={styles.trigger}
|
||||
{...input}
|
||||
>
|
||||
<Localized id="configure-slack-channel-triggers-allComments">
|
||||
All Comments
|
||||
</Localized>
|
||||
</CheckBox>
|
||||
)}
|
||||
</Field>
|
||||
<Field
|
||||
name={`${channel}.triggers.reportedComments`}
|
||||
type="checkbox"
|
||||
parse={parseBool}
|
||||
<Localized id="configure-slack-channel-triggers-reportedComments">
|
||||
Reported Comments
|
||||
</Localized>
|
||||
</CheckBox>
|
||||
)}
|
||||
</Field>
|
||||
<Field
|
||||
name={`${channel}.triggers.pendingComments`}
|
||||
type="checkbox"
|
||||
parse={parseBool}
|
||||
>
|
||||
{({ input }) => (
|
||||
<CheckBox
|
||||
id={`configure-slack-channel-triggers-pendingComments-${input.name}`}
|
||||
disabled={disabled || !channelEnabled}
|
||||
className={styles.trigger}
|
||||
{...input}
|
||||
>
|
||||
{({ input }) => (
|
||||
<CheckBox
|
||||
id={`configure-slack-channel-triggers-reportedComments-${input.name}`}
|
||||
disabled={
|
||||
disabled || allCommentsValue || !channelEnabled
|
||||
}
|
||||
className={styles.trigger}
|
||||
{...input}
|
||||
>
|
||||
<Localized id="configure-slack-channel-triggers-reportedComments">
|
||||
Reported Comments
|
||||
</Localized>
|
||||
</CheckBox>
|
||||
)}
|
||||
</Field>
|
||||
<Field
|
||||
name={`${channel}.triggers.pendingComments`}
|
||||
type="checkbox"
|
||||
parse={parseBool}
|
||||
<Localized id="configure-slack-channel-triggers-pendingComments">
|
||||
Pending Comments
|
||||
</Localized>
|
||||
</CheckBox>
|
||||
)}
|
||||
</Field>
|
||||
<Field
|
||||
name={`${channel}.triggers.featuredComments`}
|
||||
type="checkbox"
|
||||
parse={parseBool}
|
||||
>
|
||||
{({ input }) => (
|
||||
<CheckBox
|
||||
id={`configure-slack-channel-triggers-featuredComments-${input.name}`}
|
||||
disabled={disabled || !channelEnabled}
|
||||
className={styles.trigger}
|
||||
{...input}
|
||||
>
|
||||
{({ input }) => (
|
||||
<CheckBox
|
||||
id={`configure-slack-channel-triggers-pendingComments-${input.name}`}
|
||||
disabled={
|
||||
disabled || allCommentsValue || !channelEnabled
|
||||
}
|
||||
className={styles.trigger}
|
||||
{...input}
|
||||
>
|
||||
<Localized id="configure-slack-channel-triggers-pendingComments">
|
||||
Pending Comments
|
||||
</Localized>
|
||||
</CheckBox>
|
||||
)}
|
||||
</Field>
|
||||
<Field
|
||||
name={`${channel}.triggers.featuredComments`}
|
||||
type="checkbox"
|
||||
parse={parseBool}
|
||||
>
|
||||
{({ input }) => (
|
||||
<CheckBox
|
||||
id={`configure-slack-channel-triggers-featuredComments-${input.name}`}
|
||||
disabled={
|
||||
disabled || allCommentsValue || !channelEnabled
|
||||
}
|
||||
className={styles.trigger}
|
||||
{...input}
|
||||
>
|
||||
<Localized id="configure-slack-channel-triggers-featuredComments">
|
||||
Featured Comments
|
||||
</Localized>
|
||||
</CheckBox>
|
||||
)}
|
||||
</Field>
|
||||
</div>
|
||||
)}
|
||||
</Field>
|
||||
<Localized id="configure-slack-channel-triggers-featuredComments">
|
||||
Featured Comments
|
||||
</Localized>
|
||||
</CheckBox>
|
||||
)}
|
||||
</Field>
|
||||
</div>
|
||||
</FormField>
|
||||
<div>
|
||||
<Button
|
||||
|
||||
@@ -41,7 +41,6 @@ const SlackConfigContainer: FunctionComponent<Props> = ({ form, settings }) => {
|
||||
name: "",
|
||||
hookURL: "",
|
||||
triggers: {
|
||||
allComments: false,
|
||||
reportedComments: false,
|
||||
pendingComments: false,
|
||||
featuredComments: false,
|
||||
@@ -57,7 +56,6 @@ const SlackConfigContainer: FunctionComponent<Props> = ({ form, settings }) => {
|
||||
enabled: true,
|
||||
hookURL: "",
|
||||
triggers: {
|
||||
allComments: false,
|
||||
reportedComments: false,
|
||||
pendingComments: false,
|
||||
featuredComments: false,
|
||||
@@ -143,7 +141,6 @@ const enhanced = withFragmentContainer<Props>({
|
||||
name
|
||||
hookURL
|
||||
triggers {
|
||||
allComments
|
||||
reportedComments
|
||||
pendingComments
|
||||
featuredComments
|
||||
|
||||
@@ -965,11 +965,6 @@ type SlackConfiguration {
|
||||
}
|
||||
|
||||
type SlackChannelTriggers {
|
||||
"""
|
||||
allComments is whether this channel will receive all comments entering moderation
|
||||
"""
|
||||
allComments: Boolean!
|
||||
|
||||
"""
|
||||
reportedComments is whether this channel will receive reported comments
|
||||
"""
|
||||
@@ -3539,11 +3534,6 @@ input CommenterAccountFeaturesInput {
|
||||
}
|
||||
|
||||
input SlackTriggersConfigurationInput {
|
||||
"""
|
||||
allComments is whether this channel will receive all comments entering moderation
|
||||
"""
|
||||
allComments: Boolean
|
||||
|
||||
"""
|
||||
reportedComments is whether this channel will receive reported comments
|
||||
"""
|
||||
|
||||
@@ -31,35 +31,23 @@ type Payload =
|
||||
| CommentFeaturedInput
|
||||
| CommentReleasedInput;
|
||||
|
||||
function enteredModeration(channel: SUBSCRIPTION_CHANNELS, payload: Payload) {
|
||||
const p: any = payload;
|
||||
return (
|
||||
channel === SUBSCRIPTION_CHANNELS.COMMENT_ENTERED_MODERATION_QUEUE &&
|
||||
p.hasOwnProperty("queue") &&
|
||||
(p.queue === GQLMODERATION_QUEUE.REPORTED ||
|
||||
p.queue === GQLMODERATION_QUEUE.PENDING)
|
||||
);
|
||||
}
|
||||
|
||||
function isFeatured(channel: SUBSCRIPTION_CHANNELS) {
|
||||
return channel === SUBSCRIPTION_CHANNELS.COMMENT_FEATURED;
|
||||
}
|
||||
|
||||
function isReported(channel: SUBSCRIPTION_CHANNELS, payload: Payload) {
|
||||
const p: any = payload;
|
||||
return (
|
||||
channel === SUBSCRIPTION_CHANNELS.COMMENT_ENTERED_MODERATION_QUEUE &&
|
||||
p.hasOwnProperty("queue") &&
|
||||
p.queue === GQLMODERATION_QUEUE.REPORTED
|
||||
(payload as CommentEnteredModerationQueueInput).queue ===
|
||||
GQLMODERATION_QUEUE.REPORTED
|
||||
);
|
||||
}
|
||||
|
||||
function isPending(channel: SUBSCRIPTION_CHANNELS, payload: Payload) {
|
||||
const p: any = payload;
|
||||
return (
|
||||
channel === SUBSCRIPTION_CHANNELS.COMMENT_ENTERED_MODERATION_QUEUE &&
|
||||
p.hasOwnProperty("queue") &&
|
||||
p.queue === GQLMODERATION_QUEUE.PENDING
|
||||
(payload as CommentEnteredModerationQueueInput).queue ===
|
||||
GQLMODERATION_QUEUE.PENDING
|
||||
);
|
||||
}
|
||||
|
||||
@@ -74,6 +62,7 @@ function createModerationLink(ctx: SlackContext, commentID: string) {
|
||||
|
||||
async function postCommentToSlack(
|
||||
ctx: SlackContext,
|
||||
message: string,
|
||||
commentID: string,
|
||||
hookURL: string
|
||||
) {
|
||||
@@ -100,29 +89,11 @@ async function postCommentToSlack(
|
||||
const body = commentBody.replace(/<br\/?>/g, "\n");
|
||||
|
||||
const data = {
|
||||
text: `${author.username} commented on: ${storyTitle}`,
|
||||
blocks: [
|
||||
text: `${message} on *<${story.url}|${storyTitle}>*`,
|
||||
attachments: [
|
||||
{
|
||||
type: "section",
|
||||
text: {
|
||||
type: "mrkdwn",
|
||||
text: `${author.username} commented on:\n<${story.url}|${storyTitle}>`,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "section",
|
||||
text: {
|
||||
type: "mrkdwn",
|
||||
text: `<${moderateLink}|Go to Moderation> | <${commentLink}|See Comment>`,
|
||||
},
|
||||
},
|
||||
{ type: "divider" },
|
||||
{
|
||||
type: "section",
|
||||
text: {
|
||||
type: "mrkdwn",
|
||||
text: body,
|
||||
},
|
||||
text: body,
|
||||
footer: `Authored by *${author.username}* | <${moderateLink}|Go to Moderation> | <${commentLink}|See Comment>`,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -171,11 +142,16 @@ function createSlackPublisher(
|
||||
const ctx = new SlackContext({ mongo, config, tenant });
|
||||
|
||||
try {
|
||||
const inModeration = enteredModeration(channel, payload);
|
||||
const reported = isReported(channel, payload);
|
||||
const pending = isPending(channel, payload);
|
||||
const featured = isFeatured(channel);
|
||||
|
||||
// If the comment doesn't match any filter, then we don't need to send
|
||||
// anything.
|
||||
if (!reported && !pending && !featured) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { commentID } = payload;
|
||||
|
||||
for (const ch of channels) {
|
||||
@@ -194,17 +170,29 @@ function createSlackPublisher(
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
triggers.allComments &&
|
||||
(reported || pending || featured || inModeration)
|
||||
) {
|
||||
await postCommentToSlack(ctx, commentID, hookURL);
|
||||
} else if (triggers.reportedComments && reported) {
|
||||
await postCommentToSlack(ctx, commentID, hookURL);
|
||||
// Add ticket to add back all comments option (including approved)
|
||||
|
||||
if (triggers.reportedComments && reported) {
|
||||
await postCommentToSlack(
|
||||
ctx,
|
||||
"This comment has been reported",
|
||||
commentID,
|
||||
hookURL
|
||||
);
|
||||
} else if (triggers.pendingComments && pending) {
|
||||
await postCommentToSlack(ctx, commentID, hookURL);
|
||||
await postCommentToSlack(
|
||||
ctx,
|
||||
"This comment is pending",
|
||||
commentID,
|
||||
hookURL
|
||||
);
|
||||
} else if (triggers.featuredComments && featured) {
|
||||
await postCommentToSlack(ctx, commentID, hookURL);
|
||||
await postCommentToSlack(
|
||||
ctx,
|
||||
"This comment has been featured",
|
||||
commentID,
|
||||
hookURL
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
|
||||
@@ -423,7 +423,6 @@ configure-slack-channel-hookURL-description =
|
||||
follow the instructions <externalLink>here</externalLink>.
|
||||
configure-slack-channel-triggers-label =
|
||||
Receive notifications in this Slack channel for
|
||||
configure-slack-channel-triggers-allComments = All Comments
|
||||
configure-slack-channel-triggers-reportedComments = Reported Comments
|
||||
configure-slack-channel-triggers-pendingComments = Pending Comments
|
||||
configure-slack-channel-triggers-featuredComments = Featured Comments
|
||||
|
||||
Reference in New Issue
Block a user