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