Merge remote-tracking branch 'origin/next' into command-refactor
Fixed conflict with commit 78502aa6b1
This commit is contained in:
commit
4bbff69a24
23 changed files with 340 additions and 186 deletions
|
@ -262,7 +262,10 @@ fn process_admin_command(
|
|||
let parsed_config = serde_yaml::from_str::<serde_yaml::Value>(&appservice_config);
|
||||
match parsed_config {
|
||||
Ok(yaml) => match db.appservice.register_appservice(yaml) {
|
||||
Ok(()) => RoomMessageEventContent::text_plain("Appservice registered."),
|
||||
Ok(id) => RoomMessageEventContent::text_plain(format!(
|
||||
"Appservice registered with ID: {}.",
|
||||
id
|
||||
)),
|
||||
Err(e) => RoomMessageEventContent::text_plain(format!(
|
||||
"Failed to register appservice: {}",
|
||||
e
|
||||
|
|
|
@ -12,7 +12,9 @@ pub struct Appservice {
|
|||
}
|
||||
|
||||
impl Appservice {
|
||||
pub fn register_appservice(&self, yaml: serde_yaml::Value) -> Result<()> {
|
||||
/// 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(())
|
||||
Ok(id.to_owned())
|
||||
}
|
||||
|
||||
/// Remove an appservice registration
|
||||
|
|
|
@ -7,7 +7,6 @@ use ruma::{
|
|||
serde::Raw,
|
||||
RoomId, UserId,
|
||||
};
|
||||
use serde_json::json;
|
||||
use std::{collections::BTreeMap, sync::Arc};
|
||||
|
||||
use super::abstraction::Tree;
|
||||
|
@ -212,13 +211,13 @@ impl KeyBackups {
|
|||
&self,
|
||||
user_id: &UserId,
|
||||
version: &str,
|
||||
) -> Result<BTreeMap<Box<RoomId>, Raw<RoomKeyBackup>>> {
|
||||
) -> Result<BTreeMap<Box<RoomId>, RoomKeyBackup>> {
|
||||
let mut prefix = user_id.as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
prefix.extend_from_slice(version.as_bytes());
|
||||
prefix.push(0xff);
|
||||
|
||||
let mut rooms = BTreeMap::<Box<RoomId>, Raw<RoomKeyBackup>>::new();
|
||||
let mut rooms = BTreeMap::<Box<RoomId>, RoomKeyBackup>::new();
|
||||
|
||||
for result in self
|
||||
.backupkeyid_backup
|
||||
|
@ -244,7 +243,7 @@ impl KeyBackups {
|
|||
Error::bad_database("backupkeyid_backup room_id is invalid room id.")
|
||||
})?;
|
||||
|
||||
let key_data: serde_json::Value = serde_json::from_slice(&value).map_err(|_| {
|
||||
let key_data = serde_json::from_slice(&value).map_err(|_| {
|
||||
Error::bad_database("KeyBackupData in backupkeyid_backup is invalid.")
|
||||
})?;
|
||||
|
||||
|
@ -252,25 +251,13 @@ impl KeyBackups {
|
|||
})
|
||||
{
|
||||
let (room_id, session_id, key_data) = result?;
|
||||
let room_key_backup = rooms.entry(room_id).or_insert_with(|| {
|
||||
Raw::new(&RoomKeyBackup {
|
||||
rooms
|
||||
.entry(room_id)
|
||||
.or_insert_with(|| RoomKeyBackup {
|
||||
sessions: BTreeMap::new(),
|
||||
})
|
||||
.expect("RoomKeyBackup serialization")
|
||||
});
|
||||
|
||||
let mut object = room_key_backup
|
||||
.deserialize_as::<serde_json::Map<String, serde_json::Value>>()
|
||||
.map_err(|_| Error::bad_database("RoomKeyBackup is not an object"))?;
|
||||
|
||||
let sessions = object.entry("session").or_insert_with(|| json!({}));
|
||||
if let serde_json::Value::Object(unsigned_object) = sessions {
|
||||
unsigned_object.insert(session_id, key_data);
|
||||
}
|
||||
|
||||
*room_key_backup = Raw::from_json(
|
||||
serde_json::value::to_raw_value(&object).expect("Value => RawValue serialization"),
|
||||
);
|
||||
.sessions
|
||||
.insert(session_id, key_data);
|
||||
}
|
||||
|
||||
Ok(rooms)
|
||||
|
|
|
@ -171,7 +171,7 @@ impl Media {
|
|||
/// For width,height <= 96 the server uses another thumbnailing algorithm which crops the image afterwards.
|
||||
pub async fn get_thumbnail(
|
||||
&self,
|
||||
mxc: String,
|
||||
mxc: &str,
|
||||
globals: &Globals,
|
||||
width: u32,
|
||||
height: u32,
|
||||
|
|
|
@ -480,6 +480,26 @@ impl Sending {
|
|||
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))]
|
||||
async fn handle_events(
|
||||
kind: OutgoingKind,
|
||||
|
@ -520,8 +540,15 @@ impl Sending {
|
|||
&db.globals,
|
||||
db.appservice
|
||||
.get_registration(server.as_str())
|
||||
.unwrap()
|
||||
.unwrap(), // TODO: handle error
|
||||
.map_err(|e| (kind.clone(), e))?
|
||||
.ok_or_else(|| {
|
||||
(
|
||||
kind.clone(),
|
||||
Error::bad_database(
|
||||
"[Appservice] Could not load registration from db.",
|
||||
),
|
||||
)
|
||||
})?,
|
||||
appservice::event::push_events::v1::Request {
|
||||
events: &pdu_jsons,
|
||||
txn_id: (&*base64::encode_config(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue