Fix all clippy warnings, shorten line len in client_server
This commit is contained in:
parent
3ccbd02081
commit
62df9ca580
5 changed files with 155 additions and 100 deletions
|
@ -1,6 +1,8 @@
|
|||
use crate::{utils, Error, Result};
|
||||
use std::mem;
|
||||
|
||||
pub type FileMeta = (Option<String>, String, Vec<u8>);
|
||||
|
||||
pub struct Media {
|
||||
pub(super) mediaid_file: sled::Tree, // MediaId = MXC + WidthHeight + Filename + ContentType
|
||||
}
|
||||
|
@ -29,7 +31,7 @@ impl Media {
|
|||
}
|
||||
|
||||
/// Downloads a file.
|
||||
pub fn get(&self, mxc: String) -> Result<Option<(Option<String>, String, Vec<u8>)>> {
|
||||
pub fn get(&self, mxc: String) -> Result<Option<FileMeta>> {
|
||||
let mut prefix = mxc.as_bytes().to_vec();
|
||||
prefix.push(0xff);
|
||||
prefix.extend_from_slice(&0_u32.to_be_bytes()); // Width = 0 if it's not a thumbnail
|
||||
|
@ -66,12 +68,7 @@ impl Media {
|
|||
}
|
||||
|
||||
/// Downloads a file's thumbnail.
|
||||
pub fn get_thumbnail(
|
||||
&self,
|
||||
mxc: String,
|
||||
width: u32,
|
||||
height: u32,
|
||||
) -> Result<Option<(Option<String>, String, Vec<u8>)>> {
|
||||
pub fn get_thumbnail(&self, mxc: String, width: u32, height: u32) -> Result<Option<FileMeta>> {
|
||||
let mut main_prefix = mxc.as_bytes().to_vec();
|
||||
main_prefix.push(0xff);
|
||||
|
||||
|
|
|
@ -250,6 +250,7 @@ impl Rooms {
|
|||
}
|
||||
|
||||
/// Creates a new persisted data unit and adds it to a room.
|
||||
#[allow(clippy::too_many_arguments, clippy::blocks_in_if_conditions)]
|
||||
pub fn append_pdu(
|
||||
&self,
|
||||
room_id: RoomId,
|
||||
|
@ -288,7 +289,7 @@ impl Rooms {
|
|||
},
|
||||
|power_levels| {
|
||||
Ok(serde_json::from_value::<Raw<PowerLevelsEventContent>>(
|
||||
power_levels.content.clone(),
|
||||
power_levels.content,
|
||||
)
|
||||
.expect("Raw::from_value always works.")
|
||||
.deserialize()
|
||||
|
@ -298,13 +299,13 @@ impl Rooms {
|
|||
let sender_membership = self
|
||||
.room_state_get(&room_id, &EventType::RoomMember, &sender.to_string())?
|
||||
.map_or(Ok::<_, Error>(member::MembershipState::Leave), |pdu| {
|
||||
Ok(serde_json::from_value::<Raw<member::MemberEventContent>>(
|
||||
pdu.content.clone(),
|
||||
Ok(
|
||||
serde_json::from_value::<Raw<member::MemberEventContent>>(pdu.content)
|
||||
.expect("Raw::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|_| Error::bad_database("Invalid Member event in db."))?
|
||||
.membership,
|
||||
)
|
||||
.expect("Raw::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|_| Error::bad_database("Invalid Member event in db."))?
|
||||
.membership)
|
||||
})?;
|
||||
|
||||
let sender_power = power_levels.users.get(&sender).map_or_else(
|
||||
|
@ -341,7 +342,7 @@ impl Rooms {
|
|||
)?
|
||||
.map_or(Ok::<_, Error>(member::MembershipState::Leave), |pdu| {
|
||||
Ok(serde_json::from_value::<Raw<member::MemberEventContent>>(
|
||||
pdu.content.clone(),
|
||||
pdu.content,
|
||||
)
|
||||
.expect("Raw::from_value always works.")
|
||||
.deserialize()
|
||||
|
@ -373,7 +374,7 @@ impl Rooms {
|
|||
.map_or(Ok::<_, Error>(join_rules::JoinRule::Public), |pdu| {
|
||||
Ok(serde_json::from_value::<
|
||||
Raw<join_rules::JoinRulesEventContent>,
|
||||
>(pdu.content.clone())
|
||||
>(pdu.content)
|
||||
.expect("Raw::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|_| {
|
||||
|
@ -501,7 +502,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)? {
|
||||
unsigned.insert("prev_content".to_owned(), prev_pdu.content.clone());
|
||||
unsigned.insert("prev_content".to_owned(), prev_pdu.content);
|
||||
unsigned.insert(
|
||||
"prev_sender".to_owned(),
|
||||
serde_json::to_value(prev_pdu.sender).expect("UserId::to_value always works"),
|
||||
|
@ -575,28 +576,24 @@ impl Rooms {
|
|||
self.roomstateid_pdu.insert(key, &*pdu_json.to_string())?;
|
||||
}
|
||||
|
||||
match event_type {
|
||||
EventType::RoomRedaction => {
|
||||
if let Some(redact_id) = &redacts {
|
||||
// TODO: Reason
|
||||
let _reason =
|
||||
serde_json::from_value::<Raw<redaction::RedactionEventContent>>(content)
|
||||
.expect("Raw::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|_| {
|
||||
Error::BadRequest(
|
||||
ErrorKind::InvalidParam,
|
||||
"Invalid redaction event content.",
|
||||
)
|
||||
})?
|
||||
.reason;
|
||||
if let EventType::RoomRedaction = event_type {
|
||||
if let Some(redact_id) = &redacts {
|
||||
// TODO: Reason
|
||||
let _reason =
|
||||
serde_json::from_value::<Raw<redaction::RedactionEventContent>>(content)
|
||||
.expect("Raw::from_value always works.")
|
||||
.deserialize()
|
||||
.map_err(|_| {
|
||||
Error::BadRequest(
|
||||
ErrorKind::InvalidParam,
|
||||
"Invalid redaction event content.",
|
||||
)
|
||||
})?
|
||||
.reason;
|
||||
|
||||
self.redact_pdu(&redact_id)?;
|
||||
}
|
||||
self.redact_pdu(&redact_id)?;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
self.edus.room_read_set(&room_id, &sender, index)?;
|
||||
|
||||
Ok(pdu.event_id)
|
||||
|
|
|
@ -42,7 +42,7 @@ impl Uiaa {
|
|||
.map(|session| {
|
||||
Ok::<_, Error>(self.get_uiaa_session(&user_id, &device_id, session)?)
|
||||
})
|
||||
.unwrap_or(Ok(uiaainfo.clone()))?;
|
||||
.unwrap_or_else(|| Ok(uiaainfo.clone()))?;
|
||||
|
||||
// Find out what the user completed
|
||||
match &**kind {
|
||||
|
|
|
@ -502,7 +502,7 @@ impl Users {
|
|||
));
|
||||
}
|
||||
|
||||
let mut user_signing_key_key = prefix.clone();
|
||||
let mut user_signing_key_key = prefix;
|
||||
user_signing_key_key.extend_from_slice(user_signing_key_id.as_bytes());
|
||||
|
||||
self.keyid_key.insert(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue