},
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)]
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,
},
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)]
ModAdd::create(context.pool(), &form).await?;
- let admins = PersonViewSafe::admins(context.pool()).await?;
+ let admins = PersonView::admins(context.pool()).await?;
let res = AddAdminResponse { admins };
},
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)]
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,
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)]
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"));
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)]
// 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 };
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)]
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"));
}
// 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?;
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)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct BanFromCommunityResponse {
- pub person_view: PersonViewSafe,
+ pub person_view: PersonView,
pub banned: bool,
}
CommentReplyView,
CommunityModeratorView,
PersonMentionView,
- PersonViewSafe,
+ PersonView,
};
use serde::{Deserialize, Serialize};
#[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>,
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AddAdminResponse {
- pub admins: Vec<PersonViewSafe>,
+ pub admins: Vec<PersonView>,
}
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[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,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct BlockPersonResponse {
- pub person_view: PersonViewSafe,
+ pub person_view: PersonView,
pub blocked: bool,
}
};
use lemmy_db_views::structs::{
CommentView,
- LocalUserSettingsView,
+ LocalUserView,
PostView,
RegistrationApplicationView,
SiteView,
CommunityModeratorView,
CommunityView,
PersonBlockView,
- PersonViewSafe,
+ PersonView,
};
use lemmy_db_views_moderator::structs::{
AdminPurgeCommentView,
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)]
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)]
#[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>,
#[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>,
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,
}
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"))?;
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,
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)
}
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",
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(),);
CommunityFollowerView,
CommunityModeratorView,
PersonBlockView,
- PersonViewSafe,
+ PersonView,
};
use lemmy_utils::{error::LemmyError, version, ConnectionId};
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()?;
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)]
// 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;
};
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)]
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;
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;
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,
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;
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)]
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))]
pub struct LocalUser {
pub id: LocalUserId,
pub person_id: PersonId,
+ #[serde(skip)]
pub password_encrypted: String,
pub email: Option<String>,
pub show_nsfw: bool,
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))]
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,
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;
}
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
///
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)))
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
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();
.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 {
- comment_report: a.0,
- comment: a.1,
- post: a.2,
- community: a.3,
- creator: a.4,
- comment_creator: a.5,
- counts: a.6,
- creator_banned_from_community: a.7.is_some(),
- my_vote: a.8,
- resolver: a.9,
- })
- .collect::<Vec<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,
+ community: a.3,
+ creator: a.4,
+ comment_creator: a.5,
+ counts: a.6,
+ creator_banned_from_community: a.7.is_some(),
+ my_vote: a.8,
+ resolver: a.9,
+ }
}
}
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},
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,
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,
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,
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 {
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,
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
.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,
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,
},
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,
type CommentViewTuple = (
Comment,
- PersonSafe,
+ Person,
Post,
- CommunitySafe,
+ Community,
CommentAggregates,
Option<CommunityPersonBan>,
Option<CommunityFollower>,
)
.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(),
)
.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(),
.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 {
- comment: a.0,
- creator: a.1,
- post: a.2,
- community: a.3,
- counts: a.4,
- creator_banned_from_community: a.5.is_some(),
- subscribed: CommunityFollower::to_subscribed_type(&a.6),
- saved: a.7.is_some(),
- creator_blocked: a.8.is_some(),
- my_vote: a.9,
- })
- .collect::<Vec<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,
+ community: a.3,
+ counts: a.4,
+ creator_banned_from_community: a.5.is_some(),
+ subscribed: CommunityFollower::to_subscribed_type(&a.6),
+ saved: a.7.is_some(),
+ creator_blocked: a.8.is_some(),
+ my_vote: a.9,
+ }
}
}
CommentSortType,
CommentView,
Community,
- CommunitySafe,
DbPool,
LocalUser,
Person,
PersonBlock,
- PersonSafe,
Post,
};
use lemmy_db_schema::{
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,
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,
featured_community: false,
featured_local: false,
},
- community: CommunitySafe {
+ community: Community {
id: data.inserted_community.id,
name: "test community 5".to_string(),
icon: None,
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,
-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},
};
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?;
.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 {
- local_user: a.0,
- person: a.1,
- counts: a.2,
- })
- .collect::<Vec<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,
+ }
}
}
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;
type PostReportViewTuple = (
PostReport,
Post,
- CommunitySafe,
- PersonSafe,
- PersonSafe,
+ Community,
+ Person,
+ Person,
Option<CommunityPersonBan>,
Option<i16>,
PostAggregates,
- Option<PersonSafe>,
+ Option<Person>,
);
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?;
.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();
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 {
- post_report: a.0,
- post: a.1,
- community: a.2,
- creator: a.3,
- post_creator: a.4,
- creator_banned_from_community: a.5.is_some(),
- my_vote: a.6,
- counts: a.7,
- resolver: a.8,
- })
- .collect::<Vec<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,
+ creator: a.3,
+ post_creator: a.4,
+ creator_banned_from_community: a.5.is_some(),
+ my_vote: a.6,
+ counts: a.7,
+ resolver: a.8,
+ }
}
}
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},
},
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,
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,
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,
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,
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,
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
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,
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!(
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,
type PostViewTuple = (
Post,
- PersonSafe,
- CommunitySafe,
+ Person,
+ Community,
Option<CommunityPersonBan>,
PostAggregates,
Option<CommunityFollower>,
)
.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(),
)
.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(),
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 {
- post: a.0,
- creator: a.1,
- community: a.2,
- creator_banned_from_community: a.3.is_some(),
- counts: a.4,
- subscribed: CommunityFollower::to_subscribed_type(&a.5),
- saved: a.6.is_some(),
- read: a.7.is_some(),
- creator_blocked: a.8.is_some(),
- my_vote: a.9,
- unread_comments: a.10,
- })
- .collect::<Vec<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,
+ creator_banned_from_community: a.3.is_some(),
+ counts: a.4,
+ subscribed: CommunityFollower::to_subscribed_type(&a.5),
+ saved: a.6.is_some(),
+ read: a.7.is_some(),
+ creator_blocked: a.8.is_some(),
+ my_vote: a.9,
+ unread_comments: a.10,
+ }
}
}
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},
},
},
my_vote: None,
unread_comments: 0,
- creator: PersonSafe {
+ creator: Person {
id: inserted_person.id,
name: inserted_person.name.clone(),
display_name: None,
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,
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,
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;
type PrivateMessageReportViewTuple = (
PrivateMessageReport,
PrivateMessage,
- PersonSafe,
- PersonSafe,
- Option<PersonSafe>,
+ Person,
+ Person,
+ Option<Person>,
);
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?;
.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();
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 {
- private_message_report: a.0,
- private_message: a.1,
- private_message_creator: a.2,
- creator: a.3,
- resolver: a.4,
- })
- .collect::<Vec<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,
+ }
}
}
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> {
.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?;
)
.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();
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 {
- private_message: a.0,
- creator: a.1,
- recipient: a.2,
- })
- .collect::<Vec<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,
+ }
}
}
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> {
.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?;
.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();
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 {
- registration_application: a.0,
- creator_local_user: a.1,
- creator: a.2,
- admin: a.3,
- })
- .collect::<Vec<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,
+ }
}
}
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,
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,
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,
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,
};
.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,
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);
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,
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
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
#[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)]
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,
};
type CommentReplyViewTuple = (
CommentReply,
Comment,
- PersonSafe,
+ Person,
Post,
- CommunitySafe,
- PersonSafe,
+ Community,
+ Person,
CommentAggregates,
Option<CommunityPersonBan>,
Option<CommunityFollower>,
.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(),
.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(),
.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 {
- comment_reply: a.0,
- comment: a.1,
- creator: a.2,
- post: a.3,
- community: a.4,
- recipient: a.5,
- counts: a.6,
- creator_banned_from_community: a.7.is_some(),
- subscribed: CommunityFollower::to_subscribed_type(&a.8),
- saved: a.9.is_some(),
- creator_blocked: a.10.is_some(),
- my_vote: a.11,
- })
- .collect::<Vec<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,
+ post: a.3,
+ community: a.4,
+ recipient: a.5,
+ counts: a.6,
+ creator_banned_from_community: a.7.is_some(),
+ subscribed: CommunityFollower::to_subscribed_type(&a.8),
+ saved: a.9.is_some(),
+ creator_blocked: a.10.is_some(),
+ my_vote: a.11,
+ }
}
}
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> {
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))
.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 {
- person: a.0,
- community: a.1,
- })
- .collect::<Vec<Self>>()
+impl JoinView for CommunityBlockView {
+ type JoinTuple = CommunityBlockViewTuple;
+ fn from_tuple(a: Self::JoinTuple) -> Self {
+ Self {
+ person: a.0,
+ community: a.1,
+ }
}
}
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> {
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> {
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))
.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 {
- community: a.0,
- follower: a.1,
- })
- .collect::<Vec<Self>>()
+impl JoinView for CommunityFollowerView {
+ type JoinTuple = CommunityFollowerViewTuple;
+ fn from_tuple(a: Self::JoinTuple) -> Self {
+ Self {
+ community: a.0,
+ follower: a.1,
+ }
}
}
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> {
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> {
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))
.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
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)
.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 {
- community: a.0,
- moderator: a.1,
- })
- .collect::<Vec<Self>>()
+impl JoinView for CommunityModeratorView {
+ type JoinTuple = CommunityModeratorViewTuple;
+ fn from_tuple(a: Self::JoinTuple) -> Self {
+ Self {
+ community: a.0,
+ moderator: a.1,
+ }
}
}
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},
};
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(
.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 })
-use crate::structs::{CommunityModeratorView, CommunityView, PersonViewSafe};
+use crate::structs::{CommunityModeratorView, CommunityView, PersonView};
use diesel::{
result::Error,
BoolExpressionMethods,
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,
use typed_builder::TypedBuilder;
type CommunityViewTuple = (
- CommunitySafe,
+ Community,
CommunityAggregates,
Option<CommunityFollower>,
Option<CommunityBlock>,
),
)
.select((
- Community::safe_columns_tuple(),
+ community::all_columns,
community_aggregates::all_columns,
community_follower::all_columns.nullable(),
community_block::all_columns.nullable(),
return Ok(true);
}
- let is_admin = PersonViewSafe::admins(pool)
+ let is_admin = PersonView::admins(pool)
.await
.map(|v| {
v.into_iter()
),
)
.select((
- Community::safe_columns_tuple(),
+ community::all_columns,
community_aggregates::all_columns,
community_follower::all_columns.nullable(),
community_block::all_columns.nullable(),
.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 {
- community: a.0,
- counts: a.1,
- subscribed: CommunityFollower::to_subscribed_type(&a.2),
- blocked: a.3.is_some(),
- })
- .collect::<Vec<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(),
+ }
}
}
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> {
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))
.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 {
- person: a.0,
- target: a.1,
- })
- .collect::<Vec<Self>>()
+impl JoinView for PersonBlockView {
+ type JoinTuple = PersonBlockViewTuple;
+ fn from_tuple(a: Self::JoinTuple) -> Self {
+ Self {
+ person: a.0,
+ target: a.1,
+ }
}
}
},
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,
};
type PersonMentionViewTuple = (
PersonMention,
Comment,
- PersonSafe,
+ Person,
Post,
- CommunitySafe,
- PersonSafe,
+ Community,
+ Person,
CommentAggregates,
Option<CommunityPersonBan>,
Option<CommunityFollower>,
.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(),
.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(),
.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 {
- person_mention: a.0,
- comment: a.1,
- creator: a.2,
- post: a.3,
- community: a.4,
- recipient: a.5,
- counts: a.6,
- creator_banned_from_community: a.7.is_some(),
- subscribed: CommunityFollower::to_subscribed_type(&a.8),
- saved: a.9.is_some(),
- creator_blocked: a.10.is_some(),
- my_vote: a.11,
- })
- .collect::<Vec<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,
+ post: a.3,
+ community: a.4,
+ recipient: a.5,
+ counts: a.6,
+ creator_banned_from_community: a.7.is_some(),
+ subscribed: CommunityFollower::to_subscribed_type(&a.8),
+ saved: a.9.is_some(),
+ creator_blocked: a.10.is_some(),
+ my_vote: a.11,
+ }
}
}
-use crate::structs::PersonViewSafe;
+use crate::structs::PersonView;
use diesel::{
dsl::{now, IntervalDsl},
result::Error,
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
),
)
.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())
}
}
}
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 {
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 {
- person: a.0,
- counts: a.1,
- })
- .collect::<Vec<Self>>()
+impl JoinView for PersonView {
+ type JoinTuple = PersonViewTuple;
+ fn from_tuple(a: Self::JoinTuple) -> Self {
+ Self {
+ person: a.0,
+ counts: a.1,
+ }
}
}
source::{
comment::Comment,
comment_reply::CommentReply,
- community::CommunitySafe,
- person::PersonSafe,
+ community::Community,
+ person::Person,
person_mention::PersonMention,
post::Post,
},
#[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,
#[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
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
}
#[derive(Debug, Serialize, Deserialize, Clone)]
-pub struct PersonViewSafe {
- pub person: PersonSafe,
+pub struct PersonView {
+ pub person: Person,
pub counts: PersonAggregates,
}
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> {
.inner_join(post::table)
.select((
admin_purge_comment::all_columns,
- Person::safe_columns_tuple().nullable(),
+ person::all_columns.nullable(),
post::all_columns,
))
.into_boxed();
.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 {
- admin_purge_comment: a.0,
- admin: a.1,
- post: a.2,
- })
- .collect::<Vec<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,
+ }
}
}
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> {
.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();
.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 {
- admin_purge_community: a.0,
- admin: a.1,
- })
- .collect::<Vec<Self>>()
+impl JoinView for AdminPurgeCommunityView {
+ type JoinTuple = AdminPurgeCommunityViewTuple;
+ fn from_tuple(a: Self::JoinTuple) -> Self {
+ Self {
+ admin_purge_community: a.0,
+ admin: a.1,
+ }
}
}
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> {
.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();
.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 {
- admin_purge_person: a.0,
- admin: a.1,
- })
- .collect::<Vec<Self>>()
+impl JoinView for AdminPurgePersonView {
+ type JoinTuple = AdminPurgePersonViewTuple;
+ fn from_tuple(a: Self::JoinTuple) -> Self {
+ Self {
+ admin_purge_person: a.0,
+ admin: a.1,
+ }
}
}
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> {
.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();
.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 {
- admin_purge_post: a.0,
- admin: a.1,
- community: a.2,
- })
- .collect::<Vec<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,
+ }
}
}
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> {
)
.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();
.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 {
- mod_add_community: a.0,
- moderator: a.1,
- community: a.2,
- modded_person: a.3,
- })
- .collect::<Vec<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,
+ }
}
}
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> {
.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();
.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 {
- mod_add: a.0,
- moderator: a.1,
- modded_person: a.2,
- })
- .collect::<Vec<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,
+ }
}
}
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> {
)
.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();
.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 {
- mod_ban_from_community: a.0,
- moderator: a.1,
- community: a.2,
- banned_person: a.3,
- })
- .collect::<Vec<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,
+ }
}
}
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> {
.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();
.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 {
- mod_ban: a.0,
- moderator: a.1,
- banned_person: a.2,
- })
- .collect::<Vec<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,
+ }
}
}
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> {
.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();
.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 {
- mod_feature_post: a.0,
- moderator: a.1,
- post: a.2,
- community: a.3,
- })
- .collect::<Vec<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,
+ }
}
}
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
.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();
.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 {
- mod_hide_community: a.0,
- admin: a.1,
- community: a.2,
- })
- .collect::<Vec<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,
+ }
}
}
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> {
.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();
.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 {
- mod_lock_post: a.0,
- moderator: a.1,
- post: a.2,
- community: a.3,
- })
- .collect::<Vec<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,
+ }
}
}
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 {
.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();
.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 {
- mod_remove_comment: a.0,
- moderator: a.1,
- comment: a.2,
- commenter: a.3,
- post: a.4,
- community: a.5,
- })
- .collect::<Vec<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,
+ }
}
}
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> {
.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();
.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 {
- mod_remove_community: a.0,
- moderator: a.1,
- community: a.2,
- })
- .collect::<Vec<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,
+ }
}
}
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> {
.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();
.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 {
- mod_remove_post: a.0,
- moderator: a.1,
- post: a.2,
- community: a.3,
- })
- .collect::<Vec<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,
+ }
}
}
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> {
)
.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();
.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 {
- mod_transfer_community: a.0,
- moderator: a.1,
- community: a.2,
- modded_person: a.3,
- })
- .collect::<Vec<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,
+ }
}
}
newtypes::{CommunityId, PersonId},
source::{
comment::Comment,
- community::CommunitySafe,
+ community::Community,
moderator::{
AdminPurgeComment,
AdminPurgeCommunity,
ModRemovePost,
ModTransferCommunity,
},
- person::PersonSafe,
+ person::Person,
post::Post,
},
};
#[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)]