]> Untitled Git - lemmy.git/commitdiff
update/fix migration, add some doc
authoreiknat <eiknat@dev.chapo.chat>
Wed, 4 Nov 2020 02:15:11 +0000 (21:15 -0500)
committereiknat <eiknat@dev.chapo.chat>
Wed, 11 Nov 2020 20:11:52 +0000 (15:11 -0500)
also run cargo fmt/clippy

16 files changed:
lemmy_api/src/comment.rs
lemmy_api/src/community.rs
lemmy_api/src/lib.rs
lemmy_api/src/post.rs
lemmy_api/src/user.rs
lemmy_db/src/comment_report.rs
lemmy_db/src/community.rs
lemmy_db/src/lib.rs
lemmy_db/src/post_report.rs
lemmy_db/src/schema.rs
lemmy_structs/src/comment.rs
lemmy_structs/src/user.rs
lemmy_websocket/src/chat_server.rs
lemmy_websocket/src/handlers.rs
migrations/2020-10-13-212240_create_report_tables/up.sql
src/routes/api.rs

index 083cb84101dd5dabd46e6c64556277e63d0a7411..b1107d0dc00c907422f1f3e178595436bcc0336a 100644 (file)
@@ -1,11 +1,11 @@
 use crate::{
   check_community_ban,
+  collect_moderated_communities,
   get_post,
   get_user_from_jwt,
   get_user_from_jwt_opt,
   is_mod_or_admin,
   Perform,
-  collect_moderated_communities,
 };
 use actix_web::web::Data;
 use lemmy_apub::{ApubLikeableType, ApubObjectType};
@@ -20,9 +20,9 @@ use lemmy_db::{
   Crud,
   Likeable,
   ListingType,
+  Reportable,
   Saveable,
   SortType,
-  Reportable,
 };
 use lemmy_structs::{blocking, comment::*, send_local_notifs};
 use lemmy_utils::{
@@ -32,9 +32,12 @@ use lemmy_utils::{
   ConnectionId,
   LemmyError,
 };
-use lemmy_websocket::{messages::{SendComment, SendUserRoomMessage}, LemmyContext, UserOperation};
+use lemmy_websocket::{
+  messages::{SendComment, SendModRoomMessage, SendUserRoomMessage},
+  LemmyContext,
+  UserOperation,
+};
 use std::str::FromStr;
-use lemmy_websocket::messages::SendModRoomMessage;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for CreateComment {
@@ -687,6 +690,7 @@ impl Perform for GetComments {
   }
 }
 
+/// Creates a comment report and notifies the moderators of the community
 #[async_trait::async_trait(?Send)]
 impl Perform for CreateCommentReport {
   type Response = CreateCommentReportResponse;
@@ -707,27 +711,30 @@ impl Perform for CreateCommentReport {
     if reason.len() > 1000 {
       return Err(APIError::err("report_too_long").into());
     }
-    
+
     let user_id = user.id;
     let comment_id = data.comment_id;
     let comment = blocking(context.pool(), move |conn| {
       CommentView::read(&conn, comment_id, None)
-    }).await??;
+    })
+    .await??;
 
     check_community_ban(user_id, comment.community_id, context.pool()).await?;
 
     let report_form = CommentReportForm {
       creator_id: user_id,
       comment_id,
-      comment_text: comment.content,
+      original_comment_text: comment.content,
       reason: data.reason.to_owned(),
     };
 
     let report = match blocking(context.pool(), move |conn| {
       CommentReport::report(conn, &report_form)
-    }).await? {
+    })
+    .await?
+    {
       Ok(report) => report,
-      Err(_e) => return Err(APIError::err("couldnt_create_report").into())
+      Err(_e) => return Err(APIError::err("couldnt_create_report").into()),
     };
 
     let res = CreateCommentReportResponse { success: true };
@@ -750,6 +757,7 @@ impl Perform for CreateCommentReport {
   }
 }
 
+/// Resolves or unresolves a comment report and notifies the moderators of the community
 #[async_trait::async_trait(?Send)]
 impl Perform for ResolveCommentReport {
   type Response = ResolveCommentReportResponse;
@@ -765,7 +773,8 @@ impl Perform for ResolveCommentReport {
     let report_id = data.report_id;
     let report = blocking(context.pool(), move |conn| {
       CommentReportView::read(&conn, report_id)
-    }).await??;
+    })
+    .await??;
 
     let user_id = user.id;
     is_mod_or_admin(context.pool(), user_id, report.community_id).await?;
