mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 05:26:59 +00:00
refactor: clean up clippy warnings
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -6474,6 +6474,7 @@ dependencies = [
|
||||
"once_cell",
|
||||
"rand 0.8.5",
|
||||
"redis-kiss",
|
||||
"revolt-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -101,9 +101,9 @@ pub async fn client(db: &'static Database, stream: TcpStream, addr: SocketAddr)
|
||||
|
||||
info!("User {addr:?} authenticated as @{}", user.username);
|
||||
|
||||
let _ = db
|
||||
.update_session_last_seen(&session_id, Timestamp::now_utc())
|
||||
.await;
|
||||
db.update_session_last_seen(&session_id, Timestamp::now_utc())
|
||||
.await
|
||||
.ok();
|
||||
|
||||
// Create local state.
|
||||
let mut state = State::from(user, session_id);
|
||||
|
||||
@@ -181,7 +181,7 @@ impl Server {
|
||||
}
|
||||
|
||||
/// Update server data
|
||||
pub async fn update<'a>(
|
||||
pub async fn update(
|
||||
&mut self,
|
||||
db: &Database,
|
||||
partial: PartialServer,
|
||||
|
||||
@@ -7,11 +7,5 @@ mod rocket;
|
||||
#[cfg(feature = "rocket-impl")]
|
||||
mod schema;
|
||||
|
||||
#[cfg(feature = "axum-impl")]
|
||||
pub use self::axum::*;
|
||||
#[cfg(feature = "rocket-impl")]
|
||||
pub use self::rocket::*;
|
||||
#[cfg(feature = "rocket-impl")]
|
||||
pub use self::schema::*;
|
||||
pub use model::*;
|
||||
pub use ops::*;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use ::mongodb::options::{Collation, CollationStrength, FindOneOptions, FindOptions};
|
||||
use authifier::models::Session;
|
||||
use futures::StreamExt;
|
||||
use iso8601_timestamp::{typenum as t, Timestamp, UtcOffset};
|
||||
use iso8601_timestamp::Timestamp;
|
||||
use revolt_result::Result;
|
||||
|
||||
use crate::DocumentId;
|
||||
|
||||
@@ -4,7 +4,7 @@ use once_cell::sync::Lazy;
|
||||
|
||||
use crate::events::client::EventV1;
|
||||
|
||||
static Q: Lazy<(Sender<AuthifierEvent>, Receiver<AuthifierEvent>)> = Lazy::new(|| unbounded());
|
||||
static Q: Lazy<(Sender<AuthifierEvent>, Receiver<AuthifierEvent>)> = Lazy::new(unbounded);
|
||||
|
||||
/// Get sender
|
||||
pub fn sender() -> Sender<AuthifierEvent> {
|
||||
|
||||
@@ -15,8 +15,7 @@ impl crate::Bot {
|
||||
avatar: user.avatar.map(|x| x.id).unwrap_or_default(),
|
||||
description: user
|
||||
.profile
|
||||
.map(|profile| profile.content)
|
||||
.flatten()
|
||||
.and_then(|profile| profile.content)
|
||||
.unwrap_or_default(),
|
||||
}
|
||||
}
|
||||
@@ -1114,7 +1113,7 @@ impl crate::User {
|
||||
}
|
||||
|
||||
/// Convert user object into user model without presence information
|
||||
pub async fn into_known_static<'a>(self, is_online: bool) -> User {
|
||||
pub async fn into_known_static(self, is_online: bool) -> User {
|
||||
let badges = self.get_badges().await;
|
||||
|
||||
User {
|
||||
|
||||
@@ -54,7 +54,7 @@ use revolt_rocket_okapi::{
|
||||
use schemars::schema::{InstanceType, SchemaObject, SingleOrVec};
|
||||
|
||||
#[cfg(feature = "rocket-impl")]
|
||||
impl<'r> OpenApiFromRequest<'r> for IdempotencyKey {
|
||||
impl OpenApiFromRequest<'_> for IdempotencyKey {
|
||||
fn from_request_input(
|
||||
_gen: &mut OpenApiGenerator,
|
||||
_name: String,
|
||||
|
||||
@@ -104,7 +104,7 @@ impl PermissionQuery for DatabasePermissionQuery<'_> {
|
||||
.unwrap_or_default();
|
||||
|
||||
self.cached_mutual_connection = Some(value);
|
||||
matches!(value, true)
|
||||
value
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
||||
@@ -310,14 +310,14 @@ impl Channel {
|
||||
/// This returns a Result because the recipient name can't be determined here without a db call,
|
||||
/// which can't be done since this is models, which can't reference the database crate.
|
||||
///
|
||||
/// If it returns Err, you need to fetch the name from the db.
|
||||
pub fn name(&self) -> Result<&str, ()> {
|
||||
/// If it returns None, you need to fetch the name from the db.
|
||||
pub fn name(&self) -> Option<&str> {
|
||||
match self {
|
||||
Channel::DirectMessage { .. } => Err(()),
|
||||
Channel::SavedMessages { .. } => Ok("Saved Messages"),
|
||||
Channel::DirectMessage { .. } => None,
|
||||
Channel::SavedMessages { .. } => Some("Saved Messages"),
|
||||
Channel::TextChannel { name, .. }
|
||||
| Channel::Group { name, .. }
|
||||
| Channel::VoiceChannel { name, .. } => Ok(name),
|
||||
| Channel::VoiceChannel { name, .. } => Some(name),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,9 @@ redis-is-patched = []
|
||||
# Async
|
||||
async-std = { version = "1.8.0", features = ["attributes"] }
|
||||
|
||||
# Config for loading Redis URI
|
||||
revolt-config = { version = "0.8.7", path = "../config" }
|
||||
|
||||
[dependencies]
|
||||
# Utility
|
||||
log = "0.4.17"
|
||||
|
||||
@@ -197,6 +197,8 @@ mod tests {
|
||||
|
||||
#[async_std::test]
|
||||
async fn it_works() {
|
||||
revolt_config::config().await;
|
||||
|
||||
// Clear the region before we start the tests:
|
||||
clear_region(None).await;
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ pub async fn fetch_public_bot(
|
||||
target: Reference,
|
||||
) -> Result<Json<PublicBot>> {
|
||||
let bot = db.fetch_bot(&target.id).await?;
|
||||
if !bot.public && user.map_or(true, |x| x.id != bot.owner) {
|
||||
if !bot.public && user.is_none_or(|x| x.id != bot.owner) {
|
||||
return Err(create_error!(NotFound));
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,8 @@ pub async fn message_send(
|
||||
// Create model user / members
|
||||
let model_user = user
|
||||
.clone()
|
||||
.into_known_static(revolt_presence::is_online(&user.id).await).await;
|
||||
.into_known_static(revolt_presence::is_online(&user.id).await)
|
||||
.await;
|
||||
|
||||
let model_member: Option<v0::Member> = query
|
||||
.member_ref()
|
||||
@@ -491,7 +492,7 @@ mod test {
|
||||
let (_, _, other_user) = harness.new_user().await;
|
||||
let (server, _) = harness.new_server(&user).await;
|
||||
let channel = harness.new_channel(&server).await;
|
||||
let (role_id, mut role) = harness
|
||||
let (role_id, _role) = harness
|
||||
.new_role(
|
||||
&server,
|
||||
1,
|
||||
|
||||
@@ -41,7 +41,7 @@ pub async fn call(
|
||||
// - If not, create it.
|
||||
let client = reqwest::Client::new();
|
||||
let result = client
|
||||
.get(&format!(
|
||||
.get(format!(
|
||||
"{}/room/{}",
|
||||
config.hosts.voso_legacy,
|
||||
channel.id()
|
||||
@@ -59,7 +59,7 @@ pub async fn call(
|
||||
reqwest::StatusCode::OK => (),
|
||||
reqwest::StatusCode::NOT_FOUND => {
|
||||
if (client
|
||||
.post(&format!(
|
||||
.post(format!(
|
||||
"{}/room/{}",
|
||||
config.hosts.voso_legacy,
|
||||
channel.id()
|
||||
@@ -81,7 +81,7 @@ pub async fn call(
|
||||
|
||||
// Then create a user for the room.
|
||||
if let Ok(response) = client
|
||||
.post(&format!(
|
||||
.post(format!(
|
||||
"{}/room/{}/user/{}",
|
||||
config.hosts.voso_legacy,
|
||||
channel.id(),
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
use revolt_database::{events::client::EventV1, Database, Report, Snapshot, SnapshotContent, User};
|
||||
use revolt_models::v0::{ReportStatus, ReportedContent};
|
||||
use revolt_result::{create_error, Result};
|
||||
use serde::Deserialize;
|
||||
use ulid::Ulid;
|
||||
use validator::Validate;
|
||||
use revolt_database::{Database, User};
|
||||
use revolt_result::Result;
|
||||
|
||||
use rocket::{serde::json::Json, State};
|
||||
use rocket::State;
|
||||
|
||||
/// # Acknowledge Policy Changes
|
||||
///
|
||||
|
||||
@@ -136,7 +136,6 @@ pub async fn root() -> Result<Json<RevoltConfig>> {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(feature = "FIXME: THIS TEST CAUSES cargo test TO SEG FAULT, I HAVE NO CLUE HOW")]
|
||||
mod test {
|
||||
use crate::rocket;
|
||||
use rocket::http::Status;
|
||||
|
||||
@@ -36,11 +36,11 @@ pub async fn webhook_execute(
|
||||
let permissions: PermissionValue = webhook.permissions.into();
|
||||
permissions.throw_if_lacking_channel_permission(ChannelPermission::SendMessage)?;
|
||||
|
||||
if data.attachments.as_ref().map_or(false, |v| !v.is_empty()) {
|
||||
if data.attachments.as_ref().is_some_and(|v| !v.is_empty()) {
|
||||
permissions.throw_if_lacking_channel_permission(ChannelPermission::UploadFiles)?;
|
||||
}
|
||||
|
||||
if data.embeds.as_ref().map_or(false, |v| !v.is_empty()) {
|
||||
if data.embeds.as_ref().is_some_and(|v| !v.is_empty()) {
|
||||
permissions.throw_if_lacking_channel_permission(ChannelPermission::SendEmbeds)?;
|
||||
}
|
||||
|
||||
|
||||
@@ -621,7 +621,7 @@ pub struct Event {
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct EventHeader<'r>(pub &'r str);
|
||||
|
||||
impl<'r> std::ops::Deref for EventHeader<'r> {
|
||||
impl std::ops::Deref for EventHeader<'_> {
|
||||
type Target = str;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
||||
@@ -109,8 +109,6 @@ fn resolve_bucket<'r>(request: &'r rocket::Request<'_>) -> (&'r str, Option<&'r
|
||||
};
|
||||
|
||||
if let Some(segment) = segment {
|
||||
let resource = resource;
|
||||
|
||||
let method = request.method();
|
||||
match (segment, resource, method) {
|
||||
("users", target, Method::Patch) => ("user_edit", target),
|
||||
@@ -254,7 +252,7 @@ impl<'r> FromRequest<'r> for Ratelimiter {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> OpenApiFromRequest<'r> for Ratelimiter {
|
||||
impl OpenApiFromRequest<'_> for Ratelimiter {
|
||||
fn from_request_input(
|
||||
_gen: &mut OpenApiGenerator,
|
||||
_name: String,
|
||||
|
||||
@@ -198,10 +198,7 @@ impl TestHarness {
|
||||
(channel.clone(), member, message)
|
||||
}
|
||||
|
||||
pub async fn with_session<'c>(
|
||||
session: Session,
|
||||
request: LocalRequest<'c>,
|
||||
) -> LocalResponse<'c> {
|
||||
pub async fn with_session(session: Session, request: LocalRequest<'_>) -> LocalResponse<'_> {
|
||||
request
|
||||
.header(Header::new("x-session-token", session.token.to_string()))
|
||||
.dispatch()
|
||||
|
||||
@@ -327,7 +327,7 @@ pub async fn populate_special(original_url: String, metadata: &mut WebsiteMetada
|
||||
Special::Twitch { .. } => metadata.colour = Some("#7B68EE".to_string()),
|
||||
Special::Lightspeed { .. } => metadata.colour = Some("#7445D9".to_string()),
|
||||
Special::Spotify { .. } => metadata.colour = Some("#1ABC9C".to_string()),
|
||||
Special::Soundcloud { .. } => metadata.colour = Some("#FF7F50".to_string()),
|
||||
Special::Soundcloud => metadata.colour = Some("#FF7F50".to_string()),
|
||||
Special::AppleMusic { .. } => metadata.colour = Some("#FA233B".to_string()),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user