fix: resolve all clippy warnings — redundant closures, dead code, collapsible_if, needless borrow
Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Failing after 9m25s
test / unit (pull_request) Successful in 16m57s
test / integration (pull_request) Failing after 17m29s
Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Failing after 9m25s
test / unit (pull_request) Successful in 16m57s
test / integration (pull_request) Failing after 17m29s
This commit is contained in:
13
.githooks/pre-commit
Executable file
13
.githooks/pre-commit
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
echo "→ cargo fmt"
|
||||
if ! cargo fmt --all -- --check; then
|
||||
echo " run 'cargo fmt --all' to fix formatting"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "→ cargo clippy"
|
||||
if ! cargo clippy --workspace -- -D warnings; then
|
||||
exit 1
|
||||
fi
|
||||
@@ -237,14 +237,13 @@ impl Activity for UndoActivity {
|
||||
|
||||
match obj_type {
|
||||
"Follow" => {
|
||||
if let Some(obj_url) = self.object.get("object").and_then(|o| o.as_str()) {
|
||||
if let Ok(url) = Url::parse(obj_url) {
|
||||
if let Some(user_id) = crate::urls::extract_user_id_from_url(&url) {
|
||||
data.federation_repo
|
||||
.remove_follower(user_id, self.actor.inner().as_str())
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
if let Some(obj_url) = self.object.get("object").and_then(|o| o.as_str())
|
||||
&& let Ok(url) = Url::parse(obj_url)
|
||||
&& let Some(user_id) = crate::urls::extract_user_id_from_url(&url)
|
||||
{
|
||||
data.federation_repo
|
||||
.remove_follower(user_id, self.actor.inner().as_str())
|
||||
.await?;
|
||||
}
|
||||
data.object_handler
|
||||
.on_actor_removed(self.actor.inner())
|
||||
@@ -260,14 +259,14 @@ impl Activity for UndoActivity {
|
||||
.and_then(|id| id.as_str())
|
||||
.or_else(|| self.object.get("id").and_then(|id| id.as_str()));
|
||||
|
||||
if let Some(ap_id_str) = ap_id_str {
|
||||
if let Ok(ap_id) = Url::parse(ap_id_str) {
|
||||
data.object_handler
|
||||
.on_delete(&ap_id, self.actor.inner())
|
||||
.await
|
||||
.map_err(|e| Error::from(anyhow::anyhow!(e)))?;
|
||||
tracing::info!(ap_id = %ap_id_str, "undo Add (watchlist remove)");
|
||||
}
|
||||
if let Some(ap_id_str) = ap_id_str
|
||||
&& let Ok(ap_id) = Url::parse(ap_id_str)
|
||||
{
|
||||
data.object_handler
|
||||
.on_delete(&ap_id, self.actor.inner())
|
||||
.await
|
||||
.map_err(|e| Error::from(anyhow::anyhow!(e)))?;
|
||||
tracing::info!(ap_id = %ap_id_str, "undo Add (watchlist remove)");
|
||||
}
|
||||
}
|
||||
other => {
|
||||
|
||||
@@ -14,6 +14,7 @@ pub struct FederationData {
|
||||
pub(crate) domain: String,
|
||||
pub(crate) allow_registration: bool,
|
||||
pub(crate) software_name: String,
|
||||
#[allow(dead_code)]
|
||||
pub(crate) event_publisher: Option<Arc<dyn EventPublisher>>,
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ pub struct ActivityPubService {
|
||||
}
|
||||
|
||||
impl ActivityPubService {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub async fn new(
|
||||
repo: Arc<dyn FederationRepository>,
|
||||
user_repo: Arc<dyn ApUserRepository>,
|
||||
@@ -748,7 +749,7 @@ impl ActivityPubService {
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||
// Wrap with @context so Mastodon's JSON-LD processor can resolve field names.
|
||||
let person_json = serde_json::to_value(&WithContext::new_default(person))?;
|
||||
let person_json = serde_json::to_value(WithContext::new_default(person))?;
|
||||
|
||||
let update_id = Url::parse(&format!(
|
||||
"{}/activities/update/{}",
|
||||
|
||||
@@ -22,6 +22,7 @@ pub fn actor_url(base_url: &str, user_id: uuid::Uuid) -> Url {
|
||||
}
|
||||
|
||||
/// Extract the username segment from a /users/:username URL.
|
||||
#[allow(dead_code)]
|
||||
pub fn extract_username_from_url(url: &Url) -> Option<String> {
|
||||
url.path()
|
||||
.strip_prefix("/users/")
|
||||
|
||||
@@ -26,6 +26,7 @@ pub struct ThoughtNote {
|
||||
}
|
||||
|
||||
impl ThoughtNote {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new_public(
|
||||
id: Url,
|
||||
actor_url: Url,
|
||||
|
||||
@@ -81,7 +81,7 @@ fn row_to_entry(r: FeedRow) -> FeedEntry {
|
||||
in_reply_to_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
|
||||
in_reply_to_url: r.in_reply_to_url,
|
||||
ap_id: r.t_ap_id,
|
||||
visibility: Visibility::from_str(&r.visibility),
|
||||
visibility: Visibility::from_db_str(&r.visibility),
|
||||
content_warning: r.content_warning,
|
||||
sensitive: r.sensitive,
|
||||
local: r.t_local,
|
||||
|
||||
@@ -95,7 +95,7 @@ fn row_to_entry(r: FeedRow) -> FeedEntry {
|
||||
in_reply_to_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
|
||||
in_reply_to_url: r.in_reply_to_url,
|
||||
ap_id: r.t_ap_id,
|
||||
visibility: Visibility::from_str(&r.visibility),
|
||||
visibility: Visibility::from_db_str(&r.visibility),
|
||||
content_warning: r.content_warning,
|
||||
sensitive: r.sensitive,
|
||||
local: r.t_local,
|
||||
|
||||
@@ -77,7 +77,7 @@ impl FollowRepository for PgFollowRepository {
|
||||
.map(|o| o.map(|r| Follow {
|
||||
follower_id: UserId::from_uuid(r.follower_id),
|
||||
following_id: UserId::from_uuid(r.following_id),
|
||||
state: FollowState::from_str(&r.state),
|
||||
state: FollowState::from_db_str(&r.state),
|
||||
ap_id: r.ap_id,
|
||||
created_at: r.created_at,
|
||||
}))
|
||||
|
||||
@@ -62,7 +62,7 @@ impl NotificationRepository for PgNotificationRepository {
|
||||
.map(|r| Notification {
|
||||
id: NotificationId::from_uuid(r.id),
|
||||
user_id: UserId::from_uuid(r.user_id),
|
||||
notification_type: NotificationType::from_str(&r.r#type),
|
||||
notification_type: NotificationType::from_db_str(&r.r#type),
|
||||
from_user_id: r.from_user_id.map(UserId::from_uuid),
|
||||
thought_id: r.thought_id.map(ThoughtId::from_uuid),
|
||||
read: r.read,
|
||||
|
||||
@@ -45,7 +45,7 @@ impl From<ThoughtRow> for Thought {
|
||||
in_reply_to_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
|
||||
in_reply_to_url: r.in_reply_to_url,
|
||||
ap_id: r.ap_id,
|
||||
visibility: Visibility::from_str(&r.visibility),
|
||||
visibility: Visibility::from_db_str(&r.visibility),
|
||||
content_warning: r.content_warning,
|
||||
sensitive: r.sensitive,
|
||||
local: r.local,
|
||||
|
||||
@@ -35,7 +35,7 @@ pub async fn create_thought(
|
||||
let visibility = input
|
||||
.visibility
|
||||
.as_deref()
|
||||
.map(Visibility::from_str)
|
||||
.map(Visibility::from_db_str)
|
||||
.unwrap_or(Visibility::Public);
|
||||
let thought = Thought::new_local(
|
||||
ThoughtId::new(),
|
||||
|
||||
@@ -10,7 +10,7 @@ pub enum NotificationType {
|
||||
Reply,
|
||||
}
|
||||
impl NotificationType {
|
||||
pub fn from_str(s: &str) -> Self {
|
||||
pub fn from_db_str(s: &str) -> Self {
|
||||
match s {
|
||||
"like" => Self::Like,
|
||||
"boost" => Self::Boost,
|
||||
|
||||
@@ -26,7 +26,7 @@ pub enum FollowState {
|
||||
Rejected,
|
||||
}
|
||||
impl FollowState {
|
||||
pub fn from_str(s: &str) -> Self {
|
||||
pub fn from_db_str(s: &str) -> Self {
|
||||
match s {
|
||||
"pending" => Self::Pending,
|
||||
"rejected" => Self::Rejected,
|
||||
|
||||
@@ -9,7 +9,7 @@ pub enum Visibility {
|
||||
Direct,
|
||||
}
|
||||
impl Visibility {
|
||||
pub fn from_str(s: &str) -> Self {
|
||||
pub fn from_db_str(s: &str) -> Self {
|
||||
match s {
|
||||
"followers" => Self::Followers,
|
||||
"unlisted" => Self::Unlisted,
|
||||
|
||||
@@ -101,7 +101,7 @@ pub async fn get_users(
|
||||
let users: Vec<_> = result
|
||||
.items
|
||||
.iter()
|
||||
.map(|u| crate::handlers::auth::to_user_response(u))
|
||||
.map(crate::handlers::auth::to_user_response)
|
||||
.collect();
|
||||
return Ok(Json(serde_json::json!({
|
||||
"items": users, "total": result.total, "page": result.page, "per_page": result.per_page
|
||||
|
||||
Reference in New Issue
Block a user