mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 03:11:08 +00:00
Fix some things
This commit is contained in:
parent
3e4059aabb
commit
2bf8574bc8
24 changed files with 94 additions and 94 deletions
|
@ -39,7 +39,7 @@ pub struct VerifyUrlData(pub DbPool);
|
||||||
impl UrlVerifier for VerifyUrlData {
|
impl UrlVerifier for VerifyUrlData {
|
||||||
async fn verify(&self, url: &Url) -> Result<(), &'static str> {
|
async fn verify(&self, url: &Url) -> Result<(), &'static str> {
|
||||||
let mut conn = get_conn(&self.0).await.expect("get connection");
|
let mut conn = get_conn(&self.0).await.expect("get connection");
|
||||||
let local_site_data = fetch_local_site_data(&mut *conn)
|
let local_site_data = fetch_local_site_data(conn)
|
||||||
.await
|
.await
|
||||||
.expect("read local site data");
|
.expect("read local site data");
|
||||||
check_apub_id_valid(url, &local_site_data)?;
|
check_apub_id_valid(url, &local_site_data)?;
|
||||||
|
@ -99,12 +99,12 @@ pub(crate) struct LocalSiteData {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn fetch_local_site_data(
|
pub(crate) async fn fetch_local_site_data(
|
||||||
mut conn: impl DbConn,
|
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(&mut *conn).await.ok();
|
let local_site = LocalSite::read(get_conn(pool).await?).await.ok();
|
||||||
let allowed_instances = Instance::allowlist(&mut *conn).await?;
|
let allowed_instances = Instance::allowlist(get_conn(pool).await?).await?;
|
||||||
let blocked_instances = Instance::blocklist(&mut *conn).await?;
|
let blocked_instances = Instance::blocklist(get_conn(pool).await?).await?;
|
||||||
|
|
||||||
Ok(LocalSiteData {
|
Ok(LocalSiteData {
|
||||||
local_site,
|
local_site,
|
||||||
|
|
|
@ -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::DbConn,
|
utils::{DbConn, 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,16 +92,16 @@ 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(conn, comment))]
|
#[tracing::instrument(skip(conn, comment))]
|
||||||
async fn get_comment_parent_creator(
|
async fn get_comment_parent_creator(
|
||||||
mut conn: impl DbConn,
|
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() {
|
||||||
let parent_comment = Comment::read(&mut *conn, parent_comment_id).await?;
|
let parent_comment = Comment::read(get_conn(pool).await?, parent_comment_id).await?;
|
||||||
parent_comment.creator_id
|
parent_comment.creator_id
|
||||||
} else {
|
} else {
|
||||||
let parent_post_id = comment.post_id;
|
let parent_post_id = comment.post_id;
|
||||||
let parent_post = Post::read(&mut *conn, parent_post_id).await?;
|
let parent_post = Post::read(get_conn(pool).await?, parent_post_id).await?;
|
||||||
parent_post.creator_id
|
parent_post.creator_id
|
||||||
};
|
};
|
||||||
Ok(Person::read(&mut *conn, parent_creator_id).await?.into())
|
Ok(Person::read(get_conn(pool).await?, parent_creator_id).await?.into())
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ impl Object for ApubComment {
|
||||||
verify_domains_match(note.attributed_to.inner(), note.id.inner())?;
|
verify_domains_match(note.attributed_to.inner(), note.id.inner())?;
|
||||||
verify_is_public(¬e.to, ¬e.cc)?;
|
verify_is_public(¬e.to, ¬e.cc)?;
|
||||||
let community = note.community(context).await?;
|
let community = note.community(context).await?;
|
||||||
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
|
let local_site_data = fetch_local_site_data(context.pool()).await?;
|
||||||
|
|
||||||
check_apub_id_valid_with_strictness(
|
check_apub_id_valid_with_strictness(
|
||||||
note.id.inner(),
|
note.id.inner(),
|
||||||
|
|
|
@ -188,7 +188,7 @@ impl ApubCommunity {
|
||||||
) -> Result<Vec<Url>, LemmyError> {
|
) -> Result<Vec<Url>, LemmyError> {
|
||||||
let id = self.id;
|
let id = self.id;
|
||||||
|
|
||||||
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
|
let local_site_data = fetch_local_site_data(context.pool()).await?;
|
||||||
let follows = CommunityFollowerView::for_community(context.conn().await?, id).await?;
|
let follows = CommunityFollowerView::for_community(context.conn().await?, id).await?;
|
||||||
let inboxes: Vec<Url> = follows
|
let inboxes: Vec<Url> = follows
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
@ -197,7 +197,7 @@ pub(in crate::objects) async fn fetch_instance_actor_for_object<T: Into<Url> + C
|
||||||
|
|
||||||
pub(crate) async fn remote_instance_inboxes(mut conn: impl DbConn) -> Result<Vec<Url>, LemmyError> {
|
pub(crate) async fn remote_instance_inboxes(mut conn: impl DbConn) -> Result<Vec<Url>, LemmyError> {
|
||||||
Ok(
|
Ok(
|
||||||
Site::read_remote_sites(&mut *conn)
|
Site::read_remote_sites(conn)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| ApubSite::from(s).shared_inbox_or_inbox())
|
.map(|s| ApubSite::from(s).shared_inbox_or_inbox())
|
||||||
|
|
|
@ -118,7 +118,7 @@ impl Object for ApubPerson {
|
||||||
expected_domain: &Url,
|
expected_domain: &Url,
|
||||||
context: &Data<Self::DataType>,
|
context: &Data<Self::DataType>,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
|
let local_site_data = fetch_local_site_data(context.pool()).await?;
|
||||||
let slur_regex = &local_site_opt_to_slur_regex(&local_site_data.local_site);
|
let slur_regex = &local_site_opt_to_slur_regex(&local_site_data.local_site);
|
||||||
|
|
||||||
check_slurs(&person.preferred_username, slur_regex)?;
|
check_slurs(&person.preferred_username, slur_regex)?;
|
||||||
|
|
|
@ -143,7 +143,7 @@ impl Object for ApubPost {
|
||||||
verify_is_remote_object(page.id.inner(), context.settings())?;
|
verify_is_remote_object(page.id.inner(), context.settings())?;
|
||||||
};
|
};
|
||||||
|
|
||||||
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
|
let local_site_data = fetch_local_site_data(context.pool()).await?;
|
||||||
|
|
||||||
let community = page.community(context).await?;
|
let community = page.community(context).await?;
|
||||||
check_apub_id_valid_with_strictness(
|
check_apub_id_valid_with_strictness(
|
||||||
|
|
|
@ -102,7 +102,7 @@ impl Object for ApubPrivateMessage {
|
||||||
verify_domains_match(note.id.inner(), expected_domain)?;
|
verify_domains_match(note.id.inner(), expected_domain)?;
|
||||||
verify_domains_match(note.attributed_to.inner(), note.id.inner())?;
|
verify_domains_match(note.attributed_to.inner(), note.id.inner())?;
|
||||||
|
|
||||||
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
|
let local_site_data = fetch_local_site_data(context.pool()).await?;
|
||||||
|
|
||||||
check_apub_id_valid_with_strictness(
|
check_apub_id_valid_with_strictness(
|
||||||
note.id.inner(),
|
note.id.inner(),
|
||||||
|
|
|
@ -80,7 +80,7 @@ impl Group {
|
||||||
expected_domain: &Url,
|
expected_domain: &Url,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let local_site_data = fetch_local_site_data(context.conn().await?).await?;
|
let local_site_data = fetch_local_site_data(context.pool()).await?;
|
||||||
|
|
||||||
check_apub_id_valid_with_strictness(
|
check_apub_id_valid_with_strictness(
|
||||||
self.id.inner(),
|
self.id.inner(),
|
||||||
|
|
|
@ -35,7 +35,7 @@ impl LanguageTag {
|
||||||
lang: LanguageId,
|
lang: LanguageId,
|
||||||
mut conn: impl DbConn,
|
mut conn: impl DbConn,
|
||||||
) -> Result<Option<LanguageTag>, LemmyError> {
|
) -> Result<Option<LanguageTag>, LemmyError> {
|
||||||
let lang = Language::read_from_id(&mut *conn, lang).await?;
|
let lang = Language::read_from_id(conn, lang).await?;
|
||||||
|
|
||||||
// undetermined
|
// undetermined
|
||||||
if lang.id == UNDETERMINED_ID {
|
if lang.id == UNDETERMINED_ID {
|
||||||
|
@ -55,7 +55,7 @@ impl LanguageTag {
|
||||||
let mut langs = Vec::<Language>::new();
|
let mut langs = Vec::<Language>::new();
|
||||||
|
|
||||||
for l in lang_ids {
|
for l in lang_ids {
|
||||||
langs.push(Language::read_from_id(&mut *conn, l).await?);
|
langs.push(Language::read_from_id(conn, l).await?);
|
||||||
}
|
}
|
||||||
|
|
||||||
let langs = langs
|
let langs = langs
|
||||||
|
@ -73,7 +73,7 @@ impl LanguageTag {
|
||||||
mut conn: impl DbConn,
|
mut conn: impl DbConn,
|
||||||
) -> 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(&mut *conn, identifier.as_deref()).await?;
|
let language = Language::read_id_from_code(conn, identifier.as_deref()).await?;
|
||||||
|
|
||||||
Ok(language)
|
Ok(language)
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ impl LanguageTag {
|
||||||
|
|
||||||
for l in langs {
|
for l in langs {
|
||||||
let id = l.identifier;
|
let id = l.identifier;
|
||||||
language_ids.push(Language::read_id_from_code(&mut *conn, Some(&id)).await?);
|
language_ids.push(Language::read_id_from_code(conn, Some(&id)).await?);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(language_ids.into_iter().flatten().collect())
|
Ok(language_ids.into_iter().flatten().collect())
|
||||||
|
|
|
@ -11,7 +11,7 @@ impl CommentAggregates {
|
||||||
pub async fn read(mut conn: impl DbConn, comment_id: CommentId) -> Result<Self, Error> {
|
pub async fn read(mut conn: impl DbConn, comment_id: CommentId) -> Result<Self, Error> {
|
||||||
comment_aggregates::table
|
comment_aggregates::table
|
||||||
.filter(comment_aggregates::comment_id.eq(comment_id))
|
.filter(comment_aggregates::comment_id.eq(comment_id))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ impl CommentAggregates {
|
||||||
comment_aggregates::score,
|
comment_aggregates::score,
|
||||||
comment_aggregates::published,
|
comment_aggregates::published,
|
||||||
)))
|
)))
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ impl CommunityAggregates {
|
||||||
pub async fn read(mut conn: impl DbConn, community_id: CommunityId) -> Result<Self, Error> {
|
pub async fn read(mut conn: impl DbConn, community_id: CommunityId) -> Result<Self, Error> {
|
||||||
community_aggregates::table
|
community_aggregates::table
|
||||||
.filter(community_aggregates::community_id.eq(community_id))
|
.filter(community_aggregates::community_id.eq(community_id))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ impl PersonAggregates {
|
||||||
pub async fn read(mut conn: impl DbConn, person_id: PersonId) -> Result<Self, Error> {
|
pub async fn read(mut conn: impl DbConn, person_id: PersonId) -> Result<Self, Error> {
|
||||||
person_aggregates::table
|
person_aggregates::table
|
||||||
.filter(person_aggregates::person_id.eq(person_id))
|
.filter(person_aggregates::person_id.eq(person_id))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ impl PersonPostAggregates {
|
||||||
.on_conflict((person_id, post_id))
|
.on_conflict((person_id, post_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(form)
|
.set(form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
|
@ -28,7 +28,7 @@ impl PersonPostAggregates {
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
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>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ impl PostAggregates {
|
||||||
pub async fn read(mut conn: impl DbConn, post_id: PostId) -> Result<Self, Error> {
|
pub async fn read(mut conn: impl DbConn, post_id: PostId) -> Result<Self, Error> {
|
||||||
post_aggregates::table
|
post_aggregates::table
|
||||||
.filter(post_aggregates::post_id.eq(post_id))
|
.filter(post_aggregates::post_id.eq(post_id))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ impl PostAggregates {
|
||||||
post_aggregates::newest_comment_time_necro,
|
post_aggregates::newest_comment_time_necro,
|
||||||
)),
|
)),
|
||||||
))
|
))
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
impl SiteAggregates {
|
impl SiteAggregates {
|
||||||
pub async fn read(mut conn: impl DbConn) -> Result<Self, Error> {
|
pub async fn read(mut conn: impl DbConn) -> Result<Self, Error> {
|
||||||
site_aggregates::table.first::<Self>(&mut *conn).await
|
site_aggregates::table.first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,13 @@ impl Crud for Activity {
|
||||||
type UpdateForm = ActivityUpdateForm;
|
type UpdateForm = ActivityUpdateForm;
|
||||||
type IdType = i32;
|
type IdType = i32;
|
||||||
async fn read(mut conn: impl DbConn, activity_id: i32) -> Result<Self, Error> {
|
async fn read(mut conn: impl DbConn, activity_id: i32) -> Result<Self, Error> {
|
||||||
activity.find(activity_id).first::<Self>(&mut *conn).await
|
activity.find(activity_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, new_activity: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl DbConn, new_activity: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
insert_into(activity)
|
insert_into(activity)
|
||||||
.values(new_activity)
|
.values(new_activity)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,12 +31,12 @@ impl Crud for Activity {
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
diesel::update(activity.find(activity_id))
|
diesel::update(activity.find(activity_id))
|
||||||
.set(new_activity)
|
.set(new_activity)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn delete(mut conn: impl DbConn, activity_id: i32) -> Result<usize, Error> {
|
async fn delete(mut conn: impl DbConn, activity_id: i32) -> Result<usize, Error> {
|
||||||
diesel::delete(activity.find(activity_id))
|
diesel::delete(activity.find(activity_id))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ impl Activity {
|
||||||
) -> Result<Activity, Error> {
|
) -> Result<Activity, Error> {
|
||||||
activity
|
activity
|
||||||
.filter(ap_id.eq(object_id))
|
.filter(ap_id.eq(object_id))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,14 +62,14 @@ 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 conn: impl DbConn,
|
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 mut lang_ids = convert_update_languages(&mut *conn, language_ids).await?;
|
let mut lang_ids = convert_update_languages(get_conn(pool).await?, language_ids).await?;
|
||||||
|
|
||||||
// No need to update if languages are unchanged
|
// No need to update if languages are unchanged
|
||||||
let current = LocalUserLanguage::read(&mut *conn, for_local_user_id).await?;
|
let current = LocalUserLanguage::read(get_conn(pool).await?, for_local_user_id).await?;
|
||||||
if current == lang_ids {
|
if current == lang_ids {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ impl LocalUserLanguage {
|
||||||
lang_ids.push(UNDETERMINED_ID);
|
lang_ids.push(UNDETERMINED_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
conn
|
get_conn(pool).await?
|
||||||
.build_transaction()
|
.build_transaction()
|
||||||
.run(|conn| {
|
.run(|conn| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
|
@ -118,7 +118,7 @@ impl SiteLanguage {
|
||||||
.inner_join(site_language::table)
|
.inner_join(site_language::table)
|
||||||
.order(site_language::id)
|
.order(site_language::id)
|
||||||
.select(site_language::language_id)
|
.select(site_language::language_id)
|
||||||
.load(&mut *conn)
|
.load(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,32 +127,32 @@ impl SiteLanguage {
|
||||||
.filter(site_language::site_id.eq(for_site_id))
|
.filter(site_language::site_id.eq(for_site_id))
|
||||||
.order(site_language::language_id)
|
.order(site_language::language_id)
|
||||||
.select(site_language::language_id)
|
.select(site_language::language_id)
|
||||||
.load(&mut *conn)
|
.load(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read(mut conn: impl DbConn, for_site_id: SiteId) -> Result<Vec<LanguageId>, Error> {
|
pub async fn read(pool: &DbPool, for_site_id: SiteId) -> Result<Vec<LanguageId>, Error> {
|
||||||
let langs = Self::read_raw(&mut *conn, for_site_id).await?;
|
let langs = Self::read_raw(get_conn(pool).await?, for_site_id).await?;
|
||||||
|
|
||||||
convert_read_languages(&mut *conn, langs).await
|
convert_read_languages(get_conn(pool).await?, langs).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update(
|
pub async fn update(
|
||||||
mut conn: impl DbConn,
|
pool: &DbPool,
|
||||||
language_ids: Vec<LanguageId>,
|
language_ids: Vec<LanguageId>,
|
||||||
site: &Site,
|
site: &Site,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
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(&mut *conn, language_ids).await?;
|
let lang_ids = convert_update_languages(get_conn(pool).await?, language_ids).await?;
|
||||||
|
|
||||||
// No need to update if languages are unchanged
|
// No need to update if languages are unchanged
|
||||||
let current = SiteLanguage::read(&mut *conn, site.id).await?;
|
let current = SiteLanguage::read(get_conn(pool).await?, site.id).await?;
|
||||||
if current == lang_ids {
|
if current == lang_ids {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
conn
|
get_conn(pool).await?
|
||||||
.build_transaction()
|
.build_transaction()
|
||||||
.run(|conn| {
|
.run(|conn| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
|
@ -198,7 +198,7 @@ impl CommunityLanguage {
|
||||||
.filter(language_id.eq(for_language_id))
|
.filter(language_id.eq(for_language_id))
|
||||||
.filter(community_id.eq(for_community_id)),
|
.filter(community_id.eq(for_community_id)),
|
||||||
))
|
))
|
||||||
.get_result(&mut *conn)
|
.get_result(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if is_allowed {
|
if is_allowed {
|
||||||
|
@ -216,7 +216,7 @@ impl CommunityLanguage {
|
||||||
/// community language, and it shouldnt be possible to post content in languages which are not
|
/// community language, and it shouldnt be possible to post content in languages which are not
|
||||||
/// allowed by local site.
|
/// allowed by local site.
|
||||||
async fn limit_languages(
|
async fn limit_languages(
|
||||||
mut conn: impl DbConn,
|
pool: &DbPool,
|
||||||
for_instance_id: InstanceId,
|
for_instance_id: InstanceId,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
use crate::schema::{
|
use crate::schema::{
|
||||||
|
@ -230,12 +230,12 @@ impl CommunityLanguage {
|
||||||
.filter(c::instance_id.eq(for_instance_id))
|
.filter(c::instance_id.eq(for_instance_id))
|
||||||
.filter(sl::language_id.is_null())
|
.filter(sl::language_id.is_null())
|
||||||
.select(cl::language_id)
|
.select(cl::language_id)
|
||||||
.get_results(&mut *conn)
|
.get_results(get_conn(pool).await?)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
for c in community_languages {
|
for c in community_languages {
|
||||||
delete(cl::community_language.filter(cl::language_id.eq(c)))
|
delete(cl::community_language.filter(cl::language_id.eq(c)))
|
||||||
.execute(&mut *conn)
|
.execute(get_conn(pool).await?)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -250,35 +250,35 @@ impl CommunityLanguage {
|
||||||
.filter(community_id.eq(for_community_id))
|
.filter(community_id.eq(for_community_id))
|
||||||
.order(language_id)
|
.order(language_id)
|
||||||
.select(language_id)
|
.select(language_id)
|
||||||
.get_results(&mut *conn)
|
.get_results(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read(
|
pub async fn read(
|
||||||
mut conn: impl DbConn,
|
pool: &DbPool
|
||||||
for_community_id: CommunityId,
|
for_community_id: CommunityId,
|
||||||
) -> Result<Vec<LanguageId>, Error> {
|
) -> Result<Vec<LanguageId>, Error> {
|
||||||
let langs = Self::read_raw(&mut *conn, for_community_id).await?;
|
let langs = Self::read_raw(get_conn(pool).await?, for_community_id).await?;
|
||||||
convert_read_languages(&mut *conn, langs).await
|
convert_read_languages(get_conn(pool).await?, langs).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update(
|
pub async fn update(
|
||||||
mut conn: impl DbConn,
|
pool: &DbPool,
|
||||||
mut language_ids: Vec<LanguageId>,
|
mut language_ids: Vec<LanguageId>,
|
||||||
for_community_id: CommunityId,
|
for_community_id: CommunityId,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
if language_ids.is_empty() {
|
if language_ids.is_empty() {
|
||||||
language_ids = SiteLanguage::read_local_raw(&mut *conn).await?;
|
language_ids = SiteLanguage::read_local_raw(get_conn(pool).await?).await?;
|
||||||
}
|
}
|
||||||
let lang_ids = convert_update_languages(&mut *conn, language_ids).await?;
|
let lang_ids = convert_update_languages(get_conn(pool).await?, language_ids).await?;
|
||||||
|
|
||||||
// No need to update if languages are unchanged
|
// No need to update if languages are unchanged
|
||||||
let current = CommunityLanguage::read_raw(&mut *conn, for_community_id).await?;
|
let current = CommunityLanguage::read_raw(get_conn(pool).await?, for_community_id).await?;
|
||||||
if current == lang_ids {
|
if current == lang_ids {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
conn
|
get_conn(pool).await?
|
||||||
.build_transaction()
|
.build_transaction()
|
||||||
.run(|conn| {
|
.run(|conn| {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
|
@ -316,7 +316,7 @@ pub async fn default_post_language(
|
||||||
.filter(ul::local_user_id.eq(local_user_id))
|
.filter(ul::local_user_id.eq(local_user_id))
|
||||||
.filter(cl::community_id.eq(community_id))
|
.filter(cl::community_id.eq(community_id))
|
||||||
.select(cl::language_id)
|
.select(cl::language_id)
|
||||||
.get_results::<LanguageId>(&mut *conn)
|
.get_results::<LanguageId>(conn)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if intersection.len() == 1 {
|
if intersection.len() == 1 {
|
||||||
|
@ -358,7 +358,7 @@ async fn convert_read_languages(
|
||||||
use crate::schema::language::dsl::{id, language};
|
use crate::schema::language::dsl::{id, language};
|
||||||
let count: i64 = language
|
let count: i64 = language
|
||||||
.select(count(id))
|
.select(count(id))
|
||||||
.first(&mut *conn)
|
.first(conn)
|
||||||
.await
|
.await
|
||||||
.expect("read number of languages");
|
.expect("read number of languages");
|
||||||
count as usize
|
count as usize
|
||||||
|
|
|
@ -18,12 +18,12 @@ impl CaptchaAnswer {
|
||||||
pub async fn insert(mut conn: impl DbConn, captcha: &CaptchaAnswerForm) -> Result<Self, Error> {
|
pub async fn insert(mut conn: impl DbConn, captcha: &CaptchaAnswerForm) -> Result<Self, Error> {
|
||||||
insert_into(captcha_answer)
|
insert_into(captcha_answer)
|
||||||
.values(captcha)
|
.values(captcha)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn check_captcha(
|
pub async fn check_captcha(
|
||||||
mut conn: impl DbConn,
|
pool: &DbPool,
|
||||||
to_check: CheckCaptchaAnswer,
|
to_check: CheckCaptchaAnswer,
|
||||||
) -> Result<bool, Error> {
|
) -> Result<bool, Error> {
|
||||||
// fetch requested captcha
|
// fetch requested captcha
|
||||||
|
@ -32,12 +32,12 @@ impl CaptchaAnswer {
|
||||||
.filter((uuid).eq(to_check.uuid))
|
.filter((uuid).eq(to_check.uuid))
|
||||||
.filter(lower(answer).eq(to_check.answer.to_lowercase().clone())),
|
.filter(lower(answer).eq(to_check.answer.to_lowercase().clone())),
|
||||||
))
|
))
|
||||||
.get_result::<bool>(&mut *conn)
|
.get_result::<bool>(get_conn(pool).await?)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// delete checked captcha
|
// delete checked captcha
|
||||||
delete(captcha_answer.filter(uuid.eq(to_check.uuid)))
|
delete(captcha_answer.filter(uuid.eq(to_check.uuid)))
|
||||||
.execute(&mut *conn)
|
.execute(get_conn(pool).await?)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(captcha_exists)
|
Ok(captcha_exists)
|
||||||
|
|
|
@ -34,7 +34,7 @@ impl Comment {
|
||||||
deleted.eq(true),
|
deleted.eq(true),
|
||||||
updated.eq(naive_now()),
|
updated.eq(naive_now()),
|
||||||
))
|
))
|
||||||
.get_results::<Self>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,12 +45,12 @@ impl Comment {
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
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>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
mut conn: impl DbConn,
|
pool: &DbPool,
|
||||||
comment_form: &CommentInsertForm,
|
comment_form: &CommentInsertForm,
|
||||||
parent_path: Option<&Ltree>,
|
parent_path: Option<&Ltree>,
|
||||||
) -> Result<Comment, Error> {
|
) -> Result<Comment, Error> {
|
||||||
|
@ -60,7 +60,7 @@ impl Comment {
|
||||||
.on_conflict(ap_id)
|
.on_conflict(ap_id)
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(comment_form)
|
.set(comment_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(get_conn(pool).await?)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if let Ok(comment_insert) = inserted_comment {
|
if let Ok(comment_insert) = inserted_comment {
|
||||||
|
@ -78,7 +78,7 @@ impl Comment {
|
||||||
|
|
||||||
let updated_comment = diesel::update(comment.find(comment_id))
|
let updated_comment = diesel::update(comment.find(comment_id))
|
||||||
.set(path.eq(ltree))
|
.set(path.eq(ltree))
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(get_conn(pool).await?)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Update the child count for the parent comment_aggregates
|
// Update the child count for the parent comment_aggregates
|
||||||
|
@ -111,7 +111,7 @@ where ca.comment_id = c.id"
|
||||||
);
|
);
|
||||||
|
|
||||||
sql_query(update_child_count_stmt)
|
sql_query(update_child_count_stmt)
|
||||||
.execute(&mut *conn)
|
.execute(get_conn(pool).await?)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ where ca.comment_id = c.id"
|
||||||
Ok(
|
Ok(
|
||||||
comment
|
comment
|
||||||
.filter(ap_id.eq(object_id))
|
.filter(ap_id.eq(object_id))
|
||||||
.first::<Comment>(&mut *conn)
|
.first::<Comment>(conn)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.map(Into::into),
|
.map(Into::into),
|
||||||
|
@ -153,12 +153,12 @@ impl Crud for Comment {
|
||||||
type UpdateForm = CommentUpdateForm;
|
type UpdateForm = CommentUpdateForm;
|
||||||
type IdType = CommentId;
|
type IdType = CommentId;
|
||||||
async fn read(mut conn: impl DbConn, comment_id: CommentId) -> Result<Self, Error> {
|
async fn read(mut conn: impl DbConn, comment_id: CommentId) -> Result<Self, Error> {
|
||||||
comment.find(comment_id).first::<Self>(&mut *conn).await
|
comment.find(comment_id).first::<Self>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(mut conn: impl DbConn, comment_id: CommentId) -> Result<usize, Error> {
|
async fn delete(mut conn: impl DbConn, comment_id: CommentId) -> Result<usize, Error> {
|
||||||
diesel::delete(comment.find(comment_id))
|
diesel::delete(comment.find(comment_id))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ impl Crud for Comment {
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
diesel::update(comment.find(comment_id))
|
diesel::update(comment.find(comment_id))
|
||||||
.set(comment_form)
|
.set(comment_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ impl Likeable for CommentLike {
|
||||||
.on_conflict((comment_id, person_id))
|
.on_conflict((comment_id, person_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(comment_like_form)
|
.set(comment_like_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn remove(
|
async fn remove(
|
||||||
|
@ -204,7 +204,7 @@ impl Likeable for CommentLike {
|
||||||
.filter(comment_id.eq(comment_id_))
|
.filter(comment_id.eq(comment_id_))
|
||||||
.filter(person_id.eq(person_id_)),
|
.filter(person_id.eq(person_id_)),
|
||||||
)
|
)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,7 +222,7 @@ impl Saveable for CommentSaved {
|
||||||
.on_conflict((comment_id, person_id))
|
.on_conflict((comment_id, person_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(comment_saved_form)
|
.set(comment_saved_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn unsave(
|
async fn unsave(
|
||||||
|
@ -235,7 +235,7 @@ impl Saveable for CommentSaved {
|
||||||
.filter(comment_id.eq(comment_saved_form.comment_id))
|
.filter(comment_id.eq(comment_saved_form.comment_id))
|
||||||
.filter(person_id.eq(comment_saved_form.person_id)),
|
.filter(person_id.eq(comment_saved_form.person_id)),
|
||||||
)
|
)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ impl Crud for CommentReply {
|
||||||
async fn read(mut conn: impl DbConn, comment_reply_id: CommentReplyId) -> Result<Self, Error> {
|
async fn read(mut conn: impl DbConn, comment_reply_id: CommentReplyId) -> Result<Self, Error> {
|
||||||
comment_reply
|
comment_reply
|
||||||
.find(comment_reply_id)
|
.find(comment_reply_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ impl Crud for CommentReply {
|
||||||
.on_conflict((recipient_id, comment_id))
|
.on_conflict((recipient_id, comment_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(comment_reply_form)
|
.set(comment_reply_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ impl Crud for CommentReply {
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
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>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ impl CommentReply {
|
||||||
.filter(read.eq(false)),
|
.filter(read.eq(false)),
|
||||||
)
|
)
|
||||||
.set(read.eq(true))
|
.set(read.eq(true))
|
||||||
.get_results::<Self>(&mut *conn)
|
.get_results::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ impl CommentReply {
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
comment_reply
|
comment_reply
|
||||||
.filter(comment_id.eq(for_comment_id))
|
.filter(comment_id.eq(for_comment_id))
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ impl Reportable for CommentReport {
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
insert_into(comment_report)
|
insert_into(comment_report)
|
||||||
.values(comment_report_form)
|
.values(comment_report_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ impl Reportable for CommentReport {
|
||||||
resolver_id.eq(by_resolver_id),
|
resolver_id.eq(by_resolver_id),
|
||||||
updated.eq(naive_now()),
|
updated.eq(naive_now()),
|
||||||
))
|
))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ impl Reportable for CommentReport {
|
||||||
resolver_id.eq(by_resolver_id),
|
resolver_id.eq(by_resolver_id),
|
||||||
updated.eq(naive_now()),
|
updated.eq(naive_now()),
|
||||||
))
|
))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,19 +30,19 @@ impl Crud for Community {
|
||||||
async fn read(mut conn: impl DbConn, community_id: CommunityId) -> Result<Self, Error> {
|
async fn read(mut conn: impl DbConn, community_id: CommunityId) -> Result<Self, Error> {
|
||||||
community::table
|
community::table
|
||||||
.find(community_id)
|
.find(community_id)
|
||||||
.first::<Self>(&mut *conn)
|
.first::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(mut conn: impl DbConn, community_id: CommunityId) -> Result<usize, Error> {
|
async fn delete(mut conn: impl DbConn, community_id: CommunityId) -> Result<usize, Error> {
|
||||||
diesel::delete(community::table.find(community_id))
|
diesel::delete(community::table.find(community_id))
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(mut conn: impl DbConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
async fn create(mut conn: impl DbConn, form: &Self::InsertForm) -> Result<Self, Error> {
|
||||||
let is_new_community = match &form.actor_id {
|
let is_new_community = match &form.actor_id {
|
||||||
Some(id) => Community::read_from_apub_id(&mut *conn, id)
|
Some(id) => Community::read_from_apub_id(conn, id)
|
||||||
.await?
|
.await?
|
||||||
.is_none(),
|
.is_none(),
|
||||||
None => true,
|
None => true,
|
||||||
|
|
|
@ -16,7 +16,7 @@ impl Blockable for CommunityBlock {
|
||||||
.on_conflict((person_id, community_id))
|
.on_conflict((person_id, community_id))
|
||||||
.do_update()
|
.do_update()
|
||||||
.set(community_block_form)
|
.set(community_block_form)
|
||||||
.get_result::<Self>(&mut *conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
async fn unblock(
|
async fn unblock(
|
||||||
|
@ -28,7 +28,7 @@ impl Blockable for CommunityBlock {
|
||||||
.filter(person_id.eq(community_block_form.person_id))
|
.filter(person_id.eq(community_block_form.person_id))
|
||||||
.filter(community_id.eq(community_block_form.community_id)),
|
.filter(community_id.eq(community_block_form.community_id)),
|
||||||
)
|
)
|
||||||
.execute(&mut *conn)
|
.execute(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue