Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions lib/interaction_handlers/block_action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockActionInteraction> = async data => {
console.log(`Block action!`);
Expand All @@ -20,7 +20,27 @@ const block_action: InteractionHandler<BlockActionInteraction> = 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": {
Expand Down
38 changes: 37 additions & 1 deletion lib/interaction_handlers/view_submission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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<string>("reject");

const view_submission: InteractionHandler<ViewSubmissionInteraction> = 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];
Expand Down
3 changes: 3 additions & 0 deletions lib/secrets_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand Down