pub struct EventFactory { /* private fields */ }
Implementations§
Source§impl EventFactory
impl EventFactory
pub fn new() -> Self
pub fn room(self, room_id: &RoomId) -> Self
pub fn sender(self, sender: &UserId) -> Self
Sourcepub fn event<E: StaticEventContent<IsPrefix = False>>(
&self,
content: E,
) -> EventBuilder<E>
pub fn event<E: StaticEventContent<IsPrefix = False>>( &self, content: E, ) -> EventBuilder<E>
Create an event from any event content.
Sourcepub fn text_msg(
&self,
content: impl Into<String>,
) -> EventBuilder<RoomMessageEventContent>
pub fn text_msg( &self, content: impl Into<String>, ) -> EventBuilder<RoomMessageEventContent>
Create a new plain text m.room.message
.
Sourcepub fn emote(
&self,
content: impl Into<String>,
) -> EventBuilder<RoomMessageEventContent>
pub fn emote( &self, content: impl Into<String>, ) -> EventBuilder<RoomMessageEventContent>
Create a new plain emote m.room.message
.
Sourcepub fn member(&self, member: &UserId) -> EventBuilder<RoomMemberEventContent>
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::{
SyncStateEvent,
room::member::{MembershipState, RoomMemberEventContent},
},
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();
Sourcepub fn room_tombstone(
&self,
body: impl Into<String>,
replacement: &RoomId,
) -> EventBuilder<RoomTombstoneEventContent>
pub fn room_tombstone( &self, body: impl Into<String>, replacement: &RoomId, ) -> EventBuilder<RoomTombstoneEventContent>
Create a tombstone state event for the room.
Sourcepub fn room_topic(
&self,
topic: impl Into<String>,
) -> EventBuilder<RoomTopicEventContent>
pub fn room_topic( &self, topic: impl Into<String>, ) -> EventBuilder<RoomTopicEventContent>
Create a state event for the topic.
Sourcepub fn room_name(
&self,
name: impl Into<String>,
) -> EventBuilder<RoomNameEventContent>
pub fn room_name( &self, name: impl Into<String>, ) -> EventBuilder<RoomNameEventContent>
Create a state event for the room name.
Sourcepub fn room_avatar(&self) -> EventBuilder<RoomAvatarEventContent>
pub fn room_avatar(&self) -> EventBuilder<RoomAvatarEventContent>
Create an empty state event for the room avatar.
Sourcepub fn member_hints(
&self,
service_members: BTreeSet<OwnedUserId>,
) -> EventBuilder<MemberHintsEventContent>
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::{SyncStateEvent, member_hints::MemberHintsEventContent},
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();
Sourcepub fn text_html(
&self,
plain: impl Into<String>,
html: impl Into<String>,
) -> EventBuilder<RoomMessageEventContent>
pub fn text_html( &self, plain: impl Into<String>, html: impl Into<String>, ) -> EventBuilder<RoomMessageEventContent>
Create a new plain/html m.room.message
.
Sourcepub fn notice(
&self,
content: impl Into<String>,
) -> EventBuilder<RoomMessageEventContent>
pub fn notice( &self, content: impl Into<String>, ) -> EventBuilder<RoomMessageEventContent>
Create a new plain notice m.room.message
.
Sourcepub fn reaction(
&self,
event_id: &EventId,
annotation: impl Into<String>,
) -> EventBuilder<ReactionEventContent>
pub fn reaction( &self, event_id: &EventId, annotation: impl Into<String>, ) -> EventBuilder<ReactionEventContent>
Add a reaction to an event.
Sourcepub fn redaction(
&self,
event_id: &EventId,
) -> EventBuilder<RoomRedactionEventContent>
pub fn redaction( &self, event_id: &EventId, ) -> EventBuilder<RoomRedactionEventContent>
Create a live redaction for the given event id.
Note: this is not a redacted event, but a redaction event, that will cause another event to be redacted.
Sourcepub fn redacted<T: StaticEventContent<IsPrefix = False> + RedactedMessageLikeEventContent>(
&self,
redacter: &UserId,
content: T,
) -> EventBuilder<T>
pub fn redacted<T: StaticEventContent<IsPrefix = False> + RedactedMessageLikeEventContent>( &self, redacter: &UserId, content: T, ) -> EventBuilder<T>
Create a redacted event, with extra information in the unsigned section about the redaction itself.
Sourcepub fn redacted_state<T: StaticEventContent<IsPrefix = False> + RedactedStateEventContent>(
&self,
redacter: &UserId,
state_key: impl Into<String>,
content: T,
) -> EventBuilder<T>
pub fn redacted_state<T: StaticEventContent<IsPrefix = False> + RedactedStateEventContent>( &self, redacter: &UserId, state_key: impl Into<String>, content: T, ) -> EventBuilder<T>
Create a redacted state event, with extra information in the unsigned section about the redaction itself.
Sourcepub fn poll_start(
&self,
content: impl Into<String>,
poll_question: impl Into<String>,
answers: Vec<impl Into<String>>,
) -> EventBuilder<UnstablePollStartEventContent>
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.
Sourcepub fn poll_edit(
&self,
edited_event_id: &EventId,
poll_question: impl Into<String>,
answers: Vec<impl Into<String>>,
) -> EventBuilder<ReplacementUnstablePollStartEventContent>
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.
Sourcepub fn poll_response(
&self,
answers: Vec<impl Into<String>>,
poll_start_id: &EventId,
) -> EventBuilder<UnstablePollResponseEventContent>
pub fn poll_response( &self, answers: Vec<impl Into<String>>, poll_start_id: &EventId, ) -> EventBuilder<UnstablePollResponseEventContent>
Create a poll response with the given answer id and the associated poll start event id.
Sourcepub fn poll_end(
&self,
content: impl Into<String>,
poll_start_id: &EventId,
) -> EventBuilder<UnstablePollEndEventContent>
pub fn poll_end( &self, content: impl Into<String>, poll_start_id: &EventId, ) -> EventBuilder<UnstablePollEndEventContent>
Create a poll response with the given text and the associated poll start event id.
Sourcepub fn image(
&self,
filename: String,
url: OwnedMxcUri,
) -> EventBuilder<RoomMessageEventContent>
pub fn image( &self, filename: String, url: OwnedMxcUri, ) -> EventBuilder<RoomMessageEventContent>
Creates a plain (unencrypted) image event content referencing the given MXC ID.
Sourcepub fn gallery(
&self,
body: String,
filename: String,
url: OwnedMxcUri,
) -> EventBuilder<RoomMessageEventContent>
pub fn gallery( &self, body: String, filename: String, url: OwnedMxcUri, ) -> EventBuilder<RoomMessageEventContent>
Create a gallery event containing a single plain (unencrypted) image referencing the given MXC ID.
Sourcepub fn typing(&self, user_ids: Vec<&UserId>) -> EventBuilder<TypingEventContent>
pub fn typing(&self, user_ids: Vec<&UserId>) -> EventBuilder<TypingEventContent>
Create a typing notification event.
Sourcepub fn read_receipts(&self) -> ReadReceiptBuilder<'_>
pub fn read_receipts(&self) -> ReadReceiptBuilder<'_>
Create a read receipt event.
Sourcepub fn create(
&self,
creator_user_id: &UserId,
room_version: RoomVersionId,
) -> EventBuilder<RoomCreateEventContent>
pub fn create( &self, creator_user_id: &UserId, room_version: RoomVersionId, ) -> EventBuilder<RoomCreateEventContent>
Create a new m.room.create
event.
Sourcepub fn power_levels(
&self,
map: &mut BTreeMap<OwnedUserId, Int>,
) -> EventBuilder<RoomPowerLevelsEventContent>
pub fn power_levels( &self, map: &mut BTreeMap<OwnedUserId, Int>, ) -> EventBuilder<RoomPowerLevelsEventContent>
Create a new m.room.power_levels
event.
Sourcepub fn server_acl(
&self,
allow_ip_literals: bool,
allow: Vec<String>,
deny: Vec<String>,
) -> EventBuilder<RoomServerAclEventContent>
pub fn server_acl( &self, allow_ip_literals: bool, allow: Vec<String>, deny: Vec<String>, ) -> EventBuilder<RoomServerAclEventContent>
Create a new m.room.server_acl
event.
Sourcepub fn canonical_alias(
&self,
alias: Option<OwnedRoomAliasId>,
alt_aliases: Vec<OwnedRoomAliasId>,
) -> EventBuilder<RoomCanonicalAliasEventContent>
pub fn canonical_alias( &self, alias: Option<OwnedRoomAliasId>, alt_aliases: Vec<OwnedRoomAliasId>, ) -> EventBuilder<RoomCanonicalAliasEventContent>
Create a new m.room.canonical_alias
event.
Sourcepub fn beacon(
&self,
beacon_info_event_id: OwnedEventId,
latitude: f64,
longitude: f64,
uncertainty: u32,
ts: Option<MilliSecondsSinceUnixEpoch>,
) -> EventBuilder<BeaconEventContent>
pub fn beacon( &self, beacon_info_event_id: OwnedEventId, latitude: f64, longitude: f64, uncertainty: u32, ts: Option<MilliSecondsSinceUnixEpoch>, ) -> EventBuilder<BeaconEventContent>
Create a new org.matrix.msc3672.beacon
event.
use matrix_sdk_test::event_factory::EventFactory;
use ruma::{
MilliSecondsSinceUnixEpoch,
events::{MessageLikeEvent, beacon::BeaconEventContent},
owned_event_id, room_id,
serde::Raw,
user_id,
};
let factory = EventFactory::new().room(room_id!("!test:localhost"));
let event: Raw<MessageLikeEvent<BeaconEventContent>> = factory
.beacon(
owned_event_id!("$123456789abc:localhost"),
10.1,
15.2,
5,
Some(MilliSecondsSinceUnixEpoch(1000u32.into())),
)
.sender(user_id!("@alice:localhost"))
.into_raw();
Sourcepub fn sticker(
&self,
body: impl Into<String>,
info: ImageInfo,
url: OwnedMxcUri,
) -> EventBuilder<StickerEventContent>
pub fn sticker( &self, body: impl Into<String>, info: ImageInfo, url: OwnedMxcUri, ) -> EventBuilder<StickerEventContent>
Create a new m.sticker
event.
Sourcepub fn call_invite(
&self,
call_id: OwnedVoipId,
lifetime: UInt,
offer: SessionDescription,
version: VoipVersionId,
) -> EventBuilder<CallInviteEventContent>
pub fn call_invite( &self, call_id: OwnedVoipId, lifetime: UInt, offer: SessionDescription, version: VoipVersionId, ) -> EventBuilder<CallInviteEventContent>
Create a new m.call.invite
event.
Sourcepub fn call_notify(
&self,
call_id: String,
application: ApplicationType,
notify_type: NotifyType,
mentions: Mentions,
) -> EventBuilder<CallNotifyEventContent>
pub fn call_notify( &self, call_id: String, application: ApplicationType, notify_type: NotifyType, mentions: Mentions, ) -> EventBuilder<CallNotifyEventContent>
Create a new m.call.notify
event.
Sourcepub fn direct(&self) -> EventBuilder<DirectEventContent>
pub fn direct(&self) -> EventBuilder<DirectEventContent>
Create a new m.direct
global account data event.
Sourcepub fn ignored_user_list(
&self,
users: impl IntoIterator<Item = OwnedUserId>,
) -> EventBuilder<IgnoredUserListEventContent>
pub fn ignored_user_list( &self, users: impl IntoIterator<Item = OwnedUserId>, ) -> EventBuilder<IgnoredUserListEventContent>
Create a new m.ignored_user_list
global account data event.
Sourcepub fn push_rules(&self, rules: Ruleset) -> EventBuilder<PushRulesEventContent>
pub fn push_rules(&self, rules: Ruleset) -> EventBuilder<PushRulesEventContent>
Create a new m.push_rules
global account data event.
Sourcepub fn space_child(
&self,
parent: OwnedRoomId,
child: OwnedRoomId,
) -> EventBuilder<SpaceChildEventContent>
pub fn space_child( &self, parent: OwnedRoomId, child: OwnedRoomId, ) -> EventBuilder<SpaceChildEventContent>
Create a new m.space.child
state event.
Sourcepub fn space_parent(
&self,
parent: OwnedRoomId,
child: OwnedRoomId,
) -> EventBuilder<SpaceParentEventContent>
pub fn space_parent( &self, parent: OwnedRoomId, child: OwnedRoomId, ) -> EventBuilder<SpaceParentEventContent>
Create a new m.space.parent
state event.
Sourcepub fn set_next_ts(&self, value: u64)
pub fn set_next_ts(&self, value: u64)
Set the next server timestamp.
Timestamps will continue to increase by 1 (millisecond) from that value.