Skip to content

Read pictures and encrypted messages in history - #33

Merged
TroyHernandez merged 6 commits into
mainfrom
history-media
Nov 18, 2026
Merged

TroyHernandez merged 6 commits into
mainfrom
history-media

Conversation

@TroyHernandez

Copy link
Copy Markdown
Contributor

chat_history() on Matrix skipped 2 kinds of event:

  • Pictures and files. The contract says chat_history() puts inbound media in a message's attachments, as chat_poll() does. Matrix's history dropped every msgtype other than text, notice and emote.
  • Encrypted events. History read only m.room.message, so on an E2EE client an encrypted room's history was empty.

A consumer's restart backfill reads history. So a picture sent while it was down was never seen, and an encrypted room came back with no context.

History now reads its page the way the poll reads a sync: the same media extractor and the same decrypt step, with the page wrapped in the shape a sync has. Both build their messages through 2 shared helpers (matrix_decrypted_message(), matrix_media_message()), so one event gives the same chat_message from either. A test compares the two field for field.

  • A page that cannot be decrypted is reported and read for its cleartext. An event this device holds no key for stays unread, as in a poll.
  • The decrypt step is the poll's, so it may request a missing room key from this user's other devices, as a poll does.
  • A msgtype the contract has no word for, with nothing to fetch (a location), is still dropped.

Stacked on #32 (base content-keys), since both change chat_poll()'s message builders. It moves to main when #32 merges. No version bump yet.

Tests: 23 new assertions in test_matrix.R, 16 of which fail on #32's code. test_matrix.R 598, test_matrix_mxclient.R 202 and test_contract.R 312, all passing.

chat_send() and chat_edit() take content, a named list of keys for
the message's own content, such as a namespaced "ai.cornball.agent"
that one client reads and the rest ignore. Matrix adds them beside
body and msgtype, in the cleartext path through mx_send() (as rich
goes, since mx_send_text() takes no extra content, with the mentions,
thread and markdown it would have built) and in the encrypted path as
extra content inside the ciphertext. An edit puts them in
m.new_content. A key chat.api writes itself is refused.

Received, a cleartext message's raw now carries the event's whole
content as raw$content, looked up from the sync by event id as the
times are: mx_extract_text_events() keeps 6 fields and drops the rest.
A decrypted record has content already, and history's raw is the
event, so raw$content reads the same on all 3. The loopback adapter
records the keys there too; the other adapters take the argument and
ignore it, as they ignore rich.
The keys went in m.new_content only. A client showing the edit event
itself, its original out of view, saw the fallback without them. They
now go in both, as chat_edit() already does with formatted text. Asked
for by the app that reads the keys.
chat_message()'s raw now promises the event's whole content in
raw$content for a Matrix message. A picture reached chat_poll() with the
media record alone as its raw.
chat_history() on Matrix skipped every picture and every encrypted
event. A restart's backfill reads history, so it never saw a picture
sent while a bot was down, and saw nothing of an encrypted room.
History now reads its page through the poll's own media and decrypt
steps and builds the same messages, through helpers both share.
@TroyHernandez
TroyHernandez changed the base branch from content-keys to main November 18, 2026 23:22
@TroyHernandez
TroyHernandez merged commit 21f3456 into main Nov 18, 2026
2 checks passed
@TroyHernandez
TroyHernandez deleted the history-media branch November 18, 2026 23:50
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