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:
Charles Hall 2024-05-14 19:40:35 -07:00
parent f855bd09d1
commit e3672eb4e0
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
10 changed files with 39 additions and 30 deletions

View file

@ -282,10 +282,7 @@ impl Service {
}
pub(crate) fn get_name(&self, room_id: &RoomId) -> Result<Option<String>> {
services()
.rooms
.state_accessor
.room_state_get(room_id, &StateEventType::RoomName, "")?
self.room_state_get(room_id, &StateEventType::RoomName, "")?
.map_or(Ok(None), |s| {
serde_json::from_str(s.content.get())
.map(|c: RoomNameEventContent| Some(c.name))
@ -300,16 +297,15 @@ impl Service {
}
pub(crate) fn get_avatar(&self, room_id: &RoomId) -> Result<JsOption<RoomAvatarEventContent>> {
services()
.rooms
.state_accessor
.room_state_get(room_id, &StateEventType::RoomAvatar, "")?
self.room_state_get(room_id, &StateEventType::RoomAvatar, "")?
.map_or(Ok(JsOption::Undefined), |s| {
serde_json::from_str(s.content.get())
.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(
&self,
room_id: &RoomId,
@ -340,10 +336,7 @@ impl Service {
room_id: &RoomId,
user_id: &UserId,
) -> Result<Option<RoomMemberEventContent>> {
services()
.rooms
.state_accessor
.room_state_get(room_id, &StateEventType::RoomMember, user_id.as_str())?
self.room_state_get(room_id, &StateEventType::RoomMember, user_id.as_str())?
.map_or(Ok(None), |s| {
serde_json::from_str(s.content.get())
.map_err(|_| Error::bad_database("Invalid room member event in database."))