ITADN
mautrix/go/Issues

QR code login image not rendered: Format/FormattedBody on m.image overrides image display

#463Closedagiliton 创建于 2026-02-21
A
agilitoncommented
## Bug Description The `sendQR()` function in `bridgev2/commands/login.go` sends QR codes as `m.image` events but also includes `format: org.matrix.custom.html` and `formatted_body` with a `<pre><code>` block. This causes Element (and likely other clients) to render the HTML formatted body instead of the actual QR image. ## Expected Behavior QR code should render as a scannable image in Element and other Matrix clients. ## Actual Behavior QR code appears as a `qr.png` file attachment (thumbnail not shown) or as a text code block, depending on the client. The image is never rendered inline. ## Root Cause In `bridgev2/commands/login.go`, the `sendQR()` function constructs the event content like this: ```go content := &event.MessageEventContent{ MsgType: event.MsgImage, FileName: "qr.png", URL: qrMXC, File: qrFile, Body: qr, // Raw QR text data Format: event.FormatHTML, FormattedBody: fmt.Sprintf("<pre><code>%s</code></pre>", html.EscapeString(qr)), } ``` **Two issues:** 1. **`Format` + `FormattedBody` override image rendering**: When Element sees `format: org.matrix.custom.html` on any message (even `m.image`), it renders the `formatted_body` HTML instead of the image. The spec allows `format`/`formatted_body` on `m.image` for caption purposes, but here it contains the raw QR text data in a code block — not a caption. 2. **Missing `info` field**: The event has no `info` object (no `mimetype`, `w`, `h`, `size`). While not strictly required, many clients use this to decide whether/how to render an image thumbnail. Without it, some clients fall back to showing a file attachment. ## Suggested Fix Remove the `Format` and `FormattedBody` fields from the image event, and add an `info` field: ```go content := &event.MessageEventContent{ MsgType: event.MsgImage, FileName: "qr.png", Body: "qr.png", URL: qrMXC, File: qrFile, Info: &event.FileInfo{ MimeType: "image/png", // Width/Height could be set from the generated image dimensions }, } ``` If the text-based QR fallback is desired for clients that cannot render images, it could be sent as a separate `m.text` message or included in `Body` as alt-text (but not in `FormattedBody` with `Format: org.matrix.custom.html`). ## Environment - Bridge: mautrix-whatsapp v0.2602.0 - Homeserver: Synapse 1.147.1 - Client: Element Web (latest) - Encryption: E2EE enabled (appservice mode) ## How to Reproduce 1. Start a WhatsApp bridge login flow by sending `login qr` to the bridge bot 2. Observe the QR code event in Element — it shows as a file attachment or code block, not as an inline image 3. Inspect the decrypted event content: it has both `msgtype: m.image` with `url`/`file` fields AND `format: org.matrix.custom.html` with `formatted_body: "<pre><code>...""`
关闭于 2026-02-21 1 条评论