]> Untitled Git - lemmy.git/commitdiff
Adding community_view to PostResponse.
authorDessalines <tyhou13@gmx.com>
Wed, 23 Dec 2020 21:56:20 +0000 (16:56 -0500)
committerDessalines <tyhou13@gmx.com>
Wed, 23 Dec 2020 21:56:20 +0000 (16:56 -0500)
- Changing to_vec function name.

22 files changed:
lemmy_api/src/post.rs
lemmy_db/src/views/comment_report_view.rs
lemmy_db/src/views/comment_view.rs
lemmy_db/src/views/community/community_follower_view.rs
lemmy_db/src/views/community/community_moderator_view.rs
lemmy_db/src/views/community/community_view.rs
lemmy_db/src/views/mod.rs
lemmy_db/src/views/moderator/mod_add_community_view.rs
lemmy_db/src/views/moderator/mod_add_view.rs
lemmy_db/src/views/moderator/mod_ban_from_community_view.rs
lemmy_db/src/views/moderator/mod_ban_view.rs
lemmy_db/src/views/moderator/mod_lock_post_view.rs
lemmy_db/src/views/moderator/mod_remove_comment_view.rs
lemmy_db/src/views/moderator/mod_remove_community_view.rs
lemmy_db/src/views/moderator/mod_remove_post_view.rs
lemmy_db/src/views/moderator/mod_sticky_post_view.rs
lemmy_db/src/views/post_report_view.rs
lemmy_db/src/views/post_view.rs
lemmy_db/src/views/private_message_view.rs
lemmy_db/src/views/user_mention_view.rs
lemmy_db/src/views/user_view.rs
lemmy_structs/src/post.rs

index 20b5b8d556e1e6f77fef4a1f137675adc0858526..f358946263e09df84a349e8d96a687a8779f185f 100644 (file)
@@ -14,7 +14,7 @@ use lemmy_db::{
   source::post::Post_,
   views::{
     comment_view::CommentQueryBuilder,
-    community::community_moderator_view::CommunityModeratorView,
+    community::{community_moderator_view::CommunityModeratorView, community_view::CommunityView},
     post_report_view::{PostReportQueryBuilder, PostReportView},
     post_view::{PostQueryBuilder, PostView},
   },
@@ -201,6 +201,16 @@ impl Perform for GetPost {
     })
     .await??;
 
+    // Necessary for the sidebar
+    let community_view = match blocking(context.pool(), move |conn| {
+      CommunityView::read(conn, community_id, user_id)
+    })
+    .await?
+    {
+      Ok(community) => community,
+      Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
+    };
+
     let online = context
       .chat_server()
       .send(GetPostUsersOnline { post_id: data.id })
