Return the ID of the appservice that was created by register_appservice

This commit is contained in:
Torsten Flammiger 2022-01-31 11:52:33 +01:00 committed by Jonas Zohren
parent 8f69f02e59
commit e24d75cffc
No known key found for this signature in database
GPG key ID: FE3ED5D90A175463
2 changed files with 6 additions and 7 deletions

View file

@ -110,13 +110,10 @@ impl Admin {
}
AdminCommand::RegisterAppservice(yaml) => {
match guard.appservice.register_appservice(yaml) {
Ok(Some(id)) => {
Ok(id) => {
let msg: String = format!("OK. Appservice {} created", id);
send_message(RoomMessageEventContent::text_plain(msg), guard, &state_lock);
}
Ok(None) => {
send_message(RoomMessageEventContent::text_plain("WARN. Appservice created, but its ID was not returned!"), guard, &state_lock);
}
Err(_) => {
send_message(RoomMessageEventContent::text_plain("ERR: Failed register appservice. Check server log"), guard, &state_lock);
}

View file

@ -12,7 +12,9 @@ pub struct Appservice {
}
impl Appservice {
pub fn register_appservice(&self, yaml: serde_yaml::Value) -> Result<Option<String>> {
/// Registers an appservice and returns the ID to the caller
///
pub fn register_appservice(&self, yaml: serde_yaml::Value) -> Result<String> {
// TODO: Rumaify
let id = yaml.get("id").unwrap().as_str().unwrap();
self.id_appserviceregistrations.insert(
@ -22,9 +24,9 @@ impl Appservice {
self.cached_registrations
.write()
.unwrap()
.insert(id.to_owned(), yaml);
.insert(id.to_owned(), yaml.to_owned());
Ok(Some(id.to_owned()))
Ok(id.to_owned())
}
/// Remove an appservice registration