Skip to content

Commit

Permalink
Merge pull request #434 from ojaha065/develop
Browse files Browse the repository at this point in the history
Hotfix: Clear truncate timeout if the message is deleted
  • Loading branch information
ojaha065 authored Sep 9, 2024
2 parents 65ec131 + 204515e commit 7f9f555
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 7 additions & 2 deletions resources/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,22 @@ features:
oauth_config:
scopes:
bot:
- channels:join
- channels:manage
- chat:write
- chat:write.public
- commands
- metadata.message:read
- reactions:write
- channels:join
- channels:manage
settings:
event_subscriptions:
request_url: https://lounasbotti-disec.fly.dev/slack/events
bot_events:
- app_home_opened
- message_metadata_deleted
metadata_subscriptions:
- app_id: A02EYG04A83
event_type: lounasbotti_message
interactivity:
is_enabled: true
request_url: https://lounasbotti-disec.fly.dev/slack/events
Expand Down
16 changes: 14 additions & 2 deletions src/BotEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ const initEvents = (app: bolt.App, settings: Settings): void => {
});
});

// No need to try truncating if the message is already deleted
app.event("message_metadata_deleted", async args => {
const tt = truncateTimeouts.find(tt => tt.ts === args.payload.message_ts);
if (tt) {
console.debug(`Message ${args.payload.message_ts} removed? Clearing timeout...`);
clearTimeout(tt.timeout);
truncateTimeouts.splice(truncateTimeouts.indexOf(tt), 1);
}
});

// Fetch additional
if (settings.additionalRestaurants?.length) {
app.action({type: "block_actions", action_id: RegExp(`fetchAdditionalRestaurant-(?:${settings.additionalRestaurants.join("|")})`)}, async args => {
Expand Down Expand Up @@ -255,7 +265,8 @@ const initEvents = (app: bolt.App, settings: Settings): void => {
blocks: cachedData.blocks,
text: "Lounaslistat",
unfurl_links: false,
unfurl_media: false
unfurl_media: false,
metadata: { event_type: "lounasbotti_message", event_payload: {} }
});

handleMainTriggerResponse(response, app, settings, channel, cachedData.data, isTomorrowRequest);
Expand All @@ -266,7 +277,8 @@ const initEvents = (app: bolt.App, settings: Settings): void => {
blocks: cachedData.blocks,
text: "Lounaslistat",
unfurl_links: false,
unfurl_media: false
unfurl_media: false,
metadata: { event_type: "lounasbotti_message", event_payload: {} }
});

handleMainTriggerResponse(response, app, settings, response.channel ?? args.payload.channel, cachedData.data, isTomorrowRequest);
Expand Down

0 comments on commit 7f9f555

Please sign in to comment.