matrix: Panic when the message-passing channel overflows

This commit is contained in:
mirsal 2024-11-25 04:04:43 +00:00
parent 50f0bcd3c7
commit 148d4e7e43
Signed by: mirsal
GPG Key ID: F78F9FE84AE5B610

View File

@ -32,6 +32,8 @@ use tokio::{
sync::broadcast
};
use tracing::info;
async fn on_stripped_state_member(
room_member: StrippedRoomMemberEvent,
client: Client,
@ -97,18 +99,24 @@ pub async fn login_and_sync<T: Clone>(
loop {
tokio::select! {
Ok(_) = client.sync(settings.clone()) => return Ok(()),
Ok((msg, rooms)) = rx.recv() => {
recv = rx.recv() => match recv {
Ok((msg, rooms)) => {
let msg = &msg.clone();
for r in rooms {
info!("Joining room {}", r);
let room = client.join_room_by_id(<&RoomId>::try_from(r.as_str())
.expect("invalid room ID")
).await.expect(format!("Failed to join room {}", r).as_str());
info!("Posting to room {}", r);
room.send(RoomMessageEventContent::text_html(msg.clone(), msg)).await
.expect("Failed to send matrix event");
}
},
Err(e) => {
panic!("Broadcast channel is lagging: {e:?}");
}
}
}
}