Skip to content

Commit

Permalink
Fix timing and undefined emoji issues
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumManiac committed Mar 11, 2024
1 parent e18f285 commit a4cc722
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions src/utils/eventReminders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { WebClient, ChatPostMessageResponse } from "@slack/web-api";
import moment from "moment-timezone";

import CalendarEvent from "../classes/CalendarEvent";
import { postMessage, addReactionToMessage, getMessagePermalink, getAllSlackUsers } from "./slack";
import { postMessage, getMessagePermalink, getAllSlackUsers } from "./slack";
import { getDefaultSlackChannels } from "./channels";
import { generateEmojiPair } from "./slackEmojis";
import { generateEmojiPair, seedMessageReactions } from "./slackEmojis";
import SlackChannel from "../classes/SlackChannel";
import SlackUser from "../classes/SlackUser";
import { postMessageToSingleChannelGuestsInChannels } from "./users";
Expand Down Expand Up @@ -160,13 +160,9 @@ export async function postReminderToChannel(

const timestamp = res.ts;

if (reactEmojis !== undefined) {
if (reactEmojis != undefined && reactEmojis.length > 0) {
try {
const [emoji1, emoji2] = reactEmojis;
await addReactionToMessage(client, channel.id, emoji1, timestamp);
// Add small manual delay to ensure sequential reactions
await new Promise((resolve) => setTimeout(resolve, 250));
await addReactionToMessage(client, channel.id, emoji2, timestamp);
await seedMessageReactions(client, channel.id, reactEmojis, timestamp);
} catch (error) {
SlackLogger.getInstance().error(
`Failed to add reactions \`${reactEmojis}\` to message \`${timestamp}\` in \`${channel.name}\` with error:`,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/slackEmojis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function seedMessageReactions(
timestamp: string | number,
): Promise<void> {
const response = await addReactionToMessage(client, channel, emojis[0], timestamp);

await new Promise((resolve) => setTimeout(resolve, 500));
if (response.ok) {
await addReactionToMessage(client, channel, emojis[1], timestamp);
}
Expand Down

0 comments on commit a4cc722

Please sign in to comment.