fisken/src/invite.rs

39 lines
1.2 KiB
Rust
Raw Normal View History

2024-09-26 12:49:23 +02:00
// Stolen from https://github.com/matrix-org/matrix-rust-sdk/blob/5ba90611b43915926a37be83f3de1d4d53bca6bd/examples/autojoin/src/main.rs
use tokio::time::{sleep, Duration};
use matrix_sdk::ruma::events::room::member::StrippedRoomMemberEvent;
use matrix_sdk::{Client, Room};
pub async fn on_stripped_state_member(
room_member: StrippedRoomMemberEvent,
client: Client,
room: Room,
) {
if room_member.state_key != client.user_id().unwrap() {
return;
}
tokio::spawn(async move {
let mut delay = 2;
while let Err(err) = room.join().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
eprintln!(
"Failed to join room {} ({err:?}), retrying in {delay}s",
room.room_id()
);
sleep(Duration::from_secs(delay)).await;
delay *= 2;
if delay > 3600 {
eprintln!("Can't join room {} ({err:?})", room.room_id());
break;
}
}
println!("Successfully joined room {}", room.room_id());
});
}