mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 08:11:24 +01:00
change rustfmt configuration
This change is fully automated, except the `rustfmt.toml` changes and a few clippy directives to allow specific functions with too many lines because they are longer now.
This commit is contained in:
parent
40d6ce230d
commit
0afc1d2f50
123 changed files with 7881 additions and 4687 deletions
|
|
@ -2,7 +2,6 @@ mod data;
|
|||
use std::{collections::HashSet, sync::Arc};
|
||||
|
||||
pub(crate) use data::Data;
|
||||
|
||||
use ruma::{
|
||||
events::{
|
||||
direct::DirectEvent,
|
||||
|
|
@ -34,7 +33,8 @@ impl Service {
|
|||
last_state: Option<Vec<Raw<AnyStrippedStateEvent>>>,
|
||||
update_joined_count: bool,
|
||||
) -> Result<()> {
|
||||
// Keep track what remote users exist by adding them as "deactivated" users
|
||||
// Keep track what remote users exist by adding them as "deactivated"
|
||||
// users
|
||||
if user_id.server_name() != services().globals.server_name() {
|
||||
services().users.create(user_id, None)?;
|
||||
// TODO: displayname, avatar url
|
||||
|
|
@ -51,17 +51,26 @@ impl Service {
|
|||
if let Some(predecessor) = services()
|
||||
.rooms
|
||||
.state_accessor
|
||||
.room_state_get(room_id, &StateEventType::RoomCreate, "")?
|
||||
.and_then(|create| serde_json::from_str(create.content.get()).ok())
|
||||
.and_then(|content: RoomCreateEventContent| content.predecessor)
|
||||
.room_state_get(
|
||||
room_id,
|
||||
&StateEventType::RoomCreate,
|
||||
"",
|
||||
)?
|
||||
.and_then(|create| {
|
||||
serde_json::from_str(create.content.get()).ok()
|
||||
})
|
||||
.and_then(|content: RoomCreateEventContent| {
|
||||
content.predecessor
|
||||
})
|
||||
{
|
||||
// Copy user settings from predecessor to the current room:
|
||||
// Copy user settings from predecessor to the current
|
||||
// room:
|
||||
// - Push rules
|
||||
//
|
||||
// TODO: finish this once push rules are implemented.
|
||||
//
|
||||
// let mut push_rules_event_content: PushRulesEvent = account_data
|
||||
// .get(
|
||||
// let mut push_rules_event_content: PushRulesEvent =
|
||||
// account_data .get(
|
||||
// None,
|
||||
// user_id,
|
||||
// EventType::PushRules,
|
||||
|
|
@ -90,8 +99,13 @@ impl Service {
|
|||
)?
|
||||
.map(|event| {
|
||||
serde_json::from_str(event.get()).map_err(|e| {
|
||||
warn!("Invalid account data event in db: {e:?}");
|
||||
Error::BadDatabase("Invalid account data event in db.")
|
||||
warn!(
|
||||
"Invalid account data event in db: \
|
||||
{e:?}"
|
||||
);
|
||||
Error::BadDatabase(
|
||||
"Invalid account data event in db.",
|
||||
)
|
||||
})
|
||||
})
|
||||
{
|
||||
|
|
@ -112,20 +126,32 @@ impl Service {
|
|||
.get(
|
||||
None,
|
||||
user_id,
|
||||
GlobalAccountDataEventType::Direct.to_string().into(),
|
||||
GlobalAccountDataEventType::Direct
|
||||
.to_string()
|
||||
.into(),
|
||||
)?
|
||||
.map(|event| {
|
||||
serde_json::from_str::<DirectEvent>(event.get()).map_err(|e| {
|
||||
warn!("Invalid account data event in db: {e:?}");
|
||||
Error::BadDatabase("Invalid account data event in db.")
|
||||
})
|
||||
serde_json::from_str::<DirectEvent>(event.get())
|
||||
.map_err(|e| {
|
||||
warn!(
|
||||
"Invalid account data event in \
|
||||
db: {e:?}"
|
||||
);
|
||||
Error::BadDatabase(
|
||||
"Invalid account data event in db.",
|
||||
)
|
||||
})
|
||||
})
|
||||
{
|
||||
let mut direct_event = direct_event?;
|
||||
let mut room_ids_updated = false;
|
||||
|
||||
for room_ids in direct_event.content.0.values_mut() {
|
||||
if room_ids.iter().any(|r| r == &predecessor.room_id) {
|
||||
for room_ids in direct_event.content.0.values_mut()
|
||||
{
|
||||
if room_ids
|
||||
.iter()
|
||||
.any(|r| r == &predecessor.room_id)
|
||||
{
|
||||
room_ids.push(room_id.to_owned());
|
||||
room_ids_updated = true;
|
||||
}
|
||||
|
|
@ -135,7 +161,9 @@ impl Service {
|
|||
services().account_data.update(
|
||||
None,
|
||||
user_id,
|
||||
GlobalAccountDataEventType::Direct.to_string().into(),
|
||||
GlobalAccountDataEventType::Direct
|
||||
.to_string()
|
||||
.into(),
|
||||
&serde_json::to_value(&direct_event)
|
||||
.expect("to json always works"),
|
||||
)?;
|
||||
|
|
@ -160,9 +188,14 @@ impl Service {
|
|||
.into(),
|
||||
)?
|
||||
.map(|event| {
|
||||
serde_json::from_str::<IgnoredUserListEvent>(event.get()).map_err(|e| {
|
||||
serde_json::from_str::<IgnoredUserListEvent>(
|
||||
event.get(),
|
||||
)
|
||||
.map_err(|e| {
|
||||
warn!("Invalid account data event in db: {e:?}");
|
||||
Error::BadDatabase("Invalid account data event in db.")
|
||||
Error::BadDatabase(
|
||||
"Invalid account data event in db.",
|
||||
)
|
||||
})
|
||||
})
|
||||
.transpose()?
|
||||
|
|
@ -199,7 +232,10 @@ impl Service {
|
|||
}
|
||||
|
||||
#[tracing::instrument(skip(self, room_id))]
|
||||
pub(crate) fn get_our_real_users(&self, room_id: &RoomId) -> Result<Arc<HashSet<OwnedUserId>>> {
|
||||
pub(crate) fn get_our_real_users(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<Arc<HashSet<OwnedUserId>>> {
|
||||
self.db.get_our_real_users(room_id)
|
||||
}
|
||||
|
||||
|
|
@ -214,7 +250,11 @@ impl Service {
|
|||
|
||||
/// Makes a user forget a room.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn forget(&self, room_id: &RoomId, user_id: &UserId) -> Result<()> {
|
||||
pub(crate) fn forget(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
user_id: &UserId,
|
||||
) -> Result<()> {
|
||||
self.db.forget(room_id, user_id)
|
||||
}
|
||||
|
||||
|
|
@ -228,11 +268,16 @@ impl Service {
|
|||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn server_in_room(&self, server: &ServerName, room_id: &RoomId) -> Result<bool> {
|
||||
pub(crate) fn server_in_room(
|
||||
&self,
|
||||
server: &ServerName,
|
||||
room_id: &RoomId,
|
||||
) -> Result<bool> {
|
||||
self.db.server_in_room(server, room_id)
|
||||
}
|
||||
|
||||
/// Returns an iterator of all rooms a server participates in (as far as we know).
|
||||
/// Returns an iterator of all rooms a server participates in (as far as we
|
||||
/// know).
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn server_rooms<'a>(
|
||||
&'a self,
|
||||
|
|
@ -251,12 +296,18 @@ impl Service {
|
|||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn room_joined_count(&self, room_id: &RoomId) -> Result<Option<u64>> {
|
||||
pub(crate) fn room_joined_count(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<Option<u64>> {
|
||||
self.db.room_joined_count(room_id)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn room_invited_count(&self, room_id: &RoomId) -> Result<Option<u64>> {
|
||||
pub(crate) fn room_invited_count(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<Option<u64>> {
|
||||
self.db.room_invited_count(room_id)
|
||||
}
|
||||
|
||||
|
|
@ -288,7 +339,11 @@ impl Service {
|
|||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn get_left_count(&self, room_id: &RoomId, user_id: &UserId) -> Result<Option<u64>> {
|
||||
pub(crate) fn get_left_count(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
user_id: &UserId,
|
||||
) -> Result<Option<u64>> {
|
||||
self.db.get_left_count(room_id, user_id)
|
||||
}
|
||||
|
||||
|
|
@ -306,7 +361,9 @@ impl Service {
|
|||
pub(crate) fn rooms_invited<'a>(
|
||||
&'a self,
|
||||
user_id: &UserId,
|
||||
) -> impl Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>)>> + 'a {
|
||||
) -> impl Iterator<
|
||||
Item = Result<(OwnedRoomId, Vec<Raw<AnyStrippedStateEvent>>)>,
|
||||
> + 'a {
|
||||
self.db.rooms_invited(user_id)
|
||||
}
|
||||
|
||||
|
|
@ -333,27 +390,44 @@ impl Service {
|
|||
pub(crate) fn rooms_left<'a>(
|
||||
&'a self,
|
||||
user_id: &UserId,
|
||||
) -> impl Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnySyncStateEvent>>)>> + 'a {
|
||||
) -> impl Iterator<Item = Result<(OwnedRoomId, Vec<Raw<AnySyncStateEvent>>)>> + 'a
|
||||
{
|
||||
self.db.rooms_left(user_id)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn once_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
|
||||
pub(crate) fn once_joined(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
) -> Result<bool> {
|
||||
self.db.once_joined(user_id, room_id)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn is_joined(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
|
||||
pub(crate) fn is_joined(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
) -> Result<bool> {
|
||||
self.db.is_joined(user_id, room_id)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn is_invited(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
|
||||
pub(crate) fn is_invited(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
) -> Result<bool> {
|
||||
self.db.is_invited(user_id, room_id)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn is_left(&self, user_id: &UserId, room_id: &RoomId) -> Result<bool> {
|
||||
pub(crate) fn is_left(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
) -> Result<bool> {
|
||||
self.db.is_left(user_id, room_id)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue