Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e028519
Add helpers and visibility for the upcoming Event port
erikjohnston May 9, 2026
6135aac
Add Event pyclass to Rust
erikjohnston May 9, 2026
8e64822
Port EventBase hierarchy to the Rust Event class
erikjohnston May 9, 2026
1cc69f1
Fix tests after porting `EventBase` to Rust
erikjohnston May 12, 2026
5542419
Fix `EventProtocol` to work with the Rust class
erikjohnston May 13, 2026
a5081d1
Newsfile
erikjohnston May 15, 2026
e58c297
Correctly handle failing to parse event dict from DB
erikjohnston May 18, 2026
cdc09df
s/on-the-wire/over-the-wire
erikjohnston May 21, 2026
d7a8dc5
Comment which fields are mutable and immutable
erikjohnston May 21, 2026
d4801f7
Docstring for type_state_key_tuple
erikjohnston May 21, 2026
f5f7e7c
Convert get_room_id_for_optional_room_id into match
erikjohnston May 21, 2026
7115164
Update error for auth_event_ids
erikjohnston May 21, 2026
69c8d22
Ensure we don't have stray auth_events or event_id fields unexpectedl…
erikjohnston May 21, 2026
e82ebe1
Small refactor to ensure we call 'validate' for all formats
erikjohnston May 21, 2026
8e6e29c
Fix MAX_PDU_SIZE_BYTES
erikjohnston May 21, 2026
27e312d
Make JsonObject.object private
erikjohnston May 21, 2026
fc65b1d
Add room version to error
erikjohnston May 21, 2026
24e7f85
Rename to parsed_event
erikjohnston May 21, 2026
aae2de1
Update get_dict docstring
erikjohnston May 21, 2026
894d223
Mention where get_templated_pdu_json is used
erikjohnston May 21, 2026
1bbb033
Drop SimpleAuthPrevEvents
erikjohnston May 21, 2026
b99fd73
s/debug_assert/ensure
erikjohnston May 21, 2026
c9e9d76
Make MAX_DURATION a SynapseDuration
erikjohnston May 21, 2026
025f1a4
Fix tests
erikjohnston May 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/19701.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Port the python Event classes to Rust.
16 changes: 15 additions & 1 deletion rust/src/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,33 @@ fn duration_module(py: Python<'_>) -> PyResult<&Bound<'_, PyAny>> {
}

/// Mirrors the `synapse.util.duration.Duration` Python class.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct SynapseDuration {
microseconds: u64,
}

impl SynapseDuration {
/// For now we only need to create durations from milliseconds.
pub fn from_milliseconds(milliseconds: u64) -> Self {
pub const fn from_milliseconds(milliseconds: u64) -> Self {
Self {
microseconds: milliseconds * 1_000,
}
}
}

impl<'py> IntoPyObject<'py> for SynapseDuration {
type Target = PyAny;
type Output = Bound<'py, Self::Target>;
type Error = PyErr;

fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
let duration_module = duration_module(py)?;
let kwargs = [("microseconds", self.microseconds)].into_py_dict(py)?;
let duration_instance = duration_module.call_method("Duration", (), Some(&kwargs))?;
Ok(duration_instance.into_bound())
}
}

