]> Untitled Git - lemmy.git/commitdiff
Removing old communityviews
authorDessalines <tyhou13@gmx.com>
Sun, 6 Dec 2020 14:12:51 +0000 (09:12 -0500)
committerDessalines <tyhou13@gmx.com>
Sun, 6 Dec 2020 14:12:51 +0000 (09:12 -0500)
18 files changed:
lemmy_api/src/community.rs
lemmy_api/src/lib.rs
lemmy_api/src/post.rs
lemmy_api/src/site.rs
lemmy_api/src/user.rs
lemmy_apub/src/activities/receive/community.rs
lemmy_apub/src/activities/send/community.rs
lemmy_apub/src/fetcher.rs
lemmy_apub/src/http/community.rs
lemmy_apub/src/inbox/community_inbox.rs
lemmy_apub/src/objects/community.rs
lemmy_db/src/community.rs
lemmy_db/src/community_view.rs [deleted file]
lemmy_db/src/lib.rs
lemmy_structs/src/community.rs
lemmy_structs/src/post.rs
lemmy_structs/src/site.rs
lemmy_structs/src/user.rs

index 8024e1e279c365b095be55d45b4c71b46214c2f6..dcd9be0585d9f46835477e953e71fce249648b11 100644 (file)
@@ -13,13 +13,17 @@ use lemmy_db::{
   comment::Comment,
   comment_view::CommentQueryBuilder,
   community::*,
-  community_view::*,
   diesel_option_overwrite,
   moderator::*,
   naive_now,
   post::Post,
   site::*,
-  views::user_view::UserViewSafe,
+  views::{
+    community_follower_view::CommunityFollowerView,
+    community_moderator_view::CommunityModeratorView,
+    community_view::{CommunityQueryBuilder, CommunityView},
+    user_view::UserViewSafe,
+  },
   Bannable,
   Crud,
   Followable,
@@ -95,7 +99,7 @@ impl Perform for GetCommunity {
       .unwrap_or(1);
 
     let res = GetCommunityResponse {
-      community: community_view,
+      community_view,
       moderators,
       online,
     };
@@ -202,9 +206,7 @@ impl Perform for CreateCommunity {
     })
     .await??;
 
-    Ok(CommunityResponse {
-      community: community_view,
-    })
+    Ok(CommunityResponse { community_view })
   }
 }
 
@@ -227,7 +229,7 @@ impl Perform for EditCommunity {
     let edit_id = data.edit_id;
     let mods: Vec<i32> = blocking(context.pool(), move |conn| {
       CommunityModeratorView::for_community(conn, edit_id)
-        .map(|v| v.into_iter().map(|m| m.user_id).collect())
+        .map(|v| v.into_iter().map(|m| m.moderator.id).collect())
     })
     .await??;
     if !mods.contains(&user.id) {
@@ -284,9 +286,7 @@ impl Perform for EditCommunity {
     })
     .await??;
 
-    let res = CommunityResponse {
-      community: community_view,
-    };
+    let res = CommunityResponse { community_view };
 
     send_community_websocket(&res, context, websocket_id, UserOperation::EditCommunity);
 
@@ -340,9 +340,7 @@ impl Perform for DeleteCommunity {
     })
     .await??;
 
-    let res = CommunityResponse {
-      community: community_view,
-    };
+    let res = CommunityResponse { community_view };
 
     send_community_websocket(&res, context, websocket_id, UserOperation::DeleteCommunity);
 
@@ -408,9 +406,7 @@ impl Perform for RemoveCommunity {
     })
     .await??;
 
-    let res = CommunityResponse {
-      community: community_view,
-    };
+    let res = CommunityResponse { community_view };
 
     send_community_websocket(&res, context, websocket_id, UserOperation::RemoveCommunity);
 
