fix: logging thread crash when admin room does not exist
use std::convert::{TryFrom, TryInto};
-use crate::{pdu::PduBuilder, Error};
+use crate::pdu::PduBuilder;
+use log::warn;
use rocket::futures::{channel::mpsc, stream::StreamExt};
use ruma::{events::room::message, events::EventType, UserId};
use tokio::select;
@@ -34,10 +35,12 @@ impl Admin {
.try_into()
.expect("#admins:server_name is a valid room alias"),
)
- .unwrap()
- .ok_or_else(|| Error::BadConfig("Conduit instance does not have an #admins room."))
.unwrap();
+ if conduit_room.is_none() {
+ warn!("Conduit instance does not have an #admins room. Logging to that room will not work.");
+ }
+
loop {
select! {
Some(event) = receiver.next() => {
@@ -45,6 +48,7 @@ impl Admin {
AdminCommand::SendTextMessage(message) => {
println!("{:?}", message);
+ if let Some(conduit_room) = &conduit_room {
db.rooms.build_and_append_pdu(
PduBuilder {
event_type: EventType::RoomMessage,
@@ -65,6 +69,7 @@ impl Admin {
}
}
}
+ }
});
}
