mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-12-28 13:33:47 +03:00
Cleanup appservice events after removing the appservice
This commit is contained in:
parent
fb2a7ebf66
commit
cc13112592
2 changed files with 41 additions and 3 deletions
|
@ -112,7 +112,18 @@ impl Admin {
|
||||||
guard.appservice.register_appservice(yaml).unwrap(); // TODO handle error
|
guard.appservice.register_appservice(yaml).unwrap(); // TODO handle error
|
||||||
}
|
}
|
||||||
AdminCommand::UnregisterAppservice(service_name) => {
|
AdminCommand::UnregisterAppservice(service_name) => {
|
||||||
guard.appservice.unregister_appservice(&service_name).unwrap(); // TODO: see above
|
if let Ok(_) = guard.appservice.unregister_appservice(&service_name) {
|
||||||
|
if let Ok(_) = guard.sending.cleanup_events(&service_name) {
|
||||||
|
let msg: String = format!("OK. Appservice {} removed", service_name);
|
||||||
|
send_message(RoomMessageEventContent::text_plain(msg), guard, &state_lock);
|
||||||
|
} else {
|
||||||
|
let msg: String = format!("WARN: Appservice {} removed, but failed to cleanup events", service_name);
|
||||||
|
send_message(RoomMessageEventContent::text_plain(msg), guard, &state_lock);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let msg: String = format!("ERR. Appservice {} not removed", service_name);
|
||||||
|
send_message(RoomMessageEventContent::text_plain(msg), guard, &state_lock);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
AdminCommand::ListAppservices => {
|
AdminCommand::ListAppservices => {
|
||||||
if let Ok(appservices) = guard.appservice.iter_ids().map(|ids| ids.collect::<Vec<_>>()) {
|
if let Ok(appservices) = guard.appservice.iter_ids().map(|ids| ids.collect::<Vec<_>>()) {
|
||||||
|
|
|
@ -480,6 +480,26 @@ impl Sending {
|
||||||
hash.as_ref().to_owned()
|
hash.as_ref().to_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Cleanup event data
|
||||||
|
/// Used for instance after we remove an appservice registration
|
||||||
|
///
|
||||||
|
#[tracing::instrument(skip(self))]
|
||||||
|
pub fn cleanup_events(&self, key_id: &str) -> Result<()> {
|
||||||
|
let mut prefix = b"+".to_vec();
|
||||||
|
prefix.extend_from_slice(key_id.as_bytes());
|
||||||
|
prefix.push(0xff);
|
||||||
|
|
||||||
|
for (key, _) in self.servercurrentevent_data.scan_prefix(prefix.clone()) {
|
||||||
|
self.servercurrentevent_data.remove(&key).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (key, _) in self.servernameevent_data.scan_prefix(prefix.clone()) {
|
||||||
|
self.servernameevent_data.remove(&key).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(db, events, kind))]
|
#[tracing::instrument(skip(db, events, kind))]
|
||||||
async fn handle_events(
|
async fn handle_events(
|
||||||
kind: OutgoingKind,
|
kind: OutgoingKind,
|
||||||
|
@ -520,8 +540,15 @@ impl Sending {
|
||||||
&db.globals,
|
&db.globals,
|
||||||
db.appservice
|
db.appservice
|
||||||
.get_registration(server.as_str())
|
.get_registration(server.as_str())
|
||||||
.unwrap()
|
.map_err(|e| (kind.clone(), e))?
|
||||||
.unwrap(), // TODO: handle error
|
.ok_or_else(|| {
|
||||||
|
(
|
||||||
|
kind.clone(),
|
||||||
|
Error::bad_database(
|
||||||
|
"[Appservice] Could not load registration from db.",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
})?,
|
||||||
appservice::event::push_events::v1::Request {
|
appservice::event::push_events::v1::Request {
|
||||||
events: &pdu_jsons,
|
events: &pdu_jsons,
|
||||||
txn_id: (&*base64::encode_config(
|
txn_id: (&*base64::encode_config(
|
||||||
|
|
Loading…
Reference in a new issue