Skip to content

Refactor Reaction Grouping and Enhance Traceroute Responses#18

Open
tylerpieper wants to merge 3 commits into
ArizonaMeshtasticCommunity:mainfrom
tylerpieper:feature/traceroute-reactions-update
Open

Refactor Reaction Grouping and Enhance Traceroute Responses#18
tylerpieper wants to merge 3 commits into
ArizonaMeshtasticCommunity:mainfrom
tylerpieper:feature/traceroute-reactions-update

Conversation

@tylerpieper
Copy link
Copy Markdown
Contributor

Refactor Reaction Grouping and Enhance Traceroute Responses

This PR introduces two quality-of-life improvements to the Meshtastic Discord Bridge, aimed at reducing channel clutter and making information easier to read at a glance.

What's Changed

1. Emoji Reaction Grouping

Previously, when multiple nodes reacted with the same emoji, the bridge would append a new line for each reaction (e.g. 👍 - [abc1], 👍 - [def2]).

Reactions are now grouped by emoji on a single line, and the list of lines is sorted natively so numbers or identical emojis stay clustered and consistent.

  • Before:
    👍 - [abc1]
    👍 - [def2]
    
  • After:
    👍 - [abc1], [def2]
    

2. Traceroute Reply Correlation

Previously, outbound traceroutes and their corresponding replies were handled as independent events, which could lead to multiple separate messages in the channel for a single trace.

With this update:

  • Outbound TRs: Sent to the channel as usual, but the bot now tracks the Discord Message ID.
  • Inbound Replies: Instead of posting a new message, the bot matches the inbound reply (request_id) to the outbound request, fetches the original Discord message, and edits the embed to indicate completion.
  • Route Display: The bot decodes the RouteDiscovery payload on the reply and extracts the forward route array. It translates node numbers to short names (if available in the DB) and adds a Route Taken field to the original embed (e.g., NodeA → NodeB → NodeC).
  • Orphan Fallback: If the original outbound message cannot be found, the bot gracefully falls back to sending a new message explicitly stating it is a "Traceroute Reply Received" with the path taken.

⚠️ Important Note to Maintainers (Database Schema Change)

To correlate inbound traceroute replies to the original outbound Discord messages, this PR adds a discord_message_id column to the traceroute table in meshtastic.db.

I've included a resilient migration step in the setup_database() method that utilizes ALTER TABLE within a try/except block to seamlessly upgrade existing databases without any manual intervention or breakage.

@tylerpieper
Copy link
Copy Markdown
Contributor Author

Additional PR Change: Increase Message History Retention for Reactions

Context

Slipping in an extra bug fix for this PR before code review: someone noticed that reactions sent to messages a few hours old were not attaching to their original Discord messages. Instead, they were showing up as standalone new messages.

Root Cause

The message_history SQLite table is used by the mqttbridge cog to map Meshtastic reply_ids to the original discord_message_id. However, the store_message_history logic was aggressively pruning this table to keep only the last 50 messages. On an active mesh network, an original message would quickly fall out of the top 50, effectively erasing the link needed to attach a tapback/reaction to the original Discord embed.

Fix

Increased the message_history retention limit from 50 messages to 10,000 messages.

  • When the row count exceeds 10,000, it safely trims down to the newest 9,500 messages.
  • Since we are using an SQLite database, storing 10,000 records takes up virtually no extra disk space or performance overhead, but will keep days of message history available for late reactions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant