go through a ton of pedantic clippy lints
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
33727a3423
commit
e2c7afe69c
61 changed files with 282 additions and 247 deletions
|
@ -36,7 +36,10 @@ use ruma::{
|
|||
use serde_json::value::RawValue as RawJsonValue;
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
|
||||
use crate::{service::*, services, Error, PduEvent};
|
||||
use crate::{
|
||||
service::{pdu, Arc, BTreeMap, HashMap, Result, RwLock},
|
||||
services, Error, PduEvent,
|
||||
};
|
||||
|
||||
use super::state_compressor::CompressedStateEvent;
|
||||
|
||||
|
@ -63,7 +66,7 @@ impl Service {
|
|||
/// 8. If not timeline event: stop
|
||||
/// 9. Fetch any missing prev events doing all checks listed here starting at 1. These are timeline
|
||||
/// events
|
||||
/// 10. Fetch missing state and auth chain events by calling /state_ids at backwards extremities
|
||||
/// 10. Fetch missing state and auth chain events by calling `/state_ids` at backwards extremities
|
||||
/// doing all the checks in this list starting at 1. These are not timeline events
|
||||
/// 11. Check the auth of the event passes based on the state of the event
|
||||
/// 12. Ensure that the state is derived from the previous current state (i.e. we calculated by
|
||||
|
@ -101,7 +104,7 @@ impl Service {
|
|||
|
||||
// 1. Skip the PDU if we already have it as a timeline event
|
||||
if let Some(pdu_id) = services().rooms.timeline.get_pdu_id(event_id)? {
|
||||
return Ok(Some(pdu_id.to_vec()));
|
||||
return Ok(Some(pdu_id));
|
||||
}
|
||||
|
||||
let create_event = services()
|
||||
|
@ -202,7 +205,7 @@ impl Service {
|
|||
e.insert((Instant::now(), 1));
|
||||
}
|
||||
hash_map::Entry::Occupied(mut e) => {
|
||||
*e.get_mut() = (Instant::now(), e.get().1 + 1)
|
||||
*e.get_mut() = (Instant::now(), e.get().1 + 1);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
@ -246,7 +249,7 @@ impl Service {
|
|||
e.insert((Instant::now(), 1));
|
||||
}
|
||||
hash_map::Entry::Occupied(mut e) => {
|
||||
*e.get_mut() = (Instant::now(), e.get().1 + 1)
|
||||
*e.get_mut() = (Instant::now(), e.get().1 + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -440,7 +443,7 @@ impl Service {
|
|||
if !matches!(
|
||||
auth_events
|
||||
.get(&(StateEventType::RoomCreate, "".to_owned()))
|
||||
.map(|a| a.as_ref()),
|
||||
.map(std::convert::AsRef::as_ref),
|
||||
Some(_) | None
|
||||
) {
|
||||
return Err(Error::BadRequest(
|
||||
|
@ -733,7 +736,9 @@ impl Service {
|
|||
.get_shortstatekey(&StateEventType::RoomCreate, "")?
|
||||
.expect("Room exists");
|
||||
|
||||
if state.get(&create_shortstatekey).map(|id| id.as_ref())
|
||||
if state
|
||||
.get(&create_shortstatekey)
|
||||
.map(std::convert::AsRef::as_ref)
|
||||
!= Some(&create_event.event_id)
|
||||
{
|
||||
return Err(Error::bad_database(
|
||||
|
@ -1167,7 +1172,7 @@ impl Service {
|
|||
}
|
||||
}
|
||||
}
|
||||
events_with_auth_events.push((id, None, events_in_reverse_order))
|
||||
events_with_auth_events.push((id, None, events_in_reverse_order));
|
||||
}
|
||||
|
||||
// We go through all the signatures we see on the PDUs and their unresolved
|
||||
|
@ -1185,7 +1190,7 @@ impl Service {
|
|||
warn!(
|
||||
"Could not fetch all signatures for PDUs from {}: {:?}",
|
||||
origin, e
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
let mut pdus = vec![];
|
||||
|
@ -1565,7 +1570,7 @@ impl Service {
|
|||
}
|
||||
|
||||
drop(pkm);
|
||||
}
|
||||
};
|
||||
|
||||
if servers.is_empty() {
|
||||
info!("server is empty, we had all keys locally, not fetching any keys");
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::{
|
||||
service::rooms::timeline::{data::PduData, PduCount},
|
||||
Result,
|
||||
};
|
||||
use crate::{service::rooms::timeline::PduCount, PduEvent, Result};
|
||||
use ruma::{EventId, RoomId, UserId};
|
||||
|
||||
pub trait Data: Send + Sync {
|
||||
fn add_relation(&self, from: u64, to: u64) -> Result<()>;
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn relations_until<'a>(
|
||||
&'a self,
|
||||
user_id: &'a UserId,
|
||||
room_id: u64,
|
||||
target: u64,
|
||||
until: PduCount,
|
||||
) -> PduData<'a>;
|
||||
) -> Result<Box<dyn Iterator<Item = Result<(PduCount, PduEvent)>> + 'a>>;
|
||||
fn mark_as_referenced(&self, room_id: &RoomId, event_ids: &[Arc<EventId>]) -> Result<()>;
|
||||
fn is_event_referenced(&self, room_id: &RoomId, event_id: &EventId) -> Result<bool>;
|
||||
fn mark_event_soft_failed(&self, event_id: &EventId) -> Result<()>;
|
||||
|
|
|
@ -78,7 +78,7 @@ impl Service {
|
|||
})
|
||||
})
|
||||
.take(limit)
|
||||
.filter_map(|r| r.ok()) // Filter out buggy events
|
||||
.filter_map(std::result::Result::ok) // Filter out buggy events
|
||||
.filter(|(_, pdu)| {
|
||||
services()
|
||||
.rooms
|
||||
|
@ -125,7 +125,7 @@ impl Service {
|
|||
})
|
||||
})
|
||||
.take(limit)
|
||||
.filter_map(|r| r.ok()) // Filter out buggy events
|
||||
.filter_map(std::result::Result::ok) // Filter out buggy events
|
||||
.filter(|(_, pdu)| {
|
||||
services()
|
||||
.rooms
|
||||
|
|
|
@ -62,11 +62,11 @@ impl Service {
|
|||
let mut results = Vec::new();
|
||||
|
||||
while let Some(current_room) = {
|
||||
while stack.last().map_or(false, |s| s.is_empty()) {
|
||||
while stack.last().map_or(false, std::vec::Vec::is_empty) {
|
||||
stack.pop();
|
||||
}
|
||||
if !stack.is_empty() {
|
||||
stack.last_mut().and_then(|s| s.pop())
|
||||
stack.last_mut().and_then(std::vec::Vec::pop)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ impl Service {
|
|||
.roomid_spacechunk_cache
|
||||
.lock()
|
||||
.unwrap()
|
||||
.get_mut(¤t_room.to_owned())
|
||||
.get_mut(¤t_room.clone())
|
||||
.as_ref()
|
||||
{
|
||||
if let Some(cached) = cached {
|
||||
|
@ -202,7 +202,7 @@ impl Service {
|
|||
.send_federation_request(
|
||||
server,
|
||||
federation::space::get_hierarchy::v1::Request {
|
||||
room_id: current_room.to_owned(),
|
||||
room_id: current_room.clone(),
|
||||
suggested_only,
|
||||
},
|
||||
)
|
||||
|
|
|
@ -81,16 +81,15 @@ impl Service {
|
|||
/// The user was a joined member at this state (potentially in the past)
|
||||
fn user_was_joined(&self, shortstatehash: u64, user_id: &UserId) -> bool {
|
||||
self.user_membership(shortstatehash, user_id)
|
||||
.map(|s| s == MembershipState::Join)
|
||||
.unwrap_or_default() // Return sensible default, i.e. false
|
||||
.is_ok_and(|s| s == MembershipState::Join) // Return sensible default, i.e. false
|
||||
}
|
||||
|
||||
/// The user was an invited or joined room member at this state (potentially
|
||||
/// in the past)
|
||||
fn user_was_invited(&self, shortstatehash: u64, user_id: &UserId) -> bool {
|
||||
self.user_membership(shortstatehash, user_id)
|
||||
.map(|s| s == MembershipState::Join || s == MembershipState::Invite)
|
||||
.unwrap_or_default() // Return sensible default, i.e. false
|
||||
.is_ok_and(|s| s == MembershipState::Join || s == MembershipState::Invite)
|
||||
// Return sensible default, i.e. false
|
||||
}
|
||||
|
||||
/// Whether a server is allowed to see an event through federation, based on
|
||||
|
@ -102,9 +101,8 @@ impl Service {
|
|||
room_id: &RoomId,
|
||||
event_id: &EventId,
|
||||
) -> Result<bool> {
|
||||
let shortstatehash = match self.pdu_shortstatehash(event_id)? {
|
||||
Some(shortstatehash) => shortstatehash,
|
||||
None => return Ok(true),
|
||||
let Some(shortstatehash) = self.pdu_shortstatehash(event_id)? else {
|
||||
return Ok(true);
|
||||
};
|
||||
|
||||
if let Some(visibility) = self
|
||||
|
@ -130,7 +128,7 @@ impl Service {
|
|||
.rooms
|
||||
.state_cache
|
||||
.room_members(room_id)
|
||||
.filter_map(|r| r.ok())
|
||||
.filter_map(std::result::Result::ok)
|
||||
.filter(|member| member.server_name() == origin);
|
||||
|
||||
let visibility = match history_visibility {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
mod data;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
pub use data::Data;
|
||||
use ruma::{
|
||||
api::client::{error::ErrorKind, threads::get_threads::v1::IncludeThreads},
|
||||
|
@ -56,7 +58,7 @@ impl Service {
|
|||
|
||||
if let CanonicalJsonValue::Object(unsigned) = root_pdu_json
|
||||
.entry("unsigned".to_owned())
|
||||
.or_insert_with(|| CanonicalJsonValue::Object(Default::default()))
|
||||
.or_insert_with(|| CanonicalJsonValue::Object(BTreeMap::default()))
|
||||
{
|
||||
if let Some(mut relations) = unsigned
|
||||
.get("m.relations")
|
||||
|
|
|
@ -6,8 +6,6 @@ use crate::{PduEvent, Result};
|
|||
|
||||
use super::PduCount;
|
||||
|
||||
pub type PduData<'a> = Result<Box<dyn Iterator<Item = Result<(PduCount, PduEvent)>> + 'a>>;
|
||||
|
||||
pub trait Data: Send + Sync {
|
||||
fn last_timeline_count(&self, sender_user: &UserId, room_id: &RoomId) -> Result<PduCount>;
|
||||
|
||||
|
@ -68,12 +66,23 @@ pub trait Data: Send + Sync {
|
|||
|
||||
/// Returns an iterator over all events and their tokens in a room that happened before the
|
||||
/// event with id `until` in reverse-chronological order.
|
||||
fn pdus_until<'a>(&'a self, user_id: &UserId, room_id: &RoomId, until: PduCount)
|
||||
-> PduData<'a>;
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn pdus_until<'a>(
|
||||
&'a self,
|
||||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
until: PduCount,
|
||||
) -> Result<Box<dyn Iterator<Item = Result<(PduCount, PduEvent)>> + 'a>>;
|
||||
|
||||
/// Returns an iterator over all events in a room that happened after the event with id `from`
|
||||
/// in chronological order.
|
||||
fn pdus_after<'a>(&'a self, user_id: &UserId, room_id: &RoomId, from: PduCount) -> PduData<'a>;
|
||||
#[allow(clippy::type_complexity)]
|
||||
fn pdus_after<'a>(
|
||||
&'a self,
|
||||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
from: PduCount,
|
||||
) -> Result<Box<dyn Iterator<Item = Result<(PduCount, PduEvent)>> + 'a>>;
|
||||
|
||||
fn increment_notification_counts(
|
||||
&self,
|
||||
|
|
|
@ -243,7 +243,7 @@ impl Service {
|
|||
if let Some(state_key) = &pdu.state_key {
|
||||
if let CanonicalJsonValue::Object(unsigned) = pdu_json
|
||||
.entry("unsigned".to_owned())
|
||||
.or_insert_with(|| CanonicalJsonValue::Object(Default::default()))
|
||||
.or_insert_with(|| CanonicalJsonValue::Object(BTreeMap::default()))
|
||||
{
|
||||
if let Some(shortstatehash) = services()
|
||||
.rooms
|
||||
|
@ -400,8 +400,10 @@ impl Service {
|
|||
})
|
||||
})
|
||||
.transpose()?
|
||||
.map(|ev: PushRulesEvent| ev.content.global)
|
||||
.unwrap_or_else(|| Ruleset::server_default(user));
|
||||
.map_or_else(
|
||||
|| Ruleset::server_default(user),
|
||||
|ev: PushRulesEvent| ev.content.global,
|
||||
);
|
||||
|
||||
let mut highlight = false;
|
||||
let mut notify = false;
|
||||
|
@ -686,7 +688,7 @@ impl Service {
|
|||
.rooms
|
||||
.alias
|
||||
.local_aliases_for_room(&pdu.room_id)
|
||||
.filter_map(|r| r.ok())
|
||||
.filter_map(std::result::Result::ok)
|
||||
.any(|room_alias| aliases.is_match(room_alias.as_str()))
|
||||
};
|
||||
|
||||
|
@ -930,7 +932,7 @@ impl Service {
|
|||
.filter(|v| v.starts_with('@'))
|
||||
.unwrap_or(sender.as_str());
|
||||
let server_name = services().globals.server_name();
|
||||
let server_user = format!("@conduit:{}", server_name);
|
||||
let server_user = format!("@conduit:{server_name}");
|
||||
let content = serde_json::from_str::<ExtractMembership>(pdu.content.get())
|
||||
.map_err(|_| Error::bad_database("Invalid content in pdu."))?;
|
||||
|
||||
|
@ -947,7 +949,7 @@ impl Service {
|
|||
.rooms
|
||||
.state_cache
|
||||
.room_members(room_id)
|
||||
.filter_map(|m| m.ok())
|
||||
.filter_map(std::result::Result::ok)
|
||||
.filter(|m| m.server_name() == server_name)
|
||||
.filter(|m| m != target)
|
||||
.count();
|
||||
|
@ -973,7 +975,7 @@ impl Service {
|
|||
.rooms
|
||||
.state_cache
|
||||
.room_members(room_id)
|
||||
.filter_map(|m| m.ok())
|
||||
.filter_map(std::result::Result::ok)
|
||||
.filter(|m| m.server_name() == server_name)
|
||||
.filter(|m| m != target)
|
||||
.count();
|
||||
|
@ -1016,7 +1018,7 @@ impl Service {
|
|||
.rooms
|
||||
.state_cache
|
||||
.room_servers(room_id)
|
||||
.filter_map(|r| r.ok())
|
||||
.filter_map(std::result::Result::ok)
|
||||
.collect();
|
||||
|
||||
// In case we are kicking or banning a user, we need to inform their server of the change
|
||||
|
@ -1217,7 +1219,7 @@ impl Service {
|
|||
.roomid_mutex_federation
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.to_owned())
|
||||
.entry(room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let mutex_lock = mutex.lock().await;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue