]> Untitled Git - lemmy.git/blobdiff - crates/db_views/src/comment_report_view.rs
Make functions work with both connection and pool (#3420)
[lemmy.git] / crates / db_views / src / comment_report_view.rs
index df14ea5592032a98ba45f004e23f467e48610171..9c50eb67fa18002ecdeb16f9145d48de4ab1ad06 100644 (file)
@@ -40,7 +40,7 @@ impl CommentReportView {
   ///
   /// * `report_id` - the report id to obtain
   pub async fn read(
-    pool: &DbPool,
+    pool: &mut DbPool<'_>,
     report_id: CommentReportId,
     my_person_id: PersonId,
   ) -> Result<Self, Error> {
@@ -62,12 +62,7 @@ impl CommentReportView {
         community_person_ban::table.on(
           community::id
             .eq(community_person_ban::community_id)
-            .and(community_person_ban::person_id.eq(comment::creator_id))
-            .and(
-              community_person_ban::expires
-                .is_null()
-                .or(community_person_ban::expires.gt(now)),
-            ),
+            .and(community_person_ban::person_id.eq(comment::creator_id)),
         ),
       )
       .left_join(
@@ -101,7 +96,7 @@ impl CommentReportView {
 
   /// Returns the current unresolved post report count for the communities you mod
   pub async fn get_report_count(
-    pool: &DbPool,
+    pool: &mut DbPool<'_>,
     my_person_id: PersonId,
     admin: bool,
     community_id: Option<CommunityId>,
@@ -144,9 +139,9 @@ impl CommentReportView {
 
 #[derive(TypedBuilder)]
 #[builder(field_defaults(default))]
-pub struct CommentReportQuery<'a> {
+pub struct CommentReportQuery<'a, 'b: 'a> {
   #[builder(!default)]
-  pool: &'a DbPool,
+  pool: &'a mut DbPool<'b>,
   #[builder(!default)]
   my_person_id: PersonId,
   #[builder(!default)]
@@ -157,7 +152,7 @@ pub struct CommentReportQuery<'a> {
   unresolved_only: Option<bool>,
 }
 
-impl<'a> CommentReportQuery<'a> {
+impl<'a, 'b: 'a> CommentReportQuery<'a, 'b> {
   pub async fn list(self) -> Result<Vec<CommentReportView>, Error> {
     let conn = &mut get_conn(self.pool).await?;
 
@@ -213,7 +208,7 @@ impl<'a> CommentReportQuery<'a> {
       query = query.filter(post::community_id.eq(community_id));
     }
 
-    if self.unresolved_only.unwrap_or(true) {
+    if self.unresolved_only.unwrap_or(false) {
       query = query.filter(comment_report::resolved.eq(false));
     }
 
@@ -298,6 +293,7 @@ mod tests {
   #[serial]
   async fn test_crud() {
     let pool = &build_db_pool_for_tests().await;
+    let pool = &mut pool.into();
 
     let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
       .await
@@ -482,6 +478,7 @@ mod tests {
         downvotes: 0,
         published: agg.published,
         child_count: 0,
+        hot_rank: 1728,
       },
       my_vote: None,
       resolver: None,
@@ -597,6 +594,7 @@ mod tests {
       .pool(pool)
       .my_person_id(inserted_timmy.id)
       .admin(false)
+      .unresolved_only(Some(true))
       .build()
       .list()
       .await