Fix a bunch of clippy lints
parent
364820aae4
commit
a6bb9bbe68
|
@ -233,8 +233,7 @@ pub async fn get_public_rooms_filtered_helper(
|
||||||
.map_err(|_| {
|
.map_err(|_| {
|
||||||
Error::bad_database("Invalid room name event in database.")
|
Error::bad_database("Invalid room name event in database.")
|
||||||
})?
|
})?
|
||||||
.name
|
.name)
|
||||||
.map(|n| n.to_owned().into()))
|
|
||||||
})?,
|
})?,
|
||||||
num_joined_members: db
|
num_joined_members: db
|
||||||
.rooms
|
.rooms
|
||||||
|
|
|
@ -32,10 +32,9 @@ pub async fn set_displayname_route(
|
||||||
.set_displayname(&sender_user, body.displayname.clone())?;
|
.set_displayname(&sender_user, body.displayname.clone())?;
|
||||||
|
|
||||||
// Send a new membership event and presence update into all joined rooms
|
// Send a new membership event and presence update into all joined rooms
|
||||||
let all_rooms_joined = db.rooms.rooms_joined(&sender_user).collect::<Vec<_>>();
|
let all_rooms_joined: Vec<_> = db
|
||||||
|
.rooms
|
||||||
for (pdu_builder, room_id) in all_rooms_joined
|
.rooms_joined(&sender_user)
|
||||||
.into_iter()
|
|
||||||
.filter_map(|r| r.ok())
|
.filter_map(|r| r.ok())
|
||||||
.map(|room_id| {
|
.map(|room_id| {
|
||||||
Ok::<_, Error>((
|
Ok::<_, Error>((
|
||||||
|
@ -53,7 +52,7 @@ pub async fn set_displayname_route(
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
Error::bad_database(
|
Error::bad_database(
|
||||||
"Tried to send displayname update for user not in the \
|
"Tried to send displayname update for user not in the \
|
||||||
room.",
|
room.",
|
||||||
)
|
)
|
||||||
})?
|
})?
|
||||||
.content
|
.content
|
||||||
|
@ -72,7 +71,9 @@ pub async fn set_displayname_route(
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
.filter_map(|r| r.ok())
|
.filter_map(|r| r.ok())
|
||||||
{
|
.collect();
|
||||||
|
|
||||||
|
for (pdu_builder, room_id) in all_rooms_joined {
|
||||||
let mutex_state = Arc::clone(
|
let mutex_state = Arc::clone(
|
||||||
db.globals
|
db.globals
|
||||||
.roomid_mutex_state
|
.roomid_mutex_state
|
||||||
|
@ -166,10 +167,9 @@ pub async fn set_avatar_url_route(
|
||||||
db.users.set_blurhash(&sender_user, body.blurhash.clone())?;
|
db.users.set_blurhash(&sender_user, body.blurhash.clone())?;
|
||||||
|
|
||||||
// Send a new membership event and presence update into all joined rooms
|
// Send a new membership event and presence update into all joined rooms
|
||||||
let all_joined_rooms = db.rooms.rooms_joined(&sender_user).collect::<Vec<_>>();
|
let all_joined_rooms: Vec<_> = db
|
||||||
|
.rooms
|
||||||
for (pdu_builder, room_id) in all_joined_rooms
|
.rooms_joined(&sender_user)
|
||||||
.into_iter()
|
|
||||||
.filter_map(|r| r.ok())
|
.filter_map(|r| r.ok())
|
||||||
.map(|room_id| {
|
.map(|room_id| {
|
||||||
Ok::<_, Error>((
|
Ok::<_, Error>((
|
||||||
|
@ -187,7 +187,7 @@ pub async fn set_avatar_url_route(
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
Error::bad_database(
|
Error::bad_database(
|
||||||
"Tried to send displayname update for user not in the \
|
"Tried to send displayname update for user not in the \
|
||||||
room.",
|
room.",
|
||||||
)
|
)
|
||||||
})?
|
})?
|
||||||
.content
|
.content
|
||||||
|
@ -206,7 +206,9 @@ pub async fn set_avatar_url_route(
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
.filter_map(|r| r.ok())
|
.filter_map(|r| r.ok())
|
||||||
{
|
.collect();
|
||||||
|
|
||||||
|
for (pdu_builder, room_id) in all_joined_rooms {
|
||||||
let mutex_state = Arc::clone(
|
let mutex_state = Arc::clone(
|
||||||
db.globals
|
db.globals
|
||||||
.roomid_mutex_state
|
.roomid_mutex_state
|
||||||
|
|
|
@ -335,7 +335,7 @@ async fn sync_helper(
|
||||||
true,
|
true,
|
||||||
state_events,
|
state_events,
|
||||||
)
|
)
|
||||||
} else if timeline_pdus.len() == 0 && since_shortstatehash == Some(current_shortstatehash) {
|
} else if timeline_pdus.is_empty() && since_shortstatehash == Some(current_shortstatehash) {
|
||||||
// No state changes
|
// No state changes
|
||||||
(Vec::new(), None, None, false, Vec::new())
|
(Vec::new(), None, None, false, Vec::new())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -644,7 +644,7 @@ impl Database {
|
||||||
|
|
||||||
if db.globals.database_version()? < 9 {
|
if db.globals.database_version()? < 9 {
|
||||||
// Update tokenids db layout
|
// Update tokenids db layout
|
||||||
let batch = db
|
let mut iter = db
|
||||||
.rooms
|
.rooms
|
||||||
.tokenids
|
.tokenids
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -672,9 +672,7 @@ impl Database {
|
||||||
println!("new {:?}", new_key);
|
println!("new {:?}", new_key);
|
||||||
Some((new_key, Vec::new()))
|
Some((new_key, Vec::new()))
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.peekable();
|
||||||
|
|
||||||
let mut iter = batch.into_iter().peekable();
|
|
||||||
|
|
||||||
while iter.peek().is_some() {
|
while iter.peek().is_some() {
|
||||||
db.rooms
|
db.rooms
|
||||||
|
|
|
@ -65,12 +65,12 @@ impl Engine {
|
||||||
self.writer.lock()
|
self.writer.lock()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_lock<'a>(&'a self) -> &'a Connection {
|
fn read_lock(&self) -> &Connection {
|
||||||
self.read_conn_tls
|
self.read_conn_tls
|
||||||
.get_or(|| Self::prepare_conn(&self.path, self.cache_size_per_thread).unwrap())
|
.get_or(|| Self::prepare_conn(&self.path, self.cache_size_per_thread).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_lock_iterator<'a>(&'a self) -> &'a Connection {
|
fn read_lock_iterator(&self) -> &Connection {
|
||||||
self.read_iterator_conn_tls
|
self.read_iterator_conn_tls
|
||||||
.get_or(|| Self::prepare_conn(&self.path, self.cache_size_per_thread).unwrap())
|
.get_or(|| Self::prepare_conn(&self.path, self.cache_size_per_thread).unwrap())
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ impl AccountData {
|
||||||
roomuserdataid.push(0xff);
|
roomuserdataid.push(0xff);
|
||||||
roomuserdataid.extend_from_slice(&event_type.as_bytes());
|
roomuserdataid.extend_from_slice(&event_type.as_bytes());
|
||||||
|
|
||||||
let mut key = prefix.clone();
|
let mut key = prefix;
|
||||||
key.extend_from_slice(event_type.as_bytes());
|
key.extend_from_slice(event_type.as_bytes());
|
||||||
|
|
||||||
let json = serde_json::to_value(data).expect("all types here can be serialized"); // TODO: maybe add error handling
|
let json = serde_json::to_value(data).expect("all types here can be serialized"); // TODO: maybe add error handling
|
||||||
|
|
|
@ -385,7 +385,7 @@ impl Rooms {
|
||||||
self.save_state_from_diff(
|
self.save_state_from_diff(
|
||||||
new_shortstatehash,
|
new_shortstatehash,
|
||||||
statediffnew.clone(),
|
statediffnew.clone(),
|
||||||
statediffremoved.clone(),
|
statediffremoved,
|
||||||
2, // every state change is 2 event changes on average
|
2, // every state change is 2 event changes on average
|
||||||
states_parents,
|
states_parents,
|
||||||
)?;
|
)?;
|
||||||
|
@ -497,8 +497,7 @@ impl Rooms {
|
||||||
|
|
||||||
Ok(response)
|
Ok(response)
|
||||||
} else {
|
} else {
|
||||||
let mut response = Vec::new();
|
let response = vec![(shortstatehash, added.clone(), added, removed)];
|
||||||
response.push((shortstatehash, added.clone(), added, removed));
|
|
||||||
self.stateinfo_cache
|
self.stateinfo_cache
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -609,7 +608,7 @@ impl Rooms {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if parent_states.len() == 0 {
|
if parent_states.is_empty() {
|
||||||
// There is no parent layer, create a new state
|
// There is no parent layer, create a new state
|
||||||
let mut value = 0_u64.to_be_bytes().to_vec(); // 0 means no parent
|
let mut value = 0_u64.to_be_bytes().to_vec(); // 0 means no parent
|
||||||
for new in &statediffnew {
|
for new in &statediffnew {
|
||||||
|
@ -689,7 +688,7 @@ impl Rooms {
|
||||||
state_hash: &StateHashId,
|
state_hash: &StateHashId,
|
||||||
globals: &super::globals::Globals,
|
globals: &super::globals::Globals,
|
||||||
) -> Result<(u64, bool)> {
|
) -> Result<(u64, bool)> {
|
||||||
Ok(match self.statehash_shortstatehash.get(&state_hash)? {
|
Ok(match self.statehash_shortstatehash.get(state_hash)? {
|
||||||
Some(shortstatehash) => (
|
Some(shortstatehash) => (
|
||||||
utils::u64_from_bytes(&shortstatehash)
|
utils::u64_from_bytes(&shortstatehash)
|
||||||
.map_err(|_| Error::bad_database("Invalid shortstatehash in db."))?,
|
.map_err(|_| Error::bad_database("Invalid shortstatehash in db."))?,
|
||||||
|
@ -698,7 +697,7 @@ impl Rooms {
|
||||||
None => {
|
None => {
|
||||||
let shortstatehash = globals.next_count()?;
|
let shortstatehash = globals.next_count()?;
|
||||||
self.statehash_shortstatehash
|
self.statehash_shortstatehash
|
||||||
.insert(&state_hash, &shortstatehash.to_be_bytes())?;
|
.insert(state_hash, &shortstatehash.to_be_bytes())?;
|
||||||
(shortstatehash, false)
|
(shortstatehash, false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1768,8 +1767,8 @@ impl Rooms {
|
||||||
};
|
};
|
||||||
self.save_state_from_diff(
|
self.save_state_from_diff(
|
||||||
shortstatehash,
|
shortstatehash,
|
||||||
statediffnew.clone(),
|
statediffnew,
|
||||||
statediffremoved.clone(),
|
statediffremoved,
|
||||||
1_000_000, // high number because no state will be based on this one
|
1_000_000, // high number because no state will be based on this one
|
||||||
states_parents,
|
states_parents,
|
||||||
)?;
|
)?;
|
||||||
|
@ -1914,15 +1913,14 @@ impl Rooms {
|
||||||
let mut key = shortroomid.to_be_bytes().to_vec();
|
let mut key = shortroomid.to_be_bytes().to_vec();
|
||||||
key.extend_from_slice(&token.to_be_bytes());
|
key.extend_from_slice(&token.to_be_bytes());
|
||||||
|
|
||||||
Ok(self
|
self.roomsynctoken_shortstatehash
|
||||||
.roomsynctoken_shortstatehash
|
|
||||||
.get(&key)?
|
.get(&key)?
|
||||||
.map(|bytes| {
|
.map(|bytes| {
|
||||||
utils::u64_from_bytes(&bytes).map_err(|_| {
|
utils::u64_from_bytes(&bytes).map_err(|_| {
|
||||||
Error::bad_database("Invalid shortstatehash in roomsynctoken_shortstatehash")
|
Error::bad_database("Invalid shortstatehash in roomsynctoken_shortstatehash")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.transpose()?)
|
.transpose()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new persisted data unit and adds it to a room.
|
/// Creates a new persisted data unit and adds it to a room.
|
||||||
|
@ -2475,16 +2473,15 @@ impl Rooms {
|
||||||
self.roomuserid_leftcount.remove(&roomuser_id)?;
|
self.roomuserid_leftcount.remove(&roomuser_id)?;
|
||||||
}
|
}
|
||||||
member::MembershipState::Leave | member::MembershipState::Ban => {
|
member::MembershipState::Leave | member::MembershipState::Ban => {
|
||||||
if update_joined_count {
|
if update_joined_count
|
||||||
if self
|
&& self
|
||||||
.room_members(room_id)
|
.room_members(room_id)
|
||||||
.chain(self.room_members_invited(room_id))
|
.chain(self.room_members_invited(room_id))
|
||||||
.filter_map(|r| r.ok())
|
.filter_map(|r| r.ok())
|
||||||
.all(|u| u.server_name() != user_id.server_name())
|
.all(|u| u.server_name() != user_id.server_name())
|
||||||
{
|
{
|
||||||
self.roomserverids.remove(&roomserver_id)?;
|
self.roomserverids.remove(&roomserver_id)?;
|
||||||
self.serverroomids.remove(&serverroom_id)?;
|
self.serverroomids.remove(&serverroom_id)?;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
self.userroomid_leftstate.insert(
|
self.userroomid_leftstate.insert(
|
||||||
&userroom_id,
|
&userroom_id,
|
||||||
|
@ -2621,45 +2618,43 @@ impl Rooms {
|
||||||
|
|
||||||
if let Some(b) = maybe {
|
if let Some(b) = maybe {
|
||||||
Ok(b)
|
Ok(b)
|
||||||
|
} else if let Some(namespaces) = appservice.1.get("namespaces") {
|
||||||
|
let users = namespaces
|
||||||
|
.get("users")
|
||||||
|
.and_then(|users| users.as_sequence())
|
||||||
|
.map_or_else(Vec::new, |users| {
|
||||||
|
users
|
||||||
|
.iter()
|
||||||
|
.filter_map(|users| Regex::new(users.get("regex")?.as_str()?).ok())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
});
|
||||||
|
|
||||||
|
let bridge_user_id = appservice
|
||||||
|
.1
|
||||||
|
.get("sender_localpart")
|
||||||
|
.and_then(|string| string.as_str())
|
||||||
|
.and_then(|string| {
|
||||||
|
UserId::parse_with_server_name(string, db.globals.server_name()).ok()
|
||||||
|
});
|
||||||
|
|
||||||
|
let in_room = bridge_user_id
|
||||||
|
.map_or(false, |id| self.is_joined(&id, room_id).unwrap_or(false))
|
||||||
|
|| self.room_members(&room_id).any(|userid| {
|
||||||
|
userid.map_or(false, |userid| {
|
||||||
|
users.iter().any(|r| r.is_match(userid.as_str()))
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
self.appservice_in_room_cache
|
||||||
|
.write()
|
||||||
|
.unwrap()
|
||||||
|
.entry(room_id.clone())
|
||||||
|
.or_default()
|
||||||
|
.insert(appservice.0.clone(), in_room);
|
||||||
|
|
||||||
|
Ok(in_room)
|
||||||
} else {
|
} else {
|
||||||
if let Some(namespaces) = appservice.1.get("namespaces") {
|
Ok(false)
|
||||||
let users = namespaces
|
|
||||||
.get("users")
|
|
||||||
.and_then(|users| users.as_sequence())
|
|
||||||
.map_or_else(Vec::new, |users| {
|
|
||||||
users
|
|
||||||
.iter()
|
|
||||||
.filter_map(|users| Regex::new(users.get("regex")?.as_str()?).ok())
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
});
|
|
||||||
|
|
||||||
let bridge_user_id = appservice
|
|
||||||
.1
|
|
||||||
.get("sender_localpart")
|
|
||||||
.and_then(|string| string.as_str())
|
|
||||||
.and_then(|string| {
|
|
||||||
UserId::parse_with_server_name(string, db.globals.server_name()).ok()
|
|
||||||
});
|
|
||||||
|
|
||||||
let in_room = bridge_user_id
|
|
||||||
.map_or(false, |id| self.is_joined(&id, room_id).unwrap_or(false))
|
|
||||||
|| self.room_members(&room_id).any(|userid| {
|
|
||||||
userid.map_or(false, |userid| {
|
|
||||||
users.iter().any(|r| r.is_match(userid.as_str()))
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
self.appservice_in_room_cache
|
|
||||||
.write()
|
|
||||||
.unwrap()
|
|
||||||
.entry(room_id.clone())
|
|
||||||
.or_default()
|
|
||||||
.insert(appservice.0.clone(), in_room);
|
|
||||||
|
|
||||||
Ok(in_room)
|
|
||||||
} else {
|
|
||||||
Ok(false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3452,10 +3447,7 @@ impl Rooms {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache in RAM
|
// Cache in RAM
|
||||||
self.auth_chain_cache
|
self.auth_chain_cache.lock().unwrap().insert(key, chain);
|
||||||
.lock()
|
|
||||||
.unwrap()
|
|
||||||
.insert(key.clone(), chain);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@ where
|
||||||
|
|
||||||
let result = find_actual_destination(globals, &destination).await;
|
let result = find_actual_destination(globals, &destination).await;
|
||||||
|
|
||||||
(result.0, result.1.clone().into_uri_string())
|
(result.0, result.1.into_uri_string())
|
||||||
};
|
};
|
||||||
|
|
||||||
let actual_destination_str = actual_destination.clone().into_https_string();
|
let actual_destination_str = actual_destination.clone().into_https_string();
|
||||||
|
@ -1529,7 +1529,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
if !state_res::event_auth::auth_check(
|
let check_result = state_res::event_auth::auth_check(
|
||||||
&room_version,
|
&room_version,
|
||||||
&incoming_pdu,
|
&incoming_pdu,
|
||||||
previous_create.clone(),
|
previous_create.clone(),
|
||||||
|
@ -1543,8 +1543,9 @@ async fn upgrade_outlier_to_timeline_pdu(
|
||||||
.and_then(|event_id| db.rooms.get_pdu(&event_id).ok().flatten())
|
.and_then(|event_id| db.rooms.get_pdu(&event_id).ok().flatten())
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.map_err(|_e| "Auth check failed.".to_owned())?
|
.map_err(|_e| "Auth check failed.".to_owned())?;
|
||||||
{
|
|
||||||
|
if !check_result {
|
||||||
return Err("Event has failed auth check with state at the event.".into());
|
return Err("Event has failed auth check with state at the event.".into());
|
||||||
}
|
}
|
||||||
debug!("Auth check succeeded.");
|
debug!("Auth check succeeded.");
|
||||||
|
|
Loading…
Reference in New Issue