From: Dessalines Date: Thu, 25 Nov 2021 18:00:26 +0000 (-0500) Subject: Merge pull request #1937 from LemmyNet/disable-edit-email-notifications X-Git-Url: http://these/git/?a=commitdiff_plain;h=be65b6869fff52a41f19afe1f2d054af012b8c93;hp=27a687bcd0b2cd362d02f0fb10a16c80a6a6aa55;p=lemmy.git Merge pull request #1937 from LemmyNet/disable-edit-email-notifications Dont send email notifications for edited comments (fixes #1925) --- diff --git a/Cargo.lock b/Cargo.lock index a5b5c86c..d6fd15a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1722,7 +1722,7 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "lemmy_api" -version = "0.14.1" +version = "0.14.3" dependencies = [ "actix", "actix-rt", @@ -1765,7 +1765,7 @@ dependencies = [ [[package]] name = "lemmy_api_common" -version = "0.14.1" +version = "0.14.3" dependencies = [ "actix-web", "chrono", @@ -1782,7 +1782,7 @@ dependencies = [ [[package]] name = "lemmy_api_crud" -version = "0.14.1" +version = "0.14.3" dependencies = [ "actix", "actix-rt", @@ -1826,7 +1826,7 @@ dependencies = [ [[package]] name = "lemmy_apub" -version = "0.14.1" +version = "0.14.3" dependencies = [ "activitystreams-kinds", "actix", @@ -1872,7 +1872,7 @@ dependencies = [ [[package]] name = "lemmy_apub_lib" -version = "0.14.1" +version = "0.14.3" dependencies = [ "activitystreams", "actix-web", @@ -1898,7 +1898,7 @@ dependencies = [ [[package]] name = "lemmy_apub_lib_derive" -version = "0.14.1" +version = "0.14.3" dependencies = [ "proc-macro2 1.0.32", "quote 1.0.10", @@ -1908,7 +1908,7 @@ dependencies = [ [[package]] name = "lemmy_db_schema" -version = "0.14.1" +version = "0.14.3" dependencies = [ "bcrypt", "chrono", @@ -1930,7 +1930,7 @@ dependencies = [ [[package]] name = "lemmy_db_views" -version = "0.14.1" +version = "0.14.3" dependencies = [ "diesel", "lemmy_db_schema", @@ -1942,7 +1942,7 @@ dependencies = [ [[package]] name = "lemmy_db_views_actor" -version = "0.14.1" +version = "0.14.3" dependencies = [ "diesel", "lemmy_db_schema", @@ -1951,7 +1951,7 @@ dependencies = [ [[package]] name = "lemmy_db_views_moderator" -version = "0.14.1" +version = "0.14.3" dependencies = [ "diesel", "lemmy_db_schema", @@ -1960,7 +1960,7 @@ dependencies = [ [[package]] name = "lemmy_routes" -version = "0.14.1" +version = "0.14.3" dependencies = [ "actix", "actix-http", @@ -1987,7 +1987,7 @@ dependencies = [ [[package]] name = "lemmy_server" -version = "0.14.1" +version = "0.14.3" dependencies = [ "activitystreams", "actix", @@ -2029,7 +2029,7 @@ dependencies = [ [[package]] name = "lemmy_utils" -version = "0.14.1" +version = "0.14.3" dependencies = [ "actix-rt", "actix-web", @@ -2066,7 +2066,7 @@ dependencies = [ [[package]] name = "lemmy_websocket" -version = "0.14.1" +version = "0.14.3" dependencies = [ "actix", "actix-web", diff --git a/Cargo.toml b/Cargo.toml index bd247b7d..1a5c07cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lemmy_server" -version = "0.14.1" +version = "0.14.3" edition = "2018" description = "A link aggregator for the fediverse" license = "AGPL-3.0" @@ -31,18 +31,18 @@ members = [ ] [dependencies] -lemmy_api = { version = "=0.14.1", path = "./crates/api" } -lemmy_api_crud = { version = "=0.14.1", path = "./crates/api_crud" } -lemmy_apub = { version = "=0.14.1", path = "./crates/apub" } -lemmy_apub_lib = { version = "=0.14.1", path = "./crates/apub_lib" } -lemmy_utils = { version = "=0.14.1", path = "./crates/utils" } -lemmy_db_schema = { version = "=0.14.1", path = "./crates/db_schema" } -lemmy_db_views = { version = "=0.14.1", path = "./crates/db_views" } -lemmy_db_views_moderator = { version = "=0.14.1", path = "./crates/db_views_moderator" } -lemmy_db_views_actor = { version = "=0.14.1", path = "./crates/db_views_actor" } -lemmy_api_common = { version = "=0.14.1", path = "crates/api_common" } -lemmy_websocket = { version = "=0.14.1", path = "./crates/websocket" } -lemmy_routes = { version = "=0.14.1", path = "./crates/routes" } +lemmy_api = { version = "=0.14.3", path = "./crates/api" } +lemmy_api_crud = { version = "=0.14.3", path = "./crates/api_crud" } +lemmy_apub = { version = "=0.14.3", path = "./crates/apub" } +lemmy_apub_lib = { version = "=0.14.3", path = "./crates/apub_lib" } +lemmy_utils = { version = "=0.14.3", path = "./crates/utils" } +lemmy_db_schema = { version = "=0.14.3", path = "./crates/db_schema" } +lemmy_db_views = { version = "=0.14.3", path = "./crates/db_views" } +lemmy_db_views_moderator = { version = "=0.14.3", path = "./crates/db_views_moderator" } +lemmy_db_views_actor = { version = "=0.14.3", path = "./crates/db_views_actor" } +lemmy_api_common = { version = "=0.14.3", path = "crates/api_common" } +lemmy_websocket = { version = "=0.14.3", path = "./crates/websocket" } +lemmy_routes = { version = "=0.14.3", path = "./crates/routes" } diesel = "1.4.8" diesel_migrations = "1.4.0" chrono = { version = "0.4.19", features = ["serde"] } diff --git a/crates/api/Cargo.toml b/crates/api/Cargo.toml index f09c1234..82359145 100644 --- a/crates/api/Cargo.toml +++ b/crates/api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lemmy_api" -version = "0.14.1" +version = "0.14.3" edition = "2018" description = "A link aggregator for the fediverse" license = "AGPL-3.0" @@ -13,15 +13,15 @@ path = "src/lib.rs" doctest = false [dependencies] -lemmy_apub = { version = "=0.14.1", path = "../apub" } -lemmy_apub_lib = { version = "=0.14.1", path = "../apub_lib" } -lemmy_utils = { version = "=0.14.1", path = "../utils" } -lemmy_db_schema = { version = "=0.14.1", path = "../db_schema" } -lemmy_db_views = { version = "=0.14.1", path = "../db_views" } -lemmy_db_views_moderator = { version = "=0.14.1", path = "../db_views_moderator" } -lemmy_db_views_actor = { version = "=0.14.1", path = "../db_views_actor" } -lemmy_api_common = { version = "=0.14.1", path = "../api_common" } -lemmy_websocket = { version = "=0.14.1", path = "../websocket" } +lemmy_apub = { version = "=0.14.3", path = "../apub" } +lemmy_apub_lib = { version = "=0.14.3", path = "../apub_lib" } +lemmy_utils = { version = "=0.14.3", path = "../utils" } +lemmy_db_schema = { version = "=0.14.3", path = "../db_schema" } +lemmy_db_views = { version = "=0.14.3", path = "../db_views" } +lemmy_db_views_moderator = { version = "=0.14.3", path = "../db_views_moderator" } +lemmy_db_views_actor = { version = "=0.14.3", path = "../db_views_actor" } +lemmy_api_common = { version = "=0.14.3", path = "../api_common" } +lemmy_websocket = { version = "=0.14.3", path = "../websocket" } diesel = "1.4.8" bcrypt = "0.10.1" chrono = { version = "0.4.19", features = ["serde"] } diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index 74a3d303..d535c467 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -120,6 +120,9 @@ pub async fn match_websocket_operation( UserOperation::CreatePostLike => { do_websocket_operation::(context, id, op, data).await } + UserOperation::MarkPostAsRead => { + do_websocket_operation::(context, id, op, data).await + } UserOperation::SavePost => do_websocket_operation::(context, id, op, data).await, UserOperation::CreatePostReport => { do_websocket_operation::(context, id, op, data).await diff --git a/crates/api/src/post.rs b/crates/api/src/post.rs index c7acb08f..60a580b8 100644 --- a/crates/api/src/post.rs +++ b/crates/api/src/post.rs @@ -9,6 +9,7 @@ use lemmy_api_common::{ get_local_user_view_from_jwt, is_mod_or_admin, mark_post_as_read, + mark_post_as_unread, post::*, }; use lemmy_apub::{ @@ -118,6 +119,41 @@ impl Perform for CreatePostLike { } } +#[async_trait::async_trait(?Send)] +impl Perform for MarkPostAsRead { + type Response = PostResponse; + + async fn perform( + &self, + context: &Data, + _websocket_id: Option, + ) -> Result { + let data = self; + let local_user_view = + get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?; + + let post_id = data.post_id; + let person_id = local_user_view.person.id; + + // Mark the post as read / unread + if data.read { + mark_post_as_read(person_id, post_id, context.pool()).await?; + } else { + mark_post_as_unread(person_id, post_id, context.pool()).await?; + } + + // Fetch it + let post_view = blocking(context.pool(), move |conn| { + PostView::read(conn, post_id, Some(person_id)) + }) + .await??; + + let res = Self::Response { post_view }; + + Ok(res) + } +} + #[async_trait::async_trait(?Send)] impl Perform for LockPost { type Response = PostResponse; diff --git a/crates/api_common/Cargo.toml b/crates/api_common/Cargo.toml index 9b7c5640..93290bb1 100644 --- a/crates/api_common/Cargo.toml +++ b/crates/api_common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lemmy_api_common" -version = "0.14.1" +version = "0.14.3" edition = "2018" description = "A link aggregator for the fediverse" license = "AGPL-3.0" @@ -13,11 +13,11 @@ path = "src/lib.rs" doctest = false [dependencies] -lemmy_db_views = { version = "=0.14.1", path = "../db_views" } -lemmy_db_views_moderator = { version = "=0.14.1", path = "../db_views_moderator" } -lemmy_db_views_actor = { version = "=0.14.1", path = "../db_views_actor" } -lemmy_db_schema = { version = "=0.14.1", path = "../db_schema" } -lemmy_utils = { version = "=0.14.1", path = "../utils" } +lemmy_db_views = { version = "=0.14.3", path = "../db_views" } +lemmy_db_views_moderator = { version = "=0.14.3", path = "../db_views_moderator" } +lemmy_db_views_actor = { version = "=0.14.3", path = "../db_views_actor" } +lemmy_db_schema = { version = "=0.14.3", path = "../db_schema" } +lemmy_utils = { version = "=0.14.3", path = "../utils" } serde = { version = "1.0.130", features = ["derive"] } diesel = "1.4.8" actix-web = { version = "4.0.0-beta.9", default-features = false, features = ["cookies"] } diff --git a/crates/api_common/src/comment.rs b/crates/api_common/src/comment.rs index eadbceb2..afe76a99 100644 --- a/crates/api_common/src/comment.rs +++ b/crates/api_common/src/comment.rs @@ -11,6 +11,12 @@ pub struct CreateComment { pub auth: String, } +#[derive(Serialize, Deserialize)] +pub struct GetComment { + pub id: CommentId, + pub auth: Option, +} + #[derive(Serialize, Deserialize)] pub struct EditComment { pub content: String, diff --git a/crates/api_common/src/lib.rs b/crates/api_common/src/lib.rs index bf6246a0..f5b6ebad 100644 --- a/crates/api_common/src/lib.rs +++ b/crates/api_common/src/lib.rs @@ -81,7 +81,21 @@ pub async fn mark_post_as_read( PostRead::mark_as_read(conn, &post_read_form) }) .await? - .map_err(|_| ApiError::err_plain("couldnt_mark_post_as_read").into()) + .map_err(|e| ApiError::err("couldnt_mark_post_as_read", e).into()) +} + +pub async fn mark_post_as_unread( + person_id: PersonId, + post_id: PostId, + pool: &DbPool, +) -> Result { + let post_read_form = PostReadForm { post_id, person_id }; + + blocking(pool, move |conn| { + PostRead::mark_as_unread(conn, &post_read_form) + }) + .await? + .map_err(|e| ApiError::err("couldnt_mark_post_as_read", e).into()) } pub async fn get_local_user_view_from_jwt( diff --git a/crates/api_common/src/post.rs b/crates/api_common/src/post.rs index d4a8c3f5..6e2c3179 100644 --- a/crates/api_common/src/post.rs +++ b/crates/api_common/src/post.rs @@ -92,6 +92,13 @@ pub struct RemovePost { pub auth: String, } +#[derive(Serialize, Deserialize)] +pub struct MarkPostAsRead { + pub post_id: PostId, + pub read: bool, + pub auth: String, +} + #[derive(Serialize, Deserialize)] pub struct LockPost { pub post_id: PostId, diff --git a/crates/api_crud/Cargo.toml b/crates/api_crud/Cargo.toml index 2b1cba76..33954e6e 100644 --- a/crates/api_crud/Cargo.toml +++ b/crates/api_crud/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lemmy_api_crud" -version = "0.14.1" +version = "0.14.3" edition = "2018" description = "A link aggregator for the fediverse" license = "AGPL-3.0" @@ -8,15 +8,15 @@ homepage = "https://join-lemmy.org/" documentation = "https://join-lemmy.org/docs/en/index.html" [dependencies] -lemmy_apub = { version = "=0.14.1", path = "../apub" } -lemmy_apub_lib = { version = "=0.14.1", path = "../apub_lib" } -lemmy_utils = { version = "=0.14.1", path = "../utils" } -lemmy_db_schema = { version = "=0.14.1", path = "../db_schema" } -lemmy_db_views = { version = "=0.14.1", path = "../db_views" } -lemmy_db_views_moderator = { version = "=0.14.1", path = "../db_views_moderator" } -lemmy_db_views_actor = { version = "=0.14.1", path = "../db_views_actor" } -lemmy_api_common = { version = "=0.14.1", path = "../api_common" } -lemmy_websocket = { version = "=0.14.1", path = "../websocket" } +lemmy_apub = { version = "=0.14.3", path = "../apub" } +lemmy_apub_lib = { version = "=0.14.3", path = "../apub_lib" } +lemmy_utils = { version = "=0.14.3", path = "../utils" } +lemmy_db_schema = { version = "=0.14.3", path = "../db_schema" } +lemmy_db_views = { version = "=0.14.3", path = "../db_views" } +lemmy_db_views_moderator = { version = "=0.14.3", path = "../db_views_moderator" } +lemmy_db_views_actor = { version = "=0.14.3", path = "../db_views_actor" } +lemmy_api_common = { version = "=0.14.3", path = "../api_common" } +lemmy_websocket = { version = "=0.14.3", path = "../websocket" } diesel = "1.4.8" bcrypt = "0.10.1" chrono = { version = "0.4.19", features = ["serde"] } diff --git a/crates/api_crud/src/comment/read.rs b/crates/api_crud/src/comment/read.rs index 4cd42bb9..4789b84f 100644 --- a/crates/api_crud/src/comment/read.rs +++ b/crates/api_crud/src/comment/read.rs @@ -12,10 +12,39 @@ use lemmy_db_schema::{ ListingType, SortType, }; -use lemmy_db_views::comment_view::CommentQueryBuilder; +use lemmy_db_views::comment_view::{CommentQueryBuilder, CommentView}; use lemmy_utils::{ApiError, ConnectionId, LemmyError}; use lemmy_websocket::LemmyContext; +#[async_trait::async_trait(?Send)] +impl PerformCrud for GetComment { + type Response = CommentResponse; + + async fn perform( + &self, + context: &Data, + _websocket_id: Option, + ) -> Result { + let data = self; + let local_user_view = + get_local_user_view_from_jwt_opt(&data.auth, context.pool(), context.secret()).await?; + + let person_id = local_user_view.map(|u| u.person.id); + let id = data.id; + let comment_view = blocking(context.pool(), move |conn| { + CommentView::read(conn, id, person_id) + }) + .await? + .map_err(|e| ApiError::err("couldnt_find_comment", e))?; + + Ok(Self::Response { + comment_view, + form_id: None, + recipient_ids: Vec::new(), + }) + } +} + #[async_trait::async_trait(?Send)] impl PerformCrud for GetComments { type Response = GetCommentsResponse; diff --git a/crates/api_crud/src/lib.rs b/crates/api_crud/src/lib.rs index f77632f9..9f1553ee 100644 --- a/crates/api_crud/src/lib.rs +++ b/crates/api_crud/src/lib.rs @@ -108,6 +108,9 @@ pub async fn match_websocket_operation_crud( UserOperationCrud::RemoveComment => { do_websocket_operation::(context, id, op, data).await } + UserOperationCrud::GetComment => { + do_websocket_operation::(context, id, op, data).await + } UserOperationCrud::GetComments => { do_websocket_operation::(context, id, op, data).await } diff --git a/crates/apub/Cargo.toml b/crates/apub/Cargo.toml index e7d49adb..8a5b2edc 100644 --- a/crates/apub/Cargo.toml +++ b/crates/apub/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lemmy_apub" -version = "0.14.1" +version = "0.14.3" edition = "2018" description = "A link aggregator for the fediverse" license = "AGPL-3.0" @@ -13,13 +13,13 @@ path = "src/lib.rs" doctest = false [dependencies] -lemmy_utils = { version = "=0.14.1", path = "../utils" } -lemmy_apub_lib = { version = "=0.14.1", path = "../apub_lib" } -lemmy_db_schema = { version = "=0.14.1", path = "../db_schema" } -lemmy_db_views = { version = "=0.14.1", path = "../db_views" } -lemmy_db_views_actor = { version = "=0.14.1", path = "../db_views_actor" } -lemmy_api_common = { version = "=0.14.1", path = "../api_common" } -lemmy_websocket = { version = "=0.14.1", path = "../websocket" } +lemmy_utils = { version = "=0.14.3", path = "../utils" } +lemmy_apub_lib = { version = "=0.14.3", path = "../apub_lib" } +lemmy_db_schema = { version = "=0.14.3", path = "../db_schema" } +lemmy_db_views = { version = "=0.14.3", path = "../db_views" } +lemmy_db_views_actor = { version = "=0.14.3", path = "../db_views_actor" } +lemmy_api_common = { version = "=0.14.3", path = "../api_common" } +lemmy_websocket = { version = "=0.14.3", path = "../websocket" } diesel = "1.4.8" activitystreams-kinds = "0.1.2" bcrypt = "0.10.1" diff --git a/crates/apub_lib/Cargo.toml b/crates/apub_lib/Cargo.toml index 0ab4b2b2..66ec3fc4 100644 --- a/crates/apub_lib/Cargo.toml +++ b/crates/apub_lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lemmy_apub_lib" -version = "0.14.1" +version = "0.14.3" edition = "2018" description = "A link aggregator for the fediverse" license = "AGPL-3.0" @@ -8,8 +8,8 @@ homepage = "https://join-lemmy.org/" documentation = "https://join-lemmy.org/docs/en/index.html" [dependencies] -lemmy_utils = { version = "=0.14.1", path = "../utils" } -lemmy_apub_lib_derive = { version = "=0.14.1", path = "../apub_lib_derive" } +lemmy_utils = { version = "=0.14.3", path = "../utils" } +lemmy_apub_lib_derive = { version = "=0.14.3", path = "../apub_lib_derive" } activitystreams = "0.7.0-alpha.11" serde = { version = "1.0.130", features = ["derive"] } async-trait = "0.1.51" diff --git a/crates/apub_lib_derive/Cargo.toml b/crates/apub_lib_derive/Cargo.toml index f3b6e85f..176e47b9 100644 --- a/crates/apub_lib_derive/Cargo.toml +++ b/crates/apub_lib_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lemmy_apub_lib_derive" -version = "0.14.1" +version = "0.14.3" edition = "2018" description = "A link aggregator for the fediverse" license = "AGPL-3.0" diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index f57228b6..2cdf74b0 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lemmy_db_schema" -version = "0.14.1" +version = "0.14.3" edition = "2018" description = "A link aggregator for the fediverse" license = "AGPL-3.0" @@ -11,8 +11,8 @@ documentation = "https://join-lemmy.org/docs/en/index.html" doctest = false [dependencies] -lemmy_utils = { version = "=0.14.1", path = "../utils" } -lemmy_apub_lib = { version = "=0.14.1", path = "../apub_lib" } +lemmy_utils = { version = "=0.14.3", path = "../utils" } +lemmy_apub_lib = { version = "=0.14.3", path = "../apub_lib" } diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"] } diesel_migrations = "1.4.0" chrono = { version = "0.4.19", features = ["serde"] } diff --git a/crates/db_views/Cargo.toml b/crates/db_views/Cargo.toml index 338b8302..c831bcd2 100644 --- a/crates/db_views/Cargo.toml +++ b/crates/db_views/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lemmy_db_views" -version = "0.14.1" +version = "0.14.3" edition = "2018" description = "A link aggregator for the fediverse" license = "AGPL-3.0" @@ -11,7 +11,7 @@ documentation = "https://join-lemmy.org/docs/en/index.html" doctest = false [dependencies] -lemmy_db_schema = { version = "=0.14.1", path = "../db_schema" } +lemmy_db_schema = { version = "=0.14.3", path = "../db_schema" } diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"] } serde = { version = "1.0.130", features = ["derive"] } tracing = "0.1.29" diff --git a/crates/db_views/src/comment_report_view.rs b/crates/db_views/src/comment_report_view.rs index 5b39a5eb..34385175 100644 --- a/crates/db_views/src/comment_report_view.rs +++ b/crates/db_views/src/comment_report_view.rs @@ -147,22 +147,28 @@ impl CommentReportView { let mut query = comment_report::table .inner_join(comment::table) .inner_join(post::table.on(comment::post_id.eq(post::id))) - .inner_join( - community_moderator::table.on(community_moderator::community_id.eq(post::community_id)), - ) .filter(comment_report::resolved.eq(false)) .into_boxed(); - // If its not an admin, get only the ones you mod - if !admin { - query = query.filter(community_moderator::person_id.eq(my_person_id)); - } - if let Some(community_id) = community_id { query = query.filter(post::community_id.eq(community_id)) } - query.select(count(comment_report::id)).first::(conn) + // If its not an admin, get only the ones you mod + if !admin { + query + .inner_join( + community_moderator::table.on( + community_moderator::community_id + .eq(post::community_id) + .and(community_moderator::person_id.eq(my_person_id)), + ), + ) + .select(count(comment_report::id)) + .first::(conn) + } else { + query.select(count(comment_report::id)).first::(conn) + } } } @@ -216,10 +222,6 @@ impl<'a> CommentReportQueryBuilder<'a> { .inner_join(community::table.on(post::community_id.eq(community::id))) .inner_join(person::table.on(comment_report::creator_id.eq(person::id))) .inner_join(person_alias_1::table.on(comment::creator_id.eq(person_alias_1::id))) - // Test this join - .inner_join( - community_moderator::table.on(community_moderator::community_id.eq(post::community_id)), - ) .inner_join( comment_aggregates::table.on(comment_report::comment_id.eq(comment_aggregates::comment_id)), ) @@ -254,11 +256,6 @@ impl<'a> CommentReportQueryBuilder<'a> { )) .into_boxed(); - // If its not an admin, get only the ones you mod - if !self.admin { - query = query.filter(community_moderator::person_id.eq(self.my_person_id)); - } - if let Some(community_id) = self.community_id { query = query.filter(post::community_id.eq(community_id)); } @@ -269,11 +266,25 @@ impl<'a> CommentReportQueryBuilder<'a> { let (limit, offset) = limit_and_offset(self.page, self.limit); - let res = query - .order_by(comment_report::published.asc()) + query = query + .order_by(comment_report::published.desc()) .limit(limit) - .offset(offset) - .load::(self.conn)?; + .offset(offset); + + // If its not an admin, get only the ones you mod + let res = if !self.admin { + query + .inner_join( + community_moderator::table.on( + community_moderator::community_id + .eq(post::community_id) + .and(community_moderator::person_id.eq(self.my_person_id)), + ), + ) + .load::(self.conn)? + } else { + query.load::(self.conn)? + }; Ok(CommentReportView::from_tuple_to_vec(res)) } @@ -498,8 +509,8 @@ mod tests { assert_eq!( reports, [ - expected_sara_report_view.to_owned(), - expected_jessica_report_view.to_owned() + expected_jessica_report_view.to_owned(), + expected_sara_report_view.to_owned() ] ); diff --git a/crates/db_views/src/post_report_view.rs b/crates/db_views/src/post_report_view.rs index f27ba50a..e5594487 100644 --- a/crates/db_views/src/post_report_view.rs +++ b/crates/db_views/src/post_report_view.rs @@ -131,23 +131,28 @@ impl PostReportView { use diesel::dsl::*; let mut query = post_report::table .inner_join(post::table) - // Test this join - .inner_join( - community_moderator::table.on(community_moderator::community_id.eq(post::community_id)), - ) .filter(post_report::resolved.eq(false)) .into_boxed(); - // If its not an admin, get only the ones you mod - if !admin { - query = query.filter(community_moderator::person_id.eq(my_person_id)); - } - if let Some(community_id) = community_id { query = query.filter(post::community_id.eq(community_id)) } - query.select(count(post_report::id)).first::(conn) + // If its not an admin, get only the ones you mod + if !admin { + query + .inner_join( + community_moderator::table.on( + community_moderator::community_id + .eq(post::community_id) + .and(community_moderator::person_id.eq(my_person_id)), + ), + ) + .select(count(post_report::id)) + .first::(conn) + } else { + query.select(count(post_report::id)).first::(conn) + } } } @@ -200,9 +205,6 @@ impl<'a> PostReportQueryBuilder<'a> { .inner_join(community::table.on(post::community_id.eq(community::id))) .inner_join(person::table.on(post_report::creator_id.eq(person::id))) .inner_join(person_alias_1::table.on(post::creator_id.eq(person_alias_1::id))) - .inner_join( - community_moderator::table.on(community_moderator::community_id.eq(post::community_id)), - ) .left_join( community_person_ban::table.on( post::community_id @@ -234,11 +236,6 @@ impl<'a> PostReportQueryBuilder<'a> { )) .into_boxed(); - // If its not an admin, get only the ones you mod - if !self.admin { - query = query.filter(community_moderator::person_id.eq(self.my_person_id)); - } - if let Some(community_id) = self.community_id { query = query.filter(post::community_id.eq(community_id)); } @@ -249,11 +246,25 @@ impl<'a> PostReportQueryBuilder<'a> { let (limit, offset) = limit_and_offset(self.page, self.limit); - let res = query - .order_by(post_report::published.asc()) + query = query + .order_by(post_report::published.desc()) .limit(limit) - .offset(offset) - .load::(self.conn)?; + .offset(offset); + + // If its not an admin, get only the ones you mod + let res = if !self.admin { + query + .inner_join( + community_moderator::table.on( + community_moderator::community_id + .eq(post::community_id) + .and(community_moderator::person_id.eq(self.my_person_id)), + ), + ) + .load::(self.conn)? + } else { + query.load::(self.conn)? + }; Ok(PostReportView::from_tuple_to_vec(res)) } @@ -481,8 +492,8 @@ mod tests { assert_eq!( reports, [ - expected_sara_report_view.to_owned(), - expected_jessica_report_view.to_owned() + expected_jessica_report_view.to_owned(), + expected_sara_report_view.to_owned() ] ); diff --git a/crates/db_views_actor/Cargo.toml b/crates/db_views_actor/Cargo.toml index 8ba30a28..36a29081 100644 --- a/crates/db_views_actor/Cargo.toml +++ b/crates/db_views_actor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lemmy_db_views_actor" -version = "0.14.1" +version = "0.14.3" edition = "2018" description = "A link aggregator for the fediverse" license = "AGPL-3.0" @@ -11,6 +11,6 @@ documentation = "https://join-lemmy.org/docs/en/index.html" doctest = false [dependencies] -lemmy_db_schema = { version = "=0.14.1", path = "../db_schema" } +lemmy_db_schema = { version = "=0.14.3", path = "../db_schema" } diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"] } serde = { version = "1.0.130", features = ["derive"] } diff --git a/crates/db_views_moderator/Cargo.toml b/crates/db_views_moderator/Cargo.toml index 24cf6fee..9128a955e 100644 --- a/crates/db_views_moderator/Cargo.toml +++ b/crates/db_views_moderator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lemmy_db_views_moderator" -version = "0.14.1" +version = "0.14.3" edition = "2018" description = "A link aggregator for the fediverse" license = "AGPL-3.0" @@ -11,6 +11,6 @@ documentation = "https://join-lemmy.org/docs/en/index.html" doctest = false [dependencies] -lemmy_db_schema = { version = "=0.14.1", path = "../db_schema" } +lemmy_db_schema = { version = "=0.14.3", path = "../db_schema" } diesel = { version = "1.4.8", features = ["postgres","chrono","r2d2","serde_json"] } serde = { version = "1.0.130", features = ["derive"] } diff --git a/crates/routes/Cargo.toml b/crates/routes/Cargo.toml index 357ae8a1..eee84184 100644 --- a/crates/routes/Cargo.toml +++ b/crates/routes/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lemmy_routes" -version = "0.14.1" +version = "0.14.3" edition = "2018" description = "A link aggregator for the fediverse" license = "AGPL-3.0" @@ -11,13 +11,13 @@ documentation = "https://join-lemmy.org/docs/en/index.html" doctest = false [dependencies] -lemmy_utils = { version = "=0.14.1", path = "../utils" } -lemmy_websocket = { version = "=0.14.1", path = "../websocket" } -lemmy_db_views = { version = "=0.14.1", path = "../db_views" } -lemmy_db_views_actor = { version = "=0.14.1", path = "../db_views_actor" } -lemmy_db_schema = { version = "=0.14.1", path = "../db_schema" } -lemmy_api_common = { version = "=0.14.1", path = "../api_common" } -lemmy_apub = { version = "=0.14.1", path = "../apub" } +lemmy_utils = { version = "=0.14.3", path = "../utils" } +lemmy_websocket = { version = "=0.14.3", path = "../websocket" } +lemmy_db_views = { version = "=0.14.3", path = "../db_views" } +lemmy_db_views_actor = { version = "=0.14.3", path = "../db_views_actor" } +lemmy_db_schema = { version = "=0.14.3", path = "../db_schema" } +lemmy_api_common = { version = "=0.14.3", path = "../api_common" } +lemmy_apub = { version = "=0.14.3", path = "../apub" } diesel = "1.4.8" actix = "0.12.0" actix-web = { version = "4.0.0-beta.9", default-features = false, features = ["rustls"] } diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index 02c6cadd..e30df048 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lemmy_utils" -version = "0.14.1" +version = "0.14.3" edition = "2018" description = "A link aggregator for the fediverse" license = "AGPL-3.0" diff --git a/crates/utils/src/utils.rs b/crates/utils/src/utils.rs index 1f3252ff..1c33b4c5 100644 --- a/crates/utils/src/utils.rs +++ b/crates/utils/src/utils.rs @@ -13,7 +13,7 @@ static MENTIONS_REGEX: Lazy = Lazy::new(|| { static VALID_ACTOR_NAME_REGEX: Lazy = Lazy::new(|| Regex::new(r"^[a-zA-Z0-9_]{3,}$").expect("compile regex")); static VALID_POST_TITLE_REGEX: Lazy = - Lazy::new(|| Regex::new(r".*\S.*").expect("compile regex")); + Lazy::new(|| Regex::new(r".*\S{3,}.*").expect("compile regex")); static VALID_MATRIX_ID_REGEX: Lazy = Lazy::new(|| { Regex::new(r"^@[A-Za-z0-9._=-]+:[A-Za-z0-9.-]+\.[A-Za-z]{2,}$").expect("compile regex") }); @@ -120,8 +120,14 @@ pub fn scrape_text_for_mentions(text: &str) -> Vec { out.into_iter().unique().collect() } +fn has_newline(name: &str) -> bool { + name.contains('\n') +} + pub fn is_valid_actor_name(name: &str, actor_name_max_length: usize) -> bool { - name.chars().count() <= actor_name_max_length && VALID_ACTOR_NAME_REGEX.is_match(name) + name.chars().count() <= actor_name_max_length + && VALID_ACTOR_NAME_REGEX.is_match(name) + && !has_newline(name) } // Can't do a regex here, reverse lookarounds not supported @@ -130,14 +136,15 @@ pub fn is_valid_display_name(name: &str, actor_name_max_length: usize) -> bool { && !name.starts_with('\u{200b}') && name.chars().count() >= 3 && name.chars().count() <= actor_name_max_length + && !has_newline(name) } pub fn is_valid_matrix_id(matrix_id: &str) -> bool { - VALID_MATRIX_ID_REGEX.is_match(matrix_id) + VALID_MATRIX_ID_REGEX.is_match(matrix_id) && !has_newline(matrix_id) } pub fn is_valid_post_title(title: &str) -> bool { - VALID_POST_TITLE_REGEX.is_match(title) + VALID_POST_TITLE_REGEX.is_match(title) && !has_newline(title) } pub fn get_ip(conn_info: &ConnectionInfo) -> IpAddr { @@ -166,7 +173,7 @@ pub fn clean_url_params(mut url: Url) -> Url { #[cfg(test)] mod tests { - use crate::utils::clean_url_params; + use crate::utils::{clean_url_params, is_valid_post_title}; use url::Url; #[test] @@ -180,4 +187,13 @@ mod tests { let cleaned = clean_url_params(url.clone()); assert_eq!(url.to_string(), cleaned.to_string()); } + + #[test] + fn regex_checks() { + assert!(!is_valid_post_title("hi")); + assert!(is_valid_post_title("him")); + assert!(!is_valid_post_title("n\n\n\n\nanother")); + assert!(!is_valid_post_title("hello there!\n this is a test.")); + assert!(is_valid_post_title("hello there! this is a test.")); + } } diff --git a/crates/websocket/Cargo.toml b/crates/websocket/Cargo.toml index 787faab1..6e9a7bf9 100644 --- a/crates/websocket/Cargo.toml +++ b/crates/websocket/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lemmy_websocket" -version = "0.14.1" +version = "0.14.3" edition = "2018" description = "A link aggregator for the fediverse" license = "AGPL-3.0" @@ -13,11 +13,11 @@ path = "src/lib.rs" doctest = false [dependencies] -lemmy_utils = { version = "=0.14.1", path = "../utils" } -lemmy_api_common = { version = "=0.14.1", path = "../api_common" } -lemmy_db_schema = { version = "=0.14.1", path = "../db_schema" } -lemmy_db_views = { version = "=0.14.1", path = "../db_views" } -lemmy_db_views_actor = { version = "=0.14.1", path = "../db_views_actor" } +lemmy_utils = { version = "=0.14.3", path = "../utils" } +lemmy_api_common = { version = "=0.14.3", path = "../api_common" } +lemmy_db_schema = { version = "=0.14.3", path = "../db_schema" } +lemmy_db_views = { version = "=0.14.3", path = "../db_views" } +lemmy_db_views_actor = { version = "=0.14.3", path = "../db_views_actor" } reqwest = { version = "0.11.4", features = ["json"] } tracing = "0.1.29" rand = "0.8.4" diff --git a/crates/websocket/src/chat_server.rs b/crates/websocket/src/chat_server.rs index 9fa258ff..2b58b2c1 100644 --- a/crates/websocket/src/chat_server.rs +++ b/crates/websocket/src/chat_server.rs @@ -491,7 +491,10 @@ impl ChatServer { } else { let user_operation = UserOperation::from_str(op)?; let fut = (message_handler)(context, msg.id, user_operation.clone(), data); - rate_limiter.message().wrap(ip, fut).await + match user_operation { + UserOperation::GetCaptcha => rate_limiter.post().wrap(ip, fut).await, + _ => rate_limiter.message().wrap(ip, fut).await, + } } } } diff --git a/crates/websocket/src/lib.rs b/crates/websocket/src/lib.rs index b7ab5bf2..f422ac51 100644 --- a/crates/websocket/src/lib.rs +++ b/crates/websocket/src/lib.rs @@ -110,6 +110,7 @@ pub enum UserOperation { CreatePostLike, LockPost, StickyPost, + MarkPostAsRead, SavePost, CreatePostReport, ResolvePostReport, @@ -168,6 +169,7 @@ pub enum UserOperationCrud { RemovePost, // Comment CreateComment, + GetComment, GetComments, EditComment, DeleteComment, diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index 18a125e0..17fb3201 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/dev/docker-compose.yml @@ -26,7 +26,7 @@ services: - postgres lemmy-ui: - image: dessalines/lemmy-ui:0.14.1 + image: dessalines/lemmy-ui:0.14.3 restart: always environment: - LEMMY_INTERNAL_HOST=lemmy:8536 diff --git a/docker/federation/docker-compose.yml b/docker/federation/docker-compose.yml index cf01bc9b..b33df805 100644 --- a/docker/federation/docker-compose.yml +++ b/docker/federation/docker-compose.yml @@ -28,7 +28,7 @@ services: - ./volumes/pictrs_alpha:/mnt lemmy-alpha-ui: - image: dessalines/lemmy-ui:0.14.1 + image: dessalines/lemmy-ui:0.14.3 environment: - LEMMY_INTERNAL_HOST=lemmy-alpha:8541 - LEMMY_EXTERNAL_HOST=localhost:8541 @@ -57,7 +57,7 @@ services: - ./volumes/postgres_alpha:/var/lib/postgresql/data lemmy-beta-ui: - image: dessalines/lemmy-ui:0.14.1 + image: dessalines/lemmy-ui:0.14.3 environment: - LEMMY_INTERNAL_HOST=lemmy-beta:8551 - LEMMY_EXTERNAL_HOST=localhost:8551 @@ -86,7 +86,7 @@ services: - ./volumes/postgres_beta:/var/lib/postgresql/data lemmy-gamma-ui: - image: dessalines/lemmy-ui:0.14.1 + image: dessalines/lemmy-ui:0.14.3 environment: - LEMMY_INTERNAL_HOST=lemmy-gamma:8561 - LEMMY_EXTERNAL_HOST=localhost:8561 @@ -116,7 +116,7 @@ services: # An instance with only an allowlist for beta lemmy-delta-ui: - image: dessalines/lemmy-ui:0.14.1 + image: dessalines/lemmy-ui:0.14.3 environment: - LEMMY_INTERNAL_HOST=lemmy-delta:8571 - LEMMY_EXTERNAL_HOST=localhost:8571 @@ -146,7 +146,7 @@ services: # An instance who has a blocklist, with lemmy-alpha blocked lemmy-epsilon-ui: - image: dessalines/lemmy-ui:0.14.1 + image: dessalines/lemmy-ui:0.14.3 environment: - LEMMY_INTERNAL_HOST=lemmy-epsilon:8581 - LEMMY_EXTERNAL_HOST=localhost:8581 diff --git a/docker/prod/docker-compose.yml b/docker/prod/docker-compose.yml index eade097d..0c5969b8 100644 --- a/docker/prod/docker-compose.yml +++ b/docker/prod/docker-compose.yml @@ -12,7 +12,7 @@ services: restart: always lemmy: - image: dessalines/lemmy:0.14.1 + image: dessalines/lemmy:0.14.3 ports: - "127.0.0.1:8536:8536" restart: always @@ -25,7 +25,7 @@ services: - pictrs lemmy-ui: - image: dessalines/lemmy-ui:0.14.1 + image: dessalines/lemmy-ui:0.14.3 ports: - "127.0.0.1:1235:1234" restart: always diff --git a/migrations/2021-11-22-135324_add_activity_ap_id_index/up.sql b/migrations/2021-11-22-135324_add_activity_ap_id_index/up.sql index fedd94f5..84530508 100644 --- a/migrations/2021-11-22-135324_add_activity_ap_id_index/up.sql +++ b/migrations/2021-11-22-135324_add_activity_ap_id_index/up.sql @@ -6,13 +6,13 @@ delete from activity where ap_id is null; alter table activity alter column ap_id set not null; -- Delete dupes, keeping the first one -delete -from activity -where id not in ( - select min(id) +delete from activity a using ( + select min(id) as id, ap_id from activity - group by ap_id -); + group by ap_id having count(*) > 1 +) b +where a.ap_id = b.ap_id +and a.id <> b.id; -- The index create unique index idx_activity_ap_id on activity(ap_id); diff --git a/migrations/2021-11-23-031528_add_report_published_index/down.sql b/migrations/2021-11-23-031528_add_report_published_index/down.sql new file mode 100644 index 00000000..b5e9b51c --- /dev/null +++ b/migrations/2021-11-23-031528_add_report_published_index/down.sql @@ -0,0 +1,2 @@ +drop index idx_comment_report_published; +drop index idx_post_report_published; diff --git a/migrations/2021-11-23-031528_add_report_published_index/up.sql b/migrations/2021-11-23-031528_add_report_published_index/up.sql new file mode 100644 index 00000000..eb0c1220 --- /dev/null +++ b/migrations/2021-11-23-031528_add_report_published_index/up.sql @@ -0,0 +1,2 @@ +create index idx_comment_report_published on comment_report (published desc); +create index idx_post_report_published on post_report (published desc); diff --git a/src/api_routes.rs b/src/api_routes.rs index 0349f518..ae5fa40c 100644 --- a/src/api_routes.rs +++ b/src/api_routes.rs @@ -83,6 +83,10 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { .route("", web::put().to(route_post_crud::)) .route("/delete", web::post().to(route_post_crud::)) .route("/remove", web::post().to(route_post_crud::)) + .route( + "/mark_as_read", + web::post().to(route_post::), + ) .route("/lock", web::post().to(route_post::)) .route("/sticky", web::post().to(route_post::)) .route("/list", web::get().to(route_get_crud::)) @@ -111,6 +115,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { .service( web::scope("/comment") .wrap(rate_limit.message()) + .route("", web::get().to(route_get_crud::)) .route("", web::put().to(route_post_crud::)) .route("/delete", web::post().to(route_post_crud::)) .route("/remove", web::post().to(route_post_crud::)) @@ -156,6 +161,12 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { .wrap(rate_limit.register()) .route(web::post().to(route_post_crud::)), ) + .service( + // Handle captcha separately + web::resource("/user/get_captcha") + .wrap(rate_limit.post()) + .route(web::get().to(route_get::)), + ) // User actions .service( web::scope("/user") @@ -173,7 +184,6 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { .route("/block", web::post().to(route_post::)) // Account actions. I don't like that they're in /user maybe /accounts .route("/login", web::post().to(route_post::)) - .route("/get_captcha", web::get().to(route_get::)) .route( "/delete_account", web::post().to(route_post_crud::),