]> Untitled Git - lemmy.git/commitdiff
add more details to the report views
authoreiknat <eiknat@dev.chapo.chat>
Tue, 3 Nov 2020 03:06:20 +0000 (22:06 -0500)
committereiknat <eiknat@dev.chapo.chat>
Wed, 11 Nov 2020 20:11:52 +0000 (15:11 -0500)
lemmy_api/src/comment.rs
lemmy_api/src/community.rs
lemmy_api/src/post.rs
lemmy_db/src/comment_report.rs
lemmy_db/src/lib.rs
lemmy_db/src/post_report.rs
migrations/2020-10-13-212240_create_report_tables/up.sql

index 2b0ee0544459b338cd3e0b1b11744150b411e74d..083cb84101dd5dabd46e6c64556277e63d0a7411 100644 (file)
@@ -775,7 +775,7 @@ impl Perform for ResolveCommentReport {
       if resolved {
         CommentReport::resolve(conn, report_id.clone(), user_id)
       } else {
-        CommentReport::unresolve(conn, report_id.clone())
+        CommentReport::unresolve(conn, report_id.clone(), user_id)
       }
     };
 
index ae19c5f8f85ebfdfe78d3dd0b4cfed5feff23061..35ed4aa9c88128e2d4054c7917c3d090a7e5b0d6 100644 (file)
@@ -885,7 +885,6 @@ impl Perform for CommunityJoin {
   }
 }
 
-// is this the right place for this?
 #[async_trait::async_trait(?Send)]
 impl Perform for ModJoin {
   type Response = ModJoinResponse;
index 0abb879cf81ae9923ddb91aa5b7972ce4cbe0009..b703c2ef8d06af302137147a014b389f2fe44184 100644 (file)
@@ -841,7 +841,7 @@ impl Perform for ResolvePostReport {
       if resolved {
         PostReport::resolve(conn, report_id.clone(), user_id)
       } else {
-        PostReport::unresolve(conn, report_id.clone())
+        PostReport::unresolve(conn, report_id.clone(), user_id)
       }
     };
 
index a5ac701c197b8fdfb26404fd9e3f2cdd231e43af..83f43240702c5b3f612e45845179f7c6c28eb778 100644 (file)
@@ -17,9 +17,22 @@ table! {
       post_id -> Int4,
       current_comment_text -> Text,
       community_id -> Int4,
+      creator_actor_id -> Text,
       creator_name -> Varchar,
+      creator_preferred_username -> Nullable<Varchar>,
+      creator_avatar -> Nullable<Text>,
+      creator_local -> Bool,
       comment_creator_id -> Int4,
+      comment_creator_actor_id -> Text,
       comment_creator_name -> Varchar,
+      comment_creator_preferred_username -> Nullable<Varchar>,
+      comment_creator_avatar -> Nullable<Text>,
+      comment_creator_local -> Bool,
+      resolver_actor_id -> Nullable<Text>,
+      resolver_name -> Nullable<Varchar>,
+      resolver_preferred_username -> Nullable<Varchar>,
+      resolver_avatar -> Nullable<Text>,
+      resolver_local -> Nullable<Bool>,
     }
 }
 
@@ -55,22 +68,23 @@ impl Reportable<CommentReportForm> for CommentReport {
       .get_result::<Self>(conn)
   }
 
-  fn resolve(conn: &PgConnection, report_id: i32, by_user_id: i32) -> Result<usize, Error> {
+  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))
       .set((
         resolved.eq(true),
-        resolver_id.eq(by_user_id),
+        resolver_id.eq(by_resolver_id),
         updated.eq(naive_now()),
       ))
       .execute(conn)
   }
 
-  fn unresolve(conn: &PgConnection, report_id: i32) -> Result<usize, Error> {
+  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))
       .set((
         resolved.eq(false),
+        resolver_id.eq(by_resolver_id),
         updated.eq(naive_now()),
       ))
       .execute(conn)
@@ -94,9 +108,22 @@ pub struct CommentReportView {
   pub post_id: i32,
   pub current_comment_text: String,
   pub community_id: i32,
+  pub creator_actor_id: String,
   pub creator_name: String,
+  pub creator_preferred_username: Option<String>,
+  pub creator_avatar: Option<String>,
+  pub creator_local: bool,
   pub comment_creator_id: i32,
+  pub comment_creator_actor_id: String,
   pub comment_creator_name: String,
+  pub comment_creator_preferred_username: Option<String>,
+  pub comment_creator_avatar: Option<String>,
+  pub comment_creator_local: bool,
+  pub resolver_actor_id: Option<String>,
+  pub resolver_name: Option<String>,
+  pub resolver_preferred_username: Option<String>,
+  pub resolver_avatar: Option<String>,
+  pub resolver_local: Option<bool>,
 }
 
 pub struct CommentReportQueryBuilder<'a> {
