Skip to main content

Contextualized

Struct Contextualized 

Source
pub struct Contextualized {
    pub(crate) draft: Draft,
    pub(crate) depth: u64,
    pub(crate) room_version: KnownRoomVersionId,
    pub(crate) auth_events: EventRefs,
    pub(crate) prev_events: EventRefs,
    pub(crate) prev_state: Option<EventRefs>,
    pub(crate) membership: Option<MembershipState>,
    pub(crate) origin: Option<OwnedServerName>,
    pub(crate) origin_server_ts: MilliSecondsSinceUnixEpoch,
    pub(crate) event_id: OwnedEventId,
    pub(crate) room_id: OwnedRoomId,
    pub(crate) hashes: EventHash,
}
Expand description

State representing an event contextualized in the room DAG.

A contextualized event has been placed in the context of the room’s directed acyclic graph (DAG) by adding auth_events and prev_events references, along with the origin_server_ts and room version rules.

This state does not guarantee authorization - that check happens during verification via super::RoomEvent<Signed>::verify().

Fields§

§draft: Draft

The draft event data

§depth: u64

The depth of the event

§room_version: KnownRoomVersionId

Room version for the event

§auth_events: EventRefs

The auth events

§prev_events: EventRefs

The previous events

§prev_state: Option<EventRefs>

The previous state field.

Not externally visible outside of the crate, but used by some room versions for nothing

§membership: Option<MembershipState>

The membership field.

Not externally visible outside of the crate, but used by some room versions for nothing

§origin: Option<OwnedServerName>

The origin field.

Not externally visible outside of NLE, but used by some room versions for nothing

§origin_server_ts: MilliSecondsSinceUnixEpoch

The origin server timestamp

§event_id: OwnedEventId

The event ID

§room_id: OwnedRoomId

The room ID

§hashes: EventHash

The content hashes

Implementations§

Source§

impl Contextualized

Source

pub(crate) fn new( draft: Draft, depth: u64, room_version: KnownRoomVersionId, auth_events: EventRefs, prev_events: EventRefs, prev_state: Option<EventRefs>, membership: Option<MembershipState>, origin: Option<OwnedServerName>, origin_server_ts: MilliSecondsSinceUnixEpoch, event_id: Option<OwnedEventId>, room_id: Option<OwnedRoomId>, hashes: Option<EventHash>, ) -> Result<Self, EventContextualizationError>

Contextualize an event

Can optionally be provided an event ID. If none is provided, one will always be generated, also for room versions 1 and 2.

Source

pub(crate) fn from_signed_for_resign( signed: Signed, ) -> Result<Self, SigningError>

Recovers the Contextualized event from a Signed one for re-signing, discarding the existing signatures and hashes.

Only m.room.member events are supported, since re-signing from an already-signed state is currently only performed on member events. Room-create events are rejected here rather than special-cased.

The content was already validated when the Signed event was built, so the inner Contextualized is reused as-is without re-validation.

§Errors

Returns SigningError::InvalidContent if signed’s event type is not m.room.member.

Source

fn build_minimal_event_object(&self) -> Map<String, Value>

Builds the minimal event object for signing and hashing.

§Panics

Panics if a non-create event has no room ID.

Source

pub(crate) fn build_canonical_event_object( &self, ) -> Result<CanonicalJsonObject, SigningError>

Builds the canonical event object for signing and hashing.

§Errors

Returns a SigningError if JSON canonicalization fails.

Source

fn generate_hashes(&self) -> Result<EventHash, EventIdGenerationError>

Generate the content hashes of the object

See here https://spec.matrix.org/latest/server-server-api/#calculating-the-content-hash-for-an-event

§Errors

Returns an EventIdGenerationError if the event cannot be canonicalized or hashed, or if a room version 1 event has no server name.

Source

fn generate_event_id( &self, server_name: Option<&ServerName>, ) -> Result<OwnedEventId, EventIdGenerationError>

Generates an event ID matching the room version.

§Errors

Returns an EventIdGenerationError if the event cannot be canonicalized or hashed, or if a room version 1 event has no server name.

Trait Implementations§

Source§

impl Clone for Contextualized

Source§

fn clone(&self) -> Contextualized

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Contextualized

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Contextualized

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Contextualized

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> DropFlavorWrapper<T> for T

§

type Flavor = MayDrop

The DropFlavor that [wrap]s T into Self
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

§

const WITNESS: W = W::MAKE

A constant of the type witness
§

impl<T> Identity for T
where T: ?Sized,

§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> JsonCastable<CanonicalJsonValue> for T

§

impl<T> JsonCastable<Value> for T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more