From c249fd7d4d9f7cf68996663d67625724b710d6e0 Mon Sep 17 00:00:00 2001 From: Nyaaori <+@nyaaori.cat> Date: Wed, 21 Dec 2022 10:22:09 +0100 Subject: [PATCH] chore: code cleanup --- src/api/server_server.rs | 12 +++++------- src/service/rooms/state_accessor/data.rs | 6 ++++-- src/service/rooms/state_accessor/mod.rs | 11 ++++++----- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/api/server_server.rs b/src/api/server_server.rs index 2b7b4f50..045cf13c 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -1116,8 +1116,8 @@ fn get_missing_events( } let events = linearize_previous_events( - latest_events.into_iter().cloned(), - earliest_events.into_iter().cloned(), + latest_events.iter().cloned(), + earliest_events.iter().cloned(), limit, get_pdu, event_filter, @@ -1169,7 +1169,7 @@ where match pdu.get("prev_events") { None => { error!(?pdu, "A stored event has no 'prev_events' field"); - return None; + None } Some(prev_events) => { let val = prev_events.clone().into(); @@ -1977,12 +1977,10 @@ pub async fn claim_keys_route( #[cfg(test)] mod tests { - use super::linearize_previous_events; - use super::{add_port_to_hostname, get_ip_with_port, FedDest}; + use super::{add_port_to_hostname, get_ip_with_port, linearize_previous_events, FedDest}; use ruma::{CanonicalJsonObject, CanonicalJsonValue, OwnedEventId}; use serde::{Deserialize, Serialize}; - use serde_json::value::RawValue; - use serde_json::Value; + use serde_json::{value::RawValue, Value}; use std::collections::HashMap; #[test] diff --git a/src/service/rooms/state_accessor/data.rs b/src/service/rooms/state_accessor/data.rs index 1ac3e314..70261b09 100644 --- a/src/service/rooms/state_accessor/data.rs +++ b/src/service/rooms/state_accessor/data.rs @@ -1,8 +1,10 @@ use std::{collections::HashMap, sync::Arc}; use async_trait::async_trait; -use ruma::events::room::member::MembershipState; -use ruma::{events::StateEventType, EventId, RoomId, UserId}; +use ruma::{ + events::{room::member::MembershipState, StateEventType}, + EventId, RoomId, UserId, +}; use crate::{PduEvent, Result}; diff --git a/src/service/rooms/state_accessor/mod.rs b/src/service/rooms/state_accessor/mod.rs index 7eccbd40..7a8e65db 100644 --- a/src/service/rooms/state_accessor/mod.rs +++ b/src/service/rooms/state_accessor/mod.rs @@ -8,7 +8,8 @@ pub use data::Data; use lru_cache::LruCache; use ruma::{ events::{ - room::history_visibility::HistoryVisibility, room::member::MembershipState, StateEventType, + room::{history_visibility::HistoryVisibility, member::MembershipState}, + StateEventType, }, EventId, OwnedServerName, OwnedUserId, RoomId, ServerName, UserId, }; @@ -110,14 +111,14 @@ impl Service { Some(HistoryVisibility::Invited) => { // Allow if any member on requesting server was AT LEAST invited, else deny current_server_members - .into_iter() - .any(|member| self.user_was_invited(shortstatehash, &member)) + .iter() + .any(|member| self.user_was_invited(shortstatehash, member)) } _ => { // Allow if any member on requested server was joined, else deny current_server_members - .into_iter() - .any(|member| self.user_was_joined(shortstatehash, &member)) + .iter() + .any(|member| self.user_was_joined(shortstatehash, member)) } };