index cf578c4cb4b82ee6ba816cf33f76560368cf30f8..d7f59d03fbf7e3de9e48f57d649af38719c7a9ed 100644 (file)
@@ -115,10 +115,10 @@ pub trait Reportable<T> {
   fn report(conn: &PgConnection, form: &T) -> Result<Self, Error>
     where
         Self: Sized;
-  fn resolve(conn: &PgConnection, report_id: i32, user_id: i32) -> Result<usize, Error>
+  fn resolve(conn: &PgConnection, report_id: i32, resolver_id: i32) -> Result<usize, Error>
     where
         Self: Sized;
-  fn unresolve(conn: &PgConnection, report_id: i32) -> Result<usize, Error>
+  fn unresolve(conn: &PgConnection, report_id: i32, resolver_id: i32) -> Result<usize, Error>
     where
         Self: Sized;
 }
index 234b0e4dbfd2b9305f3216fd2ac49607503f8a10..61c32c0e2e8930d18e483bd1b6e801540c41ef66 100644 (file)
@@ -20,9 +20,22 @@ table! {
         current_post_url -> Nullable<Text>,
         current_post_body -> Nullable<Text>,
         community_id -> Int4,
+        creator_actor_id -> Text,
         creator_name -> Varchar,
+        creator_preferred_username -> Nullable<Varchar>,
+        creator_avatar -> Nullable<Text>,
+        creator_local -> Bool,
         post_creator_id -> Int4,
+        post_creator_actor_id -> Text,
         post_creator_name -> Varchar,
+        post_creator_preferred_username -> Nullable<Varchar>,
+        post_creator_avatar -> Nullable<Text>,
+        post_creator_local -> Bool,
+        resolver_actor_id -> Nullable<Text>,
+        resolver_name -> Nullable<Varchar>,
+        resolver_preferred_username -> Nullable<Varchar>,
+        resolver_avatar -> Nullable<Text>,
+        resolver_local -> Nullable<Bool>,
     }
 }
 
@@ -62,22 +75,23 @@ impl Reportable<PostReportForm> for PostReport {
       .get_result::<Self>(conn)
   }
 
-  fn resolve(conn: &PgConnection, report_id: i32, by_user_id: i32) -> Result<usize, Error> {
+  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))
       .set((
         resolved.eq(true),
-        resolver_id.eq(by_user_id),
+        resolver_id.eq(by_resolver_id),
         updated.eq(naive_now()),
       ))
       .execute(conn)
   }
 
-  fn unresolve(conn: &PgConnection, report_id: i32) -> Result<usize, Error> {
+  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))
       .set((
         resolved.eq(false),
+        resolver_id.eq(by_resolver_id),
         updated.eq(naive_now()),
       ))
       .execute(conn)
@@ -104,9 +118,22 @@ pub struct PostReportView {
   pub current_post_url: Option<String>,
   pub current_post_body: Option<String>,
   pub community_id: i32,
+  pub creator_actor_id: String,
   pub creator_name: String,
+  pub creator_preferred_username: Option<String>,
+  pub creator_avatar: Option<String>,
+  pub creator_local: bool,
   pub post_creator_id: i32,
+  pub post_creator_actor_id: String,
   pub post_creator_name: String,
+  pub post_creator_preferred_username: Option<String>,
+  pub post_creator_avatar: Option<String>,
+  pub post_creator_local: bool,
+  pub resolver_actor_id: Option<String>,
+  pub resolver_name: Option<String>,
+  pub resolver_preferred_username: Option<String>,
+  pub resolver_avatar: Option<String>,
+  pub resolver_local: Option<bool>,
 }
 
 impl PostReportView {
index 840d3d99aedd9c434567e77bda524900f628b3fc..c0547d084b9fe6616765ed64aac2ccf430bb59b3 100644 (file)
@@ -31,14 +31,31 @@ select cr.*,
 c.post_id,
 c.content as current_comment_text,
 p.community_id,
+-- report creator details
+f.actor_id as creator_actor_id,
 f.name as creator_name,
+f.preferred_username as creator_preferred_username,
+f.avatar as creator_avatar,
+f.local as creator_local,
+-- comment creator details
 u.id as comment_creator_id,
-u.name as comment_creator_name
+u.actor_id as comment_creator_actor_id,
+u.name as comment_creator_name,
+u.preferred_username as comment_creator_preferred_username,
+u.avatar as comment_creator_avatar,
+u.local as comment_creator_local,
+-- resolver details
+r.actor_id as resolver_actor_id,
+r.name as resolver_name,
+r.preferred_username as resolver_preferred_username,
+r.avatar as resolver_avatar,
+r.local as resolver_local
 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_ r on r.id = cr.resolver_id;
 
 create or replace view post_report_view as
 select pr.*,
@@ -47,9 +64,27 @@ 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,
+f.preferred_username as creator_preferred_username,
+f.avatar as creator_avatar,
+f.local as creator_local,
+-- post creator details
 u.id as post_creator_id,
-u.name as post_creator_name
+u.actor_id as post_creator_actor_id,
+u.name as post_creator_name,
+u.preferred_username as post_creator_preferred_username,
+u.avatar as post_creator_avatar,
+u.local as post_creator_local,
+-- resolver details
+r.actor_id as resolver_actor_id,
+r.name as resolver_name,
+r.preferred_username as resolver_preferred_username,
+r.avatar as resolver_avatar,
+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_ r on r.id = pr.resolver_id;