mirror of
https://gitlab.com/famedly/conduit.git
synced 2025-01-30 20:45:59 +03:00
Fix rustc / clippy warnings
This commit is contained in:
parent
a0fc5eba72
commit
756a41f22d
8 changed files with 46 additions and 54 deletions
src
|
@ -3,8 +3,7 @@ use ruma::{
|
||||||
api::client::{error::ErrorKind, r0::context::get_context},
|
api::client::{error::ErrorKind, r0::context::get_context},
|
||||||
events::EventType,
|
events::EventType,
|
||||||
};
|
};
|
||||||
use std::collections::HashSet;
|
use std::{collections::HashSet, convert::TryFrom};
|
||||||
use std::convert::TryFrom;
|
|
||||||
|
|
||||||
#[cfg(feature = "conduit_bin")]
|
#[cfg(feature = "conduit_bin")]
|
||||||
use rocket::get;
|
use rocket::get;
|
||||||
|
@ -55,8 +54,8 @@ pub async fn get_context_route(
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
if !db.rooms.lazy_load_was_sent_before(
|
if !db.rooms.lazy_load_was_sent_before(
|
||||||
&sender_user,
|
sender_user,
|
||||||
&sender_device,
|
sender_device,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&base_event.sender,
|
&base_event.sender,
|
||||||
)? {
|
)? {
|
||||||
|
@ -79,8 +78,8 @@ pub async fn get_context_route(
|
||||||
|
|
||||||
for (_, event) in &events_before {
|
for (_, event) in &events_before {
|
||||||
if !db.rooms.lazy_load_was_sent_before(
|
if !db.rooms.lazy_load_was_sent_before(
|
||||||
&sender_user,
|
sender_user,
|
||||||
&sender_device,
|
sender_device,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&event.sender,
|
&event.sender,
|
||||||
)? {
|
)? {
|
||||||
|
@ -112,8 +111,8 @@ pub async fn get_context_route(
|
||||||
|
|
||||||
for (_, event) in &events_after {
|
for (_, event) in &events_after {
|
||||||
if !db.rooms.lazy_load_was_sent_before(
|
if !db.rooms.lazy_load_was_sent_before(
|
||||||
&sender_user,
|
sender_user,
|
||||||
&sender_device,
|
sender_device,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&event.sender,
|
&event.sender,
|
||||||
)? {
|
)? {
|
||||||
|
|
|
@ -272,7 +272,7 @@ pub async fn get_key_changes_route(
|
||||||
device_list_updates.extend(
|
device_list_updates.extend(
|
||||||
db.users
|
db.users
|
||||||
.keys_changed(
|
.keys_changed(
|
||||||
&sender_user.to_string(),
|
sender_user.as_str(),
|
||||||
body.from
|
body.from
|
||||||
.parse()
|
.parse()
|
||||||
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid `from`."))?,
|
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid `from`."))?,
|
||||||
|
|
|
@ -139,7 +139,7 @@ pub async fn get_message_events_route(
|
||||||
let to = body.to.as_ref().map(|t| t.parse());
|
let to = body.to.as_ref().map(|t| t.parse());
|
||||||
|
|
||||||
db.rooms
|
db.rooms
|
||||||
.lazy_load_confirm_delivery(&sender_user, &sender_device, &body.room_id, from)?;
|
.lazy_load_confirm_delivery(sender_user, sender_device, &body.room_id, from)?;
|
||||||
|
|
||||||
// Use limit or else 10
|
// Use limit or else 10
|
||||||
let limit = body.limit.try_into().map_or(10_usize, |l: u32| l as usize);
|
let limit = body.limit.try_into().map_or(10_usize, |l: u32| l as usize);
|
||||||
|
@ -168,8 +168,8 @@ pub async fn get_message_events_route(
|
||||||
|
|
||||||
for (_, event) in &events_after {
|
for (_, event) in &events_after {
|
||||||
if !db.rooms.lazy_load_was_sent_before(
|
if !db.rooms.lazy_load_was_sent_before(
|
||||||
&sender_user,
|
sender_user,
|
||||||
&sender_device,
|
sender_device,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&event.sender,
|
&event.sender,
|
||||||
)? {
|
)? {
|
||||||
|
@ -205,8 +205,8 @@ pub async fn get_message_events_route(
|
||||||
|
|
||||||
for (_, event) in &events_before {
|
for (_, event) in &events_before {
|
||||||
if !db.rooms.lazy_load_was_sent_before(
|
if !db.rooms.lazy_load_was_sent_before(
|
||||||
&sender_user,
|
sender_user,
|
||||||
&sender_device,
|
sender_device,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&event.sender,
|
&event.sender,
|
||||||
)? {
|
)? {
|
||||||
|
@ -239,8 +239,8 @@ pub async fn get_message_events_route(
|
||||||
|
|
||||||
if let Some(next_token) = next_token {
|
if let Some(next_token) = next_token {
|
||||||
db.rooms.lazy_load_mark_sent(
|
db.rooms.lazy_load_mark_sent(
|
||||||
&sender_user,
|
sender_user,
|
||||||
&sender_device,
|
sender_device,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
lazy_loaded,
|
lazy_loaded,
|
||||||
next_token,
|
next_token,
|
||||||
|
|
|
@ -52,7 +52,7 @@ pub async fn set_displayname_route(
|
||||||
.room_state_get(
|
.room_state_get(
|
||||||
&room_id,
|
&room_id,
|
||||||
&EventType::RoomMember,
|
&EventType::RoomMember,
|
||||||
&sender_user.to_string(),
|
sender_user.as_str(),
|
||||||
)?
|
)?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
Error::bad_database(
|
Error::bad_database(
|
||||||
|
@ -195,7 +195,7 @@ pub async fn set_avatar_url_route(
|
||||||
.room_state_get(
|
.room_state_get(
|
||||||
&room_id,
|
&room_id,
|
||||||
&EventType::RoomMember,
|
&EventType::RoomMember,
|
||||||
&sender_user.to_string(),
|
sender_user.as_str(),
|
||||||
)?
|
)?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
Error::bad_database(
|
Error::bad_database(
|
||||||
|
|
|
@ -212,29 +212,23 @@ impl Database {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if sled_exists {
|
if sled_exists && config.database_backend != "sled" {
|
||||||
if config.database_backend != "sled" {
|
|
||||||
return Err(Error::bad_config(
|
return Err(Error::bad_config(
|
||||||
"Found sled at database_path, but is not specified in config.",
|
"Found sled at database_path, but is not specified in config.",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if sqlite_exists {
|
if sqlite_exists && config.database_backend != "sqlite" {
|
||||||
if config.database_backend != "sqlite" {
|
|
||||||
return Err(Error::bad_config(
|
return Err(Error::bad_config(
|
||||||
"Found sqlite at database_path, but is not specified in config.",
|
"Found sqlite at database_path, but is not specified in config.",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if rocksdb_exists {
|
if rocksdb_exists && config.database_backend != "rocksdb" {
|
||||||
if config.database_backend != "rocksdb" {
|
|
||||||
return Err(Error::bad_config(
|
return Err(Error::bad_config(
|
||||||
"Found rocksdb at database_path, but is not specified in config.",
|
"Found rocksdb at database_path, but is not specified in config.",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,7 @@ impl Admin {
|
||||||
if let Ok(response) = guard._db.memory_usage() {
|
if let Ok(response) = guard._db.memory_usage() {
|
||||||
send_message(RoomMessageEventContent::text_plain(response), guard, &state_lock);
|
send_message(RoomMessageEventContent::text_plain(response), guard, &state_lock);
|
||||||
} else {
|
} else {
|
||||||
send_message(RoomMessageEventContent::text_plain("Failed to get database memory usage.".to_string()), guard, &state_lock);
|
send_message(RoomMessageEventContent::text_plain("Failed to get database memory usage.".to_owned()), guard, &state_lock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AdminCommand::SendMessage(message) => {
|
AdminCommand::SendMessage(message) => {
|
||||||
|
|
|
@ -2727,7 +2727,7 @@ impl Rooms {
|
||||||
let state_lock = mutex_state.lock().await;
|
let state_lock = mutex_state.lock().await;
|
||||||
|
|
||||||
let mut event: RoomMemberEventContent = serde_json::from_str(
|
let mut event: RoomMemberEventContent = serde_json::from_str(
|
||||||
self.room_state_get(room_id, &EventType::RoomMember, &user_id.to_string())?
|
self.room_state_get(room_id, &EventType::RoomMember, user_id.as_str())?
|
||||||
.ok_or(Error::BadRequest(
|
.ok_or(Error::BadRequest(
|
||||||
ErrorKind::BadState,
|
ErrorKind::BadState,
|
||||||
"Cannot leave a room you are not a member of.",
|
"Cannot leave a room you are not a member of.",
|
||||||
|
@ -3462,8 +3462,7 @@ impl Rooms {
|
||||||
&key[0].to_be_bytes(),
|
&key[0].to_be_bytes(),
|
||||||
&chain
|
&chain
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| s.to_be_bytes().to_vec())
|
.flat_map(|s| s.to_be_bytes().to_vec())
|
||||||
.flatten()
|
|
||||||
.collect::<Vec<u8>>(),
|
.collect::<Vec<u8>>(),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
@ -3484,11 +3483,11 @@ impl Rooms {
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
let mut key = user_id.as_bytes().to_vec();
|
let mut key = user_id.as_bytes().to_vec();
|
||||||
key.push(0xff);
|
key.push(0xff);
|
||||||
key.extend_from_slice(&device_id.as_bytes());
|
key.extend_from_slice(device_id.as_bytes());
|
||||||
key.push(0xff);
|
key.push(0xff);
|
||||||
key.extend_from_slice(&room_id.as_bytes());
|
key.extend_from_slice(room_id.as_bytes());
|
||||||
key.push(0xff);
|
key.push(0xff);
|
||||||
key.extend_from_slice(&ll_user.as_bytes());
|
key.extend_from_slice(ll_user.as_bytes());
|
||||||
Ok(self.lazyloadedids.get(&key)?.is_some())
|
Ok(self.lazyloadedids.get(&key)?.is_some())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3528,14 +3527,14 @@ impl Rooms {
|
||||||
)) {
|
)) {
|
||||||
let mut prefix = user_id.as_bytes().to_vec();
|
let mut prefix = user_id.as_bytes().to_vec();
|
||||||
prefix.push(0xff);
|
prefix.push(0xff);
|
||||||
prefix.extend_from_slice(&device_id.as_bytes());
|
prefix.extend_from_slice(device_id.as_bytes());
|
||||||
prefix.push(0xff);
|
prefix.push(0xff);
|
||||||
prefix.extend_from_slice(&room_id.as_bytes());
|
prefix.extend_from_slice(room_id.as_bytes());
|
||||||
prefix.push(0xff);
|
prefix.push(0xff);
|
||||||
|
|
||||||
for ll_id in user_ids {
|
for ll_id in user_ids {
|
||||||
let mut key = prefix.clone();
|
let mut key = prefix.clone();
|
||||||
key.extend_from_slice(&ll_id.as_bytes());
|
key.extend_from_slice(ll_id.as_bytes());
|
||||||
self.lazyloadedids.insert(&key, &[])?;
|
self.lazyloadedids.insert(&key, &[])?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3546,15 +3545,15 @@ impl Rooms {
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
pub fn lazy_load_reset(
|
pub fn lazy_load_reset(
|
||||||
&self,
|
&self,
|
||||||
user_id: &Box<UserId>,
|
user_id: &UserId,
|
||||||
device_id: &Box<DeviceId>,
|
device_id: &DeviceId,
|
||||||
room_id: &Box<RoomId>,
|
room_id: &RoomId,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut prefix = user_id.as_bytes().to_vec();
|
let mut prefix = user_id.as_bytes().to_vec();
|
||||||
prefix.push(0xff);
|
prefix.push(0xff);
|
||||||
prefix.extend_from_slice(&device_id.as_bytes());
|
prefix.extend_from_slice(device_id.as_bytes());
|
||||||
prefix.push(0xff);
|
prefix.push(0xff);
|
||||||
prefix.extend_from_slice(&room_id.as_bytes());
|
prefix.extend_from_slice(room_id.as_bytes());
|
||||||
prefix.push(0xff);
|
prefix.push(0xff);
|
||||||
|
|
||||||
for (key, _) in self.lazyloadedids.scan_prefix(prefix) {
|
for (key, _) in self.lazyloadedids.scan_prefix(prefix) {
|
||||||
|
|
|
@ -1938,7 +1938,7 @@ pub(crate) fn fetch_and_handle_outliers<'a>(
|
||||||
match handle_outlier_pdu(
|
match handle_outlier_pdu(
|
||||||
origin,
|
origin,
|
||||||
create_event,
|
create_event,
|
||||||
&next_id,
|
next_id,
|
||||||
room_id,
|
room_id,
|
||||||
value.clone(),
|
value.clone(),
|
||||||
db,
|
db,
|
||||||
|
@ -2358,7 +2358,7 @@ pub fn get_event_route(
|
||||||
let room_id = <&RoomId>::try_from(room_id_str)
|
let room_id = <&RoomId>::try_from(room_id_str)
|
||||||
.map_err(|_| Error::bad_database("Invalid room id field in event in database"))?;
|
.map_err(|_| Error::bad_database("Invalid room id field in event in database"))?;
|
||||||
|
|
||||||
if !db.rooms.server_in_room(sender_servername, &room_id)? {
|
if !db.rooms.server_in_room(sender_servername, room_id)? {
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::Forbidden,
|
ErrorKind::Forbidden,
|
||||||
"Server is not in room",
|
"Server is not in room",
|
||||||
|
@ -2821,7 +2821,7 @@ async fn create_join_event(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
acl_check(sender_servername, room_id, &db)?;
|
acl_check(sender_servername, room_id, db)?;
|
||||||
|
|
||||||
// We need to return the state prior to joining, let's keep a reference to that here
|
// We need to return the state prior to joining, let's keep a reference to that here
|
||||||
let shortstatehash = db
|
let shortstatehash = db
|
||||||
|
|
Loading…
Reference in a new issue