Fix stuff

This commit is contained in:
dull b 2023-07-01 04:11:27 +00:00
parent 0d9db43b0a
commit 0957e2b319
18 changed files with 39 additions and 54 deletions

View file

@ -29,9 +29,8 @@ impl Perform for ListCommentReports {
let page = data.page; let page = data.page;
let limit = data.limit; let limit = data.limit;
let mut conn = context.conn().await?;
let comment_reports = CommentReportQuery::builder() let comment_reports = CommentReportQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.my_person_id(person_id) .my_person_id(person_id)
.admin(admin) .admin(admin)
.community_id(community_id) .community_id(community_id)

View file

@ -27,9 +27,8 @@ impl Perform for GetPersonMentions {
let person_id = Some(local_user_view.person.id); let person_id = Some(local_user_view.person.id);
let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts); let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts);
let mut conn = context.conn().await?;
let mentions = PersonMentionQuery::builder() let mentions = PersonMentionQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.recipient_id(person_id) .recipient_id(person_id)
.my_person_id(person_id) .my_person_id(person_id)
.sort(sort) .sort(sort)

View file

@ -24,9 +24,8 @@ impl Perform for GetReplies {
let person_id = Some(local_user_view.person.id); let person_id = Some(local_user_view.person.id);
let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts); let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts);
let mut conn = context.conn().await?;
let replies = CommentReplyQuery::builder() let replies = CommentReplyQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.recipient_id(person_id) .recipient_id(person_id)
.my_person_id(person_id) .my_person_id(person_id)
.sort(sort) .sort(sort)

View file

