run cargo fix for rust 2024 changes and rustfmt

Signed-off-by: June Clementine Strawberry <strawberry@puppygock.gay>
This commit is contained in:
June Clementine Strawberry 2025-02-23 01:17:45 -05:00
parent e97952b7f6
commit a1e1f40ded
No known key found for this signature in database
320 changed files with 2212 additions and 2039 deletions

View file

@ -3,21 +3,20 @@ mod remote;
use std::sync::Arc;
use conduwuit::{
err,
utils::{stream::TryIgnore, ReadyExt},
Err, Result, Server,
Err, Result, Server, err,
utils::{ReadyExt, stream::TryIgnore},
};
use database::{Deserialized, Ignore, Interfix, Map};
use futures::{Stream, StreamExt, TryFutureExt};
use ruma::{
events::{
room::power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent},
StateEventType,
},
OwnedRoomId, OwnedServerName, OwnedUserId, RoomAliasId, RoomId, RoomOrAliasId, UserId,
events::{
StateEventType,
room::power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent},
},
};
use crate::{admin, appservice, appservice::RegistrationInfo, globals, rooms, sending, Dep};
use crate::{Dep, admin, appservice, appservice::RegistrationInfo, globals, rooms, sending};
pub struct Service {
db: Data,

View file

@ -1,8 +1,8 @@
use std::iter::once;
use conduwuit::{debug, debug_error, err, implement, Result};
use conduwuit::{Result, debug, debug_error, err, implement};
use federation::query::get_room_information::v1::Response;
use ruma::{api::federation, OwnedRoomId, OwnedServerName, RoomAliasId, ServerName};
use ruma::{OwnedRoomId, OwnedServerName, RoomAliasId, ServerName, api::federation};
#[implement(super::Service)]
pub(super) async fn remote_resolve(

View file

@ -3,7 +3,7 @@ use std::{
sync::{Arc, Mutex},
};
use conduwuit::{err, utils, utils::math::usize_from_f64, Err, Result};
use conduwuit::{Err, Result, err, utils, utils::math::usize_from_f64};
use database::Map;
use lru_cache::LruCache;

View file

@ -8,18 +8,18 @@ use std::{
};
use conduwuit::{
at, debug, debug_error, implement, trace,
Err, Result, at, debug, debug_error, implement, trace,
utils::{
stream::{ReadyExt, TryBroadbandExt},
IterStream,
stream::{ReadyExt, TryBroadbandExt},
},
validated, warn, Err, Result,
validated, warn,
};
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt};
use ruma::{EventId, OwnedEventId, RoomId};
use self::data::Data;
use crate::{rooms, rooms::short::ShortEventId, Dep};
use crate::{Dep, rooms, rooms::short::ShortEventId};
pub struct Service {
services: Services,

View file

@ -1,9 +1,9 @@
use std::sync::Arc;
use conduwuit::{implement, utils::stream::TryIgnore, Result};
use conduwuit::{Result, implement, utils::stream::TryIgnore};
use database::Map;
use futures::Stream;
use ruma::{api::client::room::Visibility, RoomId};
use ruma::{RoomId, api::client::room::Visibility};
pub struct Service {
db: Data,

View file

@ -1,7 +1,7 @@
use conduwuit::{debug, implement, trace, warn, Err, Result};
use conduwuit::{Err, Result, debug, implement, trace, warn};
use ruma::{
events::{room::server_acl::RoomServerAclEventContent, StateEventType},
RoomId, ServerName,
events::{StateEventType, room::server_acl::RoomServerAclEventContent},
};
/// Returns Ok if the acl allows the server

View file

@ -1,16 +1,16 @@
use std::{
collections::{hash_map, BTreeMap, HashSet, VecDeque},
collections::{BTreeMap, HashSet, VecDeque, hash_map},
sync::Arc,
time::Instant,
};
use conduwuit::{
debug, debug_error, debug_warn, implement, pdu, trace,
utils::continue_exponential_backoff_secs, warn, PduEvent,
PduEvent, debug, debug_error, debug_warn, implement, pdu, trace,
utils::continue_exponential_backoff_secs, warn,
};
use futures::TryFutureExt;
use ruma::{
api::federation::event::get_event, CanonicalJsonValue, OwnedEventId, RoomId, ServerName,
CanonicalJsonValue, OwnedEventId, RoomId, ServerName, api::federation::event::get_event,
};
use super::get_room_version_id;
@ -138,12 +138,15 @@ pub(super) async fn fetch_and_handle_outliers<'a>(
.and_then(CanonicalJsonValue::as_array)
{
for auth_event in auth_events {
if let Ok(auth_event) =
serde_json::from_value::<OwnedEventId>(auth_event.clone().into())
{
todo_auth_events.push_back(auth_event);
} else {
warn!("Auth event id is not valid");
match serde_json::from_value::<OwnedEventId>(
auth_event.clone().into(),
) {
| Ok(auth_event) => {
todo_auth_events.push_back(auth_event);
},
| _ => {
warn!("Auth event id is not valid");
},
}
}
} else {

View file

@ -4,14 +4,13 @@ use std::{
};
use conduwuit::{
debug_warn, err, implement,
PduEvent, Result, debug_warn, err, implement,
state_res::{self},
PduEvent, Result,
};
use futures::{future, FutureExt};
use futures::{FutureExt, future};
use ruma::{
int, uint, CanonicalJsonValue, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, ServerName,
UInt,
CanonicalJsonValue, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, ServerName, UInt, int,
uint,
};
use super::check_room_id;
@ -43,54 +42,59 @@ pub(super) async fn fetch_prev(
while let Some(prev_event_id) = todo_outlier_stack.pop_front() {
self.services.server.check_running()?;
if let Some((pdu, mut json_opt)) = self
match self
.fetch_and_handle_outliers(origin, &[prev_event_id.clone()], create_event, room_id)
.boxed()
.await
.pop()
{
check_room_id(room_id, &pdu)?;
| Some((pdu, mut json_opt)) => {
check_room_id(room_id, &pdu)?;
let limit = self.services.server.config.max_fetch_prev_events;
if amount > limit {
debug_warn!("Max prev event limit reached! Limit: {limit}");
graph.insert(prev_event_id.clone(), HashSet::new());
continue;
}
if json_opt.is_none() {
json_opt = self
.services
.outlier
.get_outlier_pdu_json(&prev_event_id)
.await
.ok();
}
if let Some(json) = json_opt {
if pdu.origin_server_ts > first_ts_in_room {
amount = amount.saturating_add(1);
for prev_prev in &pdu.prev_events {
if !graph.contains_key(prev_prev) {
todo_outlier_stack.push_back(prev_prev.clone());
}
}
graph
.insert(prev_event_id.clone(), pdu.prev_events.iter().cloned().collect());
} else {
// Time based check failed
let limit = self.services.server.config.max_fetch_prev_events;
if amount > limit {
debug_warn!("Max prev event limit reached! Limit: {limit}");
graph.insert(prev_event_id.clone(), HashSet::new());
continue;
}
eventid_info.insert(prev_event_id.clone(), (pdu, json));
} else {
// Get json failed, so this was not fetched over federation
if json_opt.is_none() {
json_opt = self
.services
.outlier
.get_outlier_pdu_json(&prev_event_id)
.await
.ok();
}
if let Some(json) = json_opt {
if pdu.origin_server_ts > first_ts_in_room {
amount = amount.saturating_add(1);
for prev_prev in &pdu.prev_events {
if !graph.contains_key(prev_prev) {
todo_outlier_stack.push_back(prev_prev.clone());
}
}
graph.insert(
prev_event_id.clone(),
pdu.prev_events.iter().cloned().collect(),
);
} else {
// Time based check failed
graph.insert(prev_event_id.clone(), HashSet::new());
}
eventid_info.insert(prev_event_id.clone(), (pdu, json));
} else {
// Get json failed, so this was not fetched over federation
graph.insert(prev_event_id.clone(), HashSet::new());
}
},
| _ => {
// Fetch and handle failed
graph.insert(prev_event_id.clone(), HashSet::new());
}
} else {
// Fetch and handle failed
graph.insert(prev_event_id.clone(), HashSet::new());
},
}
}

View file

@ -1,10 +1,10 @@
use std::collections::{hash_map, HashMap};
use std::collections::{HashMap, hash_map};
use conduwuit::{debug, debug_warn, implement, Err, Error, PduEvent, Result};
use conduwuit::{Err, Error, PduEvent, Result, debug, debug_warn, implement};
use futures::FutureExt;
use ruma::{
api::federation::event::get_room_state_ids, events::StateEventType, EventId, OwnedEventId,
RoomId, ServerName,
EventId, OwnedEventId, RoomId, ServerName, api::federation::event::get_room_state_ids,
events::StateEventType,
};
use crate::rooms::short::ShortStateKey;

View file

@ -1,14 +1,14 @@
use std::{
collections::{hash_map, BTreeMap},
collections::{BTreeMap, hash_map},
time::Instant,
};
use conduwuit::{debug, debug::INFO_SPAN_LEVEL, err, implement, warn, Err, Result};
use conduwuit::{Err, Result, debug, debug::INFO_SPAN_LEVEL, err, implement, warn};
use futures::{
future::{try_join5, OptionFuture},
FutureExt,
future::{OptionFuture, try_join5},
};
use ruma::{events::StateEventType, CanonicalJsonValue, EventId, RoomId, ServerName, UserId};
use ruma::{CanonicalJsonValue, EventId, RoomId, ServerName, UserId, events::StateEventType};
use crate::rooms::timeline::RawPduId;

View file

@ -1,15 +1,15 @@
use std::{
collections::{hash_map, BTreeMap, HashMap},
collections::{BTreeMap, HashMap, hash_map},
sync::Arc,
};
use conduwuit::{
debug, debug_info, err, implement, state_res, trace, warn, Err, Error, PduEvent, Result,
Err, Error, PduEvent, Result, debug, debug_info, err, implement, state_res, trace, warn,
};
use futures::{future::ready, TryFutureExt};
use futures::{TryFutureExt, future::ready};
use ruma::{
api::client::error::ErrorKind, events::StateEventType, CanonicalJsonObject,
CanonicalJsonValue, EventId, RoomId, ServerName,
CanonicalJsonObject, CanonicalJsonValue, EventId, RoomId, ServerName,
api::client::error::ErrorKind, events::StateEventType,
};
use super::{check_room_id, get_room_version_id, to_room_version};

View file

@ -5,8 +5,8 @@ use std::{
};
use conduwuit::{
debug, debug::INFO_SPAN_LEVEL, implement, utils::continue_exponential_backoff_secs, Err,
PduEvent, Result,
Err, PduEvent, Result, debug, debug::INFO_SPAN_LEVEL, implement,
utils::continue_exponential_backoff_secs,
};
use ruma::{CanonicalJsonValue, EventId, OwnedEventId, RoomId, ServerName, UInt};

View file

@ -18,16 +18,16 @@ use std::{
};
use conduwuit::{
utils::{MutexMap, TryFutureExtExt},
Err, PduEvent, Result, RoomVersion, Server,
utils::{MutexMap, TryFutureExtExt},
};
use futures::TryFutureExt;
use ruma::{
events::room::create::RoomCreateEventContent, OwnedEventId, OwnedRoomId, RoomId,
RoomVersionId,
OwnedEventId, OwnedRoomId, RoomId, RoomVersionId,
events::room::create::RoomCreateEventContent,
};
use crate::{globals, rooms, sending, server_keys, Dep};
use crate::{Dep, globals, rooms, sending, server_keys};
pub struct Service {
pub mutex_federation: RoomMutexMap,

View file

@ -1,4 +1,4 @@
use conduwuit::{err, implement, pdu::gen_event_id_canonical_json, result::FlatOk, Result};
use conduwuit::{Result, err, implement, pdu::gen_event_id_canonical_json, result::FlatOk};
use ruma::{CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId};
use serde_json::value::RawValue as RawJsonValue;

View file

@ -5,13 +5,12 @@ use std::{
};
use conduwuit::{
err, implement,
Error, Result, err, implement,
state_res::{self, StateMap},
trace,
utils::stream::{automatic_width, IterStream, ReadyExt, TryWidebandExt, WidebandExt},
Error, Result,
utils::stream::{IterStream, ReadyExt, TryWidebandExt, WidebandExt, automatic_width},
};
use futures::{future::try_join, FutureExt, StreamExt, TryFutureExt, TryStreamExt};
use futures::{FutureExt, StreamExt, TryFutureExt, TryStreamExt, future::try_join};
use ruma::{OwnedEventId, RoomId, RoomVersionId};
use crate::rooms::state_compressor::CompressedState;
@ -93,11 +92,7 @@ pub async fn resolve_state(
let new_room_state: CompressedState = self
.services
.state_compressor
.compress_state_events(
state_events
.iter()
.map(|(ref ssk, eid)| (ssk, (*eid).borrow())),
)
.compress_state_events(state_events.iter().map(|(ssk, eid)| (ssk, (*eid).borrow())))
.collect()
.await;

View file

@ -6,11 +6,10 @@ use std::{
};
use conduwuit::{
debug, err, implement, trace,
PduEvent, Result, StateMap, debug, err, implement, trace,
utils::stream::{BroadbandExt, IterStream, ReadyExt, TryBroadbandExt, TryWidebandExt},
PduEvent, Result, StateMap,
};
use futures::{future::try_join, FutureExt, StreamExt, TryFutureExt, TryStreamExt};
use futures::{FutureExt, StreamExt, TryFutureExt, TryStreamExt, future::try_join};
use ruma::{OwnedEventId, RoomId, RoomVersionId};
use crate::rooms::short::ShortStateHash;

View file

@ -1,12 +1,13 @@
use std::{borrow::Borrow, collections::BTreeMap, iter::once, sync::Arc, time::Instant};
use conduwuit::{
debug, debug_info, err, implement, state_res, trace,
Err, EventTypeExt, PduEvent, Result, StateKey, debug, debug_info, err, implement, state_res,
trace,
utils::stream::{BroadbandExt, ReadyExt},
warn, Err, EventTypeExt, PduEvent, Result, StateKey,
warn,
};
use futures::{future::ready, FutureExt, StreamExt};
use ruma::{events::StateEventType, CanonicalJsonValue, RoomId, ServerName};
use futures::{FutureExt, StreamExt, future::ready};
use ruma::{CanonicalJsonValue, RoomId, ServerName, events::StateEventType};
use super::{get_room_version_id, to_room_version};
use crate::rooms::{

View file

@ -3,13 +3,12 @@
use std::{collections::HashSet, sync::Arc};
use conduwuit::{
implement,
utils::{stream::TryIgnore, IterStream, ReadyExt},
Result,
Result, implement,
utils::{IterStream, ReadyExt, stream::TryIgnore},
};
use database::{Database, Deserialized, Handle, Interfix, Map, Qry};
use futures::{pin_mut, Stream, StreamExt};
use ruma::{api::client::filter::LazyLoadOptions, DeviceId, OwnedUserId, RoomId, UserId};
use futures::{Stream, StreamExt, pin_mut};
use ruma::{DeviceId, OwnedUserId, RoomId, UserId, api::client::filter::LazyLoadOptions};
pub struct Service {
db: Data,

View file

@ -1,11 +1,11 @@
use std::sync::Arc;
use conduwuit::{implement, utils::stream::TryIgnore, Result};
use conduwuit::{Result, implement, utils::stream::TryIgnore};
use database::Map;
use futures::{Stream, StreamExt};
use ruma::RoomId;
use crate::{rooms, Dep};
use crate::{Dep, rooms};
pub struct Service {
db: Data,

View file

@ -1,6 +1,6 @@
use std::sync::Arc;
use conduwuit::{implement, Result};
use conduwuit::{Result, implement};
use database::{Deserialized, Json, Map};
use ruma::{CanonicalJsonObject, EventId};

View file

@ -1,25 +1,25 @@
use std::{mem::size_of, sync::Arc};
use conduwuit::{
PduCount, PduEvent,
arrayvec::ArrayVec,
result::LogErr,
utils::{
ReadyExt,
stream::{TryIgnore, WidebandExt},
u64_from_u8, ReadyExt,
u64_from_u8,
},
PduCount, PduEvent,
};
use database::Map;
use futures::{Stream, StreamExt};
use ruma::{api::Direction, EventId, RoomId, UserId};
use ruma::{EventId, RoomId, UserId, api::Direction};
use crate::{
rooms,
Dep, rooms,
rooms::{
short::{ShortEventId, ShortRoomId},
timeline::{PduId, RawPduId},
},
Dep,
};
pub(super) struct Data {

View file

@ -2,11 +2,11 @@ mod data;
use std::sync::Arc;
use conduwuit::{PduCount, Result};
use futures::{future::try_join, StreamExt};
use ruma::{api::Direction, EventId, RoomId, UserId};
use futures::{StreamExt, future::try_join};
use ruma::{EventId, RoomId, UserId, api::Direction};
use self::data::{Data, PdusIterItem};
use crate::{rooms, Dep};
use crate::{Dep, rooms};
pub struct Service {
services: Services,
@ -81,7 +81,7 @@ impl Service {
.collect();
'limit: while let Some(stack_pdu) = stack.pop() {
let target = match stack_pdu.0 .0 {
let target = match stack_pdu.0.0 {
| PduCount::Normal(c) => c,
// TODO: Support backfilled relations
| PduCount::Backfilled(_) => 0, // This will result in an empty iterator

View file

@ -1,18 +1,18 @@
use std::sync::Arc;
use conduwuit::{
utils::{stream::TryIgnore, ReadyExt},
Result,
utils::{ReadyExt, stream::TryIgnore},
};
use database::{Deserialized, Json, Map};
use futures::{Stream, StreamExt};
use ruma::{
events::{receipt::ReceiptEvent, AnySyncEphemeralRoomEvent},
serde::Raw,
CanonicalJsonObject, RoomId, UserId,
events::{AnySyncEphemeralRoomEvent, receipt::ReceiptEvent},
serde::Raw,
};
use crate::{globals, Dep};
use crate::{Dep, globals};
pub(super) struct Data {
roomuserid_privateread: Arc<Map>,

View file

@ -2,19 +2,19 @@ mod data;
use std::{collections::BTreeMap, sync::Arc};
use conduwuit::{debug, err, warn, PduCount, PduId, RawPduId, Result};
use futures::{try_join, Stream, TryFutureExt};
use conduwuit::{PduCount, PduId, RawPduId, Result, debug, err, warn};
use futures::{Stream, TryFutureExt, try_join};
use ruma::{
OwnedEventId, OwnedUserId, RoomId, UserId,
events::{
receipt::{ReceiptEvent, ReceiptEventContent, Receipts},
AnySyncEphemeralRoomEvent, SyncEphemeralRoomEvent,
receipt::{ReceiptEvent, ReceiptEventContent, Receipts},
},
serde::Raw,
OwnedEventId, OwnedUserId, RoomId, UserId,
};
use self::data::{Data, ReceiptItem};
use crate::{rooms, sending, Dep};
use crate::{Dep, rooms, sending};
pub struct Service {
services: Services,
@ -145,12 +145,14 @@ where
let receipt = serde_json::from_str::<SyncEphemeralRoomEvent<ReceiptEventContent>>(
value.json().get(),
);
if let Ok(value) = receipt {
for (event, receipt) in value.content {
json.insert(event, receipt);
}
} else {
debug!("failed to parse receipt: {:?}", receipt);
match receipt {
| Ok(value) =>
for (event, receipt) in value.content {
json.insert(event, receipt);
},
| _ => {
debug!("failed to parse receipt: {:?}", receipt);
},
}
}
let content = ReceiptEventContent::from_iter(json);

View file

@ -1,26 +1,24 @@
use std::sync::Arc;
use conduwuit::{
PduCount, PduEvent, Result,
arrayvec::ArrayVec,
implement,
utils::{
set,
ArrayVecExt, IterStream, ReadyExt, set,
stream::{TryIgnore, WidebandExt},
ArrayVecExt, IterStream, ReadyExt,
},
PduCount, PduEvent, Result,
};
use database::{keyval::Val, Map};
use database::{Map, keyval::Val};
use futures::{Stream, StreamExt};
use ruma::{api::client::search::search_events::v3::Criteria, RoomId, UserId};
use ruma::{RoomId, UserId, api::client::search::search_events::v3::Criteria};
use crate::{
rooms,
Dep, rooms,
rooms::{
short::ShortRoomId,
timeline::{PduId, RawPduId},
},
Dep,
};
pub struct Service {
@ -140,7 +138,7 @@ pub async fn search_pdus<'a>(
pub async fn search_pdu_ids(
&self,
query: &RoomQuery<'_>,
) -> Result<impl Stream<Item = RawPduId> + Send + '_> {
) -> Result<impl Stream<Item = RawPduId> + Send + '_ + use<'_>> {
let shortroomid = self.services.short.get_shortroomid(query.room_id).await?;
let pdu_ids = self.search_pdu_ids_query_room(query, shortroomid).await;
@ -187,7 +185,7 @@ fn search_pdu_ids_query_word(
&self,
shortroomid: ShortRoomId,
word: &str,
) -> impl Stream<Item = Val<'_>> + Send + '_ {
) -> impl Stream<Item = Val<'_>> + Send + '_ + use<'_> {
// rustc says const'ing this not yet stable
let end_id: RawPduId = PduId {
shortroomid,

View file

@ -1,13 +1,13 @@
use std::{borrow::Borrow, fmt::Debug, mem::size_of_val, sync::Arc};
pub use conduwuit::pdu::{ShortEventId, ShortId, ShortRoomId, ShortStateKey};
use conduwuit::{err, implement, utils, utils::IterStream, Result, StateKey};
use conduwuit::{Result, StateKey, err, implement, utils, utils::IterStream};
use database::{Deserialized, Get, Map, Qry};
use futures::{Stream, StreamExt};
use ruma::{events::StateEventType, EventId, RoomId};
use ruma::{EventId, RoomId, events::StateEventType};
use serde::Deserialize;
use crate::{globals, Dep};
use crate::{Dep, globals};
pub struct Service {
db: Data,

View file

@ -5,18 +5,18 @@ mod tests;
use std::sync::Arc;
use conduwuit::{
implement,
Err, Error, Result, implement,
utils::{
IterStream,
future::BoolExt,
math::usize_from_f64,
stream::{BroadbandExt, ReadyExt},
IterStream,
},
Err, Error, Result,
};
use futures::{pin_mut, stream::FuturesUnordered, FutureExt, Stream, StreamExt, TryFutureExt};
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, pin_mut, stream::FuturesUnordered};
use lru_cache::LruCache;
use ruma::{
OwnedEventId, OwnedRoomId, OwnedServerName, RoomId, ServerName, UserId,
api::{
client::space::SpaceHierarchyRoomsChunk,
federation::{
@ -25,18 +25,17 @@ use ruma::{
},
},
events::{
StateEventType,
room::join_rules::{JoinRule, RoomJoinRulesEventContent},
space::child::{HierarchySpaceChildEvent, SpaceChildEventContent},
StateEventType,
},
serde::Raw,
space::SpaceRoomJoinRule,
OwnedEventId, OwnedRoomId, OwnedServerName, RoomId, ServerName, UserId,
};
use tokio::sync::{Mutex, MutexGuard};
pub use self::pagination_token::PaginationToken;
use crate::{conduwuit::utils::TryFutureExtExt, rooms, sending, Dep};
use crate::{Dep, conduwuit::utils::TryFutureExtExt, rooms, sending};
pub struct Service {
services: Services,
@ -440,8 +439,9 @@ async fn is_accessible_child(
pub fn get_parent_children_via(
parent: &SpaceHierarchyParentSummary,
suggested_only: bool,
) -> impl DoubleEndedIterator<Item = (OwnedRoomId, impl Iterator<Item = OwnedServerName>)> + Send + '_
{
) -> impl DoubleEndedIterator<Item = (OwnedRoomId, impl Iterator<Item = OwnedServerName> + use<>)>
+ Send
+ '_ {
parent
.children_state
.iter()

View file

@ -4,7 +4,7 @@ use std::{
};
use conduwuit::{Error, Result};
use ruma::{api::client::error::ErrorKind, UInt};
use ruma::{UInt, api::client::error::ErrorKind};
use crate::rooms::short::ShortRoomId;

View file

@ -1,13 +1,13 @@
use std::str::FromStr;
use ruma::{
UInt,
api::federation::space::{SpaceHierarchyParentSummary, SpaceHierarchyParentSummaryInit},
owned_room_id, owned_server_name,
space::SpaceRoomJoinRule,
UInt,
};
use crate::rooms::spaces::{get_parent_children_via, PaginationToken};
use crate::rooms::spaces::{PaginationToken, get_parent_children_via};
#[test]
fn get_summary_children() {

View file

@ -1,36 +1,34 @@
use std::{collections::HashMap, fmt::Write, iter::once, sync::Arc};
use conduwuit::{
err,
PduEvent, Result, err,
result::FlatOk,
state_res::{self, StateMap},
utils::{
calculate_hash,
IterStream, MutexMap, MutexMapGuard, ReadyExt, calculate_hash,
stream::{BroadbandExt, TryIgnore},
IterStream, MutexMap, MutexMapGuard, ReadyExt,
},
warn, PduEvent, Result,
warn,
};
use database::{Deserialized, Ignore, Interfix, Map};
use futures::{
future::join_all, pin_mut, FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt,
FutureExt, Stream, StreamExt, TryFutureExt, TryStreamExt, future::join_all, pin_mut,
};
use ruma::{
EventId, OwnedEventId, OwnedRoomId, RoomId, RoomVersionId, UserId,
events::{
room::{create::RoomCreateEventContent, member::RoomMemberEventContent},
AnyStrippedStateEvent, StateEventType, TimelineEventType,
room::{create::RoomCreateEventContent, member::RoomMemberEventContent},
},
serde::Raw,
EventId, OwnedEventId, OwnedRoomId, RoomId, RoomVersionId, UserId,
};
use crate::{
globals, rooms,
Dep, globals, rooms,
rooms::{
short::{ShortEventId, ShortStateHash},
state_compressor::{parse_compressed_state_event, CompressedState},
state_compressor::{CompressedState, parse_compressed_state_event},
},
Dep,
};
pub struct Service {
@ -192,13 +190,13 @@ impl Service {
.await;
if !already_existed {
let states_parents = if let Ok(p) = previous_shortstatehash {
self.services
.state_compressor
.load_shortstatehash_info(p)
.await?
} else {
Vec::new()
let states_parents = match previous_shortstatehash {
| Ok(p) =>
self.services
.state_compressor
.load_shortstatehash_info(p)
.await?,
| _ => Vec::new(),
};
let (statediffnew, statediffremoved) =
@ -256,63 +254,65 @@ impl Service {
.aput::<BUFSIZE, BUFSIZE, _, _>(shorteventid, p);
}
if let Some(state_key) = &new_pdu.state_key {
let states_parents = if let Ok(p) = previous_shortstatehash {
self.services
match &new_pdu.state_key {
| Some(state_key) => {
let states_parents = match previous_shortstatehash {
| Ok(p) =>
self.services
.state_compressor
.load_shortstatehash_info(p)
.await?,
| _ => Vec::new(),
};
let shortstatekey = self
.services
.short
.get_or_create_shortstatekey(&new_pdu.kind.to_string().into(), state_key)
.await;
let new = self
.services
.state_compressor
.load_shortstatehash_info(p)
.await?
} else {
Vec::new()
};
.compress_state_event(shortstatekey, &new_pdu.event_id)
.await;
let shortstatekey = self
.services
.short
.get_or_create_shortstatekey(&new_pdu.kind.to_string().into(), state_key)
.await;
let replaces = states_parents
.last()
.map(|info| {
info.full_state
.iter()
.find(|bytes| bytes.starts_with(&shortstatekey.to_be_bytes()))
})
.unwrap_or_default();
let new = self
.services
.state_compressor
.compress_state_event(shortstatekey, &new_pdu.event_id)
.await;
if Some(&new) == replaces {
return Ok(previous_shortstatehash.expect("must exist"));
}
let replaces = states_parents
.last()
.map(|info| {
info.full_state
.iter()
.find(|bytes| bytes.starts_with(&shortstatekey.to_be_bytes()))
})
.unwrap_or_default();
// TODO: statehash with deterministic inputs
let shortstatehash = self.services.globals.next_count()?;
if Some(&new) == replaces {
return Ok(previous_shortstatehash.expect("must exist"));
}
let mut statediffnew = CompressedState::new();
statediffnew.insert(new);
// TODO: statehash with deterministic inputs
let shortstatehash = self.services.globals.next_count()?;
let mut statediffremoved = CompressedState::new();
if let Some(replaces) = replaces {
statediffremoved.insert(*replaces);
}
let mut statediffnew = CompressedState::new();
statediffnew.insert(new);
self.services.state_compressor.save_state_from_diff(
shortstatehash,
Arc::new(statediffnew),
Arc::new(statediffremoved),
2,
states_parents,
)?;
let mut statediffremoved = CompressedState::new();
if let Some(replaces) = replaces {
statediffremoved.insert(*replaces);
}
self.services.state_compressor.save_state_from_diff(
shortstatehash,
Arc::new(statediffnew),
Arc::new(statediffremoved),
2,
states_parents,
)?;
Ok(shortstatehash)
} else {
Ok(previous_shortstatehash.expect("first event in room must be a state event"))
Ok(shortstatehash)
},
| _ =>
Ok(previous_shortstatehash.expect("first event in room must be a state event")),
}
}

View file

@ -9,14 +9,16 @@ use std::{
};
use conduwuit::{
err, utils,
utils::math::{usize_from_f64, Expected},
Result,
Result, err, utils,
utils::math::{Expected, usize_from_f64},
};
use database::Map;
use lru_cache::LruCache;
use ruma::{
EventEncryptionAlgorithm, JsOption, OwnedRoomAliasId, OwnedRoomId, OwnedServerName,
OwnedUserId, RoomId, UserId,
events::{
StateEventType,
room::{
avatar::RoomAvatarEventContent,
canonical_alias::RoomCanonicalAliasEventContent,
@ -29,15 +31,12 @@ use ruma::{
name::RoomNameEventContent,
topic::RoomTopicEventContent,
},
StateEventType,
},
room::RoomType,
space::SpaceRoomJoinRule,
EventEncryptionAlgorithm, JsOption, OwnedRoomAliasId, OwnedRoomId, OwnedServerName,
OwnedUserId, RoomId, UserId,
};
use crate::{rooms, rooms::short::ShortStateHash, Dep};
use crate::{Dep, rooms, rooms::short::ShortStateHash};
pub struct Service {
pub server_visibility_cache: Mutex<LruCache<(OwnedServerName, ShortStateHash), bool>>,

View file

@ -1,8 +1,8 @@
use std::borrow::Borrow;
use conduwuit::{err, implement, PduEvent, Result, StateKey};
use conduwuit::{PduEvent, Result, StateKey, err, implement};
use futures::{Stream, StreamExt, TryFutureExt};
use ruma::{events::StateEventType, EventId, RoomId};
use ruma::{EventId, RoomId, events::StateEventType};
use serde::Deserialize;
/// Returns a single PDU from `room_id` with key (`event_type`,`state_key`).

View file

@ -1,11 +1,11 @@
use conduwuit::{error, implement, utils::stream::ReadyExt};
use futures::StreamExt;
use ruma::{
events::{
room::history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent},
StateEventType,
},
EventId, RoomId, ServerName,
events::{
StateEventType,
room::history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent},
},
};
/// Whether a server is allowed to see an event through federation, based on

View file

@ -1,27 +1,26 @@
use std::{borrow::Borrow, ops::Deref, sync::Arc};
use conduwuit::{
at, err, implement, pair_of,
PduEvent, Result, StateKey, at, err, implement, pair_of,
utils::{
result::FlatOk,
stream::{BroadbandExt, IterStream, ReadyExt, TryExpect},
},
PduEvent, Result, StateKey,
};
use database::Deserialized;
use futures::{future::try_join, pin_mut, FutureExt, Stream, StreamExt, TryFutureExt};
use futures::{FutureExt, Stream, StreamExt, TryFutureExt, future::try_join, pin_mut};
use ruma::{
events::{
room::member::{MembershipState, RoomMemberEventContent},
StateEventType,
},
EventId, OwnedEventId, UserId,
events::{
StateEventType,
room::member::{MembershipState, RoomMemberEventContent},
},
};
use serde::Deserialize;
use crate::rooms::{
short::{ShortEventId, ShortStateHash, ShortStateKey},
state_compressor::{compress_state_event, parse_compressed_state_event, CompressedState},
state_compressor::{CompressedState, compress_state_event, parse_compressed_state_event},
};
/// The user was a joined member at this state (potentially in the past)

View file

@ -1,14 +1,14 @@
use conduwuit::{error, implement, pdu::PduBuilder, Err, Error, Result};
use conduwuit::{Err, Error, Result, error, implement, pdu::PduBuilder};
use ruma::{
EventId, RoomId, UserId,
events::{
StateEventType, TimelineEventType,
room::{
history_visibility::{HistoryVisibility, RoomHistoryVisibilityEventContent},
member::{MembershipState, RoomMemberEventContent},
power_levels::{RoomPowerLevels, RoomPowerLevelsEventContent},
},
StateEventType, TimelineEventType,
},
EventId, RoomId, UserId,
};
use crate::rooms::state::RoomMutexGuard;
@ -44,7 +44,7 @@ pub async fn user_can_redact(
)));
}
if let Ok(pl_event_content) = self
match self
.room_state_get_content::<RoomPowerLevelsEventContent>(
room_id,
&StateEventType::RoomPowerLevels,
@ -52,33 +52,35 @@ pub async fn user_can_redact(
)
.await
{
let pl_event: RoomPowerLevels = pl_event_content.into();
Ok(pl_event.user_can_redact_event_of_other(sender)
|| pl_event.user_can_redact_own_event(sender)
&& if let Ok(redacting_event) = redacting_event {
if federation {
redacting_event.sender.server_name() == sender.server_name()
} else {
redacting_event.sender == sender
}
} else {
false
})
} else {
// Falling back on m.room.create to judge power level
if let Ok(room_create) = self
.room_state_get(room_id, &StateEventType::RoomCreate, "")
.await
{
Ok(room_create.sender == sender
|| redacting_event
.as_ref()
.is_ok_and(|redacting_event| redacting_event.sender == sender))
} else {
Err(Error::bad_database(
"No m.room.power_levels or m.room.create events in database for room",
))
}
| Ok(pl_event_content) => {
let pl_event: RoomPowerLevels = pl_event_content.into();
Ok(pl_event.user_can_redact_event_of_other(sender)
|| pl_event.user_can_redact_own_event(sender)
&& match redacting_event {
| Ok(redacting_event) =>
if federation {
redacting_event.sender.server_name() == sender.server_name()
} else {
redacting_event.sender == sender
},
| _ => false,
})
},
| _ => {
// Falling back on m.room.create to judge power level
match self
.room_state_get(room_id, &StateEventType::RoomCreate, "")
.await
{
| Ok(room_create) => Ok(room_create.sender == sender
|| redacting_event
.as_ref()
.is_ok_and(|redacting_event| redacting_event.sender == sender)),
| _ => Err(Error::bad_database(
"No m.room.power_levels or m.room.create events in database for room",
)),
}
},
}
}

View file

@ -4,31 +4,31 @@ use std::{
};
use conduwuit::{
is_not_empty,
Result, is_not_empty,
result::LogErr,
utils::{stream::TryIgnore, ReadyExt, StreamTools},
warn, Result,
utils::{ReadyExt, StreamTools, stream::TryIgnore},
warn,
};
use database::{serialize_key, Deserialized, Ignore, Interfix, Json, Map};
use futures::{future::join5, pin_mut, stream::iter, Stream, StreamExt};
use database::{Deserialized, Ignore, Interfix, Json, Map, serialize_key};
use futures::{Stream, StreamExt, future::join5, pin_mut, stream::iter};
use itertools::Itertools;
use ruma::{
OwnedRoomId, OwnedServerName, RoomId, ServerName, UserId,
events::{
AnyStrippedStateEvent, AnySyncStateEvent, GlobalAccountDataEventType,
RoomAccountDataEventType, StateEventType,
direct::DirectEvent,
room::{
create::RoomCreateEventContent,
member::{MembershipState, RoomMemberEventContent},
power_levels::RoomPowerLevelsEventContent,
},
AnyStrippedStateEvent, AnySyncStateEvent, GlobalAccountDataEventType,
RoomAccountDataEventType, StateEventType,
},
int,
serde::Raw,
OwnedRoomId, OwnedServerName, RoomId, ServerName, UserId,
};
use crate::{account_data, appservice::RegistrationInfo, globals, rooms, users, Dep};
use crate::{Dep, account_data, appservice::RegistrationInfo, globals, rooms, users};
pub struct Service {
appservice_in_room_cache: AppServiceInRoomCache,

View file

@ -6,10 +6,10 @@ use std::{
};
use conduwuit::{
Result,
arrayvec::ArrayVec,
at, checked, err, expected, utils,
utils::{bytes, math::usize_from_f64, stream::IterStream},
Result,
};
use database::Map;
use futures::{Stream, StreamExt};
@ -17,9 +17,8 @@ use lru_cache::LruCache;
use ruma::{EventId, RoomId};
use crate::{
rooms,
Dep, rooms,
rooms::short::{ShortEventId, ShortId, ShortStateHash, ShortStateKey},
Dep,
};
pub struct Service {

View file

@ -1,22 +1,21 @@
use std::{collections::BTreeMap, sync::Arc};
use conduwuit::{
err,
PduCount, PduEvent, PduId, RawPduId, Result, err,
utils::{
stream::{TryIgnore, WidebandExt},
ReadyExt,
stream::{TryIgnore, WidebandExt},
},
PduCount, PduEvent, PduId, RawPduId, Result,
};
use database::{Deserialized, Map};
use futures::{Stream, StreamExt};
use ruma::{
api::client::threads::get_threads::v1::IncludeThreads, events::relation::BundledThread, uint,
CanonicalJsonValue, EventId, OwnedUserId, RoomId, UserId,
api::client::threads::get_threads::v1::IncludeThreads, events::relation::BundledThread, uint,
};
use serde_json::json;
use crate::{rooms, rooms::short::ShortRoomId, Dep};
use crate::{Dep, rooms, rooms::short::ShortRoomId};
pub struct Service {
db: Data,
@ -121,10 +120,13 @@ impl Service {
}
let mut users = Vec::new();
if let Ok(userids) = self.get_participants(&root_id).await {
users.extend_from_slice(&userids);
} else {
users.push(root_pdu.sender);
match self.get_participants(&root_id).await {
| Ok(userids) => {
users.extend_from_slice(&userids);
},
| _ => {
users.push(root_pdu.sender);
},
}
users.push(pdu.sender.clone());

View file

@ -1,18 +1,17 @@
use std::{borrow::Borrow, sync::Arc};
use conduwuit::{
at, err,
Err, PduCount, PduEvent, Result, at, err,
result::{LogErr, NotFound},
utils,
utils::stream::TryReadyExt,
Err, PduCount, PduEvent, Result,
};
use database::{Database, Deserialized, Json, KeyVal, Map};
use futures::{future::select_ok, pin_mut, FutureExt, Stream, TryFutureExt, TryStreamExt};
use ruma::{api::Direction, CanonicalJsonObject, EventId, OwnedUserId, RoomId, UserId};
use futures::{FutureExt, Stream, TryFutureExt, TryStreamExt, future::select_ok, pin_mut};
use ruma::{CanonicalJsonObject, EventId, OwnedUserId, RoomId, UserId, api::Direction};
use super::{PduId, RawPduId};
use crate::{rooms, rooms::short::ShortRoomId, Dep};
use crate::{Dep, rooms, rooms::short::ShortRoomId};
pub(super) struct Data {
eventid_outlierpdu: Arc<Map>,

View file

@ -10,22 +10,25 @@ use std::{
};
use conduwuit::{
at, debug, debug_warn, err, error, implement, info,
pdu::{gen_event_id, EventHash, PduBuilder, PduCount, PduEvent},
Err, Error, Result, Server, at, debug, debug_warn, err, error, implement, info,
pdu::{EventHash, PduBuilder, PduCount, PduEvent, gen_event_id},
state_res::{self, Event, RoomVersion},
utils::{
self, future::TryExtExt, stream::TryIgnore, IterStream, MutexMap, MutexMapGuard, ReadyExt,
self, IterStream, MutexMap, MutexMapGuard, ReadyExt, future::TryExtExt, stream::TryIgnore,
},
validated, warn, Err, Error, Result, Server,
validated, warn,
};
pub use conduwuit::{PduId, RawPduId};
use futures::{
future, future::ready, pin_mut, Future, FutureExt, Stream, StreamExt, TryStreamExt,
Future, FutureExt, Stream, StreamExt, TryStreamExt, future, future::ready, pin_mut,
};
use ruma::{
CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId, OwnedRoomId, OwnedServerName,
RoomId, RoomVersionId, ServerName, UserId,
api::federation,
canonical_json::to_canonical_value,
events::{
GlobalAccountDataEventType, StateEventType, TimelineEventType,
push_rules::PushRulesEvent,
room::{
create::RoomCreateEventContent,
@ -34,23 +37,21 @@ use ruma::{
power_levels::RoomPowerLevelsEventContent,
redaction::RoomRedactionEventContent,
},
GlobalAccountDataEventType, StateEventType, TimelineEventType,
},
push::{Action, Ruleset, Tweak},
uint, CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId, OwnedRoomId,
OwnedServerName, RoomId, RoomVersionId, ServerName, UserId,
uint,
};
use serde::Deserialize;
use serde_json::value::{to_raw_value, RawValue as RawJsonValue};
use serde_json::value::{RawValue as RawJsonValue, to_raw_value};
use self::data::Data;
pub use self::data::PdusIterItem;
use crate::{
account_data, admin, appservice,
Dep, account_data, admin, appservice,
appservice::NamespaceRegex,
globals, pusher, rooms,
rooms::{short::ShortRoomId, state_compressor::CompressedState},
sending, server_keys, users, Dep,
sending, server_keys, users,
};
// Update Relationships

View file

@ -1,19 +1,18 @@
use std::{collections::BTreeMap, sync::Arc};
use conduwuit::{
debug_info, trace,
Result, Server, debug_info, trace,
utils::{self, IterStream},
Result, Server,
};
use futures::StreamExt;
use ruma::{
OwnedRoomId, OwnedUserId, RoomId, UserId,
api::federation::transactions::edu::{Edu, TypingContent},
events::SyncEphemeralRoomEvent,
OwnedRoomId, OwnedUserId, RoomId, UserId,
};
use tokio::sync::{broadcast, RwLock};
use tokio::sync::{RwLock, broadcast};
use crate::{globals, sending, sending::EduBuf, users, Dep};
use crate::{Dep, globals, sending, sending::EduBuf, users};
pub struct Service {
server: Arc<Server>,

View file

@ -1,10 +1,10 @@
use std::sync::Arc;
use conduwuit::{implement, Result};
use conduwuit::{Result, implement};
use database::{Database, Deserialized, Map};
use ruma::{RoomId, UserId};
use crate::{globals, rooms, rooms::short::ShortStateHash, Dep};
use crate::{Dep, globals, rooms, rooms::short::ShortStateHash};
pub struct Service {
db: Data,