Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions matrix_sdk/examples/autojoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tokio::time::{sleep, Duration};
use matrix_sdk::{
self, async_trait,
events::{room::member::MemberEventContent, StrippedStateEvent},
Client, ClientConfig, EventHandler, Room, RoomType, SyncSettings,
room, Client, ClientConfig, EventHandler, Room, SyncSettings,
};
use url::Url;

Expand All @@ -30,11 +30,11 @@ impl EventHandler for AutoJoinBot {
return;
}

if room.room_type() == RoomType::Invited {
if let Some(room) = room::Invited::new(self.client.clone(), room) {
println!("Autojoining room {}", room.room_id());
let mut delay = 2;

while let Err(err) = self.client.join_room_by_id(room.room_id()).await {
while let Err(err) = room.accept_invitation().await {
// retry autojoin due to synapse sending invites, before the
// invited user can join for more information see
// https://github.com/matrix-org/synapse/issues/4345
Expand Down
14 changes: 6 additions & 8 deletions matrix_sdk/examples/command_bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use matrix_sdk::{
room::message::{MessageEventContent, MessageType, TextMessageEventContent},
AnyMessageEventContent, SyncMessageEvent,
},
Client, ClientConfig, EventHandler, Room, RoomType, SyncSettings,
room::Joined,
Client, ClientConfig, EventHandler, Room, SyncSettings,
};
use url::Url;

Expand All @@ -25,7 +26,7 @@ impl CommandBot {
#[async_trait]
impl EventHandler for CommandBot {
async fn on_room_message(&self, room: Room, event: &SyncMessageEvent<MessageEventContent>) {
if room.room_type() == RoomType::Joined {
if let Some(room) = Joined::new(self.client.clone(), room) {
let msg_body = if let SyncMessageEvent {
content:
MessageEventContent {
Expand All @@ -47,12 +48,9 @@ impl EventHandler for CommandBot {

println!("sending");

self.client
// send our message to the room we found the "!party" command in
// the last parameter is an optional Uuid which we don't care about.
.room_send(room.room_id(), content, None)
.await
.unwrap();
// send our message to the room we found the "!party" command in
// the last parameter is an optional Uuid which we don't care about.
room.send(content, None).await.unwrap();

println!("message sent");
}
Expand Down
14 changes: 4 additions & 10 deletions matrix_sdk/examples/image_bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use matrix_sdk::{
room::message::{MessageEventContent, MessageType, TextMessageEventContent},
SyncMessageEvent,
},
Client, EventHandler, Room, RoomType, SyncSettings,
room::Joined,
Client, EventHandler, Room, SyncSettings,
};
use url::Url;

Expand All @@ -33,7 +34,7 @@ impl ImageBot {
#[async_trait]
impl EventHandler for ImageBot {
async fn on_room_message(&self, room: Room, event: &SyncMessageEvent<MessageEventContent>) {
if room.room_type() == RoomType::Joined {
if let Some(room) = Joined::new(self.client.clone(), room) {
let msg_body = if let SyncMessageEvent {
content:
MessageEventContent {
Expand All @@ -52,14 +53,7 @@ impl EventHandler for ImageBot {
println!("sending image");
let mut image = self.image.lock().await;

self.client
.room_send_attachment(
room.room_id(),
"cat",
&mime::IMAGE_JPEG,
&mut *image,
None,
)
room.send_attachment("cat", &mime::IMAGE_JPEG, &mut *image, None)
.await
.unwrap();

Expand Down
Loading