matrix_sdk_test::event_factory

Struct EventFactory

Source
pub struct EventFactory { /* private fields */ }

Implementations§

Source§

impl EventFactory

Source

pub fn new() -> Self

Source

pub fn room(self, room_id: &RoomId) -> Self

Source

pub fn sender(self, sender: &UserId) -> Self

Source

pub fn event<E: EventContent>(&self, content: E) -> EventBuilder<E>

Create an event from any event content.

Source

pub fn text_msg( &self, content: impl Into<String>, ) -> EventBuilder<RoomMessageEventContent>

Create a new plain text m.room.message.

Source

pub fn member(&self, member: &UserId) -> EventBuilder<RoomMemberEventContent>

Create a new m.room.member event for the given member.

The given member will be used as the sender as well as the state_key of the m.room.member event, unless the sender was already using EventFactory::sender(), in that case only the state key will be set to the given member.

The membership field of the content is set to MembershipState::Join.

use matrix_sdk_test::event_factory::EventFactory;
use ruma::{
    events::{
        room::member::{MembershipState, RoomMemberEventContent},
        SyncStateEvent,
    },
    room_id,
    serde::Raw,
    user_id,
};

let factory = EventFactory::new().room(room_id!("!test:localhost"));

let event: Raw<SyncStateEvent<RoomMemberEventContent>> = factory
    .member(user_id!("@alice:localhost"))
    .display_name("Alice")
    .into_raw();
Source

pub fn member_hints( &self, service_members: BTreeSet<OwnedUserId>, ) -> EventBuilder<MemberHintsEventContent>

Create a new m.member_hints event with the given service members.

use std::collections::BTreeSet;

use matrix_sdk_test::event_factory::EventFactory;
use ruma::{
    events::{member_hints::MemberHintsEventContent, SyncStateEvent},
    owned_user_id, room_id,
    serde::Raw,
    user_id,
};

let factory = EventFactory::new().room(room_id!("!test:localhost"));

let event: Raw<SyncStateEvent<MemberHintsEventContent>> = factory
    .member_hints(BTreeSet::from([owned_user_id!("@alice:localhost")]))
    .sender(user_id!("@alice:localhost"))
    .into_raw();
Source

pub fn text_html( &self, plain: impl Into<String>, html: impl Into<String>, ) -> EventBuilder<RoomMessageEventContent>

Create a new plain/html m.room.message.

Source

pub fn notice( &self, content: impl Into<String>, ) -> EventBuilder<RoomMessageEventContent>

Create a new plain notice m.room.message.

Source

pub fn reaction( &self, event_id: &EventId, annotation: String, ) -> EventBuilder<ReactionEventContent>

Add a reaction to an event.

Source

pub fn redaction( &self, event_id: &EventId, ) -> EventBuilder<RoomRedactionEventContent>

Create a redaction for the given event id.

Source

pub fn poll_start( &self, content: impl Into<String>, poll_question: impl Into<String>, answers: Vec<impl Into<String>>, ) -> EventBuilder<UnstablePollStartEventContent>

Create a poll start event given a text, the question and the possible answers.

Source

pub fn poll_edit( &self, edited_event_id: &EventId, poll_question: impl Into<String>, answers: Vec<impl Into<String>>, ) -> EventBuilder<ReplacementUnstablePollStartEventContent>

Create a poll edit event given the new question and possible answers.

Source

pub fn poll_response( &self, answer_id: impl Into<String>, poll_start_id: &EventId, ) -> EventBuilder<PollResponseEventContent>

Create a poll response with the given answer id and the associated poll start event id.

Source

pub fn poll_end( &self, content: impl Into<String>, poll_start_id: &EventId, ) -> EventBuilder<PollEndEventContent>

Create a poll response with the given text and the associated poll start event id.

Source

pub fn image( &self, filename: String, url: OwnedMxcUri, ) -> EventBuilder<RoomMessageEventContent>

Creates a plain (unencrypted) image event content referencing the given MXC ID.

Source

pub fn set_next_ts(&self, value: u64)

Set the next server timestamp.

Timestamps will continue to increase by 1 (millisecond) from that value.

Trait Implementations§

Source§

impl Debug for EventFactory

Source§

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

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

impl Default for EventFactory

Source§

fn default() -> EventFactory

Returns the “default value” for a type. 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
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

Source§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
Source§

fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
Source§

fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<>
Source§

fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
Source§

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

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

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

Source§

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.
Source§

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.

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

§

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
Source§

impl<T> AsyncTraitDeps for T

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> SendOutsideWasm for T
where T: Send,

Source§

impl<T> SyncOutsideWasm for T
where T: Sync,