@@ -210,6 +220,7 @@ impl Perform for GetPost {
     // Return the jwt
     Ok(GetPostResponse {
       post_view,
+      community_view,
       comments,
       moderators,
       online,
index 7a260cd59bf3c5d14476c2df5897d2ec3c5f7e2f..52a8bdb50379f0f2c1604543bee23ca086d521df 100644 (file)
@@ -167,14 +167,14 @@ impl<'a> CommentReportQueryBuilder<'a> {
       .offset(offset)
       .load::<CommentReportViewTuple>(self.conn)?;
 
-    Ok(CommentReportView::to_vec(res))
+    Ok(CommentReportView::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for CommentReportView {
   type DbTuple = CommentReportViewTuple;
-  fn to_vec(posts: Vec<Self::DbTuple>) -> Vec<Self> {
-    posts
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         comment_report: a.0.to_owned(),
index 1b114e19057473e8deea406a01c3dee75895cba4..3ae14f64c3b4e63bfe81d39388fc0f3d7ecb4028 100644 (file)
@@ -391,14 +391,14 @@ impl<'a> CommentQueryBuilder<'a> {
       .offset(offset)
       .load::<CommentViewTuple>(self.conn)?;
 
-    Ok(CommentView::to_vec(res))
+    Ok(CommentView::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for CommentView {
   type DbTuple = CommentViewTuple;
-  fn to_vec(posts: Vec<Self::DbTuple>) -> Vec<Self> {
-    posts
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         comment: a.0.to_owned(),
index e7ba0e4a6005c13ad6e9a5de0e8faf32f231b9d3..7ed945380ed1229dadf2b718942d23004a8c3650 100644 (file)
@@ -27,7 +27,7 @@ impl CommunityFollowerView {
       .order_by(community_follower::published)
       .load::<CommunityFollowerViewTuple>(conn)?;
 
-    Ok(Self::to_vec(res))
+    Ok(Self::from_tuple_to_vec(res))
   }
 
   pub fn for_user(conn: &PgConnection, user_id: i32) -> Result<Vec<Self>, Error> {
@@ -39,14 +39,14 @@ impl CommunityFollowerView {
       .order_by(community_follower::published)
       .load::<CommunityFollowerViewTuple>(conn)?;
 
-    Ok(Self::to_vec(res))
+    Ok(Self::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for CommunityFollowerView {
   type DbTuple = CommunityFollowerViewTuple;
-  fn to_vec(users: Vec<Self::DbTuple>) -> Vec<Self> {
-    users
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         community: a.0.to_owned(),
index 6800853ea2a368bc13802543a0c2cb93b804763a..a61621266ea677fb953dc8d2f89c5b4a6ac1415d 100644 (file)
@@ -27,7 +27,7 @@ impl CommunityModeratorView {
       .order_by(community_moderator::published)
       .load::<CommunityModeratorViewTuple>(conn)?;
 
-    Ok(Self::to_vec(res))
+    Ok(Self::from_tuple_to_vec(res))
   }
 
   pub fn for_user(conn: &PgConnection, user_id: i32) -> Result<Vec<Self>, Error> {
@@ -39,14 +39,14 @@ impl CommunityModeratorView {
       .order_by(community_moderator::published)
       .load::<CommunityModeratorViewTuple>(conn)?;
 
-    Ok(Self::to_vec(res))
+    Ok(Self::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for CommunityModeratorView {
   type DbTuple = CommunityModeratorViewTuple;
-  fn to_vec(community_moderators: Vec<Self::DbTuple>) -> Vec<Self> {
-    community_moderators
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         community: a.0.to_owned(),
index 11962d79a92098df5297abd786d569fcfa520d17..0ea4388e1bc99c87a17933c7dd8a0080238217c1 100644 (file)
@@ -185,14 +185,14 @@ impl<'a> CommunityQueryBuilder<'a> {
       .filter(community::deleted.eq(false))
       .load::<CommunityViewTuple>(self.conn)?;
 
-    Ok(CommunityView::to_vec(res))
+    Ok(CommunityView::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for CommunityView {
   type DbTuple = CommunityViewTuple;
-  fn to_vec(communities: Vec<Self::DbTuple>) -> Vec<Self> {
-    communities
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         community: a.0.to_owned(),
index 3cac0bd3d8f250e827b74c3838ffad9b082a5f3b..337e2bc3b32b7e10d928962fcfe1c4a6770d15b5 100644 (file)
@@ -11,7 +11,7 @@ pub mod user_view;
 
 pub(crate) trait ViewToVec {
   type DbTuple;
-  fn to_vec(tuple: Vec<Self::DbTuple>) -> Vec<Self>
+  fn from_tuple_to_vec(tuple: Vec<Self::DbTuple>) -> Vec<Self>
   where
     Self: Sized;
 }
index 302d37a0b347d8e2a615c56cae4c9a1c2c7cce6a..6dbbe148418643425b6c746c0b2a33f9f83bd372 100644 (file)
@@ -56,14 +56,14 @@ impl ModAddCommunityView {
       .order_by(mod_add_community::when_.desc())
       .load::<ModAddCommunityViewTuple>(conn)?;
 
-    Ok(Self::to_vec(res))
+    Ok(Self::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for ModAddCommunityView {
   type DbTuple = ModAddCommunityViewTuple;
-  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
-    mrp
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         mod_add_community: a.0.to_owned(),
index 8f586a6ff8b35c20042bfdd5406144d1f6794ee9..f60a4edc5cd1b6002f3492f912f04c90159e3814 100644 (file)
@@ -47,14 +47,14 @@ impl ModAddView {
       .order_by(mod_add::when_.desc())
       .load::<ModAddViewTuple>(conn)?;
 
-    Ok(Self::to_vec(res))
+    Ok(Self::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for ModAddView {
   type DbTuple = ModAddViewTuple;
-  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
-    mrp
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         mod_add: a.0.to_owned(),
index 0ed52dd25f83dfa96424690894ae9ee85d4354ca..6bfba76f7894ce285f9fc8d9816c10b520ad990e 100644 (file)
@@ -56,14 +56,14 @@ impl ModBanFromCommunityView {
       .order_by(mod_ban_from_community::when_.desc())
       .load::<ModBanFromCommunityViewTuple>(conn)?;
 
-    Ok(Self::to_vec(res))
+    Ok(Self::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for ModBanFromCommunityView {
   type DbTuple = ModBanFromCommunityViewTuple;
-  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
-    mrp
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         mod_ban_from_community: a.0.to_owned(),
index 98cf1969f3dfa5d5f1b46278b0b5f4b8be22c6c7..2604f4a60fac3984170fc5843091f7edc13db795 100644 (file)
@@ -47,14 +47,14 @@ impl ModBanView {
       .order_by(mod_ban::when_.desc())
       .load::<ModBanViewTuple>(conn)?;
 
-    Ok(Self::to_vec(res))
+    Ok(Self::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for ModBanView {
   type DbTuple = ModBanViewTuple;
-  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
-    mrp
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         mod_ban: a.0.to_owned(),
index dbe81c5c385e5991dfcbc8d3fb5943247bcc17fa..2fcc25f7a5a5acb472100f3c715aeca1eb704366 100644 (file)
@@ -57,14 +57,14 @@ impl ModLockPostView {
       .order_by(mod_lock_post::when_.desc())
       .load::<ModLockPostViewTuple>(conn)?;
 
-    Ok(Self::to_vec(res))
+    Ok(Self::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for ModLockPostView {
   type DbTuple = ModLockPostViewTuple;
-  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
-    mrp
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         mod_lock_post: a.0.to_owned(),
index 04aab30af35e4f5f1b1463897380bb5fc9c2283f..1493089bdfba1d802600e10c5620c9ee30b870a6 100644 (file)
@@ -71,14 +71,14 @@ impl ModRemoveCommentView {
       .order_by(mod_remove_comment::when_.desc())
       .load::<ModRemoveCommentViewTuple>(conn)?;
 
-    Ok(Self::to_vec(res))
+    Ok(Self::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for ModRemoveCommentView {
   type DbTuple = ModRemoveCommentViewTuple;
-  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
-    mrp
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         mod_remove_comment: a.0.to_owned(),
index 37ffe540262fbb7e651b1186fc21ef11e17cd05b..2b9e0c8e6a1bd1af8d5232cd5e533e9865b42f91 100644 (file)
@@ -48,14 +48,14 @@ impl ModRemoveCommunityView {
       .order_by(mod_remove_community::when_.desc())
       .load::<ModRemoveCommunityTuple>(conn)?;
 
-    Ok(Self::to_vec(res))
+    Ok(Self::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for ModRemoveCommunityView {
   type DbTuple = ModRemoveCommunityTuple;
-  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
-    mrp
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         mod_remove_community: a.0.to_owned(),
index 21bf1b867a3b128778695321336a2846fc4f4a58..6b1923d5d50d90b28ba839dc88e16ec87602bf6e 100644 (file)
@@ -57,14 +57,14 @@ impl ModRemovePostView {
       .order_by(mod_remove_post::when_.desc())
       .load::<ModRemovePostViewTuple>(conn)?;
 
-    Ok(Self::to_vec(res))
+    Ok(Self::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for ModRemovePostView {
   type DbTuple = ModRemovePostViewTuple;
-  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
-    mrp
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         mod_remove_post: a.0.to_owned(),
index 8512e07935808fe345f6e96cbe699a567cba2cee..fab8ddeb520500bbeb79c65b55a08cde42dab5b0 100644 (file)
@@ -57,14 +57,14 @@ impl ModStickyPostView {
       .order_by(mod_sticky_post::when_.desc())
       .load::<ModStickyPostViewTuple>(conn)?;
 
-    Ok(Self::to_vec(res))
+    Ok(Self::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for ModStickyPostView {
   type DbTuple = ModStickyPostViewTuple;
-  fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
-    mrp
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         mod_sticky_post: a.0.to_owned(),
index 37d6275cd0abb067711d9366681eff52cc83644c..ab6adc78267204efed70c17ec1ef03f74a64ef2d 100644 (file)
@@ -153,14 +153,14 @@ impl<'a> PostReportQueryBuilder<'a> {
       .offset(offset)
       .load::<PostReportViewTuple>(self.conn)?;
 
-    Ok(PostReportView::to_vec(res))
+    Ok(PostReportView::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for PostReportView {
   type DbTuple = PostReportViewTuple;
-  fn to_vec(posts: Vec<Self::DbTuple>) -> Vec<Self> {
-    posts
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         post_report: a.0.to_owned(),
index 3cfee1b371300c14ec24e7e19c28a912209b73ac..643c60a849a41d4e25284dd3a1ca2d0064dc05fe 100644 (file)
@@ -380,14 +380,14 @@ impl<'a> PostQueryBuilder<'a> {
       .filter(community::deleted.eq(false))
       .load::<PostViewTuple>(self.conn)?;
 
-    Ok(PostView::to_vec(res))
+    Ok(PostView::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for PostView {
   type DbTuple = PostViewTuple;
-  fn to_vec(posts: Vec<Self::DbTuple>) -> Vec<Self> {
-    posts
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         post: a.0.to_owned(),
index f439a75d54128f0235038e54cbc3ddbd36d995e9..d6f1f63acf96e09da9ca791f27a267ad0e32eb36 100644 (file)
@@ -109,14 +109,15 @@ impl<'a> PrivateMessageQueryBuilder<'a> {
       .order_by(private_message::published.desc())
       .load::<PrivateMessageViewTuple>(self.conn)?;
 
-    Ok(PrivateMessageView::to_vec(res))
+    Ok(PrivateMessageView::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for PrivateMessageView {
   type DbTuple = PrivateMessageViewTuple;
-  fn to_vec(pm: Vec<Self::DbTuple>) -> Vec<Self> {
-    pm.iter()
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
+      .iter()
       .map(|a| Self {
         private_message: a.0.to_owned(),
         creator: a.1.to_owned(),
index 2cd1cd3c87dca2426e6d4985f79c5ed38cb0aaa2..0f9073b5abb9e928bb17b9b0a50294ce49dc580b 100644 (file)
@@ -293,14 +293,14 @@ impl<'a> UserMentionQueryBuilder<'a> {
       .offset(offset)
       .load::<UserMentionViewTuple>(self.conn)?;
 
-    Ok(UserMentionView::to_vec(res))
+    Ok(UserMentionView::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for UserMentionView {
   type DbTuple = UserMentionViewTuple;
-  fn to_vec(posts: Vec<Self::DbTuple>) -> Vec<Self> {
-    posts
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         user_mention: a.0.to_owned(),
index f3109011e91a13d50c3f863da89b967c2ab65d92..36b52522764bc9bc2016b0c295f3a5fa155ca817 100644 (file)
@@ -58,7 +58,7 @@ impl UserViewSafe {
       .order_by(user_::published)
       .load::<UserViewSafeTuple>(conn)?;
 
-    Ok(Self::to_vec(admins))
+    Ok(Self::from_tuple_to_vec(admins))
   }
 
   pub fn banned(conn: &PgConnection) -> Result<Vec<Self>, Error> {
@@ -68,7 +68,7 @@ impl UserViewSafe {
       .filter(user_::banned.eq(true))
       .load::<UserViewSafeTuple>(conn)?;
 
-    Ok(Self::to_vec(banned))
+    Ok(Self::from_tuple_to_vec(banned))
   }
 }
 
@@ -149,14 +149,14 @@ impl<'a> UserQueryBuilder<'a> {
 
     let res = query.load::<UserViewSafeTuple>(self.conn)?;
 
-    Ok(UserViewSafe::to_vec(res))
+    Ok(UserViewSafe::from_tuple_to_vec(res))
   }
 }
 
 impl ViewToVec for UserViewSafe {
   type DbTuple = UserViewSafeTuple;
-  fn to_vec(users: Vec<Self::DbTuple>) -> Vec<Self> {
-    users
+  fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+    items
       .iter()
       .map(|a| Self {
         user: a.0.to_owned(),
index ac29d8f7807d373ad0f24ad697bc141fbedffa93..0c6c23d7bf1afe8fb9656e47caa53d4aa8b43bcb 100644 (file)
@@ -1,6 +1,6 @@
 use lemmy_db::views::{
   comment_view::CommentView,
-  community::community_moderator_view::CommunityModeratorView,
+  community::{community_moderator_view::CommunityModeratorView, community_view::CommunityView},
   post_report_view::PostReportView,
   post_view::PostView,
 };
@@ -30,6 +30,7 @@ pub struct GetPost {
 #[derive(Serialize)]
 pub struct GetPostResponse {
   pub post_view: PostView,
+  pub community_view: CommunityView,
   pub comments: Vec<CommentView>,
   pub moderators: Vec<CommunityModeratorView>,
   pub online: usize,