Skip to content

Add mx_send_event() and mx_set_state() generic senders#13

Merged
TroyHernandez merged 1 commit into
mainfrom
feature/generic-send-event
Jun 10, 2026
Merged

Add mx_send_event() and mx_set_state() generic senders#13
TroyHernandez merged 1 commit into
mainfrom
feature/generic-send-event

Conversation

@TroyHernandez

Copy link
Copy Markdown
Contributor

mx.api could only send m.room.message (mx_send) and m.reaction (mx_react). E2EE needs to send m.room.encrypted events and set m.room.encryption state, so add two generic PUTs: mx_send_event(session, room_id, event_type, content) and mx_set_state(session, room_id, event_type, content, state_key). Both mirror mx_send. Consumed by mx.client's E2EE transport, validated live (full encrypted round-trip on Conduit).

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 TroyHernandez merged commit 68db660 into main Jun 10, 2026
5 of 6 checks passed
@TroyHernandez TroyHernandez deleted the feature/generic-send-event branch June 10, 2026 06:37
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
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