diff --git a/.woodpecker.yml b/.woodpecker.yml index ff4685ac2..57b085bb4 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -65,6 +65,16 @@ steps: # need make existing toolchain available - cargo +nightly fmt -- --check + cargo_machete: + group: format + image: rustlang/rust:nightly + commands: + - wget https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-x86_64-unknown-linux-musl.tgz + - tar -xvf cargo-binstall-x86_64-unknown-linux-musl.tgz + - cp cargo-binstall /usr/local/cargo/bin + - cargo binstall -y cargo-machete + - cargo machete + restore-cache: image: meltwater/drone-cache:v1 pull: true diff --git a/Cargo.lock b/Cargo.lock index 42e66ea49..26f232a1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -329,18 +329,6 @@ dependencies = [ "pin-project-lite", ] -[[package]] -name = "actix-web-prom" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9df3127d20a5d01c9fc9aceb969a38d31a6767e1b48a54d55a8f56c769a84923" -dependencies = [ - "actix-web", - "futures-core", - "pin-project-lite", - "prometheus", -] - [[package]] name = "addr2line" version = "0.21.0" @@ -2543,13 +2531,12 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lemmy_api" -version = "0.19.0-rc.3" +version = "0.19.0-rc.4" dependencies = [ "activitypub_federation", "actix-web", "actix-web-httpauth", "anyhow", - "async-trait", "base64 0.21.5", "bcrypt", "captcha", @@ -2561,20 +2548,18 @@ dependencies = [ "lemmy_db_views_actor", "lemmy_db_views_moderator", "lemmy_utils", - "serde", "serial_test", "sitemap-rs", "tokio", "totp-rs", "tracing", "url", - "uuid", "wav", ] [[package]] name = "lemmy_api_common" -version = "0.19.0-rc.3" +version = "0.19.0-rc.4" dependencies = [ "activitypub_federation", "actix-web", @@ -2613,19 +2598,16 @@ dependencies = [ [[package]] name = "lemmy_api_crud" -version = "0.19.0-rc.3" +version = "0.19.0-rc.4" dependencies = [ "activitypub_federation", "actix-web", - "async-trait", "bcrypt", - "chrono", "lemmy_api_common", "lemmy_db_schema", "lemmy_db_views", "lemmy_db_views_actor", "lemmy_utils", - "serde", "tracing", "url", "uuid", @@ -2634,7 +2616,7 @@ dependencies = [ [[package]] name = "lemmy_apub" -version = "0.19.0-rc.3" +version = "0.19.0-rc.4" dependencies = [ "activitypub_federation", "actix-web", @@ -2654,7 +2636,6 @@ dependencies = [ "lemmy_db_views", "lemmy_db_views_actor", "lemmy_utils", - "mime", "moka", "once_cell", "reqwest", @@ -2672,7 +2653,7 @@ dependencies = [ [[package]] name = "lemmy_db_schema" -version = "0.19.0-rc.3" +version = "0.19.0-rc.4" dependencies = [ "activitypub_federation", "async-trait", @@ -2708,7 +2689,7 @@ dependencies = [ [[package]] name = "lemmy_db_views" -version = "0.19.0-rc.3" +version = "0.19.0-rc.4" dependencies = [ "actix-web", "diesel", @@ -2726,7 +2707,7 @@ dependencies = [ [[package]] name = "lemmy_db_views_actor" -version = "0.19.0-rc.3" +version = "0.19.0-rc.4" dependencies = [ "chrono", "diesel", @@ -2743,7 +2724,7 @@ dependencies = [ [[package]] name = "lemmy_db_views_moderator" -version = "0.19.0-rc.3" +version = "0.19.0-rc.4" dependencies = [ "diesel", "diesel-async", @@ -2755,16 +2736,13 @@ dependencies = [ [[package]] name = "lemmy_federate" -version = "0.19.0-rc.3" +version = "0.19.0-rc.4" dependencies = [ "activitypub_federation", "anyhow", - "async-trait", - "bytes", "chrono", "diesel", "diesel-async", - "enum_delegate", "futures", "lemmy_api_common", "lemmy_apub", @@ -2773,21 +2751,16 @@ dependencies = [ "lemmy_utils", "moka", "once_cell", - "openssl", "reqwest", - "reqwest-middleware", - "reqwest-tracing", - "serde", "serde_json", "tokio", "tokio-util", "tracing", - "tracing-subscriber", ] [[package]] name = "lemmy_routes" -version = "0.19.0-rc.3" +version = "0.19.0-rc.4" dependencies = [ "activitypub_federation", "actix-web", @@ -2804,7 +2777,6 @@ dependencies = [ "reqwest-middleware", "rss", "serde", - "strum", "tokio", "tracing", "url", @@ -2813,20 +2785,17 @@ dependencies = [ [[package]] name = "lemmy_server" -version = "0.19.0-rc.3" +version = "0.19.0-rc.4" dependencies = [ "activitypub_federation", "actix-cors", "actix-web", - "actix-web-httpauth", - "actix-web-prom", "chrono", "clap", "clokwerk", "console-subscriber 0.1.10", "diesel", "diesel-async", - "doku", "futures-util", "lemmy_api", "lemmy_api_common", @@ -2843,13 +2812,9 @@ dependencies = [ "reqwest", "reqwest-middleware", "reqwest-tracing", - "rustls 0.21.8", - "serde", "serde_json", "serial_test", "tokio", - "tokio-postgres", - "tokio-postgres-rustls", "tracing", "tracing-actix-web", "tracing-error", @@ -2861,11 +2826,10 @@ dependencies = [ [[package]] name = "lemmy_utils" -version = "0.19.0-rc.3" +version = "0.19.0-rc.4" dependencies = [ "actix-web", "anyhow", - "chrono", "deser-hjson", "diesel", "doku", diff --git a/Cargo.toml b/Cargo.toml index f152a86a9..d9e336a4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace.package] -version = "0.19.0-rc.3" +version = "0.19.0-rc.4" edition = "2021" description = "A link aggregator for the fediverse" license = "AGPL-3.0" @@ -59,16 +59,16 @@ members = [ ] [workspace.dependencies] -lemmy_api = { version = "=0.19.0-rc.3", path = "./crates/api" } -lemmy_api_crud = { version = "=0.19.0-rc.3", path = "./crates/api_crud" } -lemmy_apub = { version = "=0.19.0-rc.3", path = "./crates/apub" } -lemmy_utils = { version = "=0.19.0-rc.3", path = "./crates/utils" } -lemmy_db_schema = { version = "=0.19.0-rc.3", path = "./crates/db_schema" } -lemmy_api_common = { version = "=0.19.0-rc.3", path = "./crates/api_common" } -lemmy_routes = { version = "=0.19.0-rc.3", path = "./crates/routes" } -lemmy_db_views = { version = "=0.19.0-rc.3", path = "./crates/db_views" } -lemmy_db_views_actor = { version = "=0.19.0-rc.3", path = "./crates/db_views_actor" } -lemmy_db_views_moderator = { version = "=0.19.0-rc.3", path = "./crates/db_views_moderator" } +lemmy_api = { version = "=0.19.0-rc.4", path = "./crates/api" } +lemmy_api_crud = { version = "=0.19.0-rc.4", path = "./crates/api_crud" } +lemmy_apub = { version = "=0.19.0-rc.4", path = "./crates/apub" } +lemmy_utils = { version = "=0.19.0-rc.4", path = "./crates/utils" } +lemmy_db_schema = { version = "=0.19.0-rc.4", path = "./crates/db_schema" } +lemmy_api_common = { version = "=0.19.0-rc.4", path = "./crates/api_common" } +lemmy_routes = { version = "=0.19.0-rc.4", path = "./crates/routes" } +lemmy_db_views = { version = "=0.19.0-rc.4", path = "./crates/db_views" } +lemmy_db_views_actor = { version = "=0.19.0-rc.4", path = "./crates/db_views_actor" } +lemmy_db_views_moderator = { version = "=0.19.0-rc.4", path = "./crates/db_views_moderator" } activitypub_federation = { version = "0.5.0-beta.4", default-features = false, features = [ "actix-web", ] } @@ -129,7 +129,6 @@ tokio-postgres = "0.7.10" tokio-postgres-rustls = "0.10.0" urlencoding = "2.1.3" enum-map = "2.7" -mime = "0.3.17" [dependencies] lemmy_api = { workspace = true } @@ -139,11 +138,10 @@ lemmy_utils = { workspace = true } lemmy_db_schema = { workspace = true } lemmy_api_common = { workspace = true } lemmy_routes = { workspace = true } -lemmy_federate = { version = "0.19.0-rc.3", path = "crates/federate" } +lemmy_federate = { version = "0.19.0-rc.4", path = "crates/federate" } activitypub_federation = { workspace = true } diesel = { workspace = true } diesel-async = { workspace = true } -serde = { workspace = true } actix-web = { workspace = true } tracing = { workspace = true } tracing-actix-web = { workspace = true } @@ -155,7 +153,6 @@ reqwest = { workspace = true } reqwest-middleware = { workspace = true } reqwest-tracing = { workspace = true } clokwerk = { workspace = true } -doku = { workspace = true } serde_json = { workspace = true } tracing-opentelemetry = { workspace = true, optional = true } opentelemetry = { workspace = true, optional = true } @@ -164,13 +161,8 @@ opentelemetry-otlp = { version = "0.12.0", optional = true } pict-rs = { version = "0.4.5", optional = true } tokio.workspace = true actix-cors = "0.6.4" -rustls = { workspace = true } futures-util = { workspace = true } -tokio-postgres = { workspace = true } -tokio-postgres-rustls = { workspace = true } chrono = { workspace = true } prometheus = { version = "0.13.3", features = ["process"] } -actix-web-prom = { version = "0.6.0" } serial_test = { workspace = true } clap = { version = "4.4.7", features = ["derive"] } -actix-web-httpauth = "0.8.1" diff --git a/config/defaults.hjson b/config/defaults.hjson index 1ce63396f..c200bdd36 100644 --- a/config/defaults.hjson +++ b/config/defaults.hjson @@ -53,7 +53,8 @@ # storage usage. It may also be necessary in certain countries which don't allow copying images # from newspaper articles, but only allow hotlinking. # - # If this setting is enabled, the Opengraph image is directly returned as thumbnail. + # If this setting is enabled, the Opengraph image is directly returned as thumbnail. Note that + # it still gets proxied through the local instance if `image_proxy` is enabled. disable_external_link_previews: false } # Email sending configuration. All options except login/password are mandatory diff --git a/crates/api/Cargo.toml b/crates/api/Cargo.toml index 758a6c510..bb36bb7e3 100644 --- a/crates/api/Cargo.toml +++ b/crates/api/Cargo.toml @@ -22,11 +22,8 @@ lemmy_db_views_actor = { workspace = true, features = ["full"] } lemmy_api_common = { workspace = true, features = ["full"] } activitypub_federation = { workspace = true } bcrypt = { workspace = true } -serde = { workspace = true } actix-web = { workspace = true } base64 = { workspace = true } -uuid = { workspace = true } -async-trait = { workspace = true } captcha = { workspace = true } anyhow = { workspace = true } tracing = { workspace = true } diff --git a/crates/api/src/local_user/logout.rs b/crates/api/src/local_user/logout.rs index a2cc83b3f..10b4732b7 100644 --- a/crates/api/src/local_user/logout.rs +++ b/crates/api/src/local_user/logout.rs @@ -1,7 +1,7 @@ use crate::read_auth_token; use activitypub_federation::config::Data; use actix_web::{cookie::Cookie, HttpRequest, HttpResponse}; -use lemmy_api_common::{context::LemmyContext, utils::AUTH_COOKIE_NAME}; +use lemmy_api_common::{context::LemmyContext, utils::AUTH_COOKIE_NAME, SuccessResponse}; use lemmy_db_schema::source::login_token::LoginToken; use lemmy_db_views::structs::LocalUserView; use lemmy_utils::error::{LemmyErrorType, LemmyResult}; @@ -16,7 +16,7 @@ pub async fn logout( let jwt = read_auth_token(&req)?.ok_or(LemmyErrorType::NotLoggedIn)?; LoginToken::invalidate(&mut context.pool(), &jwt).await?; - let mut res = HttpResponse::Ok().finish(); + let mut res = HttpResponse::Ok().json(SuccessResponse::default()); let cookie = Cookie::new(AUTH_COOKIE_NAME, ""); res.add_removal_cookie(&cookie)?; Ok(res) diff --git a/crates/api_common/Cargo.toml b/crates/api_common/Cargo.toml index 9912b294a..950785e57 100644 --- a/crates/api_common/Cargo.toml +++ b/crates/api_common/Cargo.toml @@ -63,7 +63,7 @@ actix-web = { workspace = true, optional = true } enum-map = { workspace = true } urlencoding = { workspace = true } async-trait = { workspace = true } -mime = { workspace = true, optional = true } +mime = { version = "0.3.17", optional = true } webpage = { version = "1.6", default-features = false, features = [ "serde", ], optional = true } @@ -73,6 +73,9 @@ jsonwebtoken = { version = "8.3.0", optional = true } getrandom = { version = "0.2.10", features = ["js"] } task-local-extensions = "0.1.4" +[package.metadata.cargo-machete] +ignored = ["getrandom"] + [dev-dependencies] serial_test = { workspace = true } reqwest-middleware = { workspace = true } diff --git a/crates/api_crud/Cargo.toml b/crates/api_crud/Cargo.toml index 06e29044b..0799332cf 100644 --- a/crates/api_crud/Cargo.toml +++ b/crates/api_crud/Cargo.toml @@ -16,11 +16,8 @@ lemmy_db_views_actor = { workspace = true, features = ["full"] } lemmy_api_common = { workspace = true, features = ["full"] } activitypub_federation = { workspace = true } bcrypt = { workspace = true } -serde = { workspace = true } actix-web = { workspace = true } tracing = { workspace = true } url = { workspace = true } -async-trait = { workspace = true } webmention = "0.5.0" -chrono = { workspace = true } uuid = { workspace = true } diff --git a/crates/apub/Cargo.toml b/crates/apub/Cargo.toml index b67a9fb74..b65b1c707 100644 --- a/crates/apub/Cargo.toml +++ b/crates/apub/Cargo.toml @@ -38,7 +38,6 @@ anyhow = { workspace = true } reqwest = { workspace = true } once_cell = { workspace = true } serde_with = { workspace = true } -mime = { workspace = true } html2md = "0.2.14" html2text = "0.6.0" stringreader = "0.1.1" diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index 3370a5594..bf1fc0ef2 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -76,3 +76,6 @@ uuid = { workspace = true, features = ["v4"] } [dev-dependencies] serial_test = { workspace = true } + +[package.metadata.cargo-machete] +ignored = ["strum"] diff --git a/crates/db_views/src/registration_application_view.rs b/crates/db_views/src/registration_application_view.rs index 0bdd50cf1..1c0c859e8 100644 --- a/crates/db_views/src/registration_application_view.rs +++ b/crates/db_views/src/registration_application_view.rs @@ -62,7 +62,7 @@ fn queries<'a>() -> Queries< query = query .limit(limit) .offset(offset) - .order_by(registration_application::published.desc()); + .order_by(registration_application::published.asc()); query.load::(&mut conn).await }; @@ -308,7 +308,7 @@ mod tests { assert_eq!( apps, - [read_jess_app_view.clone(), expected_sara_app_view.clone()] + [expected_sara_app_view.clone(), read_jess_app_view.clone()] ); // Make sure the counts are correct diff --git a/crates/db_views_actor/Cargo.toml b/crates/db_views_actor/Cargo.toml index 93ce0f5b3..fc3573d46 100644 --- a/crates/db_views_actor/Cargo.toml +++ b/crates/db_views_actor/Cargo.toml @@ -35,3 +35,6 @@ strum_macros = { workspace = true } [dev-dependencies] serial_test = { workspace = true } tokio = { workspace = true } + +[package.metadata.cargo-machete] +ignored = ["strum"] diff --git a/crates/db_views_actor/src/comment_reply_view.rs b/crates/db_views_actor/src/comment_reply_view.rs index 6ca4182e8..e5a03eaf6 100644 --- a/crates/db_views_actor/src/comment_reply_view.rs +++ b/crates/db_views_actor/src/comment_reply_view.rs @@ -20,6 +20,7 @@ use lemmy_db_schema::{ comment_saved, community, community_follower, + community_moderator, community_person_ban, person, person_block, @@ -80,6 +81,13 @@ fn queries<'a>() -> Queries< .and(comment_like::person_id.eq(person_id_join)), ), ) + .left_join( + community_moderator::table.on( + community::id + .eq(community_moderator::community_id) + .and(community_moderator::person_id.eq(comment::creator_id)), + ), + ) .select(( comment_reply::all_columns, comment::all_columns, @@ -89,6 +97,7 @@ fn queries<'a>() -> Queries< aliases::person1.fields(person::all_columns), comment_aggregates::all_columns, community_person_ban::id.nullable().is_not_null(), + community_moderator::id.nullable().is_not_null(), CommunityFollower::select_subscribed_type(), comment_saved::id.nullable().is_not_null(), person_block::id.nullable().is_not_null(), diff --git a/crates/db_views_actor/src/person_mention_view.rs b/crates/db_views_actor/src/person_mention_view.rs index 8d04f9820..c44ee791c 100644 --- a/crates/db_views_actor/src/person_mention_view.rs +++ b/crates/db_views_actor/src/person_mention_view.rs @@ -20,6 +20,7 @@ use lemmy_db_schema::{ comment_saved, community, community_follower, + community_moderator, community_person_ban, person, person_block, @@ -85,6 +86,7 @@ fn queries<'a>() -> Queries< aliases::person1.fields(person::all_columns), comment_aggregates::all_columns, community_person_ban::id.nullable().is_not_null(), + community_moderator::id.nullable().is_not_null(), CommunityFollower::select_subscribed_type(), comment_saved::id.nullable().is_not_null(), person_block::id.nullable().is_not_null(), @@ -105,6 +107,13 @@ fn queries<'a>() -> Queries< .and(community_person_ban::person_id.eq(comment::creator_id)), ), ) + .left_join( + community_moderator::table.on( + community::id + .eq(community_moderator::community_id) + .and(community_moderator::person_id.eq(comment::creator_id)), + ), + ) .select(selection) .first::(&mut conn) .await @@ -124,6 +133,13 @@ fn queries<'a>() -> Queries< ), ), ) + .left_join( + community_moderator::table.on( + community::id + .eq(community_moderator::community_id) + .and(community_moderator::person_id.eq(comment::creator_id)), + ), + ) .select(selection); if let Some(recipient_id) = options.recipient_id { diff --git a/crates/db_views_actor/src/structs.rs b/crates/db_views_actor/src/structs.rs index bdc9e6bbd..88461701d 100644 --- a/crates/db_views_actor/src/structs.rs +++ b/crates/db_views_actor/src/structs.rs @@ -99,6 +99,7 @@ pub struct PersonMentionView { pub recipient: Person, pub counts: CommentAggregates, pub creator_banned_from_community: bool, + pub creator_is_moderator: bool, pub subscribed: SubscribedType, pub saved: bool, pub creator_blocked: bool, @@ -118,11 +119,12 @@ pub struct CommentReplyView { pub community: Community, pub recipient: Person, pub counts: CommentAggregates, - pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan - pub subscribed: SubscribedType, // Left join to CommunityFollower - pub saved: bool, // Left join to CommentSaved - pub creator_blocked: bool, // Left join to PersonBlock - pub my_vote: Option, // Left join to CommentLike + pub creator_banned_from_community: bool, + pub creator_is_moderator: bool, + pub subscribed: SubscribedType, + pub saved: bool, + pub creator_blocked: bool, + pub my_vote: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] diff --git a/crates/federate/Cargo.toml b/crates/federate/Cargo.toml index 81ad1da4c..c098f9f5b 100644 --- a/crates/federate/Cargo.toml +++ b/crates/federate/Cargo.toml @@ -26,16 +26,7 @@ diesel-async = { workspace = true, features = ["deadpool", "postgres"] } once_cell.workspace = true reqwest.workspace = true serde_json.workspace = true -serde.workspace = true tokio = { workspace = true, features = ["full"] } tracing.workspace = true - -async-trait = "0.1.74" -bytes = "1.5.0" -enum_delegate = "0.2.0" moka = { version = "0.11.3", features = ["future"] } -openssl = "0.10.57" -reqwest-middleware = "0.2.4" -reqwest-tracing = "0.4.6" tokio-util = "0.7.9" -tracing-subscriber = "0.3.17" diff --git a/crates/routes/Cargo.toml b/crates/routes/Cargo.toml index 00034425f..e0d9e1fb2 100644 --- a/crates/routes/Cargo.toml +++ b/crates/routes/Cargo.toml @@ -26,7 +26,6 @@ reqwest = { workspace = true, features = ["stream"] } reqwest-middleware = { workspace = true } serde = { workspace = true } url = { workspace = true } -strum = { workspace = true } once_cell = { workspace = true } tracing = { workspace = true } tokio = { workspace = true } diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index 1809318ed..148fc766f 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -18,7 +18,6 @@ full = ["ts-rs"] [dependencies] regex = { workspace = true } -chrono = { workspace = true } tracing = { workspace = true } tracing-error = { workspace = true } itertools = { workspace = true } diff --git a/migrations/2023-10-23-184941_hot_rank_greatest_fix/down.sql b/migrations/2023-10-23-184941_hot_rank_greatest_fix/down.sql new file mode 100644 index 000000000..434d7885a --- /dev/null +++ b/migrations/2023-10-23-184941_hot_rank_greatest_fix/down.sql @@ -0,0 +1,19 @@ +CREATE OR REPLACE FUNCTION hot_rank (score numeric, published timestamp with time zone) + RETURNS float + AS $$ +DECLARE + hours_diff numeric := EXTRACT(EPOCH FROM (now() - published)) / 3600; +BEGIN + -- 24 * 7 = 168, so after a week, it will default to 0. + IF (hours_diff > 0 AND hours_diff < 168) THEN + RETURN log(greatest (1, score + 3)) / power((hours_diff + 2), 1.8); + ELSE + -- if the post is from the future, set hot score to 0. otherwise you can game the post to + -- always be on top even with only 1 vote by setting it to the future + RETURN 0.0; + END IF; +END; +$$ +LANGUAGE plpgsql +IMMUTABLE PARALLEL SAFE; + diff --git a/migrations/2023-10-23-184941_hot_rank_greatest_fix/up.sql b/migrations/2023-10-23-184941_hot_rank_greatest_fix/up.sql new file mode 100644 index 000000000..06815591b --- /dev/null +++ b/migrations/2023-10-23-184941_hot_rank_greatest_fix/up.sql @@ -0,0 +1,25 @@ +-- The hot_rank algorithm currently uses greatest(1, score + 3) +-- This greatest of 1 incorrect because log10(1) is zero, +-- so it will push negative-voted comments / posts to the bottom, IE hot_rank = 0 +-- The update_scheduled_ranks will never recalculate them, because it ignores content +-- with hot_rank = 0 +CREATE OR REPLACE FUNCTION hot_rank (score numeric, published timestamp with time zone) + RETURNS float + AS $$ +DECLARE + hours_diff numeric := EXTRACT(EPOCH FROM (now() - published)) / 3600; +BEGIN + -- 24 * 7 = 168, so after a week, it will default to 0. + IF (hours_diff > 0 AND hours_diff < 168) THEN + -- Use greatest(2,score), so that the hot_rank will be positive and not ignored. + RETURN log(greatest (2, score + 2)) / power((hours_diff + 2), 1.8); + ELSE + -- if the post is from the future, set hot score to 0. otherwise you can game the post to + -- always be on top even with only 1 vote by setting it to the future + RETURN 0.0; + END IF; +END; +$$ +LANGUAGE plpgsql +IMMUTABLE PARALLEL SAFE; +