Skip to content

Commit

Permalink
Merge pull request #49 from rpiambulance/poll-move
Browse files Browse the repository at this point in the history
Changes to Poll Move
  • Loading branch information
lramos15 authored Feb 12, 2020
2 parents 2e60127 + a886222 commit 52a23ef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
10 changes: 8 additions & 2 deletions src/Actions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Poll } from "./Poll";
import { WebClient, WebAPICallResult, ChatPostMessageArguments } from "@slack/web-api";
import { ChatPostMessageArguments, ChatUpdateArguments, WebAPICallResult, WebClient } from "@slack/web-api";
import { KnownBlock } from "@slack/types";
import { Request, Response } from "express";
import * as Sentry from "@sentry/node";
Expand Down Expand Up @@ -109,7 +109,13 @@ export class Actions {
await this.wc.chat.delete({ channel: payload.channel.id, ts: payload.message.ts })
.catch((err: any) => console.error(err));
// Must be artificially slowed down to prevent the poll from glitching out on Slack's end
setTimeout(() => this.postMessage(payload.channel.id, payload.message.text, payload.message.blocks), 300);
setTimeout(() => this.postMessage(payload.channel.id, "Poll Moved!", []).then((res: any) => {
const msg: ChatUpdateArguments = {
channel: payload.channel.id, text: payload.message.text,
ts: res.ts, blocks: payload.message.blocks
};
this.wc.chat.update(msg);
}), 300);
} else {
this.postEphemeralOnlyAuthor("move", "poll", payload.channel.id, payload.user.id);
}
Expand Down
9 changes: 6 additions & 3 deletions src/Poll.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
KnownBlock, SectionBlock, ContextBlock, Button, ActionsBlock, StaticSelect, PlainTextElement, MrkdwnElement
ActionsBlock, Button, ContextBlock, KnownBlock, MrkdwnElement, PlainTextElement, SectionBlock, StaticSelect
} from "@slack/types";
import { PollHelpers } from "./PollHelpers";
import * as Sentry from "@sentry/node";
Expand Down Expand Up @@ -81,7 +81,10 @@ export class Poll {
}

public getBlocks(): KnownBlock[] {
return this.message;
let str = JSON.stringify(this.message);
str = str.replace("&lt;", "<")
.replace("&gt;", ">").replace("&amp;", "&");
return JSON.parse(str);
}

public getAuthor(): string {
Expand Down Expand Up @@ -182,7 +185,7 @@ export class Poll {
}

private generateVoteResults(): void {
// We throw out the old vote response and construct them again
// We throw out the old vote response and construct them again
const sectionBlocks = this.generateResults(false);
this.message = this.message.slice(0, this.getDividerId() + 1).concat(sectionBlocks);
}
Expand Down
6 changes: 2 additions & 4 deletions src/PollHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
SectionBlock, ContextBlock, PlainTextElement, Option
} from "@slack/types";
import { SectionBlock, ContextBlock, PlainTextElement, Option } from "@slack/types";

export class PollHelpers {
public static appendIfMatching(optionArray: string[], keyword: string, appendText: string): string {
Expand All @@ -22,4 +20,4 @@ export class PollHelpers {
public static buildTextElem(text: string): PlainTextElement {
return { type: "plain_text", text, emoji: true };
}
}
}

0 comments on commit 52a23ef

Please sign in to comment.