diff --git a/lib/interaction_handlers/block_action.ts b/lib/interaction_handlers/block_action.ts index 2b7e5da..f525579 100644 --- a/lib/interaction_handlers/block_action.ts +++ b/lib/interaction_handlers/block_action.ts @@ -2,7 +2,7 @@ import { BlockActionInteraction, InteractionHandler } from "../../pages/api/inte import { stageConfession, viewConfession, web } from "../main"; import { Blocks, InputSection, MarkdownText, PlainText, PlainTextInput, TextSection } from "../block_builder"; import getRepository from "../db"; -import { approve_tw_id, undo_confirm_id } from "./view_submission"; +import { approve_tw_id, reject_id, undo_confirm_id } from "./view_submission"; const block_action: InteractionHandler = async data => { console.log(`Block action!`); @@ -20,7 +20,27 @@ const block_action: InteractionHandler = async data => { } case "disapprove": { console.log(`Disapproval of message ts=${data.message.ts}`); - await viewConfession(repo, data.message.ts, false, data.user.id); + // await viewConfession(repo, data.message.ts, false, data.user.id); + const resp = await web.views.open({ + trigger_id: data.trigger_id, + view: { + callback_id: reject_id(data.message.ts), + type: "modal", + title: new PlainText(`Reject Confession`).render(), + submit: new PlainText("Reject").render(), + close: new PlainText("Cancel").render(), + blocks: new Blocks([ + new InputSection( + new PlainTextInput("reject_input", true), + new PlainText("reason"), + "reason" + ), + ]).render(), + }, + }); + if (!resp.ok) { + throw "Failed to open modal"; + } break; } case "approve:tw": { diff --git a/lib/interaction_handlers/view_submission.ts b/lib/interaction_handlers/view_submission.ts index 55dd044..f08068f 100644 --- a/lib/interaction_handlers/view_submission.ts +++ b/lib/interaction_handlers/view_submission.ts @@ -3,7 +3,7 @@ import { InteractionHandler, ViewSubmissionInteraction } from "../../pages/api/interaction_work"; import { sameUser, unviewConfession, viewConfession, web } from "../main"; import { MarkdownText, TextSection } from "../block_builder"; -import { confessions_channel, meta_channel } from "../secrets_wrapper"; +import { confessions_channel, confessions_meta_channel, meta_channel } from "../secrets_wrapper"; import { sanitize } from "../sanitizer"; import getRepository from "../db"; @@ -38,9 +38,45 @@ export const [undo_confirm_id, undo_confirm_handler] = make_dialog<{ undoer_uid: string }>("undo_confirm"); +export const [reject_id, reject_handler] = make_dialog("reject"); + const view_submission: InteractionHandler = async (data, res) => { // todo passthrough return const dialogs = [ + reject_handler(async (staging_ts) => { + if (Array.isArray(staging_ts)) { + staging_ts = staging_ts[0]; + } + const repo = await getRepository(); + const record = await repo.findOne({ staging_ts }); + if (record === undefined) { + throw `Failed to find single Postgres record with staging_ts=${staging_ts}`; + } + + // quick assert for typeck + if ( + data.view.state.values.reason.reject_input.type != + "plain_text_input" + ) + return false; + + + await viewConfession( + repo, + staging_ts, + false, + data.user.id, + data.view.state.values.reason.reject_input.value + ); + + const r = await web.chat.postMessage({ + channel: confessions_meta_channel, + text: `*rejected #${record.id}:* ${data.view.state.values.reason.reject_input.value}`, + }); + if (!r.ok) throw `Failed to send reject message`; + return true; + }), + reply_modal_handler(async (published_ts) => { if(Array.isArray(published_ts)) { published_ts = published_ts[0]; diff --git a/lib/secrets_wrapper.ts b/lib/secrets_wrapper.ts index 1a874ae..e819529 100644 --- a/lib/secrets_wrapper.ts +++ b/lib/secrets_wrapper.ts @@ -25,6 +25,7 @@ export let airtable_base: string | null; export let staging_channel: string; export let confessions_channel: string; export let meta_channel: string; +export let confessions_meta_channel: string; export let slack_signing_secret: string; export let postgres_url: string; @@ -48,6 +49,7 @@ try { staging_channel = secrets.staging_channel; confessions_channel = secrets.confessions_channel; meta_channel = secrets.meta_channel; + confessions_meta_channel = secrets.confessions_meta_channel; slack_signing_secret = secrets.slack_signing_secret; postgres_url = secrets.postgres_url; airtable_api_key = secrets.airtable_api_key ?? null; @@ -57,6 +59,7 @@ try { staging_channel = check_env("STAGING_CHANNEL_ID"); confessions_channel = check_env("CONFESSIONS_CHANNEL_ID"); meta_channel = check_env("META_CHANNEL_ID"); + confessions_meta_channel = check_env("CONFESSIONS_META_CHANNEL_ID"); slack_signing_secret = check_env("SLACK_SIGNING_SECRET"); postgres_url = check_env("POSTGRES_URL"); airtable_api_key = null;