@@ -779,8 +788,8 @@ impl Perform for ResolveCommentReport {
       }
     };
 
-    if blocking(context.pool(),resolve_fun).await?.is_err() {
-      return Err(APIError::err("couldnt_resolve_report").into())
+    if blocking(context.pool(), resolve_fun).await?.is_err() {
+      return Err(APIError::err("couldnt_resolve_report").into());
     };
 
     let report_id = data.report_id;
@@ -800,6 +809,8 @@ impl Perform for ResolveCommentReport {
   }
 }
 
+/// Lists comment reports for a community if an id is supplied
+/// or returns all comment reports for communities a user moderates
 #[async_trait::async_trait(?Send)]
 impl Perform for ListCommentReports {
   type Response = ListCommentReportsResponse;
@@ -814,18 +825,19 @@ impl Perform for ListCommentReports {
 
     let user_id = user.id;
     let community_id = data.community;
-    let community_ids = collect_moderated_communities(user_id, community_id, context.pool()).await?;
+    let community_ids =
+      collect_moderated_communities(user_id, community_id, context.pool()).await?;
 
     let page = data.page;
     let limit = data.limit;
     let comments = blocking(context.pool(), move |conn| {
       CommentReportQueryBuilder::create(conn)
-          .community_ids(community_ids)
-          .page(page)
-          .limit(limit)
-          .list()
+        .community_ids(community_ids)
+        .page(page)
+        .limit(limit)
+        .list()
     })
-        .await??;
+    .await??;
 
     let res = ListCommentReportsResponse { comments };
 
@@ -838,4 +850,4 @@ impl Perform for ListCommentReports {
 
     Ok(res)
   }
-}
\ No newline at end of file
+}
index 35ed4aa9c88128e2d4054c7917c3d090a7e5b0d6..861433a8677694140314053342790685343e7f18 100644 (file)
@@ -36,12 +36,11 @@ use lemmy_utils::{
   LemmyError,
 };
 use lemmy_websocket::{
-  messages::{GetCommunityUsersOnline, JoinCommunityRoom, SendCommunityRoomMessage},
+  messages::{GetCommunityUsersOnline, JoinCommunityRoom, JoinModRoom, SendCommunityRoomMessage},
   LemmyContext,
   UserOperation,
 };
 use std::str::FromStr;
-use lemmy_websocket::messages::JoinModRoom;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for GetCommunity {
index 96f2b0612666a31d069046c3cfe19f5ad5cefd40..7c5c5e2086dd33530a48e03429175e87a5d9e91c 100644 (file)
@@ -100,6 +100,13 @@ pub(in crate) async fn check_community_ban(
   }
 }
 
+/// Returns a list of communities that the user moderates
+/// or if a community_id is supplied validates the user is a moderator
+/// of that community and returns the community id in a vec
+///
+/// * `user_id` - the user id of the moderator
+/// * `community_id` - optional community id to check for moderator privileges
+/// * `pool` - the diesel db pool
 pub(in crate) async fn collect_moderated_communities(
   user_id: i32,
   community_id: Option<i32>,
@@ -112,7 +119,8 @@ pub(in crate) async fn collect_moderated_communities(
   } else {
     let ids = blocking(pool, move |conn: &'_ _| {
       CommunityModerator::get_user_moderated_communities(conn, user_id)
-    }).await??;
+    })
+    .await??;
     Ok(ids)
   }
 }
