mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-13 20:41:08 +00:00
Removing old communityviews
This commit is contained in:
parent
5e510e7a67
commit
36f7b20784
18 changed files with 82 additions and 469 deletions
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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},
|
||||
},
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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())?);
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
||||
|
|
Loading…
Reference in a new issue