Repository navigation
Carry a caller's own content keys on send, edit and receive - #32
Merged
Merged
Conversation
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.
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.
A consumer can now carry data of its own in a Matrix message's content, under a namespaced key that its own client reads and every other client ignores. A relay that posts an agent's tool calls as notices needs it: the app renders a card from the key, and a stock client shows the plain-text body. Before this,
richcould carry an HTML fragment and nothing else, and a received cleartext message lost every content key the text extractor does not keep.The change
chat_send(..., content = NULL)andchat_edit(..., content = NULL)on the contract.contentis a named list of keys for the message's own content.bodyandmsgtype.mx_send_text()takes no extra content, so a send with keys goes throughmx.api::mx_send(), as arichsend already does. It still builds whatmx_send_text()would have: the HTML from markdown with mention pills,m.mentionsand the thread relation. With a caller'srichfragment, the fragment is sent as given andm.mentionsstill goes in, since the notification depends on it.crypto_ops$send()asextra, which the Megolm path encrypts with the rest.extrais named only when there are keys, so a crypto seam without the argument still sends.m.new_content, beside the replacement text, and in the fallback copy around it, on both paths, aschat_edit()already does with formatted text. A client that shows the edit event itself, with its original out of view, still has them. They replace the original's, as the text does. (The fallback copy came in 1268016, at the app's request.)body,msgtype,format,formatted_body,m.relates_to,m.mentions,m.new_content. Each has its own argument. An empty list means no keys.rawgainsraw$content, the event's whole content, looked up from the sync by event id the way the timestamps already are.mx_extract_text_events()keeps 6 fields of the content and drops the rest. A decrypted record already carriescontent(mx.client 0.3.0), and history'srawis the event itself, soraw$contentreads the same on all 3 paths.chat_message()'s documentation now promises it.raw$content, so a consumer's tests read them as its code does against a homeserver. Slack, Telegram and IRC take the argument and ignore it, as they ignorerich.matrix_thread_relation()holds the threaded-reply relation thatmatrix_send_rich()built inline, now shared with the new path. Its output is unchanged.Behavior change
rawhas one more field,content.test_matrix_mxclient.Rasserted its absence, and now asserts the new shape.content.Not changed
mx_crypto_encrypt_event()copiesm.relates_toout of the ciphertext. A new test pins it.chat_send()still refuses a thread in an encrypted room. Its comment says the encrypted path has nowhere to put a relation, which is no longer so:extracan carry one, and mx.client lifts it to the envelope. Lifting the refusal is a separate change.Checked
test_matrix.R: 571 results.extra, and noextrawithout keys.m.new_contentand the fallback; without keys, neither has any.test_contract.R: 312 results, including the loopback's send, edit, refusals, and the other adapters' signatures.main's code the new tests fail 26 assertions intest_matrix.Rand 10 intest_contract.R. Against 124bf19, the 2 fallback assertions fail.test_matrix.Randtest_contract.R, the only files it touches: 571 and 312, 0 failed.R CMD check --as-cranon the built tarball at 124bf19: Status OK. It covers the S3 method signatures, which all takecontent. It ran without the suggestedtelegrampackage, which this machine lacks.R/is asrformatwrites it.The version bump follows as its own commit after review. #31 also bumps to 0.2.0.1, so whichever merges second takes the next number.