@@ -195,9 +203,7 @@ pub async fn match_websocket_operation(
     UserOperation::CommunityJoin => {
       do_websocket_operation::<CommunityJoin>(context, id, op, data).await
     }
-    UserOperation::ModJoin => {
-      do_websocket_operation::<ModJoin>(context, id, op, data).await
-    }
+    UserOperation::ModJoin => do_websocket_operation::<ModJoin>(context, id, op, data).await,
     UserOperation::SaveUserSettings => {
       do_websocket_operation::<SaveUserSettings>(context, id, op, data).await
     }
index b703c2ef8d06af302137147a014b389f2fe44184..707c833593d937c1a0d7ff7702ed44d8400b96be 100644 (file)
@@ -1,11 +1,11 @@
 use crate::{
   check_community_ban,
   check_optional_url,
+  collect_moderated_communities,
   get_user_from_jwt,
   get_user_from_jwt_opt,
   is_mod_or_admin,
   Perform,
-  collect_moderated_communities,
 };
 use actix_web::web::Data;
 use lemmy_apub::{ApubLikeableType, ApubObjectType};
@@ -21,9 +21,9 @@ use lemmy_db::{
   Crud,
   Likeable,
   ListingType,
+  Reportable,
   Saveable,
   SortType,
-  Reportable,
 };
 use lemmy_structs::{blocking, post::*};
 use lemmy_utils::{
@@ -35,13 +35,7 @@ use lemmy_utils::{
   LemmyError,
 };
 use lemmy_websocket::{
-  messages::{
-    GetPostUsersOnline,
-    JoinPostRoom,
-    SendModRoomMessage,
-    SendPost,
-    SendUserRoomMessage
-  },
+  messages::{GetPostUsersOnline, JoinPostRoom, SendModRoomMessage, SendPost, SendUserRoomMessage},
   LemmyContext,
   UserOperation,
 };
@@ -751,6 +745,7 @@ impl Perform for PostJoin {
   }
 }
 
+/// Creates a post report and notifies the moderators of the community
 #[async_trait::async_trait(?Send)]
 impl Perform for CreatePostReport {
   type Response = CreatePostReportResponse;
@@ -771,29 +766,32 @@ impl Perform for CreatePostReport {
     if reason.len() > 1000 {
       return Err(APIError::err("report_too_long").into());
     }
-    
+
     let user_id = user.id;
     let post_id = data.post_id;
     let post = blocking(context.pool(), move |conn| {
       PostView::read(&conn, post_id, None)
-    }).await??;
+    })
+    .await??;
 
     check_community_ban(user_id, post.community_id, context.pool()).await?;
 
     let report_form = PostReportForm {
       creator_id: user_id,
       post_id,
-      post_name: post.name,
-      post_url: post.url,
-      post_body: post.body,
+      original_post_name: post.name,
+      original_post_url: post.url,
+      original_post_body: post.body,
       reason: data.reason.to_owned(),
     };
 
     let report = match blocking(context.pool(), move |conn| {
       PostReport::report(conn, &report_form)
-    }).await? {
+    })
+    .await?
+    {
       Ok(report) => report,
-      Err(_e) => return Err(APIError::err("couldnt_create_report").into())
+      Err(_e) => return Err(APIError::err("couldnt_create_report").into()),
     };
 
     let res = CreatePostReportResponse { success: true };
@@ -816,6 +814,7 @@ impl Perform for CreatePostReport {
   }
 }
 
+/// Resolves or unresolves a post report and notifies the moderators of the community
 #[async_trait::async_trait(?Send)]
 impl Perform for ResolvePostReport {
   type Response = ResolvePostReportResponse;
@@ -831,7 +830,8 @@ impl Perform for ResolvePostReport {
     let report_id = data.report_id;
     let report = blocking(context.pool(), move |conn| {
       PostReportView::read(&conn, report_id)
-    }).await??;
+    })
+    .await??;
 
     let user_id = user.id;
     is_mod_or_admin(context.pool(), user_id, report.community_id).await?;
@@ -850,8 +850,8 @@ impl Perform for ResolvePostReport {
       resolved: true,
     };
 
