stop putting comments and code on the same line

This commit is contained in:
Charles Hall 2024-05-15 15:40:56 -07:00
parent 0915aba44c
commit 1911ad34d9
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
35 changed files with 305 additions and 142 deletions

View file

@ -6,8 +6,10 @@ use tracing::trace;
use crate::{services, utils, Result};
pub(crate) struct Service {
pub(crate) typing: RwLock<BTreeMap<OwnedRoomId, BTreeMap<OwnedUserId, u64>>>, // u64 is unix timestamp of timeout
pub(crate) last_typing_update: RwLock<BTreeMap<OwnedRoomId, u64>>, // timestamp of the last change to typing users
// u64 is unix timestamp of timeout
pub(crate) typing: RwLock<BTreeMap<OwnedRoomId, BTreeMap<OwnedUserId, u64>>>,
// timestamp of the last change to typing users
pub(crate) last_typing_update: RwLock<BTreeMap<OwnedRoomId, u64>>,
pub(crate) typing_update_sender: broadcast::Sender<OwnedRoomId>,
}

View file

@ -446,7 +446,8 @@ impl Service {
if !state_res::event_auth::auth_check(
&room_version,
&incoming_pdu,
None::<PduEvent>, // TODO: third party invite
// TODO: third party invite
None::<PduEvent>,
|k, s| auth_events.get(&(k.to_string().into(), s.to_owned())),
)
.map_err(|_e| Error::BadRequest(ErrorKind::InvalidParam, "Auth check failed"))?
@ -748,7 +749,8 @@ impl Service {
let check_result = state_res::event_auth::auth_check(
&room_version,
&incoming_pdu,
None::<PduEvent>, // TODO: third party invite
// TODO: third party invite
None::<PduEvent>,
|k, s| {
services()
.rooms

View file

@ -64,7 +64,8 @@ impl Service {
let events_after: Vec<_> = services()
.rooms
.pdu_metadata
.relations_until(sender_user, room_id, target, from)? // TODO: should be relations_after
// TODO: should be relations_after
.relations_until(sender_user, room_id, target, from)?
.filter(|r| {
r.as_ref().map_or(true, |(_, pdu)| {
filter_event_type.as_ref().map_or(true, |t| &&pdu.kind == t)
@ -90,14 +91,16 @@ impl Service {
.user_can_see_event(sender_user, room_id, &pdu.event_id)
.unwrap_or(false)
})
.take_while(|&(k, _)| Some(k) != to) // Stop at `to`
// Stop at `to`
.take_while(|&(k, _)| Some(k) != to)
.collect();
next_token = events_after.last().map(|(count, _)| count).copied();
let events_after: Vec<_> = events_after
.into_iter()
.rev() // relations are always most recent first
// relations are always most recent first
.rev()
.map(|(_, pdu)| pdu.to_message_like_event())
.collect();
@ -137,7 +140,8 @@ impl Service {
.user_can_see_event(sender_user, room_id, &pdu.event_id)
.unwrap_or(false)
})
.take_while(|&(k, _)| Some(k) != to) // Stop at `to`
// Stop at `to`
.take_while(|&(k, _)| Some(k) != to)
.collect();
next_token = events_before.last().map(|(count, _)| count).copied();
@ -167,7 +171,8 @@ impl Service {
let target = match services().rooms.timeline.get_pdu_count(target)? {
Some(PduCount::Normal(c)) => c,
// TODO: Support backfilled relations
_ => 0, // This will result in an empty iterator
// This will result in an empty iterator
_ => 0,
};
self.db.relations_until(user_id, room_id, target, until)
}

View file

@ -35,7 +35,8 @@ impl Service {
shortstatehash: u64,
statediffnew: Arc<HashSet<CompressedStateEvent>>,
_statediffremoved: Arc<HashSet<CompressedStateEvent>>,
state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
// Take mutex guard to make sure users get the room state mutex
state_lock: &MutexGuard<'_, ()>,
) -> Result<()> {
for event_id in statediffnew.iter().filter_map(|new| {
services()
@ -169,7 +170,8 @@ impl Service {
shortstatehash,
statediffnew,
statediffremoved,
1_000_000, // high number because no state will be based on this one
// high number because no state will be based on this one
1_000_000,
states_parents,
)?;
}
@ -315,7 +317,8 @@ impl Service {
&self,
room_id: &RoomId,
shortstatehash: u64,
mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
// Take mutex guard to make sure users get the room state mutex
mutex_lock: &MutexGuard<'_, ()>,
) -> Result<()> {
self.db.set_room_state(room_id, shortstatehash, mutex_lock)
}
@ -358,7 +361,8 @@ impl Service {
&self,
room_id: &RoomId,
event_ids: Vec<OwnedEventId>,
state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
// Take mutex guard to make sure users get the room state mutex
state_lock: &MutexGuard<'_, ()>,
) -> Result<()> {
self.db
.set_forward_extremities(room_id, event_ids, state_lock)

View file

@ -12,7 +12,8 @@ pub(crate) trait Data: Send + Sync {
&self,
room_id: &RoomId,
new_shortstatehash: u64,
_mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
// Take mutex guard to make sure users get the room state mutex
_mutex_lock: &MutexGuard<'_, ()>,
) -> Result<()>;
/// Associates a state with an event.
@ -26,6 +27,7 @@ pub(crate) trait Data: Send + Sync {
&self,
room_id: &RoomId,
event_ids: Vec<OwnedEventId>,
_mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
// Take mutex guard to make sure users get the room state mutex
_mutex_lock: &MutexGuard<'_, ()>,
) -> Result<()>;
}

View file

@ -151,8 +151,10 @@ impl Service {
let is_ignored = services()
.account_data
.get(
None, // Ignored users are in global account data
user_id, // Receiver
// Ignored users are in global account data
None,
// Receiver
user_id,
GlobalAccountDataEventType::IgnoredUserList
.to_string()
.into(),

View file

@ -21,10 +21,14 @@ pub(crate) struct Service {
LruCache<
u64,
Vec<(
u64, // shortstatehash
Arc<HashSet<CompressedStateEvent>>, // full state
Arc<HashSet<CompressedStateEvent>>, // added
Arc<HashSet<CompressedStateEvent>>, // removed
// shortstatehash
u64,
// full state
Arc<HashSet<CompressedStateEvent>>,
// added
Arc<HashSet<CompressedStateEvent>>,
// removed
Arc<HashSet<CompressedStateEvent>>,
)>,
>,
>,
@ -41,10 +45,14 @@ impl Service {
shortstatehash: u64,
) -> Result<
Vec<(
u64, // shortstatehash
Arc<HashSet<CompressedStateEvent>>, // full state
Arc<HashSet<CompressedStateEvent>>, // added
Arc<HashSet<CompressedStateEvent>>, // removed
// shortstatehash
u64,
// full state
Arc<HashSet<CompressedStateEvent>>,
// added
Arc<HashSet<CompressedStateEvent>>,
// removed
Arc<HashSet<CompressedStateEvent>>,
)>,
> {
if let Some(r) = self
@ -152,10 +160,14 @@ impl Service {
statediffremoved: Arc<HashSet<CompressedStateEvent>>,
diff_to_sibling: usize,
mut parent_states: Vec<(
u64, // shortstatehash
Arc<HashSet<CompressedStateEvent>>, // full state
Arc<HashSet<CompressedStateEvent>>, // added
Arc<HashSet<CompressedStateEvent>>, // removed
// shortstatehash
u64,
// full state
Arc<HashSet<CompressedStateEvent>>,
// added
Arc<HashSet<CompressedStateEvent>>,
// removed
Arc<HashSet<CompressedStateEvent>>,
)>,
) -> Result<()> {
let diffsum = statediffnew.len() + statediffremoved.len();
@ -318,7 +330,8 @@ impl Service {
new_shortstatehash,
statediffnew.clone(),
statediffremoved.clone(),
2, // every state change is 2 event changes on average
// every state change is 2 event changes on average
2,
states_parents,
)?;
};

View file

@ -177,7 +177,8 @@ impl Service {
pdu: &PduEvent,
mut pdu_json: CanonicalJsonObject,
leaves: Vec<OwnedEventId>,
state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
// Take mutex guard to make sure users get the room state mutex
state_lock: &MutexGuard<'_, ()>,
) -> Result<Vec<u8>> {
let shortroomid = services()
.rooms
@ -527,7 +528,8 @@ impl Service {
.threads
.add_to_thread(&thread.event_id, pdu)?;
}
_ => {} // TODO: Aggregate other types
// TODO: Aggregate other types
_ => {}
}
}
@ -598,7 +600,8 @@ impl Service {
pdu_builder: PduBuilder,
sender: &UserId,
room_id: &RoomId,
_mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
// Take mutex guard to make sure users get the room state mutex
_mutex_lock: &MutexGuard<'_, ()>,
) -> Result<(PduEvent, CanonicalJsonObject)> {
let PduBuilder {
event_type,
@ -702,7 +705,8 @@ impl Service {
let auth_check = state_res::auth_check(
&room_version,
&pdu,
None::<PduEvent>, // TODO: third_party_invite
// TODO: third_party_invite
None::<PduEvent>,
|k, s| auth_events.get(&(k.clone(), s.to_owned())),
)
.map_err(|e| {
@ -781,7 +785,8 @@ impl Service {
pdu_builder: PduBuilder,
sender: &UserId,
room_id: &RoomId,
state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
// Take mutex guard to make sure users get the room state mutex
state_lock: &MutexGuard<'_, ()>,
) -> Result<Arc<EventId>> {
let (pdu, pdu_json) =
self.create_hash_and_sign_event(pdu_builder, sender, room_id, state_lock)?;
@ -990,7 +995,8 @@ impl Service {
new_room_leaves: Vec<OwnedEventId>,
state_ids_compressed: Arc<HashSet<CompressedStateEvent>>,
soft_fail: bool,
state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
// Take mutex guard to make sure users get the room state mutex
state_lock: &MutexGuard<'_, ()>,
) -> Result<Option<Vec<u8>>> {
// We append to state before appending the pdu, so we don't have a moment in time with the
// pdu without it's state. This is okay because append_pdu can't fail.