Message Editing & Deletion
Relevant source files
The following files were used as context for generating this wiki page:
Matterbridge supports the synchronization of message edits and deletions across various chat protocols. This feature ensures that when a user modifies or removes a message on one platform (e.g., Slack), the corresponding bridged messages on other platforms (e.g., Mattermost or Discord) are updated or removed accordingly.
This functionality is a core component of the bridge's goal to maintain a consistent conversation state across disparate chat systems. The implementation relies on unique message identifiers and event-driven handlers within each protocol's bridge logic.
Sources: README.md:104, bridge/mattermost/mattermost.go:160-167
Architecture and Data Flow
The system processes edits and deletions by identifying specific event types within the config.Message structure. When a bridge receives an update from its native platform, it translates that action into a generalized event that the gateway then broadcasts to other configured bridges.
Message Deletion Flow
Deletion is triggered by the EventMsgDelete event. The bridge identifies the message to be removed using its unique ID. If the ID is present, the bridge calls the protocol-specific deletion method (e.g., DeleteMessage in the Mattermost client).
The diagram shows the logic flow when a bridge receives a deletion event.
Sources: bridge/mattermost/mattermost.go:160-167
Message Editing Flow
Editing logic typically checks if a message ID is provided in a standard message event. If an ID exists, the bridge attempts to update the existing message text via the native API rather than posting a new message.
The sequence diagram illustrates how an incoming message with an existing ID is treated as an edit.
Sources: bridge/mattermost/mattermost.go:193-196
Implementation Details
Mattermost Implementation
In the Mattermost bridge, the Send function handles both deletions and edits based on the properties of the incoming config.Message object.
| Action | Logic | Method Called |
|---|---|---|
| Delete | Check msg.Event == config.EventMsgDelete | mc.DeleteMessage(msg.ID) |
| Edit | Check msg.ID != "" (for normal events) | mc.EditMessage(msg.ID, msg.Text) |
Sources: bridge/mattermost/mattermost.go:160-167, bridge/mattermost/mattermost.go:193-196
API Integration
The Matterbridge API allows external 3rd party applications to interact with these features through structured JSON payloads. The config.IncomingMessage and config.OutgoingMessage schemas include fields essential for tracking message relationships.
| Field | Type | Description |
|---|---|---|
id | string | Unique ID of the message on the gateway/bridge. Required for edits/deletes. |
event | string | Specific matterbridge event (e.g., EventMsgDelete). |
text | string | Updated content of the message for edits. |
Sources: contrib/api.yaml:69-122
Underlying Library Support
The feature relies on the capabilities of the underlying vendor libraries used for each protocol:
- Discord: Uses
discordgo, which provides methods likeChannelMessageEdit. Sources: vendor/github.com/bwmarrin/discordgo/CONTRIBUTING.md:46 - Slack: The
slack-golibrary handles message updates and provides event metadata to support thread broadcasts and message changes. Sources: vendor/github.com/slack-go/slack/CHANGELOG.md:12-25 - Mattermost: Utilizes the
matterclientto executeDeleteMessageandEditMessagecalls. Sources: bridge/mattermost/mattermost.go:166,194
Summary
Message Editing & Deletion in Matterbridge provides real-time synchronization of message states across different chat platforms. By leveraging unique message IDs and specific event types, the bridge can effectively translate a "delete" or "edit" action from one protocol to all other connected protocols, maintaining the integrity of the cross-platform conversation.