fix: logging thread crash when admin room does not exist

next
Timo Kösters 2020-12-02 15:49:50 +01:00
parent 7078443460
commit e691e880e0
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
1 changed files with 23 additions and 18 deletions

View File

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