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,15 +237,14 @@ impl Activity for UndoActivity {
|
|||||||
|
|
||||||
match obj_type {
|
match obj_type {
|
||||||
"Follow" => {
|
"Follow" => {
|
||||||
if let Some(obj_url) = self.object.get("object").and_then(|o| o.as_str()) {
|
if let Some(obj_url) = self.object.get("object").and_then(|o| o.as_str())
|
||||||
if let Ok(url) = Url::parse(obj_url) {
|
&& let Ok(url) = Url::parse(obj_url)
|
||||||
if let Some(user_id) = crate::urls::extract_user_id_from_url(&url) {
|
&& let Some(user_id) = crate::urls::extract_user_id_from_url(&url)
|
||||||
|
{
|
||||||
data.federation_repo
|
data.federation_repo
|
||||||
.remove_follower(user_id, self.actor.inner().as_str())
|
.remove_follower(user_id, self.actor.inner().as_str())
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
data.object_handler
|
data.object_handler
|
||||||
.on_actor_removed(self.actor.inner())
|
.on_actor_removed(self.actor.inner())
|
||||||
.await
|
.await
|
||||||
@@ -260,8 +259,9 @@ impl Activity for UndoActivity {
|
|||||||
.and_then(|id| id.as_str())
|
.and_then(|id| id.as_str())
|
||||||
.or_else(|| self.object.get("id").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 Some(ap_id_str) = ap_id_str
|
||||||
if let Ok(ap_id) = Url::parse(ap_id_str) {
|
&& let Ok(ap_id) = Url::parse(ap_id_str)
|
||||||
|
{
|
||||||
data.object_handler
|
data.object_handler
|
||||||
.on_delete(&ap_id, self.actor.inner())
|
.on_delete(&ap_id, self.actor.inner())
|
||||||
.await
|
.await
|
||||||
@@ -269,7 +269,6 @@ impl Activity for UndoActivity {
|
|||||||
tracing::info!(ap_id = %ap_id_str, "undo Add (watchlist remove)");
|
tracing::info!(ap_id = %ap_id_str, "undo Add (watchlist remove)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
other => {
|
other => {
|
||||||
tracing::debug!(kind = %other, "ignoring Undo of unknown activity type");
|
tracing::debug!(kind = %other, "ignoring Undo of unknown activity type");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ pub struct FederationData {
|
|||||||
pub(crate) domain: String,
|
pub(crate) domain: String,
|
||||||
pub(crate) allow_registration: bool,
|
pub(crate) allow_registration: bool,
|
||||||
pub(crate) software_name: String,
|
pub(crate) software_name: String,
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) event_publisher: Option<Arc<dyn EventPublisher>>,
|
pub(crate) event_publisher: Option<Arc<dyn EventPublisher>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ pub struct ActivityPubService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ActivityPubService {
|
impl ActivityPubService {
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub async fn new(
|
pub async fn new(
|
||||||
repo: Arc<dyn FederationRepository>,
|
repo: Arc<dyn FederationRepository>,
|
||||||
user_repo: Arc<dyn ApUserRepository>,
|
user_repo: Arc<dyn ApUserRepository>,
|
||||||
@@ -748,7 +749,7 @@ impl ActivityPubService {
|
|||||||
.await
|
.await
|
||||||
.map_err(|e| anyhow::anyhow!("{e}"))?;
|
.map_err(|e| anyhow::anyhow!("{e}"))?;
|
||||||
// Wrap with @context so Mastodon's JSON-LD processor can resolve field names.
|
// 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!(
|
let update_id = Url::parse(&format!(
|
||||||
"{}/activities/update/{}",
|
"{}/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.
|
/// Extract the username segment from a /users/:username URL.
|
||||||
|
#[allow(dead_code)]
|
||||||
pub fn extract_username_from_url(url: &Url) -> Option<String> {
|
pub fn extract_username_from_url(url: &Url) -> Option<String> {
|
||||||
url.path()
|
url.path()
|
||||||
.strip_prefix("/users/")
|
.strip_prefix("/users/")
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ pub struct ThoughtNote {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ThoughtNote {
|
impl ThoughtNote {
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn new_public(
|
pub fn new_public(
|
||||||
id: Url,
|
id: Url,
|
||||||
actor_url: 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_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
|
||||||
in_reply_to_url: r.in_reply_to_url,
|
in_reply_to_url: r.in_reply_to_url,
|
||||||
ap_id: r.t_ap_id,
|
ap_id: r.t_ap_id,
|
||||||
visibility: Visibility::from_str(&r.visibility),
|
visibility: Visibility::from_db_str(&r.visibility),
|
||||||
content_warning: r.content_warning,
|
content_warning: r.content_warning,
|
||||||
sensitive: r.sensitive,
|
sensitive: r.sensitive,
|
||||||
local: r.t_local,
|
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_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
|
||||||
in_reply_to_url: r.in_reply_to_url,
|
in_reply_to_url: r.in_reply_to_url,
|
||||||
ap_id: r.t_ap_id,
|
ap_id: r.t_ap_id,
|
||||||
visibility: Visibility::from_str(&r.visibility),
|
visibility: Visibility::from_db_str(&r.visibility),
|
||||||
content_warning: r.content_warning,
|
content_warning: r.content_warning,
|
||||||
sensitive: r.sensitive,
|
sensitive: r.sensitive,
|
||||||
local: r.t_local,
|
local: r.t_local,
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ impl FollowRepository for PgFollowRepository {
|
|||||||
.map(|o| o.map(|r| Follow {
|
.map(|o| o.map(|r| Follow {
|
||||||
follower_id: UserId::from_uuid(r.follower_id),
|
follower_id: UserId::from_uuid(r.follower_id),
|
||||||
following_id: UserId::from_uuid(r.following_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,
|
ap_id: r.ap_id,
|
||||||
created_at: r.created_at,
|
created_at: r.created_at,
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ impl NotificationRepository for PgNotificationRepository {
|
|||||||
.map(|r| Notification {
|
.map(|r| Notification {
|
||||||
id: NotificationId::from_uuid(r.id),
|
id: NotificationId::from_uuid(r.id),
|
||||||
user_id: UserId::from_uuid(r.user_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),
|
from_user_id: r.from_user_id.map(UserId::from_uuid),
|
||||||
thought_id: r.thought_id.map(ThoughtId::from_uuid),
|
thought_id: r.thought_id.map(ThoughtId::from_uuid),
|
||||||
read: r.read,
|
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_id: r.in_reply_to_id.map(ThoughtId::from_uuid),
|
||||||
in_reply_to_url: r.in_reply_to_url,
|
in_reply_to_url: r.in_reply_to_url,
|
||||||
ap_id: r.ap_id,
|
ap_id: r.ap_id,
|
||||||
visibility: Visibility::from_str(&r.visibility),
|
visibility: Visibility::from_db_str(&r.visibility),
|
||||||
content_warning: r.content_warning,
|
content_warning: r.content_warning,
|
||||||
sensitive: r.sensitive,
|
sensitive: r.sensitive,
|
||||||
local: r.local,
|
local: r.local,
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ pub async fn create_thought(
|
|||||||
let visibility = input
|
let visibility = input
|
||||||
.visibility
|
.visibility
|
||||||
.as_deref()
|
.as_deref()
|
||||||
.map(Visibility::from_str)
|
.map(Visibility::from_db_str)
|
||||||
.unwrap_or(Visibility::Public);
|
.unwrap_or(Visibility::Public);
|
||||||
let thought = Thought::new_local(
|
let thought = Thought::new_local(
|
||||||
ThoughtId::new(),
|
ThoughtId::new(),
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ pub enum NotificationType {
|
|||||||
Reply,
|
Reply,
|
||||||
}
|
}
|
||||||
impl NotificationType {
|
impl NotificationType {
|
||||||
pub fn from_str(s: &str) -> Self {
|
pub fn from_db_str(s: &str) -> Self {
|
||||||
match s {
|
match s {
|
||||||
"like" => Self::Like,
|
"like" => Self::Like,
|
||||||
"boost" => Self::Boost,
|
"boost" => Self::Boost,
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ pub enum FollowState {
|
|||||||
Rejected,
|
Rejected,
|
||||||
}
|
}
|
||||||
impl FollowState {
|
impl FollowState {
|
||||||
pub fn from_str(s: &str) -> Self {
|
pub fn from_db_str(s: &str) -> Self {
|
||||||
match s {
|
match s {
|
||||||
"pending" => Self::Pending,
|
"pending" => Self::Pending,
|
||||||
"rejected" => Self::Rejected,
|
"rejected" => Self::Rejected,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ pub enum Visibility {
|
|||||||
Direct,
|
Direct,
|
||||||
}
|
}
|
||||||
impl Visibility {
|
impl Visibility {
|
||||||
pub fn from_str(s: &str) -> Self {
|
pub fn from_db_str(s: &str) -> Self {
|
||||||
match s {
|
match s {
|
||||||
"followers" => Self::Followers,
|
"followers" => Self::Followers,
|
||||||
"unlisted" => Self::Unlisted,
|
"unlisted" => Self::Unlisted,
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ pub async fn get_users(
|
|||||||
let users: Vec<_> = result
|
let users: Vec<_> = result
|
||||||
.items
|
.items
|
||||||
.iter()
|
.iter()
|
||||||
.map(|u| crate::handlers::auth::to_user_response(u))
|
.map(crate::handlers::auth::to_user_response)
|
||||||
.collect();
|
.collect();
|
||||||
return Ok(Json(serde_json::json!({
|
return Ok(Json(serde_json::json!({
|
||||||
"items": users, "total": result.total, "page": result.page, "per_page": result.per_page
|
"items": users, "total": result.total, "page": result.page, "per_page": result.per_page
|
||||||
|
|||||||
Reference in New Issue
Block a user