]> Untitled Git - lemmy.git/blobdiff - lemmy_db/src/views/comment_view.rs
Merge remote-tracking branch 'origin/split-db-workspace' into move_views_to_diesel_split
[lemmy.git] / lemmy_db / src / views / comment_view.rs
index 7b1d0bc615e4707b13325f41638f33ff40e2e306..1b114e19057473e8deea406a01c3dee75895cba4 100644 (file)
@@ -147,6 +147,15 @@ impl CommentView {
       my_vote,
     })
   }
+
+  /// Gets the recipient user id.
+  /// If there is no parent comment, its the post creator
+  pub fn get_recipient_id(&self) -> i32 {
+    match &self.recipient {
+      Some(parent_commenter) => parent_commenter.id,
+      None => self.post.creator_id,
+    }
+  }
 }
 
 pub struct CommentQueryBuilder<'a> {
@@ -515,6 +524,8 @@ mod tests {
 
     let _inserted_comment_like = CommentLike::like(&conn, &comment_like_form).unwrap();
 
+    let agg = CommentAggregates::read(&conn, inserted_comment.id).unwrap();
+
     let expected_comment_view_no_user = CommentView {
       creator_banned_from_community: false,
       my_vote: None,
@@ -590,7 +601,7 @@ mod tests {
         published: inserted_community.published,
       },
       counts: CommentAggregates {
-        id: inserted_comment.id, // TODO
+        id: agg.id,
         comment_id: inserted_comment.id,
         score: 1,
         upvotes: 1,