Fix most clippy lints and unnecessary conversions
This commit is contained in:
parent
eeda7cbe0a
commit
6454ff2c3d
14 changed files with 60 additions and 70 deletions
|
@ -16,8 +16,10 @@ use ruma::{
|
|||
uiaa::{AuthFlow, AuthType, UiaaInfo},
|
||||
},
|
||||
events::{
|
||||
room::member::{MembershipState, RoomMemberEventContent},
|
||||
room::message::RoomMessageEventContent,
|
||||
room::{
|
||||
member::{MembershipState, RoomMemberEventContent},
|
||||
message::RoomMessageEventContent,
|
||||
},
|
||||
GlobalAccountDataEventType, RoomEventType,
|
||||
},
|
||||
push, UserId,
|
||||
|
@ -350,7 +352,7 @@ pub async fn whoami_route(
|
|||
Ok(whoami::v3::Response {
|
||||
user_id: sender_user.clone(),
|
||||
device_id,
|
||||
is_guest: db.users.is_deactivated(&sender_user)?,
|
||||
is_guest: db.users.is_deactivated(sender_user)?,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -285,9 +285,9 @@ pub(crate) async fn get_public_rooms_filtered_helper(
|
|||
})
|
||||
.transpose()?
|
||||
.flatten()
|
||||
.ok_or(Error::bad_database(
|
||||
"Invalid room join rule event in database.",
|
||||
))?,
|
||||
.ok_or_else(|| {
|
||||
Error::bad_database("Invalid room join rule event in database.")
|
||||
})?,
|
||||
room_id,
|
||||
};
|
||||
Ok(chunk)
|
||||
|
|
|
@ -83,7 +83,7 @@ pub async fn get_remote_content(
|
|||
|
||||
db.media
|
||||
.create(
|
||||
mxc.to_string(),
|
||||
mxc.to_owned(),
|
||||
&db.globals,
|
||||
&content_response.content_disposition.as_deref(),
|
||||
&content_response.content_type.as_deref(),
|
||||
|
|
|
@ -507,7 +507,7 @@ async fn join_room_by_id_helper(
|
|||
let (make_join_response, remote_server) = make_join_response_and_server?;
|
||||
|
||||
let room_version = match make_join_response.room_version {
|
||||
Some(room_version) if db.rooms.is_supported_version(&db, &room_version) => room_version,
|
||||
Some(room_version) if db.rooms.is_supported_version(db, &room_version) => room_version,
|
||||
_ => return Err(Error::BadServerResponse("Room version is not supported")),
|
||||
};
|
||||
|
||||
|
@ -975,8 +975,7 @@ pub(crate) async fn invite_helper<'a>(
|
|||
let pub_key_map = RwLock::new(BTreeMap::new());
|
||||
|
||||
// We do not add the event_id field to the pdu here because of signature and hashes checks
|
||||
let (event_id, value) = match crate::pdu::gen_event_id_canonical_json(&response.event, &db)
|
||||
{
|
||||
let (event_id, value) = match crate::pdu::gen_event_id_canonical_json(&response.event, db) {
|
||||
Ok(t) => t,
|
||||
Err(_) => {
|
||||
// Event could not be converted to canonical json
|
||||
|
|
|
@ -4,7 +4,7 @@ use ruma::{
|
|||
error::ErrorKind,
|
||||
message::{get_message_events, send_message_event},
|
||||
},
|
||||
events::{RoomEventType, StateEventType},
|
||||
events::{MessageLikeEventType, StateEventType},
|
||||
};
|
||||
use std::{
|
||||
collections::{BTreeMap, HashSet},
|
||||
|
@ -36,9 +36,7 @@ pub async fn send_message_event_route(
|
|||
let state_lock = mutex_state.lock().await;
|
||||
|
||||
// Forbid m.room.encrypted if encryption is disabled
|
||||
if RoomEventType::RoomEncrypted == body.event_type.to_string().into()
|
||||
&& !db.globals.allow_encryption()
|
||||
{
|
||||
if body.event_type == MessageLikeEventType::RoomEncrypted && !db.globals.allow_encryption() {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::Forbidden,
|
||||
"Encryption has been disabled",
|
||||
|
|
|
@ -56,8 +56,7 @@ pub async fn login_route(
|
|||
} else {
|
||||
return Err(Error::BadRequest(ErrorKind::Forbidden, "Bad login type."));
|
||||
};
|
||||
let user_id =
|
||||
UserId::parse_with_server_name(username.to_owned(), db.globals.server_name())
|
||||
let user_id = UserId::parse_with_server_name(username, db.globals.server_name())
|
||||
.map_err(|_| {
|
||||
Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid.")
|
||||
})?;
|
||||
|
|
|
@ -73,7 +73,7 @@ pub async fn send_state_event_for_empty_key_route(
|
|||
&db,
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
&body.event_type.to_string().into(),
|
||||
&body.event_type,
|
||||
&body.body.body,
|
||||
body.state_key.to_owned(),
|
||||
)
|
||||
|
|
|
@ -61,7 +61,7 @@ pub async fn send_event_to_device_route(
|
|||
DeviceIdOrAllDevices::DeviceId(target_device_id) => db.users.add_to_device_event(
|
||||
sender_user,
|
||||
target_user_id,
|
||||
&target_device_id,
|
||||
target_device_id,
|
||||
&body.event_type,
|
||||
event.deserialize_as().map_err(|_| {
|
||||
Error::BadRequest(ErrorKind::InvalidParam, "Event is invalid")
|
||||
|
|
|
@ -177,7 +177,7 @@ impl fmt::Display for Config {
|
|||
("Turn TTL", &self.turn_ttl.to_string()),
|
||||
("Turn URIs", {
|
||||
let mut lst = vec![];
|
||||
for item in self.turn_uris.to_vec().into_iter().enumerate() {
|
||||
for item in self.turn_uris.iter().cloned().enumerate() {
|
||||
let (_, uri): (usize, String) = item;
|
||||
lst.push(uri);
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ impl fmt::Display for Config {
|
|||
}),
|
||||
];
|
||||
|
||||
let mut msg: String = "Active config values:\n\n".to_string();
|
||||
let mut msg: String = "Active config values:\n\n".to_owned();
|
||||
|
||||
for line in lines.into_iter().enumerate() {
|
||||
msg += &format!("{}: {}\n", line.1 .0, line.1 .1);
|
||||
|
|
|
@ -443,7 +443,7 @@ impl Database {
|
|||
for (roomid, _) in db.rooms.roomid_shortstatehash.iter() {
|
||||
let string = utils::string_from_bytes(&roomid).unwrap();
|
||||
let room_id = <&RoomId>::try_from(string.as_str()).unwrap();
|
||||
db.rooms.update_joined_count(room_id, &db)?;
|
||||
db.rooms.update_joined_count(room_id, db)?;
|
||||
}
|
||||
|
||||
db.globals.bump_database_version(6)?;
|
||||
|
|
|
@ -147,13 +147,11 @@ fn process_admin_message(db: &Database, room_message: String) -> RoomMessageEven
|
|||
let command_line = lines.next().expect("each string has at least one line");
|
||||
let body: Vec<_> = lines.collect();
|
||||
|
||||
let admin_command = match parse_admin_command(&command_line) {
|
||||
let admin_command = match parse_admin_command(command_line) {
|
||||
Ok(command) => command,
|
||||
Err(error) => {
|
||||
let server_name = db.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 = usage_to_html(&message, server_name);
|
||||
|
||||
return RoomMessageEventContent::text_html(message, html_message);
|
||||
|
@ -193,8 +191,8 @@ fn parse_admin_command(command_line: &str) -> std::result::Result<AdminCommand,
|
|||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -498,7 +496,7 @@ fn usage_to_html(text: &str, server_name: &ServerName) -> String {
|
|||
let text = text.replace("subcommand", "command");
|
||||
|
||||
// Escape option names (e.g. `<element-id>`) since they look like HTML tags
|
||||
let text = text.replace("<", "<").replace(">", ">");
|
||||
let text = text.replace('<', "<").replace('>', ">");
|
||||
|
||||
// Italicize the first line (command name and version text)
|
||||
let re = Regex::new("^(.*?)\n").expect("Regex compilation should not fail");
|
||||
|
@ -526,7 +524,7 @@ fn usage_to_html(text: &str, server_name: &ServerName) -> String {
|
|||
|
||||
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("# ") {
|
||||
|
@ -557,12 +555,10 @@ fn usage_to_html(text: &str, server_name: &ServerName) -> String {
|
|||
};
|
||||
|
||||
// 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.
|
||||
|
@ -606,7 +602,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
|||
},
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
db,
|
||||
&state_lock,
|
||||
)?;
|
||||
|
||||
|
@ -631,7 +627,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
|||
},
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
db,
|
||||
&state_lock,
|
||||
)?;
|
||||
|
||||
|
@ -653,7 +649,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
|||
},
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
db,
|
||||
&state_lock,
|
||||
)?;
|
||||
|
||||
|
@ -669,7 +665,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
|||
},
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
db,
|
||||
&state_lock,
|
||||
)?;
|
||||
|
||||
|
@ -687,7 +683,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
|||
},
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
db,
|
||||
&state_lock,
|
||||
)?;
|
||||
|
||||
|
@ -703,7 +699,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
|||
},
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
db,
|
||||
&state_lock,
|
||||
)?;
|
||||
|
||||
|
@ -721,7 +717,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
|||
},
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
db,
|
||||
&state_lock,
|
||||
)?;
|
||||
|
||||
|
@ -738,7 +734,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
|||
},
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
db,
|
||||
&state_lock,
|
||||
)?;
|
||||
|
||||
|
@ -761,7 +757,7 @@ pub(crate) async fn create_admin_room(db: &Database) -> Result<()> {
|
|||
},
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
db,
|
||||
&state_lock,
|
||||
)?;
|
||||
|
||||
|
@ -821,7 +817,7 @@ pub(crate) async fn make_user_admin(
|
|||
},
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
db,
|
||||
&state_lock,
|
||||
)?;
|
||||
db.rooms.build_and_append_pdu(
|
||||
|
@ -842,9 +838,9 @@ pub(crate) async fn make_user_admin(
|
|||
state_key: Some(user_id.to_string()),
|
||||
redacts: None,
|
||||
},
|
||||
&user_id,
|
||||
user_id,
|
||||
&room_id,
|
||||
&db,
|
||||
db,
|
||||
&state_lock,
|
||||
)?;
|
||||
|
||||
|
@ -867,7 +863,7 @@ pub(crate) async fn make_user_admin(
|
|||
},
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
db,
|
||||
&state_lock,
|
||||
)?;
|
||||
|
||||
|
@ -876,8 +872,8 @@ pub(crate) async fn make_user_admin(
|
|||
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`", db.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", db.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`", db.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", db.globals.server_name()),
|
||||
))
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
|
@ -886,7 +882,7 @@ pub(crate) async fn make_user_admin(
|
|||
},
|
||||
&conduit_user,
|
||||
&room_id,
|
||||
&db,
|
||||
db,
|
||||
&state_lock,
|
||||
)?;
|
||||
|
||||
|
|
|
@ -279,7 +279,7 @@ impl Rooms {
|
|||
let mut sauthevents = auth_events
|
||||
.into_iter()
|
||||
.filter_map(|(event_type, state_key)| {
|
||||
self.get_shortstatekey(&event_type.to_string().into(), &state_key)
|
||||
self.get_shortstatekey(&event_type, &state_key)
|
||||
.ok()
|
||||
.flatten()
|
||||
.map(|s| (s, (event_type, state_key)))
|
||||
|
@ -1529,7 +1529,7 @@ impl Rooms {
|
|||
{
|
||||
hash_map::Entry::Vacant(v) => {
|
||||
if let Some(last_count) = self
|
||||
.pdus_until(&sender_user, &room_id, u64::MAX)?
|
||||
.pdus_until(sender_user, room_id, u64::MAX)?
|
||||
.filter_map(|r| {
|
||||
// Filter out buggy events
|
||||
if r.is_err() {
|
||||
|
@ -2694,7 +2694,7 @@ impl Rooms {
|
|||
let (make_leave_response, remote_server) = make_leave_response_and_server?;
|
||||
|
||||
let room_version_id = match make_leave_response.room_version {
|
||||
Some(version) if self.is_supported_version(&db, &version) => version,
|
||||
Some(version) if self.is_supported_version(db, &version) => version,
|
||||
_ => return Err(Error::BadServerResponse("Room version is not supported")),
|
||||
};
|
||||
|
||||
|
@ -3467,7 +3467,7 @@ impl Rooms {
|
|||
.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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -535,7 +535,7 @@ impl Sending {
|
|||
let response = appservice_server::send_request(
|
||||
&db.globals,
|
||||
db.appservice
|
||||
.get_registration(&id)
|
||||
.get_registration(id)
|
||||
.map_err(|e| (kind.clone(), e))?
|
||||
.ok_or_else(|| {
|
||||
(
|
||||
|
|
|
@ -684,7 +684,7 @@ pub async fn send_transaction_message_route(
|
|||
}
|
||||
};
|
||||
|
||||
acl_check(&sender_servername, &room_id, &db)?;
|
||||
acl_check(sender_servername, &room_id, &db)?;
|
||||
|
||||
let mutex = Arc::clone(
|
||||
db.globals
|
||||
|
@ -699,7 +699,7 @@ pub async fn send_transaction_message_route(
|
|||
resolved_map.insert(
|
||||
event_id.clone(),
|
||||
handle_incoming_pdu(
|
||||
&sender_servername,
|
||||
sender_servername,
|
||||
&event_id,
|
||||
&room_id,
|
||||
value,
|
||||
|
@ -1214,7 +1214,7 @@ fn handle_outlier_pdu<'a>(
|
|||
&room_version,
|
||||
&incoming_pdu,
|
||||
None::<PduEvent>, // TODO: third party invite
|
||||
|k, s| auth_events.get(&(k.to_string().into(), s.to_owned())),
|
||||
|k, s| auth_events.get(&(k.to_owned(), s.to_owned())),
|
||||
)
|
||||
.map_err(|_e| "Auth check failed".to_owned())?
|
||||
{
|
||||
|
@ -1357,9 +1357,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
|
||||
for (k, id) in leaf_state {
|
||||
if let Ok((ty, st_key)) = db.rooms.get_statekey_from_short(k) {
|
||||
// FIXME: Undo .to_string().into() when StateMap
|
||||
// is updated to use StateEventType
|
||||
state.insert((ty.to_string().into(), st_key), id.clone());
|
||||
state.insert((ty, st_key), id.clone());
|
||||
} else {
|
||||
warn!("Failed to get_statekey_from_short.");
|
||||
}
|
||||
|
@ -1501,7 +1499,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
None::<PduEvent>, // TODO: third party invite
|
||||
|k, s| {
|
||||
db.rooms
|
||||
.get_shortstatekey(&k.to_string().into(), s)
|
||||
.get_shortstatekey(k, s)
|
||||
.ok()
|
||||
.flatten()
|
||||
.and_then(|shortstatekey| state_at_incoming_event.get(&shortstatekey))
|
||||
|
@ -1705,9 +1703,7 @@ async fn upgrade_outlier_to_timeline_pdu(
|
|||
.filter_map(|(k, id)| {
|
||||
db.rooms
|
||||
.get_statekey_from_short(k)
|
||||
// FIXME: Undo .to_string().into() when StateMap
|
||||
// is updated to use StateEventType
|
||||
.map(|(ty, st_key)| ((ty.to_string().into(), st_key), id))
|
||||
.map(|(ty, st_key)| ((ty, st_key), id))
|
||||
.map_err(|e| warn!("Failed to get_statekey_from_short: {}", e))
|
||||
.ok()
|
||||
})
|
||||
|
@ -1867,7 +1863,7 @@ pub(crate) fn fetch_and_handle_outliers<'a>(
|
|||
Ok(res) => {
|
||||
warn!("Got {} over federation", next_id);
|
||||
let (calculated_event_id, value) =
|
||||
match crate::pdu::gen_event_id_canonical_json(&res.pdu, &db) {
|
||||
match crate::pdu::gen_event_id_canonical_json(&res.pdu, db) {
|
||||
Ok(t) => t,
|
||||
Err(_) => {
|
||||
back_off((*next_id).to_owned());
|
||||
|
@ -2828,7 +2824,7 @@ async fn create_join_event(
|
|||
// let mut auth_cache = EventMap::new();
|
||||
|
||||
// We do not add the event_id field to the pdu here because of signature and hashes checks
|
||||
let (event_id, value) = match crate::pdu::gen_event_id_canonical_json(pdu, &db) {
|
||||
let (event_id, value) = match crate::pdu::gen_event_id_canonical_json(pdu, db) {
|
||||
Ok(t) => t,
|
||||
Err(_) => {
|
||||
// Event could not be converted to canonical json
|
||||
|
|
Loading…
Add table
Reference in a new issue