Skip to content

Commit 807835a

Browse files
committed
hello-world: Support room aliases and room IDs
We also use the proper endpoint to deal with aliases, since it is easier for the homeserver to find a room by alias rather than ID.
1 parent 76f87c3 commit 807835a

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

hello_world/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
A simple example to demonstrate `ruma-client` functionality. Sends "Hello
2-
World!" to the given room.
1+
A simple example to demonstrate `ruma-client` functionality. Joins the given
2+
room and sends "Hello World!".
33

44
# Usage
55

hello_world/src/main.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::{env, process::exit};
22

33
use ruma::{
4-
OwnedRoomAliasId, TransactionId,
5-
api::client::{alias::get_alias, membership::join_room_by_id, message::send_message_event},
4+
OwnedRoomOrAliasId, TransactionId,
5+
api::client::{membership::join_room_by_id_or_alias, message::send_message_event},
66
events::room::message::RoomMessageEventContent,
77
};
88

@@ -12,8 +12,9 @@ async fn hello_world(
1212
homeserver_url: String,
1313
username: &str,
1414
password: &str,
15-
room_alias: OwnedRoomAliasId,
15+
room_id_or_alias: OwnedRoomOrAliasId,
1616
) -> anyhow::Result<()> {
17+
// Construct and log in the client.
1718
let client = ruma_client::Client::builder()
1819
.homeserver_url(homeserver_url)
1920
.build::<HttpClient>()
@@ -22,13 +23,15 @@ async fn hello_world(
2223
.log_in(username, password, None, Some("ruma-example-client"))
2324
.await?;
2425

26+
// Join the room.
2527
let room_id = client
26-
.send_request(get_alias::v3::Request::new(room_alias))
28+
.send_request(join_room_by_id_or_alias::v3::Request::new(
29+
room_id_or_alias.clone(),
30+
))
2731
.await?
2832
.room_id;
29-
client
30-
.send_request(join_room_by_id::v3::Request::new(room_id.clone()))
31-
.await?;
33+
34+
// Send the message.
3235
client
3336
.send_request(send_message_event::v3::Request::new(
3437
room_id,

0 commit comments

Comments
 (0)