impl<'py> IntoPyObject<'py> for &SynapseDuration {
type Target = PyAny;
type Output = Bound<'py, Self::Target>;
Expand Down
137 changes: 137 additions & 0 deletions rust/src/events/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
//! Matrix Events
//!
//! Contains types and utilities for working with Matrix events.

/// Maximum size of a PDU
pub const MAX_PDU_SIZE_BYTES: usize = 65_536;

/// Event Types
pub mod event_type {
/// Event type: m.room.member
pub const M_ROOM_MEMBER: &str = "m.room.member";
/// Event type: m.room.create
pub const M_ROOM_CREATE: &str = "m.room.create";
/// Event type: m.room.join_rules
pub const M_ROOM_JOIN_RULES: &str = "m.room.join_rules";
/// Event type: m.room.power_levels
pub const M_ROOM_POWER_LEVELS: &str = "m.room.power_levels";
/// Event type: m.room.aliases
pub const M_ROOM_ALIASES: &str = "m.room.aliases";
/// Event type: m.room.history_visibility
pub const M_ROOM_HISTORY_VISIBILITY: &str = "m.room.history_visibility";
/// Event type: m.room.redaction
pub const M_ROOM_REDACTION: &str = "m.room.redaction";
}

/// Event Fields
pub mod event_field {
/// Event field: auth_events
pub const AUTH_EVENTS: &str = "auth_events";
/// Event field: content
pub const CONTENT: &str = "content";
/// Event field: depth
pub const DEPTH: &str = "depth";
/// Event field: hashes
pub const HASHES: &str = "hashes";
/// Event field: origin_server_ts
pub const ORIGIN_SERVER_TS: &str = "origin_server_ts";
/// Event field: prev_events
pub const PREV_EVENTS: &str = "prev_events";
/// Event field: room_id
pub const ROOM_ID: &str = "room_id";
/// Event field: sender
pub const SENDER: &str = "sender";
/// Event field: signatures
pub const SIGNATURES: &str = "signatures";
/// Event field: state_key
pub const STATE_KEY: &str = "state_key";
/// Event field: type
pub const TYPE: &str = "type";
/// Event field: unsigned
pub const UNSIGNED: &str = "unsigned";
/// Event field: event_id
pub const EVENT_ID: &str = "event_id";
/// Event field: origin
pub const ORIGIN: &str = "origin";
/// Event field: prev_state
pub const PREV_STATE: &str = "prev_state";
/// Event field: membership
pub const MEMBERSHIP: &str = "membership";
/// Event field: replaces_state
pub const REPLACES_STATE: &str = "replaces_state";
}

pub mod unsigned_field {
/// Unsigned field: age
pub const AGE: &str = "age";
/// Unsigned field: age_ts
pub const AGE_TS: &str = "age_ts";
/// Unsigned field: redacted_because
pub const REDACTED_BECAUSE: &str = "redacted_because";
}

/// Membership Event Fields
pub mod membership_field {
/// Membership event field: membership
pub const MEMBERSHIP: &str = "membership";
/// Membership event field: join_authorised_via_users_server
pub const JOIN_AUTHORISED_VIA_USERS_SERVER: &str = "join_authorised_via_users_server";
/// Membership event field: third_party_invite
pub const THIRD_PARTY_INVITE: &str = "third_party_invite";
/// Membership event field: signed
pub const SIGNED: &str = "signed";
}

/// Create Event Fields
pub mod create_field {
/// Create event field: creator
pub const CREATOR: &str = "creator";
}

/// Join Rules Event Fields
pub mod join_rules_field {
/// Join Rules event field: join_rule
pub const JOIN_RULE: &str = "join_rule";
/// Join Rules event field: allow
pub const ALLOW: &str = "allow";
}

/// Power Levels Event Fields
pub mod power_levels_field {
/// Power Levels event field: users
pub const USERS: &str = "users";
/// Power Levels event field: users_default
pub const USERS_DEFAULT: &str = "users_default";
/// Power Levels event field: events
pub const EVENTS: &str = "events";
/// Power Levels event field: events_default
pub const EVENTS_DEFAULT: &str = "events_default";
/// Power Levels event field: state_default
pub const STATE_DEFAULT: &str = "state_default";
/// Power Levels event field: ban
pub const BAN: &str = "ban";
/// Power Levels event field: kick
pub const KICK: &str = "kick";
/// Power Levels event field: redact
pub const REDACT: &str = "redact";
/// Power Levels event field: invite
pub const INVITE: &str = "invite";
}

/// Aliases Event Fields
pub mod aliases_field {
/// Aliases event field: aliases
pub const ALIASES: &str = "aliases";
}

/// History Visibility Event Fields
pub mod history_visibility_field {
/// History Visibility event field: history_visibility
pub const HISTORY_VISIBILITY: &str = "history_visibility";
}

/// Redaction Event Fields
pub mod redaction_field {
/// Redacts event field: redacts
pub const REDACTS: &str = "redacts";
}
Loading
Loading