mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 07:41:23 +01:00
enable unused_self lint
Functions using `services()` are allowed to pointlessly take `self` because the existence of `services()` is a crime and the solution is making the types store references to their dependencies and then going through `self`, so just allowing the lint saves us from modifying some code only to switch it back later. Much later. Getting rid of `services()` will probably be an ordeal.
This commit is contained in:
parent
f855bd09d1
commit
e3672eb4e0
10 changed files with 39 additions and 30 deletions
|
|
@ -91,6 +91,7 @@ unnested_or_patterns = "warn"
|
||||||
unreadable_literal = "warn"
|
unreadable_literal = "warn"
|
||||||
unseparated_literal_suffix = "warn"
|
unseparated_literal_suffix = "warn"
|
||||||
unused_async = "warn"
|
unused_async = "warn"
|
||||||
|
unused_self = "warn"
|
||||||
verbose_file_reads = "warn"
|
verbose_file_reads = "warn"
|
||||||
wildcard_dependencies = "warn"
|
wildcard_dependencies = "warn"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -277,12 +277,12 @@ impl Service {
|
||||||
let command_line = lines.next().expect("each string has at least one line");
|
let command_line = lines.next().expect("each string has at least one line");
|
||||||
let body: Vec<_> = lines.collect();
|
let body: Vec<_> = lines.collect();
|
||||||
|
|
||||||
let admin_command = match self.parse_admin_command(command_line) {
|
let admin_command = match Self::parse_admin_command(command_line) {
|
||||||
Ok(command) => command,
|
Ok(command) => command,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
let server_name = services().globals.server_name();
|
let server_name = services().globals.server_name();
|
||||||
let message = error.replace("server.name", server_name.as_str());
|
let message = error.replace("server.name", server_name.as_str());
|
||||||
let html_message = self.usage_to_html(&message, server_name);
|
let html_message = Self::usage_to_html(&message, server_name);
|
||||||
|
|
||||||
return RoomMessageEventContent::text_html(message, html_message);
|
return RoomMessageEventContent::text_html(message, html_message);
|
||||||
}
|
}
|
||||||
|
|
@ -306,7 +306,7 @@ impl Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse chat messages from the admin room into an AdminCommand object
|
// Parse chat messages from the admin room into an AdminCommand object
|
||||||
fn parse_admin_command(&self, command_line: &str) -> std::result::Result<AdminCommand, String> {
|
fn parse_admin_command(command_line: &str) -> std::result::Result<AdminCommand, String> {
|
||||||
// Note: argv[0] is `@grapevine:servername:`, which is treated as the main command
|
// Note: argv[0] is `@grapevine:servername:`, which is treated as the main command
|
||||||
let mut argv: Vec<_> = command_line.split_whitespace().collect();
|
let mut argv: Vec<_> = command_line.split_whitespace().collect();
|
||||||
|
|
||||||
|
|
@ -864,7 +864,7 @@ impl Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utility to turn clap's `--help` text to HTML.
|
// Utility to turn clap's `--help` text to HTML.
|
||||||
fn usage_to_html(&self, text: &str, server_name: &ServerName) -> String {
|
fn usage_to_html(text: &str, server_name: &ServerName) -> String {
|
||||||
// Replace `@grapevine:servername:-subcmdname` with `@grapevine:servername: subcmdname`
|
// Replace `@grapevine:servername:-subcmdname` with `@grapevine:servername: subcmdname`
|
||||||
let text = text.replace(
|
let text = text.replace(
|
||||||
&format!("@grapevine:{server_name}:-"),
|
&format!("@grapevine:{server_name}:-"),
|
||||||
|
|
@ -1183,6 +1183,8 @@ impl Service {
|
||||||
/// Gets the room ID of the admin room
|
/// Gets the room ID of the admin room
|
||||||
///
|
///
|
||||||
/// Errors are propagated from the database, and will have None if there is no admin room
|
/// Errors are propagated from the database, and will have None if there is no admin room
|
||||||
|
// Allowed because this function uses `services()`
|
||||||
|
#[allow(clippy::unused_self)]
|
||||||
pub(crate) fn get_admin_room(&self) -> Result<Option<OwnedRoomId>> {
|
pub(crate) fn get_admin_room(&self) -> Result<Option<OwnedRoomId>> {
|
||||||
let admin_room_alias: Box<RoomAliasId> =
|
let admin_room_alias: Box<RoomAliasId> =
|
||||||
format!("#admins:{}", services().globals.server_name())
|
format!("#admins:{}", services().globals.server_name())
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ impl Service {
|
||||||
|
|
||||||
/// Returns width, height of the thumbnail and whether it should be cropped. Returns None when
|
/// Returns width, height of the thumbnail and whether it should be cropped. Returns None when
|
||||||
/// the server should send the original file.
|
/// the server should send the original file.
|
||||||
pub(crate) fn thumbnail_properties(&self, width: u32, height: u32) -> Option<(u32, u32, bool)> {
|
fn thumbnail_properties(width: u32, height: u32) -> Option<(u32, u32, bool)> {
|
||||||
match (width, height) {
|
match (width, height) {
|
||||||
(0..=32, 0..=32) => Some((32, 32, true)),
|
(0..=32, 0..=32) => Some((32, 32, true)),
|
||||||
(0..=96, 0..=96) => Some((96, 96, true)),
|
(0..=96, 0..=96) => Some((96, 96, true)),
|
||||||
|
|
@ -113,9 +113,8 @@ impl Service {
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
) -> Result<Option<FileMeta>> {
|
) -> Result<Option<FileMeta>> {
|
||||||
let (width, height, crop) = self
|
let (width, height, crop) =
|
||||||
.thumbnail_properties(width, height)
|
Self::thumbnail_properties(width, height).unwrap_or((0, 0, false)); // 0, 0 because that's the original file
|
||||||
.unwrap_or((0, 0, false)); // 0, 0 because that's the original file
|
|
||||||
|
|
||||||
if let Ok((content_disposition, content_type, key)) =
|
if let Ok((content_disposition, content_type, key)) =
|
||||||
self.db.search_file_metadata(mxc.clone(), width, height)
|
self.db.search_file_metadata(mxc.clone(), width, height)
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ impl Service {
|
||||||
pub_key_map,
|
pub_key_map,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
self.check_room_id(room_id, &incoming_pdu)?;
|
Self::check_room_id(room_id, &incoming_pdu)?;
|
||||||
|
|
||||||
// 8. if not timeline event: stop
|
// 8. if not timeline event: stop
|
||||||
if !is_timeline_event {
|
if !is_timeline_event {
|
||||||
|
|
@ -375,7 +375,7 @@ impl Service {
|
||||||
)
|
)
|
||||||
.map_err(|_| Error::bad_database("Event is not a valid PDU."))?;
|
.map_err(|_| Error::bad_database("Event is not a valid PDU."))?;
|
||||||
|
|
||||||
self.check_room_id(room_id, &incoming_pdu)?;
|
Self::check_room_id(room_id, &incoming_pdu)?;
|
||||||
|
|
||||||
if !auth_events_known {
|
if !auth_events_known {
|
||||||
// 4. fetch any missing auth events doing all checks listed here starting at 1. These are not timeline events
|
// 4. fetch any missing auth events doing all checks listed here starting at 1. These are not timeline events
|
||||||
|
|
@ -411,7 +411,7 @@ impl Service {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.check_room_id(room_id, &auth_event)?;
|
Self::check_room_id(room_id, &auth_event)?;
|
||||||
|
|
||||||
match auth_events.entry((
|
match auth_events.entry((
|
||||||
auth_event.kind.to_string().into(),
|
auth_event.kind.to_string().into(),
|
||||||
|
|
@ -1287,7 +1287,7 @@ impl Service {
|
||||||
.await
|
.await
|
||||||
.pop()
|
.pop()
|
||||||
{
|
{
|
||||||
self.check_room_id(room_id, &pdu)?;
|
Self::check_room_id(room_id, &pdu)?;
|
||||||
|
|
||||||
if amount > services().globals.max_fetch_prev_events() {
|
if amount > services().globals.max_fetch_prev_events() {
|
||||||
// Max limit reached
|
// Max limit reached
|
||||||
|
|
@ -1612,6 +1612,8 @@ impl Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns Ok if the acl allows the server
|
/// Returns Ok if the acl allows the server
|
||||||
|
// Allowed because this function uses `services()`
|
||||||
|
#[allow(clippy::unused_self)]
|
||||||
pub(crate) fn acl_check(&self, server_name: &ServerName, room_id: &RoomId) -> Result<()> {
|
pub(crate) fn acl_check(&self, server_name: &ServerName, room_id: &RoomId) -> Result<()> {
|
||||||
let Some(acl_event) = services().rooms.state_accessor.room_state_get(
|
let Some(acl_event) = services().rooms.state_accessor.room_state_get(
|
||||||
room_id,
|
room_id,
|
||||||
|
|
@ -1815,7 +1817,7 @@ impl Service {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_room_id(&self, room_id: &RoomId, pdu: &PduEvent) -> Result<()> {
|
fn check_room_id(room_id: &RoomId, pdu: &PduEvent) -> Result<()> {
|
||||||
if pdu.room_id != room_id {
|
if pdu.room_id != room_id {
|
||||||
warn!("Found event from room {} in room {}", pdu.room_id, room_id);
|
warn!("Found event from room {} in room {}", pdu.room_id, room_id);
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,11 @@ impl Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(
|
||||||
|
clippy::too_many_arguments,
|
||||||
|
// Allowed because this function uses `services()`
|
||||||
|
clippy::unused_self,
|
||||||
|
)]
|
||||||
pub(crate) fn paginate_relations_with_filter(
|
pub(crate) fn paginate_relations_with_filter(
|
||||||
&self,
|
&self,
|
||||||
sender_user: &UserId,
|
sender_user: &UserId,
|
||||||
|
|
|
||||||
|
|
@ -415,7 +415,7 @@ impl Service {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.translate_joinrule(&join_rule)?
|
Self::translate_joinrule(&join_rule)?
|
||||||
},
|
},
|
||||||
room_type: services()
|
room_type: services()
|
||||||
.rooms
|
.rooms
|
||||||
|
|
@ -436,7 +436,7 @@ impl Service {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn translate_joinrule(&self, join_rule: &JoinRule) -> Result<SpaceRoomJoinRule> {
|
fn translate_joinrule(join_rule: &JoinRule) -> Result<SpaceRoomJoinRule> {
|
||||||
match join_rule {
|
match join_rule {
|
||||||
JoinRule::Invite => Ok(SpaceRoomJoinRule::Invite),
|
JoinRule::Invite => Ok(SpaceRoomJoinRule::Invite),
|
||||||
JoinRule::Knock => Ok(SpaceRoomJoinRule::Knock),
|
JoinRule::Knock => Ok(SpaceRoomJoinRule::Knock),
|
||||||
|
|
@ -448,6 +448,8 @@ impl Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allowed because this function uses `services()`
|
||||||
|
#[allow(clippy::unused_self)]
|
||||||
fn handle_simplified_join_rule(
|
fn handle_simplified_join_rule(
|
||||||
&self,
|
&self,
|
||||||
join_rule: &SpaceRoomJoinRule,
|
join_rule: &SpaceRoomJoinRule,
|
||||||
|
|
@ -473,7 +475,7 @@ impl Service {
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
) -> Result<bool> {
|
) -> Result<bool> {
|
||||||
if self.handle_simplified_join_rule(
|
if self.handle_simplified_join_rule(
|
||||||
&self.translate_joinrule(join_rule)?,
|
&Self::translate_joinrule(join_rule)?,
|
||||||
sender_user,
|
sender_user,
|
||||||
room_id,
|
room_id,
|
||||||
)? {
|
)? {
|
||||||
|
|
|
||||||
|
|
@ -282,10 +282,7 @@ impl Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_name(&self, room_id: &RoomId) -> Result<Option<String>> {
|
pub(crate) fn get_name(&self, room_id: &RoomId) -> Result<Option<String>> {
|
||||||
services()
|
self.room_state_get(room_id, &StateEventType::RoomName, "")?
|
||||||
.rooms
|
|
||||||
.state_accessor
|
|
||||||
.room_state_get(room_id, &StateEventType::RoomName, "")?
|
|
||||||
.map_or(Ok(None), |s| {
|
.map_or(Ok(None), |s| {
|
||||||
serde_json::from_str(s.content.get())
|
serde_json::from_str(s.content.get())
|
||||||
.map(|c: RoomNameEventContent| Some(c.name))
|
.map(|c: RoomNameEventContent| Some(c.name))
|
||||||
|
|
@ -300,16 +297,15 @@ impl Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_avatar(&self, room_id: &RoomId) -> Result<JsOption<RoomAvatarEventContent>> {
|
pub(crate) fn get_avatar(&self, room_id: &RoomId) -> Result<JsOption<RoomAvatarEventContent>> {
|
||||||
services()
|
self.room_state_get(room_id, &StateEventType::RoomAvatar, "")?
|
||||||
.rooms
|
|
||||||
.state_accessor
|
|
||||||
.room_state_get(room_id, &StateEventType::RoomAvatar, "")?
|
|
||||||
.map_or(Ok(JsOption::Undefined), |s| {
|
.map_or(Ok(JsOption::Undefined), |s| {
|
||||||
serde_json::from_str(s.content.get())
|
serde_json::from_str(s.content.get())
|
||||||
.map_err(|_| Error::bad_database("Invalid room avatar event in database."))
|
.map_err(|_| Error::bad_database("Invalid room avatar event in database."))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allowed because this function uses `services()`
|
||||||
|
#[allow(clippy::unused_self)]
|
||||||
pub(crate) fn user_can_invite(
|
pub(crate) fn user_can_invite(
|
||||||
&self,
|
&self,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
|
|
@ -340,10 +336,7 @@ impl Service {
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
user_id: &UserId,
|
user_id: &UserId,
|
||||||
) -> Result<Option<RoomMemberEventContent>> {
|
) -> Result<Option<RoomMemberEventContent>> {
|
||||||
services()
|
self.room_state_get(room_id, &StateEventType::RoomMember, user_id.as_str())?
|
||||||
.rooms
|
|
||||||
.state_accessor
|
|
||||||
.room_state_get(room_id, &StateEventType::RoomMember, user_id.as_str())?
|
|
||||||
.map_or(Ok(None), |s| {
|
.map_or(Ok(None), |s| {
|
||||||
serde_json::from_str(s.content.get())
|
serde_json::from_str(s.content.get())
|
||||||
.map_err(|_| Error::bad_database("Invalid room member event in database."))
|
.map_err(|_| Error::bad_database("Invalid room member event in database."))
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,8 @@ impl Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allowed because this function uses `services()`
|
||||||
|
#[allow(clippy::unused_self)]
|
||||||
pub(crate) fn compress_state_event(
|
pub(crate) fn compress_state_event(
|
||||||
&self,
|
&self,
|
||||||
shortstatekey: u64,
|
shortstatekey: u64,
|
||||||
|
|
@ -106,6 +108,8 @@ impl Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns shortstatekey, event id
|
/// Returns shortstatekey, event id
|
||||||
|
// Allowed because this function uses `services()`
|
||||||
|
#[allow(clippy::unused_self)]
|
||||||
pub(crate) fn parse_compressed_state_event(
|
pub(crate) fn parse_compressed_state_event(
|
||||||
&self,
|
&self,
|
||||||
compressed_event: &CompressedStateEvent,
|
compressed_event: &CompressedStateEvent,
|
||||||
|
|
|
||||||
|
|
@ -662,7 +662,7 @@ impl Service {
|
||||||
// Our depth is the maximum depth of prev_events + 1
|
// Our depth is the maximum depth of prev_events + 1
|
||||||
let depth = prev_events
|
let depth = prev_events
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|event_id| Some(services().rooms.timeline.get_pdu(event_id).ok()??.depth))
|
.filter_map(|event_id| Some(self.get_pdu(event_id).ok()??.depth))
|
||||||
.max()
|
.max()
|
||||||
.unwrap_or_else(|| uint!(0))
|
.unwrap_or_else(|| uint!(0))
|
||||||
+ uint!(1);
|
+ uint!(1);
|
||||||
|
|
|
||||||
|
|
@ -260,6 +260,8 @@ impl Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if a user is an admin
|
/// Check if a user is an admin
|
||||||
|
// Allowed because this function uses `services()`
|
||||||
|
#[allow(clippy::unused_self)]
|
||||||
pub(crate) fn is_admin(&self, user_id: &UserId) -> Result<bool> {
|
pub(crate) fn is_admin(&self, user_id: &UserId) -> Result<bool> {
|
||||||
let admin_room_alias_id =
|
let admin_room_alias_id =
|
||||||
RoomAliasId::parse(format!("#admins:{}", services().globals.server_name()))
|
RoomAliasId::parse(format!("#admins:{}", services().globals.server_name()))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue