pub struct MatrixLink { /* private fields */ }Expand description
MatrixLink represents a connection to a Matrix server. It wraps a matrix_sdk Client and provides some convenience functions for working with it.
All of the state is held in an Arc so the MatrixLink can be cloned freely.
Implementations§
Source§impl MatrixLink
impl MatrixLink
pub fn user_id(&self) -> &OwnedUserId
pub fn client(&self) -> Client
Sourcepub fn messaging(&self) -> Messaging
pub fn messaging(&self) -> Messaging
Examples found in repository?
examples/quick_start.rs (line 77)
70async fn register_event_handlers(matrix_link: MatrixLink) {
71 let rooms = matrix_link.rooms();
72
73 // We auto-accept all invitations
74 rooms.on_invitation(|_event, _room| async move { Ok(InvitationDecision::Join) });
75
76 // We send an introduction to all rooms we join
77 let messaging = matrix_link.messaging();
78 rooms.on_joined(|_event, room| async move {
79 let _ = messaging
80 .send_text_markdown(&room, "Hello!".to_owned(), MessageResponseType::InRoom)
81 .await
82 .expect("Failed to send message");
83
84 Ok(())
85 });
86
87 // We listen for reactions to messages and send a reply to the original message that received the reaction
88 let messaging = matrix_link.messaging();
89 let reacting = matrix_link.reacting();
90 reacting.on_actionable_reaction(|event, room, reaction_event_content| async move {
91 let response_text = if reaction_event_content.relates_to.key == "👍️" {
92 format!("{} reacted to this message with thumbs up!", event.sender())
93 } else {
94 format!(
95 "{} reacted to this message with an unknown-to-me reaction ({}).",
96 event.sender(),
97 reaction_event_content.relates_to.key,
98 )
99 };
100
101 let response_type =
102 MessageResponseType::Reply(reaction_event_content.relates_to.event_id.clone());
103
104 let _ = messaging
105 .send_notice_markdown(&room, response_text, response_type)
106 .await
107 .expect("Failed to send message");
108
109 Ok(())
110 });
111}pub fn media(&self) -> Media
Sourcepub fn reacting(&self) -> Reacting
pub fn reacting(&self) -> Reacting
Examples found in repository?
examples/quick_start.rs (line 89)
70async fn register_event_handlers(matrix_link: MatrixLink) {
71 let rooms = matrix_link.rooms();
72
73 // We auto-accept all invitations
74 rooms.on_invitation(|_event, _room| async move { Ok(InvitationDecision::Join) });
75
76 // We send an introduction to all rooms we join
77 let messaging = matrix_link.messaging();
78 rooms.on_joined(|_event, room| async move {
79 let _ = messaging
80 .send_text_markdown(&room, "Hello!".to_owned(), MessageResponseType::InRoom)
81 .await
82 .expect("Failed to send message");
83
84 Ok(())
85 });
86
87 // We listen for reactions to messages and send a reply to the original message that received the reaction
88 let messaging = matrix_link.messaging();
89 let reacting = matrix_link.reacting();
90 reacting.on_actionable_reaction(|event, room, reaction_event_content| async move {
91 let response_text = if reaction_event_content.relates_to.key == "👍️" {
92 format!("{} reacted to this message with thumbs up!", event.sender())
93 } else {
94 format!(
95 "{} reacted to this message with an unknown-to-me reaction ({}).",
96 event.sender(),
97 reaction_event_content.relates_to.key,
98 )
99 };
100
101 let response_type =
102 MessageResponseType::Reply(reaction_event_content.relates_to.event_id.clone());
103
104 let _ = messaging
105 .send_notice_markdown(&room, response_text, response_type)
106 .await
107 .expect("Failed to send message");
108
109 Ok(())
110 });
111}Sourcepub fn rooms(&self) -> Rooms
pub fn rooms(&self) -> Rooms
Examples found in repository?
examples/quick_start.rs (line 71)
70async fn register_event_handlers(matrix_link: MatrixLink) {
71 let rooms = matrix_link.rooms();
72
73 // We auto-accept all invitations
74 rooms.on_invitation(|_event, _room| async move { Ok(InvitationDecision::Join) });
75
76 // We send an introduction to all rooms we join
77 let messaging = matrix_link.messaging();
78 rooms.on_joined(|_event, room| async move {
79 let _ = messaging
80 .send_text_markdown(&room, "Hello!".to_owned(), MessageResponseType::InRoom)
81 .await
82 .expect("Failed to send message");
83
84 Ok(())
85 });
86
87 // We listen for reactions to messages and send a reply to the original message that received the reaction
88 let messaging = matrix_link.messaging();
89 let reacting = matrix_link.reacting();
90 reacting.on_actionable_reaction(|event, room, reaction_event_content| async move {
91 let response_text = if reaction_event_content.relates_to.key == "👍️" {
92 format!("{} reacted to this message with thumbs up!", event.sender())
93 } else {
94 format!(
95 "{} reacted to this message with an unknown-to-me reaction ({}).",
96 event.sender(),
97 reaction_event_content.relates_to.key,
98 )
99 };
100
101 let response_type =
102 MessageResponseType::Reply(reaction_event_content.relates_to.event_id.clone());
103
104 let _ = messaging
105 .send_notice_markdown(&room, response_text, response_type)
106 .await
107 .expect("Failed to send message");
108
109 Ok(())
110 });
111}pub fn threads(&self) -> Threads
Sourcepub async fn start(&self) -> Result<(), SyncError>
pub async fn start(&self) -> Result<(), SyncError>
Starts the client (listening for events, etc.)
Examples found in repository?
examples/quick_start.rs (line 32)
25async fn main() {
26 let matrix_link = create_matrix_link().await;
27
28 // matrix_link can be cloned freely
29 register_event_handlers(matrix_link.clone()).await;
30
31 matrix_link
32 .start()
33 .await
34 .expect("Failed to start MatrixLink");
35
36 println!("Done");
37}Trait Implementations§
Source§impl Clone for MatrixLink
impl Clone for MatrixLink
Source§fn clone(&self) -> MatrixLink
fn clone(&self) -> MatrixLink
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for MatrixLink
impl !RefUnwindSafe for MatrixLink
impl Send for MatrixLink
impl Sync for MatrixLink
impl Unpin for MatrixLink
impl UnsafeUnpin for MatrixLink
impl !UnwindSafe for MatrixLink
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DropFlavorWrapper<T> for T
impl<T> DropFlavorWrapper<T> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more