From: Dessalines Date: Sun, 6 Dec 2020 14:12:51 +0000 (-0500) Subject: Removing old communityviews X-Git-Url: http://these/git/ui/assets/static/%7Bpost.embed_video_url%7D?a=commitdiff_plain;h=36f7b2078471f916f03e8d38b7cab9901c4ad46f;p=lemmy.git Removing old communityviews --- diff --git a/lemmy_api/src/community.rs b/lemmy_api/src/community.rs index 8024e1e2..dcd9be05 100644 --- a/lemmy_api/src/community.rs +++ b/lemmy_api/src/community.rs @@ -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 = 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, 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, }); } diff --git a/lemmy_api/src/lib.rs b/lemmy_api/src/lib.rs index 06b629c7..13998dc4 100644 --- a/lemmy_api/src/lib.rs +++ b/lemmy_api/src/lib.rs @@ -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, }; diff --git a/lemmy_api/src/post.rs b/lemmy_api/src/post.rs index cc121c44..89bb0fa8 100644 --- a/lemmy_api/src/post.rs +++ b/lemmy_api/src/post.rs @@ -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, diff --git a/lemmy_api/src/site.rs b/lemmy_api/src/site.rs index a4e9cfd5..d865a8f8 100644 --- a/lemmy_api/src/site.rs +++ b/lemmy_api/src/site.rs @@ -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) diff --git a/lemmy_api/src/user.rs b/lemmy_api/src/user.rs index 1f10b4e5..e3f447b7 100644 --- a/lemmy_api/src/user.rs +++ b/lemmy_api/src/user.rs @@ -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}, }, diff --git a/lemmy_apub/src/activities/receive/community.rs b/lemmy_apub/src/activities/receive/community.rs index ed43b33e..80c911b1 100644 --- a/lemmy_apub/src/activities/receive/community.rs +++ b/lemmy_apub/src/activities/receive/community.rs @@ -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, diff --git a/lemmy_apub/src/activities/send/community.rs b/lemmy_apub/src/activities/send/community.rs index 775f8c25..b1a2352d 100644 --- a/lemmy_apub/src/activities/send/community.rs +++ b/lemmy_apub/src/activities/send/community.rs @@ -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 { - 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) diff --git a/lemmy_apub/src/fetcher.rs b/lemmy_apub/src/fetcher.rs index fc185703..0eb33cb7 100644 --- a/lemmy_apub/src/fetcher.rs +++ b/lemmy_apub/src/fetcher.rs @@ -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, diff --git a/lemmy_apub/src/http/community.rs b/lemmy_apub/src/http/community.rs index 0e2f2802..11322859 100644 --- a/lemmy_apub/src/http/community.rs +++ b/lemmy_apub/src/http/community.rs @@ -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; diff --git a/lemmy_apub/src/inbox/community_inbox.rs b/lemmy_apub/src/inbox/community_inbox.rs index 14878cfe..37ae444e 100644 --- a/lemmy_apub/src/inbox/community_inbox.rs +++ b/lemmy_apub/src/inbox/community_inbox.rs @@ -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, }; diff --git a/lemmy_apub/src/objects/community.rs b/lemmy_apub/src/objects/community.rs index 2b383ba5..91638ef0 100644 --- a/lemmy_apub/src/objects/community.rs +++ b/lemmy_apub/src/objects/community.rs @@ -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 = moderators.into_iter().map(|m| m.user_actor_id).collect(); + let moderators: Vec = moderators + .into_iter() + .map(|m| m.moderator.actor_id) + .collect(); let mut group = ApObject::new(Group::new()); group diff --git a/lemmy_db/src/community.rs b/lemmy_db/src/community.rs index 8638f1d6..40f04680 100644 --- a/lemmy_db/src/community.rs +++ b/lemmy_db/src/community.rs @@ -210,11 +210,11 @@ impl Community { } fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result, 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 = 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 index a6355504..00000000 --- a/lemmy_db/src/community_view.rs +++ /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, - banner -> Nullable, - description -> Nullable, - category_id -> Int4, - creator_id -> Int4, - removed -> Bool, - published -> Timestamp, - updated -> Nullable, - 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, - creator_avatar -> Nullable, - category_name -> Varchar, - number_of_subscribers -> BigInt, - number_of_posts -> BigInt, - number_of_comments -> BigInt, - hot_rank -> Int4, - user_id -> Nullable, - subscribed -> Nullable, - } -} - -table! { - community_fast_view (id) { - id -> Int4, - name -> Varchar, - title -> Varchar, - icon -> Nullable, - banner -> Nullable, - description -> Nullable, - category_id -> Int4, - creator_id -> Int4, - removed -> Bool, - published -> Timestamp, - updated -> Nullable, - 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, - creator_avatar -> Nullable, - category_name -> Varchar, - number_of_subscribers -> BigInt, - number_of_posts -> BigInt, - number_of_comments -> BigInt, - hot_rank -> Int4, - user_id -> Nullable, - subscribed -> Nullable, - } -} - -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, - avatar -> Nullable, - community_actor_id -> Text, - community_local -> Bool, - community_name -> Varchar, - community_icon -> Nullable, - } -} - -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, - avatar -> Nullable, - community_actor_id -> Text, - community_local -> Bool, - community_name -> Varchar, - community_icon -> Nullable, - } -} - -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, - avatar -> Nullable, - community_actor_id -> Text, - community_local -> Bool, - community_name -> Varchar, - community_icon -> Nullable, - } -} - -#[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, - pub banner: Option, - pub description: Option, - pub category_id: i32, - pub creator_id: i32, - pub removed: bool, - pub published: chrono::NaiveDateTime, - pub updated: Option, - 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, - pub creator_avatar: Option, - 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, - pub subscribed: Option, -} - -pub struct CommunityQueryBuilder<'a> { - conn: &'a PgConnection, - query: BoxedQuery<'a, Pg>, - sort: &'a SortType, - from_user_id: Option, - show_nsfw: bool, - search_term: Option, - page: Option, - limit: Option, -} - -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>(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>(mut self, search_term: T) -> Self { - self.search_term = search_term.get_optional(); - self - } - - pub fn page>(mut self, page: T) -> Self { - self.page = page.get_optional(); - self - } - - pub fn limit>(mut self, limit: T) -> Self { - self.limit = limit.get_optional(); - self - } - - pub fn list(self) -> Result, 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::(self.conn) - } -} - -impl CommunityView { - pub fn read( - conn: &PgConnection, - from_community_id: i32, - from_user_id: Option, - ) -> Result { - 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::(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, - pub avatar: Option, - pub community_actor_id: String, - pub community_local: bool, - pub community_name: String, - pub community_icon: Option, -} - -impl CommunityModeratorView { - pub fn for_community(conn: &PgConnection, for_community_id: i32) -> Result, Error> { - use super::community_view::community_moderator_view::dsl::*; - community_moderator_view - .filter(community_id.eq(for_community_id)) - .order_by(published) - .load::(conn) - } - - pub fn for_user(conn: &PgConnection, for_user_id: i32) -> Result, Error> { - use super::community_view::community_moderator_view::dsl::*; - community_moderator_view - .filter(user_id.eq(for_user_id)) - .order_by(published) - .load::(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, - pub avatar: Option, - pub community_actor_id: String, - pub community_local: bool, - pub community_name: String, - pub community_icon: Option, -} - -impl CommunityFollowerView { - pub fn for_community(conn: &PgConnection, from_community_id: i32) -> Result, Error> { - use super::community_view::community_follower_view::dsl::*; - community_follower_view - .filter(community_id.eq(from_community_id)) - .load::(conn) - } - - pub fn for_user(conn: &PgConnection, from_user_id: i32) -> Result, Error> { - use super::community_view::community_follower_view::dsl::*; - community_follower_view - .filter(user_id.eq(from_user_id)) - .load::(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, - pub avatar: Option, - pub community_actor_id: String, - pub community_local: bool, - pub community_name: String, - pub community_icon: Option, -} - -impl CommunityUserBanView { - pub fn get( - conn: &PgConnection, - from_user_id: i32, - from_community_id: i32, - ) -> Result { - 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::(conn) - } -} diff --git a/lemmy_db/src/lib.rs b/lemmy_db/src/lib.rs index 4f2e85cd..9fb43d6e 100644 --- a/lemmy_db/src/lib.rs +++ b/lemmy_db/src/lib.rs @@ -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; diff --git a/lemmy_structs/src/community.rs b/lemmy_structs/src/community.rs index 7db71c95..c107084b 100644 --- a/lemmy_structs/src/community.rs +++ b/lemmy_structs/src/community.rs @@ -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, 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, } diff --git a/lemmy_structs/src/post.rs b/lemmy_structs/src/post.rs index 331c2dca..8d4be325 100644 --- a/lemmy_structs/src/post.rs +++ b/lemmy_structs/src/post.rs @@ -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}; diff --git a/lemmy_structs/src/site.rs b/lemmy_structs/src/site.rs index 6dfa518b..9f2efd79 100644 --- a/lemmy_structs/src/site.rs +++ b/lemmy_structs/src/site.rs @@ -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}; diff --git a/lemmy_structs/src/user.rs b/lemmy_structs/src/user.rs index 93f92940..0a7c6f08 100644 --- a/lemmy_structs/src/user.rs +++ b/lemmy_structs/src/user.rs @@ -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};