Get rid of Safe Views, use serde_skip (#2767)
* Get rid of Safe Views, use serde_skip - Also change the ViewToVec, to work with non-vector cases. Might be necessary in preparation for #2763 - Fixes #2712 * Forgot one safe --------- Co-authored-by: Nutomic <me@nutomic.com>
This commit is contained in:
parent
48f187188b
commit
985fe24669
55 changed files with 825 additions and 1322 deletions
|
@ -18,7 +18,7 @@ use lemmy_db_schema::{
|
|||
},
|
||||
traits::{Bannable, Crud, Followable},
|
||||
};
|
||||
use lemmy_db_views_actor::structs::PersonViewSafe;
|
||||
use lemmy_db_views_actor::structs::PersonView;
|
||||
use lemmy_utils::{error::LemmyError, utils::time::naive_from_unix, ConnectionId};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
|
@ -88,7 +88,7 @@ impl Perform for BanFromCommunity {
|
|||
ModBanFromCommunity::create(context.pool(), &form).await?;
|
||||
|
||||
let person_id = data.person_id;
|
||||
let person_view = PersonViewSafe::read(context.pool(), person_id).await?;
|
||||
let person_view = PersonView::read(context.pool(), person_id).await?;
|
||||
|
||||
let res = BanFromCommunityResponse {
|
||||
person_view,
|
||||
|
|
|
@ -13,7 +13,7 @@ use lemmy_db_schema::{
|
|||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_db_views_actor::structs::PersonViewSafe;
|
||||
use lemmy_db_views_actor::structs::PersonView;
|
||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
|
@ -52,7 +52,7 @@ impl Perform for AddAdmin {
|
|||
|
||||
ModAdd::create(context.pool(), &form).await?;
|
||||
|
||||
let admins = PersonViewSafe::admins(context.pool()).await?;
|
||||
let admins = PersonView::admins(context.pool()).await?;
|
||||
|
||||
let res = AddAdminResponse { admins };
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ use lemmy_db_schema::{
|
|||
},
|
||||
traits::Crud,
|
||||
};
|
||||
use lemmy_db_views_actor::structs::PersonViewSafe;
|
||||
use lemmy_db_views_actor::structs::PersonView;
|
||||
use lemmy_utils::{error::LemmyError, utils::time::naive_from_unix, ConnectionId};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
|
@ -72,7 +72,7 @@ impl Perform for BanPerson {
|
|||
ModBan::create(context.pool(), &form).await?;
|
||||
|
||||
let person_id = data.person_id;
|
||||
let person_view = PersonViewSafe::read(context.pool(), person_id).await?;
|
||||
let person_view = PersonView::read(context.pool(), person_id).await?;
|
||||
|
||||
let res = BanPersonResponse {
|
||||
person_view,
|
||||
|
|
|
@ -9,7 +9,7 @@ use lemmy_db_schema::{
|
|||
source::person_block::{PersonBlock, PersonBlockForm},
|
||||
traits::Blockable,
|
||||
};
|
||||
use lemmy_db_views_actor::structs::PersonViewSafe;
|
||||
use lemmy_db_views_actor::structs::PersonView;
|
||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
|
@ -39,7 +39,7 @@ impl Perform for BlockPerson {
|
|||
target_id,
|
||||
};
|
||||
|
||||
let target_person_view = PersonViewSafe::read(context.pool(), target_id).await?;
|
||||
let target_person_view = PersonView::read(context.pool(), target_id).await?;
|
||||
|
||||
if target_person_view.person.admin {
|
||||
return Err(LemmyError::from_message("cant_block_admin"));
|
||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
|||
person::{BannedPersonsResponse, GetBannedPersons},
|
||||
utils::{get_local_user_view_from_jwt, is_admin},
|
||||
};
|
||||
use lemmy_db_views_actor::structs::PersonViewSafe;
|
||||
use lemmy_db_views_actor::structs::PersonView;
|
||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
|
@ -24,7 +24,7 @@ impl Perform for GetBannedPersons {
|
|||
// Make sure user is an admin
|
||||
is_admin(&local_user_view)?;
|
||||
|
||||
let banned = PersonViewSafe::banned(context.pool()).await?;
|
||||
let banned = PersonView::banned(context.pool()).await?;
|
||||
|
||||
let res = Self::Response { banned };
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ use lemmy_db_schema::{
|
|||
traits::Crud,
|
||||
};
|
||||
use lemmy_db_views::structs::SiteView;
|
||||
use lemmy_db_views_actor::structs::PersonViewSafe;
|
||||
use lemmy_db_views_actor::structs::PersonView;
|
||||
use lemmy_utils::{error::LemmyError, version, ConnectionId};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
|
@ -36,7 +36,7 @@ impl Perform for LeaveAdmin {
|
|||
is_admin(&local_user_view)?;
|
||||
|
||||
// Make sure there isn't just one admin (so if one leaves, there will still be one left)
|
||||
let admins = PersonViewSafe::admins(context.pool()).await?;
|
||||
let admins = PersonView::admins(context.pool()).await?;
|
||||
if admins.len() == 1 {
|
||||
return Err(LemmyError::from_message("cannot_leave_admin"));
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ impl Perform for LeaveAdmin {
|
|||
|
||||
// Reread site and admins
|
||||
let site_view = SiteView::read_local(context.pool()).await?;
|
||||
let admins = PersonViewSafe::admins(context.pool()).await?;
|
||||
let admins = PersonView::admins(context.pool()).await?;
|
||||
|
||||
let all_languages = Language::read_all(context.pool()).await?;
|
||||
let discussion_languages = SiteLanguage::read_local(context.pool()).await?;
|
||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_db_schema::{
|
|||
ListingType,
|
||||
SortType,
|
||||
};
|
||||
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonViewSafe};
|
||||
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonView};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
|
@ -74,7 +74,7 @@ pub struct BanFromCommunity {
|
|||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct BanFromCommunityResponse {
|
||||
pub person_view: PersonViewSafe,
|
||||
pub person_view: PersonView,
|
||||
pub banned: bool,
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ use lemmy_db_views_actor::structs::{
|
|||
CommentReplyView,
|
||||
CommunityModeratorView,
|
||||
PersonMentionView,
|
||||
PersonViewSafe,
|
||||
PersonView,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
@ -104,7 +104,7 @@ pub struct GetPersonDetails {
|
|||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct GetPersonDetailsResponse {
|
||||
pub person_view: PersonViewSafe,
|
||||
pub person_view: PersonView,
|
||||
pub comments: Vec<CommentView>,
|
||||
pub posts: Vec<PostView>,
|
||||
pub moderates: Vec<CommunityModeratorView>,
|
||||
|
@ -134,7 +134,7 @@ pub struct AddAdmin {
|
|||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct AddAdminResponse {
|
||||
pub admins: Vec<PersonViewSafe>,
|
||||
pub admins: Vec<PersonView>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
|
@ -154,12 +154,12 @@ pub struct GetBannedPersons {
|
|||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct BannedPersonsResponse {
|
||||
pub banned: Vec<PersonViewSafe>,
|
||||
pub banned: Vec<PersonView>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct BanPersonResponse {
|
||||
pub person_view: PersonViewSafe,
|
||||
pub person_view: PersonView,
|
||||
pub banned: bool,
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ pub struct BlockPerson {
|
|||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct BlockPersonResponse {
|
||||
pub person_view: PersonViewSafe,
|
||||
pub person_view: PersonView,
|
||||
pub blocked: bool,
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ use lemmy_db_schema::{
|
|||
};
|
||||
use lemmy_db_views::structs::{
|
||||
CommentView,
|
||||
LocalUserSettingsView,
|
||||
LocalUserView,
|
||||
PostView,
|
||||
RegistrationApplicationView,
|
||||
SiteView,
|
||||
|
@ -25,7 +25,7 @@ use lemmy_db_views_actor::structs::{
|
|||
CommunityModeratorView,
|
||||
CommunityView,
|
||||
PersonBlockView,
|
||||
PersonViewSafe,
|
||||
PersonView,
|
||||
};
|
||||
use lemmy_db_views_moderator::structs::{
|
||||
AdminPurgeCommentView,
|
||||
|
@ -66,7 +66,7 @@ pub struct SearchResponse {
|
|||
pub comments: Vec<CommentView>,
|
||||
pub posts: Vec<PostView>,
|
||||
pub communities: Vec<CommunityView>,
|
||||
pub users: Vec<PersonViewSafe>,
|
||||
pub users: Vec<PersonView>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
|
@ -80,7 +80,7 @@ pub struct ResolveObjectResponse {
|
|||
pub comment: Option<CommentView>,
|
||||
pub post: Option<PostView>,
|
||||
pub community: Option<CommunityView>,
|
||||
pub person: Option<PersonViewSafe>,
|
||||
pub person: Option<PersonView>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||
|
@ -217,7 +217,7 @@ pub struct SiteResponse {
|
|||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct GetSiteResponse {
|
||||
pub site_view: SiteView,
|
||||
pub admins: Vec<PersonViewSafe>,
|
||||
pub admins: Vec<PersonView>,
|
||||
pub online: usize,
|
||||
pub version: String,
|
||||
pub my_user: Option<MyUserInfo>,
|
||||
|
@ -229,7 +229,7 @@ pub struct GetSiteResponse {
|
|||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct MyUserInfo {
|
||||
pub local_user_view: LocalUserSettingsView,
|
||||
pub local_user_view: LocalUserView,
|
||||
pub follows: Vec<CommunityFollowerView>,
|
||||
pub moderates: Vec<CommunityModeratorView>,
|
||||
pub community_blocks: Vec<CommunityBlockView>,
|
||||
|
|
|
@ -22,15 +22,12 @@ use lemmy_db_schema::{
|
|||
utils::DbPool,
|
||||
ListingType,
|
||||
};
|
||||
use lemmy_db_views::{
|
||||
comment_view::CommentQuery,
|
||||
structs::{LocalUserSettingsView, LocalUserView},
|
||||
};
|
||||
use lemmy_db_views::{comment_view::CommentQuery, structs::LocalUserView};
|
||||
use lemmy_db_views_actor::structs::{
|
||||
CommunityModeratorView,
|
||||
CommunityPersonBanView,
|
||||
CommunityView,
|
||||
PersonViewSafe,
|
||||
PersonView,
|
||||
};
|
||||
use lemmy_utils::{
|
||||
claims::Claims,
|
||||
|
@ -79,7 +76,7 @@ pub async fn is_mod_or_admin_opt(
|
|||
}
|
||||
|
||||
pub async fn is_top_admin(pool: &DbPool, person_id: PersonId) -> Result<(), LemmyError> {
|
||||
let admins = PersonViewSafe::admins(pool).await?;
|
||||
let admins = PersonView::admins(pool).await?;
|
||||
let top_admin = admins
|
||||
.first()
|
||||
.ok_or_else(|| LemmyError::from_message("no admins"))?;
|
||||
|
@ -197,14 +194,14 @@ pub async fn get_local_user_settings_view_from_jwt_opt(
|
|||
jwt: Option<&Sensitive<String>>,
|
||||
pool: &DbPool,
|
||||
secret: &Secret,
|
||||
) -> Result<Option<LocalUserSettingsView>, LemmyError> {
|
||||
) -> Result<Option<LocalUserView>, LemmyError> {
|
||||
match jwt {
|
||||
Some(jwt) => {
|
||||
let claims = Claims::decode(jwt.as_ref(), &secret.jwt_secret)
|
||||
.map_err(|e| e.with_message("not_logged_in"))?
|
||||
.claims;
|
||||
let local_user_id = LocalUserId(claims.sub);
|
||||
let local_user_view = LocalUserSettingsView::read(pool, local_user_id).await?;
|
||||
let local_user_view = LocalUserView::read(pool, local_user_id).await?;
|
||||
check_user_valid(
|
||||
local_user_view.person.banned,
|
||||
local_user_view.person.ban_expires,
|
||||
|
@ -450,7 +447,7 @@ pub fn get_interface_language(user: &LocalUserView) -> Lang {
|
|||
lang_str_to_lang(&user.local_user.interface_language)
|
||||
}
|
||||
|
||||
pub fn get_interface_language_from_settings(user: &LocalUserSettingsView) -> Lang {
|
||||
pub fn get_interface_language_from_settings(user: &LocalUserView) -> Lang {
|
||||
lang_str_to_lang(&user.local_user.interface_language)
|
||||
}
|
||||
|
||||
|
@ -511,7 +508,7 @@ pub async fn send_new_applicant_email_to_admins(
|
|||
settings: &Settings,
|
||||
) -> Result<(), LemmyError> {
|
||||
// Collect the admins with emails
|
||||
let admins = LocalUserSettingsView::list_admins_with_emails(pool).await?;
|
||||
let admins = LocalUserView::list_admins_with_emails(pool).await?;
|
||||
|
||||
let applications_link = &format!(
|
||||
"{}/registration_applications",
|
||||
|
@ -536,7 +533,7 @@ pub async fn send_new_report_email_to_admins(
|
|||
settings: &Settings,
|
||||
) -> Result<(), LemmyError> {
|
||||
// Collect the admins with emails
|
||||
let admins = LocalUserSettingsView::list_admins_with_emails(pool).await?;
|
||||
let admins = LocalUserView::list_admins_with_emails(pool).await?;
|
||||
|
||||
let reports_link = &format!("{}/reports", settings.get_protocol_and_hostname(),);
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ use lemmy_db_views_actor::structs::{
|
|||
CommunityFollowerView,
|
||||
CommunityModeratorView,
|
||||
PersonBlockView,
|
||||
PersonViewSafe,
|
||||
PersonView,
|
||||
};
|
||||
use lemmy_utils::{error::LemmyError, version, ConnectionId};
|
||||
|
||||
|
@ -34,7 +34,7 @@ impl PerformCrud for GetSite {
|
|||
|
||||
let site_view = SiteView::read_local(context.pool()).await?;
|
||||
|
||||
let admins = PersonViewSafe::admins(context.pool()).await?;
|
||||
let admins = PersonView::admins(context.pool()).await?;
|
||||
|
||||
let online = context.chat_server().get_users_online()?;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ use lemmy_db_schema::{
|
|||
utils::post_to_comment_sort_type,
|
||||
};
|
||||
use lemmy_db_views::{comment_view::CommentQuery, post_view::PostQuery};
|
||||
use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonViewSafe};
|
||||
use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonView};
|
||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
|
@ -56,7 +56,7 @@ impl PerformApub for GetPersonDetails {
|
|||
|
||||
// You don't need to return settings for the user, since this comes back with GetSite
|
||||
// `my_user`
|
||||
let person_view = PersonViewSafe::read(context.pool(), person_details_id).await?;
|
||||
let person_view = PersonView::read(context.pool(), person_details_id).await?;
|
||||
|
||||
let sort = data.sort;
|
||||
let page = data.page;
|
||||
|
|
|
@ -11,7 +11,7 @@ use lemmy_api_common::{
|
|||
};
|
||||
use lemmy_db_schema::{newtypes::PersonId, source::local_site::LocalSite, utils::DbPool};
|
||||
use lemmy_db_views::structs::{CommentView, PostView};
|
||||
use lemmy_db_views_actor::structs::{CommunityView, PersonViewSafe};
|
||||
use lemmy_db_views_actor::structs::{CommunityView, PersonView};
|
||||
use lemmy_utils::{error::LemmyError, ConnectionId};
|
||||
|
||||
#[async_trait::async_trait(?Send)]
|
||||
|
@ -52,7 +52,7 @@ async fn convert_response(
|
|||
match object {
|
||||
Person(p) => {
|
||||
removed_or_deleted = p.deleted;
|
||||
res.person = Some(PersonViewSafe::read(pool, p.id).await?)
|
||||
res.person = Some(PersonView::read(pool, p.id).await?)
|
||||
}
|
||||
Community(c) => {
|
||||
removed_or_deleted = c.deleted || c.removed;
|
||||
|
|
|
@ -22,74 +22,6 @@ use crate::{
|
|||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods};
|
||||
use diesel_async::RunQueryDsl;
|
||||
|
||||
mod safe_type {
|
||||
use crate::{
|
||||
schema::community::{
|
||||
actor_id,
|
||||
banner,
|
||||
deleted,
|
||||
description,
|
||||
hidden,
|
||||
icon,
|
||||
id,
|
||||
instance_id,
|
||||
local,
|
||||
name,
|
||||
nsfw,
|
||||
posting_restricted_to_mods,
|
||||
published,
|
||||
removed,
|
||||
title,
|
||||
updated,
|
||||
},
|
||||
source::community::Community,
|
||||
traits::ToSafe,
|
||||
};
|
||||
|
||||
type Columns = (
|
||||
id,
|
||||
name,
|
||||
title,
|
||||
description,
|
||||
removed,
|
||||
published,
|
||||
updated,
|
||||
deleted,
|
||||
nsfw,
|
||||
actor_id,
|
||||
local,
|
||||
icon,
|
||||
banner,
|
||||
hidden,
|
||||
posting_restricted_to_mods,
|
||||
instance_id,
|
||||
);
|
||||
|
||||
impl ToSafe for Community {
|
||||
type SafeColumns = Columns;
|
||||
fn safe_columns_tuple() -> Self::SafeColumns {
|
||||
(
|
||||
id,
|
||||
name,
|
||||
title,
|
||||
description,
|
||||
removed,
|
||||
published,
|
||||
updated,
|
||||
deleted,
|
||||
nsfw,
|
||||
actor_id,
|
||||
local,
|
||||
icon,
|
||||
banner,
|
||||
hidden,
|
||||
posting_restricted_to_mods,
|
||||
instance_id,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Crud for Community {
|
||||
type InsertForm = CommunityInsertForm;
|
||||
|
|
|
@ -18,79 +18,6 @@ use bcrypt::{hash, DEFAULT_COST};
|
|||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||
use diesel_async::RunQueryDsl;
|
||||
|
||||
mod safe_settings_type {
|
||||
use crate::{
|
||||
schema::local_user::columns::{
|
||||
accepted_application,
|
||||
default_listing_type,
|
||||
default_sort_type,
|
||||
email,
|
||||
email_verified,
|
||||
id,
|
||||
interface_language,
|
||||
person_id,
|
||||
send_notifications_to_email,
|
||||
show_avatars,
|
||||
show_bot_accounts,
|
||||
show_new_post_notifs,
|
||||
show_nsfw,
|
||||
show_read_posts,
|
||||
show_scores,
|
||||
theme,
|
||||
validator_time,
|
||||
},
|
||||
source::local_user::LocalUser,
|
||||
traits::ToSafeSettings,
|
||||
};
|
||||
|
||||
type Columns = (
|
||||
id,
|
||||
person_id,
|
||||
email,
|
||||
show_nsfw,
|
||||
theme,
|
||||
default_sort_type,
|
||||
default_listing_type,
|
||||
interface_language,
|
||||
show_avatars,
|
||||
send_notifications_to_email,
|
||||
validator_time,
|
||||
show_bot_accounts,
|
||||
show_scores,
|
||||
show_read_posts,
|
||||
show_new_post_notifs,
|
||||
email_verified,
|
||||
accepted_application,
|
||||
);
|
||||
|
||||
impl ToSafeSettings for LocalUser {
|
||||
type SafeSettingsColumns = Columns;
|
||||
|
||||
/// Includes everything but the hashed password
|
||||
fn safe_settings_columns_tuple() -> Self::SafeSettingsColumns {
|
||||
(
|
||||
id,
|
||||
person_id,
|
||||
email,
|
||||
show_nsfw,
|
||||
theme,
|
||||
default_sort_type,
|
||||
default_listing_type,
|
||||
interface_language,
|
||||
show_avatars,
|
||||
send_notifications_to_email,
|
||||
validator_time,
|
||||
show_bot_accounts,
|
||||
show_scores,
|
||||
show_read_posts,
|
||||
show_new_post_notifs,
|
||||
email_verified,
|
||||
accepted_application,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LocalUser {
|
||||
pub async fn update_password(
|
||||
pool: &DbPool,
|
||||
|
|
|
@ -26,83 +26,6 @@ use crate::{
|
|||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods};
|
||||
use diesel_async::RunQueryDsl;
|
||||
|
||||
mod safe_type {
|
||||
use crate::{
|
||||
schema::person::columns::{
|
||||
actor_id,
|
||||
admin,
|
||||
avatar,
|
||||
ban_expires,
|
||||
banned,
|
||||
banner,
|
||||
bio,
|
||||
bot_account,
|
||||
deleted,
|
||||
display_name,
|
||||
id,
|
||||
inbox_url,
|
||||
instance_id,
|
||||
local,
|
||||
matrix_user_id,
|
||||
name,
|
||||
published,
|
||||
shared_inbox_url,
|
||||
updated,
|
||||
},
|
||||
source::person::Person,
|
||||
traits::ToSafe,
|
||||
};
|
||||
|
||||
type Columns = (
|
||||
id,
|
||||
name,
|
||||
display_name,
|
||||
avatar,
|
||||
banned,
|
||||
published,
|
||||
updated,
|
||||
actor_id,
|
||||
bio,
|
||||
local,
|
||||
banner,
|
||||
deleted,
|
||||
inbox_url,
|
||||
shared_inbox_url,
|
||||
matrix_user_id,
|
||||
admin,
|
||||
bot_account,
|
||||
ban_expires,
|
||||
instance_id,
|
||||
);
|
||||
|
||||
impl ToSafe for Person {
|
||||
type SafeColumns = Columns;
|
||||
fn safe_columns_tuple() -> Self::SafeColumns {
|
||||
(
|
||||
id,
|
||||
name,
|
||||
display_name,
|
||||
avatar,
|
||||
banned,
|
||||
published,
|
||||
updated,
|
||||
actor_id,
|
||||
bio,
|
||||
local,
|
||||
banner,
|
||||
deleted,
|
||||
inbox_url,
|
||||
shared_inbox_url,
|
||||
matrix_user_id,
|
||||
admin,
|
||||
bot_account,
|
||||
ban_expires,
|
||||
instance_id,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Crud for Person {
|
||||
type InsertForm = PersonInsertForm;
|
||||
|
|
|
@ -19,13 +19,19 @@ pub struct Community {
|
|||
pub nsfw: bool,
|
||||
pub actor_id: DbUrl,
|
||||
pub local: bool,
|
||||
#[serde(skip)]
|
||||
pub private_key: Option<String>,
|
||||
#[serde(skip)]
|
||||
pub public_key: String,
|
||||
#[serde(skip)]
|
||||
pub last_refreshed_at: chrono::NaiveDateTime,
|
||||
pub icon: Option<DbUrl>,
|
||||
pub banner: Option<DbUrl>,
|
||||
#[serde(skip_serializing)]
|
||||
pub followers_url: DbUrl,
|
||||
#[serde(skip_serializing)]
|
||||
pub inbox_url: DbUrl,
|
||||
#[serde(skip)]
|
||||
pub shared_inbox_url: Option<DbUrl>,
|
||||
/// Url where moderators collection is served over Activitypub
|
||||
#[serde(skip)]
|
||||
|
@ -38,29 +44,6 @@ pub struct Community {
|
|||
pub instance_id: InstanceId,
|
||||
}
|
||||
|
||||
/// A safe representation of community, without the sensitive info
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
|
||||
#[cfg_attr(feature = "full", diesel(table_name = community))]
|
||||
pub struct CommunitySafe {
|
||||
pub id: CommunityId,
|
||||
pub name: String,
|
||||
pub title: String,
|
||||
pub description: Option<String>,
|
||||
pub removed: bool,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub deleted: bool,
|
||||
pub nsfw: bool,
|
||||
pub actor_id: DbUrl,
|
||||
pub local: bool,
|
||||
pub icon: Option<DbUrl>,
|
||||
pub banner: Option<DbUrl>,
|
||||
pub hidden: bool,
|
||||
pub posting_restricted_to_mods: bool,
|
||||
pub instance_id: InstanceId,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, TypedBuilder)]
|
||||
#[builder(field_defaults(default))]
|
||||
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
|
||||
|
|
|
@ -10,6 +10,7 @@ use typed_builder::TypedBuilder;
|
|||
pub struct LocalUser {
|
||||
pub id: LocalUserId,
|
||||
pub person_id: PersonId,
|
||||
#[serde(skip)]
|
||||
pub password_encrypted: String,
|
||||
pub email: Option<String>,
|
||||
pub show_nsfw: bool,
|
||||
|
@ -28,30 +29,6 @@ pub struct LocalUser {
|
|||
pub accepted_application: bool,
|
||||
}
|
||||
|
||||
/// A local user view that removes password encrypted
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
|
||||
#[cfg_attr(feature = "full", diesel(table_name = local_user))]
|
||||
pub struct LocalUserSettings {
|
||||
pub id: LocalUserId,
|
||||
pub person_id: PersonId,
|
||||
pub email: Option<String>,
|
||||
pub show_nsfw: bool,
|
||||
pub theme: String,
|
||||
pub default_sort_type: i16,
|
||||
pub default_listing_type: i16,
|
||||
pub interface_language: String,
|
||||
pub show_avatars: bool,
|
||||
pub send_notifications_to_email: bool,
|
||||
pub validator_time: chrono::NaiveDateTime,
|
||||
pub show_bot_accounts: bool,
|
||||
pub show_scores: bool,
|
||||
pub show_read_posts: bool,
|
||||
pub show_new_post_notifs: bool,
|
||||
pub email_verified: bool,
|
||||
pub accepted_application: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, TypedBuilder)]
|
||||
#[builder(field_defaults(default))]
|
||||
#[cfg_attr(feature = "full", derive(Insertable))]
|
||||
|
|
|
@ -18,38 +18,17 @@ pub struct Person {
|
|||
pub actor_id: DbUrl,
|
||||
pub bio: Option<String>,
|
||||
pub local: bool,
|
||||
#[serde(skip)]
|
||||
pub private_key: Option<String>,
|
||||
#[serde(skip)]
|
||||
pub public_key: String,
|
||||
#[serde(skip)]
|
||||
pub last_refreshed_at: chrono::NaiveDateTime,
|
||||
pub banner: Option<DbUrl>,
|
||||
pub deleted: bool,
|
||||
#[serde(skip_serializing)]
|
||||
pub inbox_url: DbUrl,
|
||||
pub shared_inbox_url: Option<DbUrl>,
|
||||
pub matrix_user_id: Option<String>,
|
||||
pub admin: bool,
|
||||
pub bot_account: bool,
|
||||
pub ban_expires: Option<chrono::NaiveDateTime>,
|
||||
pub instance_id: InstanceId,
|
||||
}
|
||||
|
||||
/// A safe representation of person, without the sensitive info
|
||||
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
|
||||
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
|
||||
#[cfg_attr(feature = "full", diesel(table_name = person))]
|
||||
pub struct PersonSafe {
|
||||
pub id: PersonId,
|
||||
pub name: String,
|
||||
pub display_name: Option<String>,
|
||||
pub avatar: Option<DbUrl>,
|
||||
pub banned: bool,
|
||||
pub published: chrono::NaiveDateTime,
|
||||
pub updated: Option<chrono::NaiveDateTime>,
|
||||
pub actor_id: DbUrl,
|
||||
pub bio: Option<String>,
|
||||
pub local: bool,
|
||||
pub banner: Option<DbUrl>,
|
||||
pub deleted: bool,
|
||||
pub inbox_url: DbUrl,
|
||||
#[serde(skip)]
|
||||
pub shared_inbox_url: Option<DbUrl>,
|
||||
pub matrix_user_id: Option<String>,
|
||||
pub admin: bool,
|
||||
|
|
|
@ -140,19 +140,9 @@ pub trait Reportable {
|
|||
Self: Sized;
|
||||
}
|
||||
|
||||
pub trait ToSafe {
|
||||
type SafeColumns;
|
||||
fn safe_columns_tuple() -> Self::SafeColumns;
|
||||
}
|
||||
|
||||
pub trait ToSafeSettings {
|
||||
type SafeSettingsColumns;
|
||||
fn safe_settings_columns_tuple() -> Self::SafeSettingsColumns;
|
||||
}
|
||||
|
||||
pub trait ViewToVec {
|
||||
type DbTuple;
|
||||
fn from_tuple_to_vec(tuple: Vec<Self::DbTuple>) -> Vec<Self>
|
||||
pub trait JoinView {
|
||||
type JoinTuple;
|
||||
fn from_tuple(tuple: Self::JoinTuple) -> Self
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
|
|
@ -26,28 +26,15 @@ use lemmy_db_schema::{
|
|||
source::{
|
||||
comment::Comment,
|
||||
comment_report::CommentReport,
|
||||
community::{Community, CommunityPersonBan, CommunitySafe},
|
||||
person::{Person, PersonSafe},
|
||||
community::{Community, CommunityPersonBan},
|
||||
person::Person,
|
||||
post::Post,
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
use typed_builder::TypedBuilder;
|
||||
|
||||
type CommentReportViewTuple = (
|
||||
CommentReport,
|
||||
Comment,
|
||||
Post,
|
||||
CommunitySafe,
|
||||
PersonSafe,
|
||||
PersonSafe,
|
||||
CommentAggregates,
|
||||
Option<CommunityPersonBan>,
|
||||
Option<i16>,
|
||||
Option<PersonSafe>,
|
||||
);
|
||||
|
||||
impl CommentReportView {
|
||||
/// returns the CommentReportView for the provided report_id
|
||||
///
|
||||
|
@ -61,18 +48,7 @@ impl CommentReportView {
|
|||
|
||||
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
|
||||
|
||||
let (
|
||||
comment_report,
|
||||
comment,
|
||||
post,
|
||||
community,
|
||||
creator,
|
||||
comment_creator,
|
||||
counts,
|
||||
creator_banned_from_community,
|
||||
comment_like,
|
||||
resolver,
|
||||
) = comment_report::table
|
||||
let res = comment_report::table
|
||||
.find(report_id)
|
||||
.inner_join(comment::table)
|
||||
.inner_join(post::table.on(comment::post_id.eq(post::id)))
|
||||
|
@ -109,33 +85,18 @@ impl CommentReportView {
|
|||
comment_report::all_columns,
|
||||
comment::all_columns,
|
||||
post::all_columns,
|
||||
Community::safe_columns_tuple(),
|
||||
Person::safe_columns_tuple(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
community::all_columns,
|
||||
person::all_columns,
|
||||
person_alias_1.fields(person::all_columns),
|
||||
comment_aggregates::all_columns,
|
||||
community_person_ban::all_columns.nullable(),
|
||||
comment_like::score.nullable(),
|
||||
person_alias_2
|
||||
.fields(Person::safe_columns_tuple())
|
||||
.nullable(),
|
||||
person_alias_2.fields(person::all_columns).nullable(),
|
||||
))
|
||||
.first::<CommentReportViewTuple>(conn)
|
||||
.first::<<CommentReportView as JoinView>::JoinTuple>(conn)
|
||||
.await?;
|
||||
|
||||
let my_vote = comment_like;
|
||||
|
||||
Ok(Self {
|
||||
comment_report,
|
||||
comment,
|
||||
post,
|
||||
community,
|
||||
creator,
|
||||
comment_creator,
|
||||
counts,
|
||||
creator_banned_from_community: creator_banned_from_community.is_some(),
|
||||
my_vote,
|
||||
resolver,
|
||||
})
|
||||
Ok(Self::from_tuple(res))
|
||||
}
|
||||
|
||||
/// Returns the current unresolved post report count for the communities you mod
|
||||
|
@ -238,15 +199,13 @@ impl<'a> CommentReportQuery<'a> {
|
|||
comment_report::all_columns,
|
||||
comment::all_columns,
|
||||
post::all_columns,
|
||||
Community::safe_columns_tuple(),
|
||||
Person::safe_columns_tuple(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
community::all_columns,
|
||||
person::all_columns,
|
||||
person_alias_1.fields(person::all_columns),
|
||||
comment_aggregates::all_columns,
|
||||
community_person_ban::all_columns.nullable(),
|
||||
comment_like::score.nullable(),
|
||||
person_alias_2
|
||||
.fields(Person::safe_columns_tuple())
|
||||
.nullable(),
|
||||
person_alias_2.fields(person::all_columns).nullable(),
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -275,22 +234,34 @@ impl<'a> CommentReportQuery<'a> {
|
|||
.and(community_moderator::person_id.eq(self.my_person_id)),
|
||||
),
|
||||
)
|
||||
.load::<CommentReportViewTuple>(conn)
|
||||
.load::<<CommentReportView as JoinView>::JoinTuple>(conn)
|
||||
.await?
|
||||
} else {
|
||||
query.load::<CommentReportViewTuple>(conn).await?
|
||||
query
|
||||
.load::<<CommentReportView as JoinView>::JoinTuple>(conn)
|
||||
.await?
|
||||
};
|
||||
|
||||
Ok(CommentReportView::from_tuple_to_vec(res))
|
||||
Ok(res.into_iter().map(CommentReportView::from_tuple).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for CommentReportView {
|
||||
type DbTuple = CommentReportViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for CommentReportView {
|
||||
type JoinTuple = (
|
||||
CommentReport,
|
||||
Comment,
|
||||
Post,
|
||||
Community,
|
||||
Person,
|
||||
Person,
|
||||
CommentAggregates,
|
||||
Option<CommunityPersonBan>,
|
||||
Option<i16>,
|
||||
Option<Person>,
|
||||
);
|
||||
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
comment_report: a.0,
|
||||
comment: a.1,
|
||||
post: a.2,
|
||||
|
@ -301,8 +272,7 @@ impl ViewToVec for CommentReportView {
|
|||
creator_banned_from_community: a.7.is_some(),
|
||||
my_vote: a.8,
|
||||
resolver: a.9,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -314,15 +284,9 @@ mod tests {
|
|||
source::{
|
||||
comment::{Comment, CommentInsertForm},
|
||||
comment_report::{CommentReport, CommentReportForm},
|
||||
community::{
|
||||
Community,
|
||||
CommunityInsertForm,
|
||||
CommunityModerator,
|
||||
CommunityModeratorForm,
|
||||
CommunitySafe,
|
||||
},
|
||||
community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm},
|
||||
instance::Instance,
|
||||
person::{Person, PersonInsertForm, PersonSafe},
|
||||
person::{Person, PersonInsertForm},
|
||||
post::{Post, PostInsertForm},
|
||||
},
|
||||
traits::{Crud, Joinable, Reportable},
|
||||
|
@ -435,7 +399,7 @@ mod tests {
|
|||
comment_report: inserted_jessica_report.clone(),
|
||||
comment: inserted_comment.clone(),
|
||||
post: inserted_post,
|
||||
community: CommunitySafe {
|
||||
community: Community {
|
||||
id: inserted_community.id,
|
||||
name: inserted_community.name,
|
||||
icon: None,
|
||||
|
@ -451,9 +415,17 @@ mod tests {
|
|||
hidden: false,
|
||||
posting_restricted_to_mods: false,
|
||||
published: inserted_community.published,
|
||||
private_key: inserted_community.private_key,
|
||||
public_key: inserted_community.public_key,
|
||||
last_refreshed_at: inserted_community.last_refreshed_at,
|
||||
followers_url: inserted_community.followers_url,
|
||||
inbox_url: inserted_community.inbox_url,
|
||||
shared_inbox_url: inserted_community.shared_inbox_url,
|
||||
moderators_url: inserted_community.moderators_url,
|
||||
featured_url: inserted_community.featured_url,
|
||||
instance_id: inserted_instance.id,
|
||||
},
|
||||
creator: PersonSafe {
|
||||
creator: Person {
|
||||
id: inserted_jessica.id,
|
||||
name: inserted_jessica.name,
|
||||
display_name: None,
|
||||
|
@ -473,8 +445,11 @@ mod tests {
|
|||
matrix_user_id: None,
|
||||
ban_expires: None,
|
||||
instance_id: inserted_instance.id,
|
||||
private_key: inserted_jessica.private_key,
|
||||
public_key: inserted_jessica.public_key,
|
||||
last_refreshed_at: inserted_jessica.last_refreshed_at,
|
||||
},
|
||||
comment_creator: PersonSafe {
|
||||
comment_creator: Person {
|
||||
id: inserted_timmy.id,
|
||||
name: inserted_timmy.name.clone(),
|
||||
display_name: None,
|
||||
|
@ -494,6 +469,9 @@ mod tests {
|
|||
matrix_user_id: None,
|
||||
ban_expires: None,
|
||||
instance_id: inserted_instance.id,
|
||||
private_key: inserted_timmy.private_key.clone(),
|
||||
public_key: inserted_timmy.public_key.clone(),
|
||||
last_refreshed_at: inserted_timmy.last_refreshed_at,
|
||||
},
|
||||
creator_banned_from_community: false,
|
||||
counts: CommentAggregates {
|
||||
|
@ -513,7 +491,7 @@ mod tests {
|
|||
|
||||
let mut expected_sara_report_view = expected_jessica_report_view.clone();
|
||||
expected_sara_report_view.comment_report = inserted_sara_report;
|
||||
expected_sara_report_view.creator = PersonSafe {
|
||||
expected_sara_report_view.creator = Person {
|
||||
id: inserted_sara.id,
|
||||
name: inserted_sara.name,
|
||||
display_name: None,
|
||||
|
@ -533,6 +511,9 @@ mod tests {
|
|||
matrix_user_id: None,
|
||||
ban_expires: None,
|
||||
instance_id: inserted_instance.id,
|
||||
private_key: inserted_sara.private_key,
|
||||
public_key: inserted_sara.public_key,
|
||||
last_refreshed_at: inserted_sara.last_refreshed_at,
|
||||
};
|
||||
|
||||
// Do a batch read of timmys reports
|
||||
|
@ -580,7 +561,7 @@ mod tests {
|
|||
.updated = read_jessica_report_view_after_resolve
|
||||
.comment_report
|
||||
.updated;
|
||||
expected_jessica_report_view_after_resolve.resolver = Some(PersonSafe {
|
||||
expected_jessica_report_view_after_resolve.resolver = Some(Person {
|
||||
id: inserted_timmy.id,
|
||||
name: inserted_timmy.name.clone(),
|
||||
display_name: None,
|
||||
|
@ -596,6 +577,9 @@ mod tests {
|
|||
banner: None,
|
||||
updated: None,
|
||||
inbox_url: inserted_timmy.inbox_url.clone(),
|
||||
private_key: inserted_timmy.private_key.clone(),
|
||||
public_key: inserted_timmy.public_key.clone(),
|
||||
last_refreshed_at: inserted_timmy.last_refreshed_at,
|
||||
shared_inbox_url: None,
|
||||
matrix_user_id: None,
|
||||
ban_expires: None,
|
||||
|
|
|
@ -30,13 +30,13 @@ use lemmy_db_schema::{
|
|||
},
|
||||
source::{
|
||||
comment::{Comment, CommentSaved},
|
||||
community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe},
|
||||
community::{Community, CommunityFollower, CommunityPersonBan},
|
||||
local_user::LocalUser,
|
||||
person::{Person, PersonSafe},
|
||||
person::Person,
|
||||
person_block::PersonBlock,
|
||||
post::Post,
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
traits::JoinView,
|
||||
utils::{functions::hot_rank, fuzzy_search, get_conn, limit_and_offset_unlimited, DbPool},
|
||||
CommentSortType,
|
||||
ListingType,
|
||||
|
@ -45,9 +45,9 @@ use typed_builder::TypedBuilder;
|
|||
|
||||
type CommentViewTuple = (
|
||||
Comment,
|
||||
PersonSafe,
|
||||
Person,
|
||||
Post,
|
||||
CommunitySafe,
|
||||
Community,
|
||||
CommentAggregates,
|
||||
Option<CommunityPersonBan>,
|
||||
Option<CommunityFollower>,
|
||||
|
@ -126,9 +126,9 @@ impl CommentView {
|
|||
)
|
||||
.select((
|
||||
comment::all_columns,
|
||||
Person::safe_columns_tuple(),
|
||||
person::all_columns,
|
||||
post::all_columns,
|
||||
Community::safe_columns_tuple(),
|
||||
community::all_columns,
|
||||
comment_aggregates::all_columns,
|
||||
community_person_ban::all_columns.nullable(),
|
||||
community_follower::all_columns.nullable(),
|
||||
|
@ -252,9 +252,9 @@ impl<'a> CommentQuery<'a> {
|
|||
)
|
||||
.select((
|
||||
comment::all_columns,
|
||||
Person::safe_columns_tuple(),
|
||||
person::all_columns,
|
||||
post::all_columns,
|
||||
Community::safe_columns_tuple(),
|
||||
community::all_columns,
|
||||
comment_aggregates::all_columns,
|
||||
community_person_ban::all_columns.nullable(),
|
||||
community_follower::all_columns.nullable(),
|
||||
|
@ -375,16 +375,14 @@ impl<'a> CommentQuery<'a> {
|
|||
.load::<CommentViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
Ok(CommentView::from_tuple_to_vec(res))
|
||||
Ok(res.into_iter().map(CommentView::from_tuple).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for CommentView {
|
||||
type DbTuple = CommentViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for CommentView {
|
||||
type JoinTuple = CommentViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
comment: a.0,
|
||||
creator: a.1,
|
||||
post: a.2,
|
||||
|
@ -395,8 +393,7 @@ impl ViewToVec for CommentView {
|
|||
saved: a.7.is_some(),
|
||||
creator_blocked: a.8.is_some(),
|
||||
my_vote: a.9,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -408,12 +405,10 @@ mod tests {
|
|||
CommentSortType,
|
||||
CommentView,
|
||||
Community,
|
||||
CommunitySafe,
|
||||
DbPool,
|
||||
LocalUser,
|
||||
Person,
|
||||
PersonBlock,
|
||||
PersonSafe,
|
||||
Post,
|
||||
};
|
||||
use lemmy_db_schema::{
|
||||
|
@ -841,7 +836,7 @@ mod tests {
|
|||
path: data.inserted_comment_0.clone().path,
|
||||
language_id: LanguageId(0),
|
||||
},
|
||||
creator: PersonSafe {
|
||||
creator: Person {
|
||||
id: data.inserted_person.id,
|
||||
name: "timmy".into(),
|
||||
display_name: None,
|
||||
|
@ -861,6 +856,9 @@ mod tests {
|
|||
matrix_user_id: None,
|
||||
ban_expires: None,
|
||||
instance_id: data.inserted_instance.id,
|
||||
private_key: data.inserted_person.private_key.clone(),
|
||||
public_key: data.inserted_person.public_key.clone(),
|
||||
last_refreshed_at: data.inserted_person.last_refreshed_at,
|
||||
},
|
||||
post: Post {
|
||||
id: data.inserted_post.id,
|
||||
|
@ -885,7 +883,7 @@ mod tests {
|
|||
featured_community: false,
|
||||
featured_local: false,
|
||||
},
|
||||
community: CommunitySafe {
|
||||
community: Community {
|
||||
id: data.inserted_community.id,
|
||||
name: "test community 5".to_string(),
|
||||
icon: None,
|
||||
|
@ -902,6 +900,14 @@ mod tests {
|
|||
posting_restricted_to_mods: false,
|
||||
published: data.inserted_community.published,
|
||||
instance_id: data.inserted_instance.id,
|
||||
private_key: data.inserted_community.private_key.clone(),
|
||||
public_key: data.inserted_community.public_key.clone(),
|
||||
last_refreshed_at: data.inserted_community.last_refreshed_at,
|
||||
followers_url: data.inserted_community.followers_url.clone(),
|
||||
inbox_url: data.inserted_community.inbox_url.clone(),
|
||||
shared_inbox_url: data.inserted_community.shared_inbox_url.clone(),
|
||||
moderators_url: data.inserted_community.moderators_url.clone(),
|
||||
featured_url: data.inserted_community.featured_url.clone(),
|
||||
},
|
||||
counts: CommentAggregates {
|
||||
id: agg.id,
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
use crate::structs::{LocalUserSettingsView, LocalUserView};
|
||||
use crate::structs::LocalUserView;
|
||||
use diesel::{result::Error, BoolExpressionMethods, ExpressionMethods, JoinOnDsl, QueryDsl};
|
||||
use diesel_async::RunQueryDsl;
|
||||
use lemmy_db_schema::{
|
||||
aggregates::structs::PersonAggregates,
|
||||
newtypes::{LocalUserId, PersonId},
|
||||
schema::{local_user, person, person_aggregates},
|
||||
source::{
|
||||
local_user::{LocalUser, LocalUserSettings},
|
||||
person::{Person, PersonSafe},
|
||||
},
|
||||
traits::{ToSafe, ToSafeSettings, ViewToVec},
|
||||
source::{local_user::LocalUser, person::Person},
|
||||
traits::JoinView,
|
||||
utils::{functions::lower, get_conn, DbPool},
|
||||
};
|
||||
|
||||
|
@ -121,30 +118,6 @@ impl LocalUserView {
|
|||
counts,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type LocalUserSettingsViewTuple = (LocalUserSettings, PersonSafe, PersonAggregates);
|
||||
|
||||
impl LocalUserSettingsView {
|
||||
pub async fn read(pool: &DbPool, local_user_id: LocalUserId) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
let (local_user, person, counts) = local_user::table
|
||||
.find(local_user_id)
|
||||
.inner_join(person::table)
|
||||
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
|
||||
.select((
|
||||
LocalUser::safe_settings_columns_tuple(),
|
||||
Person::safe_columns_tuple(),
|
||||
person_aggregates::all_columns,
|
||||
))
|
||||
.first::<LocalUserSettingsViewTuple>(conn)
|
||||
.await?;
|
||||
Ok(Self {
|
||||
local_user,
|
||||
person,
|
||||
counts,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn list_admins_with_emails(pool: &DbPool) -> Result<Vec<Self>, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
|
@ -154,27 +127,24 @@ impl LocalUserSettingsView {
|
|||
.inner_join(person::table)
|
||||
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
|
||||
.select((
|
||||
LocalUser::safe_settings_columns_tuple(),
|
||||
Person::safe_columns_tuple(),
|
||||
local_user::all_columns,
|
||||
person::all_columns,
|
||||
person_aggregates::all_columns,
|
||||
))
|
||||
.load::<LocalUserSettingsViewTuple>(conn)
|
||||
.load::<LocalUserViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
Ok(LocalUserSettingsView::from_tuple_to_vec(res))
|
||||
Ok(res.into_iter().map(LocalUserView::from_tuple).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for LocalUserSettingsView {
|
||||
type DbTuple = LocalUserSettingsViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for LocalUserView {
|
||||
type JoinTuple = LocalUserViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
local_user: a.0,
|
||||
person: a.1,
|
||||
counts: a.2,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,12 +23,12 @@ use lemmy_db_schema::{
|
|||
post_report,
|
||||
},
|
||||
source::{
|
||||
community::{Community, CommunityPersonBan, CommunitySafe},
|
||||
person::{Person, PersonSafe},
|
||||
community::{Community, CommunityPersonBan},
|
||||
person::Person,
|
||||
post::Post,
|
||||
post_report::PostReport,
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
use typed_builder::TypedBuilder;
|
||||
|
@ -36,13 +36,13 @@ use typed_builder::TypedBuilder;
|
|||
type PostReportViewTuple = (
|
||||
PostReport,
|
||||
Post,
|
||||
CommunitySafe,
|
||||
PersonSafe,
|
||||
PersonSafe,
|
||||
Community,
|
||||
Person,
|
||||
Person,
|
||||
Option<CommunityPersonBan>,
|
||||
Option<i16>,
|
||||
PostAggregates,
|
||||
Option<PersonSafe>,
|
||||
Option<Person>,
|
||||
);
|
||||
|
||||
impl PostReportView {
|
||||
|
@ -99,13 +99,13 @@ impl PostReportView {
|
|||
.select((
|
||||
post_report::all_columns,
|
||||
post::all_columns,
|
||||
Community::safe_columns_tuple(),
|
||||
Person::safe_columns_tuple(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
community::all_columns,
|
||||
person::all_columns,
|
||||
person_alias_1.fields(person::all_columns),
|
||||
community_person_ban::all_columns.nullable(),
|
||||
post_like::score.nullable(),
|
||||
post_aggregates::all_columns,
|
||||
person_alias_2.fields(Person::safe_columns_tuple().nullable()),
|
||||
person_alias_2.fields(person::all_columns.nullable()),
|
||||
))
|
||||
.first::<PostReportViewTuple>(conn)
|
||||
.await?;
|
||||
|
@ -216,15 +216,13 @@ impl<'a> PostReportQuery<'a> {
|
|||
.select((
|
||||
post_report::all_columns,
|
||||
post::all_columns,
|
||||
Community::safe_columns_tuple(),
|
||||
Person::safe_columns_tuple(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
community::all_columns,
|
||||
person::all_columns,
|
||||
person_alias_1.fields(person::all_columns),
|
||||
community_person_ban::all_columns.nullable(),
|
||||
post_like::score.nullable(),
|
||||
post_aggregates::all_columns,
|
||||
person_alias_2
|
||||
.fields(Person::safe_columns_tuple())
|
||||
.nullable(),
|
||||
person_alias_2.fields(person::all_columns.nullable()),
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -259,16 +257,14 @@ impl<'a> PostReportQuery<'a> {
|
|||
query.load::<PostReportViewTuple>(conn).await?
|
||||
};
|
||||
|
||||
Ok(PostReportView::from_tuple_to_vec(res))
|
||||
Ok(res.into_iter().map(PostReportView::from_tuple).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for PostReportView {
|
||||
type DbTuple = PostReportViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for PostReportView {
|
||||
type JoinTuple = PostReportViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
post_report: a.0,
|
||||
post: a.1,
|
||||
community: a.2,
|
||||
|
@ -278,8 +274,7 @@ impl ViewToVec for PostReportView {
|
|||
my_vote: a.6,
|
||||
counts: a.7,
|
||||
resolver: a.8,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -289,15 +284,9 @@ mod tests {
|
|||
use lemmy_db_schema::{
|
||||
aggregates::structs::PostAggregates,
|
||||
source::{
|
||||
community::{
|
||||
Community,
|
||||
CommunityInsertForm,
|
||||
CommunityModerator,
|
||||
CommunityModeratorForm,
|
||||
CommunitySafe,
|
||||
},
|
||||
community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm},
|
||||
instance::Instance,
|
||||
person::{Person, PersonInsertForm, PersonSafe},
|
||||
person::{Person, PersonInsertForm},
|
||||
post::{Post, PostInsertForm},
|
||||
post_report::{PostReport, PostReportForm},
|
||||
},
|
||||
|
@ -402,7 +391,7 @@ mod tests {
|
|||
let expected_jessica_report_view = PostReportView {
|
||||
post_report: inserted_jessica_report.clone(),
|
||||
post: inserted_post.clone(),
|
||||
community: CommunitySafe {
|
||||
community: Community {
|
||||
id: inserted_community.id,
|
||||
name: inserted_community.name,
|
||||
icon: None,
|
||||
|
@ -419,8 +408,16 @@ mod tests {
|
|||
posting_restricted_to_mods: false,
|
||||
published: inserted_community.published,
|
||||
instance_id: inserted_instance.id,
|
||||
private_key: inserted_community.private_key.clone(),
|
||||
public_key: inserted_community.public_key.clone(),
|
||||
last_refreshed_at: inserted_community.last_refreshed_at,
|
||||
followers_url: inserted_community.followers_url.clone(),
|
||||
inbox_url: inserted_community.inbox_url.clone(),
|
||||
shared_inbox_url: inserted_community.shared_inbox_url.clone(),
|
||||
moderators_url: inserted_community.moderators_url.clone(),
|
||||
featured_url: inserted_community.featured_url.clone(),
|
||||
},
|
||||
creator: PersonSafe {
|
||||
creator: Person {
|
||||
id: inserted_jessica.id,
|
||||
name: inserted_jessica.name,
|
||||
display_name: None,
|
||||
|
@ -440,8 +437,11 @@ mod tests {
|
|||
matrix_user_id: None,
|
||||
ban_expires: None,
|
||||
instance_id: inserted_instance.id,
|
||||
private_key: inserted_jessica.private_key,
|
||||
public_key: inserted_jessica.public_key,
|
||||
last_refreshed_at: inserted_jessica.last_refreshed_at,
|
||||
},
|
||||
post_creator: PersonSafe {
|
||||
post_creator: Person {
|
||||
id: inserted_timmy.id,
|
||||
name: inserted_timmy.name.clone(),
|
||||
display_name: None,
|
||||
|
@ -461,6 +461,9 @@ mod tests {
|
|||
matrix_user_id: None,
|
||||
ban_expires: None,
|
||||
instance_id: inserted_instance.id,
|
||||
private_key: inserted_timmy.private_key.clone(),
|
||||
public_key: inserted_timmy.public_key.clone(),
|
||||
last_refreshed_at: inserted_timmy.last_refreshed_at,
|
||||
},
|
||||
creator_banned_from_community: false,
|
||||
my_vote: None,
|
||||
|
@ -485,7 +488,7 @@ mod tests {
|
|||
let mut expected_sara_report_view = expected_jessica_report_view.clone();
|
||||
expected_sara_report_view.post_report = inserted_sara_report;
|
||||
expected_sara_report_view.my_vote = None;
|
||||
expected_sara_report_view.creator = PersonSafe {
|
||||
expected_sara_report_view.creator = Person {
|
||||
id: inserted_sara.id,
|
||||
name: inserted_sara.name,
|
||||
display_name: None,
|
||||
|
@ -505,6 +508,9 @@ mod tests {
|
|||
matrix_user_id: None,
|
||||
ban_expires: None,
|
||||
instance_id: inserted_instance.id,
|
||||
private_key: inserted_sara.private_key,
|
||||
public_key: inserted_sara.public_key,
|
||||
last_refreshed_at: inserted_sara.last_refreshed_at,
|
||||
};
|
||||
|
||||
// Do a batch read of timmys reports
|
||||
|
@ -550,7 +556,7 @@ mod tests {
|
|||
expected_jessica_report_view_after_resolve
|
||||
.post_report
|
||||
.updated = read_jessica_report_view_after_resolve.post_report.updated;
|
||||
expected_jessica_report_view_after_resolve.resolver = Some(PersonSafe {
|
||||
expected_jessica_report_view_after_resolve.resolver = Some(Person {
|
||||
id: inserted_timmy.id,
|
||||
name: inserted_timmy.name.clone(),
|
||||
display_name: None,
|
||||
|
@ -570,6 +576,9 @@ mod tests {
|
|||
matrix_user_id: None,
|
||||
ban_expires: None,
|
||||
instance_id: inserted_instance.id,
|
||||
private_key: inserted_timmy.private_key.clone(),
|
||||
public_key: inserted_timmy.public_key.clone(),
|
||||
last_refreshed_at: inserted_timmy.last_refreshed_at,
|
||||
});
|
||||
|
||||
assert_eq!(
|
||||
|
|
|
@ -33,13 +33,13 @@ use lemmy_db_schema::{
|
|||
post_saved,
|
||||
},
|
||||
source::{
|
||||
community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe},
|
||||
community::{Community, CommunityFollower, CommunityPersonBan},
|
||||
local_user::LocalUser,
|
||||
person::{Person, PersonSafe},
|
||||
person::Person,
|
||||
person_block::PersonBlock,
|
||||
post::{Post, PostRead, PostSaved},
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
traits::JoinView,
|
||||
utils::{functions::hot_rank, fuzzy_search, get_conn, limit_and_offset, DbPool},
|
||||
ListingType,
|
||||
SortType,
|
||||
|
@ -49,8 +49,8 @@ use typed_builder::TypedBuilder;
|
|||
|
||||
type PostViewTuple = (
|
||||
Post,
|
||||
PersonSafe,
|
||||
CommunitySafe,
|
||||
Person,
|
||||
Community,
|
||||
Option<CommunityPersonBan>,
|
||||
PostAggregates,
|
||||
Option<CommunityFollower>,
|
||||
|
@ -144,8 +144,8 @@ impl PostView {
|
|||
)
|
||||
.select((
|
||||
post::all_columns,
|
||||
Person::safe_columns_tuple(),
|
||||
Community::safe_columns_tuple(),
|
||||
person::all_columns,
|
||||
community::all_columns,
|
||||
community_person_ban::all_columns.nullable(),
|
||||
post_aggregates::all_columns,
|
||||
community_follower::all_columns.nullable(),
|
||||
|
@ -326,8 +326,8 @@ impl<'a> PostQuery<'a> {
|
|||
)
|
||||
.select((
|
||||
post::all_columns,
|
||||
Person::safe_columns_tuple(),
|
||||
Community::safe_columns_tuple(),
|
||||
person::all_columns,
|
||||
community::all_columns,
|
||||
community_person_ban::all_columns.nullable(),
|
||||
post_aggregates::all_columns,
|
||||
community_follower::all_columns.nullable(),
|
||||
|
@ -485,16 +485,14 @@ impl<'a> PostQuery<'a> {
|
|||
|
||||
let res = query.load::<PostViewTuple>(conn).await?;
|
||||
|
||||
Ok(PostView::from_tuple_to_vec(res))
|
||||
Ok(res.into_iter().map(PostView::from_tuple).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for PostView {
|
||||
type DbTuple = PostViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for PostView {
|
||||
type JoinTuple = PostViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
post: a.0,
|
||||
creator: a.1,
|
||||
community: a.2,
|
||||
|
@ -506,8 +504,7 @@ impl ViewToVec for PostView {
|
|||
creator_blocked: a.8.is_some(),
|
||||
my_vote: a.9,
|
||||
unread_comments: a.10,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -520,12 +517,12 @@ mod tests {
|
|||
newtypes::LanguageId,
|
||||
source::{
|
||||
actor_language::LocalUserLanguage,
|
||||
community::{Community, CommunityInsertForm, CommunitySafe},
|
||||
community::{Community, CommunityInsertForm},
|
||||
community_block::{CommunityBlock, CommunityBlockForm},
|
||||
instance::Instance,
|
||||
language::Language,
|
||||
local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
|
||||
person::{Person, PersonInsertForm, PersonSafe},
|
||||
person::{Person, PersonInsertForm},
|
||||
person_block::{PersonBlock, PersonBlockForm},
|
||||
post::{Post, PostInsertForm, PostLike, PostLikeForm},
|
||||
},
|
||||
|
@ -934,7 +931,7 @@ mod tests {
|
|||
},
|
||||
my_vote: None,
|
||||
unread_comments: 0,
|
||||
creator: PersonSafe {
|
||||
creator: Person {
|
||||
id: inserted_person.id,
|
||||
name: inserted_person.name.clone(),
|
||||
display_name: None,
|
||||
|
@ -954,9 +951,12 @@ mod tests {
|
|||
matrix_user_id: None,
|
||||
ban_expires: None,
|
||||
instance_id: data.inserted_instance.id,
|
||||
private_key: inserted_person.private_key.clone(),
|
||||
public_key: inserted_person.public_key.clone(),
|
||||
last_refreshed_at: inserted_person.last_refreshed_at,
|
||||
},
|
||||
creator_banned_from_community: false,
|
||||
community: CommunitySafe {
|
||||
community: Community {
|
||||
id: inserted_community.id,
|
||||
name: inserted_community.name.clone(),
|
||||
icon: None,
|
||||
|
@ -973,6 +973,14 @@ mod tests {
|
|||
posting_restricted_to_mods: false,
|
||||
published: inserted_community.published,
|
||||
instance_id: data.inserted_instance.id,
|
||||
private_key: inserted_community.private_key.clone(),
|
||||
public_key: inserted_community.public_key.clone(),
|
||||
last_refreshed_at: inserted_community.last_refreshed_at,
|
||||
followers_url: inserted_community.followers_url.clone(),
|
||||
inbox_url: inserted_community.inbox_url.clone(),
|
||||
shared_inbox_url: inserted_community.shared_inbox_url.clone(),
|
||||
moderators_url: inserted_community.moderators_url.clone(),
|
||||
featured_url: inserted_community.featured_url.clone(),
|
||||
},
|
||||
counts: PostAggregates {
|
||||
id: agg.id,
|
||||
|
|
|
@ -5,11 +5,11 @@ use lemmy_db_schema::{
|
|||
newtypes::PrivateMessageReportId,
|
||||
schema::{person, private_message, private_message_report},
|
||||
source::{
|
||||
person::{Person, PersonSafe},
|
||||
person::Person,
|
||||
private_message::PrivateMessage,
|
||||
private_message_report::PrivateMessageReport,
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
use typed_builder::TypedBuilder;
|
||||
|
@ -17,9 +17,9 @@ use typed_builder::TypedBuilder;
|
|||
type PrivateMessageReportViewTuple = (
|
||||
PrivateMessageReport,
|
||||
PrivateMessage,
|
||||
PersonSafe,
|
||||
PersonSafe,
|
||||
Option<PersonSafe>,
|
||||
Person,
|
||||
Person,
|
||||
Option<Person>,
|
||||
);
|
||||
|
||||
impl PrivateMessageReportView {
|
||||
|
@ -47,11 +47,9 @@ impl PrivateMessageReportView {
|
|||
.select((
|
||||
private_message_report::all_columns,
|
||||
private_message::all_columns,
|
||||
Person::safe_columns_tuple(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
person_alias_2
|
||||
.fields(Person::safe_columns_tuple())
|
||||
.nullable(),
|
||||
person::all_columns,
|
||||
person_alias_1.fields(person::all_columns),
|
||||
person_alias_2.fields(person::all_columns).nullable(),
|
||||
))
|
||||
.first::<PrivateMessageReportViewTuple>(conn)
|
||||
.await?;
|
||||
|
@ -108,11 +106,9 @@ impl<'a> PrivateMessageReportQuery<'a> {
|
|||
.select((
|
||||
private_message_report::all_columns,
|
||||
private_message::all_columns,
|
||||
Person::safe_columns_tuple(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
person_alias_2
|
||||
.fields(Person::safe_columns_tuple())
|
||||
.nullable(),
|
||||
person::all_columns,
|
||||
person_alias_1.fields(person::all_columns),
|
||||
person_alias_2.fields(person::all_columns).nullable(),
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -129,23 +125,25 @@ impl<'a> PrivateMessageReportQuery<'a> {
|
|||
|
||||
let res = query.load::<PrivateMessageReportViewTuple>(conn).await?;
|
||||
|
||||
Ok(PrivateMessageReportView::from_tuple_to_vec(res))
|
||||
Ok(
|
||||
res
|
||||
.into_iter()
|
||||
.map(PrivateMessageReportView::from_tuple)
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for PrivateMessageReportView {
|
||||
type DbTuple = PrivateMessageReportViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for PrivateMessageReportView {
|
||||
type JoinTuple = PrivateMessageReportViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
private_message_report: a.0,
|
||||
private_message: a.1,
|
||||
private_message_creator: a.2,
|
||||
creator: a.3,
|
||||
resolver: a.4,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,17 +12,14 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::{PersonId, PrivateMessageId},
|
||||
schema::{person, private_message},
|
||||
source::{
|
||||
person::{Person, PersonSafe},
|
||||
private_message::PrivateMessage,
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{person::Person, private_message::PrivateMessage},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
use tracing::debug;
|
||||
use typed_builder::TypedBuilder;
|
||||
|
||||
type PrivateMessageViewTuple = (PrivateMessage, PersonSafe, PersonSafe);
|
||||
type PrivateMessageViewTuple = (PrivateMessage, Person, Person);
|
||||
|
||||
impl PrivateMessageView {
|
||||
pub async fn read(pool: &DbPool, private_message_id: PrivateMessageId) -> Result<Self, Error> {
|
||||
|
@ -38,8 +35,8 @@ impl PrivateMessageView {
|
|||
.order_by(private_message::published.desc())
|
||||
.select((
|
||||
private_message::all_columns,
|
||||
Person::safe_columns_tuple(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
person::all_columns,
|
||||
person_alias_1.fields(person::all_columns),
|
||||
))
|
||||
.first::<PrivateMessageViewTuple>(conn)
|
||||
.await?;
|
||||
|
@ -89,8 +86,8 @@ impl<'a> PrivateMessageQuery<'a> {
|
|||
)
|
||||
.select((
|
||||
private_message::all_columns,
|
||||
Person::safe_columns_tuple(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
person::all_columns,
|
||||
person_alias_1.fields(person::all_columns),
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -124,20 +121,22 @@ impl<'a> PrivateMessageQuery<'a> {
|
|||
|
||||
let res = query.load::<PrivateMessageViewTuple>(conn).await?;
|
||||
|
||||
Ok(PrivateMessageView::from_tuple_to_vec(res))
|
||||
Ok(
|
||||
res
|
||||
.into_iter()
|
||||
.map(PrivateMessageView::from_tuple)
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for PrivateMessageView {
|
||||
type DbTuple = PrivateMessageViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for PrivateMessageView {
|
||||
type JoinTuple = PrivateMessageViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
private_message: a.0,
|
||||
creator: a.1,
|
||||
recipient: a.2,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,21 +11,17 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
schema::{local_user, person, registration_application},
|
||||
source::{
|
||||
local_user::{LocalUser, LocalUserSettings},
|
||||
person::{Person, PersonSafe},
|
||||
local_user::LocalUser,
|
||||
person::Person,
|
||||
registration_application::RegistrationApplication,
|
||||
},
|
||||
traits::{ToSafe, ToSafeSettings, ViewToVec},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
use typed_builder::TypedBuilder;
|
||||
|
||||
type RegistrationApplicationViewTuple = (
|
||||
RegistrationApplication,
|
||||
LocalUserSettings,
|
||||
PersonSafe,
|
||||
Option<PersonSafe>,
|
||||
);
|
||||
type RegistrationApplicationViewTuple =
|
||||
(RegistrationApplication, LocalUser, Person, Option<Person>);
|
||||
|
||||
impl RegistrationApplicationView {
|
||||
pub async fn read(pool: &DbPool, registration_application_id: i32) -> Result<Self, Error> {
|
||||
|
@ -46,11 +42,9 @@ impl RegistrationApplicationView {
|
|||
.order_by(registration_application::published.desc())
|
||||
.select((
|
||||
registration_application::all_columns,
|
||||
LocalUser::safe_settings_columns_tuple(),
|
||||
Person::safe_columns_tuple(),
|
||||
person_alias_1
|
||||
.fields(Person::safe_columns_tuple())
|
||||
.nullable(),
|
||||
local_user::all_columns,
|
||||
person::all_columns,
|
||||
person_alias_1.fields(person::all_columns).nullable(),
|
||||
))
|
||||
.first::<RegistrationApplicationViewTuple>(conn)
|
||||
.await?;
|
||||
|
@ -115,11 +109,9 @@ impl<'a> RegistrationApplicationQuery<'a> {
|
|||
.order_by(registration_application::published.desc())
|
||||
.select((
|
||||
registration_application::all_columns,
|
||||
LocalUser::safe_settings_columns_tuple(),
|
||||
Person::safe_columns_tuple(),
|
||||
person_alias_1
|
||||
.fields(Person::safe_columns_tuple())
|
||||
.nullable(),
|
||||
local_user::all_columns,
|
||||
person::all_columns,
|
||||
person_alias_1.fields(person::all_columns).nullable(),
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -140,22 +132,24 @@ impl<'a> RegistrationApplicationQuery<'a> {
|
|||
|
||||
let res = query.load::<RegistrationApplicationViewTuple>(conn).await?;
|
||||
|
||||
Ok(RegistrationApplicationView::from_tuple_to_vec(res))
|
||||
Ok(
|
||||
res
|
||||
.into_iter()
|
||||
.map(RegistrationApplicationView::from_tuple)
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for RegistrationApplicationView {
|
||||
type DbTuple = RegistrationApplicationViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for RegistrationApplicationView {
|
||||
type JoinTuple = RegistrationApplicationViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
registration_application: a.0,
|
||||
creator_local_user: a.1,
|
||||
creator: a.2,
|
||||
admin: a.3,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -168,8 +162,8 @@ mod tests {
|
|||
use lemmy_db_schema::{
|
||||
source::{
|
||||
instance::Instance,
|
||||
local_user::{LocalUser, LocalUserInsertForm, LocalUserSettings, LocalUserUpdateForm},
|
||||
person::{Person, PersonInsertForm, PersonSafe},
|
||||
local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
|
||||
person::{Person, PersonInsertForm},
|
||||
registration_application::{
|
||||
RegistrationApplication,
|
||||
RegistrationApplicationInsertForm,
|
||||
|
@ -272,7 +266,7 @@ mod tests {
|
|||
|
||||
let mut expected_sara_app_view = RegistrationApplicationView {
|
||||
registration_application: sara_app.clone(),
|
||||
creator_local_user: LocalUserSettings {
|
||||
creator_local_user: LocalUser {
|
||||
id: inserted_sara_local_user.id,
|
||||
person_id: inserted_sara_local_user.person_id,
|
||||
email: inserted_sara_local_user.email,
|
||||
|
@ -290,8 +284,9 @@ mod tests {
|
|||
show_new_post_notifs: inserted_sara_local_user.show_new_post_notifs,
|
||||
email_verified: inserted_sara_local_user.email_verified,
|
||||
accepted_application: inserted_sara_local_user.accepted_application,
|
||||
password_encrypted: inserted_sara_local_user.password_encrypted,
|
||||
},
|
||||
creator: PersonSafe {
|
||||
creator: Person {
|
||||
id: inserted_sara_person.id,
|
||||
name: inserted_sara_person.name.clone(),
|
||||
display_name: None,
|
||||
|
@ -311,6 +306,9 @@ mod tests {
|
|||
shared_inbox_url: None,
|
||||
matrix_user_id: None,
|
||||
instance_id: inserted_instance.id,
|
||||
private_key: inserted_sara_person.private_key,
|
||||
public_key: inserted_sara_person.public_key,
|
||||
last_refreshed_at: inserted_sara_person.last_refreshed_at,
|
||||
},
|
||||
admin: None,
|
||||
};
|
||||
|
@ -366,7 +364,7 @@ mod tests {
|
|||
.accepted_application = true;
|
||||
expected_sara_app_view.registration_application.admin_id = Some(inserted_timmy_person.id);
|
||||
|
||||
expected_sara_app_view.admin = Some(PersonSafe {
|
||||
expected_sara_app_view.admin = Some(Person {
|
||||
id: inserted_timmy_person.id,
|
||||
name: inserted_timmy_person.name.clone(),
|
||||
display_name: None,
|
||||
|
@ -386,6 +384,9 @@ mod tests {
|
|||
shared_inbox_url: None,
|
||||
matrix_user_id: None,
|
||||
instance_id: inserted_instance.id,
|
||||
private_key: inserted_timmy_person.private_key,
|
||||
public_key: inserted_timmy_person.public_key,
|
||||
last_refreshed_at: inserted_timmy_person.last_refreshed_at,
|
||||
});
|
||||
assert_eq!(read_sara_app_view_after_approve, expected_sara_app_view);
|
||||
|
||||
|
|
|
@ -3,11 +3,11 @@ use lemmy_db_schema::{
|
|||
source::{
|
||||
comment::Comment,
|
||||
comment_report::CommentReport,
|
||||
community::CommunitySafe,
|
||||
community::Community,
|
||||
local_site::LocalSite,
|
||||
local_site_rate_limit::LocalSiteRateLimit,
|
||||
local_user::{LocalUser, LocalUserSettings},
|
||||
person::{Person, PersonSafe},
|
||||
local_user::LocalUser,
|
||||
person::Person,
|
||||
post::Post,
|
||||
post_report::PostReport,
|
||||
private_message::PrivateMessage,
|
||||
|
@ -24,21 +24,21 @@ pub struct CommentReportView {
|
|||
pub comment_report: CommentReport,
|
||||
pub comment: Comment,
|
||||
pub post: Post,
|
||||
pub community: CommunitySafe,
|
||||
pub creator: PersonSafe,
|
||||
pub comment_creator: PersonSafe,
|
||||
pub community: Community,
|
||||
pub creator: Person,
|
||||
pub comment_creator: Person,
|
||||
pub counts: CommentAggregates,
|
||||
pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan
|
||||
pub my_vote: Option<i16>, // Left join to CommentLike
|
||||
pub resolver: Option<PersonSafe>,
|
||||
pub resolver: Option<Person>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
||||
pub struct CommentView {
|
||||
pub comment: Comment,
|
||||
pub creator: PersonSafe,
|
||||
pub creator: Person,
|
||||
pub post: Post,
|
||||
pub community: CommunitySafe,
|
||||
pub community: Community,
|
||||
pub counts: CommentAggregates,
|
||||
pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan
|
||||
pub subscribed: SubscribedType, // Left join to CommunityFollower
|
||||
|
@ -54,31 +54,24 @@ pub struct LocalUserView {
|
|||
pub counts: PersonAggregates,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct LocalUserSettingsView {
|
||||
pub local_user: LocalUserSettings,
|
||||
pub person: PersonSafe,
|
||||
pub counts: PersonAggregates,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
||||
pub struct PostReportView {
|
||||
pub post_report: PostReport,
|
||||
pub post: Post,
|
||||
pub community: CommunitySafe,
|
||||
pub creator: PersonSafe,
|
||||
pub post_creator: PersonSafe,
|
||||
pub community: Community,
|
||||
pub creator: Person,
|
||||
pub post_creator: Person,
|
||||
pub creator_banned_from_community: bool,
|
||||
pub my_vote: Option<i16>,
|
||||
pub counts: PostAggregates,
|
||||
pub resolver: Option<PersonSafe>,
|
||||
pub resolver: Option<Person>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
||||
pub struct PostView {
|
||||
pub post: Post,
|
||||
pub creator: PersonSafe,
|
||||
pub community: CommunitySafe,
|
||||
pub creator: Person,
|
||||
pub community: Community,
|
||||
pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan
|
||||
pub counts: PostAggregates,
|
||||
pub subscribed: SubscribedType, // Left join to CommunityFollower
|
||||
|
@ -92,25 +85,25 @@ pub struct PostView {
|
|||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
||||
pub struct PrivateMessageView {
|
||||
pub private_message: PrivateMessage,
|
||||
pub creator: PersonSafe,
|
||||
pub recipient: PersonSafe,
|
||||
pub creator: Person,
|
||||
pub recipient: Person,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
||||
pub struct PrivateMessageReportView {
|
||||
pub private_message_report: PrivateMessageReport,
|
||||
pub private_message: PrivateMessage,
|
||||
pub private_message_creator: PersonSafe,
|
||||
pub creator: PersonSafe,
|
||||
pub resolver: Option<PersonSafe>,
|
||||
pub private_message_creator: Person,
|
||||
pub creator: Person,
|
||||
pub resolver: Option<Person>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
||||
pub struct RegistrationApplicationView {
|
||||
pub registration_application: RegistrationApplication,
|
||||
pub creator_local_user: LocalUserSettings,
|
||||
pub creator: PersonSafe,
|
||||
pub admin: Option<PersonSafe>,
|
||||
pub creator_local_user: LocalUser,
|
||||
pub creator: Person,
|
||||
pub admin: Option<Person>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
|
|
|
@ -28,12 +28,12 @@ use lemmy_db_schema::{
|
|||
source::{
|
||||
comment::{Comment, CommentSaved},
|
||||
comment_reply::CommentReply,
|
||||
community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe},
|
||||
person::{Person, PersonSafe},
|
||||
community::{Community, CommunityFollower, CommunityPersonBan},
|
||||
person::Person,
|
||||
person_block::PersonBlock,
|
||||
post::Post,
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
traits::JoinView,
|
||||
utils::{functions::hot_rank, get_conn, limit_and_offset, DbPool},
|
||||
CommentSortType,
|
||||
};
|
||||
|
@ -42,10 +42,10 @@ use typed_builder::TypedBuilder;
|
|||
type CommentReplyViewTuple = (
|
||||
CommentReply,
|
||||
Comment,
|
||||
PersonSafe,
|
||||
Person,
|
||||
Post,
|
||||
CommunitySafe,
|
||||
PersonSafe,
|
||||
Community,
|
||||
Person,
|
||||
CommentAggregates,
|
||||
Option<CommunityPersonBan>,
|
||||
Option<CommunityFollower>,
|
||||
|
@ -130,10 +130,10 @@ impl CommentReplyView {
|
|||
.select((
|
||||
comment_reply::all_columns,
|
||||
comment::all_columns,
|
||||
Person::safe_columns_tuple(),
|
||||
person::all_columns,
|
||||
post::all_columns,
|
||||
Community::safe_columns_tuple(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
community::all_columns,
|
||||
person_alias_1.fields(person::all_columns),
|
||||
comment_aggregates::all_columns,
|
||||
community_person_ban::all_columns.nullable(),
|
||||
community_follower::all_columns.nullable(),
|
||||
|
@ -251,10 +251,10 @@ impl<'a> CommentReplyQuery<'a> {
|
|||
.select((
|
||||
comment_reply::all_columns,
|
||||
comment::all_columns,
|
||||
Person::safe_columns_tuple(),
|
||||
person::all_columns,
|
||||
post::all_columns,
|
||||
Community::safe_columns_tuple(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
community::all_columns,
|
||||
person_alias_1.fields(person::all_columns),
|
||||
comment_aggregates::all_columns,
|
||||
community_person_ban::all_columns.nullable(),
|
||||
community_follower::all_columns.nullable(),
|
||||
|
@ -293,16 +293,14 @@ impl<'a> CommentReplyQuery<'a> {
|
|||
.load::<CommentReplyViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
Ok(CommentReplyView::from_tuple_to_vec(res))
|
||||
Ok(res.into_iter().map(CommentReplyView::from_tuple).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for CommentReplyView {
|
||||
type DbTuple = CommentReplyViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for CommentReplyView {
|
||||
type JoinTuple = CommentReplyViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
comment_reply: a.0,
|
||||
comment: a.1,
|
||||
creator: a.2,
|
||||
|
@ -315,7 +313,6 @@ impl ViewToVec for CommentReplyView {
|
|||
saved: a.9.is_some(),
|
||||
creator_blocked: a.10.is_some(),
|
||||
my_vote: a.11,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,15 +4,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{community, community_block, person},
|
||||
source::{
|
||||
community::{Community, CommunitySafe},
|
||||
person::{Person, PersonSafe},
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{community::Community, person::Person},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
|
||||
type CommunityBlockViewTuple = (PersonSafe, CommunitySafe);
|
||||
type CommunityBlockViewTuple = (Person, Community);
|
||||
|
||||
impl CommunityBlockView {
|
||||
pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
||||
|
@ -20,10 +17,7 @@ impl CommunityBlockView {
|
|||
let res = community_block::table
|
||||
.inner_join(person::table)
|
||||
.inner_join(community::table)
|
||||
.select((
|
||||
Person::safe_columns_tuple(),
|
||||
Community::safe_columns_tuple(),
|
||||
))
|
||||
.select((person::all_columns, community::all_columns))
|
||||
.filter(community_block::person_id.eq(person_id))
|
||||
.filter(community::deleted.eq(false))
|
||||
.filter(community::removed.eq(false))
|
||||
|
@ -31,19 +25,16 @@ impl CommunityBlockView {
|
|||
.load::<CommunityBlockViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
Ok(res.into_iter().map(Self::from_tuple).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for CommunityBlockView {
|
||||
type DbTuple = CommunityBlockViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for CommunityBlockView {
|
||||
type JoinTuple = CommunityBlockViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
person: a.0,
|
||||
community: a.1,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,15 +4,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::{CommunityId, PersonId},
|
||||
schema::{community, community_follower, person},
|
||||
source::{
|
||||
community::{Community, CommunitySafe},
|
||||
person::{Person, PersonSafe},
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{community::Community, person::Person},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
|
||||
type CommunityFollowerViewTuple = (CommunitySafe, PersonSafe);
|
||||
type CommunityFollowerViewTuple = (Community, Person);
|
||||
|
||||
impl CommunityFollowerView {
|
||||
pub async fn for_community(pool: &DbPool, community_id: CommunityId) -> Result<Vec<Self>, Error> {
|
||||
|
@ -20,16 +17,13 @@ impl CommunityFollowerView {
|
|||
let res = community_follower::table
|
||||
.inner_join(community::table)
|
||||
.inner_join(person::table)
|
||||
.select((
|
||||
Community::safe_columns_tuple(),
|
||||
Person::safe_columns_tuple(),
|
||||
))
|
||||
.select((community::all_columns, person::all_columns))
|
||||
.filter(community_follower::community_id.eq(community_id))
|
||||
.order_by(community::title)
|
||||
.load::<CommunityFollowerViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
Ok(res.into_iter().map(Self::from_tuple).collect())
|
||||
}
|
||||
|
||||
pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
||||
|
@ -37,10 +31,7 @@ impl CommunityFollowerView {
|
|||
let res = community_follower::table
|
||||
.inner_join(community::table)
|
||||
.inner_join(person::table)
|
||||
.select((
|
||||
Community::safe_columns_tuple(),
|
||||
Person::safe_columns_tuple(),
|
||||
))
|
||||
.select((community::all_columns, person::all_columns))
|
||||
.filter(community_follower::person_id.eq(person_id))
|
||||
.filter(community::deleted.eq(false))
|
||||
.filter(community::removed.eq(false))
|
||||
|
@ -48,19 +39,16 @@ impl CommunityFollowerView {
|
|||
.load::<CommunityFollowerViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
Ok(res.into_iter().map(Self::from_tuple).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for CommunityFollowerView {
|
||||
type DbTuple = CommunityFollowerViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for CommunityFollowerView {
|
||||
type JoinTuple = CommunityFollowerViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
community: a.0,
|
||||
follower: a.1,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,15 +4,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::{CommunityId, PersonId},
|
||||
schema::{community, community_moderator, person},
|
||||
source::{
|
||||
community::{Community, CommunitySafe},
|
||||
person::{Person, PersonSafe},
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{community::Community, person::Person},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
|
||||
type CommunityModeratorViewTuple = (CommunitySafe, PersonSafe);
|
||||
type CommunityModeratorViewTuple = (Community, Person);
|
||||
|
||||
impl CommunityModeratorView {
|
||||
pub async fn for_community(pool: &DbPool, community_id: CommunityId) -> Result<Vec<Self>, Error> {
|
||||
|
@ -20,16 +17,13 @@ impl CommunityModeratorView {
|
|||
let res = community_moderator::table
|
||||
.inner_join(community::table)
|
||||
.inner_join(person::table)
|
||||
.select((
|
||||
Community::safe_columns_tuple(),
|
||||
Person::safe_columns_tuple(),
|
||||
))
|
||||
.select((community::all_columns, person::all_columns))
|
||||
.filter(community_moderator::community_id.eq(community_id))
|
||||
.order_by(community_moderator::published)
|
||||
.load::<CommunityModeratorViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
Ok(res.into_iter().map(Self::from_tuple).collect())
|
||||
}
|
||||
|
||||
pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
||||
|
@ -37,10 +31,7 @@ impl CommunityModeratorView {
|
|||
let res = community_moderator::table
|
||||
.inner_join(community::table)
|
||||
.inner_join(person::table)
|
||||
.select((
|
||||
Community::safe_columns_tuple(),
|
||||
Person::safe_columns_tuple(),
|
||||
))
|
||||
.select((community::all_columns, person::all_columns))
|
||||
.filter(community_moderator::person_id.eq(person_id))
|
||||
.filter(community::deleted.eq(false))
|
||||
.filter(community::removed.eq(false))
|
||||
|
@ -48,7 +39,7 @@ impl CommunityModeratorView {
|
|||
.load::<CommunityModeratorViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
Ok(res.into_iter().map(Self::from_tuple).collect())
|
||||
}
|
||||
|
||||
/// Finds all communities first mods / creators
|
||||
|
@ -58,10 +49,7 @@ impl CommunityModeratorView {
|
|||
let res = community_moderator::table
|
||||
.inner_join(community::table)
|
||||
.inner_join(person::table)
|
||||
.select((
|
||||
Community::safe_columns_tuple(),
|
||||
Person::safe_columns_tuple(),
|
||||
))
|
||||
.select((community::all_columns, person::all_columns))
|
||||
// A hacky workaround instead of group_bys
|
||||
// https://stackoverflow.com/questions/24042359/how-to-join-only-one-row-in-joined-table-with-postgres
|
||||
.distinct_on(community_moderator::community_id)
|
||||
|
@ -72,19 +60,16 @@ impl CommunityModeratorView {
|
|||
.load::<CommunityModeratorViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
Ok(res.into_iter().map(Self::from_tuple).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for CommunityModeratorView {
|
||||
type DbTuple = CommunityModeratorViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for CommunityModeratorView {
|
||||
type JoinTuple = CommunityModeratorViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
community: a.0,
|
||||
moderator: a.1,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,11 +4,7 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::{CommunityId, PersonId},
|
||||
schema::{community, community_person_ban, person},
|
||||
source::{
|
||||
community::{Community, CommunitySafe},
|
||||
person::{Person, PersonSafe},
|
||||
},
|
||||
traits::ToSafe,
|
||||
source::{community::Community, person::Person},
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
|
||||
|
@ -22,10 +18,7 @@ impl CommunityPersonBanView {
|
|||
let (community, person) = community_person_ban::table
|
||||
.inner_join(community::table)
|
||||
.inner_join(person::table)
|
||||
.select((
|
||||
Community::safe_columns_tuple(),
|
||||
Person::safe_columns_tuple(),
|
||||
))
|
||||
.select((community::all_columns, person::all_columns))
|
||||
.filter(community_person_ban::community_id.eq(from_community_id))
|
||||
.filter(community_person_ban::person_id.eq(from_person_id))
|
||||
.filter(
|
||||
|
@ -34,7 +27,7 @@ impl CommunityPersonBanView {
|
|||
.or(community_person_ban::expires.gt(now)),
|
||||
)
|
||||
.order_by(community_person_ban::published)
|
||||
.first::<(CommunitySafe, PersonSafe)>(conn)
|
||||
.first::<(Community, Person)>(conn)
|
||||
.await?;
|
||||
|
||||
Ok(CommunityPersonBanView { community, person })
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::structs::{CommunityModeratorView, CommunityView, PersonViewSafe};
|
||||
use crate::structs::{CommunityModeratorView, CommunityView, PersonView};
|
||||
use diesel::{
|
||||
result::Error,
|
||||
BoolExpressionMethods,
|
||||
|
@ -14,11 +14,11 @@ use lemmy_db_schema::{
|
|||
newtypes::{CommunityId, PersonId},
|
||||
schema::{community, community_aggregates, community_block, community_follower, local_user},
|
||||
source::{
|
||||
community::{Community, CommunityFollower, CommunitySafe},
|
||||
community::{Community, CommunityFollower},
|
||||
community_block::CommunityBlock,
|
||||
local_user::LocalUser,
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
traits::JoinView,
|
||||
utils::{fuzzy_search, get_conn, limit_and_offset, DbPool},
|
||||
ListingType,
|
||||
SortType,
|
||||
|
@ -26,7 +26,7 @@ use lemmy_db_schema::{
|
|||
use typed_builder::TypedBuilder;
|
||||
|
||||
type CommunityViewTuple = (
|
||||
CommunitySafe,
|
||||
Community,
|
||||
CommunityAggregates,
|
||||
Option<CommunityFollower>,
|
||||
Option<CommunityBlock>,
|
||||
|
@ -61,7 +61,7 @@ impl CommunityView {
|
|||
),
|
||||
)
|
||||
.select((
|
||||
Community::safe_columns_tuple(),
|
||||
community::all_columns,
|
||||
community_aggregates::all_columns,
|
||||
community_follower::all_columns.nullable(),
|
||||
community_block::all_columns.nullable(),
|
||||
|
@ -103,7 +103,7 @@ impl CommunityView {
|
|||
return Ok(true);
|
||||
}
|
||||
|
||||
let is_admin = PersonViewSafe::admins(pool)
|
||||
let is_admin = PersonView::admins(pool)
|
||||
.await
|
||||
.map(|v| {
|
||||
v.into_iter()
|
||||
|
@ -155,7 +155,7 @@ impl<'a> CommunityQuery<'a> {
|
|||
),
|
||||
)
|
||||
.select((
|
||||
Community::safe_columns_tuple(),
|
||||
community::all_columns,
|
||||
community_aggregates::all_columns,
|
||||
community_follower::all_columns.nullable(),
|
||||
community_block::all_columns.nullable(),
|
||||
|
@ -221,21 +221,18 @@ impl<'a> CommunityQuery<'a> {
|
|||
.load::<CommunityViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
Ok(CommunityView::from_tuple_to_vec(res))
|
||||
Ok(res.into_iter().map(CommunityView::from_tuple).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for CommunityView {
|
||||
type DbTuple = CommunityViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for CommunityView {
|
||||
type JoinTuple = CommunityViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
community: a.0,
|
||||
counts: a.1,
|
||||
subscribed: CommunityFollower::to_subscribed_type(&a.2),
|
||||
blocked: a.3.is_some(),
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{person, person_block},
|
||||
source::person::{Person, PersonSafe},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::person::Person,
|
||||
traits::JoinView,
|
||||
utils::{get_conn, DbPool},
|
||||
};
|
||||
|
||||
type PersonBlockViewTuple = (PersonSafe, PersonSafe);
|
||||
type PersonBlockViewTuple = (Person, Person);
|
||||
|
||||
impl PersonBlockView {
|
||||
pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
||||
|
@ -22,8 +22,8 @@ impl PersonBlockView {
|
|||
target_person_alias.on(person_block::target_id.eq(target_person_alias.field(person::id))),
|
||||
)
|
||||
.select((
|
||||
Person::safe_columns_tuple(),
|
||||
target_person_alias.fields(Person::safe_columns_tuple()),
|
||||
person::all_columns,
|
||||
target_person_alias.fields(person::all_columns),
|
||||
))
|
||||
.filter(person_block::person_id.eq(person_id))
|
||||
.filter(target_person_alias.field(person::deleted).eq(false))
|
||||
|
@ -31,19 +31,16 @@ impl PersonBlockView {
|
|||
.load::<PersonBlockViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
Ok(Self::from_tuple_to_vec(res))
|
||||
Ok(res.into_iter().map(Self::from_tuple).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for PersonBlockView {
|
||||
type DbTuple = PersonBlockViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for PersonBlockView {
|
||||
type JoinTuple = PersonBlockViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
person: a.0,
|
||||
target: a.1,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,13 +27,13 @@ use lemmy_db_schema::{
|
|||
},
|
||||
source::{
|
||||
comment::{Comment, CommentSaved},
|
||||
community::{Community, CommunityFollower, CommunityPersonBan, CommunitySafe},
|
||||
person::{Person, PersonSafe},
|
||||
community::{Community, CommunityFollower, CommunityPersonBan},
|
||||
person::Person,
|
||||
person_block::PersonBlock,
|
||||
person_mention::PersonMention,
|
||||
post::Post,
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
traits::JoinView,
|
||||
utils::{functions::hot_rank, get_conn, limit_and_offset, DbPool},
|
||||
CommentSortType,
|
||||
};
|
||||
|
@ -42,10 +42,10 @@ use typed_builder::TypedBuilder;
|
|||
type PersonMentionViewTuple = (
|
||||
PersonMention,
|
||||
Comment,
|
||||
PersonSafe,
|
||||
Person,
|
||||
Post,
|
||||
CommunitySafe,
|
||||
PersonSafe,
|
||||
Community,
|
||||
Person,
|
||||
CommentAggregates,
|
||||
Option<CommunityPersonBan>,
|
||||
Option<CommunityFollower>,
|
||||
|
@ -130,10 +130,10 @@ impl PersonMentionView {
|
|||
.select((
|
||||
person_mention::all_columns,
|
||||
comment::all_columns,
|
||||
Person::safe_columns_tuple(),
|
||||
person::all_columns,
|
||||
post::all_columns,
|
||||
Community::safe_columns_tuple(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
community::all_columns,
|
||||
person_alias_1.fields(person::all_columns),
|
||||
comment_aggregates::all_columns,
|
||||
community_person_ban::all_columns.nullable(),
|
||||
community_follower::all_columns.nullable(),
|
||||
|
@ -250,10 +250,10 @@ impl<'a> PersonMentionQuery<'a> {
|
|||
.select((
|
||||
person_mention::all_columns,
|
||||
comment::all_columns,
|
||||
Person::safe_columns_tuple(),
|
||||
person::all_columns,
|
||||
post::all_columns,
|
||||
Community::safe_columns_tuple(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
community::all_columns,
|
||||
person_alias_1.fields(person::all_columns),
|
||||
comment_aggregates::all_columns,
|
||||
community_person_ban::all_columns.nullable(),
|
||||
community_follower::all_columns.nullable(),
|
||||
|
@ -292,16 +292,14 @@ impl<'a> PersonMentionQuery<'a> {
|
|||
.load::<PersonMentionViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
Ok(PersonMentionView::from_tuple_to_vec(res))
|
||||
Ok(res.into_iter().map(PersonMentionView::from_tuple).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for PersonMentionView {
|
||||
type DbTuple = PersonMentionViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for PersonMentionView {
|
||||
type JoinTuple = PersonMentionViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
person_mention: a.0,
|
||||
comment: a.1,
|
||||
creator: a.2,
|
||||
|
@ -314,7 +312,6 @@ impl ViewToVec for PersonMentionView {
|
|||
saved: a.9.is_some(),
|
||||
creator_blocked: a.10.is_some(),
|
||||
my_vote: a.11,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::structs::PersonViewSafe;
|
||||
use crate::structs::PersonView;
|
||||
use diesel::{
|
||||
dsl::{now, IntervalDsl},
|
||||
result::Error,
|
||||
|
@ -12,47 +12,47 @@ use lemmy_db_schema::{
|
|||
aggregates::structs::PersonAggregates,
|
||||
newtypes::PersonId,
|
||||
schema::{person, person_aggregates},
|
||||
source::person::{Person, PersonSafe},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::person::Person,
|
||||
traits::JoinView,
|
||||
utils::{fuzzy_search, get_conn, limit_and_offset, DbPool},
|
||||
SortType,
|
||||
};
|
||||
use std::iter::Iterator;
|
||||
use typed_builder::TypedBuilder;
|
||||
|
||||
type PersonViewSafeTuple = (PersonSafe, PersonAggregates);
|
||||
type PersonViewTuple = (Person, PersonAggregates);
|
||||
|
||||
impl PersonViewSafe {
|
||||
impl PersonView {
|
||||
pub async fn read(pool: &DbPool, person_id: PersonId) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
let (person, counts) = person::table
|
||||
let res = person::table
|
||||
.find(person_id)
|
||||
.inner_join(person_aggregates::table)
|
||||
.select((Person::safe_columns_tuple(), person_aggregates::all_columns))
|
||||
.first::<PersonViewSafeTuple>(conn)
|
||||
.select((person::all_columns, person_aggregates::all_columns))
|
||||
.first::<PersonViewTuple>(conn)
|
||||
.await?;
|
||||
Ok(Self { person, counts })
|
||||
Ok(Self::from_tuple(res))
|
||||
}
|
||||
|
||||
pub async fn admins(pool: &DbPool) -> Result<Vec<Self>, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
let admins = person::table
|
||||
.inner_join(person_aggregates::table)
|
||||
.select((Person::safe_columns_tuple(), person_aggregates::all_columns))
|
||||
.select((person::all_columns, person_aggregates::all_columns))
|
||||
.filter(person::admin.eq(true))
|
||||
.filter(person::deleted.eq(false))
|
||||
.order_by(person::published)
|
||||
.load::<PersonViewSafeTuple>(conn)
|
||||
.load::<PersonViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
Ok(Self::from_tuple_to_vec(admins))
|
||||
Ok(admins.into_iter().map(Self::from_tuple).collect())
|
||||
}
|
||||
|
||||
pub async fn banned(pool: &DbPool) -> Result<Vec<Self>, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
let banned = person::table
|
||||
.inner_join(person_aggregates::table)
|
||||
.select((Person::safe_columns_tuple(), person_aggregates::all_columns))
|
||||
.select((person::all_columns, person_aggregates::all_columns))
|
||||
.filter(
|
||||
person::banned.eq(true).and(
|
||||
person::ban_expires
|
||||
|
@ -61,10 +61,10 @@ impl PersonViewSafe {
|
|||
),
|
||||
)
|
||||
.filter(person::deleted.eq(false))
|
||||
.load::<PersonViewSafeTuple>(conn)
|
||||
.load::<PersonViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
Ok(Self::from_tuple_to_vec(banned))
|
||||
Ok(banned.into_iter().map(Self::from_tuple).collect())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,11 +80,11 @@ pub struct PersonQuery<'a> {
|
|||
}
|
||||
|
||||
impl<'a> PersonQuery<'a> {
|
||||
pub async fn list(self) -> Result<Vec<PersonViewSafe>, Error> {
|
||||
pub async fn list(self) -> Result<Vec<PersonView>, Error> {
|
||||
let conn = &mut get_conn(self.pool).await?;
|
||||
let mut query = person::table
|
||||
.inner_join(person_aggregates::table)
|
||||
.select((Person::safe_columns_tuple(), person_aggregates::all_columns))
|
||||
.select((person::all_columns, person_aggregates::all_columns))
|
||||
.into_boxed();
|
||||
|
||||
if let Some(search_term) = self.search_term {
|
||||
|
@ -118,21 +118,18 @@ impl<'a> PersonQuery<'a> {
|
|||
let (limit, offset) = limit_and_offset(self.page, self.limit)?;
|
||||
query = query.limit(limit).offset(offset);
|
||||
|
||||
let res = query.load::<PersonViewSafeTuple>(conn).await?;
|
||||
let res = query.load::<PersonViewTuple>(conn).await?;
|
||||
|
||||
Ok(PersonViewSafe::from_tuple_to_vec(res))
|
||||
Ok(res.into_iter().map(PersonView::from_tuple).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for PersonViewSafe {
|
||||
type DbTuple = PersonViewSafeTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for PersonView {
|
||||
type JoinTuple = PersonViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
person: a.0,
|
||||
counts: a.1,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ use lemmy_db_schema::{
|
|||
source::{
|
||||
comment::Comment,
|
||||
comment_reply::CommentReply,
|
||||
community::CommunitySafe,
|
||||
person::PersonSafe,
|
||||
community::Community,
|
||||
person::Person,
|
||||
person_mention::PersonMention,
|
||||
post::Post,
|
||||
},
|
||||
|
@ -14,31 +14,31 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct CommunityBlockView {
|
||||
pub person: PersonSafe,
|
||||
pub community: CommunitySafe,
|
||||
pub person: Person,
|
||||
pub community: Community,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct CommunityFollowerView {
|
||||
pub community: CommunitySafe,
|
||||
pub follower: PersonSafe,
|
||||
pub community: Community,
|
||||
pub follower: Person,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct CommunityModeratorView {
|
||||
pub community: CommunitySafe,
|
||||
pub moderator: PersonSafe,
|
||||
pub community: Community,
|
||||
pub moderator: Person,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct CommunityPersonBanView {
|
||||
pub community: CommunitySafe,
|
||||
pub person: PersonSafe,
|
||||
pub community: Community,
|
||||
pub person: Person,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct CommunityView {
|
||||
pub community: CommunitySafe,
|
||||
pub community: Community,
|
||||
pub subscribed: SubscribedType,
|
||||
pub blocked: bool,
|
||||
pub counts: CommunityAggregates,
|
||||
|
@ -46,18 +46,18 @@ pub struct CommunityView {
|
|||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct PersonBlockView {
|
||||
pub person: PersonSafe,
|
||||
pub target: PersonSafe,
|
||||
pub person: Person,
|
||||
pub target: Person,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
|
||||
pub struct PersonMentionView {
|
||||
pub person_mention: PersonMention,
|
||||
pub comment: Comment,
|
||||
pub creator: PersonSafe,
|
||||
pub creator: Person,
|
||||
pub post: Post,
|
||||
pub community: CommunitySafe,
|
||||
pub recipient: PersonSafe,
|
||||
pub community: Community,
|
||||
pub recipient: Person,
|
||||
pub counts: CommentAggregates,
|
||||
pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan
|
||||
pub subscribed: SubscribedType, // Left join to CommunityFollower
|
||||
|
@ -70,10 +70,10 @@ pub struct PersonMentionView {
|
|||
pub struct CommentReplyView {
|
||||
pub comment_reply: CommentReply,
|
||||
pub comment: Comment,
|
||||
pub creator: PersonSafe,
|
||||
pub creator: Person,
|
||||
pub post: Post,
|
||||
pub community: CommunitySafe,
|
||||
pub recipient: PersonSafe,
|
||||
pub community: Community,
|
||||
pub recipient: Person,
|
||||
pub counts: CommentAggregates,
|
||||
pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan
|
||||
pub subscribed: SubscribedType, // Left join to CommunityFollower
|
||||
|
@ -83,7 +83,7 @@ pub struct CommentReplyView {
|
|||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct PersonViewSafe {
|
||||
pub person: PersonSafe,
|
||||
pub struct PersonView {
|
||||
pub person: Person,
|
||||
pub counts: PersonAggregates,
|
||||
}
|
||||
|
|
|
@ -12,16 +12,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{admin_purge_comment, person, post},
|
||||
source::{
|
||||
moderator::AdminPurgeComment,
|
||||
person::{Person, PersonSafe},
|
||||
post::Post,
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{moderator::AdminPurgeComment, person::Person, post::Post},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
|
||||
type AdminPurgeCommentViewTuple = (AdminPurgeComment, Option<PersonSafe>, Post);
|
||||
type AdminPurgeCommentViewTuple = (AdminPurgeComment, Option<Person>, Post);
|
||||
|
||||
impl AdminPurgeCommentView {
|
||||
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||
|
@ -39,7 +35,7 @@ impl AdminPurgeCommentView {
|
|||
.inner_join(post::table)
|
||||
.select((
|
||||
admin_purge_comment::all_columns,
|
||||
Person::safe_columns_tuple().nullable(),
|
||||
person::all_columns.nullable(),
|
||||
post::all_columns,
|
||||
))
|
||||
.into_boxed();
|
||||
|
@ -57,21 +53,18 @@ impl AdminPurgeCommentView {
|
|||
.load::<AdminPurgeCommentViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
let results = Self::from_tuple_to_vec(res);
|
||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for AdminPurgeCommentView {
|
||||
type DbTuple = AdminPurgeCommentViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for AdminPurgeCommentView {
|
||||
type JoinTuple = AdminPurgeCommentViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
admin_purge_comment: a.0,
|
||||
admin: a.1,
|
||||
post: a.2,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,15 +12,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{admin_purge_community, person},
|
||||
source::{
|
||||
moderator::AdminPurgeCommunity,
|
||||
person::{Person, PersonSafe},
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{moderator::AdminPurgeCommunity, person::Person},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
|
||||
type AdminPurgeCommunityViewTuple = (AdminPurgeCommunity, Option<PersonSafe>);
|
||||
type AdminPurgeCommunityViewTuple = (AdminPurgeCommunity, Option<Person>);
|
||||
|
||||
impl AdminPurgeCommunityView {
|
||||
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||
|
@ -37,7 +34,7 @@ impl AdminPurgeCommunityView {
|
|||
.left_join(person::table.on(admin_names_join))
|
||||
.select((
|
||||
admin_purge_community::all_columns,
|
||||
Person::safe_columns_tuple().nullable(),
|
||||
person::all_columns.nullable(),
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -54,20 +51,17 @@ impl AdminPurgeCommunityView {
|
|||
.load::<AdminPurgeCommunityViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
let results = Self::from_tuple_to_vec(res);
|
||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for AdminPurgeCommunityView {
|
||||
type DbTuple = AdminPurgeCommunityViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for AdminPurgeCommunityView {
|
||||
type JoinTuple = AdminPurgeCommunityViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
admin_purge_community: a.0,
|
||||
admin: a.1,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,15 +12,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{admin_purge_person, person},
|
||||
source::{
|
||||
moderator::AdminPurgePerson,
|
||||
person::{Person, PersonSafe},
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{moderator::AdminPurgePerson, person::Person},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
|
||||
type AdminPurgePersonViewTuple = (AdminPurgePerson, Option<PersonSafe>);
|
||||
type AdminPurgePersonViewTuple = (AdminPurgePerson, Option<Person>);
|
||||
|
||||
impl AdminPurgePersonView {
|
||||
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||
|
@ -37,7 +34,7 @@ impl AdminPurgePersonView {
|
|||
.left_join(person::table.on(admin_names_join))
|
||||
.select((
|
||||
admin_purge_person::all_columns,
|
||||
Person::safe_columns_tuple().nullable(),
|
||||
person::all_columns.nullable(),
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -54,20 +51,17 @@ impl AdminPurgePersonView {
|
|||
.load::<AdminPurgePersonViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
let results = Self::from_tuple_to_vec(res);
|
||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for AdminPurgePersonView {
|
||||
type DbTuple = AdminPurgePersonViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for AdminPurgePersonView {
|
||||
type JoinTuple = AdminPurgePersonViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
admin_purge_person: a.0,
|
||||
admin: a.1,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,16 +12,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{admin_purge_post, community, person},
|
||||
source::{
|
||||
community::{Community, CommunitySafe},
|
||||
moderator::AdminPurgePost,
|
||||
person::{Person, PersonSafe},
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{community::Community, moderator::AdminPurgePost, person::Person},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
|
||||
type AdminPurgePostViewTuple = (AdminPurgePost, Option<PersonSafe>, CommunitySafe);
|
||||
type AdminPurgePostViewTuple = (AdminPurgePost, Option<Person>, Community);
|
||||
|
||||
impl AdminPurgePostView {
|
||||
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||
|
@ -39,8 +35,8 @@ impl AdminPurgePostView {
|
|||
.inner_join(community::table)
|
||||
.select((
|
||||
admin_purge_post::all_columns,
|
||||
Person::safe_columns_tuple().nullable(),
|
||||
Community::safe_columns_tuple(),
|
||||
person::all_columns.nullable(),
|
||||
community::all_columns,
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -57,21 +53,18 @@ impl AdminPurgePostView {
|
|||
.load::<AdminPurgePostViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
let results = Self::from_tuple_to_vec(res);
|
||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for AdminPurgePostView {
|
||||
type DbTuple = AdminPurgePostViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for AdminPurgePostView {
|
||||
type JoinTuple = AdminPurgePostViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
admin_purge_post: a.0,
|
||||
admin: a.1,
|
||||
community: a.2,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,21 +12,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{community, mod_add_community, person},
|
||||
source::{
|
||||
community::{Community, CommunitySafe},
|
||||
moderator::ModAddCommunity,
|
||||
person::{Person, PersonSafe},
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{community::Community, moderator::ModAddCommunity, person::Person},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
|
||||
type ModAddCommunityViewTuple = (
|
||||
ModAddCommunity,
|
||||
Option<PersonSafe>,
|
||||
CommunitySafe,
|
||||
PersonSafe,
|
||||
);
|
||||
type ModAddCommunityViewTuple = (ModAddCommunity, Option<Person>, Community, Person);
|
||||
|
||||
impl ModAddCommunityView {
|
||||
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||
|
@ -47,9 +38,9 @@ impl ModAddCommunityView {
|
|||
)
|
||||
.select((
|
||||
mod_add_community::all_columns,
|
||||
Person::safe_columns_tuple().nullable(),
|
||||
Community::safe_columns_tuple(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
person::all_columns.nullable(),
|
||||
community::all_columns,
|
||||
person_alias_1.fields(person::all_columns),
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -74,22 +65,19 @@ impl ModAddCommunityView {
|
|||
.load::<ModAddCommunityViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
let results = Self::from_tuple_to_vec(res);
|
||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModAddCommunityView {
|
||||
type DbTuple = ModAddCommunityViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for ModAddCommunityView {
|
||||
type JoinTuple = ModAddCommunityViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
mod_add_community: a.0,
|
||||
moderator: a.1,
|
||||
community: a.2,
|
||||
modded_person: a.3,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,15 +12,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{mod_add, person},
|
||||
source::{
|
||||
moderator::ModAdd,
|
||||
person::{Person, PersonSafe},
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{moderator::ModAdd, person::Person},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
|
||||
type ModAddViewTuple = (ModAdd, Option<PersonSafe>, PersonSafe);
|
||||
type ModAddViewTuple = (ModAdd, Option<Person>, Person);
|
||||
|
||||
impl ModAddView {
|
||||
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||
|
@ -38,8 +35,8 @@ impl ModAddView {
|
|||
.inner_join(person_alias_1.on(mod_add::other_person_id.eq(person_alias_1.field(person::id))))
|
||||
.select((
|
||||
mod_add::all_columns,
|
||||
Person::safe_columns_tuple().nullable(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
person::all_columns.nullable(),
|
||||
person_alias_1.fields(person::all_columns),
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -60,21 +57,18 @@ impl ModAddView {
|
|||
.load::<ModAddViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
let results = Self::from_tuple_to_vec(res);
|
||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModAddView {
|
||||
type DbTuple = ModAddViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for ModAddView {
|
||||
type JoinTuple = ModAddViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
mod_add: a.0,
|
||||
moderator: a.1,
|
||||
modded_person: a.2,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,21 +12,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{community, mod_ban_from_community, person},
|
||||
source::{
|
||||
community::{Community, CommunitySafe},
|
||||
moderator::ModBanFromCommunity,
|
||||
person::{Person, PersonSafe},
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{community::Community, moderator::ModBanFromCommunity, person::Person},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
|
||||
type ModBanFromCommunityViewTuple = (
|
||||
ModBanFromCommunity,
|
||||
Option<PersonSafe>,
|
||||
CommunitySafe,
|
||||
PersonSafe,
|
||||
);
|
||||
type ModBanFromCommunityViewTuple = (ModBanFromCommunity, Option<Person>, Community, Person);
|
||||
|
||||
impl ModBanFromCommunityView {
|
||||
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||
|
@ -49,9 +40,9 @@ impl ModBanFromCommunityView {
|
|||
)
|
||||
.select((
|
||||
mod_ban_from_community::all_columns,
|
||||
Person::safe_columns_tuple().nullable(),
|
||||
Community::safe_columns_tuple(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
person::all_columns.nullable(),
|
||||
community::all_columns,
|
||||
person_alias_1.fields(person::all_columns),
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -76,22 +67,19 @@ impl ModBanFromCommunityView {
|
|||
.load::<ModBanFromCommunityViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
let results = Self::from_tuple_to_vec(res);
|
||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModBanFromCommunityView {
|
||||
type DbTuple = ModBanFromCommunityViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for ModBanFromCommunityView {
|
||||
type JoinTuple = ModBanFromCommunityViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
mod_ban_from_community: a.0,
|
||||
moderator: a.1,
|
||||
community: a.2,
|
||||
banned_person: a.3,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,15 +12,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{mod_ban, person},
|
||||
source::{
|
||||
moderator::ModBan,
|
||||
person::{Person, PersonSafe},
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{moderator::ModBan, person::Person},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
|
||||
type ModBanViewTuple = (ModBan, Option<PersonSafe>, PersonSafe);
|
||||
type ModBanViewTuple = (ModBan, Option<Person>, Person);
|
||||
|
||||
impl ModBanView {
|
||||
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||
|
@ -38,8 +35,8 @@ impl ModBanView {
|
|||
.inner_join(person_alias_1.on(mod_ban::other_person_id.eq(person_alias_1.field(person::id))))
|
||||
.select((
|
||||
mod_ban::all_columns,
|
||||
Person::safe_columns_tuple().nullable(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
person::all_columns.nullable(),
|
||||
person_alias_1.fields(person::all_columns),
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -60,21 +57,18 @@ impl ModBanView {
|
|||
.load::<ModBanViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
let results = Self::from_tuple_to_vec(res);
|
||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModBanView {
|
||||
type DbTuple = ModBanViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for ModBanView {
|
||||
type JoinTuple = ModBanViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
mod_ban: a.0,
|
||||
moderator: a.1,
|
||||
banned_person: a.2,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,17 +12,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{community, mod_feature_post, person, post},
|
||||
source::{
|
||||
community::{Community, CommunitySafe},
|
||||
moderator::ModFeaturePost,
|
||||
person::{Person, PersonSafe},
|
||||
post::Post,
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{community::Community, moderator::ModFeaturePost, person::Person, post::Post},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
|
||||
type ModFeaturePostViewTuple = (ModFeaturePost, Option<PersonSafe>, Post, CommunitySafe);
|
||||
type ModFeaturePostViewTuple = (ModFeaturePost, Option<Person>, Post, Community);
|
||||
|
||||
impl ModFeaturePostView {
|
||||
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||
|
@ -42,9 +37,9 @@ impl ModFeaturePostView {
|
|||
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
||||
.select((
|
||||
mod_feature_post::all_columns,
|
||||
Person::safe_columns_tuple().nullable(),
|
||||
person::all_columns.nullable(),
|
||||
post::all_columns,
|
||||
Community::safe_columns_tuple(),
|
||||
community::all_columns,
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -69,22 +64,19 @@ impl ModFeaturePostView {
|
|||
.load::<ModFeaturePostViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
let results = Self::from_tuple_to_vec(res);
|
||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModFeaturePostView {
|
||||
type DbTuple = ModFeaturePostViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for ModFeaturePostView {
|
||||
type JoinTuple = ModFeaturePostViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
mod_feature_post: a.0,
|
||||
moderator: a.1,
|
||||
post: a.2,
|
||||
community: a.3,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,16 +12,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{community, mod_hide_community, person},
|
||||
source::{
|
||||
community::{Community, CommunitySafe},
|
||||
moderator::ModHideCommunity,
|
||||
person::{Person, PersonSafe},
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{community::Community, moderator::ModHideCommunity, person::Person},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
|
||||
type ModHideCommunityViewTuple = (ModHideCommunity, Option<PersonSafe>, CommunitySafe);
|
||||
type ModHideCommunityViewTuple = (ModHideCommunity, Option<Person>, Community);
|
||||
|
||||
impl ModHideCommunityView {
|
||||
// Pass in mod_id as admin_id because only admins can do this action
|
||||
|
@ -40,8 +36,8 @@ impl ModHideCommunityView {
|
|||
.inner_join(community::table.on(mod_hide_community::community_id.eq(community::id)))
|
||||
.select((
|
||||
mod_hide_community::all_columns,
|
||||
Person::safe_columns_tuple().nullable(),
|
||||
Community::safe_columns_tuple(),
|
||||
person::all_columns.nullable(),
|
||||
community::all_columns,
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -62,21 +58,18 @@ impl ModHideCommunityView {
|
|||
.load::<ModHideCommunityViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
let results = Self::from_tuple_to_vec(res);
|
||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModHideCommunityView {
|
||||
type DbTuple = ModHideCommunityViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for ModHideCommunityView {
|
||||
type JoinTuple = ModHideCommunityViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
mod_hide_community: a.0,
|
||||
admin: a.1,
|
||||
community: a.2,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,17 +12,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{community, mod_lock_post, person, post},
|
||||
source::{
|
||||
community::{Community, CommunitySafe},
|
||||
moderator::ModLockPost,
|
||||
person::{Person, PersonSafe},
|
||||
post::Post,
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{community::Community, moderator::ModLockPost, person::Person, post::Post},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
|
||||
type ModLockPostViewTuple = (ModLockPost, Option<PersonSafe>, Post, CommunitySafe);
|
||||
type ModLockPostViewTuple = (ModLockPost, Option<Person>, Post, Community);
|
||||
|
||||
impl ModLockPostView {
|
||||
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||
|
@ -43,9 +38,9 @@ impl ModLockPostView {
|
|||
.inner_join(person_alias_1.on(post::creator_id.eq(person_alias_1.field(person::id))))
|
||||
.select((
|
||||
mod_lock_post::all_columns,
|
||||
Person::safe_columns_tuple().nullable(),
|
||||
person::all_columns.nullable(),
|
||||
post::all_columns,
|
||||
Community::safe_columns_tuple(),
|
||||
community::all_columns,
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -70,22 +65,19 @@ impl ModLockPostView {
|
|||
.load::<ModLockPostViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
let results = Self::from_tuple_to_vec(res);
|
||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModLockPostView {
|
||||
type DbTuple = ModLockPostViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for ModLockPostView {
|
||||
type JoinTuple = ModLockPostViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
mod_lock_post: a.0,
|
||||
moderator: a.1,
|
||||
post: a.2,
|
||||
community: a.3,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,22 +14,22 @@ use lemmy_db_schema::{
|
|||
schema::{comment, community, mod_remove_comment, person, post},
|
||||
source::{
|
||||
comment::Comment,
|
||||
community::{Community, CommunitySafe},
|
||||
community::Community,
|
||||
moderator::ModRemoveComment,
|
||||
person::{Person, PersonSafe},
|
||||
person::Person,
|
||||
post::Post,
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
|
||||
type ModRemoveCommentViewTuple = (
|
||||
ModRemoveComment,
|
||||
Option<PersonSafe>,
|
||||
Option<Person>,
|
||||
Comment,
|
||||
PersonSafe,
|
||||
Person,
|
||||
Post,
|
||||
CommunitySafe,
|
||||
Community,
|
||||
);
|
||||
|
||||
impl ModRemoveCommentView {
|
||||
|
@ -51,11 +51,11 @@ impl ModRemoveCommentView {
|
|||
.inner_join(community::table.on(post::community_id.eq(community::id)))
|
||||
.select((
|
||||
mod_remove_comment::all_columns,
|
||||
Person::safe_columns_tuple().nullable(),
|
||||
person::all_columns.nullable(),
|
||||
comment::all_columns,
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
person_alias_1.fields(person::all_columns),
|
||||
post::all_columns,
|
||||
Community::safe_columns_tuple(),
|
||||
community::all_columns,
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -80,24 +80,21 @@ impl ModRemoveCommentView {
|
|||
.load::<ModRemoveCommentViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
let results = Self::from_tuple_to_vec(res);
|
||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModRemoveCommentView {
|
||||
type DbTuple = ModRemoveCommentViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for ModRemoveCommentView {
|
||||
type JoinTuple = ModRemoveCommentViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
mod_remove_comment: a.0,
|
||||
moderator: a.1,
|
||||
comment: a.2,
|
||||
commenter: a.3,
|
||||
post: a.4,
|
||||
community: a.5,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,16 +12,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{community, mod_remove_community, person},
|
||||
source::{
|
||||
community::{Community, CommunitySafe},
|
||||
moderator::ModRemoveCommunity,
|
||||
person::{Person, PersonSafe},
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{community::Community, moderator::ModRemoveCommunity, person::Person},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
|
||||
type ModRemoveCommunityTuple = (ModRemoveCommunity, Option<PersonSafe>, CommunitySafe);
|
||||
type ModRemoveCommunityTuple = (ModRemoveCommunity, Option<Person>, Community);
|
||||
|
||||
impl ModRemoveCommunityView {
|
||||
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||
|
@ -38,8 +34,8 @@ impl ModRemoveCommunityView {
|
|||
.inner_join(community::table)
|
||||
.select((
|
||||
mod_remove_community::all_columns,
|
||||
Person::safe_columns_tuple().nullable(),
|
||||
Community::safe_columns_tuple(),
|
||||
person::all_columns.nullable(),
|
||||
community::all_columns,
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -56,21 +52,18 @@ impl ModRemoveCommunityView {
|
|||
.load::<ModRemoveCommunityTuple>(conn)
|
||||
.await?;
|
||||
|
||||
let results = Self::from_tuple_to_vec(res);
|
||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModRemoveCommunityView {
|
||||
type DbTuple = ModRemoveCommunityTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for ModRemoveCommunityView {
|
||||
type JoinTuple = ModRemoveCommunityTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
mod_remove_community: a.0,
|
||||
moderator: a.1,
|
||||
community: a.2,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,17 +12,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{community, mod_remove_post, person, post},
|
||||
source::{
|
||||
community::{Community, CommunitySafe},
|
||||
moderator::ModRemovePost,
|
||||
person::{Person, PersonSafe},
|
||||
post::Post,
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{community::Community, moderator::ModRemovePost, person::Person, post::Post},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
|
||||
type ModRemovePostViewTuple = (ModRemovePost, Option<PersonSafe>, Post, CommunitySafe);
|
||||
type ModRemovePostViewTuple = (ModRemovePost, Option<Person>, Post, Community);
|
||||
|
||||
impl ModRemovePostView {
|
||||
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||
|
@ -43,9 +38,9 @@ impl ModRemovePostView {
|
|||
.inner_join(person_alias_1.on(post::creator_id.eq(person_alias_1.field(person::id))))
|
||||
.select((
|
||||
mod_remove_post::all_columns,
|
||||
Person::safe_columns_tuple().nullable(),
|
||||
person::all_columns.nullable(),
|
||||
post::all_columns,
|
||||
Community::safe_columns_tuple(),
|
||||
community::all_columns,
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -70,22 +65,19 @@ impl ModRemovePostView {
|
|||
.load::<ModRemovePostViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
let results = Self::from_tuple_to_vec(res);
|
||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModRemovePostView {
|
||||
type DbTuple = ModRemovePostViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for ModRemovePostView {
|
||||
type JoinTuple = ModRemovePostViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
mod_remove_post: a.0,
|
||||
moderator: a.1,
|
||||
post: a.2,
|
||||
community: a.3,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,21 +12,12 @@ use diesel_async::RunQueryDsl;
|
|||
use lemmy_db_schema::{
|
||||
newtypes::PersonId,
|
||||
schema::{community, mod_transfer_community, person},
|
||||
source::{
|
||||
community::{Community, CommunitySafe},
|
||||
moderator::ModTransferCommunity,
|
||||
person::{Person, PersonSafe},
|
||||
},
|
||||
traits::{ToSafe, ViewToVec},
|
||||
source::{community::Community, moderator::ModTransferCommunity, person::Person},
|
||||
traits::JoinView,
|
||||
utils::{get_conn, limit_and_offset, DbPool},
|
||||
};
|
||||
|
||||
type ModTransferCommunityViewTuple = (
|
||||
ModTransferCommunity,
|
||||
Option<PersonSafe>,
|
||||
CommunitySafe,
|
||||
PersonSafe,
|
||||
);
|
||||
type ModTransferCommunityViewTuple = (ModTransferCommunity, Option<Person>, Community, Person);
|
||||
|
||||
impl ModTransferCommunityView {
|
||||
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||
|
@ -49,9 +40,9 @@ impl ModTransferCommunityView {
|
|||
)
|
||||
.select((
|
||||
mod_transfer_community::all_columns,
|
||||
Person::safe_columns_tuple().nullable(),
|
||||
Community::safe_columns_tuple(),
|
||||
person_alias_1.fields(Person::safe_columns_tuple()),
|
||||
person::all_columns.nullable(),
|
||||
community::all_columns,
|
||||
person_alias_1.fields(person::all_columns),
|
||||
))
|
||||
.into_boxed();
|
||||
|
||||
|
@ -76,22 +67,19 @@ impl ModTransferCommunityView {
|
|||
.load::<ModTransferCommunityViewTuple>(conn)
|
||||
.await?;
|
||||
|
||||
let results = Self::from_tuple_to_vec(res);
|
||||
let results = res.into_iter().map(Self::from_tuple).collect();
|
||||
Ok(results)
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewToVec for ModTransferCommunityView {
|
||||
type DbTuple = ModTransferCommunityViewTuple;
|
||||
fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
|
||||
items
|
||||
.into_iter()
|
||||
.map(|a| Self {
|
||||
impl JoinView for ModTransferCommunityView {
|
||||
type JoinTuple = ModTransferCommunityViewTuple;
|
||||
fn from_tuple(a: Self::JoinTuple) -> Self {
|
||||
Self {
|
||||
mod_transfer_community: a.0,
|
||||
moderator: a.1,
|
||||
community: a.2,
|
||||
modded_person: a.3,
|
||||
})
|
||||
.collect::<Vec<Self>>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use lemmy_db_schema::{
|
|||
newtypes::{CommunityId, PersonId},
|
||||
source::{
|
||||
comment::Comment,
|
||||
community::CommunitySafe,
|
||||
community::Community,
|
||||
moderator::{
|
||||
AdminPurgeComment,
|
||||
AdminPurgeCommunity,
|
||||
|
@ -20,7 +20,7 @@ use lemmy_db_schema::{
|
|||
ModRemovePost,
|
||||
ModTransferCommunity,
|
||||
},
|
||||
person::PersonSafe,
|
||||
person::Person,
|
||||
post::Post,
|
||||
},
|
||||
};
|
||||
|
@ -29,113 +29,113 @@ use serde::{Deserialize, Serialize};
|
|||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ModAddCommunityView {
|
||||
pub mod_add_community: ModAddCommunity,
|
||||
pub moderator: Option<PersonSafe>,
|
||||
pub community: CommunitySafe,
|
||||
pub modded_person: PersonSafe,
|
||||
pub moderator: Option<Person>,
|
||||
pub community: Community,
|
||||
pub modded_person: Person,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ModAddView {
|
||||
pub mod_add: ModAdd,
|
||||
pub moderator: Option<PersonSafe>,
|
||||
pub modded_person: PersonSafe,
|
||||
pub moderator: Option<Person>,
|
||||
pub modded_person: Person,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ModBanFromCommunityView {
|
||||
pub mod_ban_from_community: ModBanFromCommunity,
|
||||
pub moderator: Option<PersonSafe>,
|
||||
pub community: CommunitySafe,
|
||||
pub banned_person: PersonSafe,
|
||||
pub moderator: Option<Person>,
|
||||
pub community: Community,
|
||||
pub banned_person: Person,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ModBanView {
|
||||
pub mod_ban: ModBan,
|
||||
pub moderator: Option<PersonSafe>,
|
||||
pub banned_person: PersonSafe,
|
||||
pub moderator: Option<Person>,
|
||||
pub banned_person: Person,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ModHideCommunityView {
|
||||
pub mod_hide_community: ModHideCommunity,
|
||||
pub admin: Option<PersonSafe>,
|
||||
pub community: CommunitySafe,
|
||||
pub admin: Option<Person>,
|
||||
pub community: Community,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ModLockPostView {
|
||||
pub mod_lock_post: ModLockPost,
|
||||
pub moderator: Option<PersonSafe>,
|
||||
pub moderator: Option<Person>,
|
||||
pub post: Post,
|
||||
pub community: CommunitySafe,
|
||||
pub community: Community,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ModRemoveCommentView {
|
||||
pub mod_remove_comment: ModRemoveComment,
|
||||
pub moderator: Option<PersonSafe>,
|
||||
pub moderator: Option<Person>,
|
||||
pub comment: Comment,
|
||||
pub commenter: PersonSafe,
|
||||
pub commenter: Person,
|
||||
pub post: Post,
|
||||
pub community: CommunitySafe,
|
||||
pub community: Community,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ModRemoveCommunityView {
|
||||
pub mod_remove_community: ModRemoveCommunity,
|
||||
pub moderator: Option<PersonSafe>,
|
||||
pub community: CommunitySafe,
|
||||
pub moderator: Option<Person>,
|
||||
pub community: Community,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ModRemovePostView {
|
||||
pub mod_remove_post: ModRemovePost,
|
||||
pub moderator: Option<PersonSafe>,
|
||||
pub moderator: Option<Person>,
|
||||
pub post: Post,
|
||||
pub community: CommunitySafe,
|
||||
pub community: Community,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ModFeaturePostView {
|
||||
pub mod_feature_post: ModFeaturePost,
|
||||
pub moderator: Option<PersonSafe>,
|
||||
pub moderator: Option<Person>,
|
||||
pub post: Post,
|
||||
pub community: CommunitySafe,
|
||||
pub community: Community,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct ModTransferCommunityView {
|
||||
pub mod_transfer_community: ModTransferCommunity,
|
||||
pub moderator: Option<PersonSafe>,
|
||||
pub community: CommunitySafe,
|
||||
pub modded_person: PersonSafe,
|
||||
pub moderator: Option<Person>,
|
||||
pub community: Community,
|
||||
pub modded_person: Person,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct AdminPurgeCommentView {
|
||||
pub admin_purge_comment: AdminPurgeComment,
|
||||
pub admin: Option<PersonSafe>,
|
||||
pub admin: Option<Person>,
|
||||
pub post: Post,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct AdminPurgeCommunityView {
|
||||
pub admin_purge_community: AdminPurgeCommunity,
|
||||
pub admin: Option<PersonSafe>,
|
||||
pub admin: Option<Person>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct AdminPurgePersonView {
|
||||
pub admin_purge_person: AdminPurgePerson,
|
||||
pub admin: Option<PersonSafe>,
|
||||
pub admin: Option<Person>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct AdminPurgePostView {
|
||||
pub admin_purge_post: AdminPurgePost,
|
||||
pub admin: Option<PersonSafe>,
|
||||
pub community: CommunitySafe,
|
||||
pub admin: Option<Person>,
|
||||
pub community: Community,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
|
||||
|
|
Loading…
Reference in a new issue