Fix style mistakes (partial)

This commit is contained in:
dull b 2023-06-30 18:21:10 +00:00
parent 773a6d3beb
commit 48a033b87f
21 changed files with 52 additions and 45 deletions

View file

@ -19,6 +19,8 @@ impl Perform for ListCommentReports {
&self, &self,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<ListCommentReportsResponse, LemmyError> { ) -> Result<ListCommentReportsResponse, LemmyError> {
let mut conn = context.conn().await?;
let data: &ListCommentReports = self; let data: &ListCommentReports = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@ -29,8 +31,6 @@ 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(&mut conn)
.my_person_id(person_id) .my_person_id(person_id)

View file

@ -70,7 +70,6 @@ mod tests {
#[serial] #[serial]
async fn test_should_not_validate_user_token_after_password_change() { async fn test_should_not_validate_user_token_after_password_change() {
let conn = &mut build_db_conn_for_tests().await; let conn = &mut build_db_conn_for_tests().await;
let secret = Secret::init(conn).await.unwrap(); let secret = Secret::init(conn).await.unwrap();
let settings = &SETTINGS.to_owned(); let settings = &SETTINGS.to_owned();

View file

@ -17,6 +17,8 @@ impl Perform for GetPersonMentions {
&self, &self,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<GetPersonMentionsResponse, LemmyError> { ) -> Result<GetPersonMentionsResponse, LemmyError> {
let mut conn = context.conn().await?;
let data: &GetPersonMentions = self; let data: &GetPersonMentions = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@ -27,8 +29,6 @@ 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(&mut conn)
.recipient_id(person_id) .recipient_id(person_id)

View file

@ -14,6 +14,8 @@ impl Perform for GetReplies {
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetRepliesResponse, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetRepliesResponse, LemmyError> {
let mut conn = context.conn().await?;
let data: &GetReplies = self; let data: &GetReplies = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@ -24,8 +26,6 @@ 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(&mut conn)
.recipient_id(person_id) .recipient_id(person_id)

View file

@ -19,6 +19,8 @@ impl Perform for ListPostReports {
&self, &self,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<ListPostReportsResponse, LemmyError> { ) -> Result<ListPostReportsResponse, LemmyError> {
let mut conn = context.conn().await?;
let data: &ListPostReports = self; let data: &ListPostReports = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
@ -29,8 +31,6 @@ 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(&mut conn)
.my_person_id(person_id) .my_person_id(person_id)

View file

@ -14,6 +14,8 @@ impl Perform for ListPrivateMessageReports {
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
let mut conn = context.conn().await?;
let local_user_view = local_user_view_from_jwt(&self.auth, context).await?; let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
is_admin(&local_user_view)?; is_admin(&local_user_view)?;
@ -21,8 +23,6 @@ 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(&mut conn)
.unresolved_only(unresolved_only) .unresolved_only(unresolved_only)

View file

@ -29,8 +29,6 @@ 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(&mut conn)
.unread_only(unread_only) .unread_only(unread_only)

View file

@ -33,8 +33,6 @@ 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(&mut conn)
.listing_type(listing_type) .listing_type(listing_type)

View file

@ -50,7 +50,6 @@ impl PerformCrud for CreateSite {
let mut conn = context.conn().await?; let mut conn = context.conn().await?;
let data: &CreateSite = self; let data: &CreateSite = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
let local_site = LocalSite::read(&mut conn).await?; let local_site = LocalSite::read(&mut conn).await?;

View file

@ -102,13 +102,15 @@ async fn local_user_settings_view_from_jwt_opt(
jwt: Option<&Sensitive<String>>, jwt: Option<&Sensitive<String>>,
context: &LemmyContext, context: &LemmyContext,
) -> Option<LocalUserView> { ) -> Option<LocalUserView> {
let mut conn = context.conn().await().ok()?;
match jwt { match jwt {
Some(jwt) => { Some(jwt) => {
let claims = Claims::decode(jwt.as_ref(), &context.secret().jwt_secret) let claims = Claims::decode(jwt.as_ref(), &context.secret().jwt_secret)
.ok()? .ok()?
.claims; .claims;
let local_user_id = LocalUserId(claims.sub); let local_user_id = LocalUserId(claims.sub);
let local_user_view = LocalUserView::read(&mut *context.conn().await.ok()?, local_user_id) let local_user_view = LocalUserView::read(&mut conn, local_user_id)
.await .await
.ok()?; .ok()?;
check_user_valid( check_user_valid(

View file

@ -90,6 +90,7 @@ impl CreateOrUpdateNote {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let mut conn = context.conn().await?; let mut conn = context.conn().await?;
// TODO: might be helpful to add a comment method to retrieve community directly // TODO: might be helpful to add a comment method to retrieve community directly
let post_id = comment.post_id; let post_id = comment.post_id;
let post = Post::read(&mut conn, post_id).await?; let post = Post::read(&mut conn, post_id).await?;

View file

@ -56,8 +56,6 @@ 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(&mut conn)
.listing_type(Some(listing_type)) .listing_type(Some(listing_type))

View file

@ -47,8 +47,6 @@ 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(&mut conn)
.local_user(local_user_view.map(|l| l.local_user).as_ref()) .local_user(local_user_view.map(|l| l.local_user).as_ref())

View file

@ -65,8 +65,6 @@ 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(&mut conn)
.sort(sort) .sort(sort)
@ -89,8 +87,6 @@ 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(&mut conn)
.local_user(local_user_clone.as_ref()) .local_user(local_user_clone.as_ref())

View file

@ -58,8 +58,6 @@ 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()

View file

@ -28,8 +28,10 @@ impl Collection for ApubCommunityFeatured {
owner: &Self::Owner, owner: &Self::Owner,
data: &Data<Self::DataType>, data: &Data<Self::DataType>,
) -> Result<Self::Kind, Self::Error> { ) -> Result<Self::Kind, Self::Error> {
let mut conn = data.conn().await?;
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(&mut conn, owner.id)
.await? .await?
.into_iter() .into_iter()
.map(ApubPost::from) .map(ApubPost::from)

View file

@ -33,8 +33,10 @@ 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 mut conn = data.conn().await?;
let moderators = let moderators =
CommunityModeratorView::for_community(&mut *data.conn().await?, owner.id).await?; CommunityModeratorView::for_community(&mut conn, 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))
@ -62,9 +64,11 @@ impl Collection for ApubCommunityModerators {
owner: &Self::Owner, owner: &Self::Owner,
data: &Data<Self::DataType>, data: &Data<Self::DataType>,
) -> Result<Self, LemmyError> { ) -> Result<Self, LemmyError> {
let mut conn = data.conn().await?;
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(&mut conn, 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 +77,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(&mut conn, &community_moderator_form).await?;
} }
} }
@ -90,7 +94,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(&mut conn, &community_moderator_form).await?;
} }
} }

View file

@ -41,14 +41,16 @@ 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 mut conn = data.conn().await?;
let post_list: Vec<ApubPost> = Post::list_for_community(&mut conn, 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(&mut conn, post.creator_id)
.await? .await?
.into(); .into();
let create = let create =

View file

@ -169,6 +169,8 @@ async fn insert_activity<T>(
where where
T: Serialize, T: Serialize,
{ {
let mut conn = data.conn().await?;
let ap_id = ap_id.clone().into(); let ap_id = ap_id.clone().into();
let form = ActivityInsertForm { let form = ActivityInsertForm {
ap_id, ap_id,
@ -177,7 +179,7 @@ where
sensitive: Some(sensitive), sensitive: Some(sensitive),
updated: None, updated: None,
}; };
Activity::create(&mut *data.conn().await?, &form).await?; Activity::create(&mut conn, &form).await?;
Ok(()) Ok(())
} }

View file

@ -86,9 +86,11 @@ 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 mut conn = data.conn().await?;
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(&mut conn, community_id).await?;
let language = LanguageTag::new_multiple(langs, &mut *data.conn().await?).await?; let language = LanguageTag::new_multiple(langs, &mut conn).await?;
let group = Group { let group = Group {
kind: GroupType::Group, kind: GroupType::Group,

View file

@ -70,8 +70,10 @@ impl Object for ApubSite {
object_id: Url, object_id: Url,
data: &Data<Self::DataType>, data: &Data<Self::DataType>,
) -> Result<Option<Self>, LemmyError> { ) -> Result<Option<Self>, LemmyError> {
let mut conn = data.conn().await?;
Ok( Ok(
Site::read_from_apub_id(&mut *data.conn().await?, &object_id.into()) Site::read_from_apub_id(&mut conn, &object_id.into())
.await? .await?
.map(Into::into), .map(Into::into),
) )
@ -83,9 +85,11 @@ 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 mut conn = data.conn().await?;
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(&mut conn, site_id).await?;
let language = LanguageTag::new_multiple(langs, &mut *data.conn().await?).await?; let language = LanguageTag::new_multiple(langs, &mut conn).await?;
let instance = Instance { let instance = Instance {
kind: ApplicationType::Application, kind: ApplicationType::Application,
@ -113,7 +117,9 @@ 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 mut conn = data.conn().await?;
let local_site_data = fetch_local_site_data(&mut conn).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())?;
@ -127,8 +133,10 @@ 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 mut conn = data.conn().await?;
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(&mut conn, domain.to_string()).await?;
let site_form = SiteInsertForm { let site_form = SiteInsertForm {
name: apub.name.clone(), name: apub.name.clone(),
@ -145,10 +153,10 @@ impl Object for ApubSite {
instance_id: instance.id, instance_id: instance.id,
}; };
let languages = let languages =
LanguageTag::to_language_id_multiple(apub.language, &mut *data.conn().await?).await?; LanguageTag::to_language_id_multiple(apub.language, &mut conn).await?;
let site = Site::create(&mut *data.conn().await?, &site_form).await?; let site = Site::create(&mut conn, &site_form).await?;
SiteLanguage::update(&mut *data.conn().await?, languages, &site).await?; SiteLanguage::update(&mut conn, languages, &site).await?;
Ok(site.into()) Ok(site.into())
} }
} }