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,21 +48,23 @@ impl Admin {
AdminCommand::SendTextMessage(message) => { AdminCommand::SendTextMessage(message) => {
println!("{:?}", message); println!("{:?}", message);
db.rooms.build_and_append_pdu( if let Some(conduit_room) = &conduit_room {
PduBuilder { db.rooms.build_and_append_pdu(
event_type: EventType::RoomMessage, PduBuilder {
content: serde_json::to_value(message).expect("event is valid, we just created it"), event_type: EventType::RoomMessage,
unsigned: None, content: serde_json::to_value(message).expect("event is valid, we just created it"),
state_key: None, unsigned: None,
redacts: None, state_key: None,
}, redacts: None,
&conduit_user, },
&conduit_room, &conduit_user,
&db.globals, &conduit_room,
&db.sending, &db.globals,
&db.admin, &db.sending,
&db.account_data, &db.admin,
).unwrap(); &db.account_data,
).unwrap();
}
} }
} }
} }