portal: silently drop empty Matrix messages instead of erroring - #225
Open
Deln0r wants to merge 1 commit into
Open
portal: silently drop empty Matrix messages instead of erroring#225Deln0r wants to merge 1 commit into
Deln0r wants to merge 1 commit into
Conversation
When a Matrix client sends a text/notice/emote with an empty body to
a Discord-bridged room, the bridge currently relays it to Discord
verbatim. Discord's API rejects the call with HTTP 400 / code 50006
("Cannot send an empty message"), and the bridge surfaces a notice
back into the Matrix room. Ten empty messages therefore become
twenty (ten originals plus ten error notices), which makes accidental
empty sends a cheap room-spam vector and is generally noisy (see mautrix#186).
Add an errEmptyMatrixMessage sentinel and check it on the
MsgText/MsgEmote/MsgNotice path of (*Portal).handleMatrixMessage,
just after parseMatrixHTML resolves the final Discord content. If the
content is whitespace-only AND there is no reply embed attached, drop
the message before making the API call: the sendMessageMetrics call
is still made with the Ignoring action so the checkpoint is recorded,
but sendNotice is false so no error message hits the room.
Non-text content (images, files, audio, video) is unaffected: those
paths attach a file separately and never reach this check.
Closes mautrix#186.
Signed-off-by: Ian Chechin <ian00chechin@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #186.
Problem
When a Matrix client sends a text/notice/emote with an empty body to a Discord-bridged room, the bridge relays it to Discord verbatim. Discord's API rejects the call with
HTTP 400/ code50006("Cannot send an empty message"), and the bridge surfaces an error notice back into the Matrix room. Ten empty messages therefore become twenty (ten originals plus ten error notices), which makes accidental empty sends a cheap room-spam vector.Fix
Add an
errEmptyMatrixMessagesentinel. On theMsgText/MsgEmote/MsgNoticebranch of(*Portal).handleMatrixMessage, just afterparseMatrixHTMLresolves the final Discord content, check whether the content is whitespace-only AND there is no reply embed attached. If so, drop the message before making the API call:The metric call is still made with the
Ignoringaction so the checkpoint is recorded, butsendNoticeisfalsefor this error class, so no error message hits the Matrix room. Non-text content (images, files, audio, video) is unaffected: those paths attach a file separately and never reach this check.Test plan
go build ./...andgo vet ./...are clean (with libolm headers available; this matches what CI does).No new test added because
portal_test.godoesn't exist in this repo and a full end-to-end integration test would need a live Discord client. Happy to add a focused unit test for the empty-content branch if you want a regression guard.