DbConn trait

This commit is contained in:
dull b 2023-07-01 03:04:38 +00:00
parent 6846210074
commit 5db6b556cc
214 changed files with 2371 additions and 2024 deletions

View File

@ -22,7 +22,7 @@ impl Perform for DistinguishComment {
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 comment_id = data.comment_id; let comment_id = data.comment_id;
let orig_comment = CommentView::read(&mut *context.conn().await?, comment_id, None).await?; let orig_comment = CommentView::read(context.conn().await?, comment_id, None).await?;
check_community_ban( check_community_ban(
local_user_view.person.id, local_user_view.person.id,
@ -44,14 +44,14 @@ impl Perform for DistinguishComment {
let form = CommentUpdateForm::builder() let form = CommentUpdateForm::builder()
.distinguished(Some(data.distinguished)) .distinguished(Some(data.distinguished))
.build(); .build();
Comment::update(&mut *context.conn().await?, comment_id, &form) Comment::update(context.conn().await?, comment_id, &form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
let comment_id = data.comment_id; let comment_id = data.comment_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let comment_view = let comment_view =
CommentView::read(&mut *context.conn().await?, comment_id, Some(person_id)).await?; CommentView::read(context.conn().await?, comment_id, Some(person_id)).await?;
Ok(CommentResponse { Ok(CommentResponse {
comment_view, comment_view,

View File

@ -25,7 +25,7 @@ impl Perform for CreateCommentLike {
#[tracing::instrument(skip(context))] #[tracing::instrument(skip(context))]
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
let data: &CreateCommentLike = self; let data: &CreateCommentLike = self;
let local_site = LocalSite::read(&mut *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
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 mut recipient_ids = Vec::<LocalUserId>::new(); let mut recipient_ids = Vec::<LocalUserId>::new();
@ -34,7 +34,7 @@ impl Perform for CreateCommentLike {
check_downvotes_enabled(data.score, &local_site)?; check_downvotes_enabled(data.score, &local_site)?;
let comment_id = data.comment_id; let comment_id = data.comment_id;
let orig_comment = CommentView::read(&mut *context.conn().await?, comment_id, None).await?; let orig_comment = CommentView::read(context.conn().await?, comment_id, None).await?;
check_community_ban( check_community_ban(
local_user_view.person.id, local_user_view.person.id,
@ -44,12 +44,11 @@ impl Perform for CreateCommentLike {
.await?; .await?;
// Add parent poster or commenter to recipients // Add parent poster or commenter to recipients
let comment_reply = let comment_reply = CommentReply::read_by_comment(context.conn().await?, comment_id).await;
CommentReply::read_by_comment(&mut *context.conn().await?, comment_id).await;
if let Ok(reply) = comment_reply { if let Ok(reply) = comment_reply {
let recipient_id = reply.recipient_id; let recipient_id = reply.recipient_id;
if let Ok(local_recipient) = if let Ok(local_recipient) =
LocalUserView::read_person(&mut *context.conn().await?, recipient_id).await LocalUserView::read_person(context.conn().await?, recipient_id).await
{ {
recipient_ids.push(local_recipient.local_user.id); recipient_ids.push(local_recipient.local_user.id);
} }
@ -65,12 +64,12 @@ impl Perform for CreateCommentLike {
// Remove any likes first // Remove any likes first
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
CommentLike::remove(&mut *context.conn().await?, person_id, comment_id).await?; CommentLike::remove(context.conn().await?, person_id, comment_id).await?;
// Only add the like if the score isnt 0 // Only add the like if the score isnt 0
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1); let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
if do_add { if do_add {
CommentLike::like(&mut *context.conn().await?, &like_form) CommentLike::like(context.conn().await?, &like_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;
} }

View File

@ -27,11 +27,11 @@ impl Perform for SaveComment {
}; };
if data.save { if data.save {
CommentSaved::save(&mut *context.conn().await?, &comment_saved_form) CommentSaved::save(context.conn().await?, &comment_saved_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
} else { } else {
CommentSaved::unsave(&mut *context.conn().await?, &comment_saved_form) CommentSaved::unsave(context.conn().await?, &comment_saved_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
} }
@ -39,7 +39,7 @@ impl Perform for SaveComment {
let comment_id = data.comment_id; let comment_id = data.comment_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let comment_view = let comment_view =
CommentView::read(&mut *context.conn().await?, comment_id, Some(person_id)).await?; CommentView::read(context.conn().await?, comment_id, Some(person_id)).await?;
Ok(CommentResponse { Ok(CommentResponse {
comment_view, comment_view,

View File

@ -27,14 +27,14 @@ impl Perform for CreateCommentReport {
) -> Result<CommentReportResponse, LemmyError> { ) -> Result<CommentReportResponse, LemmyError> {
let data: &CreateCommentReport = self; let data: &CreateCommentReport = 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 *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
let reason = self.reason.trim(); let reason = self.reason.trim();
check_report_reason(reason, &local_site)?; check_report_reason(reason, &local_site)?;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let comment_id = data.comment_id; let comment_id = data.comment_id;
let comment_view = CommentView::read(&mut *context.conn().await?, comment_id, None).await?; let comment_view = CommentView::read(context.conn().await?, comment_id, None).await?;
check_community_ban( check_community_ban(
person_id, person_id,
@ -50,12 +50,12 @@ impl Perform for CreateCommentReport {
reason: reason.to_owned(), reason: reason.to_owned(),
}; };
let report = CommentReport::report(&mut *context.conn().await?, &report_form) let report = CommentReport::report(context.conn().await?, &report_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?;
let comment_report_view = let comment_report_view =
CommentReportView::read(&mut *context.conn().await?, report.id, person_id).await?; CommentReportView::read(context.conn().await?, report.id, person_id).await?;
// Email the admins // Email the admins
if local_site.reports_email_admins { if local_site.reports_email_admins {

View File

@ -31,7 +31,7 @@ impl Perform for ListCommentReports {
let limit = data.limit; let limit = data.limit;
let mut conn = context.conn().await?; 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)
.admin(admin) .admin(admin)
.community_id(community_id) .community_id(community_id)

View File

@ -24,24 +24,24 @@ impl Perform for ResolveCommentReport {
let report_id = data.report_id; let report_id = data.report_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let report = CommentReportView::read(&mut *context.conn().await?, report_id, person_id).await?; let report = CommentReportView::read(context.conn().await?, report_id, person_id).await?;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
is_mod_or_admin(&mut *context.conn().await?, person_id, report.community.id).await?; is_mod_or_admin(context.conn().await?, person_id, report.community.id).await?;
if data.resolved { if data.resolved {
CommentReport::resolve(&mut *context.conn().await?, report_id, person_id) CommentReport::resolve(context.conn().await?, report_id, person_id)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
} else { } else {
CommentReport::unresolve(&mut *context.conn().await?, report_id, person_id) CommentReport::unresolve(context.conn().await?, report_id, person_id)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
} }
let report_id = data.report_id; let report_id = data.report_id;
let comment_report_view = let comment_report_view =
CommentReportView::read(&mut *context.conn().await?, report_id, person_id).await?; CommentReportView::read(context.conn().await?, report_id, person_id).await?;
Ok(CommentReportResponse { Ok(CommentReportResponse {
comment_report_view, comment_report_view,

View File

@ -36,7 +36,7 @@ impl Perform for AddModToCommunity {
community_id, community_id,
) )
.await?; .await?;
let community = Community::read(&mut *context.conn().await?, community_id).await?; let community = Community::read(context.conn().await?, community_id).await?;
if local_user_view.person.admin && !community.local { if local_user_view.person.admin && !community.local {
return Err(LemmyError::from_message("not_a_moderator")); return Err(LemmyError::from_message("not_a_moderator"));
} }
@ -47,11 +47,11 @@ impl Perform for AddModToCommunity {
person_id: data.person_id, person_id: data.person_id,
}; };
if data.added { if data.added {
CommunityModerator::join(&mut *context.conn().await?, &community_moderator_form) CommunityModerator::join(context.conn().await?, &community_moderator_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?; .map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
} else { } else {
CommunityModerator::leave(&mut *context.conn().await?, &community_moderator_form) CommunityModerator::leave(context.conn().await?, &community_moderator_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?; .map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
} }
@ -64,13 +64,13 @@ impl Perform for AddModToCommunity {
removed: Some(!data.added), removed: Some(!data.added),
}; };
ModAddCommunity::create(&mut *context.conn().await?, &form).await?; ModAddCommunity::create(context.conn().await?, &form).await?;
// Note: in case a remote mod is added, this returns the old moderators list, it will only get // Note: in case a remote mod is added, this returns the old moderators list, it will only get
// updated once we receive an activity from the community (like `Announce/Add/Moderator`) // updated once we receive an activity from the community (like `Announce/Add/Moderator`)
let community_id = data.community_id; let community_id = data.community_id;
let moderators = let moderators =
CommunityModeratorView::for_community(&mut *context.conn().await?, community_id).await?; CommunityModeratorView::for_community(context.conn().await?, community_id).await?;
Ok(AddModToCommunityResponse { moderators }) Ok(AddModToCommunityResponse { moderators })
} }

View File

@ -56,7 +56,7 @@ impl Perform for BanFromCommunity {
}; };
if data.ban { if data.ban {
CommunityPersonBan::ban(&mut *context.conn().await?, &community_user_ban_form) CommunityPersonBan::ban(context.conn().await?, &community_user_ban_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "community_user_already_banned"))?; .map_err(|e| LemmyError::from_error_message(e, "community_user_already_banned"))?;
@ -67,11 +67,11 @@ impl Perform for BanFromCommunity {
pending: false, pending: false,
}; };
CommunityFollower::unfollow(&mut *context.conn().await?, &community_follower_form) CommunityFollower::unfollow(context.conn().await?, &community_follower_form)
.await .await
.ok(); .ok();
} else { } else {
CommunityPersonBan::unban(&mut *context.conn().await?, &community_user_ban_form) CommunityPersonBan::unban(context.conn().await?, &community_user_ban_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "community_user_already_banned"))?; .map_err(|e| LemmyError::from_error_message(e, "community_user_already_banned"))?;
} }
@ -92,10 +92,10 @@ impl Perform for BanFromCommunity {
expires, expires,
}; };
ModBanFromCommunity::create(&mut *context.conn().await?, &form).await?; ModBanFromCommunity::create(context.conn().await?, &form).await?;
let person_id = data.person_id; let person_id = data.person_id;
let person_view = PersonView::read(&mut *context.conn().await?, person_id).await?; let person_view = PersonView::read(context.conn().await?, person_id).await?;
Ok(BanFromCommunityResponse { Ok(BanFromCommunityResponse {
person_view, person_view,

View File

@ -35,7 +35,7 @@ impl Perform for BlockCommunity {
}; };
if data.block { if data.block {
CommunityBlock::block(&mut *context.conn().await?, &community_block_form) CommunityBlock::block(context.conn().await?, &community_block_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "community_block_already_exists"))?; .map_err(|e| LemmyError::from_error_message(e, "community_block_already_exists"))?;
@ -46,11 +46,11 @@ impl Perform for BlockCommunity {
pending: false, pending: false,
}; };
CommunityFollower::unfollow(&mut *context.conn().await?, &community_follower_form) CommunityFollower::unfollow(context.conn().await?, &community_follower_form)
.await .await
.ok(); .ok();
} else { } else {
CommunityBlock::unblock(&mut *context.conn().await?, &community_block_form) CommunityBlock::unblock(context.conn().await?, &community_block_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "community_block_already_exists"))?; .map_err(|e| LemmyError::from_error_message(e, "community_block_already_exists"))?;
} }

View File

@ -25,7 +25,7 @@ impl Perform for FollowCommunity {
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 community_id = data.community_id; let community_id = data.community_id;
let community = Community::read(&mut *context.conn().await?, community_id).await?; let community = Community::read(context.conn().await?, community_id).await?;
let community_follower_form = CommunityFollowerForm { let community_follower_form = CommunityFollowerForm {
community_id: data.community_id, community_id: data.community_id,
person_id: local_user_view.person.id, person_id: local_user_view.person.id,
@ -41,12 +41,12 @@ impl Perform for FollowCommunity {
.await?; .await?;
check_community_deleted_or_removed(community_id, &mut *context.conn().await?).await?; check_community_deleted_or_removed(community_id, &mut *context.conn().await?).await?;
CommunityFollower::follow(&mut *context.conn().await?, &community_follower_form) CommunityFollower::follow(context.conn().await?, &community_follower_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?; .map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
} }
if !data.follow { if !data.follow {
CommunityFollower::unfollow(&mut *context.conn().await?, &community_follower_form) CommunityFollower::unfollow(context.conn().await?, &community_follower_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?; .map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
} }
@ -60,8 +60,7 @@ impl Perform for FollowCommunity {
None, None,
) )
.await?; .await?;
let discussion_languages = let discussion_languages = CommunityLanguage::read(context.conn().await?, community_id).await?;
CommunityLanguage::read(&mut *context.conn().await?, community_id).await?;
Ok(Self::Response { Ok(Self::Response {
community_view, community_view,

View File

@ -39,11 +39,11 @@ impl Perform for HideCommunity {
}; };
let community_id = data.community_id; let community_id = data.community_id;
Community::update(&mut *context.conn().await?, community_id, &community_form) Community::update(context.conn().await?, community_id, &community_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community_hidden_status"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community_hidden_status"))?;
ModHideCommunity::create(&mut *context.conn().await?, &mod_hide_community_form).await?; ModHideCommunity::create(context.conn().await?, &mod_hide_community_form).await?;
build_community_response(context, local_user_view, community_id).await build_community_response(context, local_user_view, community_id).await
} }

View File

@ -33,7 +33,7 @@ impl Perform for TransferCommunity {
// Fetch the community mods // Fetch the community mods
let community_id = data.community_id; let community_id = data.community_id;
let mut community_mods = let mut community_mods =
CommunityModeratorView::for_community(&mut *context.conn().await?, community_id).await?; CommunityModeratorView::for_community(context.conn().await?, community_id).await?;
// Make sure transferrer is either the top community mod, or an admin // Make sure transferrer is either the top community mod, or an admin
if !(is_top_mod(&local_user_view, &community_mods).is_ok() if !(is_top_mod(&local_user_view, &community_mods).is_ok()
@ -54,7 +54,7 @@ impl Perform for TransferCommunity {
// Delete all the mods // Delete all the mods
let community_id = data.community_id; let community_id = data.community_id;
CommunityModerator::delete_for_community(&mut *context.conn().await?, community_id).await?; CommunityModerator::delete_for_community(context.conn().await?, community_id).await?;
// TODO: this should probably be a bulk operation // TODO: this should probably be a bulk operation
// Re-add the mods, in the new order // Re-add the mods, in the new order
@ -64,7 +64,7 @@ impl Perform for TransferCommunity {
person_id: cmod.moderator.id, person_id: cmod.moderator.id,
}; };
CommunityModerator::join(&mut *context.conn().await?, &community_moderator_form) CommunityModerator::join(context.conn().await?, &community_moderator_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?; .map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
} }
@ -76,7 +76,7 @@ impl Perform for TransferCommunity {
community_id: data.community_id, community_id: data.community_id,
}; };
ModTransferCommunity::create(&mut *context.conn().await?, &form).await?; ModTransferCommunity::create(context.conn().await?, &form).await?;
let community_id = data.community_id; let community_id = data.community_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
@ -90,10 +90,9 @@ impl Perform for TransferCommunity {
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
let community_id = data.community_id; let community_id = data.community_id;
let moderators = let moderators = CommunityModeratorView::for_community(context.conn().await?, community_id)
CommunityModeratorView::for_community(&mut *context.conn().await?, community_id) .await
.await .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
// Return the jwt // Return the jwt
Ok(GetCommunityResponse { Ok(GetCommunityResponse {

View File

@ -94,11 +94,11 @@ mod tests {
#[tokio::test] #[tokio::test]
#[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 mut conn = build_db_conn_for_tests().await;
let secret = Secret::init(conn).await.unwrap(); let secret = Secret::init(&mut *conn).await.unwrap();
let settings = &SETTINGS.to_owned(); let settings = &SETTINGS.to_owned();
let inserted_instance = Instance::read_or_create(conn, "my_domain.tld".to_string()) let inserted_instance = Instance::read_or_create(&mut *conn, "my_domain.tld".to_string())
.await .await
.unwrap(); .unwrap();
@ -108,14 +108,16 @@ mod tests {
.instance_id(inserted_instance.id) .instance_id(inserted_instance.id)
.build(); .build();
let inserted_person = Person::create(conn, &new_person).await.unwrap(); let inserted_person = Person::create(&mut *conn, &new_person).await.unwrap();
let local_user_form = LocalUserInsertForm::builder() let local_user_form = LocalUserInsertForm::builder()
.person_id(inserted_person.id) .person_id(inserted_person.id)
.password_encrypted("123456".to_string()) .password_encrypted("123456".to_string())
.build(); .build();
let inserted_local_user = LocalUser::create(conn, &local_user_form).await.unwrap(); let inserted_local_user = LocalUser::create(&mut *conn, &local_user_form)
.await
.unwrap();
let jwt = Claims::jwt( let jwt = Claims::jwt(
inserted_local_user.id.0, inserted_local_user.id.0,
@ -129,13 +131,15 @@ mod tests {
// The check should fail, since the validator time is now newer than the jwt issue time // The check should fail, since the validator time is now newer than the jwt issue time
let updated_local_user = let updated_local_user =
LocalUser::update_password(conn, inserted_local_user.id, "password111") LocalUser::update_password(&mut *conn, inserted_local_user.id, "password111")
.await .await
.unwrap(); .unwrap();
let check_after = check_validator_time(&updated_local_user.validator_time, &claims); let check_after = check_validator_time(&updated_local_user.validator_time, &claims);
assert!(check_after.is_err()); assert!(check_after.is_err());
let num_deleted = Person::delete(conn, inserted_person.id).await.unwrap(); let num_deleted = Person::delete(&mut *conn, inserted_person.id)
.await
.unwrap();
assert_eq!(1, num_deleted); assert_eq!(1, num_deleted);
} }
} }

View File

@ -44,9 +44,9 @@ impl Perform for AddAdmin {
removed: Some(!data.added), removed: Some(!data.added),
}; };
ModAdd::create(&mut *context.conn().await?, &form).await?; ModAdd::create(context.conn().await?, &form).await?;
let admins = PersonView::admins(&mut *context.conn().await?).await?; let admins = PersonView::admins(context.conn().await?).await?;
Ok(AddAdminResponse { admins }) Ok(AddAdminResponse { admins })
} }

View File

@ -68,10 +68,10 @@ impl Perform for BanPerson {
expires, expires,
}; };
ModBan::create(&mut *context.conn().await?, &form).await?; ModBan::create(context.conn().await?, &form).await?;
let person_id = data.person_id; let person_id = data.person_id;
let person_view = PersonView::read(&mut *context.conn().await?, person_id).await?; let person_view = PersonView::read(context.conn().await?, person_id).await?;
Ok(BanPersonResponse { Ok(BanPersonResponse {
person_view, person_view,

View File

@ -34,18 +34,18 @@ impl Perform for BlockPerson {
target_id, target_id,
}; };
let target_person_view = PersonView::read(&mut *context.conn().await?, target_id).await?; let target_person_view = PersonView::read(context.conn().await?, target_id).await?;
if target_person_view.person.admin { if target_person_view.person.admin {
return Err(LemmyError::from_message("cant_block_admin")); return Err(LemmyError::from_message("cant_block_admin"));
} }
if data.block { if data.block {
PersonBlock::block(&mut *context.conn().await?, &person_block_form) PersonBlock::block(context.conn().await?, &person_block_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "person_block_already_exists"))?; .map_err(|e| LemmyError::from_error_message(e, "person_block_already_exists"))?;
} else { } else {
PersonBlock::unblock(&mut *context.conn().await?, &person_block_form) PersonBlock::unblock(context.conn().await?, &person_block_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "person_block_already_exists"))?; .map_err(|e| LemmyError::from_error_message(e, "person_block_already_exists"))?;
} }

View File

@ -38,7 +38,7 @@ impl Perform for ChangePassword {
let local_user_id = local_user_view.local_user.id; let local_user_id = local_user_view.local_user.id;
let new_password = data.new_password.clone(); let new_password = data.new_password.clone();
let updated_local_user = let updated_local_user =
LocalUser::update_password(&mut *context.conn().await?, local_user_id, &new_password).await?; LocalUser::update_password(context.conn().await?, local_user_id, &new_password).await?;
// Return the jwt // Return the jwt
Ok(LoginResponse { Ok(LoginResponse {

View File

@ -22,7 +22,7 @@ impl Perform for PasswordChangeAfterReset {
// Fetch the user_id from the token // Fetch the user_id from the token
let token = data.token.clone(); let token = data.token.clone();
let local_user_id = PasswordResetRequest::read_from_token(&mut *context.conn().await?, &token) let local_user_id = PasswordResetRequest::read_from_token(context.conn().await?, &token)
.await .await
.map(|p| p.local_user_id)?; .map(|p| p.local_user_id)?;
@ -36,12 +36,12 @@ impl Perform for PasswordChangeAfterReset {
// Update the user with the new password // Update the user with the new password
let password = data.password.clone(); let password = data.password.clone();
let updated_local_user = let updated_local_user =
LocalUser::update_password(&mut *context.conn().await?, local_user_id, &password) LocalUser::update_password(context.conn().await?, local_user_id, &password)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_user"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_user"))?;
// Return the jwt if login is allowed // Return the jwt if login is allowed
let site_view = SiteView::read_local(&mut *context.conn().await?).await?; let site_view = SiteView::read_local(context.conn().await?).await?;
let jwt = if site_view.local_site.registration_mode == RegistrationMode::RequireApplication let jwt = if site_view.local_site.registration_mode == RegistrationMode::RequireApplication
&& !updated_local_user.accepted_application && !updated_local_user.accepted_application
{ {

View File

@ -17,7 +17,7 @@ impl Perform for GetCaptcha {
#[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 local_site = LocalSite::read(&mut *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
if !local_site.captcha_enabled { if !local_site.captcha_enabled {
return Ok(GetCaptchaResponse { ok: None }); return Ok(GetCaptchaResponse { ok: None });
@ -37,7 +37,7 @@ impl Perform for GetCaptcha {
let captcha_form: CaptchaAnswerForm = CaptchaAnswerForm { answer }; let captcha_form: CaptchaAnswerForm = CaptchaAnswerForm { answer };
// Stores the captcha item in the db // Stores the captcha item in the db
let captcha = CaptchaAnswer::insert(&mut *context.conn().await?, &captcha_form).await?; let captcha = CaptchaAnswer::insert(context.conn().await?, &captcha_form).await?;
Ok(GetCaptchaResponse { Ok(GetCaptchaResponse {
ok: Some(CaptchaResponse { ok: Some(CaptchaResponse {

View File

@ -19,7 +19,7 @@ impl Perform for GetBannedPersons {
// Make sure user is an admin // Make sure user is an admin
is_admin(&local_user_view)?; is_admin(&local_user_view)?;
let banned = PersonView::banned(&mut *context.conn().await?).await?; let banned = PersonView::banned(context.conn().await?).await?;
Ok(Self::Response { banned }) Ok(Self::Response { banned })
} }

View File

@ -17,12 +17,12 @@ impl Perform for Login {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
let data: &Login = self; let data: &Login = self;
let site_view = SiteView::read_local(&mut *context.conn().await?).await?; let site_view = SiteView::read_local(context.conn().await?).await?;
// Fetch that username / email // Fetch that username / email
let username_or_email = data.username_or_email.clone(); let username_or_email = data.username_or_email.clone();
let local_user_view = let local_user_view =
LocalUserView::find_by_email_or_name(&mut *context.conn().await?, &username_or_email) LocalUserView::find_by_email_or_name(context.conn().await?, &username_or_email)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?;

View File

@ -29,7 +29,7 @@ impl Perform for GetPersonMentions {
let mut conn = context.conn().await?; 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)
.my_person_id(person_id) .my_person_id(person_id)
.sort(sort) .sort(sort)

View File

@ -26,7 +26,7 @@ impl Perform for GetReplies {
let mut conn = context.conn().await?; 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)
.my_person_id(person_id) .my_person_id(person_id)
.sort(sort) .sort(sort)

View File

@ -23,17 +23,17 @@ impl Perform for MarkAllAsRead {
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
// Mark all comment_replies as read // Mark all comment_replies as read
CommentReply::mark_all_as_read(&mut *context.conn().await?, person_id) CommentReply::mark_all_as_read(context.conn().await?, person_id)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
// Mark all user mentions as read // Mark all user mentions as read
PersonMention::mark_all_as_read(&mut *context.conn().await?, person_id) PersonMention::mark_all_as_read(context.conn().await?, person_id)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
// Mark all private_messages as read // Mark all private_messages as read
PrivateMessage::mark_all_as_read(&mut *context.conn().await?, person_id) PrivateMessage::mark_all_as_read(context.conn().await?, person_id)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;

View File

@ -25,8 +25,7 @@ impl Perform for MarkPersonMentionAsRead {
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 person_mention_id = data.person_mention_id; let person_mention_id = data.person_mention_id;
let read_person_mention = let read_person_mention = PersonMention::read(context.conn().await?, person_mention_id).await?;
PersonMention::read(&mut *context.conn().await?, person_mention_id).await?;
if local_user_view.person.id != read_person_mention.recipient_id { if local_user_view.person.id != read_person_mention.recipient_id {
return Err(LemmyError::from_message("couldnt_update_comment")); return Err(LemmyError::from_message("couldnt_update_comment"));

View File

@ -25,8 +25,7 @@ impl Perform for MarkCommentReplyAsRead {
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 comment_reply_id = data.comment_reply_id; let comment_reply_id = data.comment_reply_id;
let read_comment_reply = let read_comment_reply = CommentReply::read(context.conn().await?, comment_reply_id).await?;
CommentReply::read(&mut *context.conn().await?, comment_reply_id).await?;
if local_user_view.person.id != read_comment_reply.recipient_id { if local_user_view.person.id != read_comment_reply.recipient_id {
return Err(LemmyError::from_message("couldnt_update_comment")); return Err(LemmyError::from_message("couldnt_update_comment"));

View File

@ -20,14 +20,12 @@ impl Perform for GetUnreadCount {
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let replies = let replies = CommentReplyView::get_unread_replies(context.conn().await?, person_id).await?;
CommentReplyView::get_unread_replies(&mut *context.conn().await?, person_id).await?;
let mentions = let mentions = PersonMentionView::get_unread_mentions(context.conn().await?, person_id).await?;
PersonMentionView::get_unread_mentions(&mut *context.conn().await?, person_id).await?;
let private_messages = let private_messages =
PrivateMessageView::get_unread_messages(&mut *context.conn().await?, person_id).await?; PrivateMessageView::get_unread_messages(context.conn().await?, person_id).await?;
Ok(Self::Response { Ok(Self::Response {
replies, replies,

View File

@ -33,11 +33,11 @@ impl Perform for GetReportCount {
.await?; .await?;
let post_reports = let post_reports =
PostReportView::get_report_count(&mut *context.conn().await?, person_id, admin, community_id) PostReportView::get_report_count(context.conn().await?, person_id, admin, community_id)
.await?; .await?;
let private_message_reports = if admin && community_id.is_none() { let private_message_reports = if admin && community_id.is_none() {
Some(PrivateMessageReportView::get_report_count(&mut *context.conn().await?).await?) Some(PrivateMessageReportView::get_report_count(context.conn().await?).await?)
} else { } else {
None None
}; };

View File

@ -22,7 +22,7 @@ impl Perform for PasswordReset {
// Fetch that email // Fetch that email
let email = data.email.to_lowercase(); let email = data.email.to_lowercase();
let local_user_view = LocalUserView::find_by_email(&mut *context.conn().await?, &email) let local_user_view = LocalUserView::find_by_email(context.conn().await?, &email)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?;

View File

@ -35,7 +35,7 @@ impl Perform for SaveUserSettings {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
let data: &SaveUserSettings = self; let data: &SaveUserSettings = 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 site_view = SiteView::read_local(&mut *context.conn().await?).await?; let site_view = SiteView::read_local(context.conn().await?).await?;
let avatar = diesel_option_overwrite_to_url(&data.avatar)?; let avatar = diesel_option_overwrite_to_url(&data.avatar)?;
let banner = diesel_option_overwrite_to_url(&data.banner)?; let banner = diesel_option_overwrite_to_url(&data.banner)?;
@ -95,7 +95,7 @@ impl Perform for SaveUserSettings {
.banner(banner) .banner(banner)
.build(); .build();
Person::update(&mut *context.conn().await?, person_id, &person_form) Person::update(context.conn().await?, person_id, &person_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "user_already_exists"))?; .map_err(|e| LemmyError::from_error_message(e, "user_already_exists"))?;
@ -140,7 +140,7 @@ impl Perform for SaveUserSettings {
.build(); .build();
let local_user_res = let local_user_res =
LocalUser::update(&mut *context.conn().await?, local_user_id, &local_user_form).await; LocalUser::update(context.conn().await?, local_user_id, &local_user_form).await;
let updated_local_user = match local_user_res { let updated_local_user = match local_user_res {
Ok(u) => u, Ok(u) => u,
Err(e) => { Err(e) => {

View File

@ -19,7 +19,7 @@ impl Perform for VerifyEmail {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
let token = self.token.clone(); let token = self.token.clone();
let verification = EmailVerification::read_for_token(&mut *context.conn().await?, &token) let verification = EmailVerification::read_for_token(context.conn().await?, &token)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "token_not_found"))?; .map_err(|e| LemmyError::from_error_message(e, "token_not_found"))?;
@ -31,9 +31,9 @@ impl Perform for VerifyEmail {
.build(); .build();
let local_user_id = verification.local_user_id; let local_user_id = verification.local_user_id;
LocalUser::update(&mut *context.conn().await?, local_user_id, &form).await?; LocalUser::update(context.conn().await?, local_user_id, &form).await?;
EmailVerification::delete_old_tokens_for_local_user(&mut *context.conn().await?, local_user_id) EmailVerification::delete_old_tokens_for_local_user(context.conn().await?, local_user_id)
.await?; .await?;
Ok(VerifyEmailResponse {}) Ok(VerifyEmailResponse {})

View File

@ -32,7 +32,7 @@ impl Perform for FeaturePost {
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 post_id = data.post_id; let post_id = data.post_id;
let orig_post = Post::read(&mut *context.conn().await?, post_id).await?; let orig_post = Post::read(context.conn().await?, post_id).await?;
check_community_ban( check_community_ban(
local_user_view.person.id, local_user_view.person.id,
@ -65,7 +65,7 @@ impl Perform for FeaturePost {
.featured_local(Some(data.featured)) .featured_local(Some(data.featured))
.build() .build()
}; };
Post::update(&mut *context.conn().await?, post_id, &new_post).await?; Post::update(context.conn().await?, post_id, &new_post).await?;
// Mod tables // Mod tables
let form = ModFeaturePostForm { let form = ModFeaturePostForm {
@ -75,7 +75,7 @@ impl Perform for FeaturePost {
is_featured_community: data.feature_type == PostFeatureType::Community, is_featured_community: data.feature_type == PostFeatureType::Community,
}; };
ModFeaturePost::create(&mut *context.conn().await?, &form).await?; ModFeaturePost::create(context.conn().await?, &form).await?;
build_post_response( build_post_response(
context, context,

View File

@ -29,14 +29,14 @@ impl Perform for CreatePostLike {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
let data: &CreatePostLike = self; let data: &CreatePostLike = 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 *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
// Don't do a downvote if site has downvotes disabled // Don't do a downvote if site has downvotes disabled
check_downvotes_enabled(data.score, &local_site)?; check_downvotes_enabled(data.score, &local_site)?;
// Check for a community ban // Check for a community ban
let post_id = data.post_id; let post_id = data.post_id;
let post = Post::read(&mut *context.conn().await?, post_id).await?; let post = Post::read(context.conn().await?, post_id).await?;
check_community_ban( check_community_ban(
local_user_view.person.id, local_user_view.person.id,
@ -55,12 +55,12 @@ impl Perform for CreatePostLike {
// Remove any likes first // Remove any likes first
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
PostLike::remove(&mut *context.conn().await?, person_id, post_id).await?; PostLike::remove(context.conn().await?, person_id, post_id).await?;
// Only add the like if the score isnt 0 // Only add the like if the score isnt 0
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1); let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
if do_add { if do_add {
PostLike::like(&mut *context.conn().await?, &like_form) PostLike::like(context.conn().await?, &like_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_post"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_like_post"))?;
} }

View File

@ -30,7 +30,7 @@ impl Perform for LockPost {
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 post_id = data.post_id; let post_id = data.post_id;
let orig_post = Post::read(&mut *context.conn().await?, post_id).await?; let orig_post = Post::read(context.conn().await?, post_id).await?;
check_community_ban( check_community_ban(
local_user_view.person.id, local_user_view.person.id,
@ -64,7 +64,7 @@ impl Perform for LockPost {
post_id: data.post_id, post_id: data.post_id,
locked: Some(locked), locked: Some(locked),
}; };
ModLockPost::create(&mut *context.conn().await?, &form).await?; ModLockPost::create(context.conn().await?, &form).await?;
build_post_response( build_post_response(
context, context,

View File

@ -28,8 +28,7 @@ impl Perform for MarkPostAsRead {
} }
// Fetch it // Fetch it
let post_view = let post_view = PostView::read(context.conn().await?, post_id, Some(person_id), None).await?;
PostView::read(&mut *context.conn().await?, post_id, Some(person_id), None).await?;
Ok(Self::Response { post_view }) Ok(Self::Response { post_view })
} }

View File

@ -27,19 +27,18 @@ impl Perform for SavePost {
}; };
if data.save { if data.save {
PostSaved::save(&mut *context.conn().await?, &post_saved_form) PostSaved::save(context.conn().await?, &post_saved_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_post"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_save_post"))?;
} else { } else {
PostSaved::unsave(&mut *context.conn().await?, &post_saved_form) PostSaved::unsave(context.conn().await?, &post_saved_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_post"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_save_post"))?;
} }
let post_id = data.post_id; let post_id = data.post_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let post_view = let post_view = PostView::read(context.conn().await?, post_id, Some(person_id), None).await?;
PostView::read(&mut *context.conn().await?, post_id, Some(person_id), None).await?;
// Mark the post as read // Mark the post as read
mark_post_as_read(person_id, post_id, &mut *context.conn().await?).await?; mark_post_as_read(person_id, post_id, &mut *context.conn().await?).await?;

View File

@ -24,14 +24,14 @@ impl Perform for CreatePostReport {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostReportResponse, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostReportResponse, LemmyError> {
let data: &CreatePostReport = self; let data: &CreatePostReport = 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 *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
let reason = self.reason.trim(); let reason = self.reason.trim();
check_report_reason(reason, &local_site)?; check_report_reason(reason, &local_site)?;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let post_id = data.post_id; let post_id = data.post_id;
let post_view = PostView::read(&mut *context.conn().await?, post_id, None, None).await?; let post_view = PostView::read(context.conn().await?, post_id, None, None).await?;
check_community_ban( check_community_ban(
person_id, person_id,
@ -49,12 +49,12 @@ impl Perform for CreatePostReport {
reason: reason.to_owned(), reason: reason.to_owned(),
}; };
let report = PostReport::report(&mut *context.conn().await?, &report_form) let report = PostReport::report(context.conn().await?, &report_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?;
let post_report_view = let post_report_view =
PostReportView::read(&mut *context.conn().await?, report.id, person_id).await?; PostReportView::read(context.conn().await?, report.id, person_id).await?;
// Email the admins // Email the admins
if local_site.reports_email_admins { if local_site.reports_email_admins {

View File

@ -31,7 +31,7 @@ impl Perform for ListPostReports {
let limit = data.limit; let limit = data.limit;
let mut conn = context.conn().await?; 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)
.admin(admin) .admin(admin)
.community_id(community_id) .community_id(community_id)

View File

@ -21,23 +21,23 @@ impl Perform for ResolvePostReport {
let report_id = data.report_id; let report_id = data.report_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let report = PostReportView::read(&mut *context.conn().await?, report_id, person_id).await?; let report = PostReportView::read(context.conn().await?, report_id, person_id).await?;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
is_mod_or_admin(&mut *context.conn().await?, person_id, report.community.id).await?; is_mod_or_admin(context.conn().await?, person_id, report.community.id).await?;
if data.resolved { if data.resolved {
PostReport::resolve(&mut *context.conn().await?, report_id, person_id) PostReport::resolve(context.conn().await?, report_id, person_id)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
} else { } else {
PostReport::unresolve(&mut *context.conn().await?, report_id, person_id) PostReport::unresolve(context.conn().await?, report_id, person_id)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
} }
let post_report_view = let post_report_view =
PostReportView::read(&mut *context.conn().await?, report_id, person_id).await?; PostReportView::read(context.conn().await?, report_id, person_id).await?;
Ok(PostReportResponse { post_report_view }) Ok(PostReportResponse { post_report_view })
} }

View File

@ -27,7 +27,7 @@ impl Perform for MarkPrivateMessageAsRead {
// Checking permissions // Checking permissions
let private_message_id = data.private_message_id; let private_message_id = data.private_message_id;
let orig_private_message = let orig_private_message =
PrivateMessage::read(&mut *context.conn().await?, private_message_id).await?; PrivateMessage::read(context.conn().await?, private_message_id).await?;
if local_user_view.person.id != orig_private_message.recipient_id { if local_user_view.person.id != orig_private_message.recipient_id {
return Err(LemmyError::from_message("couldnt_update_private_message")); return Err(LemmyError::from_message("couldnt_update_private_message"));
} }
@ -43,7 +43,7 @@ impl Perform for MarkPrivateMessageAsRead {
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
let view = PrivateMessageView::read(&mut *context.conn().await?, private_message_id).await?; let view = PrivateMessageView::read(context.conn().await?, private_message_id).await?;
Ok(PrivateMessageResponse { Ok(PrivateMessageResponse {
private_message_view: view, private_message_view: view,
}) })

View File

@ -23,15 +23,14 @@ impl Perform for CreatePrivateMessageReport {
#[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 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?;
let local_site = LocalSite::read(&mut *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
let reason = self.reason.trim(); let reason = self.reason.trim();
check_report_reason(reason, &local_site)?; check_report_reason(reason, &local_site)?;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let private_message_id = self.private_message_id; let private_message_id = self.private_message_id;
let private_message = let private_message = PrivateMessage::read(context.conn().await?, private_message_id).await?;
PrivateMessage::read(&mut *context.conn().await?, private_message_id).await?;
let report_form = PrivateMessageReportForm { let report_form = PrivateMessageReportForm {
creator_id: person_id, creator_id: person_id,
@ -40,12 +39,12 @@ impl Perform for CreatePrivateMessageReport {
reason: reason.to_owned(), reason: reason.to_owned(),
}; };
let report = PrivateMessageReport::report(&mut *context.conn().await?, &report_form) let report = PrivateMessageReport::report(context.conn().await?, &report_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?;
let private_message_report_view = let private_message_report_view =
PrivateMessageReportView::read(&mut *context.conn().await?, report.id).await?; PrivateMessageReportView::read(context.conn().await?, report.id).await?;
// Email the admins // Email the admins
if local_site.reports_email_admins { if local_site.reports_email_admins {

View File

@ -23,7 +23,7 @@ impl Perform for ListPrivateMessageReports {
let limit = self.limit; let limit = self.limit;
let mut conn = context.conn().await?; 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)
.page(page) .page(page)
.limit(limit) .limit(limit)

View File

@ -22,17 +22,17 @@ impl Perform for ResolvePrivateMessageReport {
let report_id = self.report_id; let report_id = self.report_id;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
if self.resolved { if self.resolved {
PrivateMessageReport::resolve(&mut *context.conn().await?, report_id, person_id) PrivateMessageReport::resolve(context.conn().await?, report_id, person_id)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
} else { } else {
PrivateMessageReport::unresolve(&mut *context.conn().await?, report_id, person_id) PrivateMessageReport::unresolve(context.conn().await?, report_id, person_id)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
} }
let private_message_report_view = let private_message_report_view =
PrivateMessageReportView::read(&mut *context.conn().await?, report_id).await?; PrivateMessageReportView::read(context.conn().await?, report_id).await?;
Ok(PrivateMessageReportResponse { Ok(PrivateMessageReportResponse {
private_message_report_view, private_message_report_view,

View File

@ -14,7 +14,7 @@ impl Perform for GetFederatedInstances {
#[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 site_view = SiteView::read_local(&mut *context.conn().await?).await?; let site_view = SiteView::read_local(context.conn().await?).await?;
let federated_instances = let federated_instances =
build_federated_instances(&site_view.local_site, context.pool()).await?; build_federated_instances(&site_view.local_site, context.pool()).await?;

View File

@ -31,7 +31,7 @@ impl Perform for LeaveAdmin {
is_admin(&local_user_view)?; is_admin(&local_user_view)?;
// Make sure there isn't just one admin (so if one leaves, there will still be one left) // Make sure there isn't just one admin (so if one leaves, there will still be one left)
let admins = PersonView::admins(&mut *context.conn().await?).await?; let admins = PersonView::admins(context.conn().await?).await?;
if admins.len() == 1 { if admins.len() == 1 {
return Err(LemmyError::from_message("cannot_leave_admin")); return Err(LemmyError::from_message("cannot_leave_admin"));
} }
@ -51,17 +51,17 @@ impl Perform for LeaveAdmin {
removed: Some(true), removed: Some(true),
}; };
ModAdd::create(&mut *context.conn().await?, &form).await?; ModAdd::create(context.conn().await?, &form).await?;
// Reread site and admins // Reread site and admins
let site_view = SiteView::read_local(&mut *context.conn().await?).await?; let site_view = SiteView::read_local(context.conn().await?).await?;
let admins = PersonView::admins(&mut *context.conn().await?).await?; let admins = PersonView::admins(context.conn().await?).await?;
let all_languages = Language::read_all(&mut *context.conn().await?).await?; let all_languages = Language::read_all(context.conn().await?).await?;
let discussion_languages = SiteLanguage::read_local_raw(&mut *context.conn().await?).await?; let discussion_languages = SiteLanguage::read_local_raw(context.conn().await?).await?;
let taglines = Tagline::get_all(&mut *context.conn().await?, site_view.local_site.id).await?; let taglines = Tagline::get_all(context.conn().await?, site_view.local_site.id).await?;
let custom_emojis = let custom_emojis =
CustomEmojiView::get_all(&mut *context.conn().await?, site_view.local_site.id).await?; CustomEmojiView::get_all(context.conn().await?, site_view.local_site.id).await?;
Ok(GetSiteResponse { Ok(GetSiteResponse {
site_view, site_view,

View File

@ -40,7 +40,7 @@ impl Perform for GetModlog {
let data: &GetModlog = self; let data: &GetModlog = self;
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await; let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
let local_site = LocalSite::read(&mut *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
check_private_instance(&local_user_view, &local_site)?; check_private_instance(&local_user_view, &local_site)?;
@ -80,51 +80,47 @@ impl Perform for GetModlog {
hide_modlog_names, hide_modlog_names,
}; };
let removed_posts = match type_ { let removed_posts = match type_ {
All | ModRemovePost => ModRemovePostView::list(&mut *context.conn().await?, params).await?, All | ModRemovePost => ModRemovePostView::list(context.conn().await?, params).await?,
_ => Default::default(), _ => Default::default(),
}; };
let locked_posts = match type_ { let locked_posts = match type_ {
All | ModLockPost => ModLockPostView::list(&mut *context.conn().await?, params).await?, All | ModLockPost => ModLockPostView::list(context.conn().await?, params).await?,
_ => Default::default(), _ => Default::default(),
}; };
let featured_posts = match type_ { let featured_posts = match type_ {
All | ModFeaturePost => ModFeaturePostView::list(&mut *context.conn().await?, params).await?, All | ModFeaturePost => ModFeaturePostView::list(context.conn().await?, params).await?,
_ => Default::default(), _ => Default::default(),
}; };
let removed_comments = match type_ { let removed_comments = match type_ {
All | ModRemoveComment => { All | ModRemoveComment => ModRemoveCommentView::list(context.conn().await?, params).await?,
ModRemoveCommentView::list(&mut *context.conn().await?, params).await?
}
_ => Default::default(), _ => Default::default(),
}; };
let banned_from_community = match type_ { let banned_from_community = match type_ {
All | ModBanFromCommunity => { All | ModBanFromCommunity => {
ModBanFromCommunityView::list(&mut *context.conn().await?, params).await? ModBanFromCommunityView::list(context.conn().await?, params).await?
} }
_ => Default::default(), _ => Default::default(),
}; };
let added_to_community = match type_ { let added_to_community = match type_ {
All | ModAddCommunity => { All | ModAddCommunity => ModAddCommunityView::list(context.conn().await?, params).await?,
ModAddCommunityView::list(&mut *context.conn().await?, params).await?
}
_ => Default::default(), _ => Default::default(),
}; };
let transferred_to_community = match type_ { let transferred_to_community = match type_ {
All | ModTransferCommunity => { All | ModTransferCommunity => {
ModTransferCommunityView::list(&mut *context.conn().await?, params).await? ModTransferCommunityView::list(context.conn().await?, params).await?
} }
_ => Default::default(), _ => Default::default(),
}; };
let hidden_communities = match type_ { let hidden_communities = match type_ {
All | ModHideCommunity if other_person_id.is_none() => { All | ModHideCommunity if other_person_id.is_none() => {
ModHideCommunityView::list(&mut *context.conn().await?, params).await? ModHideCommunityView::list(context.conn().await?, params).await?
} }
_ => Default::default(), _ => Default::default(),
}; };
@ -141,40 +137,40 @@ impl Perform for GetModlog {
) = if data.community_id.is_none() { ) = if data.community_id.is_none() {
( (
match type_ { match type_ {
All | ModBan => ModBanView::list(&mut *context.conn().await?, params).await?, All | ModBan => ModBanView::list(context.conn().await?, params).await?,
_ => Default::default(), _ => Default::default(),
}, },
match type_ { match type_ {
All | ModAdd => ModAddView::list(&mut *context.conn().await?, params).await?, All | ModAdd => ModAddView::list(context.conn().await?, params).await?,
_ => Default::default(), _ => Default::default(),
}, },
match type_ { match type_ {
All | ModRemoveCommunity if other_person_id.is_none() => { All | ModRemoveCommunity if other_person_id.is_none() => {
ModRemoveCommunityView::list(&mut *context.conn().await?, params).await? ModRemoveCommunityView::list(context.conn().await?, params).await?
} }
_ => Default::default(), _ => Default::default(),
}, },
match type_ { match type_ {
All | AdminPurgePerson if other_person_id.is_none() => { All | AdminPurgePerson if other_person_id.is_none() => {
AdminPurgePersonView::list(&mut *context.conn().await?, params).await? AdminPurgePersonView::list(context.conn().await?, params).await?
} }
_ => Default::default(), _ => Default::default(),
}, },
match type_ { match type_ {
All | AdminPurgeCommunity if other_person_id.is_none() => { All | AdminPurgeCommunity if other_person_id.is_none() => {
AdminPurgeCommunityView::list(&mut *context.conn().await?, params).await? AdminPurgeCommunityView::list(context.conn().await?, params).await?
} }
_ => Default::default(), _ => Default::default(),
}, },
match type_ { match type_ {
All | AdminPurgePost if other_person_id.is_none() => { All | AdminPurgePost if other_person_id.is_none() => {
AdminPurgePostView::list(&mut *context.conn().await?, params).await? AdminPurgePostView::list(context.conn().await?, params).await?
} }
_ => Default::default(), _ => Default::default(),
}, },
match type_ { match type_ {
All | AdminPurgeComment if other_person_id.is_none() => { All | AdminPurgeComment if other_person_id.is_none() => {
AdminPurgeCommentView::list(&mut *context.conn().await?, params).await? AdminPurgeCommentView::list(context.conn().await?, params).await?
} }
_ => Default::default(), _ => Default::default(),
}, },

View File

@ -29,13 +29,13 @@ impl Perform for PurgeComment {
let comment_id = data.comment_id; let comment_id = data.comment_id;
// Read the comment to get the post_id // Read the comment to get the post_id
let comment = Comment::read(&mut *context.conn().await?, comment_id).await?; let comment = Comment::read(context.conn().await?, comment_id).await?;
let post_id = comment.post_id; let post_id = comment.post_id;
// TODO read comments for pictrs images and purge them // TODO read comments for pictrs images and purge them
Comment::delete(&mut *context.conn().await?, comment_id).await?; Comment::delete(context.conn().await?, comment_id).await?;
// Mod tables // Mod tables
let reason = data.reason.clone(); let reason = data.reason.clone();
@ -45,7 +45,7 @@ impl Perform for PurgeComment {
post_id, post_id,
}; };
AdminPurgeComment::create(&mut *context.conn().await?, &form).await?; AdminPurgeComment::create(context.conn().await?, &form).await?;
Ok(PurgeItemResponse { success: true }) Ok(PurgeItemResponse { success: true })
} }

View File

@ -30,7 +30,7 @@ impl Perform for PurgeCommunity {
let community_id = data.community_id; let community_id = data.community_id;
// Read the community to get its images // Read the community to get its images
let community = Community::read(&mut *context.conn().await?, community_id).await?; let community = Community::read(context.conn().await?, community_id).await?;
if let Some(banner) = community.banner { if let Some(banner) = community.banner {
purge_image_from_pictrs(context.client(), context.settings(), &banner) purge_image_from_pictrs(context.client(), context.settings(), &banner)
@ -52,7 +52,7 @@ impl Perform for PurgeCommunity {
) )
.await?; .await?;
Community::delete(&mut *context.conn().await?, community_id).await?; Community::delete(context.conn().await?, community_id).await?;
// Mod tables // Mod tables
let reason = data.reason.clone(); let reason = data.reason.clone();
@ -61,7 +61,7 @@ impl Perform for PurgeCommunity {
reason, reason,
}; };
AdminPurgeCommunity::create(&mut *context.conn().await?, &form).await?; AdminPurgeCommunity::create(context.conn().await?, &form).await?;
Ok(PurgeItemResponse { success: true }) Ok(PurgeItemResponse { success: true })
} }

View File

@ -29,7 +29,7 @@ impl Perform for PurgePerson {
// Read the person to get their images // Read the person to get their images
let person_id = data.person_id; let person_id = data.person_id;
let person = Person::read(&mut *context.conn().await?, person_id).await?; let person = Person::read(context.conn().await?, person_id).await?;
if let Some(banner) = person.banner { if let Some(banner) = person.banner {
purge_image_from_pictrs(context.client(), context.settings(), &banner) purge_image_from_pictrs(context.client(), context.settings(), &banner)
@ -51,7 +51,7 @@ impl Perform for PurgePerson {
) )
.await?; .await?;
Person::delete(&mut *context.conn().await?, person_id).await?; Person::delete(context.conn().await?, person_id).await?;
// Mod tables // Mod tables
let reason = data.reason.clone(); let reason = data.reason.clone();
@ -60,7 +60,7 @@ impl Perform for PurgePerson {
reason, reason,
}; };
AdminPurgePerson::create(&mut *context.conn().await?, &form).await?; AdminPurgePerson::create(context.conn().await?, &form).await?;
Ok(PurgeItemResponse { success: true }) Ok(PurgeItemResponse { success: true })
} }

View File

@ -30,7 +30,7 @@ impl Perform for PurgePost {
let post_id = data.post_id; let post_id = data.post_id;
// Read the post to get the community_id // Read the post to get the community_id
let post = Post::read(&mut *context.conn().await?, post_id).await?; let post = Post::read(context.conn().await?, post_id).await?;
// Purge image // Purge image
if let Some(url) = post.url { if let Some(url) = post.url {
@ -47,7 +47,7 @@ impl Perform for PurgePost {
let community_id = post.community_id; let community_id = post.community_id;
Post::delete(&mut *context.conn().await?, post_id).await?; Post::delete(context.conn().await?, post_id).await?;
// Mod tables // Mod tables
let reason = data.reason.clone(); let reason = data.reason.clone();
@ -57,7 +57,7 @@ impl Perform for PurgePost {
community_id, community_id,
}; };
AdminPurgePost::create(&mut *context.conn().await?, &form).await?; AdminPurgePost::create(context.conn().await?, &form).await?;
Ok(PurgeItemResponse { success: true }) Ok(PurgeItemResponse { success: true })
} }

View File

@ -37,7 +37,7 @@ impl Perform for ApproveRegistrationApplication {
}; };
let registration_application = let registration_application =
RegistrationApplication::update(&mut *context.conn().await?, app_id, &app_form).await?; RegistrationApplication::update(context.conn().await?, app_id, &app_form).await?;
// Update the local_user row // Update the local_user row
let local_user_form = LocalUserUpdateForm::builder() let local_user_form = LocalUserUpdateForm::builder()
@ -54,7 +54,7 @@ impl Perform for ApproveRegistrationApplication {
if data.approve { if data.approve {
let approved_local_user_view = let approved_local_user_view =
LocalUserView::read(&mut *context.conn().await?, approved_user_id).await?; LocalUserView::read(context.conn().await?, approved_user_id).await?;
if approved_local_user_view.local_user.email.is_some() { if approved_local_user_view.local_user.email.is_some() {
send_application_approved_email(&approved_local_user_view, context.settings())?; send_application_approved_email(&approved_local_user_view, context.settings())?;
@ -63,7 +63,7 @@ impl Perform for ApproveRegistrationApplication {
// Read the view // Read the view
let registration_application = let registration_application =
RegistrationApplicationView::read(&mut *context.conn().await?, app_id).await?; RegistrationApplicationView::read(context.conn().await?, app_id).await?;
Ok(Self::Response { Ok(Self::Response {
registration_application, registration_application,

View File

@ -17,7 +17,7 @@ impl Perform for ListRegistrationApplications {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
let data = self; let data = 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 *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
// Make sure user is an admin // Make sure user is an admin
is_admin(&local_user_view)?; is_admin(&local_user_view)?;
@ -29,7 +29,7 @@ impl Perform for ListRegistrationApplications {
let limit = data.limit; let limit = data.limit;
let mut conn = context.conn().await?; 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)
.verified_email_only(Some(verified_email_only)) .verified_email_only(Some(verified_email_only))
.page(page) .page(page)

View File

@ -16,7 +16,7 @@ impl Perform for GetUnreadRegistrationApplicationCount {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
let data = self; let data = 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 *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
// Only let admins do this // Only let admins do this
is_admin(&local_user_view)?; is_admin(&local_user_view)?;

View File

@ -30,7 +30,7 @@ pub async fn build_comment_response(
recipient_ids: Vec<LocalUserId>, recipient_ids: Vec<LocalUserId>,
) -> Result<CommentResponse, LemmyError> { ) -> Result<CommentResponse, LemmyError> {
let person_id = local_user_view.map(|l| l.person.id); let person_id = local_user_view.map(|l| l.person.id);
let comment_view = CommentView::read(&mut *context.conn().await?, comment_id, person_id).await?; let comment_view = CommentView::read(context.conn().await?, comment_id, person_id).await?;
Ok(CommentResponse { Ok(CommentResponse {
comment_view, comment_view,
recipient_ids, recipient_ids,
@ -58,8 +58,7 @@ pub async fn build_community_response(
Some(is_mod_or_admin), Some(is_mod_or_admin),
) )
.await?; .await?;
let discussion_languages = let discussion_languages = CommunityLanguage::read(context.conn().await?, community_id).await?;
CommunityLanguage::read(&mut *context.conn().await?, community_id).await?;
Ok(CommunityResponse { Ok(CommunityResponse {
community_view, community_view,
@ -73,7 +72,7 @@ pub async fn build_post_response(
person_id: PersonId, person_id: PersonId,
post_id: PostId, post_id: PostId,
) -> Result<PostResponse, LemmyError> { ) -> Result<PostResponse, LemmyError> {
let is_mod_or_admin = is_mod_or_admin(&mut *context.conn().await?, person_id, community_id) let is_mod_or_admin = is_mod_or_admin(context.conn().await?, person_id, community_id)
.await .await
.is_ok(); .is_ok();
let post_view = PostView::read( let post_view = PostView::read(
@ -105,7 +104,7 @@ pub async fn send_local_notifs(
.filter(|m| m.is_local(&context.settings().hostname) && m.name.ne(&person.name)) .filter(|m| m.is_local(&context.settings().hostname) && m.name.ne(&person.name))
{ {
let mention_name = mention.name.clone(); let mention_name = mention.name.clone();
let user_view = LocalUserView::read_from_name(&mut *context.conn().await?, &mention_name).await; let user_view = LocalUserView::read_from_name(context.conn().await?, &mention_name).await;
if let Ok(mention_user_view) = user_view { if let Ok(mention_user_view) = user_view {
// TODO // TODO
// At some point, make it so you can't tag the parent creator either // At some point, make it so you can't tag the parent creator either
@ -120,7 +119,7 @@ pub async fn send_local_notifs(
// Allow this to fail softly, since comment edits might re-update or replace it // Allow this to fail softly, since comment edits might re-update or replace it
// Let the uniqueness handle this fail // Let the uniqueness handle this fail
PersonMention::create(&mut *context.conn().await?, &user_mention_form) PersonMention::create(context.conn().await?, &user_mention_form)
.await .await
.ok(); .ok();
@ -139,7 +138,7 @@ pub async fn send_local_notifs(
// Send comment_reply to the parent commenter / poster // Send comment_reply to the parent commenter / poster
if let Some(parent_comment_id) = comment.parent_comment_id() { if let Some(parent_comment_id) = comment.parent_comment_id() {
let parent_comment = Comment::read(&mut *context.conn().await?, parent_comment_id).await?; let parent_comment = Comment::read(context.conn().await?, parent_comment_id).await?;
// Get the parent commenter local_user // Get the parent commenter local_user
let parent_creator_id = parent_comment.creator_id; let parent_creator_id = parent_comment.creator_id;
@ -152,8 +151,7 @@ pub async fn send_local_notifs(
// Don't send a notif to yourself // Don't send a notif to yourself
if parent_comment.creator_id != person.id && !creator_blocked { if parent_comment.creator_id != person.id && !creator_blocked {
let user_view = let user_view = LocalUserView::read_person(context.conn().await?, parent_creator_id).await;
LocalUserView::read_person(&mut *context.conn().await?, parent_creator_id).await;
if let Ok(parent_user_view) = user_view { if let Ok(parent_user_view) = user_view {
recipient_ids.push(parent_user_view.local_user.id); recipient_ids.push(parent_user_view.local_user.id);
@ -165,7 +163,7 @@ pub async fn send_local_notifs(
// Allow this to fail softly, since comment edits might re-update or replace it // Allow this to fail softly, since comment edits might re-update or replace it
// Let the uniqueness handle this fail // Let the uniqueness handle this fail
CommentReply::create(&mut *context.conn().await?, &comment_reply_form) CommentReply::create(context.conn().await?, &comment_reply_form)
.await .await
.ok(); .ok();
@ -190,7 +188,7 @@ pub async fn send_local_notifs(
if post.creator_id != person.id && !creator_blocked { if post.creator_id != person.id && !creator_blocked {
let creator_id = post.creator_id; let creator_id = post.creator_id;
let parent_user = LocalUserView::read_person(&mut *context.conn().await?, creator_id).await; let parent_user = LocalUserView::read_person(context.conn().await?, creator_id).await;
if let Ok(parent_user_view) = parent_user { if let Ok(parent_user_view) = parent_user {
recipient_ids.push(parent_user_view.local_user.id); recipient_ids.push(parent_user_view.local_user.id);
@ -202,7 +200,7 @@ pub async fn send_local_notifs(
// Allow this to fail softly, since comment edits might re-update or replace it // Allow this to fail softly, since comment edits might re-update or replace it
// Let the uniqueness handle this fail // Let the uniqueness handle this fail
CommentReply::create(&mut *context.conn().await?, &comment_reply_form) CommentReply::create(context.conn().await?, &comment_reply_form)
.await .await
.ok(); .ok();

View File

@ -50,11 +50,11 @@ 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(
conn: &mut DbConn, mut conn: impl DbConn,
person_id: PersonId, person_id: PersonId,
community_id: CommunityId, community_id: CommunityId,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let is_mod_or_admin = CommunityView::is_mod_or_admin(conn, person_id, community_id).await?; let is_mod_or_admin = CommunityView::is_mod_or_admin(&mut *conn, person_id, community_id).await?;
if !is_mod_or_admin { if !is_mod_or_admin {
return Err(LemmyError::from_message("not_a_mod_or_admin")); return Err(LemmyError::from_message("not_a_mod_or_admin"));
} }
@ -63,13 +63,13 @@ 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(
conn: &mut DbConn, mut conn: impl DbConn,
local_user_view: Option<&LocalUserView>, local_user_view: Option<&LocalUserView>,
community_id: Option<CommunityId>, community_id: Option<CommunityId>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
if let Some(local_user_view) = local_user_view { if let Some(local_user_view) = local_user_view {
if let Some(community_id) = community_id { if let Some(community_id) = community_id {
is_mod_or_admin(conn, local_user_view.person.id, community_id).await is_mod_or_admin(&mut *conn, local_user_view.person.id, community_id).await
} else { } else {
is_admin(local_user_view) is_admin(local_user_view)
} }
@ -101,8 +101,8 @@ pub fn is_top_mod(
} }
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
pub async fn get_post(post_id: PostId, conn: &mut DbConn) -> Result<Post, LemmyError> { pub async fn get_post(post_id: PostId, mut conn: impl DbConn) -> Result<Post, LemmyError> {
Post::read(conn, post_id) Post::read(&mut *conn, 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,11 +111,11 @@ pub async fn get_post(post_id: PostId, conn: &mut DbConn) -> Result<Post, LemmyE
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,
conn: &mut DbConn, mut conn: impl DbConn,
) -> Result<PostRead, LemmyError> { ) -> Result<PostRead, LemmyError> {
let post_read_form = PostReadForm { post_id, person_id }; let post_read_form = PostReadForm { post_id, person_id };
PostRead::mark_as_read(conn, &post_read_form) PostRead::mark_as_read(&mut *conn, &post_read_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_mark_post_as_read")) .map_err(|e| LemmyError::from_error_message(e, "couldnt_mark_post_as_read"))
} }
@ -124,11 +124,11 @@ 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,
conn: &mut DbConn, mut conn: impl DbConn,
) -> Result<usize, LemmyError> { ) -> Result<usize, LemmyError> {
let post_read_form = PostReadForm { post_id, person_id }; let post_read_form = PostReadForm { post_id, person_id };
PostRead::mark_as_unread(conn, &post_read_form) PostRead::mark_as_unread(&mut *conn, &post_read_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_mark_post_as_read")) .map_err(|e| LemmyError::from_error_message(e, "couldnt_mark_post_as_read"))
} }
@ -142,7 +142,7 @@ pub async fn local_user_view_from_jwt(
.map_err(|e| e.with_message("not_logged_in"))? .map_err(|e| e.with_message("not_logged_in"))?
.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?, local_user_id).await?; let local_user_view = LocalUserView::read(context.conn().await?, local_user_id).await?;
check_user_valid( check_user_valid(
local_user_view.person.banned, local_user_view.person.banned,
local_user_view.person.ban_expires, local_user_view.person.ban_expires,
@ -197,9 +197,9 @@ 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,
conn: &mut DbConn, mut conn: impl DbConn,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let is_banned = CommunityPersonBanView::get(conn, person_id, community_id) let is_banned = CommunityPersonBanView::get(&mut *conn, person_id, community_id)
.await .await
.is_ok(); .is_ok();
if is_banned { if is_banned {
@ -212,9 +212,9 @@ 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,
conn: &mut DbConn, mut conn: impl DbConn,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let community = Community::read(conn, community_id) let community = Community::read(&mut *conn, community_id)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
if community.deleted || community.removed { if community.deleted || community.removed {
@ -236,9 +236,9 @@ 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,
conn: &mut DbConn, mut conn: impl DbConn,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let is_blocked = PersonBlock::read(conn, potential_blocker_id, my_id) let is_blocked = PersonBlock::read(&mut *conn, potential_blocker_id, my_id)
.await .await
.is_ok(); .is_ok();
if is_blocked { if is_blocked {
@ -279,9 +279,9 @@ pub async fn build_federated_instances(
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
let (linked, allowed, blocked) = try_join!( let (linked, allowed, blocked) = try_join!(
Instance::linked(conn_0), Instance::linked(&mut *conn_0),
Instance::allowlist(conn_1), Instance::allowlist(&mut *conn_1),
Instance::blocklist(conn_2) Instance::blocklist(&mut *conn_2)
)?; )?;
Ok(Some(FederatedInstances { Ok(Some(FederatedInstances {
@ -338,7 +338,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,
conn: &mut DbConn, mut conn: impl DbConn,
settings: &Settings, settings: &Settings,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
// Generate a random token // Generate a random token
@ -347,7 +347,7 @@ pub async fn send_password_reset_email(
// Insert the row // Insert the row
let token2 = token.clone(); let token2 = token.clone();
let local_user_id = user.local_user.id; let local_user_id = user.local_user.id;
PasswordResetRequest::create_token(conn, local_user_id, &token2).await?; PasswordResetRequest::create_token(&mut *conn, local_user_id, &token2).await?;
let email = &user.local_user.email.clone().expect("email"); let email = &user.local_user.email.clone().expect("email");
let lang = get_interface_language(user); let lang = get_interface_language(user);
@ -362,7 +362,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,
conn: &mut DbConn, mut conn: impl DbConn,
settings: &Settings, settings: &Settings,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let form = EmailVerificationForm { let form = EmailVerificationForm {
@ -375,7 +375,7 @@ pub async fn send_verification_email(
settings.get_protocol_and_hostname(), settings.get_protocol_and_hostname(),
&form.verification_token &form.verification_token
); );
EmailVerification::create(conn, &form).await?; EmailVerification::create(&mut *conn, &form).await?;
let lang = get_interface_language(user); let lang = get_interface_language(user);
let subject = lang.verify_email_subject(&settings.hostname); let subject = lang.verify_email_subject(&settings.hostname);
@ -453,11 +453,11 @@ 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,
conn: &mut DbConn, mut conn: impl DbConn,
settings: &Settings, settings: &Settings,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
// Collect the admins with emails // Collect the admins with emails
let admins = LocalUserView::list_admins_with_emails(conn).await?; let admins = LocalUserView::list_admins_with_emails(&mut *conn).await?;
let applications_link = &format!( let applications_link = &format!(
"{}/registration_applications", "{}/registration_applications",
@ -478,11 +478,11 @@ 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,
conn: &mut DbConn, mut conn: impl DbConn,
settings: &Settings, settings: &Settings,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
// Collect the admins with emails // Collect the admins with emails
let admins = LocalUserView::list_admins_with_emails(conn).await?; let admins = LocalUserView::list_admins_with_emails(&mut *conn).await?;
let reports_link = &format!("{}/reports", settings.get_protocol_and_hostname(),); let reports_link = &format!("{}/reports", settings.get_protocol_and_hostname(),);
@ -499,7 +499,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,
conn: &mut DbConn, mut conn: impl DbConn,
) -> 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)
@ -508,7 +508,8 @@ pub async fn check_registration_application(
{ {
// Fetch the registration, see if its denied // Fetch the registration, see if its denied
let local_user_id = local_user_view.local_user.id; let local_user_id = local_user_view.local_user.id;
let registration = RegistrationApplication::find_by_local_user_id(conn, local_user_id).await?; let registration =
RegistrationApplication::find_by_local_user_id(&mut *conn, local_user_id).await?;
if let Some(deny_reason) = registration.deny_reason { if let Some(deny_reason) = registration.deny_reason {
let lang = get_interface_language(local_user_view); let lang = get_interface_language(local_user_view);
let registration_denied_message = format!("{}: {}", lang.registration_denied(), &deny_reason); let registration_denied_message = format!("{}: {}", lang.registration_denied(), &deny_reason);
@ -533,11 +534,11 @@ 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,
conn: &mut DbConn, mut conn: impl DbConn,
settings: &Settings, settings: &Settings,
client: &ClientWithMiddleware, client: &ClientWithMiddleware,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let posts = Post::fetch_pictrs_posts_for_creator(conn, banned_person_id).await?; let posts = Post::fetch_pictrs_posts_for_creator(&mut *conn, banned_person_id).await?;
for post in posts { for post in posts {
if let Some(url) = post.url { if let Some(url) = post.url {
purge_image_from_pictrs(client, settings, &url).await.ok(); purge_image_from_pictrs(client, settings, &url).await.ok();
@ -549,18 +550,18 @@ pub async fn purge_image_posts_for_person(
} }
} }
Post::remove_pictrs_post_images_and_thumbnails_for_creator(conn, banned_person_id).await?; Post::remove_pictrs_post_images_and_thumbnails_for_creator(&mut *conn, banned_person_id).await?;
Ok(()) Ok(())
} }
pub async fn purge_image_posts_for_community( pub async fn purge_image_posts_for_community(
banned_community_id: CommunityId, banned_community_id: CommunityId,
conn: &mut DbConn, mut conn: impl DbConn,
settings: &Settings, settings: &Settings,
client: &ClientWithMiddleware, client: &ClientWithMiddleware,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let posts = Post::fetch_pictrs_posts_for_community(conn, banned_community_id).await?; let posts = Post::fetch_pictrs_posts_for_community(&mut *conn, banned_community_id).await?;
for post in posts { for post in posts {
if let Some(url) = post.url { if let Some(url) = post.url {
purge_image_from_pictrs(client, settings, &url).await.ok(); purge_image_from_pictrs(client, settings, &url).await.ok();
@ -572,19 +573,20 @@ pub async fn purge_image_posts_for_community(
} }
} }
Post::remove_pictrs_post_images_and_thumbnails_for_community(conn, banned_community_id).await?; Post::remove_pictrs_post_images_and_thumbnails_for_community(&mut *conn, banned_community_id)
.await?;
Ok(()) Ok(())
} }
pub async fn remove_user_data( pub async fn remove_user_data(
banned_person_id: PersonId, banned_person_id: PersonId,
conn: &mut DbConn, mut conn: impl DbConn,
settings: &Settings, settings: &Settings,
client: &ClientWithMiddleware, client: &ClientWithMiddleware,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
// Purge user images // Purge user images
let person = Person::read(conn, banned_person_id).await?; let person = Person::read(&mut *conn, banned_person_id).await?;
if let Some(avatar) = person.avatar { if let Some(avatar) = person.avatar {
purge_image_from_pictrs(client, settings, &avatar) purge_image_from_pictrs(client, settings, &avatar)
.await .await
@ -598,7 +600,7 @@ pub async fn remove_user_data(
// Update the fields to None // Update the fields to None
Person::update( Person::update(
conn, &mut *conn,
banned_person_id, banned_person_id,
&PersonUpdateForm::builder() &PersonUpdateForm::builder()
.avatar(Some(None)) .avatar(Some(None))
@ -608,15 +610,15 @@ pub async fn remove_user_data(
.await?; .await?;
// Posts // Posts
Post::update_removed_for_creator(conn, banned_person_id, None, true).await?; Post::update_removed_for_creator(&mut *conn, banned_person_id, None, true).await?;
// Purge image posts // Purge image posts
purge_image_posts_for_person(banned_person_id, conn, settings, client).await?; purge_image_posts_for_person(banned_person_id, &mut *conn, settings, client).await?;
// Communities // Communities
// Remove all communities where they're the top mod // Remove all communities where they're the top mod
// for now, remove the communities manually // for now, remove the communities manually
let first_mod_communities = CommunityModeratorView::get_community_first_mods(conn).await?; let first_mod_communities = CommunityModeratorView::get_community_first_mods(&mut *conn).await?;
// Filter to only this banned users top communities // Filter to only this banned users top communities
let banned_user_first_communities: Vec<CommunityModeratorView> = first_mod_communities let banned_user_first_communities: Vec<CommunityModeratorView> = first_mod_communities
@ -627,7 +629,7 @@ pub async fn remove_user_data(
for first_mod_community in banned_user_first_communities { for first_mod_community in banned_user_first_communities {
let community_id = first_mod_community.community.id; let community_id = first_mod_community.community.id;
Community::update( Community::update(
conn, &mut *conn,
community_id, community_id,
&CommunityUpdateForm::builder().removed(Some(true)).build(), &CommunityUpdateForm::builder().removed(Some(true)).build(),
) )
@ -644,7 +646,7 @@ pub async fn remove_user_data(
} }
// Update the fields to None // Update the fields to None
Community::update( Community::update(
conn, &mut *conn,
community_id, community_id,
&CommunityUpdateForm::builder() &CommunityUpdateForm::builder()
.icon(Some(None)) .icon(Some(None))
@ -655,7 +657,7 @@ pub async fn remove_user_data(
} }
// Comments // Comments
Comment::update_removed_for_creator(conn, banned_person_id, true).await?; Comment::update_removed_for_creator(&mut *conn, banned_person_id, true).await?;
Ok(()) Ok(())
} }
@ -663,15 +665,15 @@ 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,
conn: &mut DbConn, mut conn: impl DbConn,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
// Posts // Posts
Post::update_removed_for_creator(conn, banned_person_id, Some(community_id), true).await?; Post::update_removed_for_creator(&mut *conn, banned_person_id, Some(community_id), true).await?;
// Comments // Comments
// TODO Diesel doesn't allow updates with joins, so this has to be a loop // TODO Diesel doesn't allow updates with joins, so this has to be a loop
let comments = CommentQuery::builder() let comments = CommentQuery::builder()
.conn(conn) .conn(&mut *conn)
.creator_id(Some(banned_person_id)) .creator_id(Some(banned_person_id))
.community_id(Some(community_id)) .community_id(Some(community_id))
.limit(Some(i64::MAX)) .limit(Some(i64::MAX))
@ -682,7 +684,7 @@ pub async fn remove_user_data_in_community(
for comment_view in &comments { for comment_view in &comments {
let comment_id = comment_view.comment.id; let comment_id = comment_view.comment.id;
Comment::update( Comment::update(
conn, &mut *conn,
comment_id, comment_id,
&CommentUpdateForm::builder().removed(Some(true)).build(), &CommentUpdateForm::builder().removed(Some(true)).build(),
) )
@ -694,12 +696,12 @@ 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,
conn: &mut DbConn, mut conn: impl DbConn,
settings: &Settings, settings: &Settings,
client: &ClientWithMiddleware, client: &ClientWithMiddleware,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
// Delete their images // Delete their images
let person = Person::read(conn, person_id).await?; let person = Person::read(&mut *conn, person_id).await?;
if let Some(avatar) = person.avatar { if let Some(avatar) = person.avatar {
purge_image_from_pictrs(client, settings, &avatar) purge_image_from_pictrs(client, settings, &avatar)
.await .await
@ -713,22 +715,22 @@ pub async fn delete_user_account(
// No need to update avatar and banner, those are handled in Person::delete_account // No need to update avatar and banner, those are handled in Person::delete_account
// Comments // Comments
Comment::permadelete_for_creator(conn, person_id) Comment::permadelete_for_creator(&mut *conn, person_id)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
// Posts // Posts
Post::permadelete_for_creator(conn, person_id) Post::permadelete_for_creator(&mut *conn, person_id)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_post"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_post"))?;
// Purge image posts // Purge image posts
purge_image_posts_for_person(person_id, conn, settings, client).await?; purge_image_posts_for_person(person_id, &mut *conn, settings, client).await?;
// Leave communities they mod // Leave communities they mod
CommunityModerator::leave_all_communities(conn, person_id).await?; CommunityModerator::leave_all_communities(&mut *conn, person_id).await?;
Person::delete_account(conn, person_id).await?; Person::delete_account(&mut *conn, person_id).await?;
Ok(()) Ok(())
} }

View File

@ -43,7 +43,7 @@ impl PerformCrud for CreateComment {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
let data: &CreateComment = self; let data: &CreateComment = 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 *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
let content_slurs_removed = remove_slurs( let content_slurs_removed = remove_slurs(
&data.content.clone(), &data.content.clone(),
@ -72,9 +72,7 @@ impl PerformCrud for CreateComment {
// Fetch the parent, if it exists // Fetch the parent, if it exists
let parent_opt = if let Some(parent_id) = data.parent_id { let parent_opt = if let Some(parent_id) = data.parent_id {
Comment::read(&mut *context.conn().await?, parent_id) Comment::read(context.conn().await?, parent_id).await.ok()
.await
.ok()
} else { } else {
None None
}; };
@ -156,15 +154,14 @@ impl PerformCrud for CreateComment {
score: 1, score: 1,
}; };
CommentLike::like(&mut *context.conn().await?, &like_form) CommentLike::like(context.conn().await?, &like_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;
// If its a reply, mark the parent as read // If its a reply, mark the parent as read
if let Some(parent) = parent_opt { if let Some(parent) = parent_opt {
let parent_id = parent.id; let parent_id = parent.id;
let comment_reply = let comment_reply = CommentReply::read_by_comment(context.conn().await?, parent_id).await;
CommentReply::read_by_comment(&mut *context.conn().await?, parent_id).await;
if let Ok(reply) = comment_reply { if let Ok(reply) = comment_reply {
CommentReply::update( CommentReply::update(
&mut *context.conn().await?, &mut *context.conn().await?,

View File

@ -26,7 +26,7 @@ impl PerformCrud for DeleteComment {
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 comment_id = data.comment_id; let comment_id = data.comment_id;
let orig_comment = CommentView::read(&mut *context.conn().await?, comment_id, None).await?; let orig_comment = CommentView::read(context.conn().await?, comment_id, None).await?;
// Dont delete it if its already been deleted. // Dont delete it if its already been deleted.
if orig_comment.comment.deleted == data.deleted { if orig_comment.comment.deleted == data.deleted {
@ -56,7 +56,7 @@ impl PerformCrud for DeleteComment {
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
let post_id = updated_comment.post_id; let post_id = updated_comment.post_id;
let post = Post::read(&mut *context.conn().await?, post_id).await?; let post = Post::read(context.conn().await?, post_id).await?;
let recipient_ids = send_local_notifs( let recipient_ids = send_local_notifs(
vec![], vec![],
&updated_comment, &updated_comment,

View File

@ -17,7 +17,7 @@ impl PerformCrud for GetComment {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
let data = self; let data = self;
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await; let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
let local_site = LocalSite::read(&mut *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
check_private_instance(&local_user_view, &local_site)?; check_private_instance(&local_user_view, &local_site)?;

View File

@ -27,7 +27,7 @@ impl PerformCrud for RemoveComment {
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 comment_id = data.comment_id; let comment_id = data.comment_id;
let orig_comment = CommentView::read(&mut *context.conn().await?, comment_id, None).await?; let orig_comment = CommentView::read(context.conn().await?, comment_id, None).await?;
check_community_ban( check_community_ban(
local_user_view.person.id, local_user_view.person.id,
@ -61,10 +61,10 @@ impl PerformCrud for RemoveComment {
removed: Some(removed), removed: Some(removed),
reason: data.reason.clone(), reason: data.reason.clone(),
}; };
ModRemoveComment::create(&mut *context.conn().await?, &form).await?; ModRemoveComment::create(context.conn().await?, &form).await?;
let post_id = updated_comment.post_id; let post_id = updated_comment.post_id;
let post = Post::read(&mut *context.conn().await?, post_id).await?; let post = Post::read(context.conn().await?, post_id).await?;
let recipient_ids = send_local_notifs( let recipient_ids = send_local_notifs(
vec![], vec![],
&updated_comment, &updated_comment,

View File

@ -33,10 +33,10 @@ impl PerformCrud for EditComment {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
let data: &EditComment = self; let data: &EditComment = 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 *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
let comment_id = data.comment_id; let comment_id = data.comment_id;
let orig_comment = CommentView::read(&mut *context.conn().await?, comment_id, None).await?; let orig_comment = CommentView::read(context.conn().await?, comment_id, None).await?;
check_community_ban( check_community_ban(
local_user_view.person.id, local_user_view.person.id,
@ -72,7 +72,7 @@ impl PerformCrud for EditComment {
.language_id(data.language_id) .language_id(data.language_id)
.updated(Some(Some(naive_now()))) .updated(Some(Some(naive_now())))
.build(); .build();
let updated_comment = Comment::update(&mut *context.conn().await?, comment_id, &form) let updated_comment = Comment::update(context.conn().await?, comment_id, &form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;

View File

@ -48,7 +48,7 @@ impl PerformCrud for CreateCommunity {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
let data: &CreateCommunity = self; let data: &CreateCommunity = 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 site_view = SiteView::read_local(&mut *context.conn().await?).await?; let site_view = SiteView::read_local(context.conn().await?).await?;
let local_site = site_view.local_site; let local_site = site_view.local_site;
if local_site.community_creation_admin_only && is_admin(&local_user_view).is_err() { if local_site.community_creation_admin_only && is_admin(&local_user_view).is_err() {
@ -76,7 +76,7 @@ impl PerformCrud for CreateCommunity {
&context.settings().get_protocol_and_hostname(), &context.settings().get_protocol_and_hostname(),
)?; )?;
let community_dupe = let community_dupe =
Community::read_from_apub_id(&mut *context.conn().await?, &community_actor_id).await?; Community::read_from_apub_id(context.conn().await?, &community_actor_id).await?;
if community_dupe.is_some() { if community_dupe.is_some() {
return Err(LemmyError::from_message("community_already_exists")); return Err(LemmyError::from_message("community_already_exists"));
} }
@ -101,7 +101,7 @@ impl PerformCrud for CreateCommunity {
.instance_id(site_view.site.instance_id) .instance_id(site_view.site.instance_id)
.build(); .build();
let inserted_community = Community::create(&mut *context.conn().await?, &community_form) let inserted_community = Community::create(context.conn().await?, &community_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "community_already_exists"))?; .map_err(|e| LemmyError::from_error_message(e, "community_already_exists"))?;
@ -111,7 +111,7 @@ impl PerformCrud for CreateCommunity {
person_id: local_user_view.person.id, person_id: local_user_view.person.id,
}; };
CommunityModerator::join(&mut *context.conn().await?, &community_moderator_form) CommunityModerator::join(context.conn().await?, &community_moderator_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?; .map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
@ -122,21 +122,21 @@ impl PerformCrud for CreateCommunity {
pending: false, pending: false,
}; };
CommunityFollower::follow(&mut *context.conn().await?, &community_follower_form) CommunityFollower::follow(context.conn().await?, &community_follower_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?; .map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
// Update the discussion_languages if that's provided // Update the discussion_languages if that's provided
let community_id = inserted_community.id; let community_id = inserted_community.id;
if let Some(languages) = data.discussion_languages.clone() { if let Some(languages) = data.discussion_languages.clone() {
let site_languages = SiteLanguage::read_local_raw(&mut *context.conn().await?).await?; let site_languages = SiteLanguage::read_local_raw(context.conn().await?).await?;
// check that community languages are a subset of site languages // check that community languages are a subset of site languages
// https://stackoverflow.com/a/64227550 // https://stackoverflow.com/a/64227550
let is_subset = languages.iter().all(|item| site_languages.contains(item)); let is_subset = languages.iter().all(|item| site_languages.contains(item));
if !is_subset { if !is_subset {
return Err(LemmyError::from_message("language_not_allowed")); return Err(LemmyError::from_message("language_not_allowed"));
} }
CommunityLanguage::update(&mut *context.conn().await?, languages, community_id).await?; CommunityLanguage::update(context.conn().await?, languages, community_id).await?;
} }
build_community_response(context, local_user_view, community_id).await build_community_response(context, local_user_view, community_id).await

View File

@ -25,7 +25,7 @@ impl PerformCrud for DeleteCommunity {
// Fetch the community mods // Fetch the community mods
let community_id = data.community_id; let community_id = data.community_id;
let community_mods = let community_mods =
CommunityModeratorView::for_community(&mut *context.conn().await?, community_id).await?; CommunityModeratorView::for_community(context.conn().await?, community_id).await?;
// Make sure deleter is the top mod // Make sure deleter is the top mod
is_top_mod(&local_user_view, &community_mods)?; is_top_mod(&local_user_view, &community_mods)?;

View File

@ -20,7 +20,7 @@ impl PerformCrud for ListCommunities {
) -> Result<ListCommunitiesResponse, LemmyError> { ) -> Result<ListCommunitiesResponse, LemmyError> {
let data: &ListCommunities = self; let data: &ListCommunities = self;
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await; let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
let local_site = LocalSite::read(&mut *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok()); let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
check_private_instance(&local_user_view, &local_site)?; check_private_instance(&local_user_view, &local_site)?;
@ -33,7 +33,7 @@ impl PerformCrud for ListCommunities {
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 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)
.show_nsfw(show_nsfw) .show_nsfw(show_nsfw)
.sort(sort) .sort(sort)

View File

@ -49,7 +49,7 @@ impl PerformCrud for RemoveCommunity {
reason: data.reason.clone(), reason: data.reason.clone(),
expires, expires,
}; };
ModRemoveCommunity::create(&mut *context.conn().await?, &form).await?; ModRemoveCommunity::create(context.conn().await?, &form).await?;
build_community_response(context, local_user_view, community_id).await build_community_response(context, local_user_view, community_id).await
} }

View File

@ -30,7 +30,7 @@ impl PerformCrud for EditCommunity {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
let data: &EditCommunity = self; let data: &EditCommunity = 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 *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
let icon = diesel_option_overwrite_to_url(&data.icon)?; let icon = diesel_option_overwrite_to_url(&data.icon)?;
let banner = diesel_option_overwrite_to_url(&data.banner)?; let banner = diesel_option_overwrite_to_url(&data.banner)?;
@ -44,7 +44,7 @@ impl PerformCrud for EditCommunity {
// Verify its a mod (only mods can edit it) // Verify its a mod (only mods can edit it)
let community_id = data.community_id; let community_id = data.community_id;
let mods: Vec<PersonId> = let mods: Vec<PersonId> =
CommunityModeratorView::for_community(&mut *context.conn().await?, community_id) CommunityModeratorView::for_community(context.conn().await?, community_id)
.await .await
.map(|v| v.into_iter().map(|m| m.moderator.id).collect())?; .map(|v| v.into_iter().map(|m| m.moderator.id).collect())?;
if !mods.contains(&local_user_view.person.id) { if !mods.contains(&local_user_view.person.id) {
@ -53,14 +53,14 @@ impl PerformCrud for EditCommunity {
let community_id = data.community_id; let community_id = data.community_id;
if let Some(languages) = data.discussion_languages.clone() { if let Some(languages) = data.discussion_languages.clone() {
let site_languages = SiteLanguage::read_local_raw(&mut *context.conn().await?).await?; let site_languages = SiteLanguage::read_local_raw(context.conn().await?).await?;
// check that community languages are a subset of site languages // check that community languages are a subset of site languages
// https://stackoverflow.com/a/64227550 // https://stackoverflow.com/a/64227550
let is_subset = languages.iter().all(|item| site_languages.contains(item)); let is_subset = languages.iter().all(|item| site_languages.contains(item));
if !is_subset { if !is_subset {
return Err(LemmyError::from_message("language_not_allowed")); return Err(LemmyError::from_message("language_not_allowed"));
} }
CommunityLanguage::update(&mut *context.conn().await?, languages, community_id).await?; CommunityLanguage::update(context.conn().await?, languages, community_id).await?;
} }
let community_form = CommunityUpdateForm::builder() let community_form = CommunityUpdateForm::builder()
@ -74,7 +74,7 @@ impl PerformCrud for EditCommunity {
.build(); .build();
let community_id = data.community_id; let community_id = data.community_id;
Community::update(&mut *context.conn().await?, community_id, &community_form) Community::update(context.conn().await?, community_id, &community_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community"))?;

View File

@ -22,7 +22,7 @@ impl PerformCrud for CreateCustomEmoji {
let data: &CreateCustomEmoji = self; let data: &CreateCustomEmoji = 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 *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
// Make sure user is an admin // Make sure user is an admin
is_admin(&local_user_view)?; is_admin(&local_user_view)?;
@ -33,7 +33,7 @@ impl PerformCrud for CreateCustomEmoji {
.category(data.category.to_string()) .category(data.category.to_string())
.image_url(data.clone().image_url.into()) .image_url(data.clone().image_url.into())
.build(); .build();
let emoji = CustomEmoji::create(&mut *context.conn().await?, &emoji_form).await?; let emoji = CustomEmoji::create(context.conn().await?, &emoji_form).await?;
let mut keywords = vec![]; let mut keywords = vec![];
for keyword in &data.keywords { for keyword in &data.keywords {
let keyword_form = CustomEmojiKeywordInsertForm::builder() let keyword_form = CustomEmojiKeywordInsertForm::builder()
@ -42,8 +42,8 @@ impl PerformCrud for CreateCustomEmoji {
.build(); .build();
keywords.push(keyword_form); keywords.push(keyword_form);
} }
CustomEmojiKeyword::create(&mut *context.conn().await?, keywords).await?; CustomEmojiKeyword::create(context.conn().await?, keywords).await?;
let view = CustomEmojiView::get(&mut *context.conn().await?, emoji.id).await?; let view = CustomEmojiView::get(context.conn().await?, emoji.id).await?;
Ok(CustomEmojiResponse { custom_emoji: view }) Ok(CustomEmojiResponse { custom_emoji: view })
} }
} }

View File

@ -22,7 +22,7 @@ impl PerformCrud for DeleteCustomEmoji {
// Make sure user is an admin // Make sure user is an admin
is_admin(&local_user_view)?; is_admin(&local_user_view)?;
CustomEmoji::delete(&mut *context.conn().await?, data.id).await?; CustomEmoji::delete(context.conn().await?, data.id).await?;
Ok(DeleteCustomEmojiResponse { Ok(DeleteCustomEmojiResponse {
id: data.id, id: data.id,
success: true, success: true,

View File

@ -22,7 +22,7 @@ impl PerformCrud for EditCustomEmoji {
let data: &EditCustomEmoji = self; let data: &EditCustomEmoji = 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 *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
// Make sure user is an admin // Make sure user is an admin
is_admin(&local_user_view)?; is_admin(&local_user_view)?;
@ -32,8 +32,8 @@ impl PerformCrud for EditCustomEmoji {
.category(data.category.to_string()) .category(data.category.to_string())
.image_url(data.clone().image_url.into()) .image_url(data.clone().image_url.into())
.build(); .build();
let emoji = CustomEmoji::update(&mut *context.conn().await?, data.id, &emoji_form).await?; let emoji = CustomEmoji::update(context.conn().await?, data.id, &emoji_form).await?;
CustomEmojiKeyword::delete(&mut *context.conn().await?, data.id).await?; CustomEmojiKeyword::delete(context.conn().await?, data.id).await?;
let mut keywords = vec![]; let mut keywords = vec![];
for keyword in &data.keywords { for keyword in &data.keywords {
let keyword_form = CustomEmojiKeywordInsertForm::builder() let keyword_form = CustomEmojiKeywordInsertForm::builder()
@ -42,8 +42,8 @@ impl PerformCrud for EditCustomEmoji {
.build(); .build();
keywords.push(keyword_form); keywords.push(keyword_form);
} }
CustomEmojiKeyword::create(&mut *context.conn().await?, keywords).await?; CustomEmojiKeyword::create(context.conn().await?, keywords).await?;
let view = CustomEmojiView::get(&mut *context.conn().await?, emoji.id).await?; let view = CustomEmojiView::get(context.conn().await?, emoji.id).await?;
Ok(CustomEmojiResponse { custom_emoji: view }) Ok(CustomEmojiResponse { custom_emoji: view })
} }
} }

View File

@ -46,7 +46,7 @@ impl PerformCrud for CreatePost {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
let data: &CreatePost = self; let data: &CreatePost = 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 *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
let slur_regex = local_site_to_slur_regex(&local_site); let slur_regex = local_site_to_slur_regex(&local_site);
check_slurs(&data.name, &slur_regex)?; check_slurs(&data.name, &slur_regex)?;
@ -68,7 +68,7 @@ impl PerformCrud for CreatePost {
check_community_deleted_or_removed(data.community_id, &mut *context.conn().await?).await?; check_community_deleted_or_removed(data.community_id, &mut *context.conn().await?).await?;
let community_id = data.community_id; let community_id = data.community_id;
let community = Community::read(&mut *context.conn().await?, community_id).await?; let community = Community::read(context.conn().await?, community_id).await?;
if community.posting_restricted_to_mods { if community.posting_restricted_to_mods {
let community_id = data.community_id; let community_id = data.community_id;
let is_mod = CommunityView::is_mod_or_admin( let is_mod = CommunityView::is_mod_or_admin(
@ -121,7 +121,7 @@ impl PerformCrud for CreatePost {
.thumbnail_url(thumbnail_url) .thumbnail_url(thumbnail_url)
.build(); .build();
let inserted_post = match Post::create(&mut *context.conn().await?, &post_form).await { let inserted_post = match Post::create(context.conn().await?, &post_form).await {
Ok(post) => post, Ok(post) => post,
Err(e) => { Err(e) => {
let err_type = if e.to_string() == "value too long for type character varying(200)" { let err_type = if e.to_string() == "value too long for type character varying(200)" {
@ -158,7 +158,7 @@ impl PerformCrud for CreatePost {
score: 1, score: 1,
}; };
PostLike::like(&mut *context.conn().await?, &like_form) PostLike::like(context.conn().await?, &like_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_post"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_like_post"))?;

View File

@ -22,7 +22,7 @@ impl PerformCrud for DeletePost {
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 post_id = data.post_id; let post_id = data.post_id;
let orig_post = Post::read(&mut *context.conn().await?, post_id).await?; let orig_post = Post::read(context.conn().await?, post_id).await?;
// Dont delete it if its already been deleted. // Dont delete it if its already been deleted.
if orig_post.deleted == data.deleted { if orig_post.deleted == data.deleted {

View File

@ -27,7 +27,7 @@ impl PerformCrud for GetPost {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetPostResponse, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetPostResponse, LemmyError> {
let data: &GetPost = self; let data: &GetPost = self;
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await; let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
let local_site = LocalSite::read(&mut *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
check_private_instance(&local_user_view, &local_site)?; check_private_instance(&local_user_view, &local_site)?;
@ -37,7 +37,7 @@ impl PerformCrud for GetPost {
let post_id = if let Some(id) = data.id { let post_id = if let Some(id) = data.id {
id id
} else if let Some(comment_id) = data.comment_id { } else if let Some(comment_id) = data.comment_id {
Comment::read(&mut *context.conn().await?, comment_id) Comment::read(context.conn().await?, comment_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"))?
.post_id .post_id
@ -46,7 +46,7 @@ impl PerformCrud for GetPost {
}; };
// Check to see if the person is a mod or admin, to show deleted / removed // Check to see if the person is a mod or admin, to show deleted / removed
let community_id = Post::read(&mut *context.conn().await?, post_id) let community_id = Post::read(context.conn().await?, post_id)
.await? .await?
.community_id; .community_id;
let is_mod_or_admin = is_mod_or_admin_opt( let is_mod_or_admin = is_mod_or_admin_opt(
@ -92,18 +92,18 @@ impl PerformCrud for GetPost {
read_comments, read_comments,
..PersonPostAggregatesForm::default() ..PersonPostAggregatesForm::default()
}; };
PersonPostAggregates::upsert(&mut *context.conn().await?, &person_post_agg_form) PersonPostAggregates::upsert(context.conn().await?, &person_post_agg_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))?;
} }
let moderators = let moderators =
CommunityModeratorView::for_community(&mut *context.conn().await?, community_id).await?; CommunityModeratorView::for_community(context.conn().await?, community_id).await?;
// Fetch the cross_posts // Fetch the cross_posts
let cross_posts = if let Some(url) = &post_view.post.url { let cross_posts = if let Some(url) = &post_view.post.url {
let mut x_posts = PostQuery::builder() let mut x_posts = PostQuery::builder()
.conn(&mut *context.conn().await?) .conn(context.conn().await?)
.url_search(Some(url.inner().as_str().into())) .url_search(Some(url.inner().as_str().into()))
.build() .build()
.list() .list()

View File

@ -25,7 +25,7 @@ impl PerformCrud for RemovePost {
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 post_id = data.post_id; let post_id = data.post_id;
let orig_post = Post::read(&mut *context.conn().await?, post_id).await?; let orig_post = Post::read(context.conn().await?, post_id).await?;
check_community_ban( check_community_ban(
local_user_view.person.id, local_user_view.person.id,
@ -59,7 +59,7 @@ impl PerformCrud for RemovePost {
removed: Some(removed), removed: Some(removed),
reason: data.reason.clone(), reason: data.reason.clone(),
}; };
ModRemovePost::create(&mut *context.conn().await?, &form).await?; ModRemovePost::create(context.conn().await?, &form).await?;
build_post_response( build_post_response(
context, context,

View File

@ -32,7 +32,7 @@ impl PerformCrud for EditPost {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
let data: &EditPost = self; let data: &EditPost = 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 *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
let data_url = data.url.as_ref(); let data_url = data.url.as_ref();
@ -52,7 +52,7 @@ impl PerformCrud for EditPost {
is_valid_body_field(&data.body, true)?; is_valid_body_field(&data.body, true)?;
let post_id = data.post_id; let post_id = data.post_id;
let orig_post = Post::read(&mut *context.conn().await?, post_id).await?; let orig_post = Post::read(context.conn().await?, post_id).await?;
check_community_ban( check_community_ban(
local_user_view.person.id, local_user_view.person.id,
@ -96,7 +96,7 @@ impl PerformCrud for EditPost {
.build(); .build();
let post_id = data.post_id; let post_id = data.post_id;
let res = Post::update(&mut *context.conn().await?, post_id, &post_form).await; let res = Post::update(context.conn().await?, post_id, &post_form).await;
if let Err(e) = res { if let Err(e) = res {
let err_type = if e.to_string() == "value too long for type character varying(200)" { let err_type = if e.to_string() == "value too long for type character varying(200)" {
"post_title_too_long" "post_title_too_long"

View File

@ -37,7 +37,7 @@ impl PerformCrud for CreatePrivateMessage {
) -> Result<PrivateMessageResponse, LemmyError> { ) -> Result<PrivateMessageResponse, LemmyError> {
let data: &CreatePrivateMessage = self; let data: &CreatePrivateMessage = 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 *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
let content_slurs_removed = remove_slurs( let content_slurs_removed = remove_slurs(
&data.content.clone(), &data.content.clone(),
@ -59,7 +59,7 @@ impl PerformCrud for CreatePrivateMessage {
.build(); .build();
let inserted_private_message = let inserted_private_message =
match PrivateMessage::create(&mut *context.conn().await?, &private_message_form).await { match PrivateMessage::create(context.conn().await?, &private_message_form).await {
Ok(private_message) => private_message, Ok(private_message) => private_message,
Err(e) => { Err(e) => {
return Err(LemmyError::from_error_message( return Err(LemmyError::from_error_message(
@ -86,14 +86,12 @@ impl PerformCrud for CreatePrivateMessage {
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_private_message"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_create_private_message"))?;
let view = let view = PrivateMessageView::read(context.conn().await?, inserted_private_message.id).await?;
PrivateMessageView::read(&mut *context.conn().await?, inserted_private_message.id).await?;
// Send email to the local recipient, if one exists // Send email to the local recipient, if one exists
if view.recipient.local { if view.recipient.local {
let recipient_id = data.recipient_id; let recipient_id = data.recipient_id;
let local_recipient = let local_recipient = LocalUserView::read_person(context.conn().await?, recipient_id).await?;
LocalUserView::read_person(&mut *context.conn().await?, recipient_id).await?;
let lang = get_interface_language(&local_recipient); let lang = get_interface_language(&local_recipient);
let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname()); let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname());
let sender_name = &local_user_view.person.name; let sender_name = &local_user_view.person.name;

View File

@ -27,7 +27,7 @@ impl PerformCrud for DeletePrivateMessage {
// Checking permissions // Checking permissions
let private_message_id = data.private_message_id; let private_message_id = data.private_message_id;
let orig_private_message = let orig_private_message =
PrivateMessage::read(&mut *context.conn().await?, private_message_id).await?; PrivateMessage::read(context.conn().await?, private_message_id).await?;
if local_user_view.person.id != orig_private_message.creator_id { if local_user_view.person.id != orig_private_message.creator_id {
return Err(LemmyError::from_message("no_private_message_edit_allowed")); return Err(LemmyError::from_message("no_private_message_edit_allowed"));
} }
@ -45,7 +45,7 @@ impl PerformCrud for DeletePrivateMessage {
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
let view = PrivateMessageView::read(&mut *context.conn().await?, private_message_id).await?; let view = PrivateMessageView::read(context.conn().await?, private_message_id).await?;
Ok(PrivateMessageResponse { Ok(PrivateMessageResponse {
private_message_view: view, private_message_view: view,
}) })

View File

@ -25,7 +25,7 @@ impl PerformCrud for GetPrivateMessages {
let limit = data.limit; let limit = data.limit;
let unread_only = data.unread_only; let unread_only = data.unread_only;
let mut messages = PrivateMessageQuery::builder() let mut messages = PrivateMessageQuery::builder()
.conn(&mut *context.conn().await?) .conn(context.conn().await?)
.recipient_id(person_id) .recipient_id(person_id)
.page(page) .page(page)
.limit(limit) .limit(limit)

View File

@ -30,12 +30,12 @@ impl PerformCrud for EditPrivateMessage {
) -> Result<PrivateMessageResponse, LemmyError> { ) -> Result<PrivateMessageResponse, LemmyError> {
let data: &EditPrivateMessage = self; let data: &EditPrivateMessage = 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 *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
// Checking permissions // Checking permissions
let private_message_id = data.private_message_id; let private_message_id = data.private_message_id;
let orig_private_message = let orig_private_message =
PrivateMessage::read(&mut *context.conn().await?, private_message_id).await?; PrivateMessage::read(context.conn().await?, private_message_id).await?;
if local_user_view.person.id != orig_private_message.creator_id { if local_user_view.person.id != orig_private_message.creator_id {
return Err(LemmyError::from_message("no_private_message_edit_allowed")); return Err(LemmyError::from_message("no_private_message_edit_allowed"));
} }
@ -56,7 +56,7 @@ impl PerformCrud for EditPrivateMessage {
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
let view = PrivateMessageView::read(&mut *context.conn().await?, private_message_id).await?; let view = PrivateMessageView::read(context.conn().await?, private_message_id).await?;
Ok(PrivateMessageResponse { Ok(PrivateMessageResponse {
private_message_view: view, private_message_view: view,

View File

@ -50,7 +50,7 @@ impl PerformCrud for CreateSite {
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 *context.conn().await?).await?; let local_site = LocalSite::read(context.conn().await?).await?;
// Make sure user is an admin; other types of users should not create site data... // Make sure user is an admin; other types of users should not create site data...
is_admin(&local_user_view)?; is_admin(&local_user_view)?;
@ -75,7 +75,7 @@ impl PerformCrud for CreateSite {
let site_id = local_site.site_id; let site_id = local_site.site_id;
Site::update(&mut *context.conn().await?, site_id, &site_form).await?; Site::update(context.conn().await?, site_id, &site_form).await?;
let local_site_form = LocalSiteUpdateForm::builder() let local_site_form = LocalSiteUpdateForm::builder()
// Set the site setup to true // Set the site setup to true
@ -100,7 +100,7 @@ impl PerformCrud for CreateSite {
.captcha_difficulty(data.captcha_difficulty.clone()) .captcha_difficulty(data.captcha_difficulty.clone())
.build(); .build();
LocalSite::update(&mut *context.conn().await?, &local_site_form).await?; LocalSite::update(context.conn().await?, &local_site_form).await?;
let local_site_rate_limit_form = LocalSiteRateLimitUpdateForm::builder() let local_site_rate_limit_form = LocalSiteRateLimitUpdateForm::builder()
.message(data.rate_limit_message) .message(data.rate_limit_message)
@ -117,13 +117,12 @@ impl PerformCrud for CreateSite {
.search_per_second(data.rate_limit_search_per_second) .search_per_second(data.rate_limit_search_per_second)
.build(); .build();
LocalSiteRateLimit::update(&mut *context.conn().await?, &local_site_rate_limit_form).await?; LocalSiteRateLimit::update(context.conn().await?, &local_site_rate_limit_form).await?;
let site_view = SiteView::read_local(&mut *context.conn().await?).await?; let site_view = SiteView::read_local(context.conn().await?).await?;
let new_taglines = data.taglines.clone(); let new_taglines = data.taglines.clone();
let taglines = let taglines = Tagline::replace(context.conn().await?, local_site.id, new_taglines).await?;
Tagline::replace(&mut *context.conn().await?, local_site.id, new_taglines).await?;
let rate_limit_config = let rate_limit_config =
local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit); local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);

View File

@ -32,9 +32,9 @@ impl PerformCrud for GetSite {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetSiteResponse, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetSiteResponse, LemmyError> {
let data: &GetSite = self; let data: &GetSite = self;
let site_view = SiteView::read_local(&mut *context.conn().await?).await?; let site_view = SiteView::read_local(context.conn().await?).await?;
let admins = PersonView::admins(&mut *context.conn().await?).await?; let admins = PersonView::admins(context.conn().await?).await?;
// Build the local user // Build the local user
let my_user = if let Some(local_user_view) = let my_user = if let Some(local_user_view) =
@ -43,28 +43,27 @@ impl PerformCrud for GetSite {
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let local_user_id = local_user_view.local_user.id; let local_user_id = local_user_view.local_user.id;
let follows = CommunityFollowerView::for_person(&mut *context.conn().await?, person_id) let follows = CommunityFollowerView::for_person(context.conn().await?, person_id)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?; .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let community_blocks = CommunityBlockView::for_person(&mut *context.conn().await?, person_id) let community_blocks = CommunityBlockView::for_person(context.conn().await?, person_id)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?; .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let person_blocks = PersonBlockView::for_person(&mut *context.conn().await?, person_id) let person_blocks = PersonBlockView::for_person(context.conn().await?, person_id)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?; .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
let moderates = CommunityModeratorView::for_person(&mut *context.conn().await?, person_id) let moderates = CommunityModeratorView::for_person(context.conn().await?, person_id)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?; .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
let discussion_languages = let discussion_languages = LocalUserLanguage::read(context.conn().await?, local_user_id)
LocalUserLanguage::read(&mut *context.conn().await?, local_user_id) .await
.await .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
Some(MyUserInfo { Some(MyUserInfo {
local_user_view, local_user_view,
@ -78,11 +77,11 @@ impl PerformCrud for GetSite {
None None
}; };
let all_languages = Language::read_all(&mut *context.conn().await?).await?; let all_languages = Language::read_all(context.conn().await?).await?;
let discussion_languages = SiteLanguage::read_local_raw(&mut *context.conn().await?).await?; let discussion_languages = SiteLanguage::read_local_raw(context.conn().await?).await?;
let taglines = Tagline::get_all(&mut *context.conn().await?, site_view.local_site.id).await?; let taglines = Tagline::get_all(context.conn().await?, site_view.local_site.id).await?;
let custom_emojis = let custom_emojis =
CustomEmojiView::get_all(&mut *context.conn().await?, site_view.local_site.id).await?; CustomEmojiView::get_all(context.conn().await?, site_view.local_site.id).await?;
Ok(GetSiteResponse { Ok(GetSiteResponse {
site_view, site_view,
@ -108,7 +107,7 @@ async fn local_user_settings_view_from_jwt_opt(
.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(context.conn().await.ok()?, local_user_id)
.await .await
.ok()?; .ok()?;
check_user_valid( check_user_valid(

View File

@ -46,7 +46,7 @@ impl PerformCrud for EditSite {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<SiteResponse, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<SiteResponse, LemmyError> {
let data: &EditSite = self; let data: &EditSite = 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 site_view = SiteView::read_local(&mut *context.conn().await?).await?; let site_view = SiteView::read_local(context.conn().await?).await?;
let local_site = site_view.local_site; let local_site = site_view.local_site;
let site = site_view.site; let site = site_view.site;
@ -73,7 +73,7 @@ impl PerformCrud for EditSite {
.updated(Some(Some(naive_now()))) .updated(Some(Some(naive_now())))
.build(); .build();
Site::update(&mut *context.conn().await?, site.id, &site_form) Site::update(context.conn().await?, site.id, &site_form)
.await .await
// Ignore errors for all these, so as to not throw errors if no update occurs // Ignore errors for all these, so as to not throw errors if no update occurs
// Diesel will throw an error for empty update forms // Diesel will throw an error for empty update forms
@ -101,7 +101,7 @@ impl PerformCrud for EditSite {
.reports_email_admins(data.reports_email_admins) .reports_email_admins(data.reports_email_admins)
.build(); .build();
let update_local_site = LocalSite::update(&mut *context.conn().await?, &local_site_form) let update_local_site = LocalSite::update(context.conn().await?, &local_site_form)
.await .await
.ok(); .ok();
@ -120,15 +120,15 @@ impl PerformCrud for EditSite {
.search_per_second(data.rate_limit_search_per_second) .search_per_second(data.rate_limit_search_per_second)
.build(); .build();
LocalSiteRateLimit::update(&mut *context.conn().await?, &local_site_rate_limit_form) LocalSiteRateLimit::update(context.conn().await?, &local_site_rate_limit_form)
.await .await
.ok(); .ok();
// Replace the blocked and allowed instances // Replace the blocked and allowed instances
let allowed = data.allowed_instances.clone(); let allowed = data.allowed_instances.clone();
FederationAllowList::replace(&mut *context.conn().await?, allowed).await?; FederationAllowList::replace(context.conn().await?, allowed).await?;
let blocked = data.blocked_instances.clone(); let blocked = data.blocked_instances.clone();
FederationBlockList::replace(&mut *context.conn().await?, blocked).await?; FederationBlockList::replace(context.conn().await?, blocked).await?;
// TODO can't think of a better way to do this. // TODO can't think of a better way to do this.
// If the server suddenly requires email verification, or required applications, no old users // If the server suddenly requires email verification, or required applications, no old users
@ -142,7 +142,7 @@ impl PerformCrud for EditSite {
.map(|ols| ols.registration_mode == RegistrationMode::RequireApplication) .map(|ols| ols.registration_mode == RegistrationMode::RequireApplication)
.unwrap_or(false); .unwrap_or(false);
if !old_require_application && new_require_application { if !old_require_application && new_require_application {
LocalUser::set_all_users_registration_applications_accepted(&mut *context.conn().await?) LocalUser::set_all_users_registration_applications_accepted(context.conn().await?)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_set_all_registrations_accepted"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_set_all_registrations_accepted"))?;
} }
@ -152,16 +152,15 @@ impl PerformCrud for EditSite {
.map(|ols| ols.require_email_verification) .map(|ols| ols.require_email_verification)
.unwrap_or(false); .unwrap_or(false);
if !local_site.require_email_verification && new_require_email_verification { if !local_site.require_email_verification && new_require_email_verification {
LocalUser::set_all_users_email_verified(&mut *context.conn().await?) LocalUser::set_all_users_email_verified(context.conn().await?)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_set_all_email_verified"))?; .map_err(|e| LemmyError::from_error_message(e, "couldnt_set_all_email_verified"))?;
} }
let new_taglines = data.taglines.clone(); let new_taglines = data.taglines.clone();
let taglines = let taglines = Tagline::replace(context.conn().await?, local_site.id, new_taglines).await?;
Tagline::replace(&mut *context.conn().await?, local_site.id, new_taglines).await?;
let site_view = SiteView::read_local(&mut *context.conn().await?).await?; let site_view = SiteView::read_local(context.conn().await?).await?;
let rate_limit_config = let rate_limit_config =
local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit); local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);

View File

@ -45,7 +45,7 @@ impl PerformCrud for Register {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> { async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
let data: &Register = self; let data: &Register = self;
let site_view = SiteView::read_local(&mut *context.conn().await?).await?; let site_view = SiteView::read_local(context.conn().await?).await?;
let local_site = site_view.local_site; let local_site = site_view.local_site;
let require_registration_application = let require_registration_application =
local_site.registration_mode == RegistrationMode::RequireApplication; local_site.registration_mode == RegistrationMode::RequireApplication;
@ -104,7 +104,7 @@ impl PerformCrud for Register {
)?; )?;
if let Some(email) = &data.email { if let Some(email) = &data.email {
if LocalUser::is_email_taken(&mut *context.conn().await?, email).await? { if LocalUser::is_email_taken(context.conn().await?, email).await? {
return Err(LemmyError::from_message("email_already_exists")); return Err(LemmyError::from_message("email_already_exists"));
} }
} }
@ -125,7 +125,7 @@ impl PerformCrud for Register {
.build(); .build();
// insert the person // insert the person
let inserted_person = Person::create(&mut *context.conn().await?, &person_form) let inserted_person = Person::create(context.conn().await?, &person_form)
.await .await
.map_err(|e| LemmyError::from_error_message(e, "user_already_exists"))?; .map_err(|e| LemmyError::from_error_message(e, "user_already_exists"))?;
@ -142,8 +142,7 @@ impl PerformCrud for Register {
.accepted_application(accepted_application) .accepted_application(accepted_application)
.build(); .build();
let inserted_local_user = let inserted_local_user = LocalUser::create(context.conn().await?, &local_user_form).await?;
LocalUser::create(&mut *context.conn().await?, &local_user_form).await?;
if local_site.site_setup && require_registration_application { if local_site.site_setup && require_registration_application {
// Create the registration application // Create the registration application
@ -153,7 +152,7 @@ impl PerformCrud for Register {
answer: data.answer.clone().expect("must have an answer"), answer: data.answer.clone().expect("must have an answer"),
}; };
RegistrationApplication::create(&mut *context.conn().await?, &form).await?; RegistrationApplication::create(context.conn().await?, &form).await?;
} }
// Email the admins // Email the admins

View File

@ -97,7 +97,7 @@ impl BlockUser {
match target { match target {
SiteOrCommunity::Site(_) => { SiteOrCommunity::Site(_) => {
let inboxes = remote_instance_inboxes(&mut *context.conn().await?).await?; let inboxes = remote_instance_inboxes(context.conn().await?).await?;
send_lemmy_activity(context, block, mod_, inboxes, false).await send_lemmy_activity(context, block, mod_, inboxes, false).await
} }
SiteOrCommunity::Community(c) => { SiteOrCommunity::Community(c) => {
@ -181,7 +181,7 @@ impl ActivityHandler for BlockUser {
banned: Some(true), banned: Some(true),
expires, expires,
}; };
ModBan::create(&mut *context.conn().await?, &form).await?; ModBan::create(context.conn().await?, &form).await?;
} }
SiteOrCommunity::Community(community) => { SiteOrCommunity::Community(community) => {
let community_user_ban_form = CommunityPersonBanForm { let community_user_ban_form = CommunityPersonBanForm {
@ -189,7 +189,7 @@ impl ActivityHandler for BlockUser {
person_id: blocked_person.id, person_id: blocked_person.id,
expires: Some(expires), expires: Some(expires),
}; };
CommunityPersonBan::ban(&mut *context.conn().await?, &community_user_ban_form).await?; CommunityPersonBan::ban(context.conn().await?, &community_user_ban_form).await?;
// Also unsubscribe them from the community, if they are subscribed // Also unsubscribe them from the community, if they are subscribed
let community_follower_form = CommunityFollowerForm { let community_follower_form = CommunityFollowerForm {
@ -197,7 +197,7 @@ impl ActivityHandler for BlockUser {
person_id: blocked_person.id, person_id: blocked_person.id,
pending: false, pending: false,
}; };
CommunityFollower::unfollow(&mut *context.conn().await?, &community_follower_form) CommunityFollower::unfollow(context.conn().await?, &community_follower_form)
.await .await
.ok(); .ok();
@ -219,7 +219,7 @@ impl ActivityHandler for BlockUser {
banned: Some(true), banned: Some(true),
expires, expires,
}; };
ModBanFromCommunity::create(&mut *context.conn().await?, &form).await?; ModBanFromCommunity::create(context.conn().await?, &form).await?;
} }
} }

View File

@ -118,9 +118,12 @@ impl SiteOrCommunity {
} }
} }
async fn generate_cc(target: &SiteOrCommunity, conn: &mut DbConn) -> Result<Vec<Url>, LemmyError> { async fn generate_cc(
target: &SiteOrCommunity,
mut conn: impl DbConn,
) -> Result<Vec<Url>, LemmyError> {
Ok(match target { Ok(match target {
SiteOrCommunity::Site(_) => Site::read_remote_sites(conn) SiteOrCommunity::Site(_) => Site::read_remote_sites(&mut *conn)
.await? .await?
.into_iter() .into_iter()
.map(|s| s.actor_id.into()) .map(|s| s.actor_id.into())
@ -139,9 +142,9 @@ impl SendActivity for BanPerson {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
let person = Person::read(&mut *context.conn().await?, request.person_id).await?; let person = Person::read(context.conn().await?, request.person_id).await?;
let site = SiteOrCommunity::Site( let site = SiteOrCommunity::Site(
SiteView::read_local(&mut *context.conn().await?) SiteView::read_local(context.conn().await?)
.await? .await?
.site .site
.into(), .into(),
@ -187,11 +190,10 @@ impl SendActivity for BanFromCommunity {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
let community: ApubCommunity = let community: ApubCommunity = Community::read(context.conn().await?, request.community_id)
Community::read(&mut *context.conn().await?, request.community_id) .await?
.await? .into();
.into(); let banned_person: ApubPerson = Person::read(context.conn().await?, request.person_id)
let banned_person: ApubPerson = Person::read(&mut *context.conn().await?, request.person_id)
.await? .await?
.into(); .into();
let expires = request.expires.map(naive_from_unix); let expires = request.expires.map(naive_from_unix);

View File

@ -62,7 +62,7 @@ impl UndoBlockUser {
let mut inboxes = vec![user.shared_inbox_or_inbox()]; let mut inboxes = vec![user.shared_inbox_or_inbox()];
match target { match target {
SiteOrCommunity::Site(_) => { SiteOrCommunity::Site(_) => {
inboxes.append(&mut remote_instance_inboxes(&mut *context.conn().await?).await?); inboxes.append(&mut remote_instance_inboxes(context.conn().await?).await?);
send_lemmy_activity(context, undo, mod_, inboxes, false).await send_lemmy_activity(context, undo, mod_, inboxes, false).await
} }
SiteOrCommunity::Community(c) => { SiteOrCommunity::Community(c) => {
@ -120,7 +120,7 @@ impl ActivityHandler for UndoBlockUser {
banned: Some(false), banned: Some(false),
expires, expires,
}; };
ModBan::create(&mut *context.conn().await?, &form).await?; ModBan::create(context.conn().await?, &form).await?;
} }
SiteOrCommunity::Community(community) => { SiteOrCommunity::Community(community) => {
let community_user_ban_form = CommunityPersonBanForm { let community_user_ban_form = CommunityPersonBanForm {
@ -128,7 +128,7 @@ impl ActivityHandler for UndoBlockUser {
person_id: blocked_person.id, person_id: blocked_person.id,
expires: None, expires: None,
}; };
CommunityPersonBan::unban(&mut *context.conn().await?, &community_user_ban_form).await?; CommunityPersonBan::unban(context.conn().await?, &community_user_ban_form).await?;
// write to mod log // write to mod log
let form = ModBanFromCommunityForm { let form = ModBanFromCommunityForm {
@ -139,7 +139,7 @@ impl ActivityHandler for UndoBlockUser {
banned: Some(false), banned: Some(false),
expires, expires,
}; };
ModBanFromCommunity::create(&mut *context.conn().await?, &form).await?; ModBanFromCommunity::create(context.conn().await?, &form).await?;
} }
} }

View File

@ -119,7 +119,7 @@ impl ActivityHandler for CollectionAdd {
async fn receive(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> { async fn receive(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
insert_activity(&self.id, &self, false, false, context).await?; insert_activity(&self.id, &self, false, false, context).await?;
let (community, collection_type) = let (community, collection_type) =
Community::get_by_collection_url(&mut *context.conn().await?, &self.target.into()).await?; Community::get_by_collection_url(context.conn().await?, &self.target.into()).await?;
match collection_type { match collection_type {
CollectionType::Moderators => { CollectionType::Moderators => {
let new_mod = ObjectId::<ApubPerson>::from(self.object) let new_mod = ObjectId::<ApubPerson>::from(self.object)
@ -139,7 +139,7 @@ impl ActivityHandler for CollectionAdd {
community_id: community.id, community_id: community.id,
person_id: new_mod.id, person_id: new_mod.id,
}; };
CommunityModerator::join(&mut *context.conn().await?, &form).await?; CommunityModerator::join(context.conn().await?, &form).await?;
// write mod log // write mod log
let actor = self.actor.dereference(context).await?; let actor = self.actor.dereference(context).await?;
@ -149,7 +149,7 @@ impl ActivityHandler for CollectionAdd {
community_id: community.id, community_id: community.id,
removed: Some(false), removed: Some(false),
}; };
ModAddCommunity::create(&mut *context.conn().await?, &form).await?; ModAddCommunity::create(context.conn().await?, &form).await?;
} }
// TODO: send websocket notification about added mod // TODO: send websocket notification about added mod
} }
@ -160,7 +160,7 @@ impl ActivityHandler for CollectionAdd {
let form = PostUpdateForm::builder() let form = PostUpdateForm::builder()
.featured_community(Some(true)) .featured_community(Some(true))
.build(); .build();
Post::update(&mut *context.conn().await?, post.id, &form).await?; Post::update(context.conn().await?, post.id, &form).await?;
} }
} }
Ok(()) Ok(())
@ -177,11 +177,10 @@ impl SendActivity for AddModToCommunity {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
let community: ApubCommunity = let community: ApubCommunity = Community::read(context.conn().await?, request.community_id)
Community::read(&mut *context.conn().await?, request.community_id) .await?
.await? .into();
.into(); let updated_mod: ApubPerson = Person::read(context.conn().await?, request.person_id)
let updated_mod: ApubPerson = Person::read(&mut *context.conn().await?, request.person_id)
.await? .await?
.into(); .into();
if request.added { if request.added {
@ -214,7 +213,7 @@ impl SendActivity for FeaturePost {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
let community = Community::read(&mut *context.conn().await?, response.post_view.community.id) let community = Community::read(context.conn().await?, response.post_view.community.id)
.await? .await?
.into(); .into();
let post = response.post_view.post.clone().into(); let post = response.post_view.post.clone().into();

View File

@ -112,7 +112,7 @@ impl ActivityHandler for CollectionRemove {
async fn receive(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> { async fn receive(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
insert_activity(&self.id, &self, false, false, context).await?; insert_activity(&self.id, &self, false, false, context).await?;
let (community, collection_type) = let (community, collection_type) =
Community::get_by_collection_url(&mut *context.conn().await?, &self.target.into()).await?; Community::get_by_collection_url(context.conn().await?, &self.target.into()).await?;
match collection_type { match collection_type {
CollectionType::Moderators => { CollectionType::Moderators => {
let remove_mod = ObjectId::<ApubPerson>::from(self.object) let remove_mod = ObjectId::<ApubPerson>::from(self.object)
@ -123,7 +123,7 @@ impl ActivityHandler for CollectionRemove {
community_id: community.id, community_id: community.id,
person_id: remove_mod.id, person_id: remove_mod.id,
}; };
CommunityModerator::leave(&mut *context.conn().await?, &form).await?; CommunityModerator::leave(context.conn().await?, &form).await?;
// write mod log // write mod log
let actor = self.actor.dereference(context).await?; let actor = self.actor.dereference(context).await?;
@ -133,7 +133,7 @@ impl ActivityHandler for CollectionRemove {
community_id: community.id, community_id: community.id,
removed: Some(true), removed: Some(true),
}; };
ModAddCommunity::create(&mut *context.conn().await?, &form).await?; ModAddCommunity::create(context.conn().await?, &form).await?;
// TODO: send websocket notification about removed mod // TODO: send websocket notification about removed mod
} }
@ -144,7 +144,7 @@ impl ActivityHandler for CollectionRemove {
let form = PostUpdateForm::builder() let form = PostUpdateForm::builder()
.featured_community(Some(false)) .featured_community(Some(false))
.build(); .build();
Post::update(&mut *context.conn().await?, post.id, &form).await?; Post::update(context.conn().await?, post.id, &form).await?;
} }
} }
Ok(()) Ok(())

View File

@ -60,7 +60,7 @@ impl ActivityHandler for LockPage {
async fn receive(self, context: &Data<Self::DataType>) -> Result<(), Self::Error> { async fn receive(self, context: &Data<Self::DataType>) -> Result<(), Self::Error> {
let form = PostUpdateForm::builder().locked(Some(true)).build(); let form = PostUpdateForm::builder().locked(Some(true)).build();
let post = self.object.dereference(context).await?; let post = self.object.dereference(context).await?;
Post::update(&mut *context.conn().await?, post.id, &form).await?; Post::update(context.conn().await?, post.id, &form).await?;
Ok(()) Ok(())
} }
} }
@ -97,7 +97,7 @@ impl ActivityHandler for UndoLockPage {
insert_activity(&self.id, &self, false, false, context).await?; insert_activity(&self.id, &self, false, false, context).await?;
let form = PostUpdateForm::builder().locked(Some(false)).build(); let form = PostUpdateForm::builder().locked(Some(false)).build();
let post = self.object.object.dereference(context).await?; let post = self.object.object.dereference(context).await?;
Post::update(&mut *context.conn().await?, post.id, &form).await?; Post::update(context.conn().await?, post.id, &form).await?;
Ok(()) Ok(())
} }
} }
@ -145,8 +145,7 @@ impl SendActivity for LockPost {
}; };
AnnouncableActivities::UndoLockPost(undo) AnnouncableActivities::UndoLockPost(undo)
}; };
let community = let community = Community::read(context.conn().await?, response.post_view.community.id).await?;
Community::read(&mut *context.conn().await?, response.post_view.community.id).await?;
send_activity_in_community( send_activity_in_community(
activity, activity,
&local_user_view.person.into(), &local_user_view.person.into(),

View File

@ -44,7 +44,7 @@ pub(crate) async fn send_activity_in_community(
// send to user followers // send to user followers
if !is_mod_action { if !is_mod_action {
inboxes.extend( inboxes.extend(
&mut PersonFollower::list_followers(&mut *context.conn().await?, actor.id) &mut PersonFollower::list_followers(context.conn().await?, actor.id)
.await? .await?
.into_iter() .into_iter()
.map(|p| ApubPerson(p).shared_inbox_or_inbox()), .map(|p| ApubPerson(p).shared_inbox_or_inbox()),

View File

@ -134,7 +134,7 @@ impl ActivityHandler for Report {
reason: self.summary, reason: self.summary,
original_post_body: post.body.clone(), original_post_body: post.body.clone(),
}; };
PostReport::report(&mut *context.conn().await?, &report_form).await?; PostReport::report(context.conn().await?, &report_form).await?;
} }
PostOrComment::Comment(comment) => { PostOrComment::Comment(comment) => {
let report_form = CommentReportForm { let report_form = CommentReportForm {
@ -143,7 +143,7 @@ impl ActivityHandler for Report {
original_comment_text: comment.content.clone(), original_comment_text: comment.content.clone(),
reason: self.summary, reason: self.summary,
}; };
CommentReport::report(&mut *context.conn().await?, &report_form).await?; CommentReport::report(context.conn().await?, &report_form).await?;
} }
}; };
Ok(()) Ok(())

View File

@ -36,7 +36,7 @@ impl SendActivity for EditCommunity {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
let community = Community::read(&mut *context.conn().await?, request.community_id).await?; let community = Community::read(context.conn().await?, request.community_id).await?;
UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
} }
} }
@ -117,7 +117,7 @@ impl SendActivity for HideCommunity {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
let community = Community::read(&mut *context.conn().await?, request.community_id).await?; let community = Community::read(context.conn().await?, request.community_id).await?;
UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
} }
} }

View File

@ -91,12 +91,10 @@ impl CreateOrUpdateNote {
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
// 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 *context.conn().await?, post_id).await?; let post = Post::read(context.conn().await?, post_id).await?;
let community_id = post.community_id; let community_id = post.community_id;
let person: ApubPerson = Person::read(&mut *context.conn().await?, person_id) let person: ApubPerson = Person::read(context.conn().await?, person_id).await?.into();
.await? let community: ApubCommunity = Community::read(context.conn().await?, community_id)
.into();
let community: ApubCommunity = Community::read(&mut *context.conn().await?, community_id)
.await? .await?
.into(); .into();
@ -181,7 +179,7 @@ impl ActivityHandler for CreateOrUpdateNote {
if distinguished != existing_comment.distinguished { if distinguished != existing_comment.distinguished {
let creator = self.actor.dereference(context).await?; let creator = self.actor.dereference(context).await?;
let (post, _) = self.object.get_parents(context).await?; let (post, _) = self.object.get_parents(context).await?;
is_mod_or_admin(&mut *context.conn().await?, creator.id, post.community_id).await?; is_mod_or_admin(context.conn().await?, creator.id, post.community_id).await?;
} }
} }
@ -194,14 +192,14 @@ impl ActivityHandler for CreateOrUpdateNote {
person_id: comment.creator_id, person_id: comment.creator_id,
score: 1, score: 1,
}; };
CommentLike::like(&mut *context.conn().await?, &like_form).await?; CommentLike::like(context.conn().await?, &like_form).await?;
// Calculate initial hot_rank // Calculate initial hot_rank
CommentAggregates::update_hot_rank(&mut *context.conn().await?, comment.id).await?; CommentAggregates::update_hot_rank(context.conn().await?, comment.id).await?;
let do_send_email = self.kind == CreateOrUpdateType::Create; let do_send_email = self.kind == CreateOrUpdateType::Create;
let post_id = comment.post_id; let post_id = comment.post_id;
let post = Post::read(&mut *context.conn().await?, post_id).await?; let post = Post::read(context.conn().await?, post_id).await?;
let actor = self.actor.dereference(context).await?; let actor = self.actor.dereference(context).await?;
// Note: // Note:

View File

@ -109,10 +109,8 @@ impl CreateOrUpdatePage {
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let post = ApubPost(post.clone()); let post = ApubPost(post.clone());
let community_id = post.community_id; let community_id = post.community_id;
let person: ApubPerson = Person::read(&mut *context.conn().await?, person_id) let person: ApubPerson = Person::read(context.conn().await?, person_id).await?.into();
.await? let community: ApubCommunity = Community::read(context.conn().await?, community_id)
.into();
let community: ApubCommunity = Community::read(&mut *context.conn().await?, community_id)
.await? .await?
.into(); .into();
@ -191,10 +189,10 @@ impl ActivityHandler for CreateOrUpdatePage {
person_id: post.creator_id, person_id: post.creator_id,
score: 1, score: 1,
}; };
PostLike::like(&mut *context.conn().await?, &like_form).await?; PostLike::like(context.conn().await?, &like_form).await?;
// Calculate initial hot_rank for post // Calculate initial hot_rank for post
PostAggregates::update_hot_rank(&mut *context.conn().await?, post.id).await?; PostAggregates::update_hot_rank(context.conn().await?, post.id).await?;
Ok(()) Ok(())
} }

View File

@ -71,10 +71,8 @@ impl CreateOrUpdateChatMessage {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let recipient_id = private_message.recipient_id; let recipient_id = private_message.recipient_id;
let sender: ApubPerson = Person::read(&mut *context.conn().await?, sender_id) let sender: ApubPerson = Person::read(context.conn().await?, sender_id).await?.into();
.await? let recipient: ApubPerson = Person::read(context.conn().await?, recipient_id)
.into();
let recipient: ApubPerson = Person::read(&mut *context.conn().await?, recipient_id)
.await? .await?
.into(); .into();

View File

@ -119,7 +119,7 @@ pub(in crate::activities) async fn receive_remove_action(
reason, reason,
expires: None, expires: None,
}; };
ModRemoveCommunity::create(&mut *context.conn().await?, &form).await?; ModRemoveCommunity::create(context.conn().await?, &form).await?;
Community::update( Community::update(
&mut *context.conn().await?, &mut *context.conn().await?,
community.id, community.id,
@ -134,7 +134,7 @@ pub(in crate::activities) async fn receive_remove_action(
removed: Some(true), removed: Some(true),
reason, reason,
}; };
ModRemovePost::create(&mut *context.conn().await?, &form).await?; ModRemovePost::create(context.conn().await?, &form).await?;
Post::update( Post::update(
&mut *context.conn().await?, &mut *context.conn().await?,
post.id, post.id,
@ -149,7 +149,7 @@ pub(in crate::activities) async fn receive_remove_action(
removed: Some(true), removed: Some(true),
reason, reason,
}; };
ModRemoveComment::create(&mut *context.conn().await?, &form).await?; ModRemoveComment::create(context.conn().await?, &form).await?;
Comment::update( Comment::update(
&mut *context.conn().await?, &mut *context.conn().await?,
comment.id, comment.id,

View File

@ -51,7 +51,7 @@ impl SendActivity for DeleteAccount {
cc: vec![], cc: vec![],
}; };
let inboxes = remote_instance_inboxes(&mut *context.conn().await?).await?; let inboxes = remote_instance_inboxes(context.conn().await?).await?;
send_lemmy_activity(context, delete, &actor, inboxes, true).await?; send_lemmy_activity(context, delete, &actor, inboxes, true).await?;
Ok(()) Ok(())
} }

View File

@ -64,8 +64,7 @@ impl SendActivity for DeletePost {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
let community = let community = Community::read(context.conn().await?, response.post_view.community.id).await?;
Community::read(&mut *context.conn().await?, response.post_view.community.id).await?;
let deletable = DeletableObjects::Post(response.post_view.post.clone().into()); let deletable = DeletableObjects::Post(response.post_view.post.clone().into());
send_apub_delete_in_community( send_apub_delete_in_community(
local_user_view.person, local_user_view.person,
@ -89,8 +88,7 @@ impl SendActivity for RemovePost {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
let community = let community = Community::read(context.conn().await?, response.post_view.community.id).await?;
Community::read(&mut *context.conn().await?, response.post_view.community.id).await?;
let deletable = DeletableObjects::Post(response.post_view.post.clone().into()); let deletable = DeletableObjects::Post(response.post_view.post.clone().into());
send_apub_delete_in_community( send_apub_delete_in_community(
local_user_view.person, local_user_view.person,
@ -114,7 +112,7 @@ impl SendActivity for DeleteComment {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let community_id = response.comment_view.community.id; let community_id = response.comment_view.community.id;
let community = Community::read(&mut *context.conn().await?, community_id).await?; let community = Community::read(context.conn().await?, community_id).await?;
let person = Person::read( let person = Person::read(
&mut *context.conn().await?, &mut *context.conn().await?,
response.comment_view.creator.id, response.comment_view.creator.id,
@ -136,7 +134,7 @@ impl SendActivity for RemoveComment {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
let comment = Comment::read(&mut *context.conn().await?, request.comment_id).await?; let comment = Comment::read(context.conn().await?, request.comment_id).await?;
let community = Community::read( let community = Community::read(
&mut *context.conn().await?, &mut *context.conn().await?,
response.comment_view.community.id, response.comment_view.community.id,
@ -185,7 +183,7 @@ impl SendActivity for DeleteCommunity {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
let community = Community::read(&mut *context.conn().await?, request.community_id).await?; let community = Community::read(context.conn().await?, request.community_id).await?;
let deletable = DeletableObjects::Community(community.clone().into()); let deletable = DeletableObjects::Community(community.clone().into());
send_apub_delete_in_community( send_apub_delete_in_community(
local_user_view.person, local_user_view.person,
@ -209,7 +207,7 @@ impl SendActivity for RemoveCommunity {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
let community = Community::read(&mut *context.conn().await?, request.community_id).await?; let community = Community::read(context.conn().await?, request.community_id).await?;
let deletable = DeletableObjects::Community(community.clone().into()); let deletable = DeletableObjects::Community(community.clone().into());
send_apub_delete_in_community( send_apub_delete_in_community(
local_user_view.person, local_user_view.person,
@ -262,7 +260,7 @@ async fn send_apub_delete_private_message(
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let recipient_id = pm.recipient_id; let recipient_id = pm.recipient_id;
let recipient: ApubPerson = Person::read(&mut *context.conn().await?, recipient_id) let recipient: ApubPerson = Person::read(context.conn().await?, recipient_id)
.await? .await?
.into(); .into();

View File

@ -111,7 +111,7 @@ impl UndoDelete {
reason: None, reason: None,
expires: None, expires: None,
}; };
ModRemoveCommunity::create(&mut *context.conn().await?, &form).await?; ModRemoveCommunity::create(context.conn().await?, &form).await?;
Community::update( Community::update(
&mut *context.conn().await?, &mut *context.conn().await?,
community.id, community.id,
@ -126,7 +126,7 @@ impl UndoDelete {
removed: Some(false), removed: Some(false),
reason: None, reason: None,
}; };
ModRemovePost::create(&mut *context.conn().await?, &form).await?; ModRemovePost::create(context.conn().await?, &form).await?;
Post::update( Post::update(
&mut *context.conn().await?, &mut *context.conn().await?,
post.id, post.id,
@ -141,7 +141,7 @@ impl UndoDelete {
removed: Some(false), removed: Some(false),
reason: None, reason: None,
}; };
ModRemoveComment::create(&mut *context.conn().await?, &form).await?; ModRemoveComment::create(context.conn().await?, &form).await?;
Comment::update( Comment::update(
&mut *context.conn().await?, &mut *context.conn().await?,
comment.id, comment.id,

View File

@ -66,8 +66,7 @@ impl ActivityHandler for AcceptFollow {
// This will throw an error if no follow was requested // This will throw an error if no follow was requested
let community_id = community.id; let community_id = community.id;
let person_id = person.id; let person_id = person.id;
CommunityFollower::follow_accepted(&mut *context.conn().await?, community_id, person_id) CommunityFollower::follow_accepted(context.conn().await?, community_id, person_id).await?;
.await?;
Ok(()) Ok(())
} }

View File

@ -65,7 +65,7 @@ impl Follow {
person_id: actor.id, person_id: actor.id,
pending: true, pending: true,
}; };
CommunityFollower::follow(&mut *context.conn().await?, &community_follower_form) CommunityFollower::follow(context.conn().await?, &community_follower_form)
.await .await
.ok(); .ok();
@ -113,7 +113,7 @@ impl ActivityHandler for Follow {
follower_id: actor.id, follower_id: actor.id,
pending: false, pending: false,
}; };
PersonFollower::follow(&mut *context.conn().await?, &form).await?; PersonFollower::follow(context.conn().await?, &form).await?;
} }
UserOrCommunity::Community(c) => { UserOrCommunity::Community(c) => {
let form = CommunityFollowerForm { let form = CommunityFollowerForm {
@ -121,7 +121,7 @@ impl ActivityHandler for Follow {
person_id: actor.id, person_id: actor.id,
pending: false, pending: false,
}; };
CommunityFollower::follow(&mut *context.conn().await?, &form).await?; CommunityFollower::follow(context.conn().await?, &form).await?;
} }
} }
@ -139,7 +139,7 @@ impl SendActivity for BlockCommunity {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
let community = Community::read(&mut *context.conn().await?, request.community_id).await?; let community = Community::read(context.conn().await?, request.community_id).await?;
UndoFollow::send(&local_user_view.person.into(), &community.into(), context).await UndoFollow::send(&local_user_view.person.into(), &community.into(), context).await
} }
} }

View File

@ -27,10 +27,9 @@ impl SendActivity for FollowCommunity {
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?; let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
let person = local_user_view.person.clone().into(); let person = local_user_view.person.clone().into();
let community: ApubCommunity = let community: ApubCommunity = Community::read(context.conn().await?, request.community_id)
Community::read(&mut *context.conn().await?, request.community_id) .await?
.await? .into();
.into();
if community.local { if community.local {
Ok(()) Ok(())
} else if request.follow { } else if request.follow {

Some files were not shown because too many files have changed in this diff Show More