-    if blocking(context.pool(),resolve_fun).await?.is_err() {
-      return Err(APIError::err("couldnt_resolve_report").into())
+    if blocking(context.pool(), resolve_fun).await?.is_err() {
+      return Err(APIError::err("couldnt_resolve_report").into());
     };
 
     context.chat_server().do_send(SendModRoomMessage {
@@ -865,6 +865,8 @@ impl Perform for ResolvePostReport {
   }
 }
 
+/// Lists post reports for a community if an id is supplied
+/// or returns all post reports for communities a user moderates
 #[async_trait::async_trait(?Send)]
 impl Perform for ListPostReports {
   type Response = ListPostReportsResponse;
@@ -879,18 +881,19 @@ impl Perform for ListPostReports {
 
     let user_id = user.id;
     let community_id = data.community;
-    let community_ids = collect_moderated_communities(user_id, community_id, context.pool()).await?;
+    let community_ids =
+      collect_moderated_communities(user_id, community_id, context.pool()).await?;
 
     let page = data.page;
     let limit = data.limit;
     let posts = blocking(context.pool(), move |conn| {
       PostReportQueryBuilder::create(conn)
-          .community_ids(community_ids)
-          .page(page)
-          .limit(limit)
-          .list()
+        .community_ids(community_ids)
+        .page(page)
+        .limit(limit)
+        .list()
     })
-        .await??;
+    .await??;
 
     let res = ListPostReportsResponse { posts };
 
index 5efc63310cf77b7404a8f21eed732a08057f9119..3b0b6d3fe47f4b9f925642478ab2b371e4ef8da3 100644 (file)
@@ -2,11 +2,11 @@ use crate::{
   captcha_espeak_wav_base64,
   check_optional_url,
   claims::Claims,
+  collect_moderated_communities,
   get_user_from_jwt,
   get_user_from_jwt_opt,
   is_admin,
   Perform,
-  collect_moderated_communities
 };
 use actix_web::web::Data;
 use anyhow::Context;
@@ -1312,7 +1312,8 @@ impl Perform for GetReportCount {
 
     let user_id = user.id;
     let community_id = data.community;
-    let community_ids = collect_moderated_communities(user_id, community_id, context.pool()).await?;
+    let community_ids =
+      collect_moderated_communities(user_id, community_id, context.pool()).await?;
 
     let res = {
       if community_ids.is_empty() {
@@ -1323,12 +1324,16 @@ impl Perform for GetReportCount {
         }
       } else {
         let ids = community_ids.clone();
-        let comment_reports = blocking(context.pool(), move |conn|
-            CommentReportView::get_report_count(conn, &ids)).await??;
+        let comment_reports = blocking(context.pool(), move |conn| {
+          CommentReportView::get_report_count(conn, &ids)
+        })
+        .await??;
 
         let ids = community_ids.clone();
-        let post_reports = blocking(context.pool(), move |conn|
-            PostReportView::get_report_count(conn, &ids)).await??;
+        let post_reports = blocking(context.pool(), move |conn| {
+          PostReportView::get_report_count(conn, &ids)
+        })
+        .await??;
 
         GetReportCountResponse {
           community: data.community,
index 83f43240702c5b3f612e45845179f7c6c28eb778..b1037f111ba0bcbc216c09e33bc8d18560ce9c58 100644 (file)
@@ -1,14 +1,21 @@
 use diesel::{dsl::*, pg::Pg, result::Error, *};
 use serde::{Deserialize, Serialize};
 
-use crate::{limit_and_offset, MaybeOptional, schema::comment_report, comment::Comment, Reportable, naive_now};
+use crate::{
+  comment::Comment,
+  limit_and_offset,
+  naive_now,
+  schema::comment_report,
+  MaybeOptional,
+  Reportable,
+};
 
 table! {
     comment_report_view (id) {
       id -> Int4,
       creator_id -> Int4,
       comment_id -> Int4,
-      comment_text -> Text,
+      original_comment_text -> Text,
       reason -> Text,
       resolved -> Bool,
       resolver_id -> Nullable<Int4>,
@@ -43,7 +50,7 @@ pub struct CommentReport {
   pub id: i32,
   pub creator_id: i32,
   pub comment_id: i32,
-  pub comment_text: String,
+  pub original_comment_text: String,
   pub reason: String,
   pub resolved: bool,
   pub resolver_id: Option<i32>,
@@ -56,11 +63,15 @@ pub struct CommentReport {
 pub struct CommentReportForm {
   pub creator_id: i32,
   pub comment_id: i32,
-  pub comment_text: String,
+  pub original_comment_text: String,
   pub reason: String,
 }
 
 impl Reportable<CommentReportForm> for CommentReport {
+  /// creates a comment report and returns it
+  ///
+  /// * `conn` - the postgres connection
+  /// * `comment_report_form` - the filled CommentReportForm to insert
   fn report(conn: &PgConnection, comment_report_form: &CommentReportForm) -> Result<Self, Error> {
     use crate::schema::comment_report::dsl::*;
     insert_into(comment_report)
@@ -68,6 +79,11 @@ impl Reportable<CommentReportForm> for CommentReport {
       .get_result::<Self>(conn)
   }
 
+  /// resolve a comment report
+  ///
+  /// * `conn` - the postgres connection
+  /// * `report_id` - the id of the report to resolve
+  /// * `by_resolver_id` - the id of the user resolving the report
   fn resolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result<usize, Error> {
     use crate::schema::comment_report::dsl::*;
     update(comment_report.find(report_id))
@@ -79,6 +95,11 @@ impl Reportable<CommentReportForm> for CommentReport {
       .execute(conn)
   }
 
+  /// unresolve a comment report
+  ///
+  /// * `conn` - the postgres connection
+  /// * `report_id` - the id of the report to unresolve
+  /// * `by_resolver_id` - the id of the user unresolving the report
   fn unresolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result<usize, Error> {
     use crate::schema::comment_report::dsl::*;
     update(comment_report.find(report_id))
@@ -91,15 +112,13 @@ impl Reportable<CommentReportForm> for CommentReport {
   }
 }
 
-#[derive(
-Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, Clone,
-)]
+#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, Clone)]
 #[table_name = "comment_report_view"]
 pub struct CommentReportView {
   pub id: i32,
   pub creator_id: i32,
   pub comment_id: i32,
-  pub comment_text: String,
+  pub original_comment_text: String,
   pub reason: String,
   pub resolved: bool,
   pub resolver_id: Option<i32>,
@@ -136,19 +155,23 @@ pub struct CommentReportQueryBuilder<'a> {
 }
 
 impl CommentReportView {
+  /// returns the CommentReportView for the provided report_id
+  ///
+  /// * `report_id` - the report id to obtain
   pub fn read(conn: &PgConnection, report_id: i32) -> Result<Self, Error> {
     use super::comment_report::comment_report_view::dsl::*;
-    comment_report_view
-      .find(report_id)
-      .first::<Self>(conn)
+    comment_report_view.find(report_id).first::<Self>(conn)
   }
 
-  pub fn get_report_count(conn: &PgConnection, community_ids: &Vec<i32>) -> Result<i32, Error> {
+  /// returns the current unresolved comment report count for the supplied community ids
+  ///
+  /// * `community_ids` - a Vec<i32> of community_ids to get a count for
+  pub fn get_report_count(conn: &PgConnection, community_ids: &Vec<i32>) -> Result<i64, Error> {
     use super::comment_report::comment_report_view::dsl::*;
     comment_report_view
       .filter(resolved.eq(false).and(community_id.eq_any(community_ids)))
-      .select(sql::<sql_types::Integer>("COUNT(*)"))
-      .first::<i32>(conn)
+      .select(count(id))
+      .first::<i64>(conn)
   }
 }
 
index a888015e41264c19dcbd861c703df78fa690d9ed..b047439864ae6ce48b906c6c721c74ab76e125c6 100644 (file)
@@ -225,12 +225,15 @@ impl CommunityModerator {
     diesel::delete(community_moderator.filter(community_id.eq(for_community_id))).execute(conn)
   }
 
-  pub fn get_user_moderated_communities(conn: &PgConnection, for_user_id: i32) -> Result<Vec<i32>, Error> {
+  pub fn get_user_moderated_communities(
+    conn: &PgConnection,
+    for_user_id: i32,
+  ) -> Result<Vec<i32>, Error> {
     use crate::schema::community_moderator::dsl::*;
     community_moderator
-        .filter(user_id.eq(for_user_id))
-        .select(community_id)
-        .load::<i32>(conn)
+      .filter(user_id.eq(for_user_id))
+      .select(community_id)
+      .load::<i32>(conn)
   }
 }
 
index d7f59d03fbf7e3de9e48f57d649af38719c7a9ed..655ba68b0afc977baad053f29f80477963302520 100644 (file)
@@ -113,14 +113,14 @@ pub trait Readable<T> {
 
 pub trait Reportable<T> {
   fn report(conn: &PgConnection, form: &T) -> Result<Self, Error>
-    where
-        Self: Sized;
+  where
+    Self: Sized;
   fn resolve(conn: &PgConnection, report_id: i32, resolver_id: i32) -> Result<usize, Error>
-    where
-        Self: Sized;
+  where
+    Self: Sized;
   fn unresolve(conn: &PgConnection, report_id: i32, resolver_id: i32) -> Result<usize, Error>
-    where
-        Self: Sized;
+  where
+    Self: Sized;
 }
 
 pub trait MaybeOptional<T> {
index 61c32c0e2e8930d18e483bd1b6e801540c41ef66..3422f54a5dff2ec6645fd86a2fcc1e2f159e5952 100644 (file)
@@ -1,16 +1,23 @@
 use diesel::{dsl::*, pg::Pg, result::Error, *};
 use serde::{Deserialize, Serialize};
 
-use crate::{limit_and_offset, MaybeOptional, schema::post_report, post::Post, Reportable, naive_now};
+use crate::{
+  limit_and_offset,
+  naive_now,
+  post::Post,
+  schema::post_report,
+  MaybeOptional,
+  Reportable,
+};
 
 table! {
     post_report_view (id) {
         id -> Int4,
         creator_id -> Int4,
         post_id -> Int4,
-        post_name -> Varchar,
-        post_url -> Nullable<Text>,
-        post_body -> Nullable<Text>,
+        original_post_name -> Varchar,
+        original_post_url -> Nullable<Text>,
+        original_post_body -> Nullable<Text>,
         reason -> Text,
         resolved -> Bool,
         resolver_id -> Nullable<Int4>,
@@ -46,9 +53,9 @@ pub struct PostReport {
   pub id: i32,
   pub creator_id: i32,
   pub post_id: i32,
-  pub post_name: String,
-  pub post_url: Option<String>,
-  pub post_body: Option<String>,
+  pub original_post_name: String,
+  pub original_post_url: Option<String>,
+  pub original_post_body: Option<String>,
   pub reason: String,
   pub resolved: bool,
   pub resolver_id: Option<i32>,
@@ -61,13 +68,17 @@ pub struct PostReport {
 pub struct PostReportForm {
   pub creator_id: i32,
   pub post_id: i32,
-  pub post_name: String,
-  pub post_url: Option<String>,
-  pub post_body: Option<String>,
+  pub original_post_name: String,
+  pub original_post_url: Option<String>,
+  pub original_post_body: Option<String>,
   pub reason: String,
 }
 
 impl Reportable<PostReportForm> for PostReport {
+  /// creates a post report and returns it
+  ///
+  /// * `conn` - the postgres connection
+  /// * `post_report_form` - the filled CommentReportForm to insert
   fn report(conn: &PgConnection, post_report_form: &PostReportForm) -> Result<Self, Error> {
     use crate::schema::post_report::dsl::*;
     insert_into(post_report)
@@ -75,6 +86,11 @@ impl Reportable<PostReportForm> for PostReport {
       .get_result::<Self>(conn)
   }
 
+  /// resolve a post report
+  ///
+  /// * `conn` - the postgres connection
+  /// * `report_id` - the id of the report to resolve
+  /// * `by_resolver_id` - the id of the user resolving the report
   fn resolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result<usize, Error> {
     use crate::schema::post_report::dsl::*;
     update(post_report.find(report_id))
@@ -86,6 +102,11 @@ impl Reportable<PostReportForm> for PostReport {
       .execute(conn)
   }
 
+  /// resolve a post report
+  ///
+  /// * `conn` - the postgres connection
+  /// * `report_id` - the id of the report to unresolve
+  /// * `by_resolver_id` - the id of the user unresolving the report
   fn unresolve(conn: &PgConnection, report_id: i32, by_resolver_id: i32) -> Result<usize, Error> {
     use crate::schema::post_report::dsl::*;
     update(post_report.find(report_id))
@@ -98,17 +119,15 @@ impl Reportable<PostReportForm> for PostReport {
   }
 }
 
-#[derive(
-Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, Clone,
-)]
+#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, Clone)]
 #[table_name = "post_report_view"]
 pub struct PostReportView {
   pub id: i32,
   pub creator_id: i32,
   pub post_id: i32,
-  pub post_name: String,
-  pub post_url: Option<String>,
-  pub post_body: Option<String>,
+  pub original_post_name: String,
+  pub original_post_url: Option<String>,
+  pub original_post_body: Option<String>,
   pub reason: String,
   pub resolved: bool,
   pub resolver_id: Option<i32>,
@@ -137,19 +156,23 @@ pub struct PostReportView {
 }
 
 impl PostReportView {
+  /// returns the PostReportView for the provided report_id
+  ///
+  /// * `report_id` - the report id to obtain
   pub fn read(conn: &PgConnection, report_id: i32) -> Result<Self, Error> {
     use super::post_report::post_report_view::dsl::*;
-    post_report_view
-      .find(report_id)
-      .first::<Self>(conn)
+    post_report_view.find(report_id).first::<Self>(conn)
   }
 
-  pub fn get_report_count(conn: &PgConnection, community_ids: &Vec<i32>) -> Result<i32, Error> {
+  /// returns the current unresolved post report count for the supplied community ids
+  ///
+  /// * `community_ids` - a Vec<i32> of community_ids to get a count for
+  pub fn get_report_count(conn: &PgConnection, community_ids: &Vec<i32>) -> Result<i64, Error> {
     use super::post_report::post_report_view::dsl::*;
     post_report_view
       .filter(resolved.eq(false).and(community_id.eq_any(community_ids)))
-      .select(sql::<sql_types::Integer>("COUNT(*)"))
-      .first::<i32>(conn)
+      .select(count(id))
+      .first::<i64>(conn)
   }
 }
 
index b23deff34818d13d83686c111cfd708a837f4445..400c87d420ab3e97ac0f9f8e3f8e54029cb9998f 100644 (file)
@@ -86,7 +86,7 @@ table! {
         id -> Int4,
         creator_id -> Int4,
         comment_id -> Int4,
-        comment_text -> Text,
+        original_comment_text -> Text,
         reason -> Text,
         resolved -> Bool,
         resolver_id -> Nullable<Int4>,
@@ -389,9 +389,9 @@ table! {
         id -> Int4,
         creator_id -> Int4,
         post_id -> Int4,
-        post_name -> Varchar,
-        post_url -> Nullable<Text>,
-        post_body -> Nullable<Text>,
+        original_post_name -> Varchar,
+        original_post_url -> Nullable<Text>,
+        original_post_body -> Nullable<Text>,
         reason -> Text,
         resolved -> Bool,
         resolver_id -> Nullable<Int4>,
index 5ca7a532544105b2b990ec0e68c3b071946cd3cf..ed292caed4eb37b27937b3cef3da6e8205522960 100644 (file)
@@ -1,7 +1,4 @@
-use lemmy_db::{
-  comment_view::CommentView,
-  comment_report::CommentReportView,
-};
+use lemmy_db::{comment_report::CommentReportView, comment_view::CommentView};
 use serde::{Deserialize, Serialize};
 
 #[derive(Deserialize)]
index 03a84ce4cd579b9dbac9eb77b2f0678e8d4103d5..bf4a362860557365dedfe8c8f1ec2967ab1371c7 100644 (file)
@@ -247,6 +247,6 @@ pub struct GetReportCount {
 #[derive(Serialize, Deserialize, Clone, Debug)]
 pub struct GetReportCountResponse {
   pub community: Option<i32>,
-  pub comment_reports: i32,
-  pub post_reports: i32,
+  pub comment_reports: i64,
+  pub post_reports: i64,
 }
index 0a524e3db002129bf92323db93c1b780cc9c99fd..0be54c33f8fb2241bf3ac41811aad652195d8699 100644 (file)
@@ -260,8 +260,8 @@ impl ChatServer {
     community_id: CommunityId,
     websocket_id: Option<ConnectionId>,
   ) -> Result<(), LemmyError>
-    where
-      Response: Serialize,
+  where
+    Response: Serialize,
   {
     let res_str = &serialize_websocket_message(op, response)?;
     if let Some(sessions) = self.mod_rooms.get(&community_id) {
index 0b5703ab1ea94d29cd4262a0fd926e4958dde760..d95dfd57fab8d82b5d882badccfbe2970b81c7a2 100644 (file)
@@ -121,8 +121,8 @@ where
 }
 
 impl<Response> Handler<SendModRoomMessage<Response>> for ChatServer
-  where
-    Response: Serialize,
+where
+  Response: Serialize,
 {
   type Result = ();
 
index c0547d084b9fe6616765ed64aac2ccf430bb59b3..e9dce1adb327996dab53b3fad71f2d2d7461c193 100644 (file)
@@ -2,7 +2,7 @@ create table comment_report (
   id            serial    primary key,
   creator_id    int       references user_ on update cascade on delete cascade not null,   -- user reporting comment
   comment_id    int       references comment on update cascade on delete cascade not null, -- comment being reported
-  comment_text  text      not null,
+  original_comment_text  text      not null,
   reason        text      not null,
   resolved      bool      not null default false,
   resolver_id   int       references user_ on update cascade on delete cascade,   -- user resolving report
@@ -15,9 +15,9 @@ create table post_report (
   id            serial    primary key,
   creator_id    int       references user_ on update cascade on delete cascade not null, -- user reporting post
   post_id       int       references post on update cascade on delete cascade not null,  -- post being reported
-  post_name        varchar(100) not null,
-  post_url      text,
-  post_body     text,
+  original_post_name     varchar(100) not null,
+  original_post_url       text,
+  original_post_body      text,
   reason        text      not null,
   resolved      bool      not null default false,
   resolver_id   int       references user_ on update cascade on delete cascade,   -- user resolving report
@@ -54,7 +54,7 @@ from comment_report cr
 left join comment c on c.id = cr.comment_id
 left join post p on p.id = c.post_id
 left join user_ u on u.id = c.creator_id
-left join user_ f on f.id = cr.creator_id;
+left join user_ f on f.id = cr.creator_id
 left join user_ r on r.id = cr.resolver_id;
 
 create or replace view post_report_view as
@@ -63,7 +63,6 @@ p.name as current_post_name,
 p.url as current_post_url,
 p.body as current_post_body,
 p.community_id,
-f.name as creator_name,
 -- report creator details
 f.actor_id as creator_actor_id,
 f.name as creator_name,
@@ -86,5 +85,5 @@ r.local as resolver_local
 from post_report pr
 left join post p on p.id = pr.post_id
 left join user_ u on u.id = p.creator_id
-left join user_ f on f.id = pr.creator_id;
+left join user_ f on f.id = pr.creator_id
 left join user_ r on r.id = pr.resolver_id;
index 7b95b4ee4aff32c44c337b45a3a883e71404740f..167797d7da90e088e6924e5d87bee8cdbcb8d47b 100644 (file)
@@ -82,8 +82,11 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
           .route("/save", web::put().to(route_post::<SavePost>))
           .route("/join", web::post().to(route_post::<PostJoin>))
           .route("/report", web::post().to(route_post::<CreatePostReport>))
-          .route("/report/resolve", web::put().to(route_post::<ResolvePostReport>))
-          .route("/report/list", web::get().to(route_get::<ListPostReports>))
+          .route(
+            "/report/resolve",
+            web::put().to(route_post::<ResolvePostReport>),
+          )
+          .route("/report/list", web::get().to(route_get::<ListPostReports>)),
       )
       // Comment
       .service(
@@ -101,8 +104,14 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
           .route("/save", web::put().to(route_post::<SaveComment>))
           .route("/list", web::get().to(route_get::<GetComments>))
           .route("/report", web::post().to(route_post::<CreateCommentReport>))
-          .route("/report/resolve", web::put().to(route_post::<ResolveCommentReport>))
-          .route("/report/list", web::get().to(route_get::<ListCommentReports>))
+          .route(
+            "/report/resolve",
+            web::put().to(route_post::<ResolveCommentReport>),
+          )
+          .route(
+            "/report/list",
+            web::get().to(route_get::<ListCommentReports>),
+          ),
       )
       // Private Message
       .service(
@@ -171,10 +180,7 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
             "/save_user_settings",
             web::put().to(route_post::<SaveUserSettings>),
           )
-          .route(
-            "/report_count",
-            web::get().to(route_get::<GetReportCount>)
-          ),
+          .route("/report_count", web::get().to(route_get::<GetReportCount>)),
       )
       // Admin Actions
       .service(