@ -29,9 +29,8 @@ impl Perform for ListPostReports {
let page = data.page; let page = data.page;
let limit = data.limit; let limit = data.limit;
let mut conn = context.conn().await?;
let post_reports = PostReportQuery::builder() let post_reports = PostReportQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.my_person_id(person_id) .my_person_id(person_id)
.admin(admin) .admin(admin)
.community_id(community_id) .community_id(community_id)

View file

@ -21,9 +21,8 @@ impl Perform for ListPrivateMessageReports {
let unresolved_only = self.unresolved_only; let unresolved_only = self.unresolved_only;
let page = self.page; let page = self.page;
let limit = self.limit; let limit = self.limit;
let mut conn = context.conn().await?;
let private_message_reports = PrivateMessageReportQuery::builder() let private_message_reports = PrivateMessageReportQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.unresolved_only(unresolved_only) .unresolved_only(unresolved_only)
.page(page) .page(page)
.limit(limit) .limit(limit)

View file

@ -27,9 +27,8 @@ impl Perform for ListRegistrationApplications {
let page = data.page; let page = data.page;
let limit = data.limit; let limit = data.limit;
let mut conn = context.conn().await?;
let registration_applications = RegistrationApplicationQuery::builder() let registration_applications = RegistrationApplicationQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.unread_only(unread_only) .unread_only(unread_only)
.verified_email_only(Some(verified_email_only)) .verified_email_only(Some(verified_email_only))
.page(page) .page(page)

View file

@ -31,9 +31,8 @@ impl PerformCrud for ListCommunities {
let page = data.page; let page = data.page;
let limit = data.limit; let limit = data.limit;
let local_user = local_user_view.map(|l| l.local_user); let local_user = local_user_view.map(|l| l.local_user);
let mut conn = context.conn().await?;
let communities = CommunityQuery::builder() let communities = CommunityQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.listing_type(listing_type) .listing_type(listing_type)
.show_nsfw(show_nsfw) .show_nsfw(show_nsfw)
.sort(sort) .sort(sort)

View file

@ -54,9 +54,8 @@ impl PerformApub for GetComments {
let parent_path_cloned = parent_path.clone(); let parent_path_cloned = parent_path.clone();
let post_id = data.post_id; let post_id = data.post_id;
let local_user = local_user_view.map(|l| l.local_user); let local_user = local_user_view.map(|l| l.local_user);
let mut conn = context.conn().await?;
let comments = CommentQuery::builder() let comments = CommentQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.listing_type(Some(listing_type)) .listing_type(Some(listing_type))
.sort(sort) .sort(sort)
.max_depth(max_depth) .max_depth(max_depth)

View file

@ -49,9 +49,8 @@ impl PerformApub for GetPosts {
.await .await
.is_ok(); .is_ok();
let mut conn = context.conn().await?;
let posts = PostQuery::builder() let posts = PostQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.local_user(local_user_view.map(|l| l.local_user).as_ref()) .local_user(local_user_view.map(|l| l.local_user).as_ref())
.listing_type(Some(listing_type)) .listing_type(Some(listing_type))
.sort(sort) .sort(sort)

View file

@ -63,9 +63,8 @@ impl PerformApub for GetPersonDetails {
let local_user = local_user_view.map(|l| l.local_user); let local_user = local_user_view.map(|l| l.local_user);
let local_user_clone = local_user.clone(); let local_user_clone = local_user.clone();
let mut conn = context.conn().await?;
let posts_query = PostQuery::builder() let posts_query = PostQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.sort(sort) .sort(sort)
.saved_only(saved_only) .saved_only(saved_only)
.local_user(local_user.as_ref()) .local_user(local_user.as_ref())
@ -86,9 +85,8 @@ impl PerformApub for GetPersonDetails {
} }
.await?; .await?;
let mut conn = context.conn().await?;
let comments_query = CommentQuery::builder() let comments_query = CommentQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.local_user(local_user_clone.as_ref()) .local_user(local_user_clone.as_ref())
.sort(sort.map(post_to_comment_sort_type)) .sort(sort.map(post_to_comment_sort_type))
.saved_only(saved_only) .saved_only(saved_only)

View file

@ -56,11 +56,10 @@ impl PerformApub for Search {
}; };
let creator_id = data.creator_id; let creator_id = data.creator_id;
let local_user = local_user_view.map(|l| l.local_user); let local_user = local_user_view.map(|l| l.local_user);
let mut conn = context.conn().await?;
match search_type { match search_type {
SearchType::Posts => { SearchType::Posts => {
posts = PostQuery::builder() posts = PostQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.sort(sort) .sort(sort)
.listing_type(listing_type) .listing_type(listing_type)
.community_id(community_id) .community_id(community_id)
@ -76,7 +75,7 @@ impl PerformApub for Search {
} }
SearchType::Comments => { SearchType::Comments => {
comments = CommentQuery::builder() comments = CommentQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.sort(sort.map(post_to_comment_sort_type)) .sort(sort.map(post_to_comment_sort_type))
.listing_type(listing_type) .listing_type(listing_type)
.search_term(Some(q)) .search_term(Some(q))
@ -91,7 +90,7 @@ impl PerformApub for Search {
} }
SearchType::Communities => { SearchType::Communities => {
communities = CommunityQuery::builder() communities = CommunityQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.sort(sort) .sort(sort)
.listing_type(listing_type) .listing_type(listing_type)
.search_term(Some(q)) .search_term(Some(q))
@ -105,7 +104,7 @@ impl PerformApub for Search {
} }
SearchType::Users => { SearchType::Users => {
users = PersonQuery::builder() users = PersonQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.sort(sort) .sort(sort)
.search_term(Some(q)) .search_term(Some(q))
.page(page) .page(page)
@ -121,7 +120,7 @@ impl PerformApub for Search {
let local_user_ = local_user.clone(); let local_user_ = local_user.clone();
posts = PostQuery::builder() posts = PostQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.sort(sort) .sort(sort)
.listing_type(listing_type) .listing_type(listing_type)
.community_id(community_id) .community_id(community_id)
@ -139,7 +138,7 @@ impl PerformApub for Search {
let local_user_ = local_user.clone(); let local_user_ = local_user.clone();
comments = CommentQuery::builder() comments = CommentQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.sort(sort.map(post_to_comment_sort_type)) .sort(sort.map(post_to_comment_sort_type))
.listing_type(listing_type) .listing_type(listing_type)
.search_term(Some(q)) .search_term(Some(q))
@ -158,7 +157,7 @@ impl PerformApub for Search {
vec![] vec![]
} else { } else {
CommunityQuery::builder() CommunityQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.sort(sort) .sort(sort)
.listing_type(listing_type) .listing_type(listing_type)
.search_term(Some(q)) .search_term(Some(q))
@ -177,7 +176,7 @@ impl PerformApub for Search {
vec![] vec![]
} else { } else {
PersonQuery::builder() PersonQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.sort(sort) .sort(sort)
.search_term(Some(q)) .search_term(Some(q))
.page(page) .page(page)
@ -189,7 +188,7 @@ impl PerformApub for Search {
} }
SearchType::Url => { SearchType::Url => {
posts = PostQuery::builder() posts = PostQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.sort(sort) .sort(sort)
.listing_type(listing_type) .listing_type(listing_type)
.community_id(community_id) .community_id(community_id)

View file

@ -29,7 +29,7 @@ impl Collection for ApubCommunityFeatured {
data: &Data<Self::DataType>, data: &Data<Self::DataType>,
) -> Result<Self::Kind, Self::Error> { ) -> Result<Self::Kind, Self::Error> {
let ordered_items = try_join_all( let ordered_items = try_join_all(
Post::list_featured_for_community(&mut *data.conn().await?, owner.id) Post::list_featured_for_community(data.conn().await?, owner.id)
.await? .await?
.into_iter() .into_iter()
.map(ApubPost::from) .map(ApubPost::from)

View file

@ -33,8 +33,7 @@ impl Collection for ApubCommunityModerators {
owner: &Self::Owner, owner: &Self::Owner,
data: &Data<Self::DataType>, data: &Data<Self::DataType>,
) -> Result<Self::Kind, LemmyError> { ) -> Result<Self::Kind, LemmyError> {
let moderators = let moderators = CommunityModeratorView::for_community(data.conn().await?, owner.id).await?;
CommunityModeratorView::for_community(&mut *data.conn().await?, owner.id).await?;
let ordered_items = moderators let ordered_items = moderators
.into_iter() .into_iter()
.map(|m| ObjectId::<ApubPerson>::from(m.moderator.actor_id)) .map(|m| ObjectId::<ApubPerson>::from(m.moderator.actor_id))
@ -64,7 +63,7 @@ impl Collection for ApubCommunityModerators {
) -> Result<Self, LemmyError> { ) -> Result<Self, LemmyError> {
let community_id = owner.id; let community_id = owner.id;
let current_moderators = let current_moderators =
CommunityModeratorView::for_community(&mut *data.conn().await?, community_id).await?; CommunityModeratorView::for_community(data.conn().await?, community_id).await?;
// Remove old mods from database which arent in the moderators collection anymore // Remove old mods from database which arent in the moderators collection anymore
for mod_user in &current_moderators { for mod_user in &current_moderators {
let mod_id = ObjectId::from(mod_user.moderator.actor_id.clone()); let mod_id = ObjectId::from(mod_user.moderator.actor_id.clone());
@ -73,7 +72,7 @@ impl Collection for ApubCommunityModerators {
community_id: mod_user.community.id, community_id: mod_user.community.id,
person_id: mod_user.moderator.id, person_id: mod_user.moderator.id,
}; };
CommunityModerator::leave(&mut *data.conn().await?, &community_moderator_form).await?; CommunityModerator::leave(data.conn().await?, &community_moderator_form).await?;
} }
} }
@ -90,7 +89,7 @@ impl Collection for ApubCommunityModerators {
community_id: owner.id, community_id: owner.id,
person_id: mod_user.id, person_id: mod_user.id,
}; };
CommunityModerator::join(&mut *data.conn().await?, &community_moderator_form).await?; CommunityModerator::join(data.conn().await?, &community_moderator_form).await?;
} }
} }

View file

@ -41,14 +41,14 @@ impl Collection for ApubCommunityOutbox {
owner: &Self::Owner, owner: &Self::Owner,
data: &Data<Self::DataType>, data: &Data<Self::DataType>,
) -> Result<Self::Kind, LemmyError> { ) -> Result<Self::Kind, LemmyError> {
let post_list: Vec<ApubPost> = Post::list_for_community(&mut *data.conn().await?, owner.id) let post_list: Vec<ApubPost> = Post::list_for_community(data.conn().await?, owner.id)
.await? .await?
.into_iter() .into_iter()
.map(Into::into) .map(Into::into)
.collect(); .collect();
let mut ordered_items = vec![]; let mut ordered_items = vec![];
for post in post_list { for post in post_list {
let person = Person::read(&mut *data.conn().await?, post.creator_id) let person = Person::read(data.conn().await?, post.creator_id)
.await? .await?
.into(); .into();
let create = let create =

View file

@ -176,7 +176,7 @@ where
sensitive: Some(sensitive), sensitive: Some(sensitive),
updated: None, updated: None,
}; };
Activity::create(&mut *data.conn().await?, &form).await?; Activity::create(data.conn().await?, &form).await?;
Ok(()) Ok(())
} }

View file

@ -83,8 +83,8 @@ impl Object for ApubCommunity {
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn into_json(self, data: &Data<Self::DataType>) -> Result<Group, LemmyError> { async fn into_json(self, data: &Data<Self::DataType>) -> Result<Group, LemmyError> {
let community_id = self.id; let community_id = self.id;
let langs = CommunityLanguage::read(&mut *data.conn().await?, community_id).await?; let langs = CommunityLanguage::read(data.conn().await?, community_id).await?;
let language = LanguageTag::new_multiple(langs, &mut *data.conn().await?).await?; let language = LanguageTag::new_multiple(langs, data.conn().await?).await?;
let group = Group { let group = Group {
kind: GroupType::Group, kind: GroupType::Group,

View file

@ -71,7 +71,7 @@ impl Object for ApubSite {
data: &Data<Self::DataType>, data: &Data<Self::DataType>,
) -> Result<Option<Self>, LemmyError> { ) -> Result<Option<Self>, LemmyError> {
Ok( Ok(
Site::read_from_apub_id(&mut *data.conn().await?, &object_id.into()) Site::read_from_apub_id(data.conn().await?, &object_id.into())
.await? .await?
.map(Into::into), .map(Into::into),
) )
@ -84,8 +84,8 @@ impl Object for ApubSite {
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn into_json(self, data: &Data<Self::DataType>) -> Result<Self::Kind, LemmyError> { async fn into_json(self, data: &Data<Self::DataType>) -> Result<Self::Kind, LemmyError> {
let site_id = self.id; let site_id = self.id;
let langs = SiteLanguage::read(&mut *data.conn().await?, site_id).await?; let langs = SiteLanguage::read(data.conn().await?, site_id).await?;
let language = LanguageTag::new_multiple(langs, &mut *data.conn().await?).await?; let language = LanguageTag::new_multiple(langs, data.conn().await?).await?;
let instance = Instance { let instance = Instance {
kind: ApplicationType::Application, kind: ApplicationType::Application,
@ -113,7 +113,7 @@ impl Object for ApubSite {
expected_domain: &Url, expected_domain: &Url,
data: &Data<Self::DataType>, data: &Data<Self::DataType>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let local_site_data = fetch_local_site_data(&mut *data.conn().await?).await?; let local_site_data = fetch_local_site_data(data.conn().await?).await?;
check_apub_id_valid_with_strictness(apub.id.inner(), true, &local_site_data, data.settings())?; check_apub_id_valid_with_strictness(apub.id.inner(), true, &local_site_data, data.settings())?;
verify_domains_match(expected_domain, apub.id.inner())?; verify_domains_match(expected_domain, apub.id.inner())?;
@ -128,7 +128,7 @@ impl Object for ApubSite {
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn from_json(apub: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, LemmyError> { async fn from_json(apub: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, LemmyError> {
let domain = apub.id.inner().domain().expect("group id has domain"); let domain = apub.id.inner().domain().expect("group id has domain");
let instance = DbInstance::read_or_create(&mut *data.conn().await?, domain.to_string()).await?; let instance = DbInstance::read_or_create(data.conn().await?, domain.to_string()).await?;
let site_form = SiteInsertForm { let site_form = SiteInsertForm {
name: apub.name.clone(), name: apub.name.clone(),
@ -144,11 +144,10 @@ impl Object for ApubSite {
private_key: None, private_key: None,
instance_id: instance.id, instance_id: instance.id,
}; };
let languages = let languages = LanguageTag::to_language_id_multiple(apub.language, data.conn().await?).await?;
LanguageTag::to_language_id_multiple(apub.language, &mut *data.conn().await?).await?;
let site = Site::create(&mut *data.conn().await?, &site_form).await?; let site = Site::create(data.conn().await?, &site_form).await?;
SiteLanguage::update(&mut *data.conn().await?, languages, &site).await?; SiteLanguage::update(data.conn().await?, languages, &site).await?;
Ok(site.into()) Ok(site.into())
} }
} }

View file

@ -124,9 +124,8 @@ async fn get_feed_data(
) -> Result<HttpResponse, LemmyError> { ) -> Result<HttpResponse, LemmyError> {
let site_view = SiteView::read_local(context.conn().await?).await?; let site_view = SiteView::read_local(context.conn().await?).await?;
let mut conn = context.conn().await?;
let posts = PostQuery::builder() let posts = PostQuery::builder()
.conn(&mut *conn) .conn(context.conn().await?)
.listing_type(Some(listing_type)) .listing_type(Some(listing_type))
.sort(Some(sort_type)) .sort(Some(sort_type))
.limit(Some(limit)) .limit(Some(limit))