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
16 changes: 8 additions & 8 deletions src/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export class Actions {
case "bottom":
this.onBottomSelected(payload, poll);
break;
case "lock":
this.onLockSelected(payload, poll);
case "close":
this.onCloseSelected(payload, poll);
break;
case "delete":
this.onDeleteSelected(payload, poll);
Expand Down Expand Up @@ -82,10 +82,10 @@ export class Actions {

private onResetSelected(payload: any, poll: Poll): void {
payload.message.text = "Vote reset!";
if (poll.getLockedStatus()) {
if (poll.getClosedStatus()) {
this.wc.chat.postEphemeral({
channel: payload.channel.id,
text: "You cannot reset your vote after the poll has been locked.", user: payload.user.id
text: "You cannot reset your vote after the poll has been closed.", user: payload.user.id
});
} else {
poll.resetVote(payload.user.id);
Expand All @@ -106,13 +106,13 @@ export class Actions {
}
}

private onLockSelected(payload: any, poll: Poll): void {
payload.message.text = "Poll locked!";
private onCloseSelected(payload: any, poll: Poll): void {
payload.message.text = "Poll is closed!";
if (Actions.isPollAuthor(payload, poll)) {
poll.lockPoll();
poll.closePoll();
payload.message.blocks = poll.getBlocks();
} else {
this.postEphemeralOnlyAuthor("lock", "poll", payload.channel.id, payload.user.id);
this.postEphemeralOnlyAuthor("close", "poll", payload.channel.id, payload.user.id);
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/Poll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Poll {
placeholder: Static.buildTextElem("Poll Options"),
options: [
Static.buildSelectOption("Reset your vote", "reset"),
Static.buildSelectOption(":lock: Lock poll", "lock"),
Static.buildSelectOption("Close the poll", "close"),
Static.buildSelectOption("Move to bottom", "bottom"),
Static.buildSelectOption("Delete poll", "delete")
]
Expand All @@ -77,14 +77,14 @@ export class Poll {
private message: KnownBlock[] = [];
private multiple = false;
private anonymous = false;
private isLocked = false;
private isClosed = false;
constructor(message: KnownBlock[]) {
this.message = message;
// Since its databaseless the way we know if it is anonymous or multiple is by parsing the title
this.multiple = this.checkIfMsgContains("(Multiple Answers)");
this.anonymous = this.checkIfMsgContains("(Anonymous)");
// If there's no buttons then the poll is locked
this.isLocked = this.message[3].type === "divider";
// If there's no buttons then the poll is closed
this.isClosed = this.message[3].type === "divider";
}

public getBlocks(): KnownBlock[] {
Expand All @@ -95,8 +95,8 @@ export class Poll {
return ((this.message[1] as ContextBlock).elements[0] as PlainTextElement).text.replace("Asked by: ", "");
}

public getLockedStatus(): boolean {
return this.isLocked;
public getClosedStatus(): boolean {
return this.isClosed;
}

private getVotesAndUserIndex(button: Button, userId: string): { votes: string[]; userIdIndex: number } {
Expand Down Expand Up @@ -130,9 +130,9 @@ export class Poll {
this.generateVoteResults();
}

public lockPoll(): void {
if (this.isLocked) return;
this.isLocked = true;
public closePoll(): void {
if (this.isClosed) return;
this.isClosed = true;
this.generateVoteResults();
this.message = this.message.slice(0, 2).concat(this.message.slice(this.getDividerId() - 1));
// ((this.message[2] as ActionsBlock).elements[0] as StaticSelect).options!.splice(0, 2);
Expand Down Expand Up @@ -178,7 +178,7 @@ export class Poll {
return false;
});
const sections = Object.keys(votes).map(key => this.buildVoteTally(overrideAnon, votes, key) as SectionBlock);
if (this.isLocked) sections.unshift(Static.buildSectionBlock(":lock:"));
if (this.isClosed) sections.unshift(Static.buildSectionBlock(":lock:"));
return sections;
}

Expand Down