Merge branch 'add_remove_appservice' into 'next'

Add ability to remove an appservice

See merge request famedly/conduit!236
This commit is contained in:
Timo Kösters 2022-01-13 11:38:17 +00:00
commit b25354c747
4 changed files with 40 additions and 0 deletions

View file

@ -42,6 +42,14 @@ could help.
## Appservice-specific instructions
### Remove an appservice
To remove an appservice go to your admin room and execute
```@conduit:your.server.name: unregister_appservice <name>```
where `<name>` one of the output of `list_appservices`.
### Tested appservices
These appservices have been tested and work with Conduit without any extra steps:

View file

@ -12,6 +12,7 @@ use tracing::warn;
pub enum AdminCommand {
RegisterAppservice(serde_yaml::Value),
UnregisterAppservice(String),
ListAppservices,
SendMessage(RoomMessageEventContent),
}
@ -96,6 +97,9 @@ impl Admin {
AdminCommand::RegisterAppservice(yaml) => {
guard.appservice.register_appservice(yaml).unwrap(); // TODO handle error
}
AdminCommand::UnregisterAppservice(service_name) => {
guard.appservice.unregister_appservice(&service_name).unwrap(); // TODO: see above
}
AdminCommand::ListAppservices => {
if let Ok(appservices) = guard.appservice.iter_ids().map(|ids| ids.collect::<Vec<_>>()) {
let count = appservices.len();

View file

@ -27,6 +27,21 @@ impl Appservice {
Ok(())
}
/// Remove an appservice registration
///
/// # Arguments
///
/// * `service_name` - the name you send to register the service previously
pub fn unregister_appservice(&self, service_name: &str) -> Result<()> {
self.id_appserviceregistrations
.remove(service_name.as_bytes())?;
self.cached_registrations
.write()
.unwrap()
.remove(service_name);
Ok(())
}
pub fn get_registration(&self, id: &str) -> Result<Option<serde_yaml::Value>> {
self.cached_registrations
.read()

View file

@ -1528,6 +1528,19 @@ impl Rooms {
));
}
}
"unregister_appservice" => {
if args.len() == 1 {
db.admin.send(AdminCommand::UnregisterAppservice(
args[0].to_owned(),
));
} else {
db.admin.send(AdminCommand::SendMessage(
RoomMessageEventContent::text_plain(
"Missing appservice identifier",
),
));
}
}
"list_appservices" => {
db.admin.send(AdminCommand::ListAppservices);
}