@@ -445,9 +441,8 @@ impl Perform for ListCommunities {
     let page = data.page;
     let limit = data.limit;
     let communities = blocking(context.pool(), move |conn| {
-      CommunityQueryBuilder::create(conn)
+      CommunityQueryBuilder::create(conn, user_id)
         .sort(&sort)
-        .for_user(user_id)
         .show_nsfw(show_nsfw)
         .page(page)
         .limit(limit)
@@ -519,12 +514,10 @@ impl Perform for FollowCommunity {
     // For now, just assume that remote follows are accepted.
     // Otherwise, the subscribed will be null
     if !community.local {
-      community_view.subscribed = Some(data.follow);
+      community_view.subscribed = data.follow;
     }
 
-    Ok(CommunityResponse {
-      community: community_view,
-    })
+    Ok(CommunityResponse { community_view })
   }
 }
 
@@ -645,7 +638,7 @@ impl Perform for BanFromCommunity {
     .await??;
 
     let res = BanFromCommunityResponse {
-      user: user_view,
+      user_view,
       banned: data.ban,
     };
 
@@ -779,7 +772,7 @@ impl Perform for TransferCommunity {
     .await??;
     let creator_index = community_mods
       .iter()
-      .position(|r| r.user_id == data.user_id)
+      .position(|r| r.moderator.id == data.user_id)
       .context(location_info!())?;
     let creator_user = community_mods.remove(creator_index);
     community_mods.insert(0, creator_user);
@@ -793,8 +786,8 @@ impl Perform for TransferCommunity {
     // TODO: this should probably be a bulk operation
     for cmod in &community_mods {
       let community_moderator_form = CommunityModeratorForm {
-        community_id: cmod.community_id,
-        user_id: cmod.user_id,
+        community_id: cmod.community.id,
+        user_id: cmod.moderator.id,
       };
 
       let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
@@ -838,7 +831,7 @@ impl Perform for TransferCommunity {
 
     // Return the jwt
     Ok(GetCommunityResponse {
-      community: community_view,
+      community_view,
       moderators,
       online: 0,
     })
@@ -851,15 +844,16 @@ fn send_community_websocket(
   websocket_id: Option<ConnectionId>,
   op: UserOperation,
 ) {
+  // TODO is there any way around this?
   // Strip out the user id and subscribed when sending to others
-  let mut res_sent = res.clone();
-  res_sent.community.user_id = None;
-  res_sent.community.subscribed = None;
+  // let mut res_sent = res.clone();
+  // res_sent.community_view.user_id = None;
+  // res_sent.community.subscribed = None;
 
   context.chat_server().do_send(SendCommunityRoomMessage {
     op,
-    response: res_sent,
-    community_id: res.community.id,
+    response: res.to_owned(),
+    community_id: res.community_view.community.id,
     websocket_id,
   });
 }
index 06b629c772cd78e592c91ba802e67f603d93f46e..13998dc4dc98489c63b316a2b023d3bd63371a0f 100644 (file)
@@ -2,9 +2,9 @@ use crate::claims::Claims;
 use actix_web::{web, web::Data};
 use lemmy_db::{
   community::{Community, CommunityModerator},
-  community_view::CommunityUserBanView,
   post::Post,
   user::User_,
+  views::community_user_ban_view::CommunityUserBanView,
   Crud,
   DbPool,
 };
index cc121c44c13a8fdba224f619a66805ca4a2d27e7..89bb0fa87555f439a6720aec89be33eaf0ab7093 100644 (file)
@@ -11,13 +11,16 @@ use actix_web::web::Data;
 use lemmy_apub::{ApubLikeableType, ApubObjectType};
 use lemmy_db::{
   comment_view::*,
-  community_view::*,
   moderator::*,
   naive_now,
   post::*,
   post_report::*,
   post_view::*,
-  views::site_view::SiteView,
+  views::{
+    community_moderator_view::CommunityModeratorView,
+    community_view::CommunityView,
+    site_view::SiteView,
+  },
   Crud,
   Likeable,
   ListingType,
index a4e9cfd567ab9ae006a5aa47ad7dc70cf3416a00..d865a8f811939f2644c7ca790a97619c759df8e3 100644 (file)
@@ -13,7 +13,6 @@ use lemmy_db::{
   aggregates::site_aggregates::SiteAggregates,
   category::*,
   comment_view::*,
-  community_view::*,
   diesel_option_overwrite,
   moderator::*,
   moderator_views::*,
@@ -21,6 +20,7 @@ use lemmy_db::{
   post_view::*,
   site::*,
   views::{
+    community_view::CommunityQueryBuilder,
     site_view::SiteView,
     user_view::{UserQueryBuilder, UserViewSafe},
   },
@@ -392,7 +392,7 @@ impl Perform for Search {
       }
       SearchType::Communities => {
         communities = blocking(context.pool(), move |conn| {
-          CommunityQueryBuilder::create(conn)
+          CommunityQueryBuilder::create(conn, None)
             .sort(&sort)
             .search_term(q)
             .page(page)
@@ -445,7 +445,7 @@ impl Perform for Search {
         let sort = SortType::from_str(&data.sort)?;
 
         communities = blocking(context.pool(), move |conn| {
-          CommunityQueryBuilder::create(conn)
+          CommunityQueryBuilder::create(conn, None)
             .sort(&sort)
             .search_term(q)
             .page(page)
index 1f10b4e5bc5924460ddff3a17b112867b87f5a67..e3f447b7c2e8d7a0be3e39a35dfcb02fae39de6f 100644 (file)
@@ -19,7 +19,6 @@ use lemmy_db::{
   comment_report::CommentReportView,
   comment_view::*,
   community::*,
-  community_view::*,
   diesel_option_overwrite,
   moderator::*,
   naive_now,
@@ -34,6 +33,8 @@ use lemmy_db::{
   user_mention::*,
   user_mention_view::*,
   views::{
+    community_follower_view::CommunityFollowerView,
+    community_moderator_view::CommunityModeratorView,
     site_view::SiteView,
     user_view::{UserViewDangerous, UserViewSafe},
   },
index ed43b33e301c627817206ce440c6f8d99a392a61..80c911b142eeacb26d6b419d1d7795b5b3572c25 100644 (file)
@@ -4,7 +4,7 @@ use activitystreams::{
   base::{AnyBase, ExtendsExt},
 };
 use anyhow::Context;
-use lemmy_db::{community::Community, community_view::CommunityView};
+use lemmy_db::{community::Community, views::community_view::CommunityView};
 use lemmy_structs::{blocking, community::CommunityResponse};
 use lemmy_utils::{location_info, LemmyError};
 use lemmy_websocket::{messages::SendCommunityRoomMessage, LemmyContext, UserOperation};
@@ -21,13 +21,13 @@ pub(crate) async fn receive_delete_community(
 
   let community_id = deleted_community.id;
   let res = CommunityResponse {
-    community: blocking(context.pool(), move |conn| {
+    community_view: blocking(context.pool(), move |conn| {
       CommunityView::read(conn, community_id, None)
     })
     .await??,
   };
 
-  let community_id = res.community.id;
+  let community_id = res.community_view.community.id;
   context.chat_server().do_send(SendCommunityRoomMessage {
     op: UserOperation::EditCommunity,
     response: res,
@@ -64,13 +64,13 @@ pub(crate) async fn receive_remove_community(
 
   let community_id = removed_community.id;
   let res = CommunityResponse {
-    community: blocking(context.pool(), move |conn| {
+    community_view: blocking(context.pool(), move |conn| {
       CommunityView::read(conn, community_id, None)
     })
     .await??,
   };
 
-  let community_id = res.community.id;
+  let community_id = res.community_view.community.id;
   context.chat_server().do_send(SendCommunityRoomMessage {
     op: UserOperation::EditCommunity,
     response: res,
@@ -100,13 +100,13 @@ pub(crate) async fn receive_undo_delete_community(
 
   let community_id = deleted_community.id;
   let res = CommunityResponse {
-    community: blocking(context.pool(), move |conn| {
+    community_view: blocking(context.pool(), move |conn| {
       CommunityView::read(conn, community_id, None)
     })
     .await??,
   };
 
-  let community_id = res.community.id;
+  let community_id = res.community_view.community.id;
   context.chat_server().do_send(SendCommunityRoomMessage {
     op: UserOperation::EditCommunity,
     response: res,
@@ -146,13 +146,13 @@ pub(crate) async fn receive_undo_remove_community(
 
   let community_id = removed_community.id;
   let res = CommunityResponse {
-    community: blocking(context.pool(), move |conn| {
+    community_view: blocking(context.pool(), move |conn| {
       CommunityView::read(conn, community_id, None)
     })
     .await??,
   };
 
-  let community_id = res.community.id;
+  let community_id = res.community_view.community.id;
 
   context.chat_server().do_send(SendCommunityRoomMessage {
     op: UserOperation::EditCommunity,
index 775f8c25fa8dd011990add83c61c1a7f0f59a634..b1a2352d3dbffb088931be5b20c33751ce9144fa 100644 (file)
@@ -23,7 +23,11 @@ use activitystreams::{
 };
 use anyhow::Context;
 use itertools::Itertools;
-use lemmy_db::{community::Community, community_view::CommunityFollowerView, DbPool};
+use lemmy_db::{
+  community::Community,
+  views::community_follower_view::CommunityFollowerView,
+  DbPool,
+};
 use lemmy_structs::blocking;
 use lemmy_utils::{location_info, settings::Settings, LemmyError};
 use lemmy_websocket::LemmyContext;
@@ -179,9 +183,9 @@ impl ActorType for Community {
     .await??;
     let inboxes = inboxes
       .into_iter()
-      .filter(|i| !i.user_local)
+      .filter(|i| !i.follower.local)
       .map(|u| -> Result<Url, LemmyError> {
-        let url = Url::parse(&u.user_actor_id)?;
+        let url = Url::parse(&u.follower.actor_id)?;
         let domain = url.domain().context(location_info!())?;
         let port = if let Some(port) = url.port() {
           format!(":{}", port)
index fc18570352adc0997352e156933cff3a45e6f388..0eb33cb753daab8630fb033905619e21bb164866 100644 (file)
@@ -16,12 +16,11 @@ use lemmy_db::{
   comment::{Comment, CommentForm},
   comment_view::CommentView,
   community::{Community, CommunityForm, CommunityModerator, CommunityModeratorForm},
-  community_view::CommunityView,
   naive_now,
   post::{Post, PostForm},
   post_view::PostView,
   user::{UserForm, User_},
-  views::user_view::UserViewSafe,
+  views::{community_view::CommunityView, user_view::UserViewSafe},
   Crud,
   Joinable,
   SearchType,
index 0e2f2802e98e2a28f5e203879f91adc36d4cfac2..113228595a54e77c7973081fe60c99e74625fd0d 100644 (file)
@@ -9,7 +9,11 @@ use activitystreams::{
   collection::{CollectionExt, OrderedCollection, UnorderedCollection},
 };
 use actix_web::{body::Body, web, HttpResponse};
-use lemmy_db::{community::Community, community_view::CommunityFollowerView, post::Post};
+use lemmy_db::{
+  community::Community,
+  post::Post,
+  views::community_follower_view::CommunityFollowerView,
+};
 use lemmy_structs::blocking;
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
index 14878cfe5a43412d203b5b756d06ecdfcb05f090..37ae444e912658851011e20fb19e8cd1c110fa66 100644 (file)
@@ -28,8 +28,8 @@ use actix_web::{web, HttpRequest, HttpResponse};
 use anyhow::{anyhow, Context};
 use lemmy_db::{
   community::{Community, CommunityFollower, CommunityFollowerForm},
-  community_view::CommunityUserBanView,
   user::User_,
+  views::community_user_ban_view::CommunityUserBanView,
   DbPool,
   Followable,
 };
index 2b383ba5b818623c848cdc64063e0d5f1d3748ac..91638ef02e34275e1b21e81f2ac1b12c67b584e6 100644 (file)
@@ -22,8 +22,8 @@ use activitystreams_ext::Ext2;
 use anyhow::Context;
 use lemmy_db::{
   community::{Community, CommunityForm},
-  community_view::CommunityModeratorView,
   naive_now,
+  views::community_moderator_view::CommunityModeratorView,
   DbPool,
 };
 use lemmy_structs::blocking;
@@ -49,7 +49,10 @@ impl ToApub for Community {
       CommunityModeratorView::for_community(&conn, id)
     })
     .await??;
-    let moderators: Vec<String> = moderators.into_iter().map(|m| m.user_actor_id).collect();
+    let moderators: Vec<String> = moderators
+      .into_iter()
+      .map(|m| m.moderator.actor_id)
+      .collect();
 
     let mut group = ApObject::new(Group::new());
     group
index 8638f1d648706500523d8ed75994574f2d847171..40f046804dac8d36eb0a8b9ca5fb1278617037c8 100644 (file)
@@ -210,11 +210,11 @@ impl Community {
   }
 
   fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result<Vec<i32>, Error> {
-    use crate::{community_view::CommunityModeratorView, views::user_view::UserViewSafe};
+    use crate::views::{community_moderator_view::CommunityModeratorView, user_view::UserViewSafe};
     let mut mods_and_admins: Vec<i32> = Vec::new();
     mods_and_admins.append(
       &mut CommunityModeratorView::for_community(conn, community_id)
-        .map(|v| v.into_iter().map(|m| m.user_id).collect())?,
+        .map(|v| v.into_iter().map(|m| m.moderator.id).collect())?,
     );
     mods_and_admins
       .append(&mut UserViewSafe::admins(conn).map(|v| v.into_iter().map(|a| a.user.id).collect())?);
diff --git a/lemmy_db/src/community_view.rs b/lemmy_db/src/community_view.rs
deleted file mode 100644 (file)
index a635550..0000000
+++ /dev/null
@@ -1,398 +0,0 @@
-use super::community_view::community_fast_view::BoxedQuery;
-use crate::{fuzzy_search, limit_and_offset, MaybeOptional, SortType};
-use diesel::{pg::Pg, result::Error, *};
-use serde::{Deserialize, Serialize};
-
-table! {
-  community_view (id) {
-    id -> Int4,
-    name -> Varchar,
-    title -> Varchar,
-    icon -> Nullable<Text>,
-    banner -> Nullable<Text>,
-    description -> Nullable<Text>,
-    category_id -> Int4,
-    creator_id -> Int4,
-    removed -> Bool,
-    published -> Timestamp,
-    updated -> Nullable<Timestamp>,
-    deleted -> Bool,
-    nsfw -> Bool,
-    actor_id -> Text,
-    local -> Bool,
-    last_refreshed_at -> Timestamp,
-    creator_actor_id -> Text,
-    creator_local -> Bool,
-    creator_name -> Varchar,
-    creator_preferred_username -> Nullable<Varchar>,
-    creator_avatar -> Nullable<Text>,
-    category_name -> Varchar,
-    number_of_subscribers -> BigInt,
-    number_of_posts -> BigInt,
-    number_of_comments -> BigInt,
-    hot_rank -> Int4,
-    user_id -> Nullable<Int4>,
-    subscribed -> Nullable<Bool>,
-  }
-}
-
-table! {
-  community_fast_view (id) {
-    id -> Int4,
-    name -> Varchar,
-    title -> Varchar,
-    icon -> Nullable<Text>,
-    banner -> Nullable<Text>,
-    description -> Nullable<Text>,
-    category_id -> Int4,
-    creator_id -> Int4,
-    removed -> Bool,
-    published -> Timestamp,
-    updated -> Nullable<Timestamp>,
-    deleted -> Bool,
-    nsfw -> Bool,
-    actor_id -> Text,
-    local -> Bool,
-    last_refreshed_at -> Timestamp,
-    creator_actor_id -> Text,
-    creator_local -> Bool,
-    creator_name -> Varchar,
-    creator_preferred_username -> Nullable<Varchar>,
-    creator_avatar -> Nullable<Text>,
-    category_name -> Varchar,
-    number_of_subscribers -> BigInt,
-    number_of_posts -> BigInt,
-    number_of_comments -> BigInt,
-    hot_rank -> Int4,
-    user_id -> Nullable<Int4>,
-    subscribed -> Nullable<Bool>,
-  }
-}
-
-table! {
-  community_moderator_view (id) {
-    id -> Int4,
-    community_id -> Int4,
-    user_id -> Int4,
-    published -> Timestamp,
-    user_actor_id -> Text,
-    user_local -> Bool,
-    user_name -> Varchar,
-    user_preferred_username -> Nullable<Varchar>,
-    avatar -> Nullable<Text>,
-    community_actor_id -> Text,
-    community_local -> Bool,
-    community_name -> Varchar,
-    community_icon -> Nullable<Text>,
-  }
-}
-
-table! {
-  community_follower_view (id) {
-    id -> Int4,
-    community_id -> Int4,
-    user_id -> Int4,
-    published -> Timestamp,
-    user_actor_id -> Text,
-    user_local -> Bool,
-    user_name -> Varchar,
-    user_preferred_username -> Nullable<Varchar>,
-    avatar -> Nullable<Text>,
-    community_actor_id -> Text,
-    community_local -> Bool,
-    community_name -> Varchar,
-    community_icon -> Nullable<Text>,
-  }
-}
-
-table! {
-  community_user_ban_view (id) {
-    id -> Int4,
-    community_id -> Int4,
-    user_id -> Int4,
-    published -> Timestamp,
-    user_actor_id -> Text,
-    user_local -> Bool,
-    user_name -> Varchar,
-    user_preferred_username -> Nullable<Varchar>,
-    avatar -> Nullable<Text>,
-    community_actor_id -> Text,
-    community_local -> Bool,
-    community_name -> Varchar,
-    community_icon -> Nullable<Text>,
-  }
-}
-
-#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, QueryableByName, Clone)]
-#[table_name = "community_fast_view"]
-pub struct CommunityView {
-  pub id: i32,
-  pub name: String,
-  pub title: String,
-  pub icon: Option<String>,
-  pub banner: Option<String>,
-  pub description: Option<String>,
-  pub category_id: i32,
-  pub creator_id: i32,
-  pub removed: bool,
-  pub published: chrono::NaiveDateTime,
-  pub updated: Option<chrono::NaiveDateTime>,
-  pub deleted: bool,
-  pub nsfw: bool,
-  pub actor_id: String,
-  pub local: bool,
-  pub last_refreshed_at: chrono::NaiveDateTime,
-  pub creator_actor_id: String,
-  pub creator_local: bool,
-  pub creator_name: String,
-  pub creator_preferred_username: Option<String>,
-  pub creator_avatar: Option<String>,
-  pub category_name: String,
-  pub number_of_subscribers: i64,
-  pub number_of_posts: i64,
-  pub number_of_comments: i64,
-  pub hot_rank: i32,
-  pub user_id: Option<i32>,
-  pub subscribed: Option<bool>,
-}
-
-pub struct CommunityQueryBuilder<'a> {
-  conn: &'a PgConnection,
-  query: BoxedQuery<'a, Pg>,
-  sort: &'a SortType,
-  from_user_id: Option<i32>,
-  show_nsfw: bool,
-  search_term: Option<String>,
-  page: Option<i64>,
-  limit: Option<i64>,
-}
-
-impl<'a> CommunityQueryBuilder<'a> {
-  pub fn create(conn: &'a PgConnection) -> Self {
-    use super::community_view::community_fast_view::dsl::*;
-
-    let query = community_fast_view.into_boxed();
-
-    CommunityQueryBuilder {
-      conn,
-      query,
-      sort: &SortType::Hot,
-      from_user_id: None,
-      show_nsfw: true,
-      search_term: None,
-      page: None,
-      limit: None,
-    }
-  }
-
-  pub fn sort(mut self, sort: &'a SortType) -> Self {
-    self.sort = sort;
-    self
-  }
-
-  pub fn for_user<T: MaybeOptional<i32>>(mut self, from_user_id: T) -> Self {
-    self.from_user_id = from_user_id.get_optional();
-    self
-  }
-
-  pub fn show_nsfw(mut self, show_nsfw: bool) -> Self {
-    self.show_nsfw = show_nsfw;
-    self
-  }
-
-  pub fn search_term<T: MaybeOptional<String>>(mut self, search_term: T) -> Self {
-    self.search_term = search_term.get_optional();
-    self
-  }
-
-  pub fn page<T: MaybeOptional<i64>>(mut self, page: T) -> Self {
-    self.page = page.get_optional();
-    self
-  }
-
-  pub fn limit<T: MaybeOptional<i64>>(mut self, limit: T) -> Self {
-    self.limit = limit.get_optional();
-    self
-  }
-
-  pub fn list(self) -> Result<Vec<CommunityView>, Error> {
-    use super::community_view::community_fast_view::dsl::*;
-
-    let mut query = self.query;
-
-    if let Some(search_term) = self.search_term {
-      let searcher = fuzzy_search(&search_term);
-      query = query
-        .filter(name.ilike(searcher.to_owned()))
-        .or_filter(title.ilike(searcher.to_owned()))
-        .or_filter(description.ilike(searcher));
-    };
-
-    // The view lets you pass a null user_id, if you're not logged in
-    match self.sort {
-      SortType::New => query = query.order_by(published.desc()).filter(user_id.is_null()),
-      SortType::TopAll => match self.from_user_id {
-        Some(from_user_id) => {
-          query = query
-            .filter(user_id.eq(from_user_id))
-            .order_by((subscribed.asc(), number_of_subscribers.desc()))
-        }
-        None => {
-          query = query
-            .order_by(number_of_subscribers.desc())
-            .filter(user_id.is_null())
-        }
-      },
-      // Covers all other sorts, including hot
-      _ => {
-        query = query
-          .order_by(hot_rank.desc())
-          .then_order_by(number_of_subscribers.desc())
-          .filter(user_id.is_null())
-      }
-    };
-
-    if !self.show_nsfw {
-      query = query.filter(nsfw.eq(false));
-    };
-
-    let (limit, offset) = limit_and_offset(self.page, self.limit);
-    query
-      .limit(limit)
-      .offset(offset)
-      .filter(removed.eq(false))
-      .filter(deleted.eq(false))
-      .load::<CommunityView>(self.conn)
-  }
-}
-
-impl CommunityView {
-  pub fn read(
-    conn: &PgConnection,
-    from_community_id: i32,
-    from_user_id: Option<i32>,
-  ) -> Result<Self, Error> {
-    use super::community_view::community_fast_view::dsl::*;
-
-    let mut query = community_fast_view.into_boxed();
-
-    query = query.filter(id.eq(from_community_id));
-
-    // The view lets you pass a null user_id, if you're not logged in
-    if let Some(from_user_id) = from_user_id {
-      query = query.filter(user_id.eq(from_user_id));
-    } else {
-      query = query.filter(user_id.is_null());
-    };
-
-    query.first::<Self>(conn)
-  }
-}
-
-#[derive(
-  Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
-)]
-#[table_name = "community_moderator_view"]
-pub struct CommunityModeratorView {
-  pub id: i32,
-  pub community_id: i32,
-  pub user_id: i32,
-  pub published: chrono::NaiveDateTime,
-  pub user_actor_id: String,
-  pub user_local: bool,
-  pub user_name: String,
-  pub user_preferred_username: Option<String>,
-  pub avatar: Option<String>,
-  pub community_actor_id: String,
-  pub community_local: bool,
-  pub community_name: String,
-  pub community_icon: Option<String>,
-}
-
-impl CommunityModeratorView {
-  pub fn for_community(conn: &PgConnection, for_community_id: i32) -> Result<Vec<Self>, Error> {
-    use super::community_view::community_moderator_view::dsl::*;
-    community_moderator_view
-      .filter(community_id.eq(for_community_id))
-      .order_by(published)
-      .load::<Self>(conn)
-  }
-
-  pub fn for_user(conn: &PgConnection, for_user_id: i32) -> Result<Vec<Self>, Error> {
-    use super::community_view::community_moderator_view::dsl::*;
-    community_moderator_view
-      .filter(user_id.eq(for_user_id))
-      .order_by(published)
-      .load::<Self>(conn)
-  }
-}
-
-#[derive(
-  Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
-)]
-#[table_name = "community_follower_view"]
-pub struct CommunityFollowerView {
-  pub id: i32,
-  pub community_id: i32,
-  pub user_id: i32,
-  pub published: chrono::NaiveDateTime,
-  pub user_actor_id: String,
-  pub user_local: bool,
-  pub user_name: String,
-  pub user_preferred_username: Option<String>,
-  pub avatar: Option<String>,
-  pub community_actor_id: String,
-  pub community_local: bool,
-  pub community_name: String,
-  pub community_icon: Option<String>,
-}
-
-impl CommunityFollowerView {
-  pub fn for_community(conn: &PgConnection, from_community_id: i32) -> Result<Vec<Self>, Error> {
-    use super::community_view::community_follower_view::dsl::*;
-    community_follower_view
-      .filter(community_id.eq(from_community_id))
-      .load::<Self>(conn)
-  }
-
-  pub fn for_user(conn: &PgConnection, from_user_id: i32) -> Result<Vec<Self>, Error> {
-    use super::community_view::community_follower_view::dsl::*;
-    community_follower_view
-      .filter(user_id.eq(from_user_id))
-      .load::<Self>(conn)
-  }
-}
-
-#[derive(
-  Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize, QueryableByName, Clone,
-)]
-#[table_name = "community_user_ban_view"]
-pub struct CommunityUserBanView {
-  pub id: i32,
-  pub community_id: i32,
-  pub user_id: i32,
-  pub published: chrono::NaiveDateTime,
-  pub user_actor_id: String,
-  pub user_local: bool,
-  pub user_name: String,
-  pub user_preferred_username: Option<String>,
-  pub avatar: Option<String>,
-  pub community_actor_id: String,
-  pub community_local: bool,
-  pub community_name: String,
-  pub community_icon: Option<String>,
-}
-
-impl CommunityUserBanView {
-  pub fn get(
-    conn: &PgConnection,
-    from_user_id: i32,
-    from_community_id: i32,
-  ) -> Result<Self, Error> {
-    use super::community_view::community_user_ban_view::dsl::*;
-    community_user_ban_view
-      .filter(user_id.eq(from_user_id))
-      .filter(community_id.eq(from_community_id))
-      .first::<Self>(conn)
-  }
-}
index 4f2e85cd47da88dcc17836e819ca6ab88fb8b6e6..9fb43d6e4959f68d7f8e17477ecc2d236d8f5d16 100644 (file)
@@ -18,7 +18,6 @@ pub mod comment;
 pub mod comment_report;
 pub mod comment_view;
 pub mod community;
-pub mod community_view;
 pub mod moderator;
 pub mod moderator_views;
 pub mod password_reset_request;
index 7db71c9537b2369c020a87143acf846d922ef755..c107084bb92beb6d967ed88446cd5e2115f8cc84 100644 (file)
@@ -1,6 +1,8 @@
-use lemmy_db::{
-  community_view::{CommunityFollowerView, CommunityModeratorView, CommunityView},
-  views::user_view::UserViewSafe,
+use lemmy_db::views::{
+  community_follower_view::CommunityFollowerView,
+  community_moderator_view::CommunityModeratorView,
+  community_view::CommunityView,
+  user_view::UserViewSafe,
 };
 use serde::{Deserialize, Serialize};
 
@@ -13,7 +15,7 @@ pub struct GetCommunity {
 
 #[derive(Serialize)]
 pub struct GetCommunityResponse {
-  pub community: CommunityView,
+  pub community_view: CommunityView,
   pub moderators: Vec<CommunityModeratorView>,
   pub online: usize,
 }
@@ -32,7 +34,7 @@ pub struct CreateCommunity {
 
 #[derive(Serialize, Clone)]
 pub struct CommunityResponse {
-  pub community: CommunityView,
+  pub community_view: CommunityView,
 }
 
 #[derive(Deserialize, Debug)]
@@ -61,7 +63,7 @@ pub struct BanFromCommunity {
 
 #[derive(Serialize, Clone)]
 pub struct BanFromCommunityResponse {
-  pub user: UserViewSafe,
+  pub user_view: UserViewSafe,
   pub banned: bool,
 }
 
index 331c2dca45e944636d101b65697db5920af8176c..8d4be325b5a4b45e5663f5657368d18f1db19942 100644 (file)
@@ -1,8 +1,8 @@
 use lemmy_db::{
   comment_view::CommentView,
-  community_view::{CommunityModeratorView, CommunityView},
   post_report::PostReportView,
   post_view::PostView,
+  views::{community_moderator_view::CommunityModeratorView, community_view::CommunityView},
 };
 use serde::{Deserialize, Serialize};
 
index 6dfa518bdffc41d81a903285494af11f0f448874..9f2efd79de4feabcaa4c7a4691cac999377df110 100644 (file)
@@ -2,11 +2,10 @@ use lemmy_db::{
   aggregates::site_aggregates::SiteAggregates,
   category::*,
   comment_view::*,
-  community_view::*,
   moderator_views::*,
   post_view::*,
   user::*,
-  views::{site_view::SiteView, user_view::UserViewSafe},
+  views::{community_view::CommunityView, site_view::SiteView, user_view::UserViewSafe},
 };
 use serde::{Deserialize, Serialize};
 
index 93f92940449df4411ca8c26c40a8ea40db80dd5a..0a7c6f08bfb1c600e840ef2dccfb5db425c876c1 100644 (file)
@@ -1,10 +1,13 @@
 use lemmy_db::{
   comment_view::{CommentView, ReplyView},
-  community_view::{CommunityFollowerView, CommunityModeratorView},
   post_view::PostView,
   private_message_view::PrivateMessageView,
   user_mention_view::UserMentionView,
-  views::user_view::{UserViewDangerous, UserViewSafe},
+  views::{
+    community_follower_view::CommunityFollowerView,
+    community_moderator_view::CommunityModeratorView,
+    user_view::{UserViewDangerous, UserViewSafe},
+  },
 };
 use serde::{Deserialize, Serialize};