remove various unnecessary qualifications
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
aedb5966fe
commit
7c1624931d
17 changed files with 39 additions and 42 deletions
|
@ -28,7 +28,7 @@ where
|
|||
Error::BadServerResponse("Invalid destination")
|
||||
})
|
||||
.unwrap()
|
||||
.map(bytes::BytesMut::freeze);
|
||||
.map(BytesMut::freeze);
|
||||
|
||||
let mut parts = http_request.uri().clone().into_parts();
|
||||
let old_path_and_query = parts.path_and_query.unwrap().as_str().to_owned();
|
||||
|
|
|
@ -66,7 +66,7 @@ pub async fn join_room_by_id_route(body: Ruma<join_room_by_id::v3::Request>) ->
|
|||
.iter()
|
||||
.filter_map(|event| serde_json::from_str(event.json().get()).ok())
|
||||
.filter_map(|event: serde_json::Value| event.get("sender").cloned())
|
||||
.filter_map(|sender| sender.as_str().map(std::borrow::ToOwned::to_owned))
|
||||
.filter_map(|sender| sender.as_str().map(ToOwned::to_owned))
|
||||
.filter_map(|sender| UserId::parse(sender).ok())
|
||||
.map(|user| user.server_name().to_owned()),
|
||||
);
|
||||
|
@ -123,7 +123,7 @@ pub async fn join_room_by_id_or_alias_route(
|
|||
.iter()
|
||||
.filter_map(|event| serde_json::from_str(event.json().get()).ok())
|
||||
.filter_map(|event: serde_json::Value| event.get("sender").cloned())
|
||||
.filter_map(|sender| sender.as_str().map(std::borrow::ToOwned::to_owned))
|
||||
.filter_map(|sender| sender.as_str().map(ToOwned::to_owned))
|
||||
.filter_map(|sender| UserId::parse(sender).ok())
|
||||
.map(|user| user.server_name().to_owned()),
|
||||
);
|
||||
|
@ -1382,7 +1382,7 @@ async fn remote_leave_room(user_id: &UserId, room_id: &RoomId) -> Result<()> {
|
|||
.iter()
|
||||
.filter_map(|event| serde_json::from_str(event.json().get()).ok())
|
||||
.filter_map(|event: serde_json::Value| event.get("sender").cloned())
|
||||
.filter_map(|sender| sender.as_str().map(std::borrow::ToOwned::to_owned))
|
||||
.filter_map(|sender| sender.as_str().map(ToOwned::to_owned))
|
||||
.filter_map(|sender| UserId::parse(sender).ok())
|
||||
.map(|user| user.server_name().to_owned())
|
||||
.collect();
|
||||
|
|
|
@ -262,7 +262,7 @@ where
|
|||
}
|
||||
};
|
||||
|
||||
let mut http_request = http::Request::builder().uri(parts.uri).method(parts.method);
|
||||
let mut http_request = Request::builder().uri(parts.uri).method(parts.method);
|
||||
*http_request.headers_mut().unwrap() = parts.headers;
|
||||
|
||||
if let Some(CanonicalJsonValue::Object(json_body)) = &mut json_body {
|
||||
|
|
|
@ -19,7 +19,7 @@ impl Watchers {
|
|||
let mut rx = match self.watchers.write().unwrap().entry(prefix.to_vec()) {
|
||||
hash_map::Entry::Occupied(o) => o.get().1.clone(),
|
||||
hash_map::Entry::Vacant(v) => {
|
||||
let (tx, rx) = tokio::sync::watch::channel(());
|
||||
let (tx, rx) = watch::channel(());
|
||||
v.insert((tx, rx.clone()));
|
||||
rx
|
||||
},
|
||||
|
|
|
@ -18,7 +18,7 @@ impl service::account_data::Data for KeyValueDatabase {
|
|||
&self, room_id: Option<&RoomId>, user_id: &UserId, event_type: RoomAccountDataEventType,
|
||||
data: &serde_json::Value,
|
||||
) -> Result<()> {
|
||||
let mut prefix = room_id.map(std::string::ToString::to_string).unwrap_or_default().as_bytes().to_vec();
|
||||
let mut prefix = room_id.map(ToString::to_string).unwrap_or_default().as_bytes().to_vec();
|
||||
prefix.push(0xFF);
|
||||
prefix.extend_from_slice(user_id.as_bytes());
|
||||
prefix.push(0xFF);
|
||||
|
@ -60,7 +60,7 @@ impl service::account_data::Data for KeyValueDatabase {
|
|||
fn get(
|
||||
&self, room_id: Option<&RoomId>, user_id: &UserId, kind: RoomAccountDataEventType,
|
||||
) -> Result<Option<Box<serde_json::value::RawValue>>> {
|
||||
let mut key = room_id.map(std::string::ToString::to_string).unwrap_or_default().as_bytes().to_vec();
|
||||
let mut key = room_id.map(ToString::to_string).unwrap_or_default().as_bytes().to_vec();
|
||||
key.push(0xFF);
|
||||
key.extend_from_slice(user_id.as_bytes());
|
||||
key.push(0xFF);
|
||||
|
@ -81,7 +81,7 @@ impl service::account_data::Data for KeyValueDatabase {
|
|||
) -> Result<HashMap<RoomAccountDataEventType, Raw<AnyEphemeralRoomEvent>>> {
|
||||
let mut userdata = HashMap::new();
|
||||
|
||||
let mut prefix = room_id.map(std::string::ToString::to_string).unwrap_or_default().as_bytes().to_vec();
|
||||
let mut prefix = room_id.map(ToString::to_string).unwrap_or_default().as_bytes().to_vec();
|
||||
prefix.push(0xFF);
|
||||
prefix.extend_from_slice(user_id.as_bytes());
|
||||
prefix.push(0xFF);
|
||||
|
|
|
@ -62,7 +62,7 @@ impl service::globals::Data for KeyValueDatabase {
|
|||
futures.push(self.userroomid_highlightcount.watch_prefix(&userid_prefix));
|
||||
|
||||
// Events for rooms we are in
|
||||
for room_id in services().rooms.state_cache.rooms_joined(user_id).filter_map(std::result::Result::ok) {
|
||||
for room_id in services().rooms.state_cache.rooms_joined(user_id).filter_map(Result::ok) {
|
||||
let short_roomid = services()
|
||||
.rooms
|
||||
.short
|
||||
|
|
|
@ -122,11 +122,11 @@ impl service::media::Data for KeyValueDatabase {
|
|||
let mut value = Vec::<u8>::new();
|
||||
value.extend_from_slice(×tamp.as_secs().to_be_bytes());
|
||||
value.push(0xFF);
|
||||
value.extend_from_slice(data.title.as_ref().map(std::string::String::as_bytes).unwrap_or_default());
|
||||
value.extend_from_slice(data.title.as_ref().map(String::as_bytes).unwrap_or_default());
|
||||
value.push(0xFF);
|
||||
value.extend_from_slice(data.description.as_ref().map(std::string::String::as_bytes).unwrap_or_default());
|
||||
value.extend_from_slice(data.description.as_ref().map(String::as_bytes).unwrap_or_default());
|
||||
value.push(0xFF);
|
||||
value.extend_from_slice(data.image.as_ref().map(std::string::String::as_bytes).unwrap_or_default());
|
||||
value.extend_from_slice(data.image.as_ref().map(String::as_bytes).unwrap_or_default());
|
||||
value.push(0xFF);
|
||||
value.extend_from_slice(&data.image_size.unwrap_or(0).to_be_bytes());
|
||||
value.push(0xFF);
|
||||
|
|
|
@ -22,7 +22,7 @@ impl service::uiaa::Data for KeyValueDatabase {
|
|||
.read()
|
||||
.unwrap()
|
||||
.get(&(user_id.to_owned(), device_id.to_owned(), session.to_owned()))
|
||||
.map(std::borrow::ToOwned::to_owned)
|
||||
.map(ToOwned::to_owned)
|
||||
}
|
||||
|
||||
fn update_uiaa_session(
|
||||
|
|
|
@ -229,7 +229,7 @@ impl KeyValueDatabase {
|
|||
|
||||
if !Path::new(&config.database_path).exists() {
|
||||
debug!("Database path does not exist, assuming this is a new setup and creating it");
|
||||
std::fs::create_dir_all(&config.database_path).map_err(|e| {
|
||||
fs::create_dir_all(&config.database_path).map_err(|e| {
|
||||
error!("Failed to create database path: {e}");
|
||||
Error::BadConfig(
|
||||
"Database folder doesn't exists and couldn't be created (e.g. due to missing permissions). Please \
|
||||
|
@ -864,7 +864,7 @@ impl KeyValueDatabase {
|
|||
|
||||
let mut account_data = serde_json::from_str::<PushRulesEvent>(raw_rules_list.get()).unwrap();
|
||||
|
||||
let user_default_rules = ruma::push::Ruleset::server_default(&user);
|
||||
let user_default_rules = Ruleset::server_default(&user);
|
||||
account_data.content.global.update_with_server_default(user_default_rules);
|
||||
|
||||
services().account_data.update(
|
||||
|
|
|
@ -473,7 +473,7 @@ async fn run_server() -> io::Result<()> {
|
|||
}
|
||||
|
||||
async fn spawn_task<B: Send + 'static>(
|
||||
req: axum::http::Request<B>, next: axum::middleware::Next<B>,
|
||||
req: http::Request<B>, next: axum::middleware::Next<B>,
|
||||
) -> std::result::Result<axum::response::Response, StatusCode> {
|
||||
if services().globals.shutdown.load(atomic::Ordering::Relaxed) {
|
||||
return Err(StatusCode::SERVICE_UNAVAILABLE);
|
||||
|
@ -482,12 +482,12 @@ async fn spawn_task<B: Send + 'static>(
|
|||
}
|
||||
|
||||
async fn unrecognized_method<B: Send + 'static>(
|
||||
req: axum::http::Request<B>, next: axum::middleware::Next<B>,
|
||||
req: http::Request<B>, next: axum::middleware::Next<B>,
|
||||
) -> std::result::Result<axum::response::Response, StatusCode> {
|
||||
let method = req.method().clone();
|
||||
let uri = req.uri().clone();
|
||||
let inner = next.run(req).await;
|
||||
if inner.status() == axum::http::StatusCode::METHOD_NOT_ALLOWED {
|
||||
if inner.status() == StatusCode::METHOD_NOT_ALLOWED {
|
||||
warn!("Method not allowed: {method} {uri}");
|
||||
return Ok(RumaResponse(UiaaResponse::MatrixError(RumaError {
|
||||
body: ErrorBody::Standard {
|
||||
|
|
|
@ -609,9 +609,7 @@ impl Service {
|
|||
Err(_) => RoomMessageEventContent::text_plain("Failed to get appservice."),
|
||||
},
|
||||
AppserviceCommand::List => {
|
||||
if let Ok(appservices) =
|
||||
services().appservice.iter_ids().map(std::iter::Iterator::collect::<Vec<_>>)
|
||||
{
|
||||
if let Ok(appservices) = services().appservice.iter_ids().map(Iterator::collect::<Vec<_>>) {
|
||||
let count = appservices.len();
|
||||
let output = format!(
|
||||
"Appservices ({}): {}",
|
||||
|
|
|
@ -469,7 +469,7 @@ impl Service<'_> {
|
|||
if self.unix_socket_path().is_some() {
|
||||
match &self.unix_socket_path() {
|
||||
Some(path) => {
|
||||
std::fs::remove_file(path).unwrap();
|
||||
fs::remove_file(path).unwrap();
|
||||
},
|
||||
None => error!(
|
||||
"Unable to remove socket file at {:?} during shutdown.",
|
||||
|
|
|
@ -75,7 +75,7 @@ impl Service {
|
|||
debug!("Got local file path: {:?}", file_path);
|
||||
|
||||
debug!("Deleting local file {:?} from filesystem, original MXC: {}", file_path, mxc);
|
||||
tokio::fs::remove_file(file_path).await?;
|
||||
fs::remove_file(file_path).await?;
|
||||
|
||||
debug!("Deleting MXC {mxc} from database");
|
||||
self.db.delete_file_mxc(mxc.clone())?;
|
||||
|
@ -318,20 +318,20 @@ impl Service {
|
|||
u64::from(original_width) * u64::from(height) / u64::from(original_height)
|
||||
};
|
||||
if use_width {
|
||||
if intermediate <= u64::from(::std::u32::MAX) {
|
||||
if intermediate <= u64::from(std::u32::MAX) {
|
||||
(width, intermediate as u32)
|
||||
} else {
|
||||
(
|
||||
(u64::from(width) * u64::from(::std::u32::MAX) / intermediate) as u32,
|
||||
::std::u32::MAX,
|
||||
(u64::from(width) * u64::from(std::u32::MAX) / intermediate) as u32,
|
||||
std::u32::MAX,
|
||||
)
|
||||
}
|
||||
} else if intermediate <= u64::from(::std::u32::MAX) {
|
||||
} else if intermediate <= u64::from(std::u32::MAX) {
|
||||
(intermediate as u32, height)
|
||||
} else {
|
||||
(
|
||||
::std::u32::MAX,
|
||||
(u64::from(height) * u64::from(::std::u32::MAX) / intermediate) as u32,
|
||||
std::u32::MAX,
|
||||
(u64::from(height) * u64::from(std::u32::MAX) / intermediate) as u32,
|
||||
)
|
||||
}
|
||||
};
|
||||
|
|
|
@ -55,7 +55,7 @@ impl Service {
|
|||
warn!("Failed to find destination {}: {}", destination, e);
|
||||
Error::BadServerResponse("Invalid destination")
|
||||
})?
|
||||
.map(bytes::BytesMut::freeze);
|
||||
.map(BytesMut::freeze);
|
||||
|
||||
let reqwest_request = reqwest::Request::try_from(http_request)?;
|
||||
|
||||
|
|
|
@ -367,7 +367,7 @@ impl Service {
|
|||
|
||||
// The original create event must be in the auth events
|
||||
if !matches!(
|
||||
auth_events.get(&(StateEventType::RoomCreate, "".to_owned())).map(std::convert::AsRef::as_ref),
|
||||
auth_events.get(&(StateEventType::RoomCreate, "".to_owned())).map(AsRef::as_ref),
|
||||
Some(_) | None
|
||||
) {
|
||||
return Err(Error::BadRequest(
|
||||
|
@ -623,8 +623,7 @@ impl Service {
|
|||
.get_shortstatekey(&StateEventType::RoomCreate, "")?
|
||||
.expect("Room exists");
|
||||
|
||||
if state.get(&create_shortstatekey).map(std::convert::AsRef::as_ref) != Some(&create_event.event_id)
|
||||
{
|
||||
if state.get(&create_shortstatekey).map(AsRef::as_ref) != Some(&create_event.event_id) {
|
||||
return Err(Error::bad_database("Incoming event refers to wrong create event."));
|
||||
}
|
||||
|
||||
|
|
|
@ -57,11 +57,11 @@ impl Service {
|
|||
let mut results = Vec::new();
|
||||
|
||||
while let Some(current_room) = {
|
||||
while stack.last().map_or(false, std::vec::Vec::is_empty) {
|
||||
while stack.last().map_or(false, Vec::is_empty) {
|
||||
stack.pop();
|
||||
}
|
||||
if !stack.is_empty() {
|
||||
stack.last_mut().and_then(std::vec::Vec::pop)
|
||||
stack.last_mut().and_then(Vec::pop)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -402,7 +402,7 @@ impl Service {
|
|||
match join_rule {
|
||||
JoinRule::Restricted(r) => {
|
||||
for rule in &r.allow {
|
||||
if let join_rules::AllowRule::RoomMembership(rm) = rule {
|
||||
if let AllowRule::RoomMembership(rm) = rule {
|
||||
if let Ok(true) = services().rooms.state_cache.is_joined(sender_user, &rm.room_id) {
|
||||
return Ok(true);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ pub(crate) fn millis_since_unix_epoch() -> u64 {
|
|||
}
|
||||
|
||||
pub(crate) fn increment(old: Option<&[u8]>) -> Option<Vec<u8>> {
|
||||
let number = match old.map(std::convert::TryInto::try_into) {
|
||||
let number = match old.map(TryInto::try_into) {
|
||||
Some(Ok(bytes)) => {
|
||||
let number = u64::from_be_bytes(bytes);
|
||||
number + 1
|
||||
|
@ -80,7 +80,7 @@ pub(crate) fn common_elements(
|
|||
mut iterators: impl Iterator<Item = impl Iterator<Item = Vec<u8>>>, check_order: impl Fn(&[u8], &[u8]) -> Ordering,
|
||||
) -> Option<impl Iterator<Item = Vec<u8>>> {
|
||||
let first_iterator = iterators.next()?;
|
||||
let mut other_iterators = iterators.map(std::iter::Iterator::peekable).collect::<Vec<_>>();
|
||||
let mut other_iterators = iterators.map(Iterator::peekable).collect::<Vec<_>>();
|
||||
|
||||
Some(first_iterator.filter(move |target| {
|
||||
other_iterators.iter_mut().all(|it| {
|
||||
|
@ -112,14 +112,14 @@ pub(crate) fn to_canonical_object<T: serde::Serialize>(value: T) -> Result<Canon
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn deserialize_from_str<'de, D: serde::de::Deserializer<'de>, T: FromStr<Err = E>, E: std::fmt::Display>(
|
||||
pub(crate) fn deserialize_from_str<'de, D: serde::de::Deserializer<'de>, T: FromStr<Err = E>, E: fmt::Display>(
|
||||
deserializer: D,
|
||||
) -> Result<T, D::Error> {
|
||||
struct Visitor<T: FromStr<Err = E>, E>(std::marker::PhantomData<T>);
|
||||
impl<T: FromStr<Err = Err>, Err: std::fmt::Display> serde::de::Visitor<'_> for Visitor<T, Err> {
|
||||
impl<T: FromStr<Err = Err>, Err: fmt::Display> serde::de::Visitor<'_> for Visitor<T, Err> {
|
||||
type Value = T;
|
||||
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(formatter, "a parsable string")
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue