cargo clippy

This commit is contained in:
Nyaaori 2022-10-10 14:09:11 +02:00
parent ca82b2940d
commit f430b87459
No known key found for this signature in database
GPG key ID: E7819C3ED4D1F82E
32 changed files with 139 additions and 166 deletions

View file

@ -179,7 +179,7 @@ impl Service {
}
pub fn start_handler(self: &Arc<Self>) {
let self2 = Arc::clone(&self);
let self2 = Arc::clone(self);
tokio::spawn(async move {
self2.handler().await;
});
@ -270,13 +270,11 @@ impl Service {
let command_line = lines.next().expect("each string has at least one line");
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,
Err(error) => {
let server_name = services().globals.server_name();
let message = error
.to_string()
.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);
return RoomMessageEventContent::text_html(message, html_message);
@ -316,8 +314,8 @@ impl Service {
// Backwards compatibility with `register_appservice`-style commands
let command_with_dashes;
if argv.len() > 1 && argv[1].contains("_") {
command_with_dashes = argv[1].replace("_", "-");
if argv.len() > 1 && argv[1].contains('_') {
command_with_dashes = argv[1].replace('_', "-");
argv[1] = &command_with_dashes;
}
@ -631,7 +629,7 @@ impl Service {
let displayname = format!("{} ⚡️", user_id.localpart());
services()
.users
.set_displayname(&user_id, Some(displayname.clone()))?;
.set_displayname(&user_id, Some(displayname))?;
// Initial account data
services().account_data.update(
@ -771,7 +769,7 @@ impl Service {
let text = text.replace("subcommand", "command");
// Escape option names (e.g. `<element-id>`) since they look like HTML tags
let text = text.replace("<", "&lt;").replace(">", "&gt;");
let text = text.replace('<', "&lt;").replace('>', "&gt;");
// Italicize the first line (command name and version text)
let re = Regex::new("^(.*?)\n").expect("Regex compilation should not fail");
@ -799,7 +797,7 @@ impl Service {
while text_lines
.get(line_index)
.map(|line| line.starts_with("#"))
.map(|line| line.starts_with('#'))
.unwrap_or(false)
{
command_body += if text_lines[line_index].starts_with("# ") {
@ -830,12 +828,10 @@ impl Service {
};
// Add HTML line-breaks
let text = text
.replace("\n\n\n", "\n\n")
.replace("\n", "<br>\n")
.replace("[nobr]<br>", "");
text
text.replace("\n\n\n", "\n\n")
.replace('\n', "<br>\n")
.replace("[nobr]<br>", "")
}
/// Create the admin room.
@ -1110,7 +1106,7 @@ impl Service {
state_key: Some(user_id.to_string()),
redacts: None,
},
&user_id,
user_id,
&room_id,
&state_lock,
)?;
@ -1142,8 +1138,8 @@ impl Service {
PduBuilder {
event_type: RoomEventType::RoomMessage,
content: to_raw_value(&RoomMessageEventContent::text_html(
format!("## Thank you for trying out Conduit!\n\nConduit is currently in Beta. This means you can join and participate in most Matrix rooms, but not all features are supported and you might run into bugs from time to time.\n\nHelpful links:\n> Website: https://conduit.rs\n> Git and Documentation: https://gitlab.com/famedly/conduit\n> Report issues: https://gitlab.com/famedly/conduit/-/issues\n\nFor a list of available commands, send the following message in this room: `@conduit:{}: --help`\n\nHere are some rooms you can join (by typing the command):\n\nConduit room (Ask questions and get notified on updates):\n`/join #conduit:fachschaften.org`\n\nConduit lounge (Off-topic, only Conduit users are allowed to join)\n`/join #conduit-lounge:conduit.rs`", services().globals.server_name()).to_owned(),
format!("<h2>Thank you for trying out Conduit!</h2>\n<p>Conduit is currently in Beta. This means you can join and participate in most Matrix rooms, but not all features are supported and you might run into bugs from time to time.</p>\n<p>Helpful links:</p>\n<blockquote>\n<p>Website: https://conduit.rs<br>Git and Documentation: https://gitlab.com/famedly/conduit<br>Report issues: https://gitlab.com/famedly/conduit/-/issues</p>\n</blockquote>\n<p>For a list of available commands, send the following message in this room: <code>@conduit:{}: --help</code></p>\n<p>Here are some rooms you can join (by typing the command):</p>\n<p>Conduit room (Ask questions and get notified on updates):<br><code>/join #conduit:fachschaften.org</code></p>\n<p>Conduit lounge (Off-topic, only Conduit users are allowed to join)<br><code>/join #conduit-lounge:conduit.rs</code></p>\n", services().globals.server_name()).to_owned(),
format!("## Thank you for trying out Conduit!\n\nConduit is currently in Beta. This means you can join and participate in most Matrix rooms, but not all features are supported and you might run into bugs from time to time.\n\nHelpful links:\n> Website: https://conduit.rs\n> Git and Documentation: https://gitlab.com/famedly/conduit\n> Report issues: https://gitlab.com/famedly/conduit/-/issues\n\nFor a list of available commands, send the following message in this room: `@conduit:{}: --help`\n\nHere are some rooms you can join (by typing the command):\n\nConduit room (Ask questions and get notified on updates):\n`/join #conduit:fachschaften.org`\n\nConduit lounge (Off-topic, only Conduit users are allowed to join)\n`/join #conduit-lounge:conduit.rs`", services().globals.server_name()),
format!("<h2>Thank you for trying out Conduit!</h2>\n<p>Conduit is currently in Beta. This means you can join and participate in most Matrix rooms, but not all features are supported and you might run into bugs from time to time.</p>\n<p>Helpful links:</p>\n<blockquote>\n<p>Website: https://conduit.rs<br>Git and Documentation: https://gitlab.com/famedly/conduit<br>Report issues: https://gitlab.com/famedly/conduit/-/issues</p>\n</blockquote>\n<p>For a list of available commands, send the following message in this room: <code>@conduit:{}: --help</code></p>\n<p>Here are some rooms you can join (by typing the command):</p>\n<p>Conduit room (Ask questions and get notified on updates):<br><code>/join #conduit:fachschaften.org</code></p>\n<p>Conduit lounge (Off-topic, only Conduit users are allowed to join)<br><code>/join #conduit-lounge:conduit.rs</code></p>\n", services().globals.server_name()),
))
.expect("event is valid, we just created it"),
unsigned: None,

View file

@ -4,7 +4,6 @@ use ruma::events::AnySyncTimelineEvent;
use crate::{services, Error, PduEvent, Result};
use bytes::BytesMut;
use ruma::api::IncomingResponse;
use ruma::{
api::{
client::push::{get_pushers, set_pusher, PusherKind},
@ -12,7 +11,7 @@ use ruma::{
self,
v1::{Device, Notification, NotificationCounts, NotificationPriority},
},
MatrixVersion, OutgoingRequest, SendAccessToken,
IncomingResponse, MatrixVersion, OutgoingRequest, SendAccessToken,
},
events::{
room::{name::RoomNameEventContent, power_levels::RoomPowerLevelsEventContent},

View file

@ -284,7 +284,7 @@ impl Service {
RoomVersion::new(room_version_id).expect("room version is supported");
let mut val = match ruma::signatures::verify_event(
&*pub_key_map.read().expect("RwLock is poisoned."),
&pub_key_map.read().expect("RwLock is poisoned."),
&value,
room_version_id,
) {
@ -1198,7 +1198,7 @@ impl Service {
.fetch_and_handle_outliers(
origin,
&[prev_event_id.clone()],
&create_event,
create_event,
room_id,
pub_key_map,
)
@ -1224,7 +1224,7 @@ impl Service {
amount += 1;
for prev_prev in &pdu.prev_events {
if !graph.contains_key(prev_prev) {
todo_outlier_stack.push(dbg!(prev_prev.clone()));
todo_outlier_stack.push(prev_prev.clone());
}
}
@ -1248,7 +1248,7 @@ impl Service {
}
}
let sorted = state_res::lexicographical_topological_sort(dbg!(&graph), |event_id| {
let sorted = state_res::lexicographical_topological_sort(&graph, |event_id| {
// This return value is the key used for sorting events,
// events are then sorted by power level, time,
// and lexically by event_id.
@ -1482,8 +1482,8 @@ impl Service {
}
let mut futures: FuturesUnordered<_> = servers
.into_iter()
.map(|(server, _)| async move {
.into_keys()
.map(|server| async move {
(
services()
.sending

View file

@ -1,7 +1,6 @@
use crate::Result;
use ruma::{EventId, OwnedEventId, RoomId};
use std::collections::HashSet;
use std::sync::Arc;
use std::{collections::HashSet, sync::Arc};
use tokio::sync::MutexGuard;
pub trait Data: Send + Sync {

View file

@ -93,7 +93,7 @@ impl Service {
services().rooms.state_cache.update_joined_count(room_id)?;
self.db
.set_room_state(room_id, shortstatehash, &state_lock)?;
.set_room_state(room_id, shortstatehash, state_lock)?;
Ok(())
}
@ -331,7 +331,7 @@ impl Service {
.transpose()?;
let room_version = create_event_content
.map(|create_event| create_event.room_version)
.ok_or_else(|| Error::BadDatabase("Invalid room version"))?;
.ok_or(Error::BadDatabase("Invalid room version"))?;
Ok(room_version)
}

View file

@ -2,29 +2,29 @@ mod data;
use std::collections::HashMap;
use std::collections::HashSet;
use std::sync::{Arc, Mutex};
use std::{
collections::HashSet,
sync::{Arc, Mutex},
};
pub use data::Data;
use regex::Regex;
use ruma::canonical_json::to_canonical_value;
use ruma::events::room::power_levels::RoomPowerLevelsEventContent;
use ruma::push::Ruleset;
use ruma::state_res::RoomVersion;
use ruma::CanonicalJsonObject;
use ruma::CanonicalJsonValue;
use ruma::OwnedEventId;
use ruma::OwnedRoomId;
use ruma::OwnedServerName;
use ruma::{
api::client::error::ErrorKind,
canonical_json::to_canonical_value,
events::{
push_rules::PushRulesEvent,
room::{create::RoomCreateEventContent, member::MembershipState},
room::{
create::RoomCreateEventContent, member::MembershipState,
power_levels::RoomPowerLevelsEventContent,
},
GlobalAccountDataEventType, RoomEventType, StateEventType,
},
push::{Action, Tweak},
state_res, uint, EventId, RoomAliasId, RoomId, UserId,
push::{Action, Ruleset, Tweak},
state_res,
state_res::RoomVersion,
uint, CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedEventId, OwnedRoomId,
OwnedServerName, RoomAliasId, RoomId, UserId,
};
use serde::Deserialize;
use serde_json::value::to_raw_value;
@ -267,7 +267,7 @@ impl Service {
.account_data
.get(
None,
&user,
user,
GlobalAccountDataEventType::PushRules.to_string().into(),
)?
.map(|event| {
@ -276,13 +276,13 @@ impl Service {
})
.transpose()?
.map(|ev: PushRulesEvent| ev.content.global)
.unwrap_or_else(|| Ruleset::server_default(&user));
.unwrap_or_else(|| Ruleset::server_default(user));
let mut highlight = false;
let mut notify = false;
for action in services().pusher.get_actions(
&user,
user,
&rules_for_user,
&power_levels,
&sync_pdu,
@ -307,10 +307,8 @@ impl Service {
highlights.push(user.clone());
}
for push_key in services().pusher.get_pushkeys(&user) {
services()
.sending
.send_push_pdu(&*pdu_id, &user, push_key?)?;
for push_key in services().pusher.get_pushkeys(user) {
services().sending.send_push_pdu(&pdu_id, user, push_key?)?;
}
}
@ -388,7 +386,7 @@ impl Service {
&& services().globals.emergency_password().is_none();
if to_conduit && !from_conduit && admin_room.as_ref() == Some(&pdu.room_id) {
services().admin.process_message(body.to_string());
services().admin.process_message(body);
}
}
}
@ -583,8 +581,8 @@ impl Service {
prev_events,
depth,
auth_events: auth_events
.iter()
.map(|(_, pdu)| pdu.event_id.clone())
.values()
.map(|pdu| pdu.event_id.clone())
.collect(),
redacts,
unsigned: if unsigned.is_empty() {
@ -683,7 +681,7 @@ impl Service {
state_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
) -> Result<Arc<EventId>> {
let (pdu, pdu_json) =
self.create_hash_and_sign_event(pdu_builder, sender, room_id, &state_lock)?;
self.create_hash_and_sign_event(pdu_builder, sender, room_id, state_lock)?;
// 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.

View file

@ -110,7 +110,7 @@ impl Service {
}
pub fn start_handler(self: &Arc<Self>) {
let self2 = Arc::clone(&self);
let self2 = Arc::clone(self);
tokio::spawn(async move {
self2.handler().await.unwrap();
});
@ -280,7 +280,7 @@ impl Service {
device_list_changes.extend(
services()
.users
.keys_changed(&room_id.to_string(), since, None)
.keys_changed(room_id.as_ref(), since, None)
.filter_map(|r| r.ok())
.filter(|user_id| user_id.server_name() == services().globals.server_name()),
);
@ -487,7 +487,7 @@ impl Service {
let response = appservice_server::send_request(
services()
.appservice
.get_registration(&id)
.get_registration(id)
.map_err(|e| (kind.clone(), e))?
.ok_or_else(|| {
(
@ -562,7 +562,7 @@ impl Service {
let pusher = match services()
.pusher
.get_pusher(&userid, pushkey)
.get_pusher(userid, pushkey)
.map_err(|e| (OutgoingKind::Push(userid.clone(), pushkey.clone()), e))?
{
Some(pusher) => pusher,
@ -573,18 +573,18 @@ impl Service {
.account_data
.get(
None,
&userid,
userid,
GlobalAccountDataEventType::PushRules.to_string().into(),
)
.unwrap_or_default()
.and_then(|event| serde_json::from_str::<PushRulesEvent>(event.get()).ok())
.map(|ev: PushRulesEvent| ev.content.global)
.unwrap_or_else(|| push::Ruleset::server_default(&userid));
.unwrap_or_else(|| push::Ruleset::server_default(userid));
let unread: UInt = services()
.rooms
.user
.notification_count(&userid, &pdu.room_id)
.notification_count(userid, &pdu.room_id)
.map_err(|e| (kind.clone(), e))?
.try_into()
.expect("notification count can't go that high");
@ -593,7 +593,7 @@ impl Service {
let _response = services()
.pusher
.send_push_notice(&userid, unread, &pusher, rules_for_user, &pdu)
.send_push_notice(userid, unread, &pusher, rules_for_user, &pdu)
.await
.map(|_response| kind.clone())
.map_err(|e| (kind.clone(), e));
@ -638,7 +638,7 @@ impl Service {
let permit = services().sending.maximum_requests.acquire().await;
let response = server_server::send_request(
&*server,
server,
send_transaction_message::v1::Request {
origin: services().globals.server_name(),
pdus: &pdu_jsons,