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