Clean up (mostly automated with cargo clippy --fix)
parent
979ec6b4fa
commit
d68c93b5fa
|
@ -21,7 +21,7 @@ where
|
|||
let hs_token = registration.get("hs_token").unwrap().as_str().unwrap();
|
||||
|
||||
let mut http_request = request
|
||||
.try_into_http_request::<BytesMut>(&destination, SendAccessToken::IfRequired(""))
|
||||
.try_into_http_request::<BytesMut>(destination, SendAccessToken::IfRequired(""))
|
||||
.unwrap()
|
||||
.map(|body| body.freeze());
|
||||
|
||||
|
|
|
@ -572,7 +572,7 @@ pub async fn change_password_route(
|
|||
|
||||
if let Some(auth) = &body.auth {
|
||||
let (worked, uiaainfo) = db.uiaa.try_auth(
|
||||
&sender_user,
|
||||
sender_user,
|
||||
sender_device,
|
||||
auth,
|
||||
&uiaainfo,
|
||||
|
@ -586,24 +586,24 @@ pub async fn change_password_route(
|
|||
} else if let Some(json) = body.json_body {
|
||||
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
||||
db.uiaa
|
||||
.create(&sender_user, &sender_device, &uiaainfo, &json)?;
|
||||
.create(sender_user, sender_device, &uiaainfo, &json)?;
|
||||
return Err(Error::Uiaa(uiaainfo));
|
||||
} else {
|
||||
return Err(Error::BadRequest(ErrorKind::NotJson, "Not json."));
|
||||
}
|
||||
|
||||
db.users
|
||||
.set_password(&sender_user, Some(&body.new_password))?;
|
||||
.set_password(sender_user, Some(&body.new_password))?;
|
||||
|
||||
if body.logout_devices {
|
||||
// Logout all devices except the current one
|
||||
for id in db
|
||||
.users
|
||||
.all_device_ids(&sender_user)
|
||||
.all_device_ids(sender_user)
|
||||
.filter_map(|id| id.ok())
|
||||
.filter(|id| id != sender_device)
|
||||
{
|
||||
db.users.remove_device(&sender_user, &id)?;
|
||||
db.users.remove_device(sender_user, &id)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -664,8 +664,8 @@ pub async fn deactivate_route(
|
|||
|
||||
if let Some(auth) = &body.auth {
|
||||
let (worked, uiaainfo) = db.uiaa.try_auth(
|
||||
&sender_user,
|
||||
&sender_device,
|
||||
sender_user,
|
||||
sender_device,
|
||||
auth,
|
||||
&uiaainfo,
|
||||
&db.users,
|
||||
|
@ -678,7 +678,7 @@ pub async fn deactivate_route(
|
|||
} else if let Some(json) = body.json_body {
|
||||
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
||||
db.uiaa
|
||||
.create(&sender_user, &sender_device, &uiaainfo, &json)?;
|
||||
.create(sender_user, sender_device, &uiaainfo, &json)?;
|
||||
return Err(Error::Uiaa(uiaainfo));
|
||||
} else {
|
||||
return Err(Error::BadRequest(ErrorKind::NotJson, "Not json."));
|
||||
|
@ -688,10 +688,10 @@ pub async fn deactivate_route(
|
|||
// TODO: work over federation invites
|
||||
let all_rooms = db
|
||||
.rooms
|
||||
.rooms_joined(&sender_user)
|
||||
.rooms_joined(sender_user)
|
||||
.chain(
|
||||
db.rooms
|
||||
.rooms_invited(&sender_user)
|
||||
.rooms_invited(sender_user)
|
||||
.map(|t| t.map(|(r, _)| r)),
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
|
@ -726,7 +726,7 @@ pub async fn deactivate_route(
|
|||
state_key: Some(sender_user.to_string()),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&state_lock,
|
||||
|
@ -734,7 +734,7 @@ pub async fn deactivate_route(
|
|||
}
|
||||
|
||||
// Remove devices and mark account as deactivated
|
||||
db.users.deactivate_account(&sender_user)?;
|
||||
db.users.deactivate_account(sender_user)?;
|
||||
|
||||
info!("{} deactivated their account", sender_user);
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ pub(crate) async fn get_alias_helper(
|
|||
}
|
||||
|
||||
let mut room_id = None;
|
||||
match db.rooms.id_from_alias(&room_alias)? {
|
||||
match db.rooms.id_from_alias(room_alias)? {
|
||||
Some(r) => room_id = Some(r),
|
||||
None => {
|
||||
for (_id, registration) in db.appservice.all()? {
|
||||
|
@ -140,7 +140,7 @@ pub(crate) async fn get_alias_helper(
|
|||
.await
|
||||
.is_ok()
|
||||
{
|
||||
room_id = Some(db.rooms.id_from_alias(&room_alias)?.ok_or_else(|| {
|
||||
room_id = Some(db.rooms.id_from_alias(room_alias)?.ok_or_else(|| {
|
||||
Error::bad_config("Appservice lied to us. Room does not exist.")
|
||||
})?);
|
||||
break;
|
||||
|
|
|
@ -27,7 +27,7 @@ pub async fn create_backup_route(
|
|||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
let version = db
|
||||
.key_backups
|
||||
.create_backup(&sender_user, &body.algorithm, &db.globals)?;
|
||||
.create_backup(sender_user, &body.algorithm, &db.globals)?;
|
||||
|
||||
db.flush()?;
|
||||
|
||||
|
@ -48,7 +48,7 @@ pub async fn update_backup_route(
|
|||
) -> ConduitResult<update_backup::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
db.key_backups
|
||||
.update_backup(&sender_user, &body.version, &body.algorithm, &db.globals)?;
|
||||
.update_backup(sender_user, &body.version, &body.algorithm, &db.globals)?;
|
||||
|
||||
db.flush()?;
|
||||
|
||||
|
@ -71,7 +71,7 @@ pub async fn get_latest_backup_route(
|
|||
|
||||
let (version, algorithm) =
|
||||
db.key_backups
|
||||
.get_latest_backup(&sender_user)?
|
||||
.get_latest_backup(sender_user)?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"Key backup does not exist.",
|
||||
|
@ -101,7 +101,7 @@ pub async fn get_backup_route(
|
|||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
let algorithm = db
|
||||
.key_backups
|
||||
.get_backup(&sender_user, &body.version)?
|
||||
.get_backup(sender_user, &body.version)?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"Key backup does not exist.",
|
||||
|
@ -132,7 +132,7 @@ pub async fn delete_backup_route(
|
|||
) -> ConduitResult<delete_backup::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
db.key_backups.delete_backup(&sender_user, &body.version)?;
|
||||
db.key_backups.delete_backup(sender_user, &body.version)?;
|
||||
|
||||
db.flush()?;
|
||||
|
||||
|
@ -172,11 +172,11 @@ pub async fn add_backup_keys_route(
|
|||
for (room_id, room) in &body.rooms {
|
||||
for (session_id, key_data) in &room.sessions {
|
||||
db.key_backups.add_key(
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&body.version,
|
||||
&room_id,
|
||||
&session_id,
|
||||
&key_data,
|
||||
room_id,
|
||||
session_id,
|
||||
key_data,
|
||||
&db.globals,
|
||||
)?
|
||||
}
|
||||
|
@ -223,11 +223,11 @@ pub async fn add_backup_key_sessions_route(
|
|||
|
||||
for (session_id, key_data) in &body.sessions {
|
||||
db.key_backups.add_key(
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&body.version,
|
||||
&body.room_id,
|
||||
&session_id,
|
||||
&key_data,
|
||||
session_id,
|
||||
key_data,
|
||||
&db.globals,
|
||||
)?
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ pub async fn add_backup_key_session_route(
|
|||
}
|
||||
|
||||
db.key_backups.add_key(
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&body.version,
|
||||
&body.room_id,
|
||||
&body.session_id,
|
||||
|
@ -303,7 +303,7 @@ pub async fn get_backup_keys_route(
|
|||
) -> ConduitResult<get_backup_keys::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
let rooms = db.key_backups.get_all(&sender_user, &body.version)?;
|
||||
let rooms = db.key_backups.get_all(sender_user, &body.version)?;
|
||||
|
||||
Ok(get_backup_keys::Response { rooms }.into())
|
||||
}
|
||||
|
@ -324,7 +324,7 @@ pub async fn get_backup_key_sessions_route(
|
|||
|
||||
let sessions = db
|
||||
.key_backups
|
||||
.get_room(&sender_user, &body.version, &body.room_id)?;
|
||||
.get_room(sender_user, &body.version, &body.room_id)?;
|
||||
|
||||
Ok(get_backup_key_sessions::Response { sessions }.into())
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ pub async fn get_backup_key_session_route(
|
|||
|
||||
let key_data = db
|
||||
.key_backups
|
||||
.get_session(&sender_user, &body.version, &body.room_id, &body.session_id)?
|
||||
.get_session(sender_user, &body.version, &body.room_id, &body.session_id)?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"Backup key not found for this user's session.",
|
||||
|
@ -368,8 +368,7 @@ pub async fn delete_backup_keys_route(
|
|||
) -> ConduitResult<delete_backup_keys::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
db.key_backups
|
||||
.delete_all_keys(&sender_user, &body.version)?;
|
||||
db.key_backups.delete_all_keys(sender_user, &body.version)?;
|
||||
|
||||
db.flush()?;
|
||||
|
||||
|
@ -395,7 +394,7 @@ pub async fn delete_backup_key_sessions_route(
|
|||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
db.key_backups
|
||||
.delete_room_keys(&sender_user, &body.version, &body.room_id)?;
|
||||
.delete_room_keys(sender_user, &body.version, &body.room_id)?;
|
||||
|
||||
db.flush()?;
|
||||
|
||||
|
@ -421,7 +420,7 @@ pub async fn delete_backup_key_session_route(
|
|||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
db.key_backups
|
||||
.delete_room_key(&sender_user, &body.version, &body.room_id, &body.session_id)?;
|
||||
.delete_room_key(sender_user, &body.version, &body.room_id, &body.session_id)?;
|
||||
|
||||
db.flush()?;
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::ConduitResult;
|
||||
use crate::Ruma;
|
||||
use crate::{ConduitResult, Ruma};
|
||||
use ruma::{
|
||||
api::client::r0::capabilities::{
|
||||
get_capabilities, Capabilities, RoomVersionStability, RoomVersionsCapability,
|
||||
|
|
|
@ -50,7 +50,7 @@ pub async fn get_context_route(
|
|||
|
||||
let events_before = db
|
||||
.rooms
|
||||
.pdus_until(&sender_user, &body.room_id, base_token)?
|
||||
.pdus_until(sender_user, &body.room_id, base_token)?
|
||||
.take(
|
||||
u32::try_from(body.limit).map_err(|_| {
|
||||
Error::BadRequest(ErrorKind::InvalidParam, "Limit value is invalid.")
|
||||
|
@ -72,7 +72,7 @@ pub async fn get_context_route(
|
|||
|
||||
let events_after = db
|
||||
.rooms
|
||||
.pdus_after(&sender_user, &body.room_id, base_token)?
|
||||
.pdus_after(sender_user, &body.room_id, base_token)?
|
||||
.take(
|
||||
u32::try_from(body.limit).map_err(|_| {
|
||||
Error::BadRequest(ErrorKind::InvalidParam, "Limit value is invalid.")
|
||||
|
|
|
@ -50,7 +50,7 @@ pub async fn get_device_route(
|
|||
|
||||
let device = db
|
||||
.users
|
||||
.get_device_metadata(&sender_user, &body.body.device_id)?
|
||||
.get_device_metadata(sender_user, &body.body.device_id)?
|
||||
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Device not found."))?;
|
||||
|
||||
Ok(get_device::Response { device }.into())
|
||||
|
@ -72,13 +72,13 @@ pub async fn update_device_route(
|
|||
|
||||
let mut device = db
|
||||
.users
|
||||
.get_device_metadata(&sender_user, &body.device_id)?
|
||||
.get_device_metadata(sender_user, &body.device_id)?
|
||||
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Device not found."))?;
|
||||
|
||||
device.display_name = body.display_name.clone();
|
||||
|
||||
db.users
|
||||
.update_device_metadata(&sender_user, &body.device_id, &device)?;
|
||||
.update_device_metadata(sender_user, &body.device_id, &device)?;
|
||||
|
||||
db.flush()?;
|
||||
|
||||
|
@ -119,8 +119,8 @@ pub async fn delete_device_route(
|
|||
|
||||
if let Some(auth) = &body.auth {
|
||||
let (worked, uiaainfo) = db.uiaa.try_auth(
|
||||
&sender_user,
|
||||
&sender_device,
|
||||
sender_user,
|
||||
sender_device,
|
||||
auth,
|
||||
&uiaainfo,
|
||||
&db.users,
|
||||
|
@ -133,13 +133,13 @@ pub async fn delete_device_route(
|
|||
} else if let Some(json) = body.json_body {
|
||||
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
||||
db.uiaa
|
||||
.create(&sender_user, &sender_device, &uiaainfo, &json)?;
|
||||
.create(sender_user, sender_device, &uiaainfo, &json)?;
|
||||
return Err(Error::Uiaa(uiaainfo));
|
||||
} else {
|
||||
return Err(Error::BadRequest(ErrorKind::NotJson, "Not json."));
|
||||
}
|
||||
|
||||
db.users.remove_device(&sender_user, &body.device_id)?;
|
||||
db.users.remove_device(sender_user, &body.device_id)?;
|
||||
|
||||
db.flush()?;
|
||||
|
||||
|
@ -182,8 +182,8 @@ pub async fn delete_devices_route(
|
|||
|
||||
if let Some(auth) = &body.auth {
|
||||
let (worked, uiaainfo) = db.uiaa.try_auth(
|
||||
&sender_user,
|
||||
&sender_device,
|
||||
sender_user,
|
||||
sender_device,
|
||||
auth,
|
||||
&uiaainfo,
|
||||
&db.users,
|
||||
|
@ -196,14 +196,14 @@ pub async fn delete_devices_route(
|
|||
} else if let Some(json) = body.json_body {
|
||||
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
||||
db.uiaa
|
||||
.create(&sender_user, &sender_device, &uiaainfo, &json)?;
|
||||
.create(sender_user, sender_device, &uiaainfo, &json)?;
|
||||
return Err(Error::Uiaa(uiaainfo));
|
||||
} else {
|
||||
return Err(Error::BadRequest(ErrorKind::NotJson, "Not json."));
|
||||
}
|
||||
|
||||
for device_id in &body.devices {
|
||||
db.users.remove_device(&sender_user, &device_id)?
|
||||
db.users.remove_device(sender_user, device_id)?
|
||||
}
|
||||
|
||||
db.flush()?;
|
||||
|
|
|
@ -158,8 +158,8 @@ pub async fn upload_signing_keys_route(
|
|||
|
||||
if let Some(auth) = &body.auth {
|
||||
let (worked, uiaainfo) = db.uiaa.try_auth(
|
||||
&sender_user,
|
||||
&sender_device,
|
||||
sender_user,
|
||||
sender_device,
|
||||
auth,
|
||||
&uiaainfo,
|
||||
&db.users,
|
||||
|
@ -172,7 +172,7 @@ pub async fn upload_signing_keys_route(
|
|||
} else if let Some(json) = body.json_body {
|
||||
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
||||
db.uiaa
|
||||
.create(&sender_user, &sender_device, &uiaainfo, &json)?;
|
||||
.create(sender_user, sender_device, &uiaainfo, &json)?;
|
||||
return Err(Error::Uiaa(uiaainfo));
|
||||
} else {
|
||||
return Err(Error::BadRequest(ErrorKind::NotJson, "Not json."));
|
||||
|
@ -181,7 +181,7 @@ pub async fn upload_signing_keys_route(
|
|||
if let Some(master_key) = &body.master_key {
|
||||
db.users.add_cross_signing_keys(
|
||||
sender_user,
|
||||
&master_key,
|
||||
master_key,
|
||||
&body.self_signing_key,
|
||||
&body.user_signing_key,
|
||||
&db.rooms,
|
||||
|
@ -242,10 +242,10 @@ pub async fn upload_signatures_route(
|
|||
.to_owned(),
|
||||
);
|
||||
db.users.sign_key(
|
||||
&user_id,
|
||||
&key_id,
|
||||
user_id,
|
||||
key_id,
|
||||
signature,
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&db.rooms,
|
||||
&db.globals,
|
||||
)?;
|
||||
|
@ -359,8 +359,8 @@ pub(crate) async fn get_keys_helper<F: Fn(&UserId) -> bool>(
|
|||
} else {
|
||||
for device_id in device_ids {
|
||||
let mut container = BTreeMap::new();
|
||||
if let Some(mut keys) = db.users.get_device_keys(&user_id.clone(), &device_id)? {
|
||||
let metadata = db.users.get_device_metadata(user_id, &device_id)?.ok_or(
|
||||
if let Some(mut keys) = db.users.get_device_keys(&user_id.clone(), device_id)? {
|
||||
let metadata = db.users.get_device_metadata(user_id, device_id)?.ok_or(
|
||||
Error::BadRequest(
|
||||
ErrorKind::InvalidParam,
|
||||
"Tried to get keys for nonexistent device.",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use crate::{
|
||||
database::media::FileMeta, database::DatabaseGuard, utils, ConduitResult, Error, Ruma,
|
||||
database::{media::FileMeta, DatabaseGuard},
|
||||
utils, ConduitResult, Error, Ruma,
|
||||
};
|
||||
use ruma::api::client::{
|
||||
error::ErrorKind,
|
||||
|
|
|
@ -56,7 +56,7 @@ pub async fn join_room_by_id_route(
|
|||
|
||||
let mut servers = db
|
||||
.rooms
|
||||
.invite_state(&sender_user, &body.room_id)?
|
||||
.invite_state(sender_user, &body.room_id)?
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.filter_map(|event| {
|
||||
|
@ -105,7 +105,7 @@ pub async fn join_room_by_id_or_alias_route(
|
|||
Ok(room_id) => {
|
||||
let mut servers = db
|
||||
.rooms
|
||||
.invite_state(&sender_user, &room_id)?
|
||||
.invite_state(sender_user, &room_id)?
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.filter_map(|event| {
|
||||
|
@ -243,7 +243,7 @@ pub async fn kick_user_route(
|
|||
state_key: Some(body.user_id.to_string()),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
&db,
|
||||
&state_lock,
|
||||
|
@ -319,7 +319,7 @@ pub async fn ban_user_route(
|
|||
state_key: Some(body.user_id.to_string()),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
&db,
|
||||
&state_lock,
|
||||
|
@ -384,7 +384,7 @@ pub async fn unban_user_route(
|
|||
state_key: Some(body.user_id.to_string()),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
&db,
|
||||
&state_lock,
|
||||
|
@ -416,7 +416,7 @@ pub async fn forget_room_route(
|
|||
) -> ConduitResult<forget_room::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
db.rooms.forget(&body.room_id, &sender_user)?;
|
||||
db.rooms.forget(&body.room_id, sender_user)?;
|
||||
|
||||
db.flush()?;
|
||||
|
||||
|
@ -440,7 +440,7 @@ pub async fn joined_rooms_route(
|
|||
Ok(joined_rooms::Response {
|
||||
joined_rooms: db
|
||||
.rooms
|
||||
.rooms_joined(&sender_user)
|
||||
.rooms_joined(sender_user)
|
||||
.filter_map(|r| r.ok())
|
||||
.collect(),
|
||||
}
|
||||
|
@ -500,7 +500,7 @@ pub async fn joined_members_route(
|
|||
) -> ConduitResult<joined_members::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
if !db.rooms.is_joined(&sender_user, &body.room_id)? {
|
||||
if !db.rooms.is_joined(sender_user, &body.room_id)? {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::Forbidden,
|
||||
"You aren't a member of the room.",
|
||||
|
@ -545,7 +545,7 @@ async fn join_room_by_id_helper(
|
|||
let state_lock = mutex_state.lock().await;
|
||||
|
||||
// Ask a remote server if we don't have this room
|
||||
if !db.rooms.exists(&room_id)? && room_id.server_name() != db.globals.server_name() {
|
||||
if !db.rooms.exists(room_id)? && room_id.server_name() != db.globals.server_name() {
|
||||
let mut make_join_response_and_server = Err(Error::BadServerResponse(
|
||||
"No server available to assist in joining.",
|
||||
));
|
||||
|
@ -606,11 +606,11 @@ async fn join_room_by_id_helper(
|
|||
"content".to_owned(),
|
||||
to_canonical_value(member::MemberEventContent {
|
||||
membership: member::MembershipState::Join,
|
||||
displayname: db.users.displayname(&sender_user)?,
|
||||
avatar_url: db.users.avatar_url(&sender_user)?,
|
||||
displayname: db.users.displayname(sender_user)?,
|
||||
avatar_url: db.users.avatar_url(sender_user)?,
|
||||
is_direct: None,
|
||||
third_party_invite: None,
|
||||
blurhash: db.users.blurhash(&sender_user)?,
|
||||
blurhash: db.users.blurhash(sender_user)?,
|
||||
reason: None,
|
||||
})
|
||||
.expect("event is valid, we just created it"),
|
||||
|
@ -658,7 +658,7 @@ async fn join_room_by_id_helper(
|
|||
)
|
||||
.await?;
|
||||
|
||||
db.rooms.get_or_create_shortroomid(&room_id, &db.globals)?;
|
||||
db.rooms.get_or_create_shortroomid(room_id, &db.globals)?;
|
||||
|
||||
let pdu = PduEvent::from_id_val(&event_id, join_event.clone())
|
||||
.map_err(|_| Error::BadServerResponse("Invalid join event PDU."))?;
|
||||
|
@ -670,7 +670,7 @@ async fn join_room_by_id_helper(
|
|||
&send_join_response,
|
||||
&room_version,
|
||||
&pub_key_map,
|
||||
&db,
|
||||
db,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
@ -678,7 +678,7 @@ async fn join_room_by_id_helper(
|
|||
.room_state
|
||||
.state
|
||||
.iter()
|
||||
.map(|pdu| validate_and_add_event_id(pdu, &room_version, &pub_key_map, &db))
|
||||
.map(|pdu| validate_and_add_event_id(pdu, &room_version, &pub_key_map, db))
|
||||
{
|
||||
let (event_id, value) = match result {
|
||||
Ok(t) => t,
|
||||
|
@ -724,14 +724,14 @@ async fn join_room_by_id_helper(
|
|||
.into_iter()
|
||||
.map(|(k, id)| db.rooms.compress_state_event(k, &id, &db.globals))
|
||||
.collect::<Result<HashSet<_>>>()?,
|
||||
&db,
|
||||
db,
|
||||
)?;
|
||||
|
||||
for result in send_join_response
|
||||
.room_state
|
||||
.auth_chain
|
||||
.iter()
|
||||
.map(|pdu| validate_and_add_event_id(pdu, &room_version, &pub_key_map, &db))
|
||||
.map(|pdu| validate_and_add_event_id(pdu, &room_version, &pub_key_map, db))
|
||||
{
|
||||
let (event_id, value) = match result {
|
||||
Ok(t) => t,
|
||||
|
@ -754,15 +754,15 @@ async fn join_room_by_id_helper(
|
|||
|
||||
// We set the room state after inserting the pdu, so that we never have a moment in time
|
||||
// where events in the current room state do not exist
|
||||
db.rooms.set_room_state(&room_id, statehashid)?;
|
||||
db.rooms.set_room_state(room_id, statehashid)?;
|
||||
} else {
|
||||
let event = member::MemberEventContent {
|
||||
membership: member::MembershipState::Join,
|
||||
displayname: db.users.displayname(&sender_user)?,
|
||||
avatar_url: db.users.avatar_url(&sender_user)?,
|
||||
displayname: db.users.displayname(sender_user)?,
|
||||
avatar_url: db.users.avatar_url(sender_user)?,
|
||||
is_direct: None,
|
||||
third_party_invite: None,
|
||||
blurhash: db.users.blurhash(&sender_user)?,
|
||||
blurhash: db.users.blurhash(sender_user)?,
|
||||
reason: None,
|
||||
};
|
||||
|
||||
|
@ -774,9 +774,9 @@ async fn join_room_by_id_helper(
|
|||
state_key: Some(sender_user.to_string()),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
sender_user,
|
||||
room_id,
|
||||
db,
|
||||
&state_lock,
|
||||
)?;
|
||||
}
|
||||
|
@ -800,7 +800,7 @@ fn validate_and_add_event_id(
|
|||
})?;
|
||||
let event_id = EventId::try_from(&*format!(
|
||||
"${}",
|
||||
ruma::signatures::reference_hash(&value, &room_version)
|
||||
ruma::signatures::reference_hash(&value, room_version)
|
||||
.expect("ruma can calculate reference hashes")
|
||||
))
|
||||
.expect("ruma's reference hashes are valid event ids");
|
||||
|
@ -927,7 +927,7 @@ pub(crate) async fn invite_helper<'a>(
|
|||
let auth_events = db.rooms.get_auth_events(
|
||||
room_id,
|
||||
&kind,
|
||||
&sender_user,
|
||||
sender_user,
|
||||
Some(&state_key),
|
||||
&content,
|
||||
)?;
|
||||
|
@ -1074,10 +1074,10 @@ pub(crate) async fn invite_helper<'a>(
|
|||
let pdu_id = server_server::handle_incoming_pdu(
|
||||
&origin,
|
||||
&event_id,
|
||||
&room_id,
|
||||
room_id,
|
||||
value,
|
||||
true,
|
||||
&db,
|
||||
db,
|
||||
&pub_key_map,
|
||||
)
|
||||
.await
|
||||
|
@ -1119,11 +1119,11 @@ pub(crate) async fn invite_helper<'a>(
|
|||
event_type: EventType::RoomMember,
|
||||
content: serde_json::to_value(member::MemberEventContent {
|
||||
membership: member::MembershipState::Invite,
|
||||
displayname: db.users.displayname(&user_id)?,
|
||||
avatar_url: db.users.avatar_url(&user_id)?,
|
||||
displayname: db.users.displayname(user_id)?,
|
||||
avatar_url: db.users.avatar_url(user_id)?,
|
||||
is_direct: Some(is_direct),
|
||||
third_party_invite: None,
|
||||
blurhash: db.users.blurhash(&user_id)?,
|
||||
blurhash: db.users.blurhash(user_id)?,
|
||||
reason: None,
|
||||
})
|
||||
.expect("event is valid, we just created it"),
|
||||
|
@ -1131,9 +1131,9 @@ pub(crate) async fn invite_helper<'a>(
|
|||
state_key: Some(user_id.to_string()),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
sender_user,
|
||||
room_id,
|
||||
&db,
|
||||
db,
|
||||
&state_lock,
|
||||
)?;
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ pub async fn send_message_event_route(
|
|||
state_key: None,
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
&db,
|
||||
&state_lock,
|
||||
|
@ -141,7 +141,7 @@ pub async fn get_message_events_route(
|
|||
get_message_events::Direction::Forward => {
|
||||
let events_after = db
|
||||
.rooms
|
||||
.pdus_after(&sender_user, &body.room_id, from)?
|
||||
.pdus_after(sender_user, &body.room_id, from)?
|
||||
.take(limit)
|
||||
.filter_map(|r| r.ok()) // Filter out buggy events
|
||||
.filter_map(|(pdu_id, pdu)| {
|
||||
|
@ -171,7 +171,7 @@ pub async fn get_message_events_route(
|
|||
get_message_events::Direction::Backward => {
|
||||
let events_before = db
|
||||
.rooms
|
||||
.pdus_until(&sender_user, &body.room_id, from)?
|
||||
.pdus_until(sender_user, &body.room_id, from)?
|
||||
.take(limit)
|
||||
.filter_map(|r| r.ok()) // Filter out buggy events
|
||||
.filter_map(|(pdu_id, pdu)| {
|
||||
|
|
|
@ -19,17 +19,17 @@ pub async fn set_presence_route(
|
|||
) -> ConduitResult<set_presence::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
for room_id in db.rooms.rooms_joined(&sender_user) {
|
||||
for room_id in db.rooms.rooms_joined(sender_user) {
|
||||
let room_id = room_id?;
|
||||
|
||||
db.rooms.edus.update_presence(
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&room_id,
|
||||
ruma::events::presence::PresenceEvent {
|
||||
content: ruma::events::presence::PresenceEventContent {
|
||||
avatar_url: db.users.avatar_url(&sender_user)?,
|
||||
avatar_url: db.users.avatar_url(sender_user)?,
|
||||
currently_active: None,
|
||||
displayname: db.users.displayname(&sender_user)?,
|
||||
displayname: db.users.displayname(sender_user)?,
|
||||
last_active_ago: Some(
|
||||
utils::millis_since_unix_epoch()
|
||||
.try_into()
|
||||
|
@ -76,7 +76,7 @@ pub async fn get_presence_route(
|
|||
if let Some(presence) = db
|
||||
.rooms
|
||||
.edus
|
||||
.get_last_presence_event(&sender_user, &room_id)?
|
||||
.get_last_presence_event(sender_user, &room_id)?
|
||||
{
|
||||
presence_event = Some(presence);
|
||||
break;
|
||||
|
|
|
@ -34,12 +34,12 @@ pub async fn set_displayname_route(
|
|||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
db.users
|
||||
.set_displayname(&sender_user, body.displayname.clone())?;
|
||||
.set_displayname(sender_user, body.displayname.clone())?;
|
||||
|
||||
// Send a new membership event and presence update into all joined rooms
|
||||
let all_rooms_joined: Vec<_> = db
|
||||
.rooms
|
||||
.rooms_joined(&sender_user)
|
||||
.rooms_joined(sender_user)
|
||||
.filter_map(|r| r.ok())
|
||||
.map(|room_id| {
|
||||
Ok::<_, Error>((
|
||||
|
@ -89,19 +89,19 @@ pub async fn set_displayname_route(
|
|||
);
|
||||
let state_lock = mutex_state.lock().await;
|
||||
|
||||
let _ =
|
||||
db.rooms
|
||||
.build_and_append_pdu(pdu_builder, &sender_user, &room_id, &db, &state_lock);
|
||||
let _ = db
|
||||
.rooms
|
||||
.build_and_append_pdu(pdu_builder, sender_user, &room_id, &db, &state_lock);
|
||||
|
||||
// Presence update
|
||||
db.rooms.edus.update_presence(
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&room_id,
|
||||
ruma::events::presence::PresenceEvent {
|
||||
content: ruma::events::presence::PresenceEventContent {
|
||||
avatar_url: db.users.avatar_url(&sender_user)?,
|
||||
avatar_url: db.users.avatar_url(sender_user)?,
|
||||
currently_active: None,
|
||||
displayname: db.users.displayname(&sender_user)?,
|
||||
displayname: db.users.displayname(sender_user)?,
|
||||
last_active_ago: Some(
|
||||
utils::millis_since_unix_epoch()
|
||||
.try_into()
|
||||
|
@ -177,14 +177,14 @@ pub async fn set_avatar_url_route(
|
|||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
db.users
|
||||
.set_avatar_url(&sender_user, body.avatar_url.clone())?;
|
||||
.set_avatar_url(sender_user, body.avatar_url.clone())?;
|
||||
|
||||
db.users.set_blurhash(&sender_user, body.blurhash.clone())?;
|
||||
db.users.set_blurhash(sender_user, body.blurhash.clone())?;
|
||||
|
||||
// Send a new membership event and presence update into all joined rooms
|
||||
let all_joined_rooms: Vec<_> = db
|
||||
.rooms
|
||||
.rooms_joined(&sender_user)
|
||||
.rooms_joined(sender_user)
|
||||
.filter_map(|r| r.ok())
|
||||
.map(|room_id| {
|
||||
Ok::<_, Error>((
|
||||
|
@ -234,19 +234,19 @@ pub async fn set_avatar_url_route(
|
|||
);
|
||||
let state_lock = mutex_state.lock().await;
|
||||
|
||||
let _ =
|
||||
db.rooms
|
||||
.build_and_append_pdu(pdu_builder, &sender_user, &room_id, &db, &state_lock);
|
||||
let _ = db
|
||||
.rooms
|
||||
.build_and_append_pdu(pdu_builder, sender_user, &room_id, &db, &state_lock);
|
||||
|
||||
// Presence update
|
||||
db.rooms.edus.update_presence(
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&room_id,
|
||||
ruma::events::presence::PresenceEvent {
|
||||
content: ruma::events::presence::PresenceEventContent {
|
||||
avatar_url: db.users.avatar_url(&sender_user)?,
|
||||
avatar_url: db.users.avatar_url(sender_user)?,
|
||||
currently_active: None,
|
||||
displayname: db.users.displayname(&sender_user)?,
|
||||
displayname: db.users.displayname(sender_user)?,
|
||||
last_active_ago: Some(
|
||||
utils::millis_since_unix_epoch()
|
||||
.try_into()
|
||||
|
|
|
@ -31,7 +31,7 @@ pub async fn get_pushrules_all_route(
|
|||
|
||||
let event = db
|
||||
.account_data
|
||||
.get::<push_rules::PushRulesEvent>(None, &sender_user, EventType::PushRules)?
|
||||
.get::<push_rules::PushRulesEvent>(None, sender_user, EventType::PushRules)?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"PushRules event not found.",
|
||||
|
@ -59,7 +59,7 @@ pub async fn get_pushrule_route(
|
|||
|
||||
let event = db
|
||||
.account_data
|
||||
.get::<push_rules::PushRulesEvent>(None, &sender_user, EventType::PushRules)?
|
||||
.get::<push_rules::PushRulesEvent>(None, sender_user, EventType::PushRules)?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"PushRules event not found.",
|
||||
|
@ -124,7 +124,7 @@ pub async fn set_pushrule_route(
|
|||
|
||||
let mut event = db
|
||||
.account_data
|
||||
.get::<push_rules::PushRulesEvent>(None, &sender_user, EventType::PushRules)?
|
||||
.get::<push_rules::PushRulesEvent>(None, sender_user, EventType::PushRules)?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"PushRules event not found.",
|
||||
|
@ -193,13 +193,8 @@ pub async fn set_pushrule_route(
|
|||
_ => {}
|
||||
}
|
||||
|
||||
db.account_data.update(
|
||||
None,
|
||||
&sender_user,
|
||||
EventType::PushRules,
|
||||
&event,
|
||||
&db.globals,
|
||||
)?;
|
||||
db.account_data
|
||||
.update(None, sender_user, EventType::PushRules, &event, &db.globals)?;
|
||||
|
||||
db.flush()?;
|
||||
|
||||
|
@ -229,7 +224,7 @@ pub async fn get_pushrule_actions_route(
|
|||
|
||||
let mut event = db
|
||||
.account_data
|
||||
.get::<push_rules::PushRulesEvent>(None, &sender_user, EventType::PushRules)?
|
||||
.get::<push_rules::PushRulesEvent>(None, sender_user, EventType::PushRules)?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"PushRules event not found.",
|
||||
|
@ -291,7 +286,7 @@ pub async fn set_pushrule_actions_route(
|
|||
|
||||
let mut event = db
|
||||
.account_data
|
||||
.get::<push_rules::PushRulesEvent>(None, &sender_user, EventType::PushRules)?
|
||||
.get::<push_rules::PushRulesEvent>(None, sender_user, EventType::PushRules)?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"PushRules event not found.",
|
||||
|
@ -332,13 +327,8 @@ pub async fn set_pushrule_actions_route(
|
|||
_ => {}
|
||||
};
|
||||
|
||||
db.account_data.update(
|
||||
None,
|
||||
&sender_user,
|
||||
EventType::PushRules,
|
||||
&event,
|
||||
&db.globals,
|
||||
)?;
|
||||
db.account_data
|
||||
.update(None, sender_user, EventType::PushRules, &event, &db.globals)?;
|
||||
|
||||
db.flush()?;
|
||||
|
||||
|
@ -368,7 +358,7 @@ pub async fn get_pushrule_enabled_route(
|
|||
|
||||
let mut event = db
|
||||
.account_data
|
||||
.get::<push_rules::PushRulesEvent>(None, &sender_user, EventType::PushRules)?
|
||||
.get::<push_rules::PushRulesEvent>(None, sender_user, EventType::PushRules)?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"PushRules event not found.",
|
||||
|
@ -432,7 +422,7 @@ pub async fn set_pushrule_enabled_route(
|
|||
|
||||
let mut event = db
|
||||
.account_data
|
||||
.get::<ruma::events::push_rules::PushRulesEvent>(None, &sender_user, EventType::PushRules)?
|
||||
.get::<ruma::events::push_rules::PushRulesEvent>(None, sender_user, EventType::PushRules)?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"PushRules event not found.",
|
||||
|
@ -478,13 +468,8 @@ pub async fn set_pushrule_enabled_route(
|
|||
_ => {}
|
||||
}
|
||||
|
||||
db.account_data.update(
|
||||
None,
|
||||
&sender_user,
|
||||
EventType::PushRules,
|
||||
&event,
|
||||
&db.globals,
|
||||
)?;
|
||||
db.account_data
|
||||
.update(None, sender_user, EventType::PushRules, &event, &db.globals)?;
|
||||
|
||||
db.flush()?;
|
||||
|
||||
|
@ -514,7 +499,7 @@ pub async fn delete_pushrule_route(
|
|||
|
||||
let mut event = db
|
||||
.account_data
|
||||
.get::<push_rules::PushRulesEvent>(None, &sender_user, EventType::PushRules)?
|
||||
.get::<push_rules::PushRulesEvent>(None, sender_user, EventType::PushRules)?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"PushRules event not found.",
|
||||
|
@ -550,13 +535,8 @@ pub async fn delete_pushrule_route(
|
|||
_ => {}
|
||||
}
|
||||
|
||||
db.account_data.update(
|
||||
None,
|
||||
&sender_user,
|
||||
EventType::PushRules,
|
||||
&event,
|
||||
&db.globals,
|
||||
)?;
|
||||
db.account_data
|
||||
.update(None, sender_user, EventType::PushRules, &event, &db.globals)?;
|
||||
|
||||
db.flush()?;
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ pub async fn set_read_marker_route(
|
|||
};
|
||||
db.account_data.update(
|
||||
Some(&body.room_id),
|
||||
&sender_user,
|
||||
sender_user,
|
||||
EventType::FullyRead,
|
||||
&fully_read_event,
|
||||
&db.globals,
|
||||
|
@ -46,7 +46,7 @@ pub async fn set_read_marker_route(
|
|||
if let Some(event) = &body.read_receipt {
|
||||
db.rooms.edus.private_read_set(
|
||||
&body.room_id,
|
||||
&sender_user,
|
||||
sender_user,
|
||||
db.rooms.get_pdu_count(event)?.ok_or(Error::BadRequest(
|
||||
ErrorKind::InvalidParam,
|
||||
"Event does not exist.",
|
||||
|
@ -54,7 +54,7 @@ pub async fn set_read_marker_route(
|
|||
&db.globals,
|
||||
)?;
|
||||
db.rooms
|
||||
.reset_notification_counts(&sender_user, &body.room_id)?;
|
||||
.reset_notification_counts(sender_user, &body.room_id)?;
|
||||
|
||||
let mut user_receipts = BTreeMap::new();
|
||||
user_receipts.insert(
|
||||
|
@ -71,7 +71,7 @@ pub async fn set_read_marker_route(
|
|||
receipt_content.insert(event.to_owned(), receipts);
|
||||
|
||||
db.rooms.edus.readreceipt_update(
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
AnyEphemeralRoomEvent::Receipt(ruma::events::receipt::ReceiptEvent {
|
||||
content: ruma::events::receipt::ReceiptEventContent(receipt_content),
|
||||
|
@ -102,7 +102,7 @@ pub async fn create_receipt_route(
|
|||
|
||||
db.rooms.edus.private_read_set(
|
||||
&body.room_id,
|
||||
&sender_user,
|
||||
sender_user,
|
||||
db.rooms
|
||||
.get_pdu_count(&body.event_id)?
|
||||
.ok_or(Error::BadRequest(
|
||||
|
@ -112,7 +112,7 @@ pub async fn create_receipt_route(
|
|||
&db.globals,
|
||||
)?;
|
||||
db.rooms
|
||||
.reset_notification_counts(&sender_user, &body.room_id)?;
|
||||
.reset_notification_counts(sender_user, &body.room_id)?;
|
||||
|
||||
let mut user_receipts = BTreeMap::new();
|
||||
user_receipts.insert(
|
||||
|
@ -128,7 +128,7 @@ pub async fn create_receipt_route(
|
|||
receipt_content.insert(body.event_id.to_owned(), receipts);
|
||||
|
||||
db.rooms.edus.readreceipt_update(
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
AnyEphemeralRoomEvent::Receipt(ruma::events::receipt::ReceiptEvent {
|
||||
content: ruma::events::receipt::ReceiptEventContent(receipt_content),
|
||||
|
|
|
@ -46,7 +46,7 @@ pub async fn redact_event_route(
|
|||
state_key: None,
|
||||
redacts: Some(body.event_id.clone()),
|
||||
},
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
&db,
|
||||
&state_lock,
|
||||
|
|
|
@ -106,7 +106,7 @@ pub async fn create_room_route(
|
|||
state_key: Some("".to_owned()),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&state_lock,
|
||||
|
@ -118,11 +118,11 @@ pub async fn create_room_route(
|
|||
event_type: EventType::RoomMember,
|
||||
content: serde_json::to_value(member::MemberEventContent {
|
||||
membership: member::MembershipState::Join,
|
||||
displayname: db.users.displayname(&sender_user)?,
|
||||
avatar_url: db.users.avatar_url(&sender_user)?,
|
||||
displayname: db.users.displayname(sender_user)?,
|
||||
avatar_url: db.users.avatar_url(sender_user)?,
|
||||
is_direct: Some(body.is_direct),
|
||||
third_party_invite: None,
|
||||
blurhash: db.users.blurhash(&sender_user)?,
|
||||
blurhash: db.users.blurhash(sender_user)?,
|
||||
reason: None,
|
||||
})
|
||||
.expect("event is valid, we just created it"),
|
||||
|
@ -130,7 +130,7 @@ pub async fn create_room_route(
|
|||
state_key: Some(sender_user.to_string()),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&state_lock,
|
||||
|
@ -185,7 +185,7 @@ pub async fn create_room_route(
|
|||
state_key: Some("".to_owned()),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&state_lock,
|
||||
|
@ -207,7 +207,7 @@ pub async fn create_room_route(
|
|||
state_key: Some("".to_owned()),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&state_lock,
|
||||
|
@ -235,7 +235,7 @@ pub async fn create_room_route(
|
|||
state_key: Some("".to_owned()),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&state_lock,
|
||||
|
@ -253,7 +253,7 @@ pub async fn create_room_route(
|
|||
state_key: Some("".to_owned()),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&state_lock,
|
||||
|
@ -279,7 +279,7 @@ pub async fn create_room_route(
|
|||
state_key: Some("".to_owned()),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&state_lock,
|
||||
|
@ -298,7 +298,7 @@ pub async fn create_room_route(
|
|||
}
|
||||
|
||||
db.rooms
|
||||
.build_and_append_pdu(pdu_builder, &sender_user, &room_id, &db, &state_lock)?;
|
||||
.build_and_append_pdu(pdu_builder, sender_user, &room_id, &db, &state_lock)?;
|
||||
}
|
||||
|
||||
// 7. Events implied by name and topic
|
||||
|
@ -312,7 +312,7 @@ pub async fn create_room_route(
|
|||
state_key: Some("".to_owned()),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&state_lock,
|
||||
|
@ -331,7 +331,7 @@ pub async fn create_room_route(
|
|||
state_key: Some("".to_owned()),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&state_lock,
|
||||
|
@ -551,11 +551,11 @@ pub async fn upgrade_room_route(
|
|||
event_type: EventType::RoomMember,
|
||||
content: serde_json::to_value(member::MemberEventContent {
|
||||
membership: member::MembershipState::Join,
|
||||
displayname: db.users.displayname(&sender_user)?,
|
||||
avatar_url: db.users.avatar_url(&sender_user)?,
|
||||
displayname: db.users.displayname(sender_user)?,
|
||||
avatar_url: db.users.avatar_url(sender_user)?,
|
||||
is_direct: None,
|
||||
third_party_invite: None,
|
||||
blurhash: db.users.blurhash(&sender_user)?,
|
||||
blurhash: db.users.blurhash(sender_user)?,
|
||||
reason: None,
|
||||
})
|
||||
.expect("event is valid, we just created it"),
|
||||
|
|
|
@ -27,7 +27,7 @@ pub async fn search_events_route(
|
|||
|
||||
let room_ids = filter.rooms.clone().unwrap_or_else(|| {
|
||||
db.rooms
|
||||
.rooms_joined(&sender_user)
|
||||
.rooms_joined(sender_user)
|
||||
.filter_map(|r| r.ok())
|
||||
.collect()
|
||||
});
|
||||
|
@ -88,7 +88,7 @@ pub async fn search_events_route(
|
|||
rank: None,
|
||||
result: db
|
||||
.rooms
|
||||
.get_pdu_from_id(&result)?
|
||||
.get_pdu_from_id(result)?
|
||||
.map(|pdu| pdu.to_room_event()),
|
||||
})
|
||||
})
|
||||
|
|
|
@ -100,8 +100,8 @@ pub async fn login_route(
|
|||
login::IncomingLoginInfo::Token { token } => {
|
||||
if let Some(jwt_decoding_key) = db.globals.jwt_decoding_key() {
|
||||
let token = jsonwebtoken::decode::<Claims>(
|
||||
&token,
|
||||
&jwt_decoding_key,
|
||||
token,
|
||||
jwt_decoding_key,
|
||||
&jsonwebtoken::Validation::default(),
|
||||
)
|
||||
.map_err(|_| Error::BadRequest(ErrorKind::InvalidUsername, "Token is invalid."))?;
|
||||
|
@ -179,7 +179,7 @@ pub async fn logout_route(
|
|||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||
|
||||
db.users.remove_device(&sender_user, sender_device)?;
|
||||
db.users.remove_device(sender_user, sender_device)?;
|
||||
|
||||
db.flush()?;
|
||||
|
||||
|
@ -209,7 +209,7 @@ pub async fn logout_all_route(
|
|||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
for device_id in db.users.all_device_ids(sender_user).flatten() {
|
||||
db.users.remove_device(&sender_user, &device_id)?;
|
||||
db.users.remove_device(sender_user, &device_id)?;
|
||||
}
|
||||
|
||||
db.flush()?;
|
||||
|
|
|
@ -308,9 +308,9 @@ async fn send_state_event_for_key_helper(
|
|||
state_key: Some(state_key),
|
||||
redacts: None,
|
||||
},
|
||||
&sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
sender_user,
|
||||
room_id,
|
||||
db,
|
||||
&state_lock,
|
||||
)?;
|
||||
|
||||
|
|
|
@ -68,8 +68,8 @@ pub async fn send_event_to_device_route(
|
|||
match target_device_id_maybe {
|
||||
DeviceIdOrAllDevices::DeviceId(target_device_id) => db.users.add_to_device_event(
|
||||
sender_user,
|
||||
&target_user_id,
|
||||
&target_device_id,
|
||||
target_user_id,
|
||||
target_device_id,
|
||||
&body.event_type,
|
||||
event.deserialize_as().map_err(|_| {
|
||||
Error::BadRequest(ErrorKind::InvalidParam, "Event is invalid")
|
||||
|
@ -78,10 +78,10 @@ pub async fn send_event_to_device_route(
|
|||
)?,
|
||||
|
||||
DeviceIdOrAllDevices::AllDevices => {
|
||||
for target_device_id in db.users.all_device_ids(&target_user_id) {
|
||||
for target_device_id in db.users.all_device_ids(target_user_id) {
|
||||
db.users.add_to_device_event(
|
||||
sender_user,
|
||||
&target_user_id,
|
||||
target_user_id,
|
||||
&target_device_id?,
|
||||
&body.event_type,
|
||||
event.deserialize_as().map_err(|_| {
|
||||
|
|
|
@ -21,7 +21,7 @@ pub fn create_typing_event_route(
|
|||
|
||||
if let Typing::Yes(duration) = body.state {
|
||||
db.rooms.edus.typing_add(
|
||||
&sender_user,
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
duration.as_millis() as u64 + utils::millis_since_unix_epoch(),
|
||||
&db.globals,
|
||||
|
@ -29,7 +29,7 @@ pub fn create_typing_event_route(
|
|||
} else {
|
||||
db.rooms
|
||||
.edus
|
||||
.typing_remove(&sender_user, &body.room_id, &db.globals)?;
|
||||
.typing_remove(sender_user, &body.room_id, &db.globals)?;
|
||||
}
|
||||
|
||||
Ok(create_typing_event::Response {}.into())
|
||||
|
|
|
@ -196,14 +196,14 @@ impl Database {
|
|||
|
||||
/// Load an existing database or create a new one.
|
||||
pub async fn load_or_create(config: &Config) -> Result<Arc<TokioRwLock<Self>>> {
|
||||
Self::check_sled_or_sqlite_db(&config)?;
|
||||
Self::check_sled_or_sqlite_db(config)?;
|
||||
|
||||
if !Path::new(&config.database_path).exists() {
|
||||
std::fs::create_dir_all(&config.database_path)
|
||||
.map_err(|_| Error::BadConfig("Database folder doesn't exists and couldn't be created (e.g. due to missing permissions). Please create the database folder yourself."))?;
|
||||
}
|
||||
|
||||
let builder = Engine::open(&config)?;
|
||||
let builder = Engine::open(config)?;
|
||||
|
||||
if config.max_request_size < 1024 {
|
||||
eprintln!("ERROR: Max request size is less than 1KB. Please increase it.");
|
||||
|
@ -618,7 +618,7 @@ impl Database {
|
|||
let short_room_id = db
|
||||
.rooms
|
||||
.roomid_shortroomid
|
||||
.get(&room_id)
|
||||
.get(room_id)
|
||||
.unwrap()
|
||||
.expect("shortroomid should exist");
|
||||
|
||||
|
@ -641,7 +641,7 @@ impl Database {
|
|||
let short_room_id = db
|
||||
.rooms
|
||||
.roomid_shortroomid
|
||||
.get(&room_id)
|
||||
.get(room_id)
|
||||
.unwrap()
|
||||
.expect("shortroomid should exist");
|
||||
|
||||
|
@ -677,7 +677,7 @@ impl Database {
|
|||
let short_room_id = db
|
||||
.rooms
|
||||
.roomid_shortroomid
|
||||
.get(&room_id)
|
||||
.get(room_id)
|
||||
.unwrap()
|
||||
.expect("shortroomid should exist");
|
||||
let mut new_key = short_room_id;
|
||||
|
@ -757,7 +757,7 @@ impl Database {
|
|||
|
||||
#[cfg(feature = "sqlite")]
|
||||
{
|
||||
Self::start_wal_clean_task(Arc::clone(&db), &config).await;
|
||||
Self::start_wal_clean_task(Arc::clone(&db), config).await;
|
||||
}
|
||||
|
||||
Ok(db)
|
||||
|
@ -964,7 +964,7 @@ impl<'r> FromRequest<'r> for DatabaseGuard {
|
|||
async fn from_request(req: &'r Request<'_>) -> rocket::request::Outcome<Self, ()> {
|
||||
let db = try_outcome!(req.guard::<&State<Arc<TokioRwLock<Database>>>>().await);
|
||||
|
||||
Ok(DatabaseGuard(Arc::clone(&db).read_owned().await)).or_forward(())
|
||||
Ok(DatabaseGuard(Arc::clone(db).read_owned().await)).or_forward(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ impl SqliteTable {
|
|||
impl Tree for SqliteTable {
|
||||
#[tracing::instrument(skip(self, key))]
|
||||
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>> {
|
||||
self.get_with_guard(&self.engine.read_lock(), key)
|
||||
self.get_with_guard(self.engine.read_lock(), key)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, key, value))]
|
||||
|
@ -275,7 +275,7 @@ impl Tree for SqliteTable {
|
|||
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = TupleOfBytes> + 'a> {
|
||||
let guard = self.engine.read_lock_iterator();
|
||||
|
||||
self.iter_with_guard(&guard)
|
||||
self.iter_with_guard(guard)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, from, backwards))]
|
||||
|
|
|
@ -32,13 +32,13 @@ impl AccountData {
|
|||
.as_bytes()
|
||||
.to_vec();
|
||||
prefix.push(0xff);
|
||||
prefix.extend_from_slice(&user_id.as_bytes());
|
||||
prefix.extend_from_slice(user_id.as_bytes());
|
||||
prefix.push(0xff);
|
||||
|
||||
let mut roomuserdataid = prefix.clone();
|
||||
roomuserdataid.extend_from_slice(&globals.next_count()?.to_be_bytes());
|
||||
roomuserdataid.push(0xff);
|
||||
roomuserdataid.extend_from_slice(&event_type.as_bytes());
|
||||
roomuserdataid.extend_from_slice(event_type.as_bytes());
|
||||
|
||||
let mut key = prefix;
|
||||
key.extend_from_slice(event_type.as_bytes());
|
||||
|
@ -83,7 +83,7 @@ impl AccountData {
|
|||
.as_bytes()
|
||||
.to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&user_id.as_bytes());
|
||||
key.extend_from_slice(user_id.as_bytes());
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(kind.as_ref().as_bytes());
|
||||
|
||||
|
@ -118,7 +118,7 @@ impl AccountData {
|
|||
.as_bytes()
|
||||
.to_vec();
|
||||
prefix.push(0xff);
|
||||
prefix.extend_from_slice(&user_id.as_bytes());
|
||||
prefix.extend_from_slice(user_id.as_bytes());
|
||||
prefix.push(0xff);
|
||||
|
||||
// Skip the data that's exactly at since, because we sent that last time
|
||||
|
|
|
@ -113,7 +113,7 @@ impl Globals {
|
|||
.map(|key| (version, key))
|
||||
})
|
||||
.and_then(|(version, key)| {
|
||||
ruma::signatures::Ed25519KeyPair::from_der(&key, version)
|
||||
ruma::signatures::Ed25519KeyPair::from_der(key, version)
|
||||
.map_err(|_| Error::bad_database("Private or public keys are invalid."))
|
||||
});
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ impl KeyBackups {
|
|||
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&version.as_bytes());
|
||||
key.extend_from_slice(version.as_bytes());
|
||||
|
||||
self.backupid_algorithm.insert(
|
||||
&key,
|
||||
|
@ -41,7 +41,7 @@ impl KeyBackups {
|
|||
pub fn delete_backup(&self, user_id: &UserId, version: &str) -> Result<()> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&version.as_bytes());
|
||||
key.extend_from_slice(version.as_bytes());
|
||||
|
||||
self.backupid_algorithm.remove(&key)?;
|
||||
self.backupid_etag.remove(&key)?;
|
||||
|
@ -64,7 +64,7 @@ impl KeyBackups {
|
|||
) -> Result<String> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&version.as_bytes());
|
||||
key.extend_from_slice(version.as_bytes());
|
||||
|
||||
if self.backupid_algorithm.get(&key)?.is_none() {
|
||||
return Err(Error::BadRequest(
|
||||
|
@ -75,7 +75,7 @@ impl KeyBackups {
|
|||
|
||||
self.backupid_algorithm.insert(
|
||||
&key,
|
||||
&serde_json::to_string(backup_metadata)
|
||||
serde_json::to_string(backup_metadata)
|
||||
.expect("BackupAlgorithm::to_string always works")
|
||||
.as_bytes(),
|
||||
)?;
|
||||
|
@ -192,7 +192,7 @@ impl KeyBackups {
|
|||
pub fn get_etag(&self, user_id: &UserId, version: &str) -> Result<String> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&version.as_bytes());
|
||||
key.extend_from_slice(version.as_bytes());
|
||||
|
||||
Ok(utils::u64_from_bytes(
|
||||
&self
|
||||
|
@ -223,7 +223,7 @@ impl KeyBackups {
|
|||
let mut parts = key.rsplit(|&b| b == 0xff);
|
||||
|
||||
let session_id =
|
||||
utils::string_from_bytes(&parts.next().ok_or_else(|| {
|
||||
utils::string_from_bytes(parts.next().ok_or_else(|| {
|
||||
Error::bad_database("backupkeyid_backup key is invalid.")
|
||||
})?)
|
||||
.map_err(|_| {
|
||||
|
@ -231,7 +231,7 @@ impl KeyBackups {
|
|||
})?;
|
||||
|
||||
let room_id = RoomId::try_from(
|
||||
utils::string_from_bytes(&parts.next().ok_or_else(|| {
|
||||
utils::string_from_bytes(parts.next().ok_or_else(|| {
|
||||
Error::bad_database("backupkeyid_backup key is invalid.")
|
||||
})?)
|
||||
.map_err(|_| Error::bad_database("backupkeyid_backup room_id is invalid."))?,
|
||||
|
@ -280,7 +280,7 @@ impl KeyBackups {
|
|||
let mut parts = key.rsplit(|&b| b == 0xff);
|
||||
|
||||
let session_id =
|
||||
utils::string_from_bytes(&parts.next().ok_or_else(|| {
|
||||
utils::string_from_bytes(parts.next().ok_or_else(|| {
|
||||
Error::bad_database("backupkeyid_backup key is invalid.")
|
||||
})?)
|
||||
.map_err(|_| {
|
||||
|
@ -325,7 +325,7 @@ impl KeyBackups {
|
|||
pub fn delete_all_keys(&self, user_id: &UserId, version: &str) -> Result<()> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&version.as_bytes());
|
||||
key.extend_from_slice(version.as_bytes());
|
||||
key.push(0xff);
|
||||
|
||||
for (outdated_key, _) in self.backupkeyid_backup.scan_prefix(key) {
|
||||
|
@ -343,9 +343,9 @@ impl KeyBackups {
|
|||
) -> Result<()> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&version.as_bytes());
|
||||
key.extend_from_slice(version.as_bytes());
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&room_id.as_bytes());
|
||||
key.extend_from_slice(room_id.as_bytes());
|
||||
key.push(0xff);
|
||||
|
||||
for (outdated_key, _) in self.backupkeyid_backup.scan_prefix(key) {
|
||||
|
@ -364,11 +364,11 @@ impl KeyBackups {
|
|||
) -> Result<()> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&version.as_bytes());
|
||||
key.extend_from_slice(version.as_bytes());
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&room_id.as_bytes());
|
||||
key.extend_from_slice(room_id.as_bytes());
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&session_id.as_bytes());
|
||||
key.extend_from_slice(session_id.as_bytes());
|
||||
|
||||
for (outdated_key, _) in self.backupkeyid_backup.scan_prefix(key) {
|
||||
self.backupkeyid_backup.remove(&outdated_key)?;
|
||||
|
|
|
@ -4,7 +4,10 @@ use image::{imageops::FilterType, GenericImageView};
|
|||
use super::abstraction::Tree;
|
||||
use crate::{utils, Error, Result};
|
||||
use std::{mem, sync::Arc};
|
||||
use tokio::{fs::File, io::AsyncReadExt, io::AsyncWriteExt};
|
||||
use tokio::{
|
||||
fs::File,
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
};
|
||||
|
||||
pub struct FileMeta {
|
||||
pub content_disposition: Option<String>,
|
||||
|
|
|
@ -236,7 +236,7 @@ pub fn get_actions<'a>(
|
|||
member_count: 10_u32.into(), // TODO: get member count efficiently
|
||||
user_display_name: db
|
||||
.users
|
||||
.displayname(&user)?
|
||||
.displayname(user)?
|
||||
.unwrap_or_else(|| user.localpart().to_owned()),
|
||||
users_power_levels: power_levels.users.clone(),
|
||||
default_power_level: power_levels.users_default,
|
||||
|
@ -302,7 +302,7 @@ async fn send_notice(
|
|||
if event_id_only {
|
||||
send_request(
|
||||
&db.globals,
|
||||
&url,
|
||||
url,
|
||||
send_event_notification::v1::Request::new(notifi),
|
||||
)
|
||||
.await?;
|
||||
|
@ -332,7 +332,7 @@ async fn send_notice(
|
|||
|
||||
send_request(
|
||||
&db.globals,
|
||||
&url,
|
||||
url,
|
||||
send_event_notification::v1::Request::new(notifi),
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -252,7 +252,7 @@ impl Rooms {
|
|||
return Ok(HashMap::new());
|
||||
};
|
||||
|
||||
let auth_events = state_res::auth_types_for_event(kind, sender, state_key, &content);
|
||||
let auth_events = state_res::auth_types_for_event(kind, sender, state_key, content);
|
||||
|
||||
let mut sauthevents = auth_events
|
||||
.into_iter()
|
||||
|
@ -339,7 +339,7 @@ impl Rooms {
|
|||
new_state_ids_compressed: HashSet<CompressedStateEvent>,
|
||||
db: &Database,
|
||||
) -> Result<()> {
|
||||
let previous_shortstatehash = self.current_shortstatehash(&room_id)?;
|
||||
let previous_shortstatehash = self.current_shortstatehash(room_id)?;
|
||||
|
||||
let state_hash = self.calculate_hash(
|
||||
&new_state_ids_compressed
|
||||
|
@ -424,7 +424,7 @@ impl Rooms {
|
|||
}
|
||||
}
|
||||
|
||||
self.update_joined_count(room_id, &db)?;
|
||||
self.update_joined_count(room_id, db)?;
|
||||
|
||||
self.roomid_shortstatehash
|
||||
.insert(room_id.as_bytes(), &new_shortstatehash.to_be_bytes())?;
|
||||
|
@ -704,7 +704,7 @@ impl Rooms {
|
|||
event_id: &EventId,
|
||||
globals: &super::globals::Globals,
|
||||
) -> Result<u64> {
|
||||
if let Some(short) = self.eventidshort_cache.lock().unwrap().get_mut(&event_id) {
|
||||
if let Some(short) = self.eventidshort_cache.lock().unwrap().get_mut(event_id) {
|
||||
return Ok(*short);
|
||||
}
|
||||
|
||||
|
@ -732,7 +732,7 @@ impl Rooms {
|
|||
#[tracing::instrument(skip(self))]
|
||||
pub fn get_shortroomid(&self, room_id: &RoomId) -> Result<Option<u64>> {
|
||||
self.roomid_shortroomid
|
||||
.get(&room_id.as_bytes())?
|
||||
.get(room_id.as_bytes())?
|
||||
.map(|bytes| {
|
||||
utils::u64_from_bytes(&bytes)
|
||||
.map_err(|_| Error::bad_database("Invalid shortroomid in db."))
|
||||
|
@ -757,7 +757,7 @@ impl Rooms {
|
|||
|
||||
let mut statekey = event_type.as_ref().as_bytes().to_vec();
|
||||
statekey.push(0xff);
|
||||
statekey.extend_from_slice(&state_key.as_bytes());
|
||||
statekey.extend_from_slice(state_key.as_bytes());
|
||||
|
||||
let short = self
|
||||
.statekey_shortstatekey
|
||||
|
@ -784,13 +784,13 @@ impl Rooms {
|
|||
room_id: &RoomId,
|
||||
globals: &super::globals::Globals,
|
||||
) -> Result<u64> {
|
||||
Ok(match self.roomid_shortroomid.get(&room_id.as_bytes())? {
|
||||
Ok(match self.roomid_shortroomid.get(room_id.as_bytes())? {
|
||||
Some(short) => utils::u64_from_bytes(&short)
|
||||
.map_err(|_| Error::bad_database("Invalid shortroomid in db."))?,
|
||||
None => {
|
||||
let short = globals.next_count()?;
|
||||
self.roomid_shortroomid
|
||||
.insert(&room_id.as_bytes(), &short.to_be_bytes())?;
|
||||
.insert(room_id.as_bytes(), &short.to_be_bytes())?;
|
||||
short
|
||||
}
|
||||
})
|
||||
|
@ -814,7 +814,7 @@ impl Rooms {
|
|||
|
||||
let mut statekey = event_type.as_ref().as_bytes().to_vec();
|
||||
statekey.push(0xff);
|
||||
statekey.extend_from_slice(&state_key.as_bytes());
|
||||
statekey.extend_from_slice(state_key.as_bytes());
|
||||
|
||||
let short = match self.statekey_shortstatekey.get(&statekey)? {
|
||||
Some(shortstatekey) => utils::u64_from_bytes(&shortstatekey)
|
||||
|
@ -891,12 +891,12 @@ impl Rooms {
|
|||
.ok_or_else(|| Error::bad_database("Invalid statekey in shortstatekey_statekey."))?;
|
||||
|
||||
let event_type =
|
||||
EventType::try_from(utils::string_from_bytes(&eventtype_bytes).map_err(|_| {
|
||||
EventType::try_from(utils::string_from_bytes(eventtype_bytes).map_err(|_| {
|
||||
Error::bad_database("Event type in shortstatekey_statekey is invalid unicode.")
|
||||
})?)
|
||||
.map_err(|_| Error::bad_database("Event type in shortstatekey_statekey is invalid."))?;
|
||||
|
||||
let state_key = utils::string_from_bytes(&statekey_bytes).map_err(|_| {
|
||||
let state_key = utils::string_from_bytes(statekey_bytes).map_err(|_| {
|
||||
Error::bad_database("Statekey in shortstatekey_statekey is invalid unicode.")
|
||||
})?;
|
||||
|
||||
|
@ -956,10 +956,8 @@ impl Rooms {
|
|||
/// Returns the `count` of this pdu's id.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn pdu_count(&self, pdu_id: &[u8]) -> Result<u64> {
|
||||
Ok(
|
||||
utils::u64_from_bytes(&pdu_id[pdu_id.len() - size_of::<u64>()..])
|
||||
.map_err(|_| Error::bad_database("PDU has invalid count bytes."))?,
|
||||
)
|
||||
.map_err(|_| Error::bad_database("PDU has invalid count bytes."))
|
||||
}
|
||||
|
||||
/// Returns the `count` of this pdu's id.
|
||||
|
@ -1076,7 +1074,7 @@ impl Rooms {
|
|||
/// Checks the `eventid_outlierpdu` Tree if not found in the timeline.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn get_pdu(&self, event_id: &EventId) -> Result<Option<Arc<PduEvent>>> {
|
||||
if let Some(p) = self.pdu_cache.lock().unwrap().get_mut(&event_id) {
|
||||
if let Some(p) = self.pdu_cache.lock().unwrap().get_mut(event_id) {
|
||||
return Ok(Some(Arc::clone(p)));
|
||||
}
|
||||
|
||||
|
@ -1138,9 +1136,9 @@ impl Rooms {
|
|||
/// Removes a pdu and creates a new one with the same id.
|
||||
#[tracing::instrument(skip(self))]
|
||||
fn replace_pdu(&self, pdu_id: &[u8], pdu: &PduEvent) -> Result<()> {
|
||||
if self.pduid_pdu.get(&pdu_id)?.is_some() {
|
||||
if self.pduid_pdu.get(pdu_id)?.is_some() {
|
||||
self.pduid_pdu.insert(
|
||||
&pdu_id,
|
||||
pdu_id,
|
||||
&serde_json::to_vec(pdu).expect("PduEvent::to_vec always works"),
|
||||
)?;
|
||||
Ok(())
|
||||
|
@ -1225,20 +1223,20 @@ impl Rooms {
|
|||
#[tracing::instrument(skip(self, pdu))]
|
||||
pub fn add_pdu_outlier(&self, event_id: &EventId, pdu: &CanonicalJsonObject) -> Result<()> {
|
||||
self.eventid_outlierpdu.insert(
|
||||
&event_id.as_bytes(),
|
||||
event_id.as_bytes(),
|
||||
&serde_json::to_vec(&pdu).expect("CanonicalJsonObject is valid"),
|
||||
)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn mark_event_soft_failed(&self, event_id: &EventId) -> Result<()> {
|
||||
self.softfailedeventids.insert(&event_id.as_bytes(), &[])
|
||||
self.softfailedeventids.insert(event_id.as_bytes(), &[])
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn is_event_soft_failed(&self, event_id: &EventId) -> Result<bool> {
|
||||
self.softfailedeventids
|
||||
.get(&event_id.as_bytes())
|
||||
.get(event_id.as_bytes())
|
||||
.map(|o| o.is_some())
|
||||
}
|
||||
|
||||
|
@ -1268,7 +1266,7 @@ impl Rooms {
|
|||
{
|
||||
if let Some(shortstatehash) = self.pdu_shortstatehash(&pdu.event_id).unwrap() {
|
||||
if let Some(prev_state) = self
|
||||
.state_get(shortstatehash, &pdu.kind, &state_key)
|
||||
.state_get(shortstatehash, &pdu.kind, state_key)
|
||||
.unwrap()
|
||||
{
|
||||
unsigned.insert(
|
||||
|
@ -1350,15 +1348,15 @@ impl Rooms {
|
|||
|
||||
let rules_for_user = db
|
||||
.account_data
|
||||
.get::<push_rules::PushRulesEvent>(None, &user, EventType::PushRules)?
|
||||
.get::<push_rules::PushRulesEvent>(None, user, EventType::PushRules)?
|
||||
.map(|ev| ev.content.global)
|
||||
.unwrap_or_else(|| push::Ruleset::server_default(&user));
|
||||
.unwrap_or_else(|| push::Ruleset::server_default(user));
|
||||
|
||||
let mut highlight = false;
|
||||
let mut notify = false;
|
||||
|
||||
for action in pusher::get_actions(
|
||||
&user,
|
||||
user,
|
||||
&rules_for_user,
|
||||
&power_levels,
|
||||
&sync_pdu,
|
||||
|
@ -1388,7 +1386,7 @@ impl Rooms {
|
|||
highlights.push(userroom_id);
|
||||
}
|
||||
|
||||
for senderkey in db.pusher.get_pusher_senderkeys(&user) {
|
||||
for senderkey in db.pusher.get_pusher_senderkeys(user) {
|
||||
db.sending.send_push_pdu(&*pdu_id, senderkey)?;
|
||||
}
|
||||
}
|
||||
|
@ -1401,7 +1399,7 @@ impl Rooms {
|
|||
match pdu.kind {
|
||||
EventType::RoomRedaction => {
|
||||
if let Some(redact_id) = &pdu.redacts {
|
||||
self.redact_pdu(&redact_id, &pdu)?;
|
||||
self.redact_pdu(redact_id, pdu)?;
|
||||
}
|
||||
}
|
||||
EventType::RoomMember => {
|
||||
|
@ -1741,9 +1739,9 @@ impl Rooms {
|
|||
state_ids_compressed: HashSet<CompressedStateEvent>,
|
||||
globals: &super::globals::Globals,
|
||||
) -> Result<()> {
|
||||
let shorteventid = self.get_or_create_shorteventid(&event_id, globals)?;
|
||||
let shorteventid = self.get_or_create_shorteventid(event_id, globals)?;
|
||||
|
||||
let previous_shortstatehash = self.current_shortstatehash(&room_id)?;
|
||||
let previous_shortstatehash = self.current_shortstatehash(room_id)?;
|
||||
|
||||
let state_hash = self.calculate_hash(
|
||||
&state_ids_compressed
|
||||
|
@ -1815,7 +1813,7 @@ impl Rooms {
|
|||
.map_or_else(|| Ok(Vec::new()), |p| self.load_shortstatehash_info(p))?;
|
||||
|
||||
let shortstatekey =
|
||||
self.get_or_create_shortstatekey(&new_pdu.kind, &state_key, globals)?;
|
||||
self.get_or_create_shortstatekey(&new_pdu.kind, state_key, globals)?;
|
||||
|
||||
let new = self.compress_state_event(shortstatekey, &new_pdu.event_id, globals)?;
|
||||
|
||||
|
@ -1840,7 +1838,7 @@ impl Rooms {
|
|||
|
||||
let mut statediffremoved = HashSet::new();
|
||||
if let Some(replaces) = replaces {
|
||||
statediffremoved.insert(replaces.clone());
|
||||
statediffremoved.insert(*replaces);
|
||||
}
|
||||
|
||||
self.save_state_from_diff(
|
||||
|
@ -1953,12 +1951,12 @@ impl Rooms {
|
|||
} = pdu_builder;
|
||||
|
||||
let prev_events = self
|
||||
.get_pdu_leaves(&room_id)?
|
||||
.get_pdu_leaves(room_id)?
|
||||
.into_iter()
|
||||
.take(20)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let create_event = self.room_state_get(&room_id, &EventType::RoomCreate, "")?;
|
||||
let create_event = self.room_state_get(room_id, &EventType::RoomCreate, "")?;
|
||||
|
||||
let create_event_content = create_event
|
||||
.as_ref()
|
||||
|
@ -1988,13 +1986,8 @@ impl Rooms {
|
|||
});
|
||||
let room_version = RoomVersion::new(&room_version_id).expect("room version is supported");
|
||||
|
||||
let auth_events = self.get_auth_events(
|
||||
&room_id,
|
||||
&event_type,
|
||||
&sender,
|
||||
state_key.as_deref(),
|
||||
&content,
|
||||
)?;
|
||||
let auth_events =
|
||||
self.get_auth_events(room_id, &event_type, sender, state_key.as_deref(), &content)?;
|
||||
|
||||
// Our depth is the maximum depth of prev_events + 1
|
||||
let depth = prev_events
|
||||
|
@ -2006,7 +1999,7 @@ impl Rooms {
|
|||
|
||||
let mut unsigned = unsigned.unwrap_or_default();
|
||||
if let Some(state_key) = &state_key {
|
||||
if let Some(prev_pdu) = self.room_state_get(&room_id, &event_type, &state_key)? {
|
||||
if let Some(prev_pdu) = self.room_state_get(room_id, &event_type, state_key)? {
|
||||
unsigned.insert("prev_content".to_owned(), prev_pdu.content.clone());
|
||||
unsigned.insert(
|
||||
"prev_sender".to_owned(),
|
||||
|
@ -2109,7 +2102,7 @@ impl Rooms {
|
|||
|
||||
// We set the room state after inserting the pdu, so that we never have a moment in time
|
||||
// where events in the current room state do not exist
|
||||
self.set_room_state(&room_id, statehashid)?;
|
||||
self.set_room_state(room_id, statehashid)?;
|
||||
|
||||
for server in self
|
||||
.room_servers(room_id)
|
||||
|
@ -2154,10 +2147,10 @@ impl Rooms {
|
|||
&& pdu
|
||||
.state_key
|
||||
.as_ref()
|
||||
.map_or(false, |state_key| users.is_match(&state_key))
|
||||
.map_or(false, |state_key| users.is_match(state_key))
|
||||
};
|
||||
let matching_aliases = |aliases: &Regex| {
|
||||
self.room_aliases(&room_id)
|
||||
self.room_aliases(room_id)
|
||||
.filter_map(|r| r.ok())
|
||||
.any(|room_alias| aliases.is_match(room_alias.as_str()))
|
||||
};
|
||||
|
@ -2300,7 +2293,7 @@ impl Rooms {
|
|||
let mut pdu = self
|
||||
.get_pdu_from_id(&pdu_id)?
|
||||
.ok_or_else(|| Error::bad_database("PDU ID points to invalid PDU."))?;
|
||||
pdu.redact(&reason)?;
|
||||
pdu.redact(reason)?;
|
||||
self.replace_pdu(&pdu_id, &pdu)?;
|
||||
Ok(())
|
||||
} else {
|
||||
|
@ -2348,13 +2341,13 @@ impl Rooms {
|
|||
match &membership {
|
||||
member::MembershipState::Join => {
|
||||
// Check if the user never joined this room
|
||||
if !self.once_joined(&user_id, &room_id)? {
|
||||
if !self.once_joined(user_id, room_id)? {
|
||||
// Add the user ID to the join list then
|
||||
self.roomuseroncejoinedids.insert(&userroom_id, &[])?;
|
||||
|
||||
// Check if the room has a predecessor
|
||||
if let Some(predecessor) = self
|
||||
.room_state_get(&room_id, &EventType::RoomCreate, "")?
|
||||
.room_state_get(room_id, &EventType::RoomCreate, "")?
|
||||
.and_then(|create| {
|
||||
serde_json::from_value::<
|
||||
Raw<ruma::events::room::create::CreateEventContent>,
|
||||
|
@ -2456,11 +2449,11 @@ impl Rooms {
|
|||
.account_data
|
||||
.get::<ignored_user_list::IgnoredUserListEvent>(
|
||||
None, // Ignored users are in global account data
|
||||
&user_id, // Receiver
|
||||
user_id, // Receiver
|
||||
EventType::IgnoredUserList,
|
||||
)?
|
||||
.map_or(false, |ignored| {
|
||||
ignored.content.ignored_users.contains(&sender)
|
||||
ignored.content.ignored_users.contains(sender)
|
||||
});
|
||||
|
||||
if is_ignored {
|
||||
|
@ -2522,7 +2515,7 @@ impl Rooms {
|
|||
let mut joined_servers = HashSet::new();
|
||||
let mut real_users = HashSet::new();
|
||||
|
||||
for joined in self.room_members(&room_id).filter_map(|r| r.ok()) {
|
||||
for joined in self.room_members(room_id).filter_map(|r| r.ok()) {
|
||||
joined_servers.insert(joined.server_name().to_owned());
|
||||
if joined.server_name() == db.globals.server_name()
|
||||
&& !db.users.is_deactivated(&joined).unwrap_or(true)
|
||||
|
@ -2532,7 +2525,7 @@ impl Rooms {
|
|||
joinedcount += 1;
|
||||
}
|
||||
|
||||
for invited in self.room_members_invited(&room_id).filter_map(|r| r.ok()) {
|
||||
for invited in self.room_members_invited(room_id).filter_map(|r| r.ok()) {
|
||||
joined_servers.insert(invited.server_name().to_owned());
|
||||
invitedcount += 1;
|
||||
}
|
||||
|
@ -2601,7 +2594,7 @@ impl Rooms {
|
|||
if let Some(users) = maybe {
|
||||
Ok(users)
|
||||
} else {
|
||||
self.update_joined_count(room_id, &db)?;
|
||||
self.update_joined_count(room_id, db)?;
|
||||
Ok(Arc::clone(
|
||||
self.our_real_users_cache
|
||||
.read()
|
||||
|
@ -2650,7 +2643,7 @@ impl Rooms {
|
|||
|
||||
let in_room = bridge_user_id
|
||||
.map_or(false, |id| self.is_joined(&id, room_id).unwrap_or(false))
|
||||
|| self.room_members(&room_id).any(|userid| {
|
||||
|| self.room_members(room_id).any(|userid| {
|
||||
userid.map_or(false, |userid| {
|
||||
users.iter().any(|r| r.is_match(userid.as_str()))
|
||||
})
|
||||
|
@ -2890,21 +2883,21 @@ impl Rooms {
|
|||
if let Some(room_id) = room_id {
|
||||
// New alias
|
||||
self.alias_roomid
|
||||
.insert(&alias.alias().as_bytes(), room_id.as_bytes())?;
|
||||
.insert(alias.alias().as_bytes(), room_id.as_bytes())?;
|
||||
let mut aliasid = room_id.as_bytes().to_vec();
|
||||
aliasid.push(0xff);
|
||||
aliasid.extend_from_slice(&globals.next_count()?.to_be_bytes());
|
||||
self.aliasid_alias.insert(&aliasid, &*alias.as_bytes())?;
|
||||
} else {
|
||||
// room_id=None means remove alias
|
||||
if let Some(room_id) = self.alias_roomid.get(&alias.alias().as_bytes())? {
|
||||
if let Some(room_id) = self.alias_roomid.get(alias.alias().as_bytes())? {
|
||||
let mut prefix = room_id.to_vec();
|
||||
prefix.push(0xff);
|
||||
|
||||
for (key, _) in self.aliasid_alias.scan_prefix(prefix) {
|
||||
self.aliasid_alias.remove(&key)?;
|
||||
}
|
||||
self.alias_roomid.remove(&alias.alias().as_bytes())?;
|
||||
self.alias_roomid.remove(alias.alias().as_bytes())?;
|
||||
} else {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
|
@ -3077,7 +3070,7 @@ impl Rooms {
|
|||
self.roomserverids.scan_prefix(prefix).map(|(key, _)| {
|
||||
Box::<ServerName>::try_from(
|
||||
utils::string_from_bytes(
|
||||
&key.rsplit(|&b| b == 0xff)
|
||||
key.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.expect("rsplit always returns an element"),
|
||||
)
|
||||
|
@ -3110,7 +3103,7 @@ impl Rooms {
|
|||
self.serverroomids.scan_prefix(prefix).map(|(key, _)| {
|
||||
RoomId::try_from(
|
||||
utils::string_from_bytes(
|
||||
&key.rsplit(|&b| b == 0xff)
|
||||
key.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.expect("rsplit always returns an element"),
|
||||
)
|
||||
|
@ -3132,7 +3125,7 @@ impl Rooms {
|
|||
self.roomuserid_joined.scan_prefix(prefix).map(|(key, _)| {
|
||||
UserId::try_from(
|
||||
utils::string_from_bytes(
|
||||
&key.rsplit(|&b| b == 0xff)
|
||||
key.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.expect("rsplit always returns an element"),
|
||||
)
|
||||
|
@ -3146,26 +3139,24 @@ impl Rooms {
|
|||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn room_joined_count(&self, room_id: &RoomId) -> Result<Option<u64>> {
|
||||
Ok(self
|
||||
.roomid_joinedcount
|
||||
self.roomid_joinedcount
|
||||
.get(room_id.as_bytes())?
|
||||
.map(|b| {
|
||||
utils::u64_from_bytes(&b)
|
||||
.map_err(|_| Error::bad_database("Invalid joinedcount in db."))
|
||||
})
|
||||
.transpose()?)
|
||||
.transpose()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn room_invited_count(&self, room_id: &RoomId) -> Result<Option<u64>> {
|
||||
Ok(self
|
||||
.roomid_invitedcount
|
||||
self.roomid_invitedcount
|
||||
.get(room_id.as_bytes())?
|
||||
.map(|b| {
|
||||
utils::u64_from_bytes(&b)
|
||||
.map_err(|_| Error::bad_database("Invalid joinedcount in db."))
|
||||
})
|
||||
.transpose()?)
|
||||
.transpose()
|
||||
}
|
||||
|
||||
/// Returns an iterator over all User IDs who ever joined a room.
|
||||
|
@ -3182,7 +3173,7 @@ impl Rooms {
|
|||
.map(|(key, _)| {
|
||||
UserId::try_from(
|
||||
utils::string_from_bytes(
|
||||
&key.rsplit(|&b| b == 0xff)
|
||||
key.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.expect("rsplit always returns an element"),
|
||||
)
|
||||
|
@ -3208,7 +3199,7 @@ impl Rooms {
|
|||
.map(|(key, _)| {
|
||||
UserId::try_from(
|
||||
utils::string_from_bytes(
|
||||
&key.rsplit(|&b| b == 0xff)
|
||||
key.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.expect("rsplit always returns an element"),
|
||||
)
|
||||
|
@ -3261,7 +3252,7 @@ impl Rooms {
|
|||
.map(|(key, _)| {
|
||||
RoomId::try_from(
|
||||
utils::string_from_bytes(
|
||||
&key.rsplit(|&b| b == 0xff)
|
||||
key.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.expect("rsplit always returns an element"),
|
||||
)
|
||||
|
@ -3287,7 +3278,7 @@ impl Rooms {
|
|||
.map(|(key, state)| {
|
||||
let room_id = RoomId::try_from(
|
||||
utils::string_from_bytes(
|
||||
&key.rsplit(|&b| b == 0xff)
|
||||
key.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.expect("rsplit always returns an element"),
|
||||
)
|
||||
|
@ -3312,7 +3303,7 @@ impl Rooms {
|
|||
) -> Result<Option<Vec<Raw<AnyStrippedStateEvent>>>> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&room_id.as_bytes());
|
||||
key.extend_from_slice(room_id.as_bytes());
|
||||
|
||||
self.userroomid_invitestate
|
||||
.get(&key)?
|
||||
|
@ -3333,7 +3324,7 @@ impl Rooms {
|
|||
) -> Result<Option<Vec<Raw<AnyStrippedStateEvent>>>> {
|
||||
let mut key = user_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&room_id.as_bytes());
|
||||
key.extend_from_slice(room_id.as_bytes());
|
||||
|
||||
self.userroomid_leftstate
|
||||
.get(&key)?
|
||||
|
@ -3360,7 +3351,7 @@ impl Rooms {
|
|||
.map(|(key, state)| {
|
||||
let room_id = RoomId::try_from(
|
||||
utils::string_from_bytes(
|
||||
&key.rsplit(|&b| b == 0xff)
|
||||
key.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.expect("rsplit always returns an element"),
|
||||
)
|
||||
|
|
|
@ -60,7 +60,7 @@ impl RoomEdus {
|
|||
let mut room_latest_id = prefix;
|
||||
room_latest_id.extend_from_slice(&globals.next_count()?.to_be_bytes());
|
||||
room_latest_id.push(0xff);
|
||||
room_latest_id.extend_from_slice(&user_id.as_bytes());
|
||||
room_latest_id.extend_from_slice(user_id.as_bytes());
|
||||
|
||||
self.readreceiptid_readreceipt.insert(
|
||||
&room_latest_id,
|
||||
|
@ -126,7 +126,7 @@ impl RoomEdus {
|
|||
) -> Result<()> {
|
||||
let mut key = room_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&user_id.as_bytes());
|
||||
key.extend_from_slice(user_id.as_bytes());
|
||||
|
||||
self.roomuserid_privateread
|
||||
.insert(&key, &count.to_be_bytes())?;
|
||||
|
@ -142,7 +142,7 @@ impl RoomEdus {
|
|||
pub fn private_read_get(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>> {
|
||||
let mut key = room_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&user_id.as_bytes());
|
||||
key.extend_from_slice(user_id.as_bytes());
|
||||
|
||||
self.roomuserid_privateread
|
||||
.get(&key)?
|
||||
|
@ -157,7 +157,7 @@ impl RoomEdus {
|
|||
pub fn last_privateread_update(&self, user_id: &UserId, room_id: &RoomId) -> Result<u64> {
|
||||
let mut key = room_id.as_bytes().to_vec();
|
||||
key.push(0xff);
|
||||
key.extend_from_slice(&user_id.as_bytes());
|
||||
key.extend_from_slice(user_id.as_bytes());
|
||||
|
||||
Ok(self
|
||||
.roomuserid_lastprivatereadupdate
|
||||
|
@ -193,7 +193,7 @@ impl RoomEdus {
|
|||
.insert(&room_typing_id, &*user_id.as_bytes())?;
|
||||
|
||||
self.roomid_lasttypingupdate
|
||||
.insert(&room_id.as_bytes(), &count)?;
|
||||
.insert(room_id.as_bytes(), &count)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ impl RoomEdus {
|
|||
|
||||
if found_outdated {
|
||||
self.roomid_lasttypingupdate
|
||||
.insert(&room_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
|
||||
.insert(room_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -268,7 +268,7 @@ impl RoomEdus {
|
|||
|
||||
if found_outdated {
|
||||
self.roomid_lasttypingupdate
|
||||
.insert(&room_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
|
||||
.insert(room_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -285,7 +285,7 @@ impl RoomEdus {
|
|||
|
||||
Ok(self
|
||||
.roomid_lasttypingupdate
|
||||
.get(&room_id.as_bytes())?
|
||||
.get(room_id.as_bytes())?
|
||||
.map_or(Ok::<_, Error>(None), |bytes| {
|
||||
Ok(Some(utils::u64_from_bytes(&bytes).map_err(|_| {
|
||||
Error::bad_database("Count in roomid_lastroomactiveupdate is invalid.")
|
||||
|
@ -342,7 +342,7 @@ impl RoomEdus {
|
|||
presence_id.push(0xff);
|
||||
presence_id.extend_from_slice(&count);
|
||||
presence_id.push(0xff);
|
||||
presence_id.extend_from_slice(&presence.sender.as_bytes());
|
||||
presence_id.extend_from_slice(presence.sender.as_bytes());
|
||||
|
||||
self.presenceid_presence.insert(
|
||||
&presence_id,
|
||||
|
@ -361,7 +361,7 @@ impl RoomEdus {
|
|||
#[tracing::instrument(skip(self))]
|
||||
pub fn ping_presence(&self, user_id: &UserId) -> Result<()> {
|
||||
self.userid_lastpresenceupdate.insert(
|
||||
&user_id.as_bytes(),
|
||||
user_id.as_bytes(),
|
||||
&utils::millis_since_unix_epoch().to_be_bytes(),
|
||||
)?;
|
||||
|
||||
|
@ -371,7 +371,7 @@ impl RoomEdus {
|
|||
/// Returns the timestamp of the last presence update of this user in millis since the unix epoch.
|
||||
pub fn last_presence_update(&self, user_id: &UserId) -> Result<Option<u64>> {
|
||||
self.userid_lastpresenceupdate
|
||||
.get(&user_id.as_bytes())?
|
||||
.get(user_id.as_bytes())?
|
||||
.map(|bytes| {
|
||||
utils::u64_from_bytes(&bytes).map_err(|_| {
|
||||
Error::bad_database("Invalid timestamp in userid_lastpresenceupdate.")
|
||||
|
@ -394,7 +394,7 @@ impl RoomEdus {
|
|||
presence_id.push(0xff);
|
||||
presence_id.extend_from_slice(&last_update.to_be_bytes());
|
||||
presence_id.push(0xff);
|
||||
presence_id.extend_from_slice(&user_id.as_bytes());
|
||||
presence_id.extend_from_slice(user_id.as_bytes());
|
||||
|
||||
self.presenceid_presence
|
||||
.get(&presence_id)?
|
||||
|
@ -480,7 +480,7 @@ impl RoomEdus {
|
|||
}
|
||||
|
||||
self.userid_lastpresenceupdate.insert(
|
||||
&user_id.as_bytes(),
|
||||
user_id.as_bytes(),
|
||||
&utils::millis_since_unix_epoch().to_be_bytes(),
|
||||
)?;
|
||||
}
|
||||
|
|
|
@ -58,9 +58,9 @@ impl OutgoingKind {
|
|||
}
|
||||
OutgoingKind::Push(user, pushkey) => {
|
||||
let mut p = b"$".to_vec();
|
||||
p.extend_from_slice(&user);
|
||||
p.extend_from_slice(user);
|
||||
p.push(0xff);
|
||||
p.extend_from_slice(&pushkey);
|
||||
p.extend_from_slice(pushkey);
|
||||
p
|
||||
}
|
||||
OutgoingKind::Normal(server) => {
|
||||
|
@ -179,8 +179,8 @@ impl Sending {
|
|||
// Insert pdus we found
|
||||
for (e, key) in &new_events {
|
||||
let value = if let SendingEventType::Edu(value) = &e.1 { &**value } else { &[] };
|
||||
guard.sending.servercurrentevent_data.insert(&key, value).unwrap();
|
||||
guard.sending.servernameevent_data.remove(&key).unwrap();
|
||||
guard.sending.servercurrentevent_data.insert(key, value).unwrap();
|
||||
guard.sending.servernameevent_data.remove(key).unwrap();
|
||||
}
|
||||
|
||||
drop(guard);
|
||||
|
@ -345,7 +345,7 @@ impl Sending {
|
|||
}
|
||||
|
||||
let event =
|
||||
serde_json::from_str::<AnySyncEphemeralRoomEvent>(&read_receipt.json().get())
|
||||
serde_json::from_str::<AnySyncEphemeralRoomEvent>(read_receipt.json().get())
|
||||
.map_err(|_| Error::bad_database("Invalid edu event in read_receipts."))?;
|
||||
let federation_event = match event {
|
||||
AnySyncEphemeralRoomEvent::Receipt(r) => {
|
||||
|
@ -486,7 +486,7 @@ impl Sending {
|
|||
match event {
|
||||
SendingEventType::Pdu(pdu_id) => {
|
||||
pdu_jsons.push(db.rooms
|
||||
.get_pdu_from_id(&pdu_id)
|
||||
.get_pdu_from_id(pdu_id)
|
||||
.map_err(|e| (kind.clone(), e))?
|
||||
.ok_or_else(|| {
|
||||
(
|
||||
|
@ -543,7 +543,7 @@ impl Sending {
|
|||
SendingEventType::Pdu(pdu_id) => {
|
||||
pdus.push(
|
||||
db.rooms
|
||||
.get_pdu_from_id(&pdu_id)
|
||||
.get_pdu_from_id(pdu_id)
|
||||
.map_err(|e| (kind.clone(), e))?
|
||||
.ok_or_else(|| {
|
||||
(
|
||||
|
@ -636,7 +636,7 @@ impl Sending {
|
|||
// TODO: check room version and remove event_id if needed
|
||||
let raw = PduEvent::convert_to_outgoing_federation_event(
|
||||
db.rooms
|
||||
.get_pdu_json_from_id(&pdu_id)
|
||||
.get_pdu_json_from_id(pdu_id)
|
||||
.map_err(|e| (OutgoingKind::Normal(server.clone()), e))?
|
||||
.ok_or_else(|| {
|
||||
(
|
||||
|
@ -711,7 +711,7 @@ impl Sending {
|
|||
let event = parts
|
||||
.next()
|
||||
.ok_or_else(|| Error::bad_database("Invalid bytes in servercurrentpdus."))?;
|
||||
let server = utils::string_from_bytes(&server).map_err(|_| {
|
||||
let server = utils::string_from_bytes(server).map_err(|_| {
|
||||
Error::bad_database("Invalid server bytes in server_currenttransaction")
|
||||
})?;
|
||||
|
||||
|
@ -750,7 +750,7 @@ impl Sending {
|
|||
let event = parts
|
||||
.next()
|
||||
.ok_or_else(|| Error::bad_database("Invalid bytes in servercurrentpdus."))?;
|
||||
let server = utils::string_from_bytes(&server).map_err(|_| {
|
||||
let server = utils::string_from_bytes(server).map_err(|_| {
|
||||
Error::bad_database("Invalid server bytes in server_currenttransaction")
|
||||
})?;
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ impl Uiaa {
|
|||
) -> Result<(bool, UiaaInfo)> {
|
||||
let mut uiaainfo = auth
|
||||
.session()
|
||||
.map(|session| self.get_uiaa_session(&user_id, &device_id, session))
|
||||
.map(|session| self.get_uiaa_session(user_id, device_id, session))
|
||||
.unwrap_or_else(|| Ok(uiaainfo.clone()))?;
|
||||
|
||||
if uiaainfo.session.is_none() {
|
||||
|
|
|
@ -81,13 +81,13 @@ impl Users {
|
|||
})?;
|
||||
|
||||
Ok(Some((
|
||||
UserId::try_from(utils::string_from_bytes(&user_bytes).map_err(|_| {
|
||||
UserId::try_from(utils::string_from_bytes(user_bytes).map_err(|_| {
|
||||
Error::bad_database("User ID in token_userdeviceid is invalid unicode.")
|
||||
})?)
|
||||
.map_err(|_| {
|
||||
Error::bad_database("User ID in token_userdeviceid is invalid.")
|
||||
})?,
|
||||
utils::string_from_bytes(&device_bytes).map_err(|_| {
|
||||
utils::string_from_bytes(device_bytes).map_err(|_| {
|
||||
Error::bad_database("Device ID in token_userdeviceid is invalid.")
|
||||
})?,
|
||||
)))
|
||||
|
@ -121,7 +121,7 @@ impl Users {
|
|||
#[tracing::instrument(skip(self, user_id, password))]
|
||||
pub fn set_password(&self, user_id: &UserId, password: Option<&str>) -> Result<()> {
|
||||
if let Some(password) = password {
|
||||
if let Ok(hash) = utils::calculate_hash(&password) {
|
||||
if let Ok(hash) = utils::calculate_hash(password) {
|
||||
self.userid_password
|
||||
.insert(user_id.as_bytes(), hash.as_bytes())?;
|
||||
Ok(())
|
||||
|
@ -245,7 +245,7 @@ impl Users {
|
|||
.expect("Device::to_string never fails."),
|
||||
)?;
|
||||
|
||||
self.set_token(user_id, &device_id, token)?;
|
||||
self.set_token(user_id, device_id, token)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ impl Users {
|
|||
.scan_prefix(prefix)
|
||||
.map(|(bytes, _)| {
|
||||
Ok(utils::string_from_bytes(
|
||||
&bytes
|
||||
bytes
|
||||
.rsplit(|&b| b == 0xff)
|
||||
.next()
|
||||
.ok_or_else(|| Error::bad_database("UserDevice ID in db is invalid."))?,
|
||||
|
@ -357,7 +357,7 @@ impl Users {
|
|||
// TODO: Use DeviceKeyId::to_string when it's available (and update everything,
|
||||
// because there are no wrapping quotation marks anymore)
|
||||
key.extend_from_slice(
|
||||
&serde_json::to_string(one_time_key_key)
|
||||
serde_json::to_string(one_time_key_key)
|
||||
.expect("DeviceKeyId::to_string always works")
|
||||
.as_bytes(),
|
||||
);
|
||||
|
@ -368,7 +368,7 @@ impl Users {
|
|||
)?;
|
||||
|
||||
self.userid_lastonetimekeyupdate
|
||||
.insert(&user_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
|
||||
.insert(user_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ impl Users {
|
|||
#[tracing::instrument(skip(self, user_id))]
|
||||
pub fn last_one_time_keys_update(&self, user_id: &UserId) -> Result<u64> {
|
||||
self.userid_lastonetimekeyupdate
|
||||
.get(&user_id.as_bytes())?
|
||||
.get(user_id.as_bytes())?
|
||||
.map(|bytes| {
|
||||
utils::u64_from_bytes(&bytes).map_err(|_| {
|
||||
Error::bad_database("Count in roomid_lastroomactiveupdate is invalid.")
|
||||
|
@ -402,7 +402,7 @@ impl Users {
|
|||
prefix.push(b':');
|
||||
|
||||
self.userid_lastonetimekeyupdate
|
||||
.insert(&user_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
|
||||
.insert(user_id.as_bytes(), &globals.next_count()?.to_be_bytes())?;
|
||||
|
||||
self.onetimekeyid_onetimekeys
|
||||
.scan_prefix(prefix)
|
||||
|
@ -680,7 +680,7 @@ impl Users {
|
|||
globals: &super::globals::Globals,
|
||||
) -> Result<()> {
|
||||
let count = globals.next_count()?.to_be_bytes();
|
||||
for room_id in rooms.rooms_joined(&user_id).filter_map(|r| r.ok()) {
|
||||
for room_id in rooms.rooms_joined(user_id).filter_map(|r| r.ok()) {
|
||||
// Don't send key updates to unencrypted rooms
|
||||
if rooms
|
||||
.room_state_get(&room_id, &EventType::RoomEncryption, "")?
|
||||
|
@ -961,7 +961,7 @@ impl Users {
|
|||
pub fn deactivate_account(&self, user_id: &UserId) -> Result<()> {
|
||||
// Remove all associated devices
|
||||
for device_id in self.all_device_ids(user_id) {
|
||||
self.remove_device(&user_id, &device_id?)?;
|
||||
self.remove_device(user_id, &device_id?)?;
|
||||
}
|
||||
|
||||
// Set the password to "" to indicate a deactivated account. Hashes will never result in an
|
||||
|
|
|
@ -66,7 +66,7 @@ where
|
|||
let limit = db.globals.max_request_size();
|
||||
let mut handle = data.open(ByteUnit::Byte(limit.into()));
|
||||
let mut body = Vec::new();
|
||||
if let Err(_) = handle.read_to_end(&mut body).await {
|
||||
if handle.read_to_end(&mut body).await.is_err() {
|
||||
// Client disconnected
|
||||
// Missing Token
|
||||
return Failure((Status::new(582), ()));
|
||||
|
@ -123,7 +123,7 @@ where
|
|||
match metadata.authentication {
|
||||
AuthScheme::AccessToken | AuthScheme::QueryOnlyAccessToken => {
|
||||
if let Some(token) = token {
|
||||
match db.users.find_from_token(&token).unwrap() {
|
||||
match db.users.find_from_token(token).unwrap() {
|
||||
// Unknown Token
|
||||
None => return Failure((Status::new(581), ())),
|
||||
Some((user_id, device_id)) => (
|
||||
|
|
|
@ -150,7 +150,7 @@ where
|
|||
} else {
|
||||
write_destination_to_cache = true;
|
||||
|
||||
let result = find_actual_destination(globals, &destination).await;
|
||||
let result = find_actual_destination(globals, destination).await;
|
||||
|
||||
(result.0, result.1.into_uri_string())
|
||||
};
|
||||
|
@ -359,7 +359,7 @@ async fn find_actual_destination(
|
|||
let (host, port) = destination_str.split_at(pos);
|
||||
FedDest::Named(host.to_string(), port.to_string())
|
||||
} else {
|
||||
match request_well_known(globals, &destination.as_str()).await {
|
||||
match request_well_known(globals, destination.as_str()).await {
|
||||
// 3: A .well-known file is available
|
||||
Some(delegated_hostname) => {
|
||||
hostname = add_port_to_hostname(&delegated_hostname).into_uri_string();
|
||||
|
@ -806,7 +806,7 @@ pub async fn send_transaction_message_route(
|
|||
.event_ids
|
||||
.iter()
|
||||
.filter_map(|id| {
|
||||
db.rooms.get_pdu_count(&id).ok().flatten().map(|r| (id, r))
|
||||
db.rooms.get_pdu_count(id).ok().flatten().map(|r| (id, r))
|
||||
})
|
||||
.max_by_key(|(_, count)| *count)
|
||||
{
|
||||
|
@ -875,8 +875,8 @@ pub async fn send_transaction_message_route(
|
|||
DeviceIdOrAllDevices::DeviceId(target_device_id) => {
|
||||
db.users.add_to_device_event(
|
||||
&sender,
|
||||
&target_user_id,
|
||||
&target_device_id,
|
||||
target_user_id,
|
||||
target_device_id,
|
||||
&ev_type.to_string(),
|
||||
event.deserialize_as().map_err(|_| {
|
||||
Error::BadRequest(
|
||||
|
@ -889,10 +889,10 @@ pub async fn send_transaction_message_route(
|
|||
}
|
||||
|
||||
DeviceIdOrAllDevices::AllDevices => {
|
||||
for target_device_id in db.users.all_device_ids(&target_user_id) {
|
||||
for target_device_id in db.users.all_device_ids(target_user_id) {
|
||||
db.users.add_to_device_event(
|
||||
&sender,
|
||||
&target_user_id,
|
||||
target_user_id,
|
||||
&target_device_id?,
|
||||
&ev_type.to_string(),
|
||||
event.deserialize_as().map_err(|_| {
|
||||
|
@ -959,7 +959,7 @@ pub(crate) async fn handle_incoming_pdu<'a>(
|
|||
db: &'a Database,
|
||||
pub_key_map: &'a RwLock<BTreeMap<String, BTreeMap<String, String>>>,
|
||||
) -> StdResult<Option<Vec<u8>>, String> {
|
||||
match db.rooms.exists(&room_id) {
|
||||
match db.rooms.exists(room_id) {
|
||||
Ok(true) => {}
|
||||
_ => {
|
||||
return Err("Room is unknown to this server.".to_string());
|
||||
|
@ -967,19 +967,19 @@ pub(crate) async fn handle_incoming_pdu<'a>(
|
|||
}
|
||||
|
||||
// 1. Skip the PDU if we already have it as a timeline event
|
||||
if let Ok(Some(pdu_id)) = db.rooms.get_pdu_id(&event_id) {
|
||||
if let Ok(Some(pdu_id)) = db.rooms.get_pdu_id(event_id) {
|
||||
return Ok(Some(pdu_id.to_vec()));
|
||||
}
|
||||
|
||||
let create_event = db
|
||||
.rooms
|
||||
.room_state_get(&room_id, &EventType::RoomCreate, "")
|
||||
.room_state_get(room_id, &EventType::RoomCreate, "")
|
||||
.map_err(|_| "Failed to ask database for event.".to_owned())?
|
||||
.ok_or_else(|| "Failed to find create event in db.".to_owned())?;
|
||||
|
||||
let first_pdu_in_room = db
|
||||
.rooms
|
||||
.first_pdu_in_room(&room_id)
|
||||
.first_pdu_in_room(room_id)
|
||||
.map_err(|_| "Error loading first room event.".to_owned())?
|
||||
.expect("Room exists");
|
||||
|
||||
|
@ -1021,7 +1021,7 @@ pub(crate) async fn handle_incoming_pdu<'a>(
|
|||
origin,
|
||||
&[prev_event_id.clone()],
|
||||
&create_event,
|
||||
&room_id,
|
||||
room_id,
|
||||
pub_key_map,
|
||||
)
|
||||
.await
|
||||
|
@ -1049,12 +1049,12 @@ pub(crate) async fn handle_incoming_pdu<'a>(
|
|||
(*prev_event_id).clone(),
|
||||
pdu.prev_events.iter().cloned().collect(),
|
||||
);
|
||||
eventid_info.insert(prev_event_id.clone(), (pdu, json));
|
||||
} else {
|
||||
// Time based check failed
|
||||
graph.insert((*prev_event_id).clone(), HashSet::new());
|
||||
eventid_info.insert(prev_event_id.clone(), (pdu, json));
|
||||
}
|
||||
|
||||
eventid_info.insert(prev_event_id.clone(), (pdu, json));
|
||||
} else {
|
||||
// Get json failed
|
||||
graph.insert((*prev_event_id).clone(), HashSet::new());
|
||||
|
@ -1146,7 +1146,7 @@ fn handle_outlier_pdu<'a>(
|
|||
|
||||
// We go through all the signatures we see on the value and fetch the corresponding signing
|
||||
// keys
|
||||
fetch_required_signing_keys(&value, &pub_key_map, db)
|
||||
fetch_required_signing_keys(&value, pub_key_map, db)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
|
@ -1210,8 +1210,8 @@ fn handle_outlier_pdu<'a>(
|
|||
.cloned()
|
||||
.map(Arc::new)
|
||||
.collect::<Vec<_>>(),
|
||||
&create_event,
|
||||
&room_id,
|
||||
create_event,
|
||||
room_id,
|
||||
pub_key_map,
|
||||
)
|
||||
.await;
|
||||
|
@ -1256,7 +1256,7 @@ fn handle_outlier_pdu<'a>(
|
|||
if auth_events
|
||||
.get(&(EventType::RoomCreate, "".to_owned()))
|
||||
.map(|a| a.as_ref())
|
||||
!= Some(&create_event)
|
||||
!= Some(create_event)
|
||||
{
|
||||
return Err("Incoming event refers to wrong create event.".to_owned());
|
||||
}
|
||||
|
@ -1273,8 +1273,6 @@ fn handle_outlier_pdu<'a>(
|
|||
None
|
||||
};
|
||||
|
||||
let incoming_pdu = Arc::new(incoming_pdu.clone());
|
||||
|
||||
if !state_res::event_auth::auth_check(
|
||||
&room_version,
|
||||
&incoming_pdu,
|
||||
|
@ -1295,7 +1293,7 @@ fn handle_outlier_pdu<'a>(
|
|||
.map_err(|_| "Failed to add pdu as outlier.".to_owned())?;
|
||||
debug!("Added pdu as outlier.");
|
||||
|
||||
Ok((incoming_pdu, val))
|
||||
Ok((Arc::new(incoming_pdu), val))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1427,7 +1425,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
}
|
||||
|
||||
auth_chain_sets.push(
|
||||
get_auth_chain(&room_id, starting_events, db)
|
||||
get_auth_chain(room_id, starting_events, db)
|
||||
.map_err(|_| "Failed to load auth chain.".to_owned())?
|
||||
.map(|event_id| (*event_id).clone())
|
||||
.collect(),
|
||||
|
@ -1478,7 +1476,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
&db.globals,
|
||||
origin,
|
||||
get_room_state_ids::v1::Request {
|
||||
room_id: &room_id,
|
||||
room_id,
|
||||
event_id: &incoming_pdu.event_id,
|
||||
},
|
||||
)
|
||||
|
@ -1487,15 +1485,15 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
Ok(res) => {
|
||||
warn!("Fetching state events at event.");
|
||||
let state_vec = fetch_and_handle_outliers(
|
||||
&db,
|
||||
db,
|
||||
origin,
|
||||
&res.pdu_ids
|
||||
.iter()
|
||||
.cloned()
|
||||
.map(Arc::new)
|
||||
.collect::<Vec<_>>(),
|
||||
&create_event,
|
||||
&room_id,
|
||||
create_event,
|
||||
room_id,
|
||||
pub_key_map,
|
||||
)
|
||||
.await;
|
||||
|
@ -1568,11 +1566,11 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
None::<PduEvent>, // TODO: third party invite
|
||||
|k, s| {
|
||||
db.rooms
|
||||
.get_shortstatekey(&k, &s)
|
||||
.get_shortstatekey(k, s)
|
||||
.ok()
|
||||
.flatten()
|
||||
.and_then(|shortstatekey| state_at_incoming_event.get(&shortstatekey))
|
||||
.and_then(|event_id| db.rooms.get_pdu(&event_id).ok().flatten())
|
||||
.and_then(|event_id| db.rooms.get_pdu(event_id).ok().flatten())
|
||||
},
|
||||
)
|
||||
.map_err(|_e| "Auth check failed.".to_owned())?;
|
||||
|
@ -1598,7 +1596,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
// applied. We start with the previous extremities (aka leaves)
|
||||
let mut extremities = db
|
||||
.rooms
|
||||
.get_pdu_leaves(&room_id)
|
||||
.get_pdu_leaves(room_id)
|
||||
.map_err(|_| "Failed to load room leaves".to_owned())?;
|
||||
|
||||
// Remove any forward extremities that are referenced by this incoming event's prev_events
|
||||
|
@ -1609,11 +1607,11 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
}
|
||||
|
||||
// Only keep those extremities were not referenced yet
|
||||
extremities.retain(|id| !matches!(db.rooms.is_event_referenced(&room_id, id), Ok(true)));
|
||||
extremities.retain(|id| !matches!(db.rooms.is_event_referenced(room_id, id), Ok(true)));
|
||||
|
||||
let current_sstatehash = db
|
||||
.rooms
|
||||
.current_shortstatehash(&room_id)
|
||||
.current_shortstatehash(room_id)
|
||||
.map_err(|_| "Failed to load current state hash.".to_owned())?
|
||||
.expect("every room has state");
|
||||
|
||||
|
@ -1625,7 +1623,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
let auth_events = db
|
||||
.rooms
|
||||
.get_auth_events(
|
||||
&room_id,
|
||||
room_id,
|
||||
&incoming_pdu.kind,
|
||||
&incoming_pdu.sender,
|
||||
incoming_pdu.state_key.as_deref(),
|
||||
|
@ -1637,7 +1635,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
.iter()
|
||||
.map(|(shortstatekey, id)| {
|
||||
db.rooms
|
||||
.compress_state_event(*shortstatekey, &id, &db.globals)
|
||||
.compress_state_event(*shortstatekey, id, &db.globals)
|
||||
.map_err(|_| "Failed to compress_state_event".to_owned())
|
||||
})
|
||||
.collect::<StdResult<_, String>>()?;
|
||||
|
@ -1656,7 +1654,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
|
||||
if soft_fail {
|
||||
append_incoming_pdu(
|
||||
&db,
|
||||
db,
|
||||
&incoming_pdu,
|
||||
val,
|
||||
extremities,
|
||||
|
@ -1680,7 +1678,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
for id in dbg!(&extremities) {
|
||||
match db
|
||||
.rooms
|
||||
.get_pdu(&id)
|
||||
.get_pdu(id)
|
||||
.map_err(|_| "Failed to ask db for pdu.".to_owned())?
|
||||
{
|
||||
Some(leaf_pdu) => {
|
||||
|
@ -1757,7 +1755,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
.iter()
|
||||
.map(|(k, id)| {
|
||||
db.rooms
|
||||
.compress_state_event(*k, &id, &db.globals)
|
||||
.compress_state_event(*k, id, &db.globals)
|
||||
.map_err(|_| "Failed to compress_state_event.".to_owned())
|
||||
})
|
||||
.collect::<StdResult<_, String>>()?
|
||||
|
@ -1769,7 +1767,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
for state in &fork_states {
|
||||
auth_chain_sets.push(
|
||||
get_auth_chain(
|
||||
&room_id,
|
||||
room_id,
|
||||
state.iter().map(|(_, id)| id.clone()).collect(),
|
||||
db,
|
||||
)
|
||||
|
@ -1828,7 +1826,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
// Set the new room state to the resolved state
|
||||
if update_state {
|
||||
db.rooms
|
||||
.force_state(&room_id, new_room_state, &db)
|
||||
.force_state(room_id, new_room_state, db)
|
||||
.map_err(|_| "Failed to set new room state.".to_owned())?;
|
||||
}
|
||||
debug!("Updated resolved state");
|
||||
|
@ -1841,7 +1839,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
// represent the state for this event.
|
||||
|
||||
let pdu_id = append_incoming_pdu(
|
||||
&db,
|
||||
db,
|
||||
&incoming_pdu,
|
||||
val,
|
||||
extremities,
|
||||
|
@ -1886,7 +1884,7 @@ pub(crate) fn fetch_and_handle_outliers<'a>(
|
|||
|
||||
let mut pdus = vec![];
|
||||
for id in events {
|
||||
if let Some((time, tries)) = db.globals.bad_event_ratelimiter.read().unwrap().get(&id) {
|
||||
if let Some((time, tries)) = db.globals.bad_event_ratelimiter.read().unwrap().get(id) {
|
||||
// Exponential backoff
|
||||
let mut min_elapsed_duration = Duration::from_secs(5 * 60) * (*tries) * (*tries);
|
||||
if min_elapsed_duration > Duration::from_secs(60 * 60 * 24) {
|
||||
|
@ -1902,7 +1900,7 @@ pub(crate) fn fetch_and_handle_outliers<'a>(
|
|||
// a. Look in the main timeline (pduid_pdu tree)
|
||||
// b. Look at outlier pdu tree
|
||||
// (get_pdu_json checks both)
|
||||
let local_pdu = db.rooms.get_pdu(&id);
|
||||
let local_pdu = db.rooms.get_pdu(id);
|
||||
let pdu = match local_pdu {
|
||||
Ok(Some(pdu)) => {
|
||||
trace!("Found {} in db", id);
|
||||
|
@ -1916,7 +1914,7 @@ pub(crate) fn fetch_and_handle_outliers<'a>(
|
|||
.send_federation_request(
|
||||
&db.globals,
|
||||
origin,
|
||||
get_event::v1::Request { event_id: &id },
|
||||
get_event::v1::Request { event_id: id },
|
||||
)
|
||||
.await
|
||||
{
|
||||
|
@ -1940,8 +1938,8 @@ pub(crate) fn fetch_and_handle_outliers<'a>(
|
|||
match handle_outlier_pdu(
|
||||
origin,
|
||||
create_event,
|
||||
&id,
|
||||
&room_id,
|
||||
id,
|
||||
room_id,
|
||||
value.clone(),
|
||||
db,
|
||||
pub_key_map,
|
||||
|
@ -2089,7 +2087,7 @@ pub(crate) async fn fetch_signing_keys(
|
|||
.sending
|
||||
.send_federation_request(
|
||||
&db.globals,
|
||||
&server,
|
||||
server,
|
||||
get_remote_server_keys::v2::Request::new(
|
||||
origin,
|
||||
MilliSecondsSinceUnixEpoch::from_system_time(
|
||||
|
@ -2168,7 +2166,7 @@ fn append_incoming_pdu(
|
|||
pdu,
|
||||
pdu_json,
|
||||
&new_room_leaves.into_iter().collect::<Vec<_>>(),
|
||||
&db,
|
||||
db,
|
||||
)?;
|
||||
|
||||
for appservice in db.appservice.all()? {
|
||||
|
@ -2206,7 +2204,7 @@ fn append_incoming_pdu(
|
|||
&& pdu
|
||||
.state_key
|
||||
.as_ref()
|
||||
.map_or(false, |state_key| users.is_match(&state_key))
|
||||
.map_or(false, |state_key| users.is_match(state_key))
|
||||
};
|
||||
let matching_aliases = |aliases: &Regex| {
|
||||
db.rooms
|
||||
|
@ -2273,7 +2271,7 @@ pub(crate) fn get_auth_chain<'a>(
|
|||
chunk_cache.extend(cached.iter().cloned());
|
||||
} else {
|
||||
misses2 += 1;
|
||||
let auth_chain = Arc::new(get_auth_chain_inner(&room_id, &event_id, db)?);
|
||||
let auth_chain = Arc::new(get_auth_chain_inner(room_id, &event_id, db)?);
|
||||
db.rooms
|
||||
.cache_auth_chain(vec![sevent_id], Arc::clone(&auth_chain))?;
|
||||
println!(
|
||||
|
@ -2821,7 +2819,7 @@ async fn create_join_event(
|
|||
// We need to return the state prior to joining, let's keep a reference to that here
|
||||
let shortstatehash = db
|
||||
.rooms
|
||||
.current_shortstatehash(&room_id)?
|
||||
.current_shortstatehash(room_id)?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"Pdu state not found.",
|
||||
|
@ -2831,7 +2829,7 @@ async fn create_join_event(
|
|||
// let mut auth_cache = EventMap::new();
|
||||
|
||||
// We do not add the event_id field to the pdu here because of signature and hashes checks
|
||||
let (event_id, value) = match crate::pdu::gen_event_id_canonical_json(&pdu) {
|
||||
let (event_id, value) = match crate::pdu::gen_event_id_canonical_json(pdu) {
|
||||
Ok(t) => t,
|
||||
Err(_) => {
|
||||
// Event could not be converted to canonical json
|
||||
|
@ -2860,7 +2858,7 @@ async fn create_join_event(
|
|||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
let pdu_id = handle_incoming_pdu(&origin, &event_id, &room_id, value, true, &db, &pub_key_map)
|
||||
let pdu_id = handle_incoming_pdu(&origin, &event_id, room_id, value, true, db, &pub_key_map)
|
||||
.await
|
||||
.map_err(|e| {
|
||||
warn!("Error while handling incoming send join PDU: {}", e);
|
||||
|
@ -2877,14 +2875,14 @@ async fn create_join_event(
|
|||
|
||||
let state_ids = db.rooms.state_full_ids(shortstatehash)?;
|
||||
let auth_chain_ids = get_auth_chain(
|
||||
&room_id,
|
||||
room_id,
|
||||
state_ids.iter().map(|(_, id)| id.clone()).collect(),
|
||||
&db,
|
||||
db,
|
||||
)?;
|
||||
|
||||
for server in db
|
||||
.rooms
|
||||
.room_servers(&room_id)
|
||||
.room_servers(room_id)
|
||||
.filter_map(|r| r.ok())
|
||||
.filter(|server| &**server != db.globals.server_name())
|
||||
{
|
||||
|
@ -2900,7 +2898,7 @@ async fn create_join_event(
|
|||
.collect(),
|
||||
state: state_ids
|
||||
.iter()
|
||||
.filter_map(|(_, id)| db.rooms.get_pdu_json(&id).ok().flatten())
|
||||
.filter_map(|(_, id)| db.rooms.get_pdu_json(id).ok().flatten())
|
||||
.map(PduEvent::convert_to_outgoing_federation_event)
|
||||
.collect(),
|
||||
})
|
||||
|
@ -3296,7 +3294,7 @@ fn get_server_keys_from_cache(
|
|||
|
||||
let event_id = EventId::try_from(&*format!(
|
||||
"${}",
|
||||
ruma::signatures::reference_hash(&value, &room_version)
|
||||
ruma::signatures::reference_hash(&value, room_version)
|
||||
.expect("ruma can calculate reference hashes")
|
||||
))
|
||||
.expect("ruma's reference hashes are valid event ids");
|
||||
|
@ -3388,10 +3386,10 @@ pub(crate) async fn fetch_join_signing_keys(
|
|||
// Try to fetch keys, failure is okay
|
||||
// Servers we couldn't find in the cache will be added to `servers`
|
||||
for pdu in &event.room_state.state {
|
||||
let _ = get_server_keys_from_cache(pdu, &mut servers, &room_version, &mut pkm, &db);
|
||||
let _ = get_server_keys_from_cache(pdu, &mut servers, room_version, &mut pkm, db);
|
||||
}
|
||||
for pdu in &event.room_state.auth_chain {
|
||||
let _ = get_server_keys_from_cache(pdu, &mut servers, &room_version, &mut pkm, &db);
|
||||
let _ = get_server_keys_from_cache(pdu, &mut servers, room_version, &mut pkm, db);
|
||||
}
|
||||
|
||||
drop(pkm);
|
||||
|
|
Loading…
Reference in New Issue