Add mx_send_event() and mx_set_state() generic senders#13
Merged
Conversation
mx_send hardcodes m.room.message and mx_react hardcodes m.reaction, with no way to send other event types. Add mx_send_event() (arbitrary room event, e.g. m.room.encrypted for E2EE) and mx_set_state() (arbitrary state event, e.g. m.room.encryption). Both thin PUTs mirroring mx_send. Needed by mx.client's end-to-end encryption transport.
TroyHernandez
added a commit
that referenced
this pull request
Jun 10, 2026
…ces (#14) * Add mx_get_state() and generic account-data get/set mx_get_state() is the read-side counterpart of mx_set_state() (e.g. check m.room.encryption before joining the send path); both it and mx_get_account_data() return NULL on M_NOT_FOUND rather than erroring. Account data stays generic (type + content) -- no DM-semantics helpers. * Add mx_send_media() with file/image/audio/video wrappers Generic upload-then-post: mx_upload() to the media repo, then an m.room.message with url + info (mimetype, size). Sugar wrappers fix the msgtype. Richer metadata (dimensions, duration) is caller-supplied via info -- no media-inspection dependencies. * Add profile get/set, mx_room_invite(), mx_redact(), mx_typing() mx_profile() reads displayname/avatar_url; mx_set_displayname() and mx_set_avatar_url() let a bot dress itself after mx_upload(). mx_room_invite() covers inviting into an existing room (creation-time invites already existed). mx_redact() is Matrix deletion, rounding out reactions. mx_typing() shows/clears the typing indicator while a slow reply generates. * Add mx_devices() and mx_delete_device() Listing is a plain GET. Deletion passes any user-interactive auth payload through verbatim and documents the 401-then-retry dance; mx.api deliberately does not automate the password exchange (that needs stored credentials, which is client-layer state). * README + NEWS for 0.3.0; bump version to 0.3.0 README: refresh the stale dev-version references (was still describing the pre-0.2.0 delta), extend the coverage table with the new endpoint families, and point the E2EE framing at mx.client as the stateful integration layer. NEWS: 0.3.0 entry covering the full batch, including mx_send_event()/mx_set_state() from #13 which never got an entry. * Media polish: msgtype auto-detect, public mx_guess_mime(), mx_media_config() mx_send_media(msgtype = NULL) now derives m.image/m.audio/m.video from the MIME family, so pointing it at a file just works. mx_guess_mime() is exported so callers don't maintain their own extension table. mx_media_config() asks the server for its upload cap (m.upload.size), v1 endpoint with legacy fallback. * Raise classed Matrix error conditions All HTTP failures now signal a condition classed c("mx_error_<ERRCODE>", "mx_error", "error"), carrying $errcode, $status, and the parsed $body, so code can react to specific failures (tryCatch(..., mx_error_M_UNKNOWN_TOKEN = relogin)) instead of grepling the message. Message text keeps the historical "Matrix error [CODE]: msg" shape, so string-matching callers keep working. mx_get_state() and mx_get_account_data() now catch by class. * Stream uploads from disk; fix mx_guess_mime() NA on unknown extension mx_upload() read the whole file into RAM before sending; switch to curl upload mode with a readfunction so multi-GB files stream from a connection (customrequest keeps the method POST). Verified live with an 8MB byte-identical round-trip. mx_guess_mime() returned NA instead of the documented octet-stream fallback on unknown extensions (named-vector miss is NA, not NULL, so %||% never fired) -- now load-bearing for msgtype auto-detection. * NEWS + README for the media/errors/streaming additions
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.
mx.api could only send
m.room.message(mx_send) andm.reaction(mx_react). E2EE needs to sendm.room.encryptedevents and setm.room.encryptionstate, so add two generic PUTs:mx_send_event(session, room_id, event_type, content)andmx_set_state(session, room_id, event_type, content, state_key). Both mirrormx_send. Consumed by mx.client's E2EE transport, validated live (full encrypted round-trip on Conduit).