Clippy suggestions
Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
This commit is contained in:
parent
f0f7542332
commit
2863fe52c1
5 changed files with 42 additions and 22 deletions
|
@ -46,14 +46,17 @@ pub enum AuthMethod<'a> {
|
|||
}
|
||||
|
||||
impl MatrixClient {
|
||||
#[must_use]
|
||||
pub fn new(client: Client) -> Self {
|
||||
Self { client }
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn new_arc(client: Client) -> Arc<Self> {
|
||||
Arc::new(Self::new(client))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn client(&self) -> &Client {
|
||||
&self.client
|
||||
}
|
||||
|
@ -65,9 +68,9 @@ impl MatrixClient {
|
|||
password,
|
||||
initial_device_display_name,
|
||||
} => {
|
||||
let tmp = self.client.matrix_auth().login_username(user, &password);
|
||||
let tmp = self.client.matrix_auth().login_username(user, password);
|
||||
if let Some(name) = initial_device_display_name {
|
||||
tmp.initial_device_display_name(&name)
|
||||
tmp.initial_device_display_name(name)
|
||||
} else {
|
||||
tmp
|
||||
}
|
||||
|
@ -122,6 +125,7 @@ impl MatrixClient {
|
|||
}
|
||||
};
|
||||
}
|
||||
#[allow(clippy::match_wildcard_for_single_variants)]
|
||||
match msg {
|
||||
RoomMessageEvent::Original(msg) => {
|
||||
impl_file_like!(&msg.content.msgtype, Image, Video, Audio, File)
|
||||
|
@ -130,6 +134,7 @@ impl MatrixClient {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
pub async fn setup_e2e(self: Arc<Self>) -> bool {
|
||||
let client = &self.client;
|
||||
|
||||
|
@ -242,20 +247,20 @@ impl MatrixClient {
|
|||
match verification {
|
||||
Verification::SasV1(v) => {
|
||||
v.accept().await.expect("Failed to accept verification");
|
||||
let emoji_str = v
|
||||
.emoji()
|
||||
.map(|emojis| {
|
||||
let emoji_str = v.emoji().map_or_else(
|
||||
|| "No emojis".to_string(),
|
||||
|emojis| {
|
||||
emojis
|
||||
.iter()
|
||||
.map(|e| format!("{} ({})", e.symbol, e.description))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
})
|
||||
.unwrap_or_else(|| "No emojis".to_string());
|
||||
let decimals = v
|
||||
.decimals()
|
||||
.map(|(n1, n2, n3)| format!("{} {} {}", n1, n2, n3))
|
||||
.unwrap_or_else(|| "No decimals".to_string());
|
||||
},
|
||||
);
|
||||
let decimals = v.decimals().map_or_else(
|
||||
|| "No decimals".to_string(),
|
||||
|(n1, n2, n3)| format!("[{n1}, {n2}, {n3}]"),
|
||||
);
|
||||
|
||||
if prompt(
|
||||
&mut stdin,
|
||||
|
@ -330,12 +335,14 @@ impl MatrixClient {
|
|||
println!(
|
||||
"Verification for {}:\nEmoji: {}\nDecimals: [{}, {}, {}]\n Confirm? (y/n)",
|
||||
device.device_id(),
|
||||
emojis.map(|e| e.emojis
|
||||
.iter()
|
||||
.map(|e| format!("{} ({})", e.symbol, e.description))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "),
|
||||
).unwrap_or_else(|| "No emojis".to_string()),
|
||||
emojis.map_or_else(
|
||||
|| "No emojis".to_string(),
|
||||
|e| e.emojis
|
||||
.iter()
|
||||
.map(|e| format!("{} ({})", e.symbol, e.description))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", "),
|
||||
),
|
||||
decimals.0, decimals.1, decimals.2
|
||||
);
|
||||
|
||||
|
@ -385,6 +392,7 @@ impl MatrixClient {
|
|||
false
|
||||
}
|
||||
|
||||
#[allow(clippy::must_use_candidate)]
|
||||
pub fn room_messages(
|
||||
room: &Room,
|
||||
since: Option<String>,
|
||||
|
|
|
@ -36,7 +36,7 @@ pub enum DecryptError {
|
|||
VersionMismatch,
|
||||
}
|
||||
|
||||
pub async fn try_decrypt<'s, E>(
|
||||
pub fn try_decrypt<'s, E>(
|
||||
jwk: &JsonWebKey,
|
||||
data: impl TryStream<Ok = Vec<u8>, Error = E> + Send + 's,
|
||||
iv: &[u8],
|
||||
|
@ -64,6 +64,7 @@ pub struct VerifyingStream<'a, S> {
|
|||
}
|
||||
|
||||
impl<'a, S> VerifyingStream<'a, S> {
|
||||
#[must_use]
|
||||
pub fn new(inner: Pin<Box<S>>, expected: &'a [u8]) -> Self {
|
||||
Self {
|
||||
inner,
|
||||
|
@ -120,5 +121,5 @@ pub async fn decrypt_file<'s, E: std::error::Error + 's>(
|
|||
sha256_expect,
|
||||
));
|
||||
|
||||
try_decrypt(&file.key, data, iv).await
|
||||
try_decrypt(&file.key, data, iv)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ use ruma_client_api::{
|
|||
sync::sync_events::v3::Filter,
|
||||
};
|
||||
|
||||
#[must_use]
|
||||
pub fn minimal_sync_filter() -> Filter {
|
||||
let mut filter = FilterDefinition::empty();
|
||||
|
||||
|
@ -19,7 +20,7 @@ pub fn minimal_sync_filter() -> Filter {
|
|||
"m.room.avatar",
|
||||
]
|
||||
.into_iter()
|
||||
.map(|s| s.to_string())
|
||||
.map(ToString::to_string)
|
||||
.collect(),
|
||||
);
|
||||
room_filter.timeline = room_event_filter;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#[must_use]
|
||||
pub fn sanitize_filename(name: &str) -> String {
|
||||
name.chars()
|
||||
.map(|c| match c {
|
||||
|
|
13
src/lib.rs
13
src/lib.rs
|
@ -1,3 +1,8 @@
|
|||
#![warn(clippy::pedantic)]
|
||||
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
|
||||
#![allow(clippy::ignored_unit_patterns)]
|
||||
#![allow(clippy::module_name_repetitions)]
|
||||
|
||||
use std::{
|
||||
fs::OpenOptions,
|
||||
os::unix::fs::OpenOptionsExt,
|
||||
|
@ -75,6 +80,7 @@ pub struct Args {
|
|||
pub key_sync_timeout: u64,
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn mxc_url_to_https(mxc_url: &str, homeserver: &str) -> String {
|
||||
format!(
|
||||
"{}_matrix/media/r0/download/{}",
|
||||
|
@ -113,6 +119,7 @@ pub enum DumpError {
|
|||
InvalidId(#[from] IdParseError),
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
pub async fn dump_room_messages(
|
||||
room: &matrix_sdk::Room,
|
||||
out_dir: &Path,
|
||||
|
@ -135,7 +142,7 @@ pub async fn dump_room_messages(
|
|||
|
||||
let mut out = Vec::with_capacity(msg.len());
|
||||
|
||||
for event in msg.into_iter() {
|
||||
for event in msg {
|
||||
let mut fm = None;
|
||||
match event.event.clone().cast::<AnyTimelineEvent>().deserialize() {
|
||||
Ok(event) => {
|
||||
|
@ -235,6 +242,7 @@ pub async fn dump_room_messages(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
pub async fn run(
|
||||
js: &mut JoinSet<Result<(), DumpError>>,
|
||||
bg_js: &mut JoinSet<Result<(), DumpError>>,
|
||||
|
@ -352,6 +360,7 @@ pub async fn run(
|
|||
|
||||
{
|
||||
log::info!("Starting E2E setup");
|
||||
#[allow(clippy::match_bool, clippy::single_match_else)]
|
||||
match client.clone().setup_e2e().await {
|
||||
true => log::info!("E2E setup done"),
|
||||
false => log::error!("E2E setup failed, E2E will not be decrypted"),
|
||||
|
@ -426,7 +435,7 @@ pub async fn run(
|
|||
.unwrap_or(room.name().unwrap_or("unknown".to_string()));
|
||||
|
||||
let room_dir =
|
||||
Path::new(&out_dir).join(sanitize_filename(&format!("{}_{}", room_id, room_name)));
|
||||
Path::new(&out_dir).join(sanitize_filename(&format!("{room_id}_{room_name}")));
|
||||
|
||||
let match_filter = if filter.is_empty() {
|
||||
true
|
||||
|
|
Loading…
Reference in a new issue