mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-23 04:41:19 +00:00
parent
acc9ca1aed
commit
443a2a00a5
82 changed files with 711 additions and 1070 deletions
|
@ -28,7 +28,7 @@ impl LemmyContext {
|
||||||
rate_limit_cell,
|
rate_limit_cell,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn pool(&self) -> impl GetConn {
|
pub fn pool(&self) -> &DbPool {
|
||||||
&self.pool
|
&self.pool
|
||||||
}
|
}
|
||||||
pub fn client(&self) -> &ClientWithMiddleware {
|
pub fn client(&self) -> &ClientWithMiddleware {
|
||||||
|
|
|
@ -24,7 +24,7 @@ use lemmy_db_schema::{
|
||||||
registration_application::RegistrationApplication,
|
registration_application::RegistrationApplication,
|
||||||
},
|
},
|
||||||
traits::{Crud, Readable},
|
traits::{Crud, Readable},
|
||||||
utils::{DbPool, GetConn},
|
utils::DbPool,
|
||||||
RegistrationMode,
|
RegistrationMode,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::{comment_view::CommentQuery, structs::LocalUserView};
|
use lemmy_db_views::{comment_view::CommentQuery, structs::LocalUserView};
|
||||||
|
@ -50,7 +50,7 @@ use url::{ParseError, Url};
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn is_mod_or_admin(
|
pub async fn is_mod_or_admin(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
@ -63,7 +63,7 @@ pub async fn is_mod_or_admin(
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn is_mod_or_admin_opt(
|
pub async fn is_mod_or_admin_opt(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
local_user_view: Option<&LocalUserView>,
|
local_user_view: Option<&LocalUserView>,
|
||||||
community_id: Option<CommunityId>,
|
community_id: Option<CommunityId>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
@ -101,7 +101,7 @@ pub fn is_top_mod(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn get_post(post_id: PostId, mut pool: &mut impl GetConn) -> Result<Post, LemmyError> {
|
pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError> {
|
||||||
Post::read(pool, post_id)
|
Post::read(pool, post_id)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))
|
||||||
|
@ -111,7 +111,7 @@ pub async fn get_post(post_id: PostId, mut pool: &mut impl GetConn) -> Result<Po
|
||||||
pub async fn mark_post_as_read(
|
pub async fn mark_post_as_read(
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
post_id: PostId,
|
post_id: PostId,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
) -> Result<PostRead, LemmyError> {
|
) -> Result<PostRead, LemmyError> {
|
||||||
let post_read_form = PostReadForm { post_id, person_id };
|
let post_read_form = PostReadForm { post_id, person_id };
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ pub async fn mark_post_as_read(
|
||||||
pub async fn mark_post_as_unread(
|
pub async fn mark_post_as_unread(
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
post_id: PostId,
|
post_id: PostId,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
) -> Result<usize, LemmyError> {
|
) -> Result<usize, LemmyError> {
|
||||||
let post_read_form = PostReadForm { post_id, person_id };
|
let post_read_form = PostReadForm { post_id, person_id };
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ pub fn check_user_valid(
|
||||||
pub async fn check_community_ban(
|
pub async fn check_community_ban(
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let is_banned = CommunityPersonBanView::get(pool, person_id, community_id)
|
let is_banned = CommunityPersonBanView::get(pool, person_id, community_id)
|
||||||
.await
|
.await
|
||||||
|
@ -212,7 +212,7 @@ pub async fn check_community_ban(
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn check_community_deleted_or_removed(
|
pub async fn check_community_deleted_or_removed(
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let community = Community::read(pool, community_id)
|
let community = Community::read(pool, community_id)
|
||||||
.await
|
.await
|
||||||
|
@ -236,7 +236,7 @@ pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> {
|
||||||
pub async fn check_person_block(
|
pub async fn check_person_block(
|
||||||
my_id: PersonId,
|
my_id: PersonId,
|
||||||
potential_blocker_id: PersonId,
|
potential_blocker_id: PersonId,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let is_blocked = PersonBlock::read(pool, potential_blocker_id, my_id)
|
let is_blocked = PersonBlock::read(pool, potential_blocker_id, my_id)
|
||||||
.await
|
.await
|
||||||
|
@ -270,7 +270,7 @@ pub fn check_private_instance(
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
pub async fn build_federated_instances(
|
pub async fn build_federated_instances(
|
||||||
local_site: &LocalSite,
|
local_site: &LocalSite,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
) -> Result<Option<FederatedInstances>, LemmyError> {
|
) -> Result<Option<FederatedInstances>, LemmyError> {
|
||||||
if local_site.federation_enabled {
|
if local_site.federation_enabled {
|
||||||
// TODO I hate that this requires 3 queries
|
// TODO I hate that this requires 3 queries
|
||||||
|
@ -334,7 +334,7 @@ pub fn send_email_to_user(
|
||||||
|
|
||||||
pub async fn send_password_reset_email(
|
pub async fn send_password_reset_email(
|
||||||
user: &LocalUserView,
|
user: &LocalUserView,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
// Generate a random token
|
// Generate a random token
|
||||||
|
@ -358,7 +358,7 @@ pub async fn send_password_reset_email(
|
||||||
pub async fn send_verification_email(
|
pub async fn send_verification_email(
|
||||||
user: &LocalUserView,
|
user: &LocalUserView,
|
||||||
new_email: &str,
|
new_email: &str,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let form = EmailVerificationForm {
|
let form = EmailVerificationForm {
|
||||||
|
@ -449,7 +449,7 @@ pub fn send_application_approved_email(
|
||||||
/// Send a new applicant email notification to all admins
|
/// Send a new applicant email notification to all admins
|
||||||
pub async fn send_new_applicant_email_to_admins(
|
pub async fn send_new_applicant_email_to_admins(
|
||||||
applicant_username: &str,
|
applicant_username: &str,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
// Collect the admins with emails
|
// Collect the admins with emails
|
||||||
|
@ -474,7 +474,7 @@ pub async fn send_new_applicant_email_to_admins(
|
||||||
pub async fn send_new_report_email_to_admins(
|
pub async fn send_new_report_email_to_admins(
|
||||||
reporter_username: &str,
|
reporter_username: &str,
|
||||||
reported_username: &str,
|
reported_username: &str,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
// Collect the admins with emails
|
// Collect the admins with emails
|
||||||
|
@ -495,7 +495,7 @@ pub async fn send_new_report_email_to_admins(
|
||||||
pub async fn check_registration_application(
|
pub async fn check_registration_application(
|
||||||
local_user_view: &LocalUserView,
|
local_user_view: &LocalUserView,
|
||||||
local_site: &LocalSite,
|
local_site: &LocalSite,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
if (local_site.registration_mode == RegistrationMode::RequireApplication
|
if (local_site.registration_mode == RegistrationMode::RequireApplication
|
||||||
|| local_site.registration_mode == RegistrationMode::Closed)
|
|| local_site.registration_mode == RegistrationMode::Closed)
|
||||||
|
@ -529,7 +529,7 @@ pub fn check_private_instance_and_federation_enabled(
|
||||||
|
|
||||||
pub async fn purge_image_posts_for_person(
|
pub async fn purge_image_posts_for_person(
|
||||||
banned_person_id: PersonId,
|
banned_person_id: PersonId,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
client: &ClientWithMiddleware,
|
client: &ClientWithMiddleware,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
@ -552,7 +552,7 @@ pub async fn purge_image_posts_for_person(
|
||||||
|
|
||||||
pub async fn purge_image_posts_for_community(
|
pub async fn purge_image_posts_for_community(
|
||||||
banned_community_id: CommunityId,
|
banned_community_id: CommunityId,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
client: &ClientWithMiddleware,
|
client: &ClientWithMiddleware,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
@ -575,7 +575,7 @@ pub async fn purge_image_posts_for_community(
|
||||||
|
|
||||||
pub async fn remove_user_data(
|
pub async fn remove_user_data(
|
||||||
banned_person_id: PersonId,
|
banned_person_id: PersonId,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
client: &ClientWithMiddleware,
|
client: &ClientWithMiddleware,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
@ -659,7 +659,7 @@ pub async fn remove_user_data(
|
||||||
pub async fn remove_user_data_in_community(
|
pub async fn remove_user_data_in_community(
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
banned_person_id: PersonId,
|
banned_person_id: PersonId,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
// Posts
|
// Posts
|
||||||
Post::update_removed_for_creator(pool, banned_person_id, Some(community_id), true).await?;
|
Post::update_removed_for_creator(pool, banned_person_id, Some(community_id), true).await?;
|
||||||
|
@ -689,7 +689,7 @@ pub async fn remove_user_data_in_community(
|
||||||
|
|
||||||
pub async fn delete_user_account(
|
pub async fn delete_user_account(
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
client: &ClientWithMiddleware,
|
client: &ClientWithMiddleware,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
|
|
|
@ -21,7 +21,7 @@ use lemmy_api_common::{
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{community::Community, person::Person, site::Site},
|
source::{community::Community, person::Person, site::Site},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{DbPool, GetConn},
|
utils::DbPool,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::SiteView;
|
use lemmy_db_views::structs::SiteView;
|
||||||
use lemmy_utils::{error::LemmyError, utils::time::naive_from_unix};
|
use lemmy_utils::{error::LemmyError, utils::time::naive_from_unix};
|
||||||
|
@ -118,10 +118,7 @@ impl SiteOrCommunity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn generate_cc(
|
async fn generate_cc(target: &SiteOrCommunity, pool: &DbPool) -> Result<Vec<Url>, LemmyError> {
|
||||||
target: &SiteOrCommunity,
|
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
) -> Result<Vec<Url>, LemmyError> {
|
|
||||||
Ok(match target {
|
Ok(match target {
|
||||||
SiteOrCommunity::Site(_) => Site::read_remote_sites(pool)
|
SiteOrCommunity::Site(_) => Site::read_remote_sites(pool)
|
||||||
.await?
|
.await?
|
||||||
|
|
|
@ -33,7 +33,7 @@ pub async fn resolve_object(
|
||||||
async fn convert_response(
|
async fn convert_response(
|
||||||
object: SearchableObjects,
|
object: SearchableObjects,
|
||||||
user_id: PersonId,
|
user_id: PersonId,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
) -> Result<Json<ResolveObjectResponse>, LemmyError> {
|
) -> Result<Json<ResolveObjectResponse>, LemmyError> {
|
||||||
use SearchableObjects::*;
|
use SearchableObjects::*;
|
||||||
let removed_or_deleted;
|
let removed_or_deleted;
|
||||||
|
|
|
@ -9,7 +9,7 @@ use lemmy_db_schema::{
|
||||||
local_site::LocalSite,
|
local_site::LocalSite,
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{DbPool, GetConn},
|
utils::DbPool,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, settings::structs::Settings};
|
use lemmy_utils::{error::LemmyError, settings::structs::Settings};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
@ -98,7 +98,7 @@ pub(crate) struct LocalSiteData {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn fetch_local_site_data(
|
pub(crate) async fn fetch_local_site_data(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
) -> Result<LocalSiteData, diesel::result::Error> {
|
) -> Result<LocalSiteData, diesel::result::Error> {
|
||||||
// LocalSite may be missing
|
// LocalSite may be missing
|
||||||
let local_site = LocalSite::read(pool).await.ok();
|
let local_site = LocalSite::read(pool).await.ok();
|
||||||
|
|
|
@ -9,7 +9,7 @@ use lemmy_api_common::context::LemmyContext;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{comment::Comment, person::Person, post::Post},
|
source::{comment::Comment, person::Person, post::Post},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{DbPool, GetConn},
|
utils::DbPool,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, utils::mention::scrape_text_for_mentions};
|
use lemmy_utils::{error::LemmyError, utils::mention::scrape_text_for_mentions};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -92,7 +92,7 @@ pub async fn collect_non_local_mentions(
|
||||||
/// top-level comment, the creator of the post, otherwise the creator of the parent comment.
|
/// top-level comment, the creator of the post, otherwise the creator of the parent comment.
|
||||||
#[tracing::instrument(skip(pool, comment))]
|
#[tracing::instrument(skip(pool, comment))]
|
||||||
async fn get_comment_parent_creator(
|
async fn get_comment_parent_creator(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
comment: &Comment,
|
comment: &Comment,
|
||||||
) -> Result<ApubPerson, LemmyError> {
|
) -> Result<ApubPerson, LemmyError> {
|
||||||
let parent_creator_id = if let Some(parent_comment_id) = comment.parent_comment_id() {
|
let parent_creator_id = if let Some(parent_comment_id) = comment.parent_comment_id() {
|
||||||
|
|
|
@ -195,9 +195,7 @@ pub(in crate::objects) async fn fetch_instance_actor_for_object<T: Into<Url> + C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn remote_instance_inboxes(
|
pub(crate) async fn remote_instance_inboxes(pool: &DbPool) -> Result<Vec<Url>, LemmyError> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
) -> Result<Vec<Url>, LemmyError> {
|
|
||||||
Ok(
|
Ok(
|
||||||
Site::read_remote_sites(pool)
|
Site::read_remote_sites(pool)
|
||||||
.await?
|
.await?
|
||||||
|
|
|
@ -2,7 +2,7 @@ use lemmy_db_schema::{
|
||||||
impls::actor_language::UNDETERMINED_ID,
|
impls::actor_language::UNDETERMINED_ID,
|
||||||
newtypes::LanguageId,
|
newtypes::LanguageId,
|
||||||
source::language::Language,
|
source::language::Language,
|
||||||
utils::{DbPool, GetConn},
|
utils::DbPool,
|
||||||
};
|
};
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -33,7 +33,7 @@ pub(crate) struct LanguageTag {
|
||||||
impl LanguageTag {
|
impl LanguageTag {
|
||||||
pub(crate) async fn new_single(
|
pub(crate) async fn new_single(
|
||||||
lang: LanguageId,
|
lang: LanguageId,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
) -> Result<Option<LanguageTag>, LemmyError> {
|
) -> Result<Option<LanguageTag>, LemmyError> {
|
||||||
let lang = Language::read_from_id(pool, lang).await?;
|
let lang = Language::read_from_id(pool, lang).await?;
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ impl LanguageTag {
|
||||||
|
|
||||||
pub(crate) async fn new_multiple(
|
pub(crate) async fn new_multiple(
|
||||||
lang_ids: Vec<LanguageId>,
|
lang_ids: Vec<LanguageId>,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
) -> Result<Vec<LanguageTag>, LemmyError> {
|
) -> Result<Vec<LanguageTag>, LemmyError> {
|
||||||
let mut langs = Vec::<Language>::new();
|
let mut langs = Vec::<Language>::new();
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ impl LanguageTag {
|
||||||
|
|
||||||
pub(crate) async fn to_language_id_single(
|
pub(crate) async fn to_language_id_single(
|
||||||
lang: Option<Self>,
|
lang: Option<Self>,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
) -> Result<Option<LanguageId>, LemmyError> {
|
) -> Result<Option<LanguageId>, LemmyError> {
|
||||||
let identifier = lang.map(|l| l.identifier);
|
let identifier = lang.map(|l| l.identifier);
|
||||||
let language = Language::read_id_from_code(pool, identifier.as_deref()).await?;
|
let language = Language::read_id_from_code(pool, identifier.as_deref()).await?;
|
||||||
|
@ -80,7 +80,7 @@ impl LanguageTag {
|
||||||
|
|
||||||
pub(crate) async fn to_language_id_multiple(
|
pub(crate) async fn to_language_id_multiple(
|
||||||
langs: Vec<Self>,
|
langs: Vec<Self>,
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
) -> Result<Vec<LanguageId>, LemmyError> {
|
) -> Result<Vec<LanguageId>, LemmyError> {
|
||||||
let mut language_ids = Vec::new();
|
let mut language_ids = Vec::new();
|
||||||
|
|
||||||
|
|
|
@ -2,25 +2,22 @@ use crate::{
|
||||||
aggregates::structs::CommentAggregates,
|
aggregates::structs::CommentAggregates,
|
||||||
newtypes::CommentId,
|
newtypes::CommentId,
|
||||||
schema::comment_aggregates,
|
schema::comment_aggregates,
|
||||||
utils::{functions::hot_rank, DbPool, GetConn},
|
utils::{functions::hot_rank, get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
impl CommentAggregates {
|
impl CommentAggregates {
|
||||||
pub async fn read(mut pool: &mut impl GetConn, comment_id: CommentId) -> Result<Self, Error> {
|
pub async fn read(pool: &DbPool, comment_id: CommentId) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
comment_aggregates::table
|
comment_aggregates::table
|
||||||
.filter(comment_aggregates::comment_id.eq(comment_id))
|
.filter(comment_aggregates::comment_id.eq(comment_id))
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_hot_rank(
|
pub async fn update_hot_rank(pool: &DbPool, comment_id: CommentId) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
comment_id: CommentId,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
|
|
||||||
diesel::update(comment_aggregates::table)
|
diesel::update(comment_aggregates::table)
|
||||||
.filter(comment_aggregates::comment_id.eq(comment_id))
|
.filter(comment_aggregates::comment_id.eq(comment_id))
|
||||||
|
|
|
@ -2,14 +2,14 @@ use crate::{
|
||||||
aggregates::structs::CommunityAggregates,
|
aggregates::structs::CommunityAggregates,
|
||||||
newtypes::CommunityId,
|
newtypes::CommunityId,
|
||||||
schema::community_aggregates,
|
schema::community_aggregates,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
impl CommunityAggregates {
|
impl CommunityAggregates {
|
||||||
pub async fn read(mut pool: &mut impl GetConn, community_id: CommunityId) -> Result<Self, Error> {
|
pub async fn read(pool: &DbPool, community_id: CommunityId) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
community_aggregates::table
|
community_aggregates::table
|
||||||
.filter(community_aggregates::community_id.eq(community_id))
|
.filter(community_aggregates::community_id.eq(community_id))
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
|
|
|
@ -2,14 +2,14 @@ use crate::{
|
||||||
aggregates::structs::PersonAggregates,
|
aggregates::structs::PersonAggregates,
|
||||||
newtypes::PersonId,
|
newtypes::PersonId,
|
||||||
schema::person_aggregates,
|
schema::person_aggregates,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
impl PersonAggregates {
|
impl PersonAggregates {
|
||||||
pub async fn read(mut pool: &mut impl GetConn, person_id: PersonId) -> Result<Self, Error> {
|
pub async fn read(pool: &DbPool, person_id: PersonId) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_aggregates::table
|
person_aggregates::table
|
||||||
.filter(person_aggregates::person_id.eq(person_id))
|
.filter(person_aggregates::person_id.eq(person_id))
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
|
|
|
@ -3,17 +3,14 @@ use crate::{
|
||||||
diesel::BoolExpressionMethods,
|
diesel::BoolExpressionMethods,
|
||||||
newtypes::{PersonId, PostId},
|
newtypes::{PersonId, PostId},
|
||||||
schema::person_post_aggregates::dsl::{person_id, person_post_aggregates, post_id},
|
schema::person_post_aggregates::dsl::{person_id, person_post_aggregates, post_id},
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
impl PersonPostAggregates {
|
impl PersonPostAggregates {
|
||||||
pub async fn upsert(
|
pub async fn upsert(pool: &DbPool, form: &PersonPostAggregatesForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
form: &PersonPostAggregatesForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
insert_into(person_post_aggregates)
|
insert_into(person_post_aggregates)
|
||||||
.values(form)
|
.values(form)
|
||||||
.on_conflict((person_id, post_id))
|
.on_conflict((person_id, post_id))
|
||||||
|
@ -22,12 +19,8 @@ impl PersonPostAggregates {
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn read(
|
pub async fn read(pool: &DbPool, person_id_: PersonId, post_id_: PostId) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_id_: PersonId,
|
|
||||||
post_id_: PostId,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
person_post_aggregates
|
person_post_aggregates
|
||||||
.filter(post_id.eq(post_id_).and(person_id.eq(person_id_)))
|
.filter(post_id.eq(post_id_).and(person_id.eq(person_id_)))
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
|
|
|
@ -2,25 +2,22 @@ use crate::{
|
||||||
aggregates::structs::PostAggregates,
|
aggregates::structs::PostAggregates,
|
||||||
newtypes::PostId,
|
newtypes::PostId,
|
||||||
schema::post_aggregates,
|
schema::post_aggregates,
|
||||||
utils::{functions::hot_rank, DbPool, GetConn},
|
utils::{functions::hot_rank, get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
impl PostAggregates {
|
impl PostAggregates {
|
||||||
pub async fn read(mut pool: &mut impl GetConn, post_id: PostId) -> Result<Self, Error> {
|
pub async fn read(pool: &DbPool, post_id: PostId) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
post_aggregates::table
|
post_aggregates::table
|
||||||
.filter(post_aggregates::post_id.eq(post_id))
|
.filter(post_aggregates::post_id.eq(post_id))
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_hot_rank(
|
pub async fn update_hot_rank(pool: &DbPool, post_id: PostId) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
post_id: PostId,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
|
|
||||||
diesel::update(post_aggregates::table)
|
diesel::update(post_aggregates::table)
|
||||||
.filter(post_aggregates::post_id.eq(post_id))
|
.filter(post_aggregates::post_id.eq(post_id))
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
aggregates::structs::SiteAggregates,
|
aggregates::structs::SiteAggregates,
|
||||||
schema::site_aggregates,
|
schema::site_aggregates,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::result::Error;
|
use diesel::result::Error;
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
impl SiteAggregates {
|
impl SiteAggregates {
|
||||||
pub async fn read(mut pool: &mut impl GetConn) -> Result<Self, Error> {
|
pub async fn read(pool: &DbPool) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
site_aggregates::table.first::<Self>(conn).await
|
site_aggregates::table.first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
schema::activity::dsl::{activity, ap_id},
|
schema::activity::dsl::{activity, ap_id},
|
||||||
source::activity::{Activity, ActivityInsertForm, ActivityUpdateForm},
|
source::activity::{Activity, ActivityInsertForm, ActivityUpdateForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
@ -13,16 +13,13 @@ impl Crud for Activity {
|
||||||
type InsertForm = ActivityInsertForm;
|
type InsertForm = ActivityInsertForm;
|
||||||
type UpdateForm = ActivityUpdateForm;
|
type UpdateForm = ActivityUpdateForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut pool: &mut impl GetConn, activity_id: i32) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, activity_id: i32) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
activity.find(activity_id).first::<Self>(conn).await
|
activity.find(activity_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(
|
async fn create(pool: &DbPool, new_activity: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
new_activity: &Self::InsertForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
insert_into(activity)
|
insert_into(activity)
|
||||||
.values(new_activity)
|
.values(new_activity)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -30,18 +27,18 @@ impl Crud for Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
activity_id: i32,
|
activity_id: i32,
|
||||||
new_activity: &Self::UpdateForm,
|
new_activity: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(activity.find(activity_id))
|
diesel::update(activity.find(activity_id))
|
||||||
.set(new_activity)
|
.set(new_activity)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn delete(mut pool: &mut impl GetConn, activity_id: i32) -> Result<usize, Error> {
|
async fn delete(pool: &DbPool, activity_id: i32) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(activity.find(activity_id))
|
diesel::delete(activity.find(activity_id))
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
|
@ -49,11 +46,8 @@ impl Crud for Activity {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Activity {
|
impl Activity {
|
||||||
pub async fn read_from_apub_id(
|
pub async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result<Activity, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
object_id: &DbUrl,
|
|
||||||
) -> Result<Activity, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
activity
|
activity
|
||||||
.filter(ap_id.eq(object_id))
|
.filter(ap_id.eq(object_id))
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
|
|
|
@ -14,7 +14,7 @@ use crate::{
|
||||||
language::Language,
|
language::Language,
|
||||||
site::Site,
|
site::Site,
|
||||||
},
|
},
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
delete,
|
delete,
|
||||||
|
@ -37,7 +37,7 @@ pub const UNDETERMINED_ID: LanguageId = LanguageId(0);
|
||||||
|
|
||||||
impl LocalUserLanguage {
|
impl LocalUserLanguage {
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_local_user_id: LocalUserId,
|
for_local_user_id: LocalUserId,
|
||||||
) -> Result<Vec<LanguageId>, Error> {
|
) -> Result<Vec<LanguageId>, Error> {
|
||||||
use crate::schema::local_user_language::dsl::{
|
use crate::schema::local_user_language::dsl::{
|
||||||
|
@ -45,7 +45,7 @@ impl LocalUserLanguage {
|
||||||
local_user_id,
|
local_user_id,
|
||||||
local_user_language,
|
local_user_language,
|
||||||
};
|
};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
conn
|
conn
|
||||||
.build_transaction()
|
.build_transaction()
|
||||||
|
@ -67,11 +67,11 @@ impl LocalUserLanguage {
|
||||||
///
|
///
|
||||||
/// If no language_id vector is given, it will show all languages
|
/// If no language_id vector is given, it will show all languages
|
||||||
pub async fn update(
|
pub async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
language_ids: Vec<LanguageId>,
|
language_ids: Vec<LanguageId>,
|
||||||
for_local_user_id: LocalUserId,
|
for_local_user_id: LocalUserId,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let mut lang_ids = convert_update_languages(conn, language_ids).await?;
|
let mut lang_ids = convert_update_languages(conn, language_ids).await?;
|
||||||
|
|
||||||
// No need to update if languages are unchanged
|
// No need to update if languages are unchanged
|
||||||
|
@ -118,8 +118,8 @@ impl LocalUserLanguage {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SiteLanguage {
|
impl SiteLanguage {
|
||||||
pub async fn read_local_raw(mut pool: &mut impl GetConn) -> Result<Vec<LanguageId>, Error> {
|
pub async fn read_local_raw(pool: &DbPool) -> Result<Vec<LanguageId>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
site::table
|
site::table
|
||||||
.inner_join(local_site::table)
|
.inner_join(local_site::table)
|
||||||
.inner_join(site_language::table)
|
.inner_join(site_language::table)
|
||||||
|
@ -130,7 +130,7 @@ impl SiteLanguage {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_raw(
|
async fn read_raw(
|
||||||
conn: &mut AsyncPgConnection,
|
conn: &mut PooledConnection<AsyncPgConnection>,
|
||||||
for_site_id: SiteId,
|
for_site_id: SiteId,
|
||||||
) -> Result<Vec<LanguageId>, Error> {
|
) -> Result<Vec<LanguageId>, Error> {
|
||||||
site_language::table
|
site_language::table
|
||||||
|
@ -141,22 +141,19 @@ impl SiteLanguage {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read(
|
pub async fn read(pool: &DbPool, for_site_id: SiteId) -> Result<Vec<LanguageId>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
for_site_id: SiteId,
|
|
||||||
) -> Result<Vec<LanguageId>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let langs = Self::read_raw(conn, for_site_id).await?;
|
let langs = Self::read_raw(conn, for_site_id).await?;
|
||||||
|
|
||||||
convert_read_languages(conn, langs).await
|
convert_read_languages(conn, langs).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update(
|
pub async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
language_ids: Vec<LanguageId>,
|
language_ids: Vec<LanguageId>,
|
||||||
site: &Site,
|
site: &Site,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let for_site_id = site.id;
|
let for_site_id = site.id;
|
||||||
let instance_id = site.instance_id;
|
let instance_id = site.instance_id;
|
||||||
let lang_ids = convert_update_languages(conn, language_ids).await?;
|
let lang_ids = convert_update_languages(conn, language_ids).await?;
|
||||||
|
@ -201,12 +198,12 @@ impl SiteLanguage {
|
||||||
impl CommunityLanguage {
|
impl CommunityLanguage {
|
||||||
/// Returns true if the given language is one of configured languages for given community
|
/// Returns true if the given language is one of configured languages for given community
|
||||||
pub async fn is_allowed_community_language(
|
pub async fn is_allowed_community_language(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_language_id: Option<LanguageId>,
|
for_language_id: Option<LanguageId>,
|
||||||
for_community_id: CommunityId,
|
for_community_id: CommunityId,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
use crate::schema::community_language::dsl::{community_id, community_language, language_id};
|
use crate::schema::community_language::dsl::{community_id, community_language, language_id};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
if let Some(for_language_id) = for_language_id {
|
if let Some(for_language_id) = for_language_id {
|
||||||
let is_allowed = select(exists(
|
let is_allowed = select(exists(
|
||||||
|
@ -258,7 +255,7 @@ impl CommunityLanguage {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_raw(
|
async fn read_raw(
|
||||||
conn: &mut AsyncPgConnection,
|
conn: &mut PooledConnection<AsyncPgConnection>,
|
||||||
for_community_id: CommunityId,
|
for_community_id: CommunityId,
|
||||||
) -> Result<Vec<LanguageId>, Error> {
|
) -> Result<Vec<LanguageId>, Error> {
|
||||||
use crate::schema::community_language::dsl::{community_id, community_language, language_id};
|
use crate::schema::community_language::dsl::{community_id, community_language, language_id};
|
||||||
|
@ -271,20 +268,20 @@ impl CommunityLanguage {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_community_id: CommunityId,
|
for_community_id: CommunityId,
|
||||||
) -> Result<Vec<LanguageId>, Error> {
|
) -> Result<Vec<LanguageId>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let langs = Self::read_raw(conn, for_community_id).await?;
|
let langs = Self::read_raw(conn, for_community_id).await?;
|
||||||
convert_read_languages(conn, langs).await
|
convert_read_languages(conn, langs).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update(
|
pub async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
mut language_ids: Vec<LanguageId>,
|
mut language_ids: Vec<LanguageId>,
|
||||||
for_community_id: CommunityId,
|
for_community_id: CommunityId,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
if language_ids.is_empty() {
|
if language_ids.is_empty() {
|
||||||
language_ids = SiteLanguage::read_local_raw(pool).await?;
|
language_ids = SiteLanguage::read_local_raw(pool).await?;
|
||||||
}
|
}
|
||||||
|
@ -324,12 +321,12 @@ impl CommunityLanguage {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn default_post_language(
|
pub async fn default_post_language(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
local_user_id: LocalUserId,
|
local_user_id: LocalUserId,
|
||||||
) -> Result<Option<LanguageId>, Error> {
|
) -> Result<Option<LanguageId>, Error> {
|
||||||
use crate::schema::{community_language::dsl as cl, local_user_language::dsl as ul};
|
use crate::schema::{community_language::dsl as cl, local_user_language::dsl as ul};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let mut intersection = ul::local_user_language
|
let mut intersection = ul::local_user_language
|
||||||
.inner_join(cl::community_language.on(ul::language_id.eq(cl::language_id)))
|
.inner_join(cl::community_language.on(ul::language_id.eq(cl::language_id)))
|
||||||
.filter(ul::local_user_id.eq(local_user_id))
|
.filter(ul::local_user_id.eq(local_user_id))
|
||||||
|
@ -399,9 +396,9 @@ mod tests {
|
||||||
convert_read_languages,
|
convert_read_languages,
|
||||||
convert_update_languages,
|
convert_update_languages,
|
||||||
default_post_language,
|
default_post_language,
|
||||||
|
get_conn,
|
||||||
CommunityLanguage,
|
CommunityLanguage,
|
||||||
DbPool,
|
DbPool,
|
||||||
GetConn,
|
|
||||||
Language,
|
Language,
|
||||||
LanguageId,
|
LanguageId,
|
||||||
LocalUserLanguage,
|
LocalUserLanguage,
|
||||||
|
@ -422,7 +419,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
async fn test_langs1(mut pool: &mut impl GetConn) -> Vec<LanguageId> {
|
async fn test_langs1(pool: &DbPool) -> Vec<LanguageId> {
|
||||||
vec![
|
vec![
|
||||||
Language::read_id_from_code(pool, Some("en"))
|
Language::read_id_from_code(pool, Some("en"))
|
||||||
.await
|
.await
|
||||||
|
@ -438,7 +435,7 @@ mod tests {
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
async fn test_langs2(mut pool: &mut impl GetConn) -> Vec<LanguageId> {
|
async fn test_langs2(pool: &DbPool) -> Vec<LanguageId> {
|
||||||
vec![
|
vec![
|
||||||
Language::read_id_from_code(pool, Some("fi"))
|
Language::read_id_from_code(pool, Some("fi"))
|
||||||
.await
|
.await
|
||||||
|
@ -451,7 +448,7 @@ mod tests {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_test_site(mut pool: &mut impl GetConn) -> (Site, Instance) {
|
async fn create_test_site(pool: &DbPool) -> (Site, Instance) {
|
||||||
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
schema::captcha_answer::dsl::{answer, captcha_answer, uuid},
|
schema::captcha_answer::dsl::{answer, captcha_answer, uuid},
|
||||||
source::captcha_answer::{CaptchaAnswer, CaptchaAnswerForm, CheckCaptchaAnswer},
|
source::captcha_answer::{CaptchaAnswer, CaptchaAnswerForm, CheckCaptchaAnswer},
|
||||||
utils::{functions::lower, DbPool, GetConn},
|
utils::{functions::lower, get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
delete,
|
delete,
|
||||||
|
@ -15,11 +15,8 @@ use diesel::{
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
impl CaptchaAnswer {
|
impl CaptchaAnswer {
|
||||||
pub async fn insert(
|
pub async fn insert(pool: &DbPool, captcha: &CaptchaAnswerForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
captcha: &CaptchaAnswerForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
|
|
||||||
insert_into(captcha_answer)
|
insert_into(captcha_answer)
|
||||||
.values(captcha)
|
.values(captcha)
|
||||||
|
@ -27,11 +24,8 @@ impl CaptchaAnswer {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn check_captcha(
|
pub async fn check_captcha(pool: &DbPool, to_check: CheckCaptchaAnswer) -> Result<bool, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
to_check: CheckCaptchaAnswer,
|
|
||||||
) -> Result<bool, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
|
|
||||||
// fetch requested captcha
|
// fetch requested captcha
|
||||||
let captcha_exists = select(exists(
|
let captcha_exists = select(exists(
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::{
|
||||||
CommentUpdateForm,
|
CommentUpdateForm,
|
||||||
},
|
},
|
||||||
traits::{Crud, Likeable, Saveable},
|
traits::{Crud, Likeable, Saveable},
|
||||||
utils::{naive_now, DbPool, GetConn, DELETED_REPLACEMENT_TEXT},
|
utils::{get_conn, naive_now, DbPool, DELETED_REPLACEMENT_TEXT},
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
dsl::{insert_into, sql_query},
|
dsl::{insert_into, sql_query},
|
||||||
|
@ -25,10 +25,10 @@ use url::Url;
|
||||||
|
|
||||||
impl Comment {
|
impl Comment {
|
||||||
pub async fn permadelete_for_creator(
|
pub async fn permadelete_for_creator(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_creator_id: PersonId,
|
for_creator_id: PersonId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
|
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
|
||||||
.set((
|
.set((
|
||||||
|
@ -41,11 +41,11 @@ impl Comment {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_removed_for_creator(
|
pub async fn update_removed_for_creator(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_creator_id: PersonId,
|
for_creator_id: PersonId,
|
||||||
new_removed: bool,
|
new_removed: bool,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
|
diesel::update(comment.filter(creator_id.eq(for_creator_id)))
|
||||||
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
||||||
.get_results::<Self>(conn)
|
.get_results::<Self>(conn)
|
||||||
|
@ -53,11 +53,11 @@ impl Comment {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
comment_form: &CommentInsertForm,
|
comment_form: &CommentInsertForm,
|
||||||
parent_path: Option<&Ltree>,
|
parent_path: Option<&Ltree>,
|
||||||
) -> Result<Comment, Error> {
|
) -> Result<Comment, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
// Insert, to get the id
|
// Insert, to get the id
|
||||||
let inserted_comment = insert_into(comment)
|
let inserted_comment = insert_into(comment)
|
||||||
|
@ -123,11 +123,8 @@ where ca.comment_id = c.id"
|
||||||
inserted_comment
|
inserted_comment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub async fn read_from_apub_id(
|
pub async fn read_from_apub_id(pool: &DbPool, object_id: Url) -> Result<Option<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
object_id: Url,
|
|
||||||
) -> Result<Option<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let object_id: DbUrl = object_id.into();
|
let object_id: DbUrl = object_id.into();
|
||||||
Ok(
|
Ok(
|
||||||
comment
|
comment
|
||||||
|
@ -156,30 +153,27 @@ impl Crud for Comment {
|
||||||
type InsertForm = CommentInsertForm;
|
type InsertForm = CommentInsertForm;
|
||||||
type UpdateForm = CommentUpdateForm;
|
type UpdateForm = CommentUpdateForm;
|
||||||
type IdType = CommentId;
|
type IdType = CommentId;
|
||||||
async fn read(mut pool: &mut impl GetConn, comment_id: CommentId) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, comment_id: CommentId) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
comment.find(comment_id).first::<Self>(conn).await
|
comment.find(comment_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(mut pool: &mut impl GetConn, comment_id: CommentId) -> Result<usize, Error> {
|
async fn delete(pool: &DbPool, comment_id: CommentId) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(comment.find(comment_id)).execute(conn).await
|
diesel::delete(comment.find(comment_id)).execute(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is unimplemented, use [[Comment::create]]
|
/// This is unimplemented, use [[Comment::create]]
|
||||||
async fn create(
|
async fn create(_pool: &DbPool, _comment_form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
_pool: &mut impl GetConn,
|
|
||||||
_comment_form: &Self::InsertForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
comment_id: CommentId,
|
comment_id: CommentId,
|
||||||
comment_form: &Self::UpdateForm,
|
comment_form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(comment.find(comment_id))
|
diesel::update(comment.find(comment_id))
|
||||||
.set(comment_form)
|
.set(comment_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -191,12 +185,9 @@ impl Crud for Comment {
|
||||||
impl Likeable for CommentLike {
|
impl Likeable for CommentLike {
|
||||||
type Form = CommentLikeForm;
|
type Form = CommentLikeForm;
|
||||||
type IdType = CommentId;
|
type IdType = CommentId;
|
||||||
async fn like(
|
async fn like(pool: &DbPool, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
comment_like_form: &CommentLikeForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::comment_like::dsl::{comment_id, comment_like, person_id};
|
use crate::schema::comment_like::dsl::{comment_id, comment_like, person_id};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(comment_like)
|
insert_into(comment_like)
|
||||||
.values(comment_like_form)
|
.values(comment_like_form)
|
||||||
.on_conflict((comment_id, person_id))
|
.on_conflict((comment_id, person_id))
|
||||||
|
@ -206,12 +197,12 @@ impl Likeable for CommentLike {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn remove(
|
async fn remove(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
person_id_: PersonId,
|
person_id_: PersonId,
|
||||||
comment_id_: CommentId,
|
comment_id_: CommentId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
use crate::schema::comment_like::dsl::{comment_id, comment_like, person_id};
|
use crate::schema::comment_like::dsl::{comment_id, comment_like, person_id};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
comment_like
|
comment_like
|
||||||
.filter(comment_id.eq(comment_id_))
|
.filter(comment_id.eq(comment_id_))
|
||||||
|
@ -225,12 +216,9 @@ impl Likeable for CommentLike {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Saveable for CommentSaved {
|
impl Saveable for CommentSaved {
|
||||||
type Form = CommentSavedForm;
|
type Form = CommentSavedForm;
|
||||||
async fn save(
|
async fn save(pool: &DbPool, comment_saved_form: &CommentSavedForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
comment_saved_form: &CommentSavedForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::comment_saved::dsl::{comment_id, comment_saved, person_id};
|
use crate::schema::comment_saved::dsl::{comment_id, comment_saved, person_id};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(comment_saved)
|
insert_into(comment_saved)
|
||||||
.values(comment_saved_form)
|
.values(comment_saved_form)
|
||||||
.on_conflict((comment_id, person_id))
|
.on_conflict((comment_id, person_id))
|
||||||
|
@ -239,12 +227,9 @@ impl Saveable for CommentSaved {
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn unsave(
|
async fn unsave(pool: &DbPool, comment_saved_form: &CommentSavedForm) -> Result<usize, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
comment_saved_form: &CommentSavedForm,
|
|
||||||
) -> Result<usize, Error> {
|
|
||||||
use crate::schema::comment_saved::dsl::{comment_id, comment_saved, person_id};
|
use crate::schema::comment_saved::dsl::{comment_id, comment_saved, person_id};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
comment_saved
|
comment_saved
|
||||||
.filter(comment_id.eq(comment_saved_form.comment_id))
|
.filter(comment_id.eq(comment_saved_form.comment_id))
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
schema::comment_reply::dsl::{comment_id, comment_reply, read, recipient_id},
|
schema::comment_reply::dsl::{comment_id, comment_reply, read, recipient_id},
|
||||||
source::comment_reply::{CommentReply, CommentReplyInsertForm, CommentReplyUpdateForm},
|
source::comment_reply::{CommentReply, CommentReplyInsertForm, CommentReplyUpdateForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
@ -13,22 +13,16 @@ impl Crud for CommentReply {
|
||||||
type InsertForm = CommentReplyInsertForm;
|
type InsertForm = CommentReplyInsertForm;
|
||||||
type UpdateForm = CommentReplyUpdateForm;
|
type UpdateForm = CommentReplyUpdateForm;
|
||||||
type IdType = CommentReplyId;
|
type IdType = CommentReplyId;
|
||||||
async fn read(
|
async fn read(pool: &DbPool, comment_reply_id: CommentReplyId) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
comment_reply_id: CommentReplyId,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
comment_reply
|
comment_reply
|
||||||
.find(comment_reply_id)
|
.find(comment_reply_id)
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(
|
async fn create(pool: &DbPool, comment_reply_form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
comment_reply_form: &Self::InsertForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
|
|
||||||
// since the return here isnt utilized, we dont need to do an update
|
// since the return here isnt utilized, we dont need to do an update
|
||||||
// but get_result doesnt return the existing row here
|
// but get_result doesnt return the existing row here
|
||||||
|
@ -42,11 +36,11 @@ impl Crud for CommentReply {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
comment_reply_id: CommentReplyId,
|
comment_reply_id: CommentReplyId,
|
||||||
comment_reply_form: &Self::UpdateForm,
|
comment_reply_form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(comment_reply.find(comment_reply_id))
|
diesel::update(comment_reply.find(comment_reply_id))
|
||||||
.set(comment_reply_form)
|
.set(comment_reply_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -56,10 +50,10 @@ impl Crud for CommentReply {
|
||||||
|
|
||||||
impl CommentReply {
|
impl CommentReply {
|
||||||
pub async fn mark_all_as_read(
|
pub async fn mark_all_as_read(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_recipient_id: PersonId,
|
for_recipient_id: PersonId,
|
||||||
) -> Result<Vec<CommentReply>, Error> {
|
) -> Result<Vec<CommentReply>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(
|
diesel::update(
|
||||||
comment_reply
|
comment_reply
|
||||||
.filter(recipient_id.eq(for_recipient_id))
|
.filter(recipient_id.eq(for_recipient_id))
|
||||||
|
@ -70,11 +64,8 @@ impl CommentReply {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_by_comment(
|
pub async fn read_by_comment(pool: &DbPool, for_comment_id: CommentId) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
for_comment_id: CommentId,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
comment_reply
|
comment_reply
|
||||||
.filter(comment_id.eq(for_comment_id))
|
.filter(comment_id.eq(for_comment_id))
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
schema::comment_report::dsl::{comment_report, resolved, resolver_id, updated},
|
schema::comment_report::dsl::{comment_report, resolved, resolver_id, updated},
|
||||||
source::comment_report::{CommentReport, CommentReportForm},
|
source::comment_report::{CommentReport, CommentReportForm},
|
||||||
traits::Reportable,
|
traits::Reportable,
|
||||||
utils::{naive_now, DbPool, GetConn},
|
utils::{get_conn, naive_now, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
dsl::{insert_into, update},
|
dsl::{insert_into, update},
|
||||||
|
@ -21,11 +21,8 @@ impl Reportable for CommentReport {
|
||||||
///
|
///
|
||||||
/// * `conn` - the postgres connection
|
/// * `conn` - the postgres connection
|
||||||
/// * `comment_report_form` - the filled CommentReportForm to insert
|
/// * `comment_report_form` - the filled CommentReportForm to insert
|
||||||
async fn report(
|
async fn report(pool: &DbPool, comment_report_form: &CommentReportForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
comment_report_form: &CommentReportForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
insert_into(comment_report)
|
insert_into(comment_report)
|
||||||
.values(comment_report_form)
|
.values(comment_report_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -38,11 +35,11 @@ impl Reportable for CommentReport {
|
||||||
/// * `report_id` - the id of the report to resolve
|
/// * `report_id` - the id of the report to resolve
|
||||||
/// * `by_resolver_id` - the id of the user resolving the report
|
/// * `by_resolver_id` - the id of the user resolving the report
|
||||||
async fn resolve(
|
async fn resolve(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
report_id_: Self::IdType,
|
report_id_: Self::IdType,
|
||||||
by_resolver_id: PersonId,
|
by_resolver_id: PersonId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
update(comment_report.find(report_id_))
|
update(comment_report.find(report_id_))
|
||||||
.set((
|
.set((
|
||||||
resolved.eq(true),
|
resolved.eq(true),
|
||||||
|
@ -59,11 +56,11 @@ impl Reportable for CommentReport {
|
||||||
/// * `report_id` - the id of the report to unresolve
|
/// * `report_id` - the id of the report to unresolve
|
||||||
/// * `by_resolver_id` - the id of the user unresolving the report
|
/// * `by_resolver_id` - the id of the user unresolving the report
|
||||||
async fn unresolve(
|
async fn unresolve(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
report_id_: Self::IdType,
|
report_id_: Self::IdType,
|
||||||
by_resolver_id: PersonId,
|
by_resolver_id: PersonId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
update(comment_report.find(report_id_))
|
update(comment_report.find(report_id_))
|
||||||
.set((
|
.set((
|
||||||
resolved.eq(false),
|
resolved.eq(false),
|
||||||
|
|
|
@ -16,7 +16,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
traits::{ApubActor, Bannable, Crud, Followable, Joinable},
|
traits::{ApubActor, Bannable, Crud, Followable, Joinable},
|
||||||
utils::{functions::lower, DbPool, GetConn},
|
utils::{functions::lower, get_conn, DbPool},
|
||||||
SubscribedType,
|
SubscribedType,
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
|
@ -27,23 +27,23 @@ impl Crud for Community {
|
||||||
type InsertForm = CommunityInsertForm;
|
type InsertForm = CommunityInsertForm;
|
||||||
type UpdateForm = CommunityUpdateForm;
|
type UpdateForm = CommunityUpdateForm;
|
||||||
type IdType = CommunityId;
|
type IdType = CommunityId;
|
||||||
async fn read(mut pool: &mut impl GetConn, community_id: CommunityId) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, community_id: CommunityId) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
community::table
|
community::table
|
||||||
.find(community_id)
|
.find(community_id)
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(mut pool: &mut impl GetConn, community_id: CommunityId) -> Result<usize, Error> {
|
async fn delete(pool: &DbPool, community_id: CommunityId) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(community::table.find(community_id))
|
diesel::delete(community::table.find(community_id))
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let is_new_community = match &form.actor_id {
|
let is_new_community = match &form.actor_id {
|
||||||
Some(id) => Community::read_from_apub_id(pool, id).await?.is_none(),
|
Some(id) => Community::read_from_apub_id(pool, id).await?.is_none(),
|
||||||
None => true,
|
None => true,
|
||||||
|
@ -67,11 +67,11 @@ impl Crud for Community {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
form: &Self::UpdateForm,
|
form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(community::table.find(community_id))
|
diesel::update(community::table.find(community_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -83,11 +83,11 @@ impl Crud for Community {
|
||||||
impl Joinable for CommunityModerator {
|
impl Joinable for CommunityModerator {
|
||||||
type Form = CommunityModeratorForm;
|
type Form = CommunityModeratorForm;
|
||||||
async fn join(
|
async fn join(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
community_moderator_form: &CommunityModeratorForm,
|
community_moderator_form: &CommunityModeratorForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::community_moderator::dsl::community_moderator;
|
use crate::schema::community_moderator::dsl::community_moderator;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(community_moderator)
|
insert_into(community_moderator)
|
||||||
.values(community_moderator_form)
|
.values(community_moderator_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -95,11 +95,11 @@ impl Joinable for CommunityModerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn leave(
|
async fn leave(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
community_moderator_form: &CommunityModeratorForm,
|
community_moderator_form: &CommunityModeratorForm,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id};
|
use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
community_moderator
|
community_moderator
|
||||||
.filter(community_id.eq(community_moderator_form.community_id))
|
.filter(community_id.eq(community_moderator_form.community_id))
|
||||||
|
@ -118,12 +118,12 @@ pub enum CollectionType {
|
||||||
impl Community {
|
impl Community {
|
||||||
/// Get the community which has a given moderators or featured url, also return the collection type
|
/// Get the community which has a given moderators or featured url, also return the collection type
|
||||||
pub async fn get_by_collection_url(
|
pub async fn get_by_collection_url(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
url: &DbUrl,
|
url: &DbUrl,
|
||||||
) -> Result<(Community, CollectionType), Error> {
|
) -> Result<(Community, CollectionType), Error> {
|
||||||
use crate::schema::community::dsl::{featured_url, moderators_url};
|
use crate::schema::community::dsl::{featured_url, moderators_url};
|
||||||
use CollectionType::*;
|
use CollectionType::*;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let res = community::table
|
let res = community::table
|
||||||
.filter(moderators_url.eq(url))
|
.filter(moderators_url.eq(url))
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
|
@ -144,11 +144,11 @@ impl Community {
|
||||||
|
|
||||||
impl CommunityModerator {
|
impl CommunityModerator {
|
||||||
pub async fn delete_for_community(
|
pub async fn delete_for_community(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_community_id: CommunityId,
|
for_community_id: CommunityId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
use crate::schema::community_moderator::dsl::{community_id, community_moderator};
|
use crate::schema::community_moderator::dsl::{community_id, community_moderator};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
diesel::delete(community_moderator.filter(community_id.eq(for_community_id)))
|
diesel::delete(community_moderator.filter(community_id.eq(for_community_id)))
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
|
@ -156,22 +156,22 @@ impl CommunityModerator {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn leave_all_communities(
|
pub async fn leave_all_communities(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_person_id: PersonId,
|
for_person_id: PersonId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
use crate::schema::community_moderator::dsl::{community_moderator, person_id};
|
use crate::schema::community_moderator::dsl::{community_moderator, person_id};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(community_moderator.filter(person_id.eq(for_person_id)))
|
diesel::delete(community_moderator.filter(person_id.eq(for_person_id)))
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_person_moderated_communities(
|
pub async fn get_person_moderated_communities(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_person_id: PersonId,
|
for_person_id: PersonId,
|
||||||
) -> Result<Vec<CommunityId>, Error> {
|
) -> Result<Vec<CommunityId>, Error> {
|
||||||
use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id};
|
use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
community_moderator
|
community_moderator
|
||||||
.filter(person_id.eq(for_person_id))
|
.filter(person_id.eq(for_person_id))
|
||||||
.select(community_id)
|
.select(community_id)
|
||||||
|
@ -184,11 +184,11 @@ impl CommunityModerator {
|
||||||
impl Bannable for CommunityPersonBan {
|
impl Bannable for CommunityPersonBan {
|
||||||
type Form = CommunityPersonBanForm;
|
type Form = CommunityPersonBanForm;
|
||||||
async fn ban(
|
async fn ban(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
community_person_ban_form: &CommunityPersonBanForm,
|
community_person_ban_form: &CommunityPersonBanForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id};
|
use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(community_person_ban)
|
insert_into(community_person_ban)
|
||||||
.values(community_person_ban_form)
|
.values(community_person_ban_form)
|
||||||
.on_conflict((community_id, person_id))
|
.on_conflict((community_id, person_id))
|
||||||
|
@ -199,11 +199,11 @@ impl Bannable for CommunityPersonBan {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn unban(
|
async fn unban(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
community_person_ban_form: &CommunityPersonBanForm,
|
community_person_ban_form: &CommunityPersonBanForm,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id};
|
use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
community_person_ban
|
community_person_ban
|
||||||
.filter(community_id.eq(community_person_ban_form.community_id))
|
.filter(community_id.eq(community_person_ban_form.community_id))
|
||||||
|
@ -233,12 +233,9 @@ impl CommunityFollower {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Followable for CommunityFollower {
|
impl Followable for CommunityFollower {
|
||||||
type Form = CommunityFollowerForm;
|
type Form = CommunityFollowerForm;
|
||||||
async fn follow(
|
async fn follow(pool: &DbPool, form: &CommunityFollowerForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
form: &CommunityFollowerForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::community_follower::dsl::{community_follower, community_id, person_id};
|
use crate::schema::community_follower::dsl::{community_follower, community_id, person_id};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(community_follower)
|
insert_into(community_follower)
|
||||||
.values(form)
|
.values(form)
|
||||||
.on_conflict((community_id, person_id))
|
.on_conflict((community_id, person_id))
|
||||||
|
@ -248,7 +245,7 @@ impl Followable for CommunityFollower {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn follow_accepted(
|
async fn follow_accepted(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
community_id_: CommunityId,
|
community_id_: CommunityId,
|
||||||
person_id_: PersonId,
|
person_id_: PersonId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
|
@ -258,7 +255,7 @@ impl Followable for CommunityFollower {
|
||||||
pending,
|
pending,
|
||||||
person_id,
|
person_id,
|
||||||
};
|
};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(
|
diesel::update(
|
||||||
community_follower
|
community_follower
|
||||||
.filter(community_id.eq(community_id_))
|
.filter(community_id.eq(community_id_))
|
||||||
|
@ -268,12 +265,9 @@ impl Followable for CommunityFollower {
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn unfollow(
|
async fn unfollow(pool: &DbPool, form: &CommunityFollowerForm) -> Result<usize, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
form: &CommunityFollowerForm,
|
|
||||||
) -> Result<usize, Error> {
|
|
||||||
use crate::schema::community_follower::dsl::{community_follower, community_id, person_id};
|
use crate::schema::community_follower::dsl::{community_follower, community_id, person_id};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
community_follower
|
community_follower
|
||||||
.filter(community_id.eq(&form.community_id))
|
.filter(community_id.eq(&form.community_id))
|
||||||
|
@ -286,11 +280,8 @@ impl Followable for CommunityFollower {
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ApubActor for Community {
|
impl ApubActor for Community {
|
||||||
async fn read_from_apub_id(
|
async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result<Option<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
object_id: &DbUrl,
|
|
||||||
) -> Result<Option<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
Ok(
|
Ok(
|
||||||
community::table
|
community::table
|
||||||
.filter(community::actor_id.eq(object_id))
|
.filter(community::actor_id.eq(object_id))
|
||||||
|
@ -302,11 +293,11 @@ impl ApubActor for Community {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_from_name(
|
async fn read_from_name(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
community_name: &str,
|
community_name: &str,
|
||||||
include_deleted: bool,
|
include_deleted: bool,
|
||||||
) -> Result<Community, Error> {
|
) -> Result<Community, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let mut q = community::table
|
let mut q = community::table
|
||||||
.into_boxed()
|
.into_boxed()
|
||||||
.filter(community::local.eq(true))
|
.filter(community::local.eq(true))
|
||||||
|
@ -320,11 +311,11 @@ impl ApubActor for Community {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_from_name_and_domain(
|
async fn read_from_name_and_domain(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
community_name: &str,
|
community_name: &str,
|
||||||
for_domain: &str,
|
for_domain: &str,
|
||||||
) -> Result<Community, Error> {
|
) -> Result<Community, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
community::table
|
community::table
|
||||||
.inner_join(instance::table)
|
.inner_join(instance::table)
|
||||||
.filter(lower(community::name).eq(community_name.to_lowercase()))
|
.filter(lower(community::name).eq(community_name.to_lowercase()))
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
||||||
schema::community_block::dsl::{community_block, community_id, person_id},
|
schema::community_block::dsl::{community_block, community_id, person_id},
|
||||||
source::community_block::{CommunityBlock, CommunityBlockForm},
|
source::community_block::{CommunityBlock, CommunityBlockForm},
|
||||||
traits::Blockable,
|
traits::Blockable,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
@ -10,11 +10,8 @@ use diesel_async::RunQueryDsl;
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Blockable for CommunityBlock {
|
impl Blockable for CommunityBlock {
|
||||||
type Form = CommunityBlockForm;
|
type Form = CommunityBlockForm;
|
||||||
async fn block(
|
async fn block(pool: &DbPool, community_block_form: &Self::Form) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
community_block_form: &Self::Form,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
insert_into(community_block)
|
insert_into(community_block)
|
||||||
.values(community_block_form)
|
.values(community_block_form)
|
||||||
.on_conflict((person_id, community_id))
|
.on_conflict((person_id, community_id))
|
||||||
|
@ -23,11 +20,8 @@ impl Blockable for CommunityBlock {
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn unblock(
|
async fn unblock(pool: &DbPool, community_block_form: &Self::Form) -> Result<usize, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
community_block_form: &Self::Form,
|
|
||||||
) -> Result<usize, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
community_block
|
community_block
|
||||||
.filter(person_id.eq(community_block_form.person_id))
|
.filter(person_id.eq(community_block_form.person_id))
|
||||||
|
|
|
@ -8,38 +8,32 @@ use crate::{
|
||||||
custom_emoji::{CustomEmoji, CustomEmojiInsertForm, CustomEmojiUpdateForm},
|
custom_emoji::{CustomEmoji, CustomEmojiInsertForm, CustomEmojiUpdateForm},
|
||||||
custom_emoji_keyword::{CustomEmojiKeyword, CustomEmojiKeywordInsertForm},
|
custom_emoji_keyword::{CustomEmojiKeyword, CustomEmojiKeywordInsertForm},
|
||||||
},
|
},
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
impl CustomEmoji {
|
impl CustomEmoji {
|
||||||
pub async fn create(
|
pub async fn create(pool: &DbPool, form: &CustomEmojiInsertForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
form: &CustomEmojiInsertForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
insert_into(custom_emoji)
|
insert_into(custom_emoji)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn update(
|
pub async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
emoji_id: CustomEmojiId,
|
emoji_id: CustomEmojiId,
|
||||||
form: &CustomEmojiUpdateForm,
|
form: &CustomEmojiUpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(custom_emoji.find(emoji_id))
|
diesel::update(custom_emoji.find(emoji_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn delete(
|
pub async fn delete(pool: &DbPool, emoji_id: CustomEmojiId) -> Result<usize, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
emoji_id: CustomEmojiId,
|
|
||||||
) -> Result<usize, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
diesel::delete(custom_emoji.find(emoji_id))
|
diesel::delete(custom_emoji.find(emoji_id))
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
|
@ -48,20 +42,17 @@ impl CustomEmoji {
|
||||||
|
|
||||||
impl CustomEmojiKeyword {
|
impl CustomEmojiKeyword {
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
form: Vec<CustomEmojiKeywordInsertForm>,
|
form: Vec<CustomEmojiKeywordInsertForm>,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(custom_emoji_keyword)
|
insert_into(custom_emoji_keyword)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_results::<Self>(conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn delete(
|
pub async fn delete(pool: &DbPool, emoji_id: CustomEmojiId) -> Result<usize, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
emoji_id: CustomEmojiId,
|
|
||||||
) -> Result<usize, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
diesel::delete(custom_emoji_keyword.filter(custom_emoji_id.eq(emoji_id)))
|
diesel::delete(custom_emoji_keyword.filter(custom_emoji_id.eq(emoji_id)))
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
verification_token,
|
verification_token,
|
||||||
},
|
},
|
||||||
source::email_verification::{EmailVerification, EmailVerificationForm},
|
source::email_verification::{EmailVerification, EmailVerificationForm},
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
dsl::{now, IntervalDsl},
|
dsl::{now, IntervalDsl},
|
||||||
|
@ -19,19 +19,16 @@ use diesel::{
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
impl EmailVerification {
|
impl EmailVerification {
|
||||||
pub async fn create(
|
pub async fn create(pool: &DbPool, form: &EmailVerificationForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
form: &EmailVerificationForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
insert_into(email_verification)
|
insert_into(email_verification)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_for_token(mut pool: &mut impl GetConn, token: &str) -> Result<Self, Error> {
|
pub async fn read_for_token(pool: &DbPool, token: &str) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
email_verification
|
email_verification
|
||||||
.filter(verification_token.eq(token))
|
.filter(verification_token.eq(token))
|
||||||
.filter(published.gt(now - 7.days()))
|
.filter(published.gt(now - 7.days()))
|
||||||
|
@ -39,10 +36,10 @@ impl EmailVerification {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn delete_old_tokens_for_local_user(
|
pub async fn delete_old_tokens_for_local_user(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
local_user_id_: LocalUserId,
|
local_user_id_: LocalUserId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(email_verification.filter(local_user_id.eq(local_user_id_)))
|
diesel::delete(email_verification.filter(local_user_id.eq(local_user_id_)))
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -4,17 +4,14 @@ use crate::{
|
||||||
federation_allowlist::{FederationAllowList, FederationAllowListForm},
|
federation_allowlist::{FederationAllowList, FederationAllowListForm},
|
||||||
instance::Instance,
|
instance::Instance,
|
||||||
},
|
},
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error};
|
use diesel::{dsl::insert_into, result::Error};
|
||||||
use diesel_async::{AsyncPgConnection, RunQueryDsl};
|
use diesel_async::{AsyncPgConnection, RunQueryDsl};
|
||||||
|
|
||||||
impl FederationAllowList {
|
impl FederationAllowList {
|
||||||
pub async fn replace(
|
pub async fn replace(pool: &DbPool, list_opt: Option<Vec<String>>) -> Result<(), Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
list_opt: Option<Vec<String>>,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
conn
|
conn
|
||||||
.build_transaction()
|
.build_transaction()
|
||||||
.run(|conn| {
|
.run(|conn| {
|
||||||
|
|
|
@ -4,17 +4,14 @@ use crate::{
|
||||||
federation_blocklist::{FederationBlockList, FederationBlockListForm},
|
federation_blocklist::{FederationBlockList, FederationBlockListForm},
|
||||||
instance::Instance,
|
instance::Instance,
|
||||||
},
|
},
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error};
|
use diesel::{dsl::insert_into, result::Error};
|
||||||
use diesel_async::{AsyncPgConnection, RunQueryDsl};
|
use diesel_async::{AsyncPgConnection, RunQueryDsl};
|
||||||
|
|
||||||
impl FederationBlockList {
|
impl FederationBlockList {
|
||||||
pub async fn replace(
|
pub async fn replace(pool: &DbPool, list_opt: Option<Vec<String>>) -> Result<(), Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
list_opt: Option<Vec<String>>,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
conn
|
conn
|
||||||
.build_transaction()
|
.build_transaction()
|
||||||
.run(|conn| {
|
.run(|conn| {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
||||||
newtypes::InstanceId,
|
newtypes::InstanceId,
|
||||||
schema::{federation_allowlist, federation_blocklist, instance},
|
schema::{federation_allowlist, federation_blocklist, instance},
|
||||||
source::instance::{Instance, InstanceForm},
|
source::instance::{Instance, InstanceForm},
|
||||||
utils::{naive_now, DbPool, GetConn},
|
utils::{get_conn, naive_now, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::{AsyncPgConnection, RunQueryDsl};
|
use diesel_async::{AsyncPgConnection, RunQueryDsl};
|
||||||
|
@ -42,26 +42,23 @@ impl Instance {
|
||||||
|
|
||||||
/// Attempt to read Instance column for the given domain. If it doesnt exist, insert a new one.
|
/// Attempt to read Instance column for the given domain. If it doesnt exist, insert a new one.
|
||||||
/// There is no need for update as the domain of an existing instance cant change.
|
/// There is no need for update as the domain of an existing instance cant change.
|
||||||
pub async fn read_or_create(mut pool: &mut impl GetConn, domain: String) -> Result<Self, Error> {
|
pub async fn read_or_create(pool: &DbPool, domain: String) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
Self::read_or_create_with_conn(conn, domain).await
|
Self::read_or_create_with_conn(conn, domain).await
|
||||||
}
|
}
|
||||||
pub async fn delete(
|
pub async fn delete(pool: &DbPool, instance_id: InstanceId) -> Result<usize, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
instance_id: InstanceId,
|
|
||||||
) -> Result<usize, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
diesel::delete(instance::table.find(instance_id))
|
diesel::delete(instance::table.find(instance_id))
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub async fn delete_all(mut pool: &mut impl GetConn) -> Result<usize, Error> {
|
pub async fn delete_all(pool: &DbPool) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(instance::table).execute(conn).await
|
diesel::delete(instance::table).execute(conn).await
|
||||||
}
|
}
|
||||||
pub async fn allowlist(mut pool: &mut impl GetConn) -> Result<Vec<Self>, Error> {
|
pub async fn allowlist(pool: &DbPool) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
instance::table
|
instance::table
|
||||||
.inner_join(federation_allowlist::table)
|
.inner_join(federation_allowlist::table)
|
||||||
.select(instance::all_columns)
|
.select(instance::all_columns)
|
||||||
|
@ -69,8 +66,8 @@ impl Instance {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn blocklist(mut pool: &mut impl GetConn) -> Result<Vec<Self>, Error> {
|
pub async fn blocklist(pool: &DbPool) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
instance::table
|
instance::table
|
||||||
.inner_join(federation_blocklist::table)
|
.inner_join(federation_blocklist::table)
|
||||||
.select(instance::all_columns)
|
.select(instance::all_columns)
|
||||||
|
@ -78,8 +75,8 @@ impl Instance {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn linked(mut pool: &mut impl GetConn) -> Result<Vec<Self>, Error> {
|
pub async fn linked(pool: &DbPool) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
instance::table
|
instance::table
|
||||||
.left_join(federation_blocklist::table)
|
.left_join(federation_blocklist::table)
|
||||||
.filter(federation_blocklist::id.is_null())
|
.filter(federation_blocklist::id.is_null())
|
||||||
|
|
|
@ -3,14 +3,14 @@ use crate::{
|
||||||
newtypes::LanguageId,
|
newtypes::LanguageId,
|
||||||
schema::language::dsl::{code, id, language},
|
schema::language::dsl::{code, id, language},
|
||||||
source::language::Language,
|
source::language::Language,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{result::Error, QueryDsl};
|
use diesel::{result::Error, QueryDsl};
|
||||||
use diesel_async::{AsyncPgConnection, RunQueryDsl};
|
use diesel_async::{AsyncPgConnection, RunQueryDsl};
|
||||||
|
|
||||||
impl Language {
|
impl Language {
|
||||||
pub async fn read_all(mut pool: &mut impl GetConn) -> Result<Vec<Language>, Error> {
|
pub async fn read_all(pool: &DbPool) -> Result<Vec<Language>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
Self::read_all_conn(conn).await
|
Self::read_all_conn(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,21 +18,18 @@ impl Language {
|
||||||
language.load::<Self>(conn).await
|
language.load::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_from_id(
|
pub async fn read_from_id(pool: &DbPool, id_: LanguageId) -> Result<Language, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
id_: LanguageId,
|
|
||||||
) -> Result<Language, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
language.filter(id.eq(id_)).first::<Self>(conn).await
|
language.filter(id.eq(id_)).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to find the given language code and return its ID. If not found, returns none.
|
/// Attempts to find the given language code and return its ID. If not found, returns none.
|
||||||
pub async fn read_id_from_code(
|
pub async fn read_id_from_code(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
code_: Option<&str>,
|
code_: Option<&str>,
|
||||||
) -> Result<Option<LanguageId>, Error> {
|
) -> Result<Option<LanguageId>, Error> {
|
||||||
if let Some(code_) = code_ {
|
if let Some(code_) = code_ {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
Ok(
|
Ok(
|
||||||
language
|
language
|
||||||
.filter(code.eq(code_))
|
.filter(code.eq(code_))
|
||||||
|
|
|
@ -1,38 +1,32 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
schema::local_site::dsl::local_site,
|
schema::local_site::dsl::local_site,
|
||||||
source::local_site::{LocalSite, LocalSiteInsertForm, LocalSiteUpdateForm},
|
source::local_site::{LocalSite, LocalSiteInsertForm, LocalSiteUpdateForm},
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error};
|
use diesel::{dsl::insert_into, result::Error};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
impl LocalSite {
|
impl LocalSite {
|
||||||
pub async fn create(
|
pub async fn create(pool: &DbPool, form: &LocalSiteInsertForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
form: &LocalSiteInsertForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
insert_into(local_site)
|
insert_into(local_site)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn read(mut pool: &mut impl GetConn) -> Result<Self, Error> {
|
pub async fn read(pool: &DbPool) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
local_site.first::<Self>(conn).await
|
local_site.first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
pub async fn update(
|
pub async fn update(pool: &DbPool, form: &LocalSiteUpdateForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
form: &LocalSiteUpdateForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
diesel::update(local_site)
|
diesel::update(local_site)
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn delete(mut pool: &mut impl GetConn) -> Result<usize, Error> {
|
pub async fn delete(pool: &DbPool) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(local_site).execute(conn).await
|
diesel::delete(local_site).execute(conn).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,36 +5,30 @@ use crate::{
|
||||||
LocalSiteRateLimitInsertForm,
|
LocalSiteRateLimitInsertForm,
|
||||||
LocalSiteRateLimitUpdateForm,
|
LocalSiteRateLimitUpdateForm,
|
||||||
},
|
},
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error};
|
use diesel::{dsl::insert_into, result::Error};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
impl LocalSiteRateLimit {
|
impl LocalSiteRateLimit {
|
||||||
pub async fn read(mut pool: &mut impl GetConn) -> Result<Self, Error> {
|
pub async fn read(pool: &DbPool) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
local_site_rate_limit::table.first::<Self>(conn).await
|
local_site_rate_limit::table.first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create(
|
pub async fn create(pool: &DbPool, form: &LocalSiteRateLimitInsertForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
form: &LocalSiteRateLimitInsertForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
insert_into(local_site_rate_limit::table)
|
insert_into(local_site_rate_limit::table)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn update(
|
pub async fn update(pool: &DbPool, form: &LocalSiteRateLimitUpdateForm) -> Result<(), Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
form: &LocalSiteRateLimitUpdateForm,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
// avoid error "There are no changes to save. This query cannot be built"
|
// avoid error "There are no changes to save. This query cannot be built"
|
||||||
if form.is_empty() {
|
if form.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(local_site_rate_limit::table)
|
diesel::update(local_site_rate_limit::table)
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
|
|
@ -13,7 +13,7 @@ use crate::{
|
||||||
local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
|
local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{naive_now, DbPool, GetConn},
|
utils::{get_conn, naive_now, DbPool},
|
||||||
};
|
};
|
||||||
use bcrypt::{hash, DEFAULT_COST};
|
use bcrypt::{hash, DEFAULT_COST};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
|
@ -21,11 +21,11 @@ use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
impl LocalUser {
|
impl LocalUser {
|
||||||
pub async fn update_password(
|
pub async fn update_password(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
local_user_id: LocalUserId,
|
local_user_id: LocalUserId,
|
||||||
new_password: &str,
|
new_password: &str,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let password_hash = hash(new_password, DEFAULT_COST).expect("Couldn't hash password");
|
let password_hash = hash(new_password, DEFAULT_COST).expect("Couldn't hash password");
|
||||||
|
|
||||||
diesel::update(local_user.find(local_user_id))
|
diesel::update(local_user.find(local_user_id))
|
||||||
|
@ -37,10 +37,8 @@ impl LocalUser {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_all_users_email_verified(
|
pub async fn set_all_users_email_verified(pool: &DbPool) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
diesel::update(local_user)
|
diesel::update(local_user)
|
||||||
.set(email_verified.eq(true))
|
.set(email_verified.eq(true))
|
||||||
.get_results::<Self>(conn)
|
.get_results::<Self>(conn)
|
||||||
|
@ -48,18 +46,18 @@ impl LocalUser {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn set_all_users_registration_applications_accepted(
|
pub async fn set_all_users_registration_applications_accepted(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(local_user)
|
diesel::update(local_user)
|
||||||
.set(accepted_application.eq(true))
|
.set(accepted_application.eq(true))
|
||||||
.get_results::<Self>(conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn is_email_taken(mut pool: &mut impl GetConn, email_: &str) -> Result<bool, Error> {
|
pub async fn is_email_taken(pool: &DbPool, email_: &str) -> Result<bool, Error> {
|
||||||
use diesel::dsl::{exists, select};
|
use diesel::dsl::{exists, select};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
select(exists(local_user.filter(email.eq(email_))))
|
select(exists(local_user.filter(email.eq(email_))))
|
||||||
.get_result(conn)
|
.get_result(conn)
|
||||||
.await
|
.await
|
||||||
|
@ -71,18 +69,18 @@ impl Crud for LocalUser {
|
||||||
type InsertForm = LocalUserInsertForm;
|
type InsertForm = LocalUserInsertForm;
|
||||||
type UpdateForm = LocalUserUpdateForm;
|
type UpdateForm = LocalUserUpdateForm;
|
||||||
type IdType = LocalUserId;
|
type IdType = LocalUserId;
|
||||||
async fn read(mut pool: &mut impl GetConn, local_user_id: LocalUserId) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, local_user_id: LocalUserId) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
local_user.find(local_user_id).first::<Self>(conn).await
|
local_user.find(local_user_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
async fn delete(mut pool: &mut impl GetConn, local_user_id: LocalUserId) -> Result<usize, Error> {
|
async fn delete(pool: &DbPool, local_user_id: LocalUserId) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(local_user.find(local_user_id))
|
diesel::delete(local_user.find(local_user_id))
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let mut form_with_encrypted_password = form.clone();
|
let mut form_with_encrypted_password = form.clone();
|
||||||
let password_hash =
|
let password_hash =
|
||||||
hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password");
|
hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password");
|
||||||
|
@ -106,11 +104,11 @@ impl Crud for LocalUser {
|
||||||
Ok(local_user_)
|
Ok(local_user_)
|
||||||
}
|
}
|
||||||
async fn update(
|
async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
local_user_id: LocalUserId,
|
local_user_id: LocalUserId,
|
||||||
form: &Self::UpdateForm,
|
form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(local_user.find(local_user_id))
|
diesel::update(local_user.find(local_user_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
|
|
@ -32,7 +32,7 @@ use crate::{
|
||||||
ModTransferCommunityForm,
|
ModTransferCommunityForm,
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
@ -42,28 +42,24 @@ impl Crud for ModRemovePost {
|
||||||
type InsertForm = ModRemovePostForm;
|
type InsertForm = ModRemovePostForm;
|
||||||
type UpdateForm = ModRemovePostForm;
|
type UpdateForm = ModRemovePostForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_remove_post::dsl::mod_remove_post;
|
use crate::schema::mod_remove_post::dsl::mod_remove_post;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
mod_remove_post.find(from_id).first::<Self>(conn).await
|
mod_remove_post.find(from_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &ModRemovePostForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &ModRemovePostForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_remove_post::dsl::mod_remove_post;
|
use crate::schema::mod_remove_post::dsl::mod_remove_post;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(mod_remove_post)
|
insert_into(mod_remove_post)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(pool: &DbPool, from_id: i32, form: &ModRemovePostForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
from_id: i32,
|
|
||||||
form: &ModRemovePostForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::mod_remove_post::dsl::mod_remove_post;
|
use crate::schema::mod_remove_post::dsl::mod_remove_post;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(mod_remove_post.find(from_id))
|
diesel::update(mod_remove_post.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -76,28 +72,24 @@ impl Crud for ModLockPost {
|
||||||
type InsertForm = ModLockPostForm;
|
type InsertForm = ModLockPostForm;
|
||||||
type UpdateForm = ModLockPostForm;
|
type UpdateForm = ModLockPostForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_lock_post::dsl::mod_lock_post;
|
use crate::schema::mod_lock_post::dsl::mod_lock_post;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
mod_lock_post.find(from_id).first::<Self>(conn).await
|
mod_lock_post.find(from_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &ModLockPostForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &ModLockPostForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_lock_post::dsl::mod_lock_post;
|
use crate::schema::mod_lock_post::dsl::mod_lock_post;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(mod_lock_post)
|
insert_into(mod_lock_post)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(pool: &DbPool, from_id: i32, form: &ModLockPostForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
from_id: i32,
|
|
||||||
form: &ModLockPostForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::mod_lock_post::dsl::mod_lock_post;
|
use crate::schema::mod_lock_post::dsl::mod_lock_post;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(mod_lock_post.find(from_id))
|
diesel::update(mod_lock_post.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -110,28 +102,24 @@ impl Crud for ModFeaturePost {
|
||||||
type InsertForm = ModFeaturePostForm;
|
type InsertForm = ModFeaturePostForm;
|
||||||
type UpdateForm = ModFeaturePostForm;
|
type UpdateForm = ModFeaturePostForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_feature_post::dsl::mod_feature_post;
|
use crate::schema::mod_feature_post::dsl::mod_feature_post;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
mod_feature_post.find(from_id).first::<Self>(conn).await
|
mod_feature_post.find(from_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &ModFeaturePostForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &ModFeaturePostForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_feature_post::dsl::mod_feature_post;
|
use crate::schema::mod_feature_post::dsl::mod_feature_post;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(mod_feature_post)
|
insert_into(mod_feature_post)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(pool: &DbPool, from_id: i32, form: &ModFeaturePostForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
from_id: i32,
|
|
||||||
form: &ModFeaturePostForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::mod_feature_post::dsl::mod_feature_post;
|
use crate::schema::mod_feature_post::dsl::mod_feature_post;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(mod_feature_post.find(from_id))
|
diesel::update(mod_feature_post.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -144,28 +132,24 @@ impl Crud for ModRemoveComment {
|
||||||
type InsertForm = ModRemoveCommentForm;
|
type InsertForm = ModRemoveCommentForm;
|
||||||
type UpdateForm = ModRemoveCommentForm;
|
type UpdateForm = ModRemoveCommentForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
|
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
mod_remove_comment.find(from_id).first::<Self>(conn).await
|
mod_remove_comment.find(from_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &ModRemoveCommentForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &ModRemoveCommentForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
|
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(mod_remove_comment)
|
insert_into(mod_remove_comment)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(pool: &DbPool, from_id: i32, form: &ModRemoveCommentForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
from_id: i32,
|
|
||||||
form: &ModRemoveCommentForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
|
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(mod_remove_comment.find(from_id))
|
diesel::update(mod_remove_comment.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -178,18 +162,15 @@ impl Crud for ModRemoveCommunity {
|
||||||
type InsertForm = ModRemoveCommunityForm;
|
type InsertForm = ModRemoveCommunityForm;
|
||||||
type UpdateForm = ModRemoveCommunityForm;
|
type UpdateForm = ModRemoveCommunityForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_remove_community::dsl::mod_remove_community;
|
use crate::schema::mod_remove_community::dsl::mod_remove_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
mod_remove_community.find(from_id).first::<Self>(conn).await
|
mod_remove_community.find(from_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(
|
async fn create(pool: &DbPool, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
form: &ModRemoveCommunityForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::mod_remove_community::dsl::mod_remove_community;
|
use crate::schema::mod_remove_community::dsl::mod_remove_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(mod_remove_community)
|
insert_into(mod_remove_community)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -197,12 +178,12 @@ impl Crud for ModRemoveCommunity {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
form: &ModRemoveCommunityForm,
|
form: &ModRemoveCommunityForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_remove_community::dsl::mod_remove_community;
|
use crate::schema::mod_remove_community::dsl::mod_remove_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(mod_remove_community.find(from_id))
|
diesel::update(mod_remove_community.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -215,21 +196,18 @@ impl Crud for ModBanFromCommunity {
|
||||||
type InsertForm = ModBanFromCommunityForm;
|
type InsertForm = ModBanFromCommunityForm;
|
||||||
type UpdateForm = ModBanFromCommunityForm;
|
type UpdateForm = ModBanFromCommunityForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
|
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
mod_ban_from_community
|
mod_ban_from_community
|
||||||
.find(from_id)
|
.find(from_id)
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(
|
async fn create(pool: &DbPool, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
form: &ModBanFromCommunityForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
|
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(mod_ban_from_community)
|
insert_into(mod_ban_from_community)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -237,12 +215,12 @@ impl Crud for ModBanFromCommunity {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
form: &ModBanFromCommunityForm,
|
form: &ModBanFromCommunityForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
|
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(mod_ban_from_community.find(from_id))
|
diesel::update(mod_ban_from_community.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -255,28 +233,24 @@ impl Crud for ModBan {
|
||||||
type InsertForm = ModBanForm;
|
type InsertForm = ModBanForm;
|
||||||
type UpdateForm = ModBanForm;
|
type UpdateForm = ModBanForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_ban::dsl::mod_ban;
|
use crate::schema::mod_ban::dsl::mod_ban;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
mod_ban.find(from_id).first::<Self>(conn).await
|
mod_ban.find(from_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &ModBanForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &ModBanForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_ban::dsl::mod_ban;
|
use crate::schema::mod_ban::dsl::mod_ban;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(mod_ban)
|
insert_into(mod_ban)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(pool: &DbPool, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
from_id: i32,
|
|
||||||
form: &ModBanForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::mod_ban::dsl::mod_ban;
|
use crate::schema::mod_ban::dsl::mod_ban;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(mod_ban.find(from_id))
|
diesel::update(mod_ban.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -290,28 +264,24 @@ impl Crud for ModHideCommunity {
|
||||||
type UpdateForm = ModHideCommunityForm;
|
type UpdateForm = ModHideCommunityForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
|
|
||||||
async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_hide_community::dsl::mod_hide_community;
|
use crate::schema::mod_hide_community::dsl::mod_hide_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
mod_hide_community.find(from_id).first::<Self>(conn).await
|
mod_hide_community.find(from_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &ModHideCommunityForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &ModHideCommunityForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_hide_community::dsl::mod_hide_community;
|
use crate::schema::mod_hide_community::dsl::mod_hide_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(mod_hide_community)
|
insert_into(mod_hide_community)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(pool: &DbPool, from_id: i32, form: &ModHideCommunityForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
from_id: i32,
|
|
||||||
form: &ModHideCommunityForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::mod_hide_community::dsl::mod_hide_community;
|
use crate::schema::mod_hide_community::dsl::mod_hide_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(mod_hide_community.find(from_id))
|
diesel::update(mod_hide_community.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -324,28 +294,24 @@ impl Crud for ModAddCommunity {
|
||||||
type InsertForm = ModAddCommunityForm;
|
type InsertForm = ModAddCommunityForm;
|
||||||
type UpdateForm = ModAddCommunityForm;
|
type UpdateForm = ModAddCommunityForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_add_community::dsl::mod_add_community;
|
use crate::schema::mod_add_community::dsl::mod_add_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
mod_add_community.find(from_id).first::<Self>(conn).await
|
mod_add_community.find(from_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &ModAddCommunityForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &ModAddCommunityForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_add_community::dsl::mod_add_community;
|
use crate::schema::mod_add_community::dsl::mod_add_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(mod_add_community)
|
insert_into(mod_add_community)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(pool: &DbPool, from_id: i32, form: &ModAddCommunityForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
from_id: i32,
|
|
||||||
form: &ModAddCommunityForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::mod_add_community::dsl::mod_add_community;
|
use crate::schema::mod_add_community::dsl::mod_add_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(mod_add_community.find(from_id))
|
diesel::update(mod_add_community.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -358,21 +324,18 @@ impl Crud for ModTransferCommunity {
|
||||||
type InsertForm = ModTransferCommunityForm;
|
type InsertForm = ModTransferCommunityForm;
|
||||||
type UpdateForm = ModTransferCommunityForm;
|
type UpdateForm = ModTransferCommunityForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
|
use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
mod_transfer_community
|
mod_transfer_community
|
||||||
.find(from_id)
|
.find(from_id)
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(
|
async fn create(pool: &DbPool, form: &ModTransferCommunityForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
form: &ModTransferCommunityForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
|
use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(mod_transfer_community)
|
insert_into(mod_transfer_community)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -380,12 +343,12 @@ impl Crud for ModTransferCommunity {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
from_id: i32,
|
from_id: i32,
|
||||||
form: &ModTransferCommunityForm,
|
form: &ModTransferCommunityForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
|
use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(mod_transfer_community.find(from_id))
|
diesel::update(mod_transfer_community.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -398,28 +361,24 @@ impl Crud for ModAdd {
|
||||||
type InsertForm = ModAddForm;
|
type InsertForm = ModAddForm;
|
||||||
type UpdateForm = ModAddForm;
|
type UpdateForm = ModAddForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_add::dsl::mod_add;
|
use crate::schema::mod_add::dsl::mod_add;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
mod_add.find(from_id).first::<Self>(conn).await
|
mod_add.find(from_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &ModAddForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &ModAddForm) -> Result<Self, Error> {
|
||||||
use crate::schema::mod_add::dsl::mod_add;
|
use crate::schema::mod_add::dsl::mod_add;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(mod_add)
|
insert_into(mod_add)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(pool: &DbPool, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
from_id: i32,
|
|
||||||
form: &ModAddForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::mod_add::dsl::mod_add;
|
use crate::schema::mod_add::dsl::mod_add;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(mod_add.find(from_id))
|
diesel::update(mod_add.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -432,28 +391,24 @@ impl Crud for AdminPurgePerson {
|
||||||
type InsertForm = AdminPurgePersonForm;
|
type InsertForm = AdminPurgePersonForm;
|
||||||
type UpdateForm = AdminPurgePersonForm;
|
type UpdateForm = AdminPurgePersonForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_person::dsl::admin_purge_person;
|
use crate::schema::admin_purge_person::dsl::admin_purge_person;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
admin_purge_person.find(from_id).first::<Self>(conn).await
|
admin_purge_person.find(from_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_person::dsl::admin_purge_person;
|
use crate::schema::admin_purge_person::dsl::admin_purge_person;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(admin_purge_person)
|
insert_into(admin_purge_person)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
from_id: i32,
|
|
||||||
form: &Self::InsertForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::admin_purge_person::dsl::admin_purge_person;
|
use crate::schema::admin_purge_person::dsl::admin_purge_person;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(admin_purge_person.find(from_id))
|
diesel::update(admin_purge_person.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -466,31 +421,27 @@ impl Crud for AdminPurgeCommunity {
|
||||||
type InsertForm = AdminPurgeCommunityForm;
|
type InsertForm = AdminPurgeCommunityForm;
|
||||||
type UpdateForm = AdminPurgeCommunityForm;
|
type UpdateForm = AdminPurgeCommunityForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_community::dsl::admin_purge_community;
|
use crate::schema::admin_purge_community::dsl::admin_purge_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
admin_purge_community
|
admin_purge_community
|
||||||
.find(from_id)
|
.find(from_id)
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_community::dsl::admin_purge_community;
|
use crate::schema::admin_purge_community::dsl::admin_purge_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(admin_purge_community)
|
insert_into(admin_purge_community)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
from_id: i32,
|
|
||||||
form: &Self::InsertForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::admin_purge_community::dsl::admin_purge_community;
|
use crate::schema::admin_purge_community::dsl::admin_purge_community;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(admin_purge_community.find(from_id))
|
diesel::update(admin_purge_community.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -503,28 +454,24 @@ impl Crud for AdminPurgePost {
|
||||||
type InsertForm = AdminPurgePostForm;
|
type InsertForm = AdminPurgePostForm;
|
||||||
type UpdateForm = AdminPurgePostForm;
|
type UpdateForm = AdminPurgePostForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_post::dsl::admin_purge_post;
|
use crate::schema::admin_purge_post::dsl::admin_purge_post;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
admin_purge_post.find(from_id).first::<Self>(conn).await
|
admin_purge_post.find(from_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_post::dsl::admin_purge_post;
|
use crate::schema::admin_purge_post::dsl::admin_purge_post;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(admin_purge_post)
|
insert_into(admin_purge_post)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
from_id: i32,
|
|
||||||
form: &Self::InsertForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::admin_purge_post::dsl::admin_purge_post;
|
use crate::schema::admin_purge_post::dsl::admin_purge_post;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(admin_purge_post.find(from_id))
|
diesel::update(admin_purge_post.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -537,28 +484,24 @@ impl Crud for AdminPurgeComment {
|
||||||
type InsertForm = AdminPurgeCommentForm;
|
type InsertForm = AdminPurgeCommentForm;
|
||||||
type UpdateForm = AdminPurgeCommentForm;
|
type UpdateForm = AdminPurgeCommentForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut pool: &mut impl GetConn, from_id: i32) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
|
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
admin_purge_comment.find(from_id).first::<Self>(conn).await
|
admin_purge_comment.find(from_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
|
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(admin_purge_comment)
|
insert_into(admin_purge_comment)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
from_id: i32,
|
|
||||||
form: &Self::InsertForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
|
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(admin_purge_comment.find(from_id))
|
diesel::update(admin_purge_comment.find(from_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
source::password_reset_request::{PasswordResetRequest, PasswordResetRequestForm},
|
source::password_reset_request::{PasswordResetRequest, PasswordResetRequestForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
dsl::{insert_into, now, IntervalDsl},
|
dsl::{insert_into, now, IntervalDsl},
|
||||||
|
@ -24,32 +24,26 @@ impl Crud for PasswordResetRequest {
|
||||||
type InsertForm = PasswordResetRequestForm;
|
type InsertForm = PasswordResetRequestForm;
|
||||||
type UpdateForm = PasswordResetRequestForm;
|
type UpdateForm = PasswordResetRequestForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(
|
async fn read(pool: &DbPool, password_reset_request_id: i32) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
password_reset_request_id: i32,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
password_reset_request
|
password_reset_request
|
||||||
.find(password_reset_request_id)
|
.find(password_reset_request_id)
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn create(
|
async fn create(pool: &DbPool, form: &PasswordResetRequestForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
form: &PasswordResetRequestForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
insert_into(password_reset_request)
|
insert_into(password_reset_request)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn update(
|
async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
password_reset_request_id: i32,
|
password_reset_request_id: i32,
|
||||||
form: &PasswordResetRequestForm,
|
form: &PasswordResetRequestForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(password_reset_request.find(password_reset_request_id))
|
diesel::update(password_reset_request.find(password_reset_request_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -59,7 +53,7 @@ impl Crud for PasswordResetRequest {
|
||||||
|
|
||||||
impl PasswordResetRequest {
|
impl PasswordResetRequest {
|
||||||
pub async fn create_token(
|
pub async fn create_token(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
from_local_user_id: LocalUserId,
|
from_local_user_id: LocalUserId,
|
||||||
token: &str,
|
token: &str,
|
||||||
) -> Result<PasswordResetRequest, Error> {
|
) -> Result<PasswordResetRequest, Error> {
|
||||||
|
@ -74,11 +68,8 @@ impl PasswordResetRequest {
|
||||||
|
|
||||||
Self::create(pool, &form).await
|
Self::create(pool, &form).await
|
||||||
}
|
}
|
||||||
pub async fn read_from_token(
|
pub async fn read_from_token(pool: &DbPool, token: &str) -> Result<PasswordResetRequest, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
token: &str,
|
|
||||||
) -> Result<PasswordResetRequest, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
hasher.update(token);
|
hasher.update(token);
|
||||||
let token_hash: String = bytes_to_hex(hasher.finalize().to_vec());
|
let token_hash: String = bytes_to_hex(hasher.finalize().to_vec());
|
||||||
|
@ -90,10 +81,10 @@ impl PasswordResetRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_recent_password_resets_count(
|
pub async fn get_recent_password_resets_count(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
user_id: LocalUserId,
|
user_id: LocalUserId,
|
||||||
) -> Result<i64, Error> {
|
) -> Result<i64, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
password_reset_request
|
password_reset_request
|
||||||
.filter(local_user_id.eq(user_id))
|
.filter(local_user_id.eq(user_id))
|
||||||
.filter(published.gt(now - 1.days()))
|
.filter(published.gt(now - 1.days()))
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
PersonUpdateForm,
|
PersonUpdateForm,
|
||||||
},
|
},
|
||||||
traits::{ApubActor, Crud, Followable},
|
traits::{ApubActor, Crud, Followable},
|
||||||
utils::{functions::lower, naive_now, DbPool, GetConn},
|
utils::{functions::lower, get_conn, naive_now, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
@ -19,33 +19,33 @@ impl Crud for Person {
|
||||||
type InsertForm = PersonInsertForm;
|
type InsertForm = PersonInsertForm;
|
||||||
type UpdateForm = PersonUpdateForm;
|
type UpdateForm = PersonUpdateForm;
|
||||||
type IdType = PersonId;
|
type IdType = PersonId;
|
||||||
async fn read(mut pool: &mut impl GetConn, person_id: PersonId) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, person_id: PersonId) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
person::table
|
person::table
|
||||||
.filter(person::deleted.eq(false))
|
.filter(person::deleted.eq(false))
|
||||||
.find(person_id)
|
.find(person_id)
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn delete(mut pool: &mut impl GetConn, person_id: PersonId) -> Result<usize, Error> {
|
async fn delete(pool: &DbPool, person_id: PersonId) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(person::table.find(person_id))
|
diesel::delete(person::table.find(person_id))
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &PersonInsertForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &PersonInsertForm) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(person::table)
|
insert_into(person::table)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn update(
|
async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
form: &PersonUpdateForm,
|
form: &PersonUpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(person::table.find(person_id))
|
diesel::update(person::table.find(person_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -57,8 +57,8 @@ impl Person {
|
||||||
/// Update or insert the person.
|
/// Update or insert the person.
|
||||||
///
|
///
|
||||||
/// This is necessary for federation, because Activitypub doesnt distinguish between these actions.
|
/// This is necessary for federation, because Activitypub doesnt distinguish between these actions.
|
||||||
pub async fn upsert(mut pool: &mut impl GetConn, form: &PersonInsertForm) -> Result<Self, Error> {
|
pub async fn upsert(pool: &DbPool, form: &PersonInsertForm) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(person::table)
|
insert_into(person::table)
|
||||||
.values(form)
|
.values(form)
|
||||||
.on_conflict(person::actor_id)
|
.on_conflict(person::actor_id)
|
||||||
|
@ -67,11 +67,8 @@ impl Person {
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn delete_account(
|
pub async fn delete_account(pool: &DbPool, person_id: PersonId) -> Result<Person, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_id: PersonId,
|
|
||||||
) -> Result<Person, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
|
|
||||||
// Set the local user info to none
|
// Set the local user info to none
|
||||||
diesel::update(local_user::table.filter(local_user::person_id.eq(person_id)))
|
diesel::update(local_user::table.filter(local_user::person_id.eq(person_id)))
|
||||||
|
@ -107,11 +104,8 @@ pub fn is_banned(banned_: bool, expires: Option<chrono::NaiveDateTime>) -> bool
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl ApubActor for Person {
|
impl ApubActor for Person {
|
||||||
async fn read_from_apub_id(
|
async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result<Option<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
object_id: &DbUrl,
|
|
||||||
) -> Result<Option<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
Ok(
|
Ok(
|
||||||
person::table
|
person::table
|
||||||
.filter(person::deleted.eq(false))
|
.filter(person::deleted.eq(false))
|
||||||
|
@ -124,11 +118,11 @@ impl ApubActor for Person {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_from_name(
|
async fn read_from_name(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
from_name: &str,
|
from_name: &str,
|
||||||
include_deleted: bool,
|
include_deleted: bool,
|
||||||
) -> Result<Person, Error> {
|
) -> Result<Person, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let mut q = person::table
|
let mut q = person::table
|
||||||
.into_boxed()
|
.into_boxed()
|
||||||
.filter(person::local.eq(true))
|
.filter(person::local.eq(true))
|
||||||
|
@ -140,11 +134,11 @@ impl ApubActor for Person {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_from_name_and_domain(
|
async fn read_from_name_and_domain(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
person_name: &str,
|
person_name: &str,
|
||||||
for_domain: &str,
|
for_domain: &str,
|
||||||
) -> Result<Person, Error> {
|
) -> Result<Person, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
person::table
|
person::table
|
||||||
.inner_join(instance::table)
|
.inner_join(instance::table)
|
||||||
|
@ -159,9 +153,9 @@ impl ApubActor for Person {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Followable for PersonFollower {
|
impl Followable for PersonFollower {
|
||||||
type Form = PersonFollowerForm;
|
type Form = PersonFollowerForm;
|
||||||
async fn follow(mut pool: &mut impl GetConn, form: &PersonFollowerForm) -> Result<Self, Error> {
|
async fn follow(pool: &DbPool, form: &PersonFollowerForm) -> Result<Self, Error> {
|
||||||
use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id};
|
use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(person_follower)
|
insert_into(person_follower)
|
||||||
.values(form)
|
.values(form)
|
||||||
.on_conflict((follower_id, person_id))
|
.on_conflict((follower_id, person_id))
|
||||||
|
@ -170,19 +164,12 @@ impl Followable for PersonFollower {
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn follow_accepted(
|
async fn follow_accepted(_: &DbPool, _: CommunityId, _: PersonId) -> Result<Self, Error> {
|
||||||
_: &mut impl GetConn,
|
|
||||||
_: CommunityId,
|
|
||||||
_: PersonId,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
async fn unfollow(
|
async fn unfollow(pool: &DbPool, form: &PersonFollowerForm) -> Result<usize, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
form: &PersonFollowerForm,
|
|
||||||
) -> Result<usize, Error> {
|
|
||||||
use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id};
|
use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
person_follower
|
person_follower
|
||||||
.filter(follower_id.eq(&form.follower_id))
|
.filter(follower_id.eq(&form.follower_id))
|
||||||
|
@ -195,10 +182,10 @@ impl Followable for PersonFollower {
|
||||||
|
|
||||||
impl PersonFollower {
|
impl PersonFollower {
|
||||||
pub async fn list_followers(
|
pub async fn list_followers(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_person_id: PersonId,
|
for_person_id: PersonId,
|
||||||
) -> Result<Vec<Person>, Error> {
|
) -> Result<Vec<Person>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_follower::table
|
person_follower::table
|
||||||
.inner_join(person::table.on(person_follower::follower_id.eq(person::id)))
|
.inner_join(person::table.on(person_follower::follower_id.eq(person::id)))
|
||||||
.filter(person_follower::person_id.eq(for_person_id))
|
.filter(person_follower::person_id.eq(for_person_id))
|
||||||
|
|
|
@ -3,18 +3,18 @@ use crate::{
|
||||||
schema::person_block::dsl::{person_block, person_id, target_id},
|
schema::person_block::dsl::{person_block, person_id, target_id},
|
||||||
source::person_block::{PersonBlock, PersonBlockForm},
|
source::person_block::{PersonBlock, PersonBlockForm},
|
||||||
traits::Blockable,
|
traits::Blockable,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
impl PersonBlock {
|
impl PersonBlock {
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_person_id: PersonId,
|
for_person_id: PersonId,
|
||||||
for_recipient_id: PersonId,
|
for_recipient_id: PersonId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_block
|
person_block
|
||||||
.filter(person_id.eq(for_person_id))
|
.filter(person_id.eq(for_person_id))
|
||||||
.filter(target_id.eq(for_recipient_id))
|
.filter(target_id.eq(for_recipient_id))
|
||||||
|
@ -26,11 +26,8 @@ impl PersonBlock {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Blockable for PersonBlock {
|
impl Blockable for PersonBlock {
|
||||||
type Form = PersonBlockForm;
|
type Form = PersonBlockForm;
|
||||||
async fn block(
|
async fn block(pool: &DbPool, person_block_form: &PersonBlockForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_block_form: &PersonBlockForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
insert_into(person_block)
|
insert_into(person_block)
|
||||||
.values(person_block_form)
|
.values(person_block_form)
|
||||||
.on_conflict((person_id, target_id))
|
.on_conflict((person_id, target_id))
|
||||||
|
@ -39,11 +36,8 @@ impl Blockable for PersonBlock {
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn unblock(
|
async fn unblock(pool: &DbPool, person_block_form: &Self::Form) -> Result<usize, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_block_form: &Self::Form,
|
|
||||||
) -> Result<usize, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
person_block
|
person_block
|
||||||
.filter(person_id.eq(person_block_form.person_id))
|
.filter(person_id.eq(person_block_form.person_id))
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
schema::person_mention::dsl::{comment_id, person_mention, read, recipient_id},
|
schema::person_mention::dsl::{comment_id, person_mention, read, recipient_id},
|
||||||
source::person_mention::{PersonMention, PersonMentionInsertForm, PersonMentionUpdateForm},
|
source::person_mention::{PersonMention, PersonMentionInsertForm, PersonMentionUpdateForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
@ -13,22 +13,16 @@ impl Crud for PersonMention {
|
||||||
type InsertForm = PersonMentionInsertForm;
|
type InsertForm = PersonMentionInsertForm;
|
||||||
type UpdateForm = PersonMentionUpdateForm;
|
type UpdateForm = PersonMentionUpdateForm;
|
||||||
type IdType = PersonMentionId;
|
type IdType = PersonMentionId;
|
||||||
async fn read(
|
async fn read(pool: &DbPool, person_mention_id: PersonMentionId) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_mention_id: PersonMentionId,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
person_mention
|
person_mention
|
||||||
.find(person_mention_id)
|
.find(person_mention_id)
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(
|
async fn create(pool: &DbPool, person_mention_form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_mention_form: &Self::InsertForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
// since the return here isnt utilized, we dont need to do an update
|
// since the return here isnt utilized, we dont need to do an update
|
||||||
// but get_result doesnt return the existing row here
|
// but get_result doesnt return the existing row here
|
||||||
insert_into(person_mention)
|
insert_into(person_mention)
|
||||||
|
@ -41,11 +35,11 @@ impl Crud for PersonMention {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
person_mention_id: PersonMentionId,
|
person_mention_id: PersonMentionId,
|
||||||
person_mention_form: &Self::UpdateForm,
|
person_mention_form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(person_mention.find(person_mention_id))
|
diesel::update(person_mention.find(person_mention_id))
|
||||||
.set(person_mention_form)
|
.set(person_mention_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -55,10 +49,10 @@ impl Crud for PersonMention {
|
||||||
|
|
||||||
impl PersonMention {
|
impl PersonMention {
|
||||||
pub async fn mark_all_as_read(
|
pub async fn mark_all_as_read(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_recipient_id: PersonId,
|
for_recipient_id: PersonId,
|
||||||
) -> Result<Vec<PersonMention>, Error> {
|
) -> Result<Vec<PersonMention>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(
|
diesel::update(
|
||||||
person_mention
|
person_mention
|
||||||
.filter(recipient_id.eq(for_recipient_id))
|
.filter(recipient_id.eq(for_recipient_id))
|
||||||
|
@ -70,11 +64,11 @@ impl PersonMention {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_by_comment_and_person(
|
pub async fn read_by_comment_and_person(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_comment_id: CommentId,
|
for_comment_id: CommentId,
|
||||||
for_recipient_id: PersonId,
|
for_recipient_id: PersonId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_mention
|
person_mention
|
||||||
.filter(comment_id.eq(for_comment_id))
|
.filter(comment_id.eq(for_comment_id))
|
||||||
.filter(recipient_id.eq(for_recipient_id))
|
.filter(recipient_id.eq(for_recipient_id))
|
||||||
|
|
|
@ -27,7 +27,7 @@ use crate::{
|
||||||
PostUpdateForm,
|
PostUpdateForm,
|
||||||
},
|
},
|
||||||
traits::{Crud, Likeable, Readable, Saveable},
|
traits::{Crud, Likeable, Readable, Saveable},
|
||||||
utils::{naive_now, DbPool, GetConn, DELETED_REPLACEMENT_TEXT, FETCH_LIMIT_MAX},
|
utils::{get_conn, naive_now, DbPool, DELETED_REPLACEMENT_TEXT, FETCH_LIMIT_MAX},
|
||||||
};
|
};
|
||||||
use ::url::Url;
|
use ::url::Url;
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl, TextExpressionMethods};
|
||||||
|
@ -38,18 +38,18 @@ impl Crud for Post {
|
||||||
type InsertForm = PostInsertForm;
|
type InsertForm = PostInsertForm;
|
||||||
type UpdateForm = PostUpdateForm;
|
type UpdateForm = PostUpdateForm;
|
||||||
type IdType = PostId;
|
type IdType = PostId;
|
||||||
async fn read(mut pool: &mut impl GetConn, post_id: PostId) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, post_id: PostId) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
post.find(post_id).first::<Self>(conn).await
|
post.find(post_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(mut pool: &mut impl GetConn, post_id: PostId) -> Result<usize, Error> {
|
async fn delete(pool: &DbPool, post_id: PostId) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(post.find(post_id)).execute(conn).await
|
diesel::delete(post.find(post_id)).execute(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(post)
|
insert_into(post)
|
||||||
.values(form)
|
.values(form)
|
||||||
.on_conflict(ap_id)
|
.on_conflict(ap_id)
|
||||||
|
@ -60,11 +60,11 @@ impl Crud for Post {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
post_id: PostId,
|
post_id: PostId,
|
||||||
new_post: &Self::UpdateForm,
|
new_post: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(post.find(post_id))
|
diesel::update(post.find(post_id))
|
||||||
.set(new_post)
|
.set(new_post)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -74,10 +74,10 @@ impl Crud for Post {
|
||||||
|
|
||||||
impl Post {
|
impl Post {
|
||||||
pub async fn list_for_community(
|
pub async fn list_for_community(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
the_community_id: CommunityId,
|
the_community_id: CommunityId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
post
|
post
|
||||||
.filter(community_id.eq(the_community_id))
|
.filter(community_id.eq(the_community_id))
|
||||||
.filter(deleted.eq(false))
|
.filter(deleted.eq(false))
|
||||||
|
@ -90,10 +90,10 @@ impl Post {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_featured_for_community(
|
pub async fn list_featured_for_community(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
the_community_id: CommunityId,
|
the_community_id: CommunityId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
post
|
post
|
||||||
.filter(community_id.eq(the_community_id))
|
.filter(community_id.eq(the_community_id))
|
||||||
.filter(deleted.eq(false))
|
.filter(deleted.eq(false))
|
||||||
|
@ -106,10 +106,10 @@ impl Post {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn permadelete_for_creator(
|
pub async fn permadelete_for_creator(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_creator_id: PersonId,
|
for_creator_id: PersonId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
diesel::update(post.filter(creator_id.eq(for_creator_id)))
|
diesel::update(post.filter(creator_id.eq(for_creator_id)))
|
||||||
.set((
|
.set((
|
||||||
|
@ -124,12 +124,12 @@ impl Post {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_removed_for_creator(
|
pub async fn update_removed_for_creator(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_creator_id: PersonId,
|
for_creator_id: PersonId,
|
||||||
for_community_id: Option<CommunityId>,
|
for_community_id: Option<CommunityId>,
|
||||||
new_removed: bool,
|
new_removed: bool,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
let mut update = diesel::update(post).into_boxed();
|
let mut update = diesel::update(post).into_boxed();
|
||||||
update = update.filter(creator_id.eq(for_creator_id));
|
update = update.filter(creator_id.eq(for_creator_id));
|
||||||
|
@ -148,11 +148,8 @@ impl Post {
|
||||||
person_id == post_creator_id
|
person_id == post_creator_id
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_from_apub_id(
|
pub async fn read_from_apub_id(pool: &DbPool, object_id: Url) -> Result<Option<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
object_id: Url,
|
|
||||||
) -> Result<Option<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let object_id: DbUrl = object_id.into();
|
let object_id: DbUrl = object_id.into();
|
||||||
Ok(
|
Ok(
|
||||||
post
|
post
|
||||||
|
@ -165,10 +162,10 @@ impl Post {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_pictrs_posts_for_creator(
|
pub async fn fetch_pictrs_posts_for_creator(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_creator_id: PersonId,
|
for_creator_id: PersonId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let pictrs_search = "%pictrs/image%";
|
let pictrs_search = "%pictrs/image%";
|
||||||
|
|
||||||
post
|
post
|
||||||
|
@ -180,10 +177,10 @@ impl Post {
|
||||||
|
|
||||||
/// Sets the url and thumbnails fields to None
|
/// Sets the url and thumbnails fields to None
|
||||||
pub async fn remove_pictrs_post_images_and_thumbnails_for_creator(
|
pub async fn remove_pictrs_post_images_and_thumbnails_for_creator(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_creator_id: PersonId,
|
for_creator_id: PersonId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let pictrs_search = "%pictrs/image%";
|
let pictrs_search = "%pictrs/image%";
|
||||||
|
|
||||||
diesel::update(
|
diesel::update(
|
||||||
|
@ -200,10 +197,10 @@ impl Post {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_pictrs_posts_for_community(
|
pub async fn fetch_pictrs_posts_for_community(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_community_id: CommunityId,
|
for_community_id: CommunityId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let pictrs_search = "%pictrs/image%";
|
let pictrs_search = "%pictrs/image%";
|
||||||
post
|
post
|
||||||
.filter(community_id.eq(for_community_id))
|
.filter(community_id.eq(for_community_id))
|
||||||
|
@ -214,10 +211,10 @@ impl Post {
|
||||||
|
|
||||||
/// Sets the url and thumbnails fields to None
|
/// Sets the url and thumbnails fields to None
|
||||||
pub async fn remove_pictrs_post_images_and_thumbnails_for_community(
|
pub async fn remove_pictrs_post_images_and_thumbnails_for_community(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_community_id: CommunityId,
|
for_community_id: CommunityId,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let pictrs_search = "%pictrs/image%";
|
let pictrs_search = "%pictrs/image%";
|
||||||
|
|
||||||
diesel::update(
|
diesel::update(
|
||||||
|
@ -238,9 +235,9 @@ impl Post {
|
||||||
impl Likeable for PostLike {
|
impl Likeable for PostLike {
|
||||||
type Form = PostLikeForm;
|
type Form = PostLikeForm;
|
||||||
type IdType = PostId;
|
type IdType = PostId;
|
||||||
async fn like(mut pool: &mut impl GetConn, post_like_form: &PostLikeForm) -> Result<Self, Error> {
|
async fn like(pool: &DbPool, post_like_form: &PostLikeForm) -> Result<Self, Error> {
|
||||||
use crate::schema::post_like::dsl::{person_id, post_id, post_like};
|
use crate::schema::post_like::dsl::{person_id, post_id, post_like};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(post_like)
|
insert_into(post_like)
|
||||||
.values(post_like_form)
|
.values(post_like_form)
|
||||||
.on_conflict((post_id, person_id))
|
.on_conflict((post_id, person_id))
|
||||||
|
@ -249,13 +246,9 @@ impl Likeable for PostLike {
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn remove(
|
async fn remove(pool: &DbPool, person_id: PersonId, post_id: PostId) -> Result<usize, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
person_id: PersonId,
|
|
||||||
post_id: PostId,
|
|
||||||
) -> Result<usize, Error> {
|
|
||||||
use crate::schema::post_like::dsl;
|
use crate::schema::post_like::dsl;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
dsl::post_like
|
dsl::post_like
|
||||||
.filter(dsl::post_id.eq(post_id))
|
.filter(dsl::post_id.eq(post_id))
|
||||||
|
@ -269,12 +262,9 @@ impl Likeable for PostLike {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Saveable for PostSaved {
|
impl Saveable for PostSaved {
|
||||||
type Form = PostSavedForm;
|
type Form = PostSavedForm;
|
||||||
async fn save(
|
async fn save(pool: &DbPool, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
post_saved_form: &PostSavedForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::post_saved::dsl::{person_id, post_id, post_saved};
|
use crate::schema::post_saved::dsl::{person_id, post_id, post_saved};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(post_saved)
|
insert_into(post_saved)
|
||||||
.values(post_saved_form)
|
.values(post_saved_form)
|
||||||
.on_conflict((post_id, person_id))
|
.on_conflict((post_id, person_id))
|
||||||
|
@ -283,12 +273,9 @@ impl Saveable for PostSaved {
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn unsave(
|
async fn unsave(pool: &DbPool, post_saved_form: &PostSavedForm) -> Result<usize, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
post_saved_form: &PostSavedForm,
|
|
||||||
) -> Result<usize, Error> {
|
|
||||||
use crate::schema::post_saved::dsl::{person_id, post_id, post_saved};
|
use crate::schema::post_saved::dsl::{person_id, post_id, post_saved};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
post_saved
|
post_saved
|
||||||
.filter(post_id.eq(post_saved_form.post_id))
|
.filter(post_id.eq(post_saved_form.post_id))
|
||||||
|
@ -302,12 +289,9 @@ impl Saveable for PostSaved {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Readable for PostRead {
|
impl Readable for PostRead {
|
||||||
type Form = PostReadForm;
|
type Form = PostReadForm;
|
||||||
async fn mark_as_read(
|
async fn mark_as_read(pool: &DbPool, post_read_form: &PostReadForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
post_read_form: &PostReadForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
use crate::schema::post_read::dsl::{person_id, post_id, post_read};
|
use crate::schema::post_read::dsl::{person_id, post_id, post_read};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(post_read)
|
insert_into(post_read)
|
||||||
.values(post_read_form)
|
.values(post_read_form)
|
||||||
.on_conflict((post_id, person_id))
|
.on_conflict((post_id, person_id))
|
||||||
|
@ -317,12 +301,9 @@ impl Readable for PostRead {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn mark_as_unread(
|
async fn mark_as_unread(pool: &DbPool, post_read_form: &PostReadForm) -> Result<usize, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
post_read_form: &PostReadForm,
|
|
||||||
) -> Result<usize, Error> {
|
|
||||||
use crate::schema::post_read::dsl::{person_id, post_id, post_read};
|
use crate::schema::post_read::dsl::{person_id, post_id, post_read};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(
|
diesel::delete(
|
||||||
post_read
|
post_read
|
||||||
.filter(post_id.eq(post_read_form.post_id))
|
.filter(post_id.eq(post_read_form.post_id))
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
schema::post_report::dsl::{post_report, resolved, resolver_id, updated},
|
schema::post_report::dsl::{post_report, resolved, resolver_id, updated},
|
||||||
source::post_report::{PostReport, PostReportForm},
|
source::post_report::{PostReport, PostReportForm},
|
||||||
traits::Reportable,
|
traits::Reportable,
|
||||||
utils::{naive_now, DbPool, GetConn},
|
utils::{get_conn, naive_now, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
dsl::{insert_into, update},
|
dsl::{insert_into, update},
|
||||||
|
@ -18,11 +18,8 @@ impl Reportable for PostReport {
|
||||||
type Form = PostReportForm;
|
type Form = PostReportForm;
|
||||||
type IdType = PostReportId;
|
type IdType = PostReportId;
|
||||||
|
|
||||||
async fn report(
|
async fn report(pool: &DbPool, post_report_form: &PostReportForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
post_report_form: &PostReportForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
insert_into(post_report)
|
insert_into(post_report)
|
||||||
.values(post_report_form)
|
.values(post_report_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -30,11 +27,11 @@ impl Reportable for PostReport {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn resolve(
|
async fn resolve(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
report_id: Self::IdType,
|
report_id: Self::IdType,
|
||||||
by_resolver_id: PersonId,
|
by_resolver_id: PersonId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
update(post_report.find(report_id))
|
update(post_report.find(report_id))
|
||||||
.set((
|
.set((
|
||||||
resolved.eq(true),
|
resolved.eq(true),
|
||||||
|
@ -46,11 +43,11 @@ impl Reportable for PostReport {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn unresolve(
|
async fn unresolve(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
report_id: Self::IdType,
|
report_id: Self::IdType,
|
||||||
by_resolver_id: PersonId,
|
by_resolver_id: PersonId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
update(post_report.find(report_id))
|
update(post_report.find(report_id))
|
||||||
.set((
|
.set((
|
||||||
resolved.eq(false),
|
resolved.eq(false),
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
schema::private_message::dsl::{ap_id, private_message, read, recipient_id},
|
schema::private_message::dsl::{ap_id, private_message, read, recipient_id},
|
||||||
source::private_message::{PrivateMessage, PrivateMessageInsertForm, PrivateMessageUpdateForm},
|
source::private_message::{PrivateMessage, PrivateMessageInsertForm, PrivateMessageUpdateForm},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
@ -15,19 +15,16 @@ impl Crud for PrivateMessage {
|
||||||
type InsertForm = PrivateMessageInsertForm;
|
type InsertForm = PrivateMessageInsertForm;
|
||||||
type UpdateForm = PrivateMessageUpdateForm;
|
type UpdateForm = PrivateMessageUpdateForm;
|
||||||
type IdType = PrivateMessageId;
|
type IdType = PrivateMessageId;
|
||||||
async fn read(
|
async fn read(pool: &DbPool, private_message_id: PrivateMessageId) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
private_message_id: PrivateMessageId,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
private_message
|
private_message
|
||||||
.find(private_message_id)
|
.find(private_message_id)
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(private_message)
|
insert_into(private_message)
|
||||||
.values(form)
|
.values(form)
|
||||||
.on_conflict(ap_id)
|
.on_conflict(ap_id)
|
||||||
|
@ -38,18 +35,18 @@ impl Crud for PrivateMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
private_message_id: PrivateMessageId,
|
private_message_id: PrivateMessageId,
|
||||||
form: &Self::UpdateForm,
|
form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(private_message.find(private_message_id))
|
diesel::update(private_message.find(private_message_id))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn delete(mut pool: &mut impl GetConn, pm_id: Self::IdType) -> Result<usize, Error> {
|
async fn delete(pool: &DbPool, pm_id: Self::IdType) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(private_message.find(pm_id))
|
diesel::delete(private_message.find(pm_id))
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
|
@ -58,10 +55,10 @@ impl Crud for PrivateMessage {
|
||||||
|
|
||||||
impl PrivateMessage {
|
impl PrivateMessage {
|
||||||
pub async fn mark_all_as_read(
|
pub async fn mark_all_as_read(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_recipient_id: PersonId,
|
for_recipient_id: PersonId,
|
||||||
) -> Result<Vec<PrivateMessage>, Error> {
|
) -> Result<Vec<PrivateMessage>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(
|
diesel::update(
|
||||||
private_message
|
private_message
|
||||||
.filter(recipient_id.eq(for_recipient_id))
|
.filter(recipient_id.eq(for_recipient_id))
|
||||||
|
@ -73,10 +70,10 @@ impl PrivateMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_from_apub_id(
|
pub async fn read_from_apub_id(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
object_id: Url,
|
object_id: Url,
|
||||||
) -> Result<Option<Self>, LemmyError> {
|
) -> Result<Option<Self>, LemmyError> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let object_id: DbUrl = object_id.into();
|
let object_id: DbUrl = object_id.into();
|
||||||
Ok(
|
Ok(
|
||||||
private_message
|
private_message
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::{
|
||||||
schema::private_message_report::dsl::{private_message_report, resolved, resolver_id, updated},
|
schema::private_message_report::dsl::{private_message_report, resolved, resolver_id, updated},
|
||||||
source::private_message_report::{PrivateMessageReport, PrivateMessageReportForm},
|
source::private_message_report::{PrivateMessageReport, PrivateMessageReportForm},
|
||||||
traits::Reportable,
|
traits::Reportable,
|
||||||
utils::{naive_now, DbPool, GetConn},
|
utils::{get_conn, naive_now, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
dsl::{insert_into, update},
|
dsl::{insert_into, update},
|
||||||
|
@ -18,11 +18,8 @@ impl Reportable for PrivateMessageReport {
|
||||||
type Form = PrivateMessageReportForm;
|
type Form = PrivateMessageReportForm;
|
||||||
type IdType = PrivateMessageReportId;
|
type IdType = PrivateMessageReportId;
|
||||||
|
|
||||||
async fn report(
|
async fn report(pool: &DbPool, pm_report_form: &PrivateMessageReportForm) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
pm_report_form: &PrivateMessageReportForm,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
insert_into(private_message_report)
|
insert_into(private_message_report)
|
||||||
.values(pm_report_form)
|
.values(pm_report_form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
|
@ -30,11 +27,11 @@ impl Reportable for PrivateMessageReport {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn resolve(
|
async fn resolve(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
report_id: Self::IdType,
|
report_id: Self::IdType,
|
||||||
by_resolver_id: PersonId,
|
by_resolver_id: PersonId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
update(private_message_report.find(report_id))
|
update(private_message_report.find(report_id))
|
||||||
.set((
|
.set((
|
||||||
resolved.eq(true),
|
resolved.eq(true),
|
||||||
|
@ -46,11 +43,11 @@ impl Reportable for PrivateMessageReport {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn unresolve(
|
async fn unresolve(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
report_id: Self::IdType,
|
report_id: Self::IdType,
|
||||||
by_resolver_id: PersonId,
|
by_resolver_id: PersonId,
|
||||||
) -> Result<usize, Error> {
|
) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
update(private_message_report.find(report_id))
|
update(private_message_report.find(report_id))
|
||||||
.set((
|
.set((
|
||||||
resolved.eq(false),
|
resolved.eq(false),
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
RegistrationApplicationUpdateForm,
|
RegistrationApplicationUpdateForm,
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
@ -18,33 +18,33 @@ impl Crud for RegistrationApplication {
|
||||||
type UpdateForm = RegistrationApplicationUpdateForm;
|
type UpdateForm = RegistrationApplicationUpdateForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(registration_application)
|
insert_into(registration_application)
|
||||||
.values(form)
|
.values(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read(mut pool: &mut impl GetConn, id_: Self::IdType) -> Result<Self, Error> {
|
async fn read(pool: &DbPool, id_: Self::IdType) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
registration_application.find(id_).first::<Self>(conn).await
|
registration_application.find(id_).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
id_: Self::IdType,
|
id_: Self::IdType,
|
||||||
form: &Self::UpdateForm,
|
form: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(registration_application.find(id_))
|
diesel::update(registration_application.find(id_))
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(mut pool: &mut impl GetConn, id_: Self::IdType) -> Result<usize, Error> {
|
async fn delete(pool: &DbPool, id_: Self::IdType) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(registration_application.find(id_))
|
diesel::delete(registration_application.find(id_))
|
||||||
.execute(conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
|
@ -53,10 +53,10 @@ impl Crud for RegistrationApplication {
|
||||||
|
|
||||||
impl RegistrationApplication {
|
impl RegistrationApplication {
|
||||||
pub async fn find_by_local_user_id(
|
pub async fn find_by_local_user_id(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
local_user_id_: LocalUserId,
|
local_user_id_: LocalUserId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
registration_application
|
registration_application
|
||||||
.filter(local_user_id.eq(local_user_id_))
|
.filter(local_user_id.eq(local_user_id_))
|
||||||
.first::<Self>(conn)
|
.first::<Self>(conn)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
schema::secret::dsl::secret,
|
schema::secret::dsl::secret,
|
||||||
source::secret::Secret,
|
source::secret::Secret,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::result::Error;
|
use diesel::result::Error;
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
@ -9,12 +9,12 @@ use diesel_async::RunQueryDsl;
|
||||||
impl Secret {
|
impl Secret {
|
||||||
/// Initialize the Secrets from the DB.
|
/// Initialize the Secrets from the DB.
|
||||||
/// Warning: You should only call this once.
|
/// Warning: You should only call this once.
|
||||||
pub async fn init(mut pool: &mut impl GetConn) -> Result<Secret, Error> {
|
pub async fn init(pool: &DbPool) -> Result<Secret, Error> {
|
||||||
Self::read_secrets(pool).await
|
Self::read_secrets(pool).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn read_secrets(mut pool: &mut impl GetConn) -> Result<Secret, Error> {
|
async fn read_secrets(pool: &DbPool) -> Result<Secret, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
secret.first::<Secret>(conn).await
|
secret.first::<Secret>(conn).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
||||||
site::{Site, SiteInsertForm, SiteUpdateForm},
|
site::{Site, SiteInsertForm, SiteUpdateForm},
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
@ -19,12 +19,12 @@ impl Crud for Site {
|
||||||
type IdType = SiteId;
|
type IdType = SiteId;
|
||||||
|
|
||||||
/// Use SiteView::read_local, or Site::read_from_apub_id instead
|
/// Use SiteView::read_local, or Site::read_from_apub_id instead
|
||||||
async fn read(_pool: &mut impl GetConn, _site_id: SiteId) -> Result<Self, Error> {
|
async fn read(_pool: &DbPool, _site_id: SiteId) -> Result<Self, Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let is_new_site = match &form.actor_id {
|
let is_new_site = match &form.actor_id {
|
||||||
Some(id_) => Site::read_from_apub_id(pool, id_).await?.is_none(),
|
Some(id_) => Site::read_from_apub_id(pool, id_).await?.is_none(),
|
||||||
None => true,
|
None => true,
|
||||||
|
@ -48,29 +48,26 @@ impl Crud for Site {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn update(
|
async fn update(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
site_id: SiteId,
|
site_id: SiteId,
|
||||||
new_site: &Self::UpdateForm,
|
new_site: &Self::UpdateForm,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::update(site.find(site_id))
|
diesel::update(site.find(site_id))
|
||||||
.set(new_site)
|
.set(new_site)
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(mut pool: &mut impl GetConn, site_id: SiteId) -> Result<usize, Error> {
|
async fn delete(pool: &DbPool, site_id: SiteId) -> Result<usize, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
diesel::delete(site.find(site_id)).execute(conn).await
|
diesel::delete(site.find(site_id)).execute(conn).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Site {
|
impl Site {
|
||||||
pub async fn read_from_apub_id(
|
pub async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result<Option<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
object_id: &DbUrl,
|
|
||||||
) -> Result<Option<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
Ok(
|
Ok(
|
||||||
site
|
site
|
||||||
.filter(actor_id.eq(object_id))
|
.filter(actor_id.eq(object_id))
|
||||||
|
@ -82,8 +79,8 @@ impl Site {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this needs fixed
|
// TODO this needs fixed
|
||||||
pub async fn read_remote_sites(mut pool: &mut impl GetConn) -> Result<Vec<Self>, Error> {
|
pub async fn read_remote_sites(pool: &DbPool) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
site.order_by(id).offset(1).get_results::<Self>(conn).await
|
site.order_by(id).offset(1).get_results::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,18 +2,18 @@ use crate::{
|
||||||
newtypes::LocalSiteId,
|
newtypes::LocalSiteId,
|
||||||
schema::tagline::dsl::{local_site_id, tagline},
|
schema::tagline::dsl::{local_site_id, tagline},
|
||||||
source::tagline::{Tagline, TaglineForm},
|
source::tagline::{Tagline, TaglineForm},
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::{AsyncPgConnection, RunQueryDsl};
|
use diesel_async::{AsyncPgConnection, RunQueryDsl};
|
||||||
|
|
||||||
impl Tagline {
|
impl Tagline {
|
||||||
pub async fn replace(
|
pub async fn replace(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
for_local_site_id: LocalSiteId,
|
for_local_site_id: LocalSiteId,
|
||||||
list_content: Option<Vec<String>>,
|
list_content: Option<Vec<String>>,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
if let Some(list) = list_content {
|
if let Some(list) = list_content {
|
||||||
conn
|
conn
|
||||||
.build_transaction()
|
.build_transaction()
|
||||||
|
@ -54,11 +54,8 @@ impl Tagline {
|
||||||
.get_results::<Self>(conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn get_all(
|
pub async fn get_all(pool: &DbPool, for_local_site_id: LocalSiteId) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
for_local_site_id: LocalSiteId,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
Self::get_all_conn(conn, for_local_site_id).await
|
Self::get_all_conn(conn, for_local_site_id).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
newtypes::{CommunityId, DbUrl, PersonId},
|
newtypes::{CommunityId, DbUrl, PersonId},
|
||||||
utils::{DbPool, GetConn},
|
utils::DbPool,
|
||||||
};
|
};
|
||||||
use diesel::result::Error;
|
use diesel::result::Error;
|
||||||
|
|
||||||
|
@ -9,21 +9,17 @@ pub trait Crud {
|
||||||
type InsertForm;
|
type InsertForm;
|
||||||
type UpdateForm;
|
type UpdateForm;
|
||||||
type IdType;
|
type IdType;
|
||||||
async fn create(mut pool: &mut impl GetConn, form: &Self::InsertForm) -> Result<Self, Error>
|
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn read(mut pool: &mut impl GetConn, id: Self::IdType) -> Result<Self, Error>
|
async fn read(pool: &DbPool, id: Self::IdType) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
/// when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column.
|
/// when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column.
|
||||||
async fn update(
|
async fn update(pool: &DbPool, id: Self::IdType, form: &Self::UpdateForm) -> Result<Self, Error>
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
id: Self::IdType,
|
|
||||||
form: &Self::UpdateForm,
|
|
||||||
) -> Result<Self, Error>
|
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn delete(_pool: &mut impl GetConn, _id: Self::IdType) -> Result<usize, Error>
|
async fn delete(_pool: &DbPool, _id: Self::IdType) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
Self::IdType: Send,
|
Self::IdType: Send,
|
||||||
|
@ -35,17 +31,17 @@ pub trait Crud {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Followable {
|
pub trait Followable {
|
||||||
type Form;
|
type Form;
|
||||||
async fn follow(mut pool: &mut impl GetConn, form: &Self::Form) -> Result<Self, Error>
|
async fn follow(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn follow_accepted(
|
async fn follow_accepted(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
) -> Result<Self, Error>
|
) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn unfollow(mut pool: &mut impl GetConn, form: &Self::Form) -> Result<usize, Error>
|
async fn unfollow(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
@ -53,10 +49,10 @@ pub trait Followable {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Joinable {
|
pub trait Joinable {
|
||||||
type Form;
|
type Form;
|
||||||
async fn join(mut pool: &mut impl GetConn, form: &Self::Form) -> Result<Self, Error>
|
async fn join(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn leave(mut pool: &mut impl GetConn, form: &Self::Form) -> Result<usize, Error>
|
async fn leave(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
@ -65,11 +61,11 @@ pub trait Joinable {
|
||||||
pub trait Likeable {
|
pub trait Likeable {
|
||||||
type Form;
|
type Form;
|
||||||
type IdType;
|
type IdType;
|
||||||
async fn like(mut pool: &mut impl GetConn, form: &Self::Form) -> Result<Self, Error>
|
async fn like(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn remove(
|
async fn remove(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
item_id: Self::IdType,
|
item_id: Self::IdType,
|
||||||
) -> Result<usize, Error>
|
) -> Result<usize, Error>
|
||||||
|
@ -80,10 +76,10 @@ pub trait Likeable {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Bannable {
|
pub trait Bannable {
|
||||||
type Form;
|
type Form;
|
||||||
async fn ban(mut pool: &mut impl GetConn, form: &Self::Form) -> Result<Self, Error>
|
async fn ban(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn unban(mut pool: &mut impl GetConn, form: &Self::Form) -> Result<usize, Error>
|
async fn unban(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
@ -91,10 +87,10 @@ pub trait Bannable {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Saveable {
|
pub trait Saveable {
|
||||||
type Form;
|
type Form;
|
||||||
async fn save(mut pool: &mut impl GetConn, form: &Self::Form) -> Result<Self, Error>
|
async fn save(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn unsave(mut pool: &mut impl GetConn, form: &Self::Form) -> Result<usize, Error>
|
async fn unsave(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
@ -102,10 +98,10 @@ pub trait Saveable {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Blockable {
|
pub trait Blockable {
|
||||||
type Form;
|
type Form;
|
||||||
async fn block(mut pool: &mut impl GetConn, form: &Self::Form) -> Result<Self, Error>
|
async fn block(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn unblock(mut pool: &mut impl GetConn, form: &Self::Form) -> Result<usize, Error>
|
async fn unblock(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
@ -113,10 +109,10 @@ pub trait Blockable {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Readable {
|
pub trait Readable {
|
||||||
type Form;
|
type Form;
|
||||||
async fn mark_as_read(mut pool: &mut impl GetConn, form: &Self::Form) -> Result<Self, Error>
|
async fn mark_as_read(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn mark_as_unread(mut pool: &mut impl GetConn, form: &Self::Form) -> Result<usize, Error>
|
async fn mark_as_unread(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
@ -125,18 +121,18 @@ pub trait Readable {
|
||||||
pub trait Reportable {
|
pub trait Reportable {
|
||||||
type Form;
|
type Form;
|
||||||
type IdType;
|
type IdType;
|
||||||
async fn report(mut pool: &mut impl GetConn, form: &Self::Form) -> Result<Self, Error>
|
async fn report(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn resolve(
|
async fn resolve(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
report_id: Self::IdType,
|
report_id: Self::IdType,
|
||||||
resolver_id: PersonId,
|
resolver_id: PersonId,
|
||||||
) -> Result<usize, Error>
|
) -> Result<usize, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn unresolve(
|
async fn unresolve(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
report_id: Self::IdType,
|
report_id: Self::IdType,
|
||||||
resolver_id: PersonId,
|
resolver_id: PersonId,
|
||||||
) -> Result<usize, Error>
|
) -> Result<usize, Error>
|
||||||
|
@ -153,23 +149,20 @@ pub trait JoinView {
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait ApubActor {
|
pub trait ApubActor {
|
||||||
async fn read_from_apub_id(
|
async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result<Option<Self>, Error>
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
object_id: &DbUrl,
|
|
||||||
) -> Result<Option<Self>, Error>
|
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
/// - actor_name is the name of the community or user to read.
|
/// - actor_name is the name of the community or user to read.
|
||||||
/// - include_deleted, if true, will return communities or users that were deleted/removed
|
/// - include_deleted, if true, will return communities or users that were deleted/removed
|
||||||
async fn read_from_name(
|
async fn read_from_name(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
actor_name: &str,
|
actor_name: &str,
|
||||||
include_deleted: bool,
|
include_deleted: bool,
|
||||||
) -> Result<Self, Error>
|
) -> Result<Self, Error>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
async fn read_from_name_and_domain(
|
async fn read_from_name_and_domain(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
actor_name: &str,
|
actor_name: &str,
|
||||||
protocol_domain: &str,
|
protocol_domain: &str,
|
||||||
) -> Result<Self, Error>
|
) -> Result<Self, Error>
|
||||||
|
|
|
@ -50,48 +50,33 @@ const POOL_TIMEOUT: Option<Duration> = Some(Duration::from_secs(5));
|
||||||
pub type DbPool = Pool<AsyncPgConnection>;
|
pub type DbPool = Pool<AsyncPgConnection>;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait GetConn: Send {
|
pub trait GetConn {
|
||||||
type Conn<'conn>: std::ops::DerefMut<Target = AsyncPgConnection> + Send
|
type Conn: std::ops::Deref<Target = AsyncPgConnection>;
|
||||||
where
|
|
||||||
Self: 'conn;
|
|
||||||
|
|
||||||
// Without `&mut`, `self` would move when this method is called,
|
async fn get_conn(self) -> Result<Self::Conn, DieselError>;
|
||||||
// which prevents calling it multiple times on the same `impl GetConn`.
|
|
||||||
async fn get_conn<'conn>(&mut self) -> Result<Self::Conn<'conn>, DieselError>
|
|
||||||
where
|
|
||||||
'life0: 'conn; //where
|
|
||||||
//Self::Conn: 'life0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<'a> GetConn for &'a DbPool {
|
impl<'a> GetConn for &'a DbPool {
|
||||||
type Conn<'conn> = PooledConnection<AsyncPgConnection>;
|
type Conn = PooledConnection<AsyncPgConnection>;
|
||||||
|
|
||||||
async fn get_conn<'conn>(&mut self) -> Result<Self::Conn<'conn>, DieselError>
|
async fn get_conn(self) -> Result<Self::Conn, DieselError> {
|
||||||
where
|
|
||||||
'life0: 'conn, //where
|
|
||||||
//Self::Conn: 'life0,
|
|
||||||
{
|
|
||||||
self.get().await.map_err(|e| QueryBuilderError(e.into()))
|
self.get().await.map_err(|e| QueryBuilderError(e.into()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl GetConn for AsyncPgConnection {
|
impl<'a> GetConn for &'a mut AsyncPgConnection {
|
||||||
type Conn<'conn> = &'conn mut AsyncPgConnection;
|
type Conn = Self;
|
||||||
|
|
||||||
async fn get_conn<'conn>(&mut self) -> Result<Self::Conn<'conn>, DieselError>
|
async fn get_conn(self) -> Result<Self::Conn, DieselError> {
|
||||||
where
|
|
||||||
'life0: 'conn, //where
|
|
||||||
//Self::Conn: 'life0,
|
|
||||||
{
|
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*pub async fn get_conn<T: GetConn>(getter: T) -> Result<T::Conn, DieselError> {
|
pub async fn get_conn<T: GetConn>(getter: T) -> Result<T::Conn, DieselError> {
|
||||||
getter.get_conn().await
|
getter.get_conn().await
|
||||||
}*/
|
}
|
||||||
|
|
||||||
pub fn get_database_url_from_env() -> Result<String, VarError> {
|
pub fn get_database_url_from_env() -> Result<String, VarError> {
|
||||||
env::var("LEMMY_DATABASE_URL")
|
env::var("LEMMY_DATABASE_URL")
|
||||||
|
|
|
@ -31,7 +31,7 @@ use lemmy_db_schema::{
|
||||||
post::Post,
|
post::Post,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
|
||||||
|
@ -40,11 +40,11 @@ impl CommentReportView {
|
||||||
///
|
///
|
||||||
/// * `report_id` - the report id to obtain
|
/// * `report_id` - the report id to obtain
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
report_id: CommentReportId,
|
report_id: CommentReportId,
|
||||||
my_person_id: PersonId,
|
my_person_id: PersonId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
|
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
|
||||||
|
|
||||||
|
@ -96,14 +96,14 @@ impl CommentReportView {
|
||||||
|
|
||||||
/// Returns the current unresolved post report count for the communities you mod
|
/// Returns the current unresolved post report count for the communities you mod
|
||||||
pub async fn get_report_count(
|
pub async fn get_report_count(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
my_person_id: PersonId,
|
my_person_id: PersonId,
|
||||||
admin: bool,
|
admin: bool,
|
||||||
community_id: Option<CommunityId>,
|
community_id: Option<CommunityId>,
|
||||||
) -> Result<i64, Error> {
|
) -> Result<i64, Error> {
|
||||||
use diesel::dsl::count;
|
use diesel::dsl::count;
|
||||||
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
let mut query = comment_report::table
|
let mut query = comment_report::table
|
||||||
.inner_join(comment::table)
|
.inner_join(comment::table)
|
||||||
|
|
|
@ -36,7 +36,7 @@ use lemmy_db_schema::{
|
||||||
post::Post,
|
post::Post,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{fuzzy_search, limit_and_offset, DbPool, GetConn},
|
utils::{fuzzy_search, get_conn, limit_and_offset, DbPool},
|
||||||
CommentSortType,
|
CommentSortType,
|
||||||
ListingType,
|
ListingType,
|
||||||
};
|
};
|
||||||
|
@ -57,11 +57,11 @@ type CommentViewTuple = (
|
||||||
|
|
||||||
impl CommentView {
|
impl CommentView {
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
comment_id: CommentId,
|
comment_id: CommentId,
|
||||||
my_person_id: Option<PersonId>,
|
my_person_id: Option<PersonId>,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
// The left join below will return None in this case
|
// The left join below will return None in this case
|
||||||
let person_id_join = my_person_id.unwrap_or(PersonId(-1));
|
let person_id_join = my_person_id.unwrap_or(PersonId(-1));
|
||||||
|
@ -431,7 +431,7 @@ mod tests {
|
||||||
inserted_community: Community,
|
inserted_community: Community,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn init_data(mut pool: &mut impl GetConn) -> Data {
|
async fn init_data(pool: &DbPool) -> Data {
|
||||||
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -781,7 +781,7 @@ mod tests {
|
||||||
cleanup(data, pool).await;
|
cleanup(data, pool).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cleanup(data: Data, mut pool: &mut impl GetConn) {
|
async fn cleanup(data: Data, pool: &DbPool) {
|
||||||
CommentLike::remove(pool, data.inserted_person.id, data.inserted_comment_0.id)
|
CommentLike::remove(pool, data.inserted_person.id, data.inserted_comment_0.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -804,7 +804,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn expected_comment_view(data: &Data, mut pool: &mut impl GetConn) -> CommentView {
|
async fn expected_comment_view(data: &Data, pool: &DbPool) -> CommentView {
|
||||||
let agg = CommentAggregates::read(pool, data.inserted_comment_0.id)
|
let agg = CommentAggregates::read(pool, data.inserted_comment_0.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -5,15 +5,15 @@ use lemmy_db_schema::{
|
||||||
newtypes::{CustomEmojiId, LocalSiteId},
|
newtypes::{CustomEmojiId, LocalSiteId},
|
||||||
schema::{custom_emoji, custom_emoji_keyword},
|
schema::{custom_emoji, custom_emoji_keyword},
|
||||||
source::{custom_emoji::CustomEmoji, custom_emoji_keyword::CustomEmojiKeyword},
|
source::{custom_emoji::CustomEmoji, custom_emoji_keyword::CustomEmojiKeyword},
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
type CustomEmojiTuple = (CustomEmoji, Option<CustomEmojiKeyword>);
|
type CustomEmojiTuple = (CustomEmoji, Option<CustomEmojiKeyword>);
|
||||||
|
|
||||||
impl CustomEmojiView {
|
impl CustomEmojiView {
|
||||||
pub async fn get(mut pool: &mut impl GetConn, emoji_id: CustomEmojiId) -> Result<Self, Error> {
|
pub async fn get(pool: &DbPool, emoji_id: CustomEmojiId) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let emojis = custom_emoji::table
|
let emojis = custom_emoji::table
|
||||||
.find(emoji_id)
|
.find(emoji_id)
|
||||||
.left_join(
|
.left_join(
|
||||||
|
@ -35,11 +35,8 @@ impl CustomEmojiView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_all(
|
pub async fn get_all(pool: &DbPool, for_local_site_id: LocalSiteId) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
for_local_site_id: LocalSiteId,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let emojis = custom_emoji::table
|
let emojis = custom_emoji::table
|
||||||
.filter(custom_emoji::local_site_id.eq(for_local_site_id))
|
.filter(custom_emoji::local_site_id.eq(for_local_site_id))
|
||||||
.left_join(
|
.left_join(
|
||||||
|
|
|
@ -7,17 +7,14 @@ use lemmy_db_schema::{
|
||||||
schema::{local_user, person, person_aggregates},
|
schema::{local_user, person, person_aggregates},
|
||||||
source::{local_user::LocalUser, person::Person},
|
source::{local_user::LocalUser, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{functions::lower, DbPool, GetConn},
|
utils::{functions::lower, get_conn, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type LocalUserViewTuple = (LocalUser, Person, PersonAggregates);
|
type LocalUserViewTuple = (LocalUser, Person, PersonAggregates);
|
||||||
|
|
||||||
impl LocalUserView {
|
impl LocalUserView {
|
||||||
pub async fn read(
|
pub async fn read(pool: &DbPool, local_user_id: LocalUserId) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
local_user_id: LocalUserId,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
|
|
||||||
let (local_user, person, counts) = local_user::table
|
let (local_user, person, counts) = local_user::table
|
||||||
.find(local_user_id)
|
.find(local_user_id)
|
||||||
|
@ -37,11 +34,8 @@ impl LocalUserView {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_person(
|
pub async fn read_person(pool: &DbPool, person_id: PersonId) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_id: PersonId,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let (local_user, person, counts) = local_user::table
|
let (local_user, person, counts) = local_user::table
|
||||||
.filter(person::id.eq(person_id))
|
.filter(person::id.eq(person_id))
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
@ -60,8 +54,8 @@ impl LocalUserView {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_from_name(mut pool: &mut impl GetConn, name: &str) -> Result<Self, Error> {
|
pub async fn read_from_name(pool: &DbPool, name: &str) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let (local_user, person, counts) = local_user::table
|
let (local_user, person, counts) = local_user::table
|
||||||
.filter(lower(person::name).eq(name.to_lowercase()))
|
.filter(lower(person::name).eq(name.to_lowercase()))
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
@ -80,11 +74,8 @@ impl LocalUserView {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn find_by_email_or_name(
|
pub async fn find_by_email_or_name(pool: &DbPool, name_or_email: &str) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
name_or_email: &str,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let (local_user, person, counts) = local_user::table
|
let (local_user, person, counts) = local_user::table
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
|
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
|
||||||
|
@ -107,8 +98,8 @@ impl LocalUserView {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn find_by_email(mut pool: &mut impl GetConn, from_email: &str) -> Result<Self, Error> {
|
pub async fn find_by_email(pool: &DbPool, from_email: &str) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let (local_user, person, counts) = local_user::table
|
let (local_user, person, counts) = local_user::table
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
|
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
|
||||||
|
@ -127,8 +118,8 @@ impl LocalUserView {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_admins_with_emails(mut pool: &mut impl GetConn) -> Result<Vec<Self>, Error> {
|
pub async fn list_admins_with_emails(pool: &DbPool) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let res = local_user::table
|
let res = local_user::table
|
||||||
.filter(person::admin.eq(true))
|
.filter(person::admin.eq(true))
|
||||||
.filter(local_user::email.is_not_null())
|
.filter(local_user::email.is_not_null())
|
||||||
|
|
|
@ -28,7 +28,7 @@ use lemmy_db_schema::{
|
||||||
post_report::PostReport,
|
post_report::PostReport,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
|
||||||
|
@ -49,11 +49,11 @@ impl PostReportView {
|
||||||
///
|
///
|
||||||
/// * `report_id` - the report id to obtain
|
/// * `report_id` - the report id to obtain
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
report_id: PostReportId,
|
report_id: PostReportId,
|
||||||
my_person_id: PersonId,
|
my_person_id: PersonId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
|
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
|
||||||
|
|
||||||
let (
|
let (
|
||||||
|
@ -121,13 +121,13 @@ impl PostReportView {
|
||||||
|
|
||||||
/// returns the current unresolved post report count for the communities you mod
|
/// returns the current unresolved post report count for the communities you mod
|
||||||
pub async fn get_report_count(
|
pub async fn get_report_count(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
my_person_id: PersonId,
|
my_person_id: PersonId,
|
||||||
admin: bool,
|
admin: bool,
|
||||||
community_id: Option<CommunityId>,
|
community_id: Option<CommunityId>,
|
||||||
) -> Result<i64, Error> {
|
) -> Result<i64, Error> {
|
||||||
use diesel::dsl::count;
|
use diesel::dsl::count;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let mut query = post_report::table
|
let mut query = post_report::table
|
||||||
.inner_join(post::table)
|
.inner_join(post::table)
|
||||||
.filter(post_report::resolved.eq(false))
|
.filter(post_report::resolved.eq(false))
|
||||||
|
|
|
@ -40,7 +40,7 @@ use lemmy_db_schema::{
|
||||||
post::{Post, PostRead, PostSaved},
|
post::{Post, PostRead, PostSaved},
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{fuzzy_search, limit_and_offset, DbPool, GetConn},
|
utils::{fuzzy_search, get_conn, limit_and_offset, DbPool},
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
@ -65,12 +65,12 @@ sql_function!(fn coalesce(x: sql_types::Nullable<sql_types::BigInt>, y: sql_type
|
||||||
|
|
||||||
impl PostView {
|
impl PostView {
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
post_id: PostId,
|
post_id: PostId,
|
||||||
my_person_id: Option<PersonId>,
|
my_person_id: Option<PersonId>,
|
||||||
is_mod_or_admin: Option<bool>,
|
is_mod_or_admin: Option<bool>,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
// The left join below will return None in this case
|
// The left join below will return None in this case
|
||||||
let person_id_join = my_person_id.unwrap_or(PersonId(-1));
|
let person_id_join = my_person_id.unwrap_or(PersonId(-1));
|
||||||
|
@ -510,7 +510,7 @@ mod tests {
|
||||||
inserted_post: Post,
|
inserted_post: Post,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn init_data(mut pool: &mut impl GetConn) -> Data {
|
async fn init_data(pool: &DbPool) -> Data {
|
||||||
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
|
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -930,7 +930,7 @@ mod tests {
|
||||||
cleanup(data, pool).await;
|
cleanup(data, pool).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn cleanup(data: Data, mut pool: &mut impl GetConn) {
|
async fn cleanup(data: Data, pool: &DbPool) {
|
||||||
let num_deleted = Post::delete(pool, data.inserted_post.id).await.unwrap();
|
let num_deleted = Post::delete(pool, data.inserted_post.id).await.unwrap();
|
||||||
Community::delete(pool, data.inserted_community.id)
|
Community::delete(pool, data.inserted_community.id)
|
||||||
.await
|
.await
|
||||||
|
@ -946,7 +946,7 @@ mod tests {
|
||||||
assert_eq!(1, num_deleted);
|
assert_eq!(1, num_deleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn expected_post_view(data: &Data, mut pool: &mut impl GetConn) -> PostView {
|
async fn expected_post_view(data: &Data, pool: &DbPool) -> PostView {
|
||||||
let (inserted_person, inserted_community, inserted_post) = (
|
let (inserted_person, inserted_community, inserted_post) = (
|
||||||
&data.inserted_person,
|
&data.inserted_person,
|
||||||
&data.inserted_community,
|
&data.inserted_community,
|
||||||
|
|
|
@ -10,7 +10,7 @@ use lemmy_db_schema::{
|
||||||
private_message_report::PrivateMessageReport,
|
private_message_report::PrivateMessageReport,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
|
||||||
|
@ -26,11 +26,8 @@ impl PrivateMessageReportView {
|
||||||
/// returns the PrivateMessageReportView for the provided report_id
|
/// returns the PrivateMessageReportView for the provided report_id
|
||||||
///
|
///
|
||||||
/// * `report_id` - the report id to obtain
|
/// * `report_id` - the report id to obtain
|
||||||
pub async fn read(
|
pub async fn read(pool: &DbPool, report_id: PrivateMessageReportId) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
report_id: PrivateMessageReportId,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
|
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
|
||||||
|
|
||||||
let (private_message_report, private_message, private_message_creator, creator, resolver) =
|
let (private_message_report, private_message, private_message_creator, creator, resolver) =
|
||||||
|
@ -67,9 +64,9 @@ impl PrivateMessageReportView {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current unresolved post report count for the communities you mod
|
/// Returns the current unresolved post report count for the communities you mod
|
||||||
pub async fn get_report_count(mut pool: &mut impl GetConn) -> Result<i64, Error> {
|
pub async fn get_report_count(pool: &DbPool) -> Result<i64, Error> {
|
||||||
use diesel::dsl::count;
|
use diesel::dsl::count;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
private_message_report::table
|
private_message_report::table
|
||||||
.inner_join(private_message::table)
|
.inner_join(private_message::table)
|
||||||
|
|
|
@ -14,7 +14,7 @@ use lemmy_db_schema::{
|
||||||
schema::{person, private_message},
|
schema::{person, private_message},
|
||||||
source::{person::Person, private_message::PrivateMessage},
|
source::{person::Person, private_message::PrivateMessage},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
@ -22,11 +22,8 @@ use typed_builder::TypedBuilder;
|
||||||
type PrivateMessageViewTuple = (PrivateMessage, Person, Person);
|
type PrivateMessageViewTuple = (PrivateMessage, Person, Person);
|
||||||
|
|
||||||
impl PrivateMessageView {
|
impl PrivateMessageView {
|
||||||
pub async fn read(
|
pub async fn read(pool: &DbPool, private_message_id: PrivateMessageId) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
private_message_id: PrivateMessageId,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
|
|
||||||
let (private_message, creator, recipient) = private_message::table
|
let (private_message, creator, recipient) = private_message::table
|
||||||
|
@ -52,12 +49,9 @@ impl PrivateMessageView {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the number of unread messages
|
/// Gets the number of unread messages
|
||||||
pub async fn get_unread_messages(
|
pub async fn get_unread_messages(pool: &DbPool, my_person_id: PersonId) -> Result<i64, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
my_person_id: PersonId,
|
|
||||||
) -> Result<i64, Error> {
|
|
||||||
use diesel::dsl::count;
|
use diesel::dsl::count;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
private_message::table
|
private_message::table
|
||||||
.filter(private_message::read.eq(false))
|
.filter(private_message::read.eq(false))
|
||||||
.filter(private_message::recipient_id.eq(my_person_id))
|
.filter(private_message::recipient_id.eq(my_person_id))
|
||||||
|
|
|
@ -16,7 +16,7 @@ use lemmy_db_schema::{
|
||||||
registration_application::RegistrationApplication,
|
registration_application::RegistrationApplication,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
|
||||||
|
@ -24,11 +24,8 @@ type RegistrationApplicationViewTuple =
|
||||||
(RegistrationApplication, LocalUser, Person, Option<Person>);
|
(RegistrationApplication, LocalUser, Person, Option<Person>);
|
||||||
|
|
||||||
impl RegistrationApplicationView {
|
impl RegistrationApplicationView {
|
||||||
pub async fn read(
|
pub async fn read(pool: &DbPool, registration_application_id: i32) -> Result<Self, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
registration_application_id: i32,
|
|
||||||
) -> Result<Self, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
|
|
||||||
let (registration_application, creator_local_user, creator, admin) =
|
let (registration_application, creator_local_user, creator, admin) =
|
||||||
|
@ -61,11 +58,8 @@ impl RegistrationApplicationView {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current unread registration_application count
|
/// Returns the current unread registration_application count
|
||||||
pub async fn get_unread_count(
|
pub async fn get_unread_count(pool: &DbPool, verified_email_only: bool) -> Result<i64, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
verified_email_only: bool,
|
|
||||||
) -> Result<i64, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
|
|
||||||
let mut query = registration_application::table
|
let mut query = registration_application::table
|
||||||
|
|
|
@ -5,12 +5,12 @@ use lemmy_db_schema::{
|
||||||
aggregates::structs::SiteAggregates,
|
aggregates::structs::SiteAggregates,
|
||||||
schema::{local_site, local_site_rate_limit, site, site_aggregates},
|
schema::{local_site, local_site_rate_limit, site, site_aggregates},
|
||||||
source::{local_site::LocalSite, local_site_rate_limit::LocalSiteRateLimit, site::Site},
|
source::{local_site::LocalSite, local_site_rate_limit::LocalSiteRateLimit, site::Site},
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl SiteView {
|
impl SiteView {
|
||||||
pub async fn read_local(mut pool: &mut impl GetConn) -> Result<Self, Error> {
|
pub async fn read_local(pool: &DbPool) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let (mut site, local_site, local_site_rate_limit, counts) = site::table
|
let (mut site, local_site, local_site_rate_limit, counts) = site::table
|
||||||
.inner_join(local_site::table)
|
.inner_join(local_site::table)
|
||||||
.inner_join(
|
.inner_join(
|
||||||
|
|
|
@ -33,7 +33,7 @@ use lemmy_db_schema::{
|
||||||
post::Post,
|
post::Post,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
CommentSortType,
|
CommentSortType,
|
||||||
};
|
};
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
@ -55,11 +55,11 @@ type CommentReplyViewTuple = (
|
||||||
|
|
||||||
impl CommentReplyView {
|
impl CommentReplyView {
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
comment_reply_id: CommentReplyId,
|
comment_reply_id: CommentReplyId,
|
||||||
my_person_id: Option<PersonId>,
|
my_person_id: Option<PersonId>,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
|
|
||||||
// The left join below will return None in this case
|
// The left join below will return None in this case
|
||||||
|
@ -155,13 +155,10 @@ impl CommentReplyView {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the number of unread replies
|
/// Gets the number of unread replies
|
||||||
pub async fn get_unread_replies(
|
pub async fn get_unread_replies(pool: &DbPool, my_person_id: PersonId) -> Result<i64, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
my_person_id: PersonId,
|
|
||||||
) -> Result<i64, Error> {
|
|
||||||
use diesel::dsl::count;
|
use diesel::dsl::count;
|
||||||
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
comment_reply::table
|
comment_reply::table
|
||||||
.inner_join(comment::table)
|
.inner_join(comment::table)
|
||||||
|
|
|
@ -6,17 +6,14 @@ use lemmy_db_schema::{
|
||||||
schema::{community, community_block, person},
|
schema::{community, community_block, person},
|
||||||
source::{community::Community, person::Person},
|
source::{community::Community, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type CommunityBlockViewTuple = (Person, Community);
|
type CommunityBlockViewTuple = (Person, Community);
|
||||||
|
|
||||||
impl CommunityBlockView {
|
impl CommunityBlockView {
|
||||||
pub async fn for_person(
|
pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_id: PersonId,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let res = community_block::table
|
let res = community_block::table
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
|
|
|
@ -6,17 +6,14 @@ use lemmy_db_schema::{
|
||||||
schema::{community, community_follower, person},
|
schema::{community, community_follower, person},
|
||||||
source::{community::Community, person::Person},
|
source::{community::Community, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type CommunityFollowerViewTuple = (Community, Person);
|
type CommunityFollowerViewTuple = (Community, Person);
|
||||||
|
|
||||||
impl CommunityFollowerView {
|
impl CommunityFollowerView {
|
||||||
pub async fn for_community(
|
pub async fn for_community(pool: &DbPool, community_id: CommunityId) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
community_id: CommunityId,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let res = community_follower::table
|
let res = community_follower::table
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
@ -29,11 +26,8 @@ impl CommunityFollowerView {
|
||||||
Ok(res.into_iter().map(Self::from_tuple).collect())
|
Ok(res.into_iter().map(Self::from_tuple).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn for_person(
|
pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_id: PersonId,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let res = community_follower::table
|
let res = community_follower::table
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
|
|
@ -6,17 +6,14 @@ use lemmy_db_schema::{
|
||||||
schema::{community, community_moderator, person},
|
schema::{community, community_moderator, person},
|
||||||
source::{community::Community, person::Person},
|
source::{community::Community, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type CommunityModeratorViewTuple = (Community, Person);
|
type CommunityModeratorViewTuple = (Community, Person);
|
||||||
|
|
||||||
impl CommunityModeratorView {
|
impl CommunityModeratorView {
|
||||||
pub async fn for_community(
|
pub async fn for_community(pool: &DbPool, community_id: CommunityId) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
community_id: CommunityId,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let res = community_moderator::table
|
let res = community_moderator::table
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
@ -28,11 +25,8 @@ impl CommunityModeratorView {
|
||||||
Ok(res.into_iter().map(Self::from_tuple).collect())
|
Ok(res.into_iter().map(Self::from_tuple).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn for_person(
|
pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_id: PersonId,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let res = community_moderator::table
|
let res = community_moderator::table
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
@ -48,8 +42,8 @@ impl CommunityModeratorView {
|
||||||
|
|
||||||
/// Finds all communities first mods / creators
|
/// Finds all communities first mods / creators
|
||||||
/// Ideally this should be a group by, but diesel doesn't support it yet
|
/// Ideally this should be a group by, but diesel doesn't support it yet
|
||||||
pub async fn get_community_first_mods(mut pool: &mut impl GetConn) -> Result<Vec<Self>, Error> {
|
pub async fn get_community_first_mods(pool: &DbPool) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let res = community_moderator::table
|
let res = community_moderator::table
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
|
|
@ -5,16 +5,16 @@ use lemmy_db_schema::{
|
||||||
newtypes::{CommunityId, PersonId},
|
newtypes::{CommunityId, PersonId},
|
||||||
schema::{community, community_person_ban, person},
|
schema::{community, community_person_ban, person},
|
||||||
source::{community::Community, person::Person},
|
source::{community::Community, person::Person},
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
impl CommunityPersonBanView {
|
impl CommunityPersonBanView {
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
from_person_id: PersonId,
|
from_person_id: PersonId,
|
||||||
from_community_id: CommunityId,
|
from_community_id: CommunityId,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let (community, person) = community_person_ban::table
|
let (community, person) = community_person_ban::table
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
|
|
|
@ -19,7 +19,7 @@ use lemmy_db_schema::{
|
||||||
local_user::LocalUser,
|
local_user::LocalUser,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{fuzzy_search, limit_and_offset, DbPool, GetConn},
|
utils::{fuzzy_search, get_conn, limit_and_offset, DbPool},
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
|
@ -34,12 +34,12 @@ type CommunityViewTuple = (
|
||||||
|
|
||||||
impl CommunityView {
|
impl CommunityView {
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
my_person_id: Option<PersonId>,
|
my_person_id: Option<PersonId>,
|
||||||
is_mod_or_admin: Option<bool>,
|
is_mod_or_admin: Option<bool>,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
// The left join below will return None in this case
|
// The left join below will return None in this case
|
||||||
let person_id_join = my_person_id.unwrap_or(PersonId(-1));
|
let person_id_join = my_person_id.unwrap_or(PersonId(-1));
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ impl CommunityView {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn is_mod_or_admin(
|
pub async fn is_mod_or_admin(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
) -> Result<bool, Error> {
|
) -> Result<bool, Error> {
|
||||||
|
|
|
@ -6,17 +6,14 @@ use lemmy_db_schema::{
|
||||||
schema::{person, person_block},
|
schema::{person, person_block},
|
||||||
source::person::Person,
|
source::person::Person,
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{DbPool, GetConn},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type PersonBlockViewTuple = (Person, Person);
|
type PersonBlockViewTuple = (Person, Person);
|
||||||
|
|
||||||
impl PersonBlockView {
|
impl PersonBlockView {
|
||||||
pub async fn for_person(
|
pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
person_id: PersonId,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let target_person_alias = diesel::alias!(person as person1);
|
let target_person_alias = diesel::alias!(person as person1);
|
||||||
|
|
||||||
let res = person_block::table
|
let res = person_block::table
|
||||||
|
|
|
@ -34,7 +34,7 @@ use lemmy_db_schema::{
|
||||||
post::Post,
|
post::Post,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
CommentSortType,
|
CommentSortType,
|
||||||
};
|
};
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
@ -56,11 +56,11 @@ type PersonMentionViewTuple = (
|
||||||
|
|
||||||
impl PersonMentionView {
|
impl PersonMentionView {
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
person_mention_id: PersonMentionId,
|
person_mention_id: PersonMentionId,
|
||||||
my_person_id: Option<PersonId>,
|
my_person_id: Option<PersonId>,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
|
|
||||||
// The left join below will return None in this case
|
// The left join below will return None in this case
|
||||||
|
@ -156,12 +156,9 @@ impl PersonMentionView {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the number of unread mentions
|
/// Gets the number of unread mentions
|
||||||
pub async fn get_unread_mentions(
|
pub async fn get_unread_mentions(pool: &DbPool, my_person_id: PersonId) -> Result<i64, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
my_person_id: PersonId,
|
|
||||||
) -> Result<i64, Error> {
|
|
||||||
use diesel::dsl::count;
|
use diesel::dsl::count;
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
person_mention::table
|
person_mention::table
|
||||||
.inner_join(comment::table)
|
.inner_join(comment::table)
|
||||||
|
|
|
@ -14,7 +14,7 @@ use lemmy_db_schema::{
|
||||||
schema::{person, person_aggregates},
|
schema::{person, person_aggregates},
|
||||||
source::person::Person,
|
source::person::Person,
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{fuzzy_search, limit_and_offset, DbPool, GetConn},
|
utils::{fuzzy_search, get_conn, limit_and_offset, DbPool},
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
|
@ -23,8 +23,8 @@ use typed_builder::TypedBuilder;
|
||||||
type PersonViewTuple = (Person, PersonAggregates);
|
type PersonViewTuple = (Person, PersonAggregates);
|
||||||
|
|
||||||
impl PersonView {
|
impl PersonView {
|
||||||
pub async fn read(mut pool: &mut impl GetConn, person_id: PersonId) -> Result<Self, Error> {
|
pub async fn read(pool: &DbPool, person_id: PersonId) -> Result<Self, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let res = person::table
|
let res = person::table
|
||||||
.find(person_id)
|
.find(person_id)
|
||||||
.inner_join(person_aggregates::table)
|
.inner_join(person_aggregates::table)
|
||||||
|
@ -34,8 +34,8 @@ impl PersonView {
|
||||||
Ok(Self::from_tuple(res))
|
Ok(Self::from_tuple(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn admins(mut pool: &mut impl GetConn) -> Result<Vec<Self>, Error> {
|
pub async fn admins(pool: &DbPool) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let admins = person::table
|
let admins = person::table
|
||||||
.inner_join(person_aggregates::table)
|
.inner_join(person_aggregates::table)
|
||||||
.select((person::all_columns, person_aggregates::all_columns))
|
.select((person::all_columns, person_aggregates::all_columns))
|
||||||
|
@ -48,8 +48,8 @@ impl PersonView {
|
||||||
Ok(admins.into_iter().map(Self::from_tuple).collect())
|
Ok(admins.into_iter().map(Self::from_tuple).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn banned(mut pool: &mut impl GetConn) -> Result<Vec<Self>, Error> {
|
pub async fn banned(pool: &DbPool) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let banned = person::table
|
let banned = person::table
|
||||||
.inner_join(person_aggregates::table)
|
.inner_join(person_aggregates::table)
|
||||||
.select((person::all_columns, person_aggregates::all_columns))
|
.select((person::all_columns, person_aggregates::all_columns))
|
||||||
|
|
|
@ -14,17 +14,14 @@ use lemmy_db_schema::{
|
||||||
schema::{admin_purge_comment, person, post},
|
schema::{admin_purge_comment, person, post},
|
||||||
source::{moderator::AdminPurgeComment, person::Person, post::Post},
|
source::{moderator::AdminPurgeComment, person::Person, post::Post},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type AdminPurgeCommentViewTuple = (AdminPurgeComment, Option<Person>, Post);
|
type AdminPurgeCommentViewTuple = (AdminPurgeComment, Option<Person>, Post);
|
||||||
|
|
||||||
impl AdminPurgeCommentView {
|
impl AdminPurgeCommentView {
|
||||||
pub async fn list(
|
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
params: ModlogListParams,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
|
|
|
@ -14,17 +14,14 @@ use lemmy_db_schema::{
|
||||||
schema::{admin_purge_community, person},
|
schema::{admin_purge_community, person},
|
||||||
source::{moderator::AdminPurgeCommunity, person::Person},
|
source::{moderator::AdminPurgeCommunity, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type AdminPurgeCommunityViewTuple = (AdminPurgeCommunity, Option<Person>);
|
type AdminPurgeCommunityViewTuple = (AdminPurgeCommunity, Option<Person>);
|
||||||
|
|
||||||
impl AdminPurgeCommunityView {
|
impl AdminPurgeCommunityView {
|
||||||
pub async fn list(
|
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
params: ModlogListParams,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
|
|
|
@ -14,17 +14,14 @@ use lemmy_db_schema::{
|
||||||
schema::{admin_purge_person, person},
|
schema::{admin_purge_person, person},
|
||||||
source::{moderator::AdminPurgePerson, person::Person},
|
source::{moderator::AdminPurgePerson, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type AdminPurgePersonViewTuple = (AdminPurgePerson, Option<Person>);
|
type AdminPurgePersonViewTuple = (AdminPurgePerson, Option<Person>);
|
||||||
|
|
||||||
impl AdminPurgePersonView {
|
impl AdminPurgePersonView {
|
||||||
pub async fn list(
|
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
params: ModlogListParams,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
|
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
|
|
@ -14,17 +14,14 @@ use lemmy_db_schema::{
|
||||||
schema::{admin_purge_post, community, person},
|
schema::{admin_purge_post, community, person},
|
||||||
source::{community::Community, moderator::AdminPurgePost, person::Person},
|
source::{community::Community, moderator::AdminPurgePost, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type AdminPurgePostViewTuple = (AdminPurgePost, Option<Person>, Community);
|
type AdminPurgePostViewTuple = (AdminPurgePost, Option<Person>, Community);
|
||||||
|
|
||||||
impl AdminPurgePostView {
|
impl AdminPurgePostView {
|
||||||
pub async fn list(
|
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
params: ModlogListParams,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
|
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
|
|
@ -14,17 +14,14 @@ use lemmy_db_schema::{
|
||||||
schema::{community, mod_add_community, person},
|
schema::{community, mod_add_community, person},
|
||||||
source::{community::Community, moderator::ModAddCommunity, person::Person},
|
source::{community::Community, moderator::ModAddCommunity, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModAddCommunityViewTuple = (ModAddCommunity, Option<Person>, Community, Person);
|
type ModAddCommunityViewTuple = (ModAddCommunity, Option<Person>, Community, Person);
|
||||||
|
|
||||||
impl ModAddCommunityView {
|
impl ModAddCommunityView {
|
||||||
pub async fn list(
|
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
params: ModlogListParams,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
|
|
@ -14,17 +14,14 @@ use lemmy_db_schema::{
|
||||||
schema::{mod_add, person},
|
schema::{mod_add, person},
|
||||||
source::{moderator::ModAdd, person::Person},
|
source::{moderator::ModAdd, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModAddViewTuple = (ModAdd, Option<Person>, Person);
|
type ModAddViewTuple = (ModAdd, Option<Person>, Person);
|
||||||
|
|
||||||
impl ModAddView {
|
impl ModAddView {
|
||||||
pub async fn list(
|
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
params: ModlogListParams,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
|
|
@ -14,17 +14,14 @@ use lemmy_db_schema::{
|
||||||
schema::{community, mod_ban_from_community, person},
|
schema::{community, mod_ban_from_community, person},
|
||||||
source::{community::Community, moderator::ModBanFromCommunity, person::Person},
|
source::{community::Community, moderator::ModBanFromCommunity, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModBanFromCommunityViewTuple = (ModBanFromCommunity, Option<Person>, Community, Person);
|
type ModBanFromCommunityViewTuple = (ModBanFromCommunity, Option<Person>, Community, Person);
|
||||||
|
|
||||||
impl ModBanFromCommunityView {
|
impl ModBanFromCommunityView {
|
||||||
pub async fn list(
|
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
params: ModlogListParams,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
|
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
|
|
|
@ -14,17 +14,14 @@ use lemmy_db_schema::{
|
||||||
schema::{mod_ban, person},
|
schema::{mod_ban, person},
|
||||||
source::{moderator::ModBan, person::Person},
|
source::{moderator::ModBan, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModBanViewTuple = (ModBan, Option<Person>, Person);
|
type ModBanViewTuple = (ModBan, Option<Person>, Person);
|
||||||
|
|
||||||
impl ModBanView {
|
impl ModBanView {
|
||||||
pub async fn list(
|
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
params: ModlogListParams,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
|
|
@ -14,17 +14,14 @@ use lemmy_db_schema::{
|
||||||
schema::{community, mod_feature_post, person, post},
|
schema::{community, mod_feature_post, person, post},
|
||||||
source::{community::Community, moderator::ModFeaturePost, person::Person, post::Post},
|
source::{community::Community, moderator::ModFeaturePost, person::Person, post::Post},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModFeaturePostViewTuple = (ModFeaturePost, Option<Person>, Post, Community);
|
type ModFeaturePostViewTuple = (ModFeaturePost, Option<Person>, Post, Community);
|
||||||
|
|
||||||
impl ModFeaturePostView {
|
impl ModFeaturePostView {
|
||||||
pub async fn list(
|
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
params: ModlogListParams,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
|
|
@ -14,18 +14,15 @@ use lemmy_db_schema::{
|
||||||
schema::{community, mod_hide_community, person},
|
schema::{community, mod_hide_community, person},
|
||||||
source::{community::Community, moderator::ModHideCommunity, person::Person},
|
source::{community::Community, moderator::ModHideCommunity, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModHideCommunityViewTuple = (ModHideCommunity, Option<Person>, Community);
|
type ModHideCommunityViewTuple = (ModHideCommunity, Option<Person>, Community);
|
||||||
|
|
||||||
impl ModHideCommunityView {
|
impl ModHideCommunityView {
|
||||||
// Pass in mod_id as admin_id because only admins can do this action
|
// Pass in mod_id as admin_id because only admins can do this action
|
||||||
pub async fn list(
|
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
params: ModlogListParams,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
|
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
|
|
@ -14,17 +14,14 @@ use lemmy_db_schema::{
|
||||||
schema::{community, mod_lock_post, person, post},
|
schema::{community, mod_lock_post, person, post},
|
||||||
source::{community::Community, moderator::ModLockPost, person::Person, post::Post},
|
source::{community::Community, moderator::ModLockPost, person::Person, post::Post},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModLockPostViewTuple = (ModLockPost, Option<Person>, Post, Community);
|
type ModLockPostViewTuple = (ModLockPost, Option<Person>, Post, Community);
|
||||||
|
|
||||||
impl ModLockPostView {
|
impl ModLockPostView {
|
||||||
pub async fn list(
|
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
params: ModlogListParams,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
|
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
|
|
|
@ -20,7 +20,7 @@ use lemmy_db_schema::{
|
||||||
post::Post,
|
post::Post,
|
||||||
},
|
},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModRemoveCommentViewTuple = (
|
type ModRemoveCommentViewTuple = (
|
||||||
|
@ -33,11 +33,8 @@ type ModRemoveCommentViewTuple = (
|
||||||
);
|
);
|
||||||
|
|
||||||
impl ModRemoveCommentView {
|
impl ModRemoveCommentView {
|
||||||
pub async fn list(
|
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
params: ModlogListParams,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let person_alias_1 = diesel::alias!(lemmy_db_schema::schema::person as person1);
|
let person_alias_1 = diesel::alias!(lemmy_db_schema::schema::person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
|
|
|
@ -14,17 +14,14 @@ use lemmy_db_schema::{
|
||||||
schema::{community, mod_remove_community, person},
|
schema::{community, mod_remove_community, person},
|
||||||
source::{community::Community, moderator::ModRemoveCommunity, person::Person},
|
source::{community::Community, moderator::ModRemoveCommunity, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModRemoveCommunityTuple = (ModRemoveCommunity, Option<Person>, Community);
|
type ModRemoveCommunityTuple = (ModRemoveCommunity, Option<Person>, Community);
|
||||||
|
|
||||||
impl ModRemoveCommunityView {
|
impl ModRemoveCommunityView {
|
||||||
pub async fn list(
|
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
params: ModlogListParams,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
let show_mod_names = !params.hide_modlog_names;
|
let show_mod_names = !params.hide_modlog_names;
|
||||||
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
let show_mod_names_expr = show_mod_names.as_sql::<diesel::sql_types::Bool>();
|
||||||
|
|
|
@ -14,17 +14,14 @@ use lemmy_db_schema::{
|
||||||
schema::{community, mod_remove_post, person, post},
|
schema::{community, mod_remove_post, person, post},
|
||||||
source::{community::Community, moderator::ModRemovePost, person::Person, post::Post},
|
source::{community::Community, moderator::ModRemovePost, person::Person, post::Post},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModRemovePostViewTuple = (ModRemovePost, Option<Person>, Post, Community);
|
type ModRemovePostViewTuple = (ModRemovePost, Option<Person>, Post, Community);
|
||||||
|
|
||||||
impl ModRemovePostView {
|
impl ModRemovePostView {
|
||||||
pub async fn list(
|
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
params: ModlogListParams,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
|
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
|
|
|
@ -14,17 +14,14 @@ use lemmy_db_schema::{
|
||||||
schema::{community, mod_transfer_community, person},
|
schema::{community, mod_transfer_community, person},
|
||||||
source::{community::Community, moderator::ModTransferCommunity, person::Person},
|
source::{community::Community, moderator::ModTransferCommunity, person::Person},
|
||||||
traits::JoinView,
|
traits::JoinView,
|
||||||
utils::{limit_and_offset, DbPool, GetConn},
|
utils::{get_conn, limit_and_offset, DbPool},
|
||||||
};
|
};
|
||||||
|
|
||||||
type ModTransferCommunityViewTuple = (ModTransferCommunity, Option<Person>, Community, Person);
|
type ModTransferCommunityViewTuple = (ModTransferCommunity, Option<Person>, Community, Person);
|
||||||
|
|
||||||
impl ModTransferCommunityView {
|
impl ModTransferCommunityView {
|
||||||
pub async fn list(
|
pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
|
||||||
mut pool: &mut impl GetConn,
|
let conn = &mut get_conn(pool).await?;
|
||||||
params: ModlogListParams,
|
|
||||||
) -> Result<Vec<Self>, Error> {
|
|
||||||
let conn = &mut *pool.get_conn().await?;
|
|
||||||
|
|
||||||
let person_alias_1 = diesel::alias!(person as person1);
|
let person_alias_1 = diesel::alias!(person as person1);
|
||||||
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
|
||||||
|
|
|
@ -6,7 +6,7 @@ use lemmy_db_schema::{
|
||||||
newtypes::LocalUserId,
|
newtypes::LocalUserId,
|
||||||
source::{community::Community, local_user::LocalUser, person::Person},
|
source::{community::Community, local_user::LocalUser, person::Person},
|
||||||
traits::{ApubActor, Crud},
|
traits::{ApubActor, Crud},
|
||||||
utils::{DbPool, GetConn},
|
utils::DbPool,
|
||||||
CommentSortType,
|
CommentSortType,
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
|
@ -227,7 +227,7 @@ async fn get_feed(
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn get_feed_user(
|
async fn get_feed_user(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
sort_type: &SortType,
|
sort_type: &SortType,
|
||||||
limit: &i64,
|
limit: &i64,
|
||||||
page: &i64,
|
page: &i64,
|
||||||
|
@ -262,7 +262,7 @@ async fn get_feed_user(
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn get_feed_community(
|
async fn get_feed_community(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
sort_type: &SortType,
|
sort_type: &SortType,
|
||||||
limit: &i64,
|
limit: &i64,
|
||||||
page: &i64,
|
page: &i64,
|
||||||
|
@ -300,7 +300,7 @@ async fn get_feed_community(
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn get_feed_front(
|
async fn get_feed_front(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
jwt_secret: &str,
|
jwt_secret: &str,
|
||||||
sort_type: &SortType,
|
sort_type: &SortType,
|
||||||
limit: &i64,
|
limit: &i64,
|
||||||
|
@ -341,7 +341,7 @@ async fn get_feed_front(
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn get_feed_inbox(
|
async fn get_feed_inbox(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
jwt_secret: &str,
|
jwt_secret: &str,
|
||||||
jwt: &str,
|
jwt: &str,
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
|
|
|
@ -33,16 +33,13 @@ use lemmy_db_schema::{
|
||||||
site::{Site, SiteInsertForm, SiteUpdateForm},
|
site::{Site, SiteInsertForm, SiteUpdateForm},
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::{naive_now, DbPool, GetConn},
|
utils::{get_conn, naive_now, DbPool},
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, settings::structs::Settings};
|
use lemmy_utils::{error::LemmyError, settings::structs::Settings};
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub async fn run_advanced_migrations(
|
pub async fn run_advanced_migrations(pool: &DbPool, settings: &Settings) -> Result<(), LemmyError> {
|
||||||
mut pool: &mut impl GetConn,
|
|
||||||
settings: &Settings,
|
|
||||||
) -> Result<(), LemmyError> {
|
|
||||||
let protocol_and_hostname = &settings.get_protocol_and_hostname();
|
let protocol_and_hostname = &settings.get_protocol_and_hostname();
|
||||||
user_updates_2020_04_02(pool, protocol_and_hostname).await?;
|
user_updates_2020_04_02(pool, protocol_and_hostname).await?;
|
||||||
community_updates_2020_04_02(pool, protocol_and_hostname).await?;
|
community_updates_2020_04_02(pool, protocol_and_hostname).await?;
|
||||||
|
@ -59,11 +56,11 @@ pub async fn run_advanced_migrations(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn user_updates_2020_04_02(
|
async fn user_updates_2020_04_02(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
use lemmy_db_schema::schema::person::dsl::{actor_id, local, person};
|
use lemmy_db_schema::schema::person::dsl::{actor_id, local, person};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
info!("Running user_updates_2020_04_02");
|
info!("Running user_updates_2020_04_02");
|
||||||
|
|
||||||
|
@ -97,11 +94,11 @@ async fn user_updates_2020_04_02(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn community_updates_2020_04_02(
|
async fn community_updates_2020_04_02(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
use lemmy_db_schema::schema::community::dsl::{actor_id, community, local};
|
use lemmy_db_schema::schema::community::dsl::{actor_id, community, local};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
info!("Running community_updates_2020_04_02");
|
info!("Running community_updates_2020_04_02");
|
||||||
|
|
||||||
|
@ -136,11 +133,11 @@ async fn community_updates_2020_04_02(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn post_updates_2020_04_03(
|
async fn post_updates_2020_04_03(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
use lemmy_db_schema::schema::post::dsl::{ap_id, local, post};
|
use lemmy_db_schema::schema::post::dsl::{ap_id, local, post};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
info!("Running post_updates_2020_04_03");
|
info!("Running post_updates_2020_04_03");
|
||||||
|
|
||||||
|
@ -171,11 +168,11 @@ async fn post_updates_2020_04_03(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn comment_updates_2020_04_03(
|
async fn comment_updates_2020_04_03(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
use lemmy_db_schema::schema::comment::dsl::{ap_id, comment, local};
|
use lemmy_db_schema::schema::comment::dsl::{ap_id, comment, local};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
info!("Running comment_updates_2020_04_03");
|
info!("Running comment_updates_2020_04_03");
|
||||||
|
|
||||||
|
@ -206,11 +203,11 @@ async fn comment_updates_2020_04_03(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn private_message_updates_2020_05_05(
|
async fn private_message_updates_2020_05_05(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
use lemmy_db_schema::schema::private_message::dsl::{ap_id, local, private_message};
|
use lemmy_db_schema::schema::private_message::dsl::{ap_id, local, private_message};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
info!("Running private_message_updates_2020_05_05");
|
info!("Running private_message_updates_2020_05_05");
|
||||||
|
|
||||||
|
@ -243,11 +240,11 @@ async fn private_message_updates_2020_05_05(
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn post_thumbnail_url_updates_2020_07_27(
|
async fn post_thumbnail_url_updates_2020_07_27(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
use lemmy_db_schema::schema::post::dsl::{post, thumbnail_url};
|
use lemmy_db_schema::schema::post::dsl::{post, thumbnail_url};
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
|
||||||
info!("Running post_thumbnail_url_updates_2020_07_27");
|
info!("Running post_thumbnail_url_updates_2020_07_27");
|
||||||
|
|
||||||
|
@ -274,8 +271,8 @@ async fn post_thumbnail_url_updates_2020_07_27(
|
||||||
|
|
||||||
/// We are setting inbox and follower URLs for local and remote actors alike, because for now
|
/// We are setting inbox and follower URLs for local and remote actors alike, because for now
|
||||||
/// all federated instances are also Lemmy and use the same URL scheme.
|
/// all federated instances are also Lemmy and use the same URL scheme.
|
||||||
async fn apub_columns_2021_02_02(mut pool: &mut impl GetConn) -> Result<(), LemmyError> {
|
async fn apub_columns_2021_02_02(pool: &DbPool) -> Result<(), LemmyError> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
info!("Running apub_columns_2021_02_02");
|
info!("Running apub_columns_2021_02_02");
|
||||||
{
|
{
|
||||||
use lemmy_db_schema::schema::person::dsl::{inbox_url, person, shared_inbox_url};
|
use lemmy_db_schema::schema::person::dsl::{inbox_url, person, shared_inbox_url};
|
||||||
|
@ -332,7 +329,7 @@ async fn apub_columns_2021_02_02(mut pool: &mut impl GetConn) -> Result<(), Lemm
|
||||||
/// Before this point, there is only a single value in the site table which refers to the local
|
/// Before this point, there is only a single value in the site table which refers to the local
|
||||||
/// Lemmy instance, so thats all we need to update.
|
/// Lemmy instance, so thats all we need to update.
|
||||||
async fn instance_actor_2022_01_28(
|
async fn instance_actor_2022_01_28(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
protocol_and_hostname: &str,
|
protocol_and_hostname: &str,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
info!("Running instance_actor_2021_09_29");
|
info!("Running instance_actor_2021_09_29");
|
||||||
|
@ -361,8 +358,8 @@ async fn instance_actor_2022_01_28(
|
||||||
/// key field is empty, generate a new keypair. It would be possible to regenerate only the pubkey,
|
/// key field is empty, generate a new keypair. It would be possible to regenerate only the pubkey,
|
||||||
/// but thats more complicated and has no benefit, as federation is already broken for these actors.
|
/// but thats more complicated and has no benefit, as federation is already broken for these actors.
|
||||||
/// https://github.com/LemmyNet/lemmy/issues/2347
|
/// https://github.com/LemmyNet/lemmy/issues/2347
|
||||||
async fn regenerate_public_keys_2022_07_05(mut pool: &mut impl GetConn) -> Result<(), LemmyError> {
|
async fn regenerate_public_keys_2022_07_05(pool: &DbPool) -> Result<(), LemmyError> {
|
||||||
let conn = &mut *pool.get_conn().await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
info!("Running regenerate_public_keys_2022_07_05");
|
info!("Running regenerate_public_keys_2022_07_05");
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -416,7 +413,7 @@ async fn regenerate_public_keys_2022_07_05(mut pool: &mut impl GetConn) -> Resul
|
||||||
/// If a site already exists, the DB migration should generate a local_site row.
|
/// If a site already exists, the DB migration should generate a local_site row.
|
||||||
/// This will only be run for brand new sites.
|
/// This will only be run for brand new sites.
|
||||||
async fn initialize_local_site_2022_10_10(
|
async fn initialize_local_site_2022_10_10(
|
||||||
mut pool: &mut impl GetConn,
|
pool: &DbPool,
|
||||||
settings: &Settings,
|
settings: &Settings,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
info!("Running initialize_local_site_2022_10_10");
|
info!("Running initialize_local_site_2022_10_10");
|
||||||
|
|
Loading…
Reference in a new issue