resolve and add even more pedantic clippy lints
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
0bb5115bd1
commit
3bc2af7d26
32 changed files with 167 additions and 167 deletions
|
@ -76,6 +76,7 @@ pub async fn get_register_available_route(
|
|||
/// - Creates a new account and populates it with default account data
|
||||
/// - If `inhibit_login` is false: Creates a device and returns device id and
|
||||
/// access_token
|
||||
#[allow(clippy::doc_markdown)]
|
||||
pub async fn register_route(body: Ruma<register::v3::Request>) -> Result<register::v3::Response> {
|
||||
if !services().globals.allow_registration() && !body.from_appservice {
|
||||
info!(
|
||||
|
@ -390,7 +391,7 @@ pub async fn change_password_route(body: Ruma<change_password::v3::Request>) ->
|
|||
|
||||
/// # `GET _matrix/client/r0/account/whoami`
|
||||
///
|
||||
/// Get user_id of the sender user.
|
||||
/// Get `user_id` of the sender user.
|
||||
///
|
||||
/// Note: Also works for Application Services
|
||||
pub async fn whoami_route(body: Ruma<whoami::v3::Request>) -> Result<whoami::v3::Response> {
|
||||
|
|
|
@ -91,8 +91,7 @@ pub async fn get_context_route(body: Ruma<get_context::v3::Request>) -> Result<g
|
|||
}
|
||||
}
|
||||
|
||||
let start_token =
|
||||
events_before.last().map(|(count, _)| count.stringify()).unwrap_or_else(|| base_token.stringify());
|
||||
let start_token = events_before.last().map_or_else(|| base_token.stringify(), |(count, _)| count.stringify());
|
||||
|
||||
let events_before: Vec<_> = events_before.into_iter().map(|(_, pdu)| pdu.to_room_event()).collect();
|
||||
|
||||
|
@ -134,7 +133,7 @@ pub async fn get_context_route(body: Ruma<get_context::v3::Request>) -> Result<g
|
|||
|
||||
let state_ids = services().rooms.state_accessor.state_full_ids(shortstatehash).await?;
|
||||
|
||||
let end_token = events_after.last().map(|(count, _)| count.stringify()).unwrap_or_else(|| base_token.stringify());
|
||||
let end_token = events_after.last().map_or_else(|| base_token.stringify(), |(count, _)| count.stringify());
|
||||
|
||||
let events_after: Vec<_> = events_after.into_iter().map(|(_, pdu)| pdu.to_room_event()).collect();
|
||||
|
||||
|
|
|
@ -363,11 +363,11 @@ pub(crate) async fn get_keys_helper<F: Fn(&UserId) -> bool>(
|
|||
}
|
||||
|
||||
Ok(get_keys::v3::Response {
|
||||
failures,
|
||||
device_keys,
|
||||
master_keys,
|
||||
self_signing_keys,
|
||||
user_signing_keys,
|
||||
device_keys,
|
||||
failures,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ pub async fn send_message_event_route(
|
|||
///
|
||||
/// - Only works if the user is joined (TODO: always allow, but only show events
|
||||
/// where the user was
|
||||
/// joined, depending on history_visibility)
|
||||
/// joined, depending on `history_visibility`)
|
||||
pub async fn get_message_events_route(
|
||||
body: Ruma<get_message_events::v3::Request>,
|
||||
) -> Result<get_message_events::v3::Response> {
|
||||
|
|
|
@ -126,9 +126,9 @@ pub async fn get_displayname_route(
|
|||
})
|
||||
}
|
||||
|
||||
/// # `PUT /_matrix/client/r0/profile/{userId}/avatar_url`
|
||||
/// # `PUT /_matrix/client/v3/profile/{userId}/avatar_url`
|
||||
///
|
||||
/// Updates the avatar_url and blurhash.
|
||||
/// Updates the `avatar_url` and `blurhash`.
|
||||
///
|
||||
/// - Also makes sure other users receive the update using presence EDUs
|
||||
pub async fn set_avatar_url_route(body: Ruma<set_avatar_url::v3::Request>) -> Result<set_avatar_url::v3::Response> {
|
||||
|
@ -192,10 +192,10 @@ pub async fn set_avatar_url_route(body: Ruma<set_avatar_url::v3::Request>) -> Re
|
|||
|
||||
/// # `GET /_matrix/client/v3/profile/{userId}/avatar_url`
|
||||
///
|
||||
/// Returns the avatar_url and blurhash of the user.
|
||||
/// Returns the `avatar_url` and `blurhash` of the user.
|
||||
///
|
||||
/// - If user is on another server and we do not have a local copy already
|
||||
/// fetch avatar_url and blurhash over federation
|
||||
/// fetch `avatar_url` and blurhash over federation
|
||||
pub async fn get_avatar_url_route(body: Ruma<get_avatar_url::v3::Request>) -> Result<get_avatar_url::v3::Response> {
|
||||
if body.user_id.server_name() != services().globals.server_name() {
|
||||
// Create and update our local copy of the user
|
||||
|
|
|
@ -34,7 +34,7 @@ use crate::{api::client_server::invite_helper, service::pdu::PduBuilder, service
|
|||
/// Creates a new room.
|
||||
///
|
||||
/// - Room ID is randomly generated
|
||||
/// - Create alias if room_alias_name is set
|
||||
/// - Create alias if `room_alias_name` is set
|
||||
/// - Send create event
|
||||
/// - Join sender user
|
||||
/// - Send power levels event
|
||||
|
@ -273,7 +273,7 @@ pub async fn create_room_route(body: Ruma<create_room::v3::Request>) -> Result<c
|
|||
event_type: TimelineEventType::RoomCreate,
|
||||
content: to_raw_value(&content).expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
state_key: Some("".to_owned()),
|
||||
state_key: Some(String::new()),
|
||||
redacts: None,
|
||||
},
|
||||
sender_user,
|
||||
|
@ -350,7 +350,7 @@ pub async fn create_room_route(body: Ruma<create_room::v3::Request>) -> Result<c
|
|||
event_type: TimelineEventType::RoomPowerLevels,
|
||||
content: to_raw_value(&power_levels_content).expect("to_raw_value always works on serde_json::Value"),
|
||||
unsigned: None,
|
||||
state_key: Some("".to_owned()),
|
||||
state_key: Some(String::new()),
|
||||
redacts: None,
|
||||
},
|
||||
sender_user,
|
||||
|
@ -373,7 +373,7 @@ pub async fn create_room_route(body: Ruma<create_room::v3::Request>) -> Result<c
|
|||
})
|
||||
.expect("We checked that alias earlier, it must be fine"),
|
||||
unsigned: None,
|
||||
state_key: Some("".to_owned()),
|
||||
state_key: Some(String::new()),
|
||||
redacts: None,
|
||||
},
|
||||
sender_user,
|
||||
|
@ -399,7 +399,7 @@ pub async fn create_room_route(body: Ruma<create_room::v3::Request>) -> Result<c
|
|||
}))
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
state_key: Some("".to_owned()),
|
||||
state_key: Some(String::new()),
|
||||
redacts: None,
|
||||
},
|
||||
sender_user,
|
||||
|
@ -418,7 +418,7 @@ pub async fn create_room_route(body: Ruma<create_room::v3::Request>) -> Result<c
|
|||
content: to_raw_value(&RoomHistoryVisibilityEventContent::new(HistoryVisibility::Shared))
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
state_key: Some("".to_owned()),
|
||||
state_key: Some(String::new()),
|
||||
redacts: None,
|
||||
},
|
||||
sender_user,
|
||||
|
@ -440,7 +440,7 @@ pub async fn create_room_route(body: Ruma<create_room::v3::Request>) -> Result<c
|
|||
}))
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
state_key: Some("".to_owned()),
|
||||
state_key: Some(String::new()),
|
||||
redacts: None,
|
||||
},
|
||||
sender_user,
|
||||
|
@ -457,7 +457,7 @@ pub async fn create_room_route(body: Ruma<create_room::v3::Request>) -> Result<c
|
|||
})?;
|
||||
|
||||
// Implicit state key defaults to ""
|
||||
pdu_builder.state_key.get_or_insert_with(|| "".to_owned());
|
||||
pdu_builder.state_key.get_or_insert_with(String::new);
|
||||
|
||||
// Silently skip encryption events if they are not allowed
|
||||
if pdu_builder.event_type == TimelineEventType::RoomEncryption && !services().globals.allow_encryption() {
|
||||
|
@ -478,7 +478,7 @@ pub async fn create_room_route(body: Ruma<create_room::v3::Request>) -> Result<c
|
|||
content: to_raw_value(&RoomNameEventContent::new(name.clone()))
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
state_key: Some("".to_owned()),
|
||||
state_key: Some(String::new()),
|
||||
redacts: None,
|
||||
},
|
||||
sender_user,
|
||||
|
@ -500,7 +500,7 @@ pub async fn create_room_route(body: Ruma<create_room::v3::Request>) -> Result<c
|
|||
})
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
state_key: Some("".to_owned()),
|
||||
state_key: Some(String::new()),
|
||||
redacts: None,
|
||||
},
|
||||
sender_user,
|
||||
|
@ -564,7 +564,7 @@ pub async fn get_room_event_route(body: Ruma<get_room_event::v3::Request>) -> Re
|
|||
/// Lists all aliases of the room.
|
||||
///
|
||||
/// - Only users joined to the room are allowed to call this TODO: Allow any
|
||||
/// user to call it if history_visibility is world readable
|
||||
/// user to call it if `history_visibility` is world readable
|
||||
pub async fn get_room_aliases_route(body: Ruma<aliases::v3::Request>) -> Result<aliases::v3::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
|
||||
|
@ -623,7 +623,7 @@ pub async fn upgrade_room_route(body: Ruma<upgrade_room::v3::Request>) -> Result
|
|||
})
|
||||
.expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
state_key: Some("".to_owned()),
|
||||
state_key: Some(String::new()),
|
||||
redacts: None,
|
||||
},
|
||||
sender_user,
|
||||
|
@ -720,7 +720,7 @@ pub async fn upgrade_room_route(body: Ruma<upgrade_room::v3::Request>) -> Result
|
|||
event_type: TimelineEventType::RoomCreate,
|
||||
content: to_raw_value(&create_event_content).expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
state_key: Some("".to_owned()),
|
||||
state_key: Some(String::new()),
|
||||
redacts: None,
|
||||
},
|
||||
sender_user,
|
||||
|
@ -785,7 +785,7 @@ pub async fn upgrade_room_route(body: Ruma<upgrade_room::v3::Request>) -> Result
|
|||
event_type: event_type.to_string().into(),
|
||||
content: event_content,
|
||||
unsigned: None,
|
||||
state_key: Some("".to_owned()),
|
||||
state_key: Some(String::new()),
|
||||
redacts: None,
|
||||
},
|
||||
sender_user,
|
||||
|
@ -827,7 +827,7 @@ pub async fn upgrade_room_route(body: Ruma<upgrade_room::v3::Request>) -> Result
|
|||
event_type: TimelineEventType::RoomPowerLevels,
|
||||
content: to_raw_value(&power_levels_event_content).expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
state_key: Some("".to_owned()),
|
||||
state_key: Some(String::new()),
|
||||
redacts: None,
|
||||
},
|
||||
sender_user,
|
||||
|
|
|
@ -192,7 +192,7 @@ pub async fn login_route(body: Ruma<login::v3::Request>) -> Result<login::v3::Re
|
|||
|
||||
// send client well-known if specified so the client knows to reconfigure itself
|
||||
let client_discovery_info = DiscoveryInfo::new(HomeserverInfo::new(
|
||||
services().globals.well_known_client().to_owned().unwrap_or_else(|| "".to_owned()),
|
||||
services().globals.well_known_client().to_owned().unwrap_or_default(),
|
||||
));
|
||||
|
||||
info!("{} logged in", user_id);
|
||||
|
|
|
@ -20,7 +20,7 @@ use crate::{service::pdu::PduBuilder, services, Error, Result, Ruma, RumaRespons
|
|||
/// - The only requirement for the content is that it has to be valid json
|
||||
/// - Tries to send the event into the room, auth rules will determine if it is
|
||||
/// allowed
|
||||
/// - If event is new canonical_alias: Rejects if alias is incorrect
|
||||
/// - If event is new `canonical_alias`: Rejects if alias is incorrect
|
||||
pub async fn send_state_event_for_key_route(
|
||||
body: Ruma<send_state_event::v3::Request>,
|
||||
) -> Result<send_state_event::v3::Response> {
|
||||
|
@ -48,7 +48,7 @@ pub async fn send_state_event_for_key_route(
|
|||
/// - The only requirement for the content is that it has to be valid json
|
||||
/// - Tries to send the event into the room, auth rules will determine if it is
|
||||
/// allowed
|
||||
/// - If event is new canonical_alias: Rejects if alias is incorrect
|
||||
/// - If event is new `canonical_alias`: Rejects if alias is incorrect
|
||||
pub async fn send_state_event_for_empty_key_route(
|
||||
body: Ruma<send_state_event::v3::Request>,
|
||||
) -> Result<RumaResponse<send_state_event::v3::Response>> {
|
||||
|
|
|
@ -68,7 +68,7 @@ use crate::{service::rooms::timeline::PduCount, services, Error, PduEvent, Resul
|
|||
/// at the point of the invite
|
||||
///
|
||||
/// For left rooms:
|
||||
/// - If the user left after `since`: prev_batch token, empty state (TODO:
|
||||
/// - If the user left after `since`: `prev_batch` token, empty state (TODO:
|
||||
/// subset of the state at the point of the leave)
|
||||
///
|
||||
/// - Sync is handled in an async task, multiple requests from the same device
|
||||
|
|
|
@ -20,15 +20,16 @@ pub async fn update_tag_route(body: Ruma<create_tag::v3::Request>) -> Result<cre
|
|||
|
||||
let event = services().account_data.get(Some(&body.room_id), sender_user, RoomAccountDataEventType::Tag)?;
|
||||
|
||||
let mut tags_event = event
|
||||
.map(|e| serde_json::from_str(e.get()).map_err(|_| Error::bad_database("Invalid account data event in db.")))
|
||||
.unwrap_or_else(|| {
|
||||
let mut tags_event = event.map_or_else(
|
||||
|| {
|
||||
Ok(TagEvent {
|
||||
content: TagEventContent {
|
||||
tags: BTreeMap::new(),
|
||||
},
|
||||
})
|
||||
})?;
|
||||
},
|
||||
|e| serde_json::from_str(e.get()).map_err(|_| Error::bad_database("Invalid account data event in db.")),
|
||||
)?;
|
||||
|
||||
tags_event.content.tags.insert(body.tag.clone().into(), body.tag_info.clone());
|
||||
|
||||
|
@ -52,15 +53,16 @@ pub async fn delete_tag_route(body: Ruma<delete_tag::v3::Request>) -> Result<del
|
|||
|
||||
let event = services().account_data.get(Some(&body.room_id), sender_user, RoomAccountDataEventType::Tag)?;
|
||||
|
||||
let mut tags_event = event
|
||||
.map(|e| serde_json::from_str(e.get()).map_err(|_| Error::bad_database("Invalid account data event in db.")))
|
||||
.unwrap_or_else(|| {
|
||||
let mut tags_event = event.map_or_else(
|
||||
|| {
|
||||
Ok(TagEvent {
|
||||
content: TagEventContent {
|
||||
tags: BTreeMap::new(),
|
||||
},
|
||||
})
|
||||
})?;
|
||||
},
|
||||
|e| serde_json::from_str(e.get()).map_err(|_| Error::bad_database("Invalid account data event in db.")),
|
||||
)?;
|
||||
|
||||
tags_event.content.tags.remove(&body.tag.clone().into());
|
||||
|
||||
|
@ -84,15 +86,16 @@ pub async fn get_tags_route(body: Ruma<get_tags::v3::Request>) -> Result<get_tag
|
|||
|
||||
let event = services().account_data.get(Some(&body.room_id), sender_user, RoomAccountDataEventType::Tag)?;
|
||||
|
||||
let tags_event = event
|
||||
.map(|e| serde_json::from_str(e.get()).map_err(|_| Error::bad_database("Invalid account data event in db.")))
|
||||
.unwrap_or_else(|| {
|
||||
let tags_event = event.map_or_else(
|
||||
|| {
|
||||
Ok(TagEvent {
|
||||
content: TagEventContent {
|
||||
tags: BTreeMap::new(),
|
||||
},
|
||||
})
|
||||
})?;
|
||||
},
|
||||
|e| serde_json::from_str(e.get()).map_err(|_| Error::bad_database("Invalid account data event in db.")),
|
||||
)?;
|
||||
|
||||
Ok(get_tags::v3::Response {
|
||||
tags: tags_event.content.tags,
|
||||
|
|
|
@ -128,8 +128,7 @@ where
|
|||
(Some(user_id), None, None, true)
|
||||
}
|
||||
},
|
||||
AuthScheme::ServerSignatures => (None, None, None, true),
|
||||
AuthScheme::None => (None, None, None, true),
|
||||
AuthScheme::ServerSignatures | AuthScheme::None => (None, None, None, true),
|
||||
}
|
||||
} else {
|
||||
match metadata.authentication {
|
||||
|
@ -341,8 +340,8 @@ where
|
|||
sender_user,
|
||||
sender_device,
|
||||
sender_servername,
|
||||
from_appservice,
|
||||
json_body,
|
||||
from_appservice,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ use crate::{
|
|||
/// (colon-plus-port if it was specified).
|
||||
///
|
||||
/// Note: A `FedDest::Named` might contain an IP address in string form if there
|
||||
/// was no port specified to construct a SocketAddr with.
|
||||
/// was no port specified to construct a `SocketAddr` with.
|
||||
///
|
||||
/// # Examples:
|
||||
/// ```rust
|
||||
|
@ -73,9 +73,9 @@ use crate::{
|
|||
/// # fn main() -> Result<(), std::net::AddrParseError> {
|
||||
/// FedDest::Literal("198.51.100.3:8448".parse()?);
|
||||
/// FedDest::Literal("[2001:db8::4:5]:443".parse()?);
|
||||
/// FedDest::Named("matrix.example.org".to_owned(), "".to_owned());
|
||||
/// FedDest::Named("matrix.example.org".to_owned(), String::new());
|
||||
/// FedDest::Named("matrix.example.org".to_owned(), ":8448".to_owned());
|
||||
/// FedDest::Named("198.51.100.5".to_owned(), "".to_owned());
|
||||
/// FedDest::Named("198.51.100.5".to_owned(), String::new());
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
|
@ -309,24 +309,21 @@ where
|
|||
debug!(
|
||||
"Timed out sending request to {} at {}: {}",
|
||||
destination, actual_destination_str, e
|
||||
)
|
||||
);
|
||||
} else if e.is_connect() {
|
||||
debug!("Failed to connect to {} at {}: {}", destination, actual_destination_str, e);
|
||||
} else if e.is_redirect() {
|
||||
debug!(
|
||||
"Redirect loop sending request to {} at {}: {}\nFinal URL: {:?}",
|
||||
destination,
|
||||
actual_destination_str,
|
||||
e,
|
||||
e.url()
|
||||
);
|
||||
} else {
|
||||
if e.is_connect() {
|
||||
debug!("Failed to connect to {} at {}: {}", destination, actual_destination_str, e)
|
||||
} else {
|
||||
if e.is_redirect() {
|
||||
debug!(
|
||||
"Redirect loop sending request to {} at {}: {}\nFinal URL: {:?}",
|
||||
destination,
|
||||
actual_destination_str,
|
||||
e,
|
||||
e.url()
|
||||
)
|
||||
} else {
|
||||
info!("Could not send request to {} at {}: {}", destination, actual_destination_str, e);
|
||||
}
|
||||
}
|
||||
info!("Could not send request to {} at {}: {}", destination, actual_destination_str, e);
|
||||
}
|
||||
|
||||
Err(e.into())
|
||||
},
|
||||
}
|
||||
|
@ -350,7 +347,7 @@ fn add_port_to_hostname(destination_str: &str) -> FedDest {
|
|||
FedDest::Named(host.to_owned(), port.to_owned())
|
||||
}
|
||||
|
||||
/// Returns: actual_destination, host header
|
||||
/// Returns: `actual_destination`, host header
|
||||
/// Implemented according to the specification at <https://matrix.org/docs/spec/server_server/r0.1.4#resolving-server-names>
|
||||
/// Numbers in comments below refer to bullet points in linked section of
|
||||
/// specification
|
||||
|
@ -1690,9 +1687,9 @@ pub async fn get_profile_information_route(
|
|||
}
|
||||
|
||||
Ok(get_profile_information::v1::Response {
|
||||
blurhash,
|
||||
displayname,
|
||||
avatar_url,
|
||||
blurhash,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue