let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
let comment_id = data.comment_id;
- let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
+ let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
check_community_ban(
local_user_view.person.id,
orig_comment.community.id,
- context.pool(),
+ &mut context.pool(),
)
.await?;
// Verify that only a mod or admin can distinguish a comment
is_mod_or_admin(
- context.pool(),
+ &mut context.pool(),
local_user_view.person.id,
orig_comment.community.id,
)
let form = CommentUpdateForm::builder()
.distinguished(Some(data.distinguished))
.build();
- Comment::update(context.pool(), comment_id, &form)
+ Comment::update(&mut context.pool(), comment_id, &form)
.await
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
let comment_id = data.comment_id;
let person_id = local_user_view.person.id;
- let comment_view = CommentView::read(context.pool(), comment_id, Some(person_id)).await?;
+ let comment_view = CommentView::read(&mut context.pool(), comment_id, Some(person_id)).await?;
Ok(CommentResponse {
comment_view,
#[tracing::instrument(skip(context))]
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
let data: &CreateCommentLike = self;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
let mut recipient_ids = Vec::<LocalUserId>::new();
check_downvotes_enabled(data.score, &local_site)?;
let comment_id = data.comment_id;
- let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
+ let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
check_community_ban(
local_user_view.person.id,
orig_comment.community.id,
- context.pool(),
+ &mut context.pool(),
)
.await?;
// Add parent poster or commenter to recipients
- let comment_reply = CommentReply::read_by_comment(context.pool(), comment_id).await;
+ let comment_reply = CommentReply::read_by_comment(&mut context.pool(), comment_id).await;
if let Ok(reply) = comment_reply {
let recipient_id = reply.recipient_id;
- if let Ok(local_recipient) = LocalUserView::read_person(context.pool(), recipient_id).await {
+ if let Ok(local_recipient) =
+ LocalUserView::read_person(&mut context.pool(), recipient_id).await
+ {
recipient_ids.push(local_recipient.local_user.id);
}
}
// Remove any likes first
let person_id = local_user_view.person.id;
- CommentLike::remove(context.pool(), person_id, comment_id).await?;
+ CommentLike::remove(&mut context.pool(), person_id, comment_id).await?;
// Only add the like if the score isnt 0
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
if do_add {
- CommentLike::like(context.pool(), &like_form)
+ CommentLike::like(&mut context.pool(), &like_form)
.await
.with_lemmy_type(LemmyErrorType::CouldntLikeComment)?;
}
};
if data.save {
- CommentSaved::save(context.pool(), &comment_saved_form)
+ CommentSaved::save(&mut context.pool(), &comment_saved_form)
.await
.with_lemmy_type(LemmyErrorType::CouldntSaveComment)?;
} else {
- CommentSaved::unsave(context.pool(), &comment_saved_form)
+ CommentSaved::unsave(&mut context.pool(), &comment_saved_form)
.await
.with_lemmy_type(LemmyErrorType::CouldntSaveComment)?;
}
let comment_id = data.comment_id;
let person_id = local_user_view.person.id;
- let comment_view = CommentView::read(context.pool(), comment_id, Some(person_id)).await?;
+ let comment_view = CommentView::read(&mut context.pool(), comment_id, Some(person_id)).await?;
Ok(CommentResponse {
comment_view,
) -> Result<CommentReportResponse, LemmyError> {
let data: &CreateCommentReport = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
let reason = self.reason.trim();
check_report_reason(reason, &local_site)?;
let person_id = local_user_view.person.id;
let comment_id = data.comment_id;
- let comment_view = CommentView::read(context.pool(), comment_id, None).await?;
+ let comment_view = CommentView::read(&mut context.pool(), comment_id, None).await?;
- check_community_ban(person_id, comment_view.community.id, context.pool()).await?;
+ check_community_ban(person_id, comment_view.community.id, &mut context.pool()).await?;
let report_form = CommentReportForm {
creator_id: person_id,
reason: reason.to_owned(),
};
- let report = CommentReport::report(context.pool(), &report_form)
+ let report = CommentReport::report(&mut context.pool(), &report_form)
.await
.with_lemmy_type(LemmyErrorType::CouldntCreateReport)?;
- let comment_report_view = CommentReportView::read(context.pool(), report.id, person_id).await?;
+ let comment_report_view =
+ CommentReportView::read(&mut context.pool(), report.id, person_id).await?;
// Email the admins
if local_site.reports_email_admins {
send_new_report_email_to_admins(
&comment_report_view.creator.name,
&comment_report_view.comment_creator.name,
- context.pool(),
+ &mut context.pool(),
context.settings(),
)
.await?;
let page = data.page;
let limit = data.limit;
let comment_reports = CommentReportQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.my_person_id(person_id)
.admin(admin)
.community_id(community_id)
let report_id = data.report_id;
let person_id = local_user_view.person.id;
- let report = CommentReportView::read(context.pool(), report_id, person_id).await?;
+ let report = CommentReportView::read(&mut context.pool(), report_id, person_id).await?;
let person_id = local_user_view.person.id;
- is_mod_or_admin(context.pool(), person_id, report.community.id).await?;
+ is_mod_or_admin(&mut context.pool(), person_id, report.community.id).await?;
if data.resolved {
- CommentReport::resolve(context.pool(), report_id, person_id)
+ CommentReport::resolve(&mut context.pool(), report_id, person_id)
.await
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
} else {
- CommentReport::unresolve(context.pool(), report_id, person_id)
+ CommentReport::unresolve(&mut context.pool(), report_id, person_id)
.await
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
}
let report_id = data.report_id;
- let comment_report_view = CommentReportView::read(context.pool(), report_id, person_id).await?;
+ let comment_report_view =
+ CommentReportView::read(&mut context.pool(), report_id, person_id).await?;
Ok(CommentReportResponse {
comment_report_view,
let community_id = data.community_id;
// Verify that only mods or admins can add mod
- is_mod_or_admin(context.pool(), local_user_view.person.id, community_id).await?;
- let community = Community::read(context.pool(), community_id).await?;
+ is_mod_or_admin(&mut context.pool(), local_user_view.person.id, community_id).await?;
+ let community = Community::read(&mut context.pool(), community_id).await?;
if local_user_view.person.admin && !community.local {
return Err(LemmyErrorType::NotAModerator)?;
}
person_id: data.person_id,
};
if data.added {
- CommunityModerator::join(context.pool(), &community_moderator_form)
+ CommunityModerator::join(&mut context.pool(), &community_moderator_form)
.await
.with_lemmy_type(LemmyErrorType::CommunityModeratorAlreadyExists)?;
} else {
- CommunityModerator::leave(context.pool(), &community_moderator_form)
+ CommunityModerator::leave(&mut context.pool(), &community_moderator_form)
.await
.with_lemmy_type(LemmyErrorType::CommunityModeratorAlreadyExists)?;
}
removed: Some(!data.added),
};
- ModAddCommunity::create(context.pool(), &form).await?;
+ ModAddCommunity::create(&mut context.pool(), &form).await?;
// 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`)
let community_id = data.community_id;
- let moderators = CommunityModeratorView::for_community(context.pool(), community_id).await?;
+ let moderators =
+ CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
Ok(AddModToCommunityResponse { moderators })
}
let expires = data.expires.map(naive_from_unix);
// Verify that only mods or admins can ban
- is_mod_or_admin(context.pool(), local_user_view.person.id, community_id).await?;
+ is_mod_or_admin(&mut context.pool(), local_user_view.person.id, community_id).await?;
is_valid_body_field(&data.reason, false)?;
let community_user_ban_form = CommunityPersonBanForm {
};
if data.ban {
- CommunityPersonBan::ban(context.pool(), &community_user_ban_form)
+ CommunityPersonBan::ban(&mut context.pool(), &community_user_ban_form)
.await
.with_lemmy_type(LemmyErrorType::CommunityUserAlreadyBanned)?;
pending: false,
};
- CommunityFollower::unfollow(context.pool(), &community_follower_form)
+ CommunityFollower::unfollow(&mut context.pool(), &community_follower_form)
.await
.ok();
} else {
- CommunityPersonBan::unban(context.pool(), &community_user_ban_form)
+ CommunityPersonBan::unban(&mut context.pool(), &community_user_ban_form)
.await
.with_lemmy_type(LemmyErrorType::CommunityUserAlreadyBanned)?;
}
// Remove/Restore their data if that's desired
if remove_data {
- remove_user_data_in_community(community_id, banned_person_id, context.pool()).await?;
+ remove_user_data_in_community(community_id, banned_person_id, &mut context.pool()).await?;
}
// Mod tables
expires,
};
- ModBanFromCommunity::create(context.pool(), &form).await?;
+ ModBanFromCommunity::create(&mut context.pool(), &form).await?;
let person_id = data.person_id;
- let person_view = PersonView::read(context.pool(), person_id).await?;
+ let person_view = PersonView::read(&mut context.pool(), person_id).await?;
Ok(BanFromCommunityResponse {
person_view,
};
if data.block {
- CommunityBlock::block(context.pool(), &community_block_form)
+ CommunityBlock::block(&mut context.pool(), &community_block_form)
.await
.with_lemmy_type(LemmyErrorType::CommunityBlockAlreadyExists)?;
pending: false,
};
- CommunityFollower::unfollow(context.pool(), &community_follower_form)
+ CommunityFollower::unfollow(&mut context.pool(), &community_follower_form)
.await
.ok();
} else {
- CommunityBlock::unblock(context.pool(), &community_block_form)
+ CommunityBlock::unblock(&mut context.pool(), &community_block_form)
.await
.with_lemmy_type(LemmyErrorType::CommunityBlockAlreadyExists)?;
}
let community_view =
- CommunityView::read(context.pool(), community_id, Some(person_id), None).await?;
+ CommunityView::read(&mut context.pool(), community_id, Some(person_id), None).await?;
Ok(BlockCommunityResponse {
blocked: data.block,
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
let community_id = data.community_id;
- let community = Community::read(context.pool(), community_id).await?;
+ let community = Community::read(&mut context.pool(), community_id).await?;
let mut community_follower_form = CommunityFollowerForm {
community_id: data.community_id,
person_id: local_user_view.person.id,
if data.follow {
if community.local {
- check_community_ban(local_user_view.person.id, community_id, context.pool()).await?;
- check_community_deleted_or_removed(community_id, context.pool()).await?;
+ check_community_ban(local_user_view.person.id, community_id, &mut context.pool()).await?;
+ check_community_deleted_or_removed(community_id, &mut context.pool()).await?;
- CommunityFollower::follow(context.pool(), &community_follower_form)
+ CommunityFollower::follow(&mut context.pool(), &community_follower_form)
.await
.with_lemmy_type(LemmyErrorType::CommunityFollowerAlreadyExists)?;
} else {
// Mark as pending, the actual federation activity is sent via `SendActivity` handler
community_follower_form.pending = true;
- CommunityFollower::follow(context.pool(), &community_follower_form)
+ CommunityFollower::follow(&mut context.pool(), &community_follower_form)
.await
.with_lemmy_type(LemmyErrorType::CommunityFollowerAlreadyExists)?;
}
}
if !data.follow {
- CommunityFollower::unfollow(context.pool(), &community_follower_form)
+ CommunityFollower::unfollow(&mut context.pool(), &community_follower_form)
.await
.with_lemmy_type(LemmyErrorType::CommunityFollowerAlreadyExists)?;
}
let community_id = data.community_id;
let person_id = local_user_view.person.id;
let community_view =
- CommunityView::read(context.pool(), community_id, Some(person_id), None).await?;
- let discussion_languages = CommunityLanguage::read(context.pool(), community_id).await?;
+ CommunityView::read(&mut context.pool(), community_id, Some(person_id), None).await?;
+ let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?;
Ok(Self::Response {
community_view,
};
let community_id = data.community_id;
- Community::update(context.pool(), community_id, &community_form)
+ Community::update(&mut context.pool(), community_id, &community_form)
.await
.with_lemmy_type(LemmyErrorType::CouldntUpdateCommunityHiddenStatus)?;
- ModHideCommunity::create(context.pool(), &mod_hide_community_form).await?;
+ ModHideCommunity::create(&mut context.pool(), &mod_hide_community_form).await?;
build_community_response(context, local_user_view, community_id).await
}
// Fetch the community mods
let community_id = data.community_id;
let mut community_mods =
- CommunityModeratorView::for_community(context.pool(), community_id).await?;
+ CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
// Make sure transferrer is either the top community mod, or an admin
if !(is_top_mod(&local_user_view, &community_mods).is_ok()
// Delete all the mods
let community_id = data.community_id;
- CommunityModerator::delete_for_community(context.pool(), community_id).await?;
+ CommunityModerator::delete_for_community(&mut context.pool(), community_id).await?;
// TODO: this should probably be a bulk operation
// Re-add the mods, in the new order
person_id: cmod.moderator.id,
};
- CommunityModerator::join(context.pool(), &community_moderator_form)
+ CommunityModerator::join(&mut context.pool(), &community_moderator_form)
.await
.with_lemmy_type(LemmyErrorType::CommunityModeratorAlreadyExists)?;
}
community_id: data.community_id,
};
- ModTransferCommunity::create(context.pool(), &form).await?;
+ ModTransferCommunity::create(&mut context.pool(), &form).await?;
let community_id = data.community_id;
let person_id = local_user_view.person.id;
- let community_view = CommunityView::read(context.pool(), community_id, Some(person_id), None)
- .await
- .with_lemmy_type(LemmyErrorType::CouldntFindCommunity)?;
+ let community_view =
+ CommunityView::read(&mut context.pool(), community_id, Some(person_id), None)
+ .await
+ .with_lemmy_type(LemmyErrorType::CouldntFindCommunity)?;
let community_id = data.community_id;
- let moderators = CommunityModeratorView::for_community(context.pool(), community_id)
+ let moderators = CommunityModeratorView::for_community(&mut context.pool(), community_id)
.await
.with_lemmy_type(LemmyErrorType::CouldntFindCommunity)?;
#[serial]
async fn test_should_not_validate_user_token_after_password_change() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let secret = Secret::init(pool).await.unwrap();
let settings = &SETTINGS.to_owned();
let added = data.added;
let added_person_id = data.person_id;
let added_admin = Person::update(
- context.pool(),
+ &mut context.pool(),
added_person_id,
&PersonUpdateForm::builder().admin(Some(added)).build(),
)
removed: Some(!data.added),
};
- ModAdd::create(context.pool(), &form).await?;
+ ModAdd::create(&mut context.pool(), &form).await?;
- let admins = PersonView::admins(context.pool()).await?;
+ let admins = PersonView::admins(&mut context.pool()).await?;
Ok(AddAdminResponse { admins })
}
let expires = data.expires.map(naive_from_unix);
let person = Person::update(
- context.pool(),
+ &mut context.pool(),
banned_person_id,
&PersonUpdateForm::builder()
.banned(Some(ban))
if remove_data {
remove_user_data(
person.id,
- context.pool(),
+ &mut context.pool(),
context.settings(),
context.client(),
)
expires,
};
- ModBan::create(context.pool(), &form).await?;
+ ModBan::create(&mut context.pool(), &form).await?;
let person_id = data.person_id;
- let person_view = PersonView::read(context.pool(), person_id).await?;
+ let person_view = PersonView::read(&mut context.pool(), person_id).await?;
Ok(BanPersonResponse {
person_view,
target_id,
};
- let target_person_view = PersonView::read(context.pool(), target_id).await?;
+ let target_person_view = PersonView::read(&mut context.pool(), target_id).await?;
if target_person_view.person.admin {
return Err(LemmyErrorType::CantBlockAdmin)?;
}
if data.block {
- PersonBlock::block(context.pool(), &person_block_form)
+ PersonBlock::block(&mut context.pool(), &person_block_form)
.await
.with_lemmy_type(LemmyErrorType::PersonBlockAlreadyExists)?;
} else {
- PersonBlock::unblock(context.pool(), &person_block_form)
+ PersonBlock::unblock(&mut context.pool(), &person_block_form)
.await
.with_lemmy_type(LemmyErrorType::PersonBlockAlreadyExists)?;
}
let local_user_id = local_user_view.local_user.id;
let new_password = data.new_password.clone();
let updated_local_user =
- LocalUser::update_password(context.pool(), local_user_id, &new_password).await?;
+ LocalUser::update_password(&mut context.pool(), local_user_id, &new_password).await?;
// Return the jwt
Ok(LoginResponse {
// Fetch the user_id from the token
let token = data.token.clone();
- let local_user_id = PasswordResetRequest::read_from_token(context.pool(), &token)
+ let local_user_id = PasswordResetRequest::read_from_token(&mut context.pool(), &token)
.await
.map(|p| p.local_user_id)?;
// Update the user with the new password
let password = data.password.clone();
- let updated_local_user = LocalUser::update_password(context.pool(), local_user_id, &password)
- .await
- .with_lemmy_type(LemmyErrorType::CouldntUpdateUser)?;
+ let updated_local_user =
+ LocalUser::update_password(&mut context.pool(), local_user_id, &password)
+ .await
+ .with_lemmy_type(LemmyErrorType::CouldntUpdateUser)?;
// Return the jwt if login is allowed
- let site_view = SiteView::read_local(context.pool()).await?;
+ let site_view = SiteView::read_local(&mut context.pool()).await?;
let jwt = if site_view.local_site.registration_mode == RegistrationMode::RequireApplication
&& !updated_local_user.accepted_application
{
#[tracing::instrument(skip(context))]
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
if !local_site.captcha_enabled {
return Ok(GetCaptchaResponse { ok: None });
let captcha_form: CaptchaAnswerForm = CaptchaAnswerForm { answer };
// Stores the captcha item in the db
- let captcha = CaptchaAnswer::insert(context.pool(), &captcha_form).await?;
+ let captcha = CaptchaAnswer::insert(&mut context.pool(), &captcha_form).await?;
Ok(GetCaptchaResponse {
ok: Some(CaptchaResponse {
// Make sure user is an admin
is_admin(&local_user_view)?;
- let banned = PersonView::banned(context.pool()).await?;
+ let banned = PersonView::banned(&mut context.pool()).await?;
Ok(Self::Response { banned })
}
async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
let data: &Login = self;
- let site_view = SiteView::read_local(context.pool()).await?;
+ let site_view = SiteView::read_local(&mut context.pool()).await?;
// Fetch that username / email
let username_or_email = data.username_or_email.clone();
- let local_user_view = LocalUserView::find_by_email_or_name(context.pool(), &username_or_email)
- .await
- .with_lemmy_type(LemmyErrorType::IncorrectLogin)?;
+ let local_user_view =
+ LocalUserView::find_by_email_or_name(&mut context.pool(), &username_or_email)
+ .await
+ .with_lemmy_type(LemmyErrorType::IncorrectLogin)?;
// Verify the password
let valid: bool = verify(
return Err(LemmyErrorType::EmailNotVerified)?;
}
- check_registration_application(&local_user_view, &site_view.local_site, context.pool()).await?;
+ check_registration_application(&local_user_view, &site_view.local_site, &mut context.pool())
+ .await?;
// Check the totp
check_totp_2fa_valid(
let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts);
let mentions = PersonMentionQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.recipient_id(person_id)
.my_person_id(person_id)
.sort(sort)
let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts);
let replies = CommentReplyQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.recipient_id(person_id)
.my_person_id(person_id)
.sort(sort)
let person_id = local_user_view.person.id;
// Mark all comment_replies as read
- CommentReply::mark_all_as_read(context.pool(), person_id)
+ CommentReply::mark_all_as_read(&mut context.pool(), person_id)
.await
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
// Mark all user mentions as read
- PersonMention::mark_all_as_read(context.pool(), person_id)
+ PersonMention::mark_all_as_read(&mut context.pool(), person_id)
.await
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
// Mark all private_messages as read
- PrivateMessage::mark_all_as_read(context.pool(), person_id)
+ PrivateMessage::mark_all_as_read(&mut context.pool(), person_id)
.await
.with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
let person_mention_id = data.person_mention_id;
- let read_person_mention = PersonMention::read(context.pool(), person_mention_id).await?;
+ let read_person_mention = PersonMention::read(&mut context.pool(), person_mention_id).await?;
if local_user_view.person.id != read_person_mention.recipient_id {
return Err(LemmyErrorType::CouldntUpdateComment)?;
let person_mention_id = read_person_mention.id;
let read = Some(data.read);
PersonMention::update(
- context.pool(),
+ &mut context.pool(),
person_mention_id,
&PersonMentionUpdateForm { read },
)
let person_mention_id = read_person_mention.id;
let person_id = local_user_view.person.id;
let person_mention_view =
- PersonMentionView::read(context.pool(), person_mention_id, Some(person_id)).await?;
+ PersonMentionView::read(&mut context.pool(), person_mention_id, Some(person_id)).await?;
Ok(PersonMentionResponse {
person_mention_view,
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
let comment_reply_id = data.comment_reply_id;
- let read_comment_reply = CommentReply::read(context.pool(), comment_reply_id).await?;
+ let read_comment_reply = CommentReply::read(&mut context.pool(), comment_reply_id).await?;
if local_user_view.person.id != read_comment_reply.recipient_id {
return Err(LemmyErrorType::CouldntUpdateComment)?;
let read = Some(data.read);
CommentReply::update(
- context.pool(),
+ &mut context.pool(),
comment_reply_id,
&CommentReplyUpdateForm { read },
)
let comment_reply_id = read_comment_reply.id;
let person_id = local_user_view.person.id;
let comment_reply_view =
- CommentReplyView::read(context.pool(), comment_reply_id, Some(person_id)).await?;
+ CommentReplyView::read(&mut context.pool(), comment_reply_id, Some(person_id)).await?;
Ok(CommentReplyResponse { comment_reply_view })
}
let person_id = local_user_view.person.id;
- let replies = CommentReplyView::get_unread_replies(context.pool(), person_id).await?;
+ let replies = CommentReplyView::get_unread_replies(&mut context.pool(), person_id).await?;
- let mentions = PersonMentionView::get_unread_mentions(context.pool(), person_id).await?;
+ let mentions = PersonMentionView::get_unread_mentions(&mut context.pool(), person_id).await?;
let private_messages =
- PrivateMessageView::get_unread_messages(context.pool(), person_id).await?;
+ PrivateMessageView::get_unread_messages(&mut context.pool(), person_id).await?;
Ok(Self::Response {
replies,
let community_id = data.community_id;
let comment_reports =
- CommentReportView::get_report_count(context.pool(), person_id, admin, community_id).await?;
+ CommentReportView::get_report_count(&mut context.pool(), person_id, admin, community_id)
+ .await?;
let post_reports =
- PostReportView::get_report_count(context.pool(), person_id, admin, community_id).await?;
+ PostReportView::get_report_count(&mut context.pool(), person_id, admin, community_id).await?;
let private_message_reports = if admin && community_id.is_none() {
- Some(PrivateMessageReportView::get_report_count(context.pool()).await?)
+ Some(PrivateMessageReportView::get_report_count(&mut context.pool()).await?)
} else {
None
};
// Fetch that email
let email = data.email.to_lowercase();
- let local_user_view = LocalUserView::find_by_email(context.pool(), &email)
+ let local_user_view = LocalUserView::find_by_email(&mut context.pool(), &email)
.await
.with_lemmy_type(LemmyErrorType::IncorrectLogin)?;
// Check for too many attempts (to limit potential abuse)
let recent_resets_count = PasswordResetRequest::get_recent_password_resets_count(
- context.pool(),
+ &mut context.pool(),
local_user_view.local_user.id,
)
.await?;
}
// Email the pure token to the user.
- send_password_reset_email(&local_user_view, context.pool(), context.settings()).await?;
+ send_password_reset_email(&local_user_view, &mut context.pool(), context.settings()).await?;
Ok(PasswordResetResponse {})
}
}
async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
let data: &SaveUserSettings = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let site_view = SiteView::read_local(context.pool()).await?;
+ let site_view = SiteView::read_local(&mut context.pool()).await?;
let avatar = diesel_option_overwrite_to_url(&data.avatar)?;
let banner = diesel_option_overwrite_to_url(&data.banner)?;
let previous_email = local_user_view.local_user.email.clone().unwrap_or_default();
// Only send the verification email if there was an email change
if previous_email.ne(email) {
- send_verification_email(&local_user_view, email, context.pool(), context.settings())
- .await?;
+ send_verification_email(
+ &local_user_view,
+ email,
+ &mut context.pool(),
+ context.settings(),
+ )
+ .await?;
}
}
.banner(banner)
.build();
- Person::update(context.pool(), person_id, &person_form)
+ Person::update(&mut context.pool(), person_id, &person_form)
.await
.with_lemmy_type(LemmyErrorType::UserAlreadyExists)?;
if let Some(discussion_languages) = data.discussion_languages.clone() {
- LocalUserLanguage::update(context.pool(), discussion_languages, local_user_id).await?;
+ LocalUserLanguage::update(&mut context.pool(), discussion_languages, local_user_id).await?;
}
// If generate_totp is Some(false), this will clear it out from the database.
.open_links_in_new_tab(data.open_links_in_new_tab)
.build();
- let local_user_res = LocalUser::update(context.pool(), local_user_id, &local_user_form).await;
+ let local_user_res =
+ LocalUser::update(&mut context.pool(), local_user_id, &local_user_form).await;
let updated_local_user = match local_user_res {
Ok(u) => u,
Err(e) => {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
let token = self.token.clone();
- let verification = EmailVerification::read_for_token(context.pool(), &token)
+ let verification = EmailVerification::read_for_token(&mut context.pool(), &token)
.await
.with_lemmy_type(LemmyErrorType::TokenNotFound)?;
.build();
let local_user_id = verification.local_user_id;
- LocalUser::update(context.pool(), local_user_id, &form).await?;
+ LocalUser::update(&mut context.pool(), local_user_id, &form).await?;
- EmailVerification::delete_old_tokens_for_local_user(context.pool(), local_user_id).await?;
+ EmailVerification::delete_old_tokens_for_local_user(&mut context.pool(), local_user_id).await?;
Ok(VerifyEmailResponse {})
}
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
let post_id = data.post_id;
- let orig_post = Post::read(context.pool(), post_id).await?;
+ let orig_post = Post::read(&mut context.pool(), post_id).await?;
check_community_ban(
local_user_view.person.id,
orig_post.community_id,
- context.pool(),
+ &mut context.pool(),
)
.await?;
- check_community_deleted_or_removed(orig_post.community_id, context.pool()).await?;
+ check_community_deleted_or_removed(orig_post.community_id, &mut context.pool()).await?;
if data.feature_type == PostFeatureType::Community {
// Verify that only the mods can feature in community
is_mod_or_admin(
- context.pool(),
+ &mut context.pool(),
local_user_view.person.id,
orig_post.community_id,
)
.featured_local(Some(data.featured))
.build()
};
- Post::update(context.pool(), post_id, &new_post).await?;
+ Post::update(&mut context.pool(), post_id, &new_post).await?;
// Mod tables
let form = ModFeaturePostForm {
is_featured_community: data.feature_type == PostFeatureType::Community,
};
- ModFeaturePost::create(context.pool(), &form).await?;
+ ModFeaturePost::create(&mut context.pool(), &form).await?;
build_post_response(
context,
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
let data: &CreatePostLike = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
// Don't do a downvote if site has downvotes disabled
check_downvotes_enabled(data.score, &local_site)?;
// Check for a community ban
let post_id = data.post_id;
- let post = Post::read(context.pool(), post_id).await?;
+ let post = Post::read(&mut context.pool(), post_id).await?;
- check_community_ban(local_user_view.person.id, post.community_id, context.pool()).await?;
- check_community_deleted_or_removed(post.community_id, context.pool()).await?;
+ check_community_ban(
+ local_user_view.person.id,
+ post.community_id,
+ &mut context.pool(),
+ )
+ .await?;
+ check_community_deleted_or_removed(post.community_id, &mut context.pool()).await?;
let like_form = PostLikeForm {
post_id: data.post_id,
// Remove any likes first
let person_id = local_user_view.person.id;
- PostLike::remove(context.pool(), person_id, post_id).await?;
+ PostLike::remove(&mut context.pool(), person_id, post_id).await?;
// Only add the like if the score isnt 0
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
if do_add {
- PostLike::like(context.pool(), &like_form)
+ PostLike::like(&mut context.pool(), &like_form)
.await
.with_lemmy_type(LemmyErrorType::CouldntLikePost)?;
}
// Mark the post as read
- mark_post_as_read(person_id, post_id, context.pool()).await?;
+ mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
build_post_response(
context,
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
let post_id = data.post_id;
- let orig_post = Post::read(context.pool(), post_id).await?;
+ let orig_post = Post::read(&mut context.pool(), post_id).await?;
check_community_ban(
local_user_view.person.id,
orig_post.community_id,
- context.pool(),
+ &mut context.pool(),
)
.await?;
- check_community_deleted_or_removed(orig_post.community_id, context.pool()).await?;
+ check_community_deleted_or_removed(orig_post.community_id, &mut context.pool()).await?;
// Verify that only the mods can lock
is_mod_or_admin(
- context.pool(),
+ &mut context.pool(),
local_user_view.person.id,
orig_post.community_id,
)
let post_id = data.post_id;
let locked = data.locked;
Post::update(
- context.pool(),
+ &mut context.pool(),
post_id,
&PostUpdateForm::builder().locked(Some(locked)).build(),
)
post_id: data.post_id,
locked: Some(locked),
};
- ModLockPost::create(context.pool(), &form).await?;
+ ModLockPost::create(&mut context.pool(), &form).await?;
build_post_response(
context,
// Mark the post as read / unread
if data.read {
- mark_post_as_read(person_id, post_id, context.pool()).await?;
+ mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
} else {
- mark_post_as_unread(person_id, post_id, context.pool()).await?;
+ mark_post_as_unread(person_id, post_id, &mut context.pool()).await?;
}
// Fetch it
- let post_view = PostView::read(context.pool(), post_id, Some(person_id), None).await?;
+ let post_view = PostView::read(&mut context.pool(), post_id, Some(person_id), None).await?;
Ok(Self::Response { post_view })
}
};
if data.save {
- PostSaved::save(context.pool(), &post_saved_form)
+ PostSaved::save(&mut context.pool(), &post_saved_form)
.await
.with_lemmy_type(LemmyErrorType::CouldntSavePost)?;
} else {
- PostSaved::unsave(context.pool(), &post_saved_form)
+ PostSaved::unsave(&mut context.pool(), &post_saved_form)
.await
.with_lemmy_type(LemmyErrorType::CouldntSavePost)?;
}
let post_id = data.post_id;
let person_id = local_user_view.person.id;
- let post_view = PostView::read(context.pool(), post_id, Some(person_id), None).await?;
+ let post_view = PostView::read(&mut context.pool(), post_id, Some(person_id), None).await?;
// Mark the post as read
- mark_post_as_read(person_id, post_id, context.pool()).await?;
+ mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
Ok(PostResponse { post_view })
}
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostReportResponse, LemmyError> {
let data: &CreatePostReport = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
let reason = self.reason.trim();
check_report_reason(reason, &local_site)?;
let person_id = local_user_view.person.id;
let post_id = data.post_id;
- let post_view = PostView::read(context.pool(), post_id, None, None).await?;
+ let post_view = PostView::read(&mut context.pool(), post_id, None, None).await?;
- check_community_ban(person_id, post_view.community.id, context.pool()).await?;
+ check_community_ban(person_id, post_view.community.id, &mut context.pool()).await?;
let report_form = PostReportForm {
creator_id: person_id,
reason: reason.to_owned(),
};
- let report = PostReport::report(context.pool(), &report_form)
+ let report = PostReport::report(&mut context.pool(), &report_form)
.await
.with_lemmy_type(LemmyErrorType::CouldntCreateReport)?;
- let post_report_view = PostReportView::read(context.pool(), report.id, person_id).await?;
+ let post_report_view = PostReportView::read(&mut context.pool(), report.id, person_id).await?;
// Email the admins
if local_site.reports_email_admins {
send_new_report_email_to_admins(
&post_report_view.creator.name,
&post_report_view.post_creator.name,
- context.pool(),
+ &mut context.pool(),
context.settings(),
)
.await?;
let page = data.page;
let limit = data.limit;
let post_reports = PostReportQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.my_person_id(person_id)
.admin(admin)
.community_id(community_id)
let report_id = data.report_id;
let person_id = local_user_view.person.id;
- let report = PostReportView::read(context.pool(), report_id, person_id).await?;
+ let report = PostReportView::read(&mut context.pool(), report_id, person_id).await?;
let person_id = local_user_view.person.id;
- is_mod_or_admin(context.pool(), person_id, report.community.id).await?;
+ is_mod_or_admin(&mut context.pool(), person_id, report.community.id).await?;
if data.resolved {
- PostReport::resolve(context.pool(), report_id, person_id)
+ PostReport::resolve(&mut context.pool(), report_id, person_id)
.await
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
} else {
- PostReport::unresolve(context.pool(), report_id, person_id)
+ PostReport::unresolve(&mut context.pool(), report_id, person_id)
.await
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
}
- let post_report_view = PostReportView::read(context.pool(), report_id, person_id).await?;
+ let post_report_view = PostReportView::read(&mut context.pool(), report_id, person_id).await?;
Ok(PostReportResponse { post_report_view })
}
// Checking permissions
let private_message_id = data.private_message_id;
- let orig_private_message = PrivateMessage::read(context.pool(), private_message_id).await?;
+ let orig_private_message =
+ PrivateMessage::read(&mut context.pool(), private_message_id).await?;
if local_user_view.person.id != orig_private_message.recipient_id {
return Err(LemmyErrorType::CouldntUpdatePrivateMessage)?;
}
let private_message_id = data.private_message_id;
let read = data.read;
PrivateMessage::update(
- context.pool(),
+ &mut context.pool(),
private_message_id,
&PrivateMessageUpdateForm::builder().read(Some(read)).build(),
)
.await
.with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?;
- let view = PrivateMessageView::read(context.pool(), private_message_id).await?;
+ let view = PrivateMessageView::read(&mut context.pool(), private_message_id).await?;
Ok(PrivateMessageResponse {
private_message_view: view,
})
#[tracing::instrument(skip(context))]
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_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
let reason = self.reason.trim();
check_report_reason(reason, &local_site)?;
let person_id = local_user_view.person.id;
let private_message_id = self.private_message_id;
- let private_message = PrivateMessage::read(context.pool(), private_message_id).await?;
+ let private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
let report_form = PrivateMessageReportForm {
creator_id: person_id,
reason: reason.to_owned(),
};
- let report = PrivateMessageReport::report(context.pool(), &report_form)
+ let report = PrivateMessageReport::report(&mut context.pool(), &report_form)
.await
.with_lemmy_type(LemmyErrorType::CouldntCreateReport)?;
let private_message_report_view =
- PrivateMessageReportView::read(context.pool(), report.id).await?;
+ PrivateMessageReportView::read(&mut context.pool(), report.id).await?;
// Email the admins
if local_site.reports_email_admins {
send_new_report_email_to_admins(
&private_message_report_view.creator.name,
&private_message_report_view.private_message_creator.name,
- context.pool(),
+ &mut context.pool(),
context.settings(),
)
.await?;
let page = self.page;
let limit = self.limit;
let private_message_reports = PrivateMessageReportQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.unresolved_only(unresolved_only)
.page(page)
.limit(limit)
let report_id = self.report_id;
let person_id = local_user_view.person.id;
if self.resolved {
- PrivateMessageReport::resolve(context.pool(), report_id, person_id)
+ PrivateMessageReport::resolve(&mut context.pool(), report_id, person_id)
.await
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
} else {
- PrivateMessageReport::unresolve(context.pool(), report_id, person_id)
+ PrivateMessageReport::unresolve(&mut context.pool(), report_id, person_id)
.await
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
}
let private_message_report_view =
- PrivateMessageReportView::read(context.pool(), report_id).await?;
+ PrivateMessageReportView::read(&mut context.pool(), report_id).await?;
Ok(PrivateMessageReportResponse {
private_message_report_view,
#[tracing::instrument(skip(context))]
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
- let site_view = SiteView::read_local(context.pool()).await?;
+ let site_view = SiteView::read_local(&mut context.pool()).await?;
let federated_instances =
- build_federated_instances(&site_view.local_site, context.pool()).await?;
+ build_federated_instances(&site_view.local_site, &mut context.pool()).await?;
Ok(Self::Response {
federated_instances,
is_admin(&local_user_view)?;
// Make sure there isn't just one admin (so if one leaves, there will still be one left)
- let admins = PersonView::admins(context.pool()).await?;
+ let admins = PersonView::admins(&mut context.pool()).await?;
if admins.len() == 1 {
return Err(LemmyErrorType::CannotLeaveAdmin)?;
}
let person_id = local_user_view.person.id;
Person::update(
- context.pool(),
+ &mut context.pool(),
person_id,
&PersonUpdateForm::builder().admin(Some(false)).build(),
)
removed: Some(true),
};
- ModAdd::create(context.pool(), &form).await?;
+ ModAdd::create(&mut context.pool(), &form).await?;
// Reread site and admins
- let site_view = SiteView::read_local(context.pool()).await?;
- let admins = PersonView::admins(context.pool()).await?;
+ let site_view = SiteView::read_local(&mut context.pool()).await?;
+ let admins = PersonView::admins(&mut context.pool()).await?;
- let all_languages = Language::read_all(context.pool()).await?;
- let discussion_languages = SiteLanguage::read_local_raw(context.pool()).await?;
- let taglines = Tagline::get_all(context.pool(), site_view.local_site.id).await?;
- let custom_emojis = CustomEmojiView::get_all(context.pool(), site_view.local_site.id).await?;
+ let all_languages = Language::read_all(&mut context.pool()).await?;
+ let discussion_languages = SiteLanguage::read_local_raw(&mut context.pool()).await?;
+ let taglines = Tagline::get_all(&mut context.pool(), site_view.local_site.id).await?;
+ let custom_emojis =
+ CustomEmojiView::get_all(&mut context.pool(), site_view.local_site.id).await?;
Ok(GetSiteResponse {
site_view,
let data: &GetModlog = self;
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
check_private_instance(&local_user_view, &local_site)?;
None => CommunityId(-1),
};
let is_mod_of_community = data.community_id.is_some()
- && is_mod_or_admin(context.pool(), local_person_id, community_id_value)
+ && is_mod_or_admin(&mut context.pool(), local_person_id, community_id_value)
.await
.is_ok();
let hide_modlog_names = local_site.hide_modlog_mod_names && !is_mod_of_community && !is_admin;
hide_modlog_names,
};
let removed_posts = match type_ {
- All | ModRemovePost => ModRemovePostView::list(context.pool(), params).await?,
+ All | ModRemovePost => ModRemovePostView::list(&mut context.pool(), params).await?,
_ => Default::default(),
};
let locked_posts = match type_ {
- All | ModLockPost => ModLockPostView::list(context.pool(), params).await?,
+ All | ModLockPost => ModLockPostView::list(&mut context.pool(), params).await?,
_ => Default::default(),
};
let featured_posts = match type_ {
- All | ModFeaturePost => ModFeaturePostView::list(context.pool(), params).await?,
+ All | ModFeaturePost => ModFeaturePostView::list(&mut context.pool(), params).await?,
_ => Default::default(),
};
let removed_comments = match type_ {
- All | ModRemoveComment => ModRemoveCommentView::list(context.pool(), params).await?,
+ All | ModRemoveComment => ModRemoveCommentView::list(&mut context.pool(), params).await?,
_ => Default::default(),
};
let banned_from_community = match type_ {
- All | ModBanFromCommunity => ModBanFromCommunityView::list(context.pool(), params).await?,
+ All | ModBanFromCommunity => {
+ ModBanFromCommunityView::list(&mut context.pool(), params).await?
+ }
_ => Default::default(),
};
let added_to_community = match type_ {
- All | ModAddCommunity => ModAddCommunityView::list(context.pool(), params).await?,
+ All | ModAddCommunity => ModAddCommunityView::list(&mut context.pool(), params).await?,
_ => Default::default(),
};
let transferred_to_community = match type_ {
- All | ModTransferCommunity => ModTransferCommunityView::list(context.pool(), params).await?,
+ All | ModTransferCommunity => {
+ ModTransferCommunityView::list(&mut context.pool(), params).await?
+ }
_ => Default::default(),
};
let hidden_communities = match type_ {
All | ModHideCommunity if other_person_id.is_none() => {
- ModHideCommunityView::list(context.pool(), params).await?
+ ModHideCommunityView::list(&mut context.pool(), params).await?
}
_ => Default::default(),
};
) = if data.community_id.is_none() {
(
match type_ {
- All | ModBan => ModBanView::list(context.pool(), params).await?,
+ All | ModBan => ModBanView::list(&mut context.pool(), params).await?,
_ => Default::default(),
},
match type_ {
- All | ModAdd => ModAddView::list(context.pool(), params).await?,
+ All | ModAdd => ModAddView::list(&mut context.pool(), params).await?,
_ => Default::default(),
},
match type_ {
All | ModRemoveCommunity if other_person_id.is_none() => {
- ModRemoveCommunityView::list(context.pool(), params).await?
+ ModRemoveCommunityView::list(&mut context.pool(), params).await?
}
_ => Default::default(),
},
match type_ {
All | AdminPurgePerson if other_person_id.is_none() => {
- AdminPurgePersonView::list(context.pool(), params).await?
+ AdminPurgePersonView::list(&mut context.pool(), params).await?
}
_ => Default::default(),
},
match type_ {
All | AdminPurgeCommunity if other_person_id.is_none() => {
- AdminPurgeCommunityView::list(context.pool(), params).await?
+ AdminPurgeCommunityView::list(&mut context.pool(), params).await?
}
_ => Default::default(),
},
match type_ {
All | AdminPurgePost if other_person_id.is_none() => {
- AdminPurgePostView::list(context.pool(), params).await?
+ AdminPurgePostView::list(&mut context.pool(), params).await?
}
_ => Default::default(),
},
match type_ {
All | AdminPurgeComment if other_person_id.is_none() => {
- AdminPurgeCommentView::list(context.pool(), params).await?
+ AdminPurgeCommentView::list(&mut context.pool(), params).await?
}
_ => Default::default(),
},
let comment_id = data.comment_id;
// Read the comment to get the post_id
- let comment = Comment::read(context.pool(), comment_id).await?;
+ let comment = Comment::read(&mut context.pool(), comment_id).await?;
let post_id = comment.post_id;
// TODO read comments for pictrs images and purge them
- Comment::delete(context.pool(), comment_id).await?;
+ Comment::delete(&mut context.pool(), comment_id).await?;
// Mod tables
let reason = data.reason.clone();
post_id,
};
- AdminPurgeComment::create(context.pool(), &form).await?;
+ AdminPurgeComment::create(&mut context.pool(), &form).await?;
Ok(PurgeItemResponse { success: true })
}
let community_id = data.community_id;
// Read the community to get its images
- let community = Community::read(context.pool(), community_id).await?;
+ let community = Community::read(&mut context.pool(), community_id).await?;
if let Some(banner) = community.banner {
purge_image_from_pictrs(context.client(), context.settings(), &banner)
purge_image_posts_for_community(
community_id,
- context.pool(),
+ &mut context.pool(),
context.settings(),
context.client(),
)
.await?;
- Community::delete(context.pool(), community_id).await?;
+ Community::delete(&mut context.pool(), community_id).await?;
// Mod tables
let reason = data.reason.clone();
reason,
};
- AdminPurgeCommunity::create(context.pool(), &form).await?;
+ AdminPurgeCommunity::create(&mut context.pool(), &form).await?;
Ok(PurgeItemResponse { success: true })
}
// Read the person to get their images
let person_id = data.person_id;
- let person = Person::read(context.pool(), person_id).await?;
+ let person = Person::read(&mut context.pool(), person_id).await?;
if let Some(banner) = person.banner {
purge_image_from_pictrs(context.client(), context.settings(), &banner)
purge_image_posts_for_person(
person_id,
- context.pool(),
+ &mut context.pool(),
context.settings(),
context.client(),
)
.await?;
- Person::delete(context.pool(), person_id).await?;
+ Person::delete(&mut context.pool(), person_id).await?;
// Mod tables
let reason = data.reason.clone();
reason,
};
- AdminPurgePerson::create(context.pool(), &form).await?;
+ AdminPurgePerson::create(&mut context.pool(), &form).await?;
Ok(PurgeItemResponse { success: true })
}
let post_id = data.post_id;
// Read the post to get the community_id
- let post = Post::read(context.pool(), post_id).await?;
+ let post = Post::read(&mut context.pool(), post_id).await?;
// Purge image
if let Some(url) = post.url {
let community_id = post.community_id;
- Post::delete(context.pool(), post_id).await?;
+ Post::delete(&mut context.pool(), post_id).await?;
// Mod tables
let reason = data.reason.clone();
community_id,
};
- AdminPurgePost::create(context.pool(), &form).await?;
+ AdminPurgePost::create(&mut context.pool(), &form).await?;
Ok(PurgeItemResponse { success: true })
}
};
let registration_application =
- RegistrationApplication::update(context.pool(), app_id, &app_form).await?;
+ RegistrationApplication::update(&mut context.pool(), app_id, &app_form).await?;
// Update the local_user row
let local_user_form = LocalUserUpdateForm::builder()
.build();
let approved_user_id = registration_application.local_user_id;
- LocalUser::update(context.pool(), approved_user_id, &local_user_form).await?;
+ LocalUser::update(&mut context.pool(), approved_user_id, &local_user_form).await?;
if data.approve {
- let approved_local_user_view = LocalUserView::read(context.pool(), approved_user_id).await?;
+ let approved_local_user_view =
+ LocalUserView::read(&mut context.pool(), approved_user_id).await?;
if approved_local_user_view.local_user.email.is_some() {
send_application_approved_email(&approved_local_user_view, context.settings()).await?;
// Read the view
let registration_application =
- RegistrationApplicationView::read(context.pool(), app_id).await?;
+ RegistrationApplicationView::read(&mut context.pool(), app_id).await?;
Ok(Self::Response {
registration_application,
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
let data = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
// Make sure user is an admin
is_admin(&local_user_view)?;
let page = data.page;
let limit = data.limit;
let registration_applications = RegistrationApplicationQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.unread_only(unread_only)
.verified_email_only(Some(verified_email_only))
.page(page)
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
let data = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
// Only let admins do this
is_admin(&local_user_view)?;
let verified_email_only = local_site.require_email_verification;
let registration_applications =
- RegistrationApplicationView::get_unread_count(context.pool(), verified_email_only).await?;
+ RegistrationApplicationView::get_unread_count(&mut context.pool(), verified_email_only)
+ .await?;
Ok(Self::Response {
registration_applications,
recipient_ids: Vec<LocalUserId>,
) -> Result<CommentResponse, LemmyError> {
let person_id = local_user_view.map(|l| l.person.id);
- let comment_view = CommentView::read(context.pool(), comment_id, person_id).await?;
+ let comment_view = CommentView::read(&mut context.pool(), comment_id, person_id).await?;
Ok(CommentResponse {
comment_view,
recipient_ids,
local_user_view: LocalUserView,
community_id: CommunityId,
) -> Result<CommunityResponse, LemmyError> {
- let is_mod_or_admin = is_mod_or_admin(context.pool(), local_user_view.person.id, community_id)
- .await
- .is_ok();
+ let is_mod_or_admin =
+ is_mod_or_admin(&mut context.pool(), local_user_view.person.id, community_id)
+ .await
+ .is_ok();
let person_id = local_user_view.person.id;
let community_view = CommunityView::read(
- context.pool(),
+ &mut context.pool(),
community_id,
Some(person_id),
Some(is_mod_or_admin),
)
.await?;
- let discussion_languages = CommunityLanguage::read(context.pool(), community_id).await?;
+ let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?;
Ok(CommunityResponse {
community_view,
person_id: PersonId,
post_id: PostId,
) -> Result<PostResponse, LemmyError> {
- let is_mod_or_admin = is_mod_or_admin(context.pool(), person_id, community_id)
+ let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), person_id, community_id)
.await
.is_ok();
let post_view = PostView::read(
- context.pool(),
+ &mut context.pool(),
post_id,
Some(person_id),
Some(is_mod_or_admin),
.filter(|m| m.is_local(&context.settings().hostname) && m.name.ne(&person.name))
{
let mention_name = mention.name.clone();
- let user_view = LocalUserView::read_from_name(context.pool(), &mention_name).await;
+ let user_view = LocalUserView::read_from_name(&mut context.pool(), &mention_name).await;
if let Ok(mention_user_view) = user_view {
// TODO
// At some point, make it so you can't tag the parent creator either
// Allow this to fail softly, since comment edits might re-update or replace it
// Let the uniqueness handle this fail
- PersonMention::create(context.pool(), &user_mention_form)
+ PersonMention::create(&mut context.pool(), &user_mention_form)
.await
.ok();
// Send comment_reply to the parent commenter / poster
if let Some(parent_comment_id) = comment.parent_comment_id() {
- let parent_comment = Comment::read(context.pool(), parent_comment_id).await?;
+ let parent_comment = Comment::read(&mut context.pool(), parent_comment_id).await?;
// Get the parent commenter local_user
let parent_creator_id = parent_comment.creator_id;
// Only add to recipients if that person isn't blocked
- let creator_blocked = check_person_block(person.id, parent_creator_id, context.pool())
+ let creator_blocked = check_person_block(person.id, parent_creator_id, &mut context.pool())
.await
.is_err();
// Don't send a notif to yourself
if parent_comment.creator_id != person.id && !creator_blocked {
- let user_view = LocalUserView::read_person(context.pool(), parent_creator_id).await;
+ let user_view = LocalUserView::read_person(&mut context.pool(), parent_creator_id).await;
if let Ok(parent_user_view) = user_view {
recipient_ids.push(parent_user_view.local_user.id);
// Allow this to fail softly, since comment edits might re-update or replace it
// Let the uniqueness handle this fail
- CommentReply::create(context.pool(), &comment_reply_form)
+ CommentReply::create(&mut context.pool(), &comment_reply_form)
.await
.ok();
} else {
// If there's no parent, its the post creator
// Only add to recipients if that person isn't blocked
- let creator_blocked = check_person_block(person.id, post.creator_id, context.pool())
+ let creator_blocked = check_person_block(person.id, post.creator_id, &mut context.pool())
.await
.is_err();
if post.creator_id != person.id && !creator_blocked {
let creator_id = post.creator_id;
- let parent_user = LocalUserView::read_person(context.pool(), creator_id).await;
+ let parent_user = LocalUserView::read_person(&mut context.pool(), creator_id).await;
if let Ok(parent_user_view) = parent_user {
recipient_ids.push(parent_user_view.local_user.id);
// Allow this to fail softly, since comment edits might re-update or replace it
// Let the uniqueness handle this fail
- CommentReply::create(context.pool(), &comment_reply_form)
+ CommentReply::create(&mut context.pool(), &comment_reply_form)
.await
.ok();
-use lemmy_db_schema::{source::secret::Secret, utils::DbPool};
+use lemmy_db_schema::{
+ source::secret::Secret,
+ utils::{ActualDbPool, DbPool},
+};
use lemmy_utils::{
rate_limit::RateLimitCell,
settings::{structs::Settings, SETTINGS},
#[derive(Clone)]
pub struct LemmyContext {
- pool: DbPool,
+ pool: ActualDbPool,
client: Arc<ClientWithMiddleware>,
secret: Arc<Secret>,
rate_limit_cell: RateLimitCell,
impl LemmyContext {
pub fn create(
- pool: DbPool,
+ pool: ActualDbPool,
client: ClientWithMiddleware,
secret: Secret,
rate_limit_cell: RateLimitCell,
rate_limit_cell,
}
}
- pub fn pool(&self) -> &DbPool {
+ pub fn pool(&self) -> DbPool<'_> {
+ DbPool::Pool(&self.pool)
+ }
+ pub fn inner_pool(&self) -> &ActualDbPool {
&self.pool
}
pub fn client(&self) -> &ClientWithMiddleware {
};
use anyhow::Context;
use chrono::NaiveDateTime;
-use futures::try_join;
use lemmy_db_schema::{
impls::person::is_banned,
newtypes::{CommunityId, DbUrl, LocalUserId, PersonId, PostId},
#[tracing::instrument(skip_all)]
pub async fn is_mod_or_admin(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
person_id: PersonId,
community_id: CommunityId,
) -> Result<(), LemmyError> {
#[tracing::instrument(skip_all)]
pub async fn is_mod_or_admin_opt(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
local_user_view: Option<&LocalUserView>,
community_id: Option<CommunityId>,
) -> Result<(), LemmyError> {
}
#[tracing::instrument(skip_all)]
-pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError> {
+pub async fn get_post(post_id: PostId, pool: &mut DbPool<'_>) -> Result<Post, LemmyError> {
Post::read(pool, post_id)
.await
.with_lemmy_type(LemmyErrorType::CouldntFindPost)
pub async fn mark_post_as_read(
person_id: PersonId,
post_id: PostId,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
) -> Result<PostRead, LemmyError> {
let post_read_form = PostReadForm { post_id, person_id };
pub async fn mark_post_as_unread(
person_id: PersonId,
post_id: PostId,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
) -> Result<usize, LemmyError> {
let post_read_form = PostReadForm { post_id, person_id };
.with_lemmy_type(LemmyErrorType::NotLoggedIn)?
.claims;
let local_user_id = LocalUserId(claims.sub);
- let local_user_view = LocalUserView::read(context.pool(), local_user_id).await?;
+ let local_user_view = LocalUserView::read(&mut context.pool(), local_user_id).await?;
check_user_valid(
local_user_view.person.banned,
local_user_view.person.ban_expires,
pub async fn check_community_ban(
person_id: PersonId,
community_id: CommunityId,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
) -> Result<(), LemmyError> {
let is_banned = CommunityPersonBanView::get(pool, person_id, community_id)
.await
#[tracing::instrument(skip_all)]
pub async fn check_community_deleted_or_removed(
community_id: CommunityId,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
) -> Result<(), LemmyError> {
let community = Community::read(pool, community_id)
.await
pub async fn check_person_block(
my_id: PersonId,
potential_blocker_id: PersonId,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
) -> Result<(), LemmyError> {
let is_blocked = PersonBlock::read(pool, potential_blocker_id, my_id)
.await
#[tracing::instrument(skip_all)]
pub async fn build_federated_instances(
local_site: &LocalSite,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
) -> Result<Option<FederatedInstances>, LemmyError> {
if local_site.federation_enabled {
// TODO I hate that this requires 3 queries
- let (linked, allowed, blocked) = try_join!(
- Instance::linked(pool),
- Instance::allowlist(pool),
- Instance::blocklist(pool)
- )?;
+ let (linked, allowed, blocked) = lemmy_db_schema::try_join_with_pool!(pool => (
+ Instance::linked,
+ Instance::allowlist,
+ Instance::blocklist
+ ))?;
Ok(Some(FederatedInstances {
linked,
pub async fn send_password_reset_email(
user: &LocalUserView,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
settings: &Settings,
) -> Result<(), LemmyError> {
// Generate a random token
pub async fn send_verification_email(
user: &LocalUserView,
new_email: &str,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
settings: &Settings,
) -> Result<(), LemmyError> {
let form = EmailVerificationForm {
/// Send a new applicant email notification to all admins
pub async fn send_new_applicant_email_to_admins(
applicant_username: &str,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
settings: &Settings,
) -> Result<(), LemmyError> {
// Collect the admins with emails
pub async fn send_new_report_email_to_admins(
reporter_username: &str,
reported_username: &str,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
settings: &Settings,
) -> Result<(), LemmyError> {
// Collect the admins with emails
pub async fn check_registration_application(
local_user_view: &LocalUserView,
local_site: &LocalSite,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
) -> Result<(), LemmyError> {
if (local_site.registration_mode == RegistrationMode::RequireApplication
|| local_site.registration_mode == RegistrationMode::Closed)
pub async fn purge_image_posts_for_person(
banned_person_id: PersonId,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
settings: &Settings,
client: &ClientWithMiddleware,
) -> Result<(), LemmyError> {
pub async fn purge_image_posts_for_community(
banned_community_id: CommunityId,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
settings: &Settings,
client: &ClientWithMiddleware,
) -> Result<(), LemmyError> {
pub async fn remove_user_data(
banned_person_id: PersonId,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
settings: &Settings,
client: &ClientWithMiddleware,
) -> Result<(), LemmyError> {
pub async fn remove_user_data_in_community(
community_id: CommunityId,
banned_person_id: PersonId,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
) -> Result<(), LemmyError> {
// Posts
Post::update_removed_for_creator(pool, banned_person_id, Some(community_id), true).await?;
pub async fn delete_user_account(
person_id: PersonId,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
settings: &Settings,
client: &ClientWithMiddleware,
) -> Result<(), LemmyError> {
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
let data: &CreateComment = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
let content_slurs_removed = remove_slurs(
&data.content.clone(),
// Check for a community ban
let post_id = data.post_id;
- let post = get_post(post_id, context.pool()).await?;
+ let post = get_post(post_id, &mut context.pool()).await?;
let community_id = post.community_id;
- check_community_ban(local_user_view.person.id, community_id, context.pool()).await?;
- check_community_deleted_or_removed(community_id, context.pool()).await?;
+ check_community_ban(local_user_view.person.id, community_id, &mut context.pool()).await?;
+ check_community_deleted_or_removed(community_id, &mut context.pool()).await?;
check_post_deleted_or_removed(&post)?;
// Check if post is locked, no new comments
// Fetch the parent, if it exists
let parent_opt = if let Some(parent_id) = data.parent_id {
- Comment::read(context.pool(), parent_id).await.ok()
+ Comment::read(&mut context.pool(), parent_id).await.ok()
} else {
None
};
let language_id = data.language_id.unwrap_or(parent_language);
CommunityLanguage::is_allowed_community_language(
- context.pool(),
+ &mut context.pool(),
Some(language_id),
community_id,
)
// Create the comment
let parent_path = parent_opt.clone().map(|t| t.path);
- let inserted_comment = Comment::create(context.pool(), &comment_form, parent_path.as_ref())
- .await
- .with_lemmy_type(LemmyErrorType::CouldntCreateComment)?;
+ let inserted_comment =
+ Comment::create(&mut context.pool(), &comment_form, parent_path.as_ref())
+ .await
+ .with_lemmy_type(LemmyErrorType::CouldntCreateComment)?;
// Necessary to update the ap_id
let inserted_comment_id = inserted_comment.id;
&protocol_and_hostname,
)?;
let updated_comment = Comment::update(
- context.pool(),
+ &mut context.pool(),
inserted_comment_id,
&CommentUpdateForm::builder().ap_id(Some(apub_id)).build(),
)
score: 1,
};
- CommentLike::like(context.pool(), &like_form)
+ CommentLike::like(&mut context.pool(), &like_form)
.await
.with_lemmy_type(LemmyErrorType::CouldntLikeComment)?;
// If its a reply, mark the parent as read
if let Some(parent) = parent_opt {
let parent_id = parent.id;
- let comment_reply = CommentReply::read_by_comment(context.pool(), parent_id).await;
+ let comment_reply = CommentReply::read_by_comment(&mut context.pool(), parent_id).await;
if let Ok(reply) = comment_reply {
CommentReply::update(
- context.pool(),
+ &mut context.pool(),
reply.id,
&CommentReplyUpdateForm { read: Some(true) },
)
// If the parent has PersonMentions mark them as read too
let person_id = local_user_view.person.id;
let person_mention =
- PersonMention::read_by_comment_and_person(context.pool(), parent_id, person_id).await;
+ PersonMention::read_by_comment_and_person(&mut context.pool(), parent_id, person_id).await;
if let Ok(mention) = person_mention {
PersonMention::update(
- context.pool(),
+ &mut context.pool(),
mention.id,
&PersonMentionUpdateForm { read: Some(true) },
)
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
let comment_id = data.comment_id;
- let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
+ let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
// Dont delete it if its already been deleted.
if orig_comment.comment.deleted == data.deleted {
check_community_ban(
local_user_view.person.id,
orig_comment.community.id,
- context.pool(),
+ &mut context.pool(),
)
.await?;
// Do the delete
let deleted = data.deleted;
let updated_comment = Comment::update(
- context.pool(),
+ &mut context.pool(),
comment_id,
&CommentUpdateForm::builder().deleted(Some(deleted)).build(),
)
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
let post_id = updated_comment.post_id;
- let post = Post::read(context.pool(), post_id).await?;
+ let post = Post::read(&mut context.pool(), post_id).await?;
let recipient_ids = send_local_notifs(
vec![],
&updated_comment,
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
let data = self;
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
check_private_instance(&local_user_view, &local_site)?;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
let comment_id = data.comment_id;
- let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
+ let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
check_community_ban(
local_user_view.person.id,
orig_comment.community.id,
- context.pool(),
+ &mut context.pool(),
)
.await?;
// Verify that only a mod or admin can remove
is_mod_or_admin(
- context.pool(),
+ &mut context.pool(),
local_user_view.person.id,
orig_comment.community.id,
)
// Do the remove
let removed = data.removed;
let updated_comment = Comment::update(
- context.pool(),
+ &mut context.pool(),
comment_id,
&CommentUpdateForm::builder().removed(Some(removed)).build(),
)
removed: Some(removed),
reason: data.reason.clone(),
};
- ModRemoveComment::create(context.pool(), &form).await?;
+ ModRemoveComment::create(&mut context.pool(), &form).await?;
let post_id = updated_comment.post_id;
- let post = Post::read(context.pool(), post_id).await?;
+ let post = Post::read(&mut context.pool(), post_id).await?;
let recipient_ids = send_local_notifs(
vec![],
&updated_comment,
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
let data: &EditComment = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
let comment_id = data.comment_id;
- let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
+ let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
check_community_ban(
local_user_view.person.id,
orig_comment.community.id,
- context.pool(),
+ &mut context.pool(),
)
.await?;
let language_id = self.language_id;
CommunityLanguage::is_allowed_community_language(
- context.pool(),
+ &mut context.pool(),
language_id,
orig_comment.community.id,
)
.language_id(data.language_id)
.updated(Some(Some(naive_now())))
.build();
- let updated_comment = Comment::update(context.pool(), comment_id, &form)
+ let updated_comment = Comment::update(&mut context.pool(), comment_id, &form)
.await
.with_lemmy_type(LemmyErrorType::CouldntUpdateComment)?;
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
let data: &CreateCommunity = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let site_view = SiteView::read_local(context.pool()).await?;
+ let site_view = SiteView::read_local(&mut context.pool()).await?;
let local_site = site_view.local_site;
if local_site.community_creation_admin_only && is_admin(&local_user_view).is_err() {
&data.name,
&context.settings().get_protocol_and_hostname(),
)?;
- let community_dupe = Community::read_from_apub_id(context.pool(), &community_actor_id).await?;
+ let community_dupe =
+ Community::read_from_apub_id(&mut context.pool(), &community_actor_id).await?;
if community_dupe.is_some() {
return Err(LemmyErrorType::CommunityAlreadyExists)?;
}
.instance_id(site_view.site.instance_id)
.build();
- let inserted_community = Community::create(context.pool(), &community_form)
+ let inserted_community = Community::create(&mut context.pool(), &community_form)
.await
.with_lemmy_type(LemmyErrorType::CommunityAlreadyExists)?;
person_id: local_user_view.person.id,
};
- CommunityModerator::join(context.pool(), &community_moderator_form)
+ CommunityModerator::join(&mut context.pool(), &community_moderator_form)
.await
.with_lemmy_type(LemmyErrorType::CommunityModeratorAlreadyExists)?;
pending: false,
};
- CommunityFollower::follow(context.pool(), &community_follower_form)
+ CommunityFollower::follow(&mut context.pool(), &community_follower_form)
.await
.with_lemmy_type(LemmyErrorType::CommunityFollowerAlreadyExists)?;
// Update the discussion_languages if that's provided
let community_id = inserted_community.id;
if let Some(languages) = data.discussion_languages.clone() {
- let site_languages = SiteLanguage::read_local_raw(context.pool()).await?;
+ let site_languages = SiteLanguage::read_local_raw(&mut context.pool()).await?;
// check that community languages are a subset of site languages
// https://stackoverflow.com/a/64227550
let is_subset = languages.iter().all(|item| site_languages.contains(item));
if !is_subset {
return Err(LemmyErrorType::LanguageNotAllowed)?;
}
- CommunityLanguage::update(context.pool(), languages, community_id).await?;
+ CommunityLanguage::update(&mut context.pool(), languages, community_id).await?;
}
build_community_response(context, local_user_view, community_id).await
// Fetch the community mods
let community_id = data.community_id;
let community_mods =
- CommunityModeratorView::for_community(context.pool(), community_id).await?;
+ CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
// Make sure deleter is the top mod
is_top_mod(&local_user_view, &community_mods)?;
let community_id = data.community_id;
let deleted = data.deleted;
Community::update(
- context.pool(),
+ &mut context.pool(),
community_id,
&CommunityUpdateForm::builder()
.deleted(Some(deleted))
) -> Result<ListCommunitiesResponse, LemmyError> {
let data: &ListCommunities = self;
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
check_private_instance(&local_user_view, &local_site)?;
let limit = data.limit;
let local_user = local_user_view.map(|l| l.local_user);
let communities = CommunityQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.listing_type(listing_type)
.show_nsfw(show_nsfw)
.sort(sort)
let community_id = data.community_id;
let removed = data.removed;
Community::update(
- context.pool(),
+ &mut context.pool(),
community_id,
&CommunityUpdateForm::builder()
.removed(Some(removed))
reason: data.reason.clone(),
expires,
};
- ModRemoveCommunity::create(context.pool(), &form).await?;
+ ModRemoveCommunity::create(&mut context.pool(), &form).await?;
build_community_response(context, local_user_view, community_id).await
}
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
let data: &EditCommunity = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
let icon = diesel_option_overwrite_to_url(&data.icon)?;
let banner = diesel_option_overwrite_to_url(&data.banner)?;
// Verify its a mod (only mods can edit it)
let community_id = data.community_id;
- let mods: Vec<PersonId> = CommunityModeratorView::for_community(context.pool(), community_id)
- .await
- .map(|v| v.into_iter().map(|m| m.moderator.id).collect())?;
+ let mods: Vec<PersonId> =
+ CommunityModeratorView::for_community(&mut context.pool(), community_id)
+ .await
+ .map(|v| v.into_iter().map(|m| m.moderator.id).collect())?;
if !mods.contains(&local_user_view.person.id) {
return Err(LemmyErrorType::NotAModerator)?;
}
let community_id = data.community_id;
if let Some(languages) = data.discussion_languages.clone() {
- let site_languages = SiteLanguage::read_local_raw(context.pool()).await?;
+ let site_languages = SiteLanguage::read_local_raw(&mut context.pool()).await?;
// check that community languages are a subset of site languages
// https://stackoverflow.com/a/64227550
let is_subset = languages.iter().all(|item| site_languages.contains(item));
if !is_subset {
return Err(LemmyErrorType::LanguageNotAllowed)?;
}
- CommunityLanguage::update(context.pool(), languages, community_id).await?;
+ CommunityLanguage::update(&mut context.pool(), languages, community_id).await?;
}
let community_form = CommunityUpdateForm::builder()
.build();
let community_id = data.community_id;
- Community::update(context.pool(), community_id, &community_form)
+ Community::update(&mut context.pool(), community_id, &community_form)
.await
.with_lemmy_type(LemmyErrorType::CouldntUpdateCommunity)?;
let data: &CreateCustomEmoji = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
// Make sure user is an admin
is_admin(&local_user_view)?;
.category(data.category.to_string())
.image_url(data.clone().image_url.into())
.build();
- let emoji = CustomEmoji::create(context.pool(), &emoji_form).await?;
+ let emoji = CustomEmoji::create(&mut context.pool(), &emoji_form).await?;
let mut keywords = vec![];
for keyword in &data.keywords {
let keyword_form = CustomEmojiKeywordInsertForm::builder()
.build();
keywords.push(keyword_form);
}
- CustomEmojiKeyword::create(context.pool(), keywords).await?;
- let view = CustomEmojiView::get(context.pool(), emoji.id).await?;
+ CustomEmojiKeyword::create(&mut context.pool(), keywords).await?;
+ let view = CustomEmojiView::get(&mut context.pool(), emoji.id).await?;
Ok(CustomEmojiResponse { custom_emoji: view })
}
}
// Make sure user is an admin
is_admin(&local_user_view)?;
- CustomEmoji::delete(context.pool(), data.id).await?;
+ CustomEmoji::delete(&mut context.pool(), data.id).await?;
Ok(DeleteCustomEmojiResponse {
id: data.id,
success: true,
let data: &EditCustomEmoji = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
// Make sure user is an admin
is_admin(&local_user_view)?;
.category(data.category.to_string())
.image_url(data.clone().image_url.into())
.build();
- let emoji = CustomEmoji::update(context.pool(), data.id, &emoji_form).await?;
- CustomEmojiKeyword::delete(context.pool(), data.id).await?;
+ let emoji = CustomEmoji::update(&mut context.pool(), data.id, &emoji_form).await?;
+ CustomEmojiKeyword::delete(&mut context.pool(), data.id).await?;
let mut keywords = vec![];
for keyword in &data.keywords {
let keyword_form = CustomEmojiKeywordInsertForm::builder()
.build();
keywords.push(keyword_form);
}
- CustomEmojiKeyword::create(context.pool(), keywords).await?;
- let view = CustomEmojiView::get(context.pool(), emoji.id).await?;
+ CustomEmojiKeyword::create(&mut context.pool(), keywords).await?;
+ let view = CustomEmojiView::get(&mut context.pool(), emoji.id).await?;
Ok(CustomEmojiResponse { custom_emoji: view })
}
}
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
let data: &CreatePost = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
let slur_regex = local_site_to_slur_regex(&local_site);
check_slurs(&data.name, &slur_regex)?;
is_valid_body_field(&data.body, true)?;
check_url_scheme(&data.url)?;
- check_community_ban(local_user_view.person.id, data.community_id, context.pool()).await?;
- check_community_deleted_or_removed(data.community_id, context.pool()).await?;
+ check_community_ban(
+ local_user_view.person.id,
+ data.community_id,
+ &mut context.pool(),
+ )
+ .await?;
+ check_community_deleted_or_removed(data.community_id, &mut context.pool()).await?;
let community_id = data.community_id;
- let community = Community::read(context.pool(), community_id).await?;
+ let community = Community::read(&mut context.pool(), community_id).await?;
if community.posting_restricted_to_mods {
let community_id = data.community_id;
let is_mod = CommunityView::is_mod_or_admin(
- context.pool(),
+ &mut context.pool(),
local_user_view.local_user.person_id,
community_id,
)
let language_id = match data.language_id {
Some(lid) => Some(lid),
None => {
- default_post_language(context.pool(), community_id, local_user_view.local_user.id).await?
+ default_post_language(
+ &mut context.pool(),
+ community_id,
+ local_user_view.local_user.id,
+ )
+ .await?
}
};
- CommunityLanguage::is_allowed_community_language(context.pool(), language_id, community_id)
- .await?;
+ CommunityLanguage::is_allowed_community_language(
+ &mut context.pool(),
+ language_id,
+ community_id,
+ )
+ .await?;
let post_form = PostInsertForm::builder()
.name(data.name.trim().to_owned())
.thumbnail_url(thumbnail_url)
.build();
- let inserted_post = Post::create(context.pool(), &post_form)
+ let inserted_post = Post::create(&mut context.pool(), &post_form)
.await
.with_lemmy_type(LemmyErrorType::CouldntCreatePost)?;
&protocol_and_hostname,
)?;
let updated_post = Post::update(
- context.pool(),
+ &mut context.pool(),
inserted_post_id,
&PostUpdateForm::builder().ap_id(Some(apub_id)).build(),
)
score: 1,
};
- PostLike::like(context.pool(), &like_form)
+ PostLike::like(&mut context.pool(), &like_form)
.await
.with_lemmy_type(LemmyErrorType::CouldntLikePost)?;
// Mark the post as read
- mark_post_as_read(person_id, post_id, context.pool()).await?;
+ mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
if let Some(url) = updated_post.url.clone() {
let task = async move {
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
let post_id = data.post_id;
- let orig_post = Post::read(context.pool(), post_id).await?;
+ let orig_post = Post::read(&mut context.pool(), post_id).await?;
// Dont delete it if its already been deleted.
if orig_post.deleted == data.deleted {
check_community_ban(
local_user_view.person.id,
orig_post.community_id,
- context.pool(),
+ &mut context.pool(),
)
.await?;
- check_community_deleted_or_removed(orig_post.community_id, context.pool()).await?;
+ check_community_deleted_or_removed(orig_post.community_id, &mut context.pool()).await?;
// Verify that only the creator can delete
if !Post::is_post_creator(local_user_view.person.id, orig_post.creator_id) {
let post_id = data.post_id;
let deleted = data.deleted;
Post::update(
- context.pool(),
+ &mut context.pool(),
post_id,
&PostUpdateForm::builder().deleted(Some(deleted)).build(),
)
async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetPostResponse, LemmyError> {
let data: &GetPost = self;
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
check_private_instance(&local_user_view, &local_site)?;
let post_id = if let Some(id) = data.id {
id
} else if let Some(comment_id) = data.comment_id {
- Comment::read(context.pool(), comment_id)
+ Comment::read(&mut context.pool(), comment_id)
.await
.with_lemmy_type(LemmyErrorType::CouldntFindPost)?
.post_id
};
// Check to see if the person is a mod or admin, to show deleted / removed
- let community_id = Post::read(context.pool(), post_id).await?.community_id;
- let is_mod_or_admin =
- is_mod_or_admin_opt(context.pool(), local_user_view.as_ref(), Some(community_id))
- .await
- .is_ok();
+ let community_id = Post::read(&mut context.pool(), post_id).await?.community_id;
+ let is_mod_or_admin = is_mod_or_admin_opt(
+ &mut context.pool(),
+ local_user_view.as_ref(),
+ Some(community_id),
+ )
+ .await
+ .is_ok();
- let post_view = PostView::read(context.pool(), post_id, person_id, Some(is_mod_or_admin))
- .await
- .with_lemmy_type(LemmyErrorType::CouldntFindPost)?;
+ let post_view = PostView::read(
+ &mut context.pool(),
+ post_id,
+ person_id,
+ Some(is_mod_or_admin),
+ )
+ .await
+ .with_lemmy_type(LemmyErrorType::CouldntFindPost)?;
// Mark the post as read
let post_id = post_view.post.id;
if let Some(person_id) = person_id {
- mark_post_as_read(person_id, post_id, context.pool()).await?;
+ mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
}
// Necessary for the sidebar subscribed
let community_view = CommunityView::read(
- context.pool(),
+ &mut context.pool(),
community_id,
person_id,
Some(is_mod_or_admin),
read_comments,
..PersonPostAggregatesForm::default()
};
- PersonPostAggregates::upsert(context.pool(), &person_post_agg_form)
+ PersonPostAggregates::upsert(&mut context.pool(), &person_post_agg_form)
.await
.with_lemmy_type(LemmyErrorType::CouldntFindPost)?;
}
- let moderators = CommunityModeratorView::for_community(context.pool(), community_id).await?;
+ let moderators =
+ CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
// Fetch the cross_posts
let cross_posts = if let Some(url) = &post_view.post.url {
let mut x_posts = PostQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.url_search(Some(url.inner().as_str().into()))
.build()
.list()
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
let post_id = data.post_id;
- let orig_post = Post::read(context.pool(), post_id).await?;
+ let orig_post = Post::read(&mut context.pool(), post_id).await?;
check_community_ban(
local_user_view.person.id,
orig_post.community_id,
- context.pool(),
+ &mut context.pool(),
)
.await?;
// Verify that only the mods can remove
is_mod_or_admin(
- context.pool(),
+ &mut context.pool(),
local_user_view.person.id,
orig_post.community_id,
)
let post_id = data.post_id;
let removed = data.removed;
Post::update(
- context.pool(),
+ &mut context.pool(),
post_id,
&PostUpdateForm::builder().removed(Some(removed)).build(),
)
removed: Some(removed),
reason: data.reason.clone(),
};
- ModRemovePost::create(context.pool(), &form).await?;
+ ModRemovePost::create(&mut context.pool(), &form).await?;
build_post_response(
context,
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
let data: &EditPost = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
let data_url = data.url.as_ref();
check_url_scheme(&data.url)?;
let post_id = data.post_id;
- let orig_post = Post::read(context.pool(), post_id).await?;
+ let orig_post = Post::read(&mut context.pool(), post_id).await?;
check_community_ban(
local_user_view.person.id,
orig_post.community_id,
- context.pool(),
+ &mut context.pool(),
)
.await?;
let language_id = self.language_id;
CommunityLanguage::is_allowed_community_language(
- context.pool(),
+ &mut context.pool(),
language_id,
orig_post.community_id,
)
.build();
let post_id = data.post_id;
- Post::update(context.pool(), post_id, &post_form)
+ Post::update(&mut context.pool(), post_id, &post_form)
.await
.with_lemmy_type(LemmyErrorType::CouldntUpdatePost)?;
) -> Result<PrivateMessageResponse, LemmyError> {
let data: &CreatePrivateMessage = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
let content_slurs_removed = remove_slurs(
&data.content.clone(),
);
is_valid_body_field(&Some(content_slurs_removed.clone()), false)?;
- check_person_block(local_user_view.person.id, data.recipient_id, context.pool()).await?;
+ check_person_block(
+ local_user_view.person.id,
+ data.recipient_id,
+ &mut context.pool(),
+ )
+ .await?;
let private_message_form = PrivateMessageInsertForm::builder()
.content(content_slurs_removed.clone())
.recipient_id(data.recipient_id)
.build();
- let inserted_private_message = PrivateMessage::create(context.pool(), &private_message_form)
- .await
- .with_lemmy_type(LemmyErrorType::CouldntCreatePrivateMessage)?;
+ let inserted_private_message =
+ PrivateMessage::create(&mut context.pool(), &private_message_form)
+ .await
+ .with_lemmy_type(LemmyErrorType::CouldntCreatePrivateMessage)?;
let inserted_private_message_id = inserted_private_message.id;
let protocol_and_hostname = context.settings().get_protocol_and_hostname();
&protocol_and_hostname,
)?;
PrivateMessage::update(
- context.pool(),
+ &mut context.pool(),
inserted_private_message.id,
&PrivateMessageUpdateForm::builder()
.ap_id(Some(apub_id))
.await
.with_lemmy_type(LemmyErrorType::CouldntCreatePrivateMessage)?;
- let view = PrivateMessageView::read(context.pool(), inserted_private_message.id).await?;
+ let view = PrivateMessageView::read(&mut context.pool(), inserted_private_message.id).await?;
// Send email to the local recipient, if one exists
if view.recipient.local {
let recipient_id = data.recipient_id;
- let local_recipient = LocalUserView::read_person(context.pool(), recipient_id).await?;
+ let local_recipient = LocalUserView::read_person(&mut context.pool(), recipient_id).await?;
let lang = get_interface_language(&local_recipient);
let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname());
let sender_name = &local_user_view.person.name;
// Checking permissions
let private_message_id = data.private_message_id;
- let orig_private_message = PrivateMessage::read(context.pool(), private_message_id).await?;
+ let orig_private_message =
+ PrivateMessage::read(&mut context.pool(), private_message_id).await?;
if local_user_view.person.id != orig_private_message.creator_id {
return Err(LemmyErrorType::EditPrivateMessageNotAllowed)?;
}
let private_message_id = data.private_message_id;
let deleted = data.deleted;
PrivateMessage::update(
- context.pool(),
+ &mut context.pool(),
private_message_id,
&PrivateMessageUpdateForm::builder()
.deleted(Some(deleted))
.await
.with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?;
- let view = PrivateMessageView::read(context.pool(), private_message_id).await?;
+ let view = PrivateMessageView::read(&mut context.pool(), private_message_id).await?;
Ok(PrivateMessageResponse {
private_message_view: view,
})
let limit = data.limit;
let unread_only = data.unread_only;
let mut messages = PrivateMessageQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.recipient_id(person_id)
.page(page)
.limit(limit)
) -> Result<PrivateMessageResponse, LemmyError> {
let data: &EditPrivateMessage = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
// Checking permissions
let private_message_id = data.private_message_id;
- let orig_private_message = PrivateMessage::read(context.pool(), private_message_id).await?;
+ let orig_private_message =
+ PrivateMessage::read(&mut context.pool(), private_message_id).await?;
if local_user_view.person.id != orig_private_message.creator_id {
return Err(LemmyErrorType::EditPrivateMessageNotAllowed)?;
}
let private_message_id = data.private_message_id;
PrivateMessage::update(
- context.pool(),
+ &mut context.pool(),
private_message_id,
&PrivateMessageUpdateForm::builder()
.content(Some(content_slurs_removed))
.await
.with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?;
- let view = PrivateMessageView::read(context.pool(), private_message_id).await?;
+ let view = PrivateMessageView::read(&mut context.pool(), private_message_id).await?;
Ok(PrivateMessageResponse {
private_message_view: view,
async fn perform(&self, context: &Data<LemmyContext>) -> Result<SiteResponse, LemmyError> {
let data: &CreateSite = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
// Make sure user is an admin; other types of users should not create site data...
is_admin(&local_user_view)?;
let site_id = local_site.site_id;
- Site::update(context.pool(), site_id, &site_form).await?;
+ Site::update(&mut context.pool(), site_id, &site_form).await?;
let local_site_form = LocalSiteUpdateForm::builder()
// Set the site setup to true
.captcha_difficulty(data.captcha_difficulty.clone())
.build();
- LocalSite::update(context.pool(), &local_site_form).await?;
+ LocalSite::update(&mut context.pool(), &local_site_form).await?;
let local_site_rate_limit_form = LocalSiteRateLimitUpdateForm::builder()
.message(data.rate_limit_message)
.search_per_second(data.rate_limit_search_per_second)
.build();
- LocalSiteRateLimit::update(context.pool(), &local_site_rate_limit_form).await?;
+ LocalSiteRateLimit::update(&mut context.pool(), &local_site_rate_limit_form).await?;
- let site_view = SiteView::read_local(context.pool()).await?;
+ let site_view = SiteView::read_local(&mut context.pool()).await?;
let new_taglines = data.taglines.clone();
- let taglines = Tagline::replace(context.pool(), local_site.id, new_taglines).await?;
+ let taglines = Tagline::replace(&mut context.pool(), local_site.id, new_taglines).await?;
let rate_limit_config =
local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);
async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetSiteResponse, LemmyError> {
let data: &GetSite = self;
- let site_view = SiteView::read_local(context.pool()).await?;
+ let site_view = SiteView::read_local(&mut context.pool()).await?;
- let admins = PersonView::admins(context.pool()).await?;
+ let admins = PersonView::admins(&mut context.pool()).await?;
// Build the local user
let my_user = if let Some(local_user_view) =
let person_id = local_user_view.person.id;
let local_user_id = local_user_view.local_user.id;
- let follows = CommunityFollowerView::for_person(context.pool(), person_id)
+ let follows = CommunityFollowerView::for_person(&mut context.pool(), person_id)
.await
.with_lemmy_type(LemmyErrorType::SystemErrLogin)?;
let person_id = local_user_view.person.id;
- let community_blocks = CommunityBlockView::for_person(context.pool(), person_id)
+ let community_blocks = CommunityBlockView::for_person(&mut context.pool(), person_id)
.await
.with_lemmy_type(LemmyErrorType::SystemErrLogin)?;
let person_id = local_user_view.person.id;
- let person_blocks = PersonBlockView::for_person(context.pool(), person_id)
+ let person_blocks = PersonBlockView::for_person(&mut context.pool(), person_id)
.await
.with_lemmy_type(LemmyErrorType::SystemErrLogin)?;
- let moderates = CommunityModeratorView::for_person(context.pool(), person_id)
+ let moderates = CommunityModeratorView::for_person(&mut context.pool(), person_id)
.await
.with_lemmy_type(LemmyErrorType::SystemErrLogin)?;
- let discussion_languages = LocalUserLanguage::read(context.pool(), local_user_id)
+ let discussion_languages = LocalUserLanguage::read(&mut context.pool(), local_user_id)
.await
.with_lemmy_type(LemmyErrorType::SystemErrLogin)?;
None
};
- let all_languages = Language::read_all(context.pool()).await?;
- let discussion_languages = SiteLanguage::read_local_raw(context.pool()).await?;
- let taglines = Tagline::get_all(context.pool(), site_view.local_site.id).await?;
- let custom_emojis = CustomEmojiView::get_all(context.pool(), site_view.local_site.id).await?;
+ let all_languages = Language::read_all(&mut context.pool()).await?;
+ let discussion_languages = SiteLanguage::read_local_raw(&mut context.pool()).await?;
+ let taglines = Tagline::get_all(&mut context.pool(), site_view.local_site.id).await?;
+ let custom_emojis =
+ CustomEmojiView::get_all(&mut context.pool(), site_view.local_site.id).await?;
Ok(GetSiteResponse {
site_view,
.ok()?
.claims;
let local_user_id = LocalUserId(claims.sub);
- let local_user_view = LocalUserView::read(context.pool(), local_user_id)
+ let local_user_view = LocalUserView::read(&mut context.pool(), local_user_id)
.await
.ok()?;
check_user_valid(
async fn perform(&self, context: &Data<LemmyContext>) -> Result<SiteResponse, LemmyError> {
let data: &EditSite = self;
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let site_view = SiteView::read_local(context.pool()).await?;
+ let site_view = SiteView::read_local(&mut context.pool()).await?;
let local_site = site_view.local_site;
let site = site_view.site;
validate_update_payload(&local_site, data)?;
if let Some(discussion_languages) = data.discussion_languages.clone() {
- SiteLanguage::update(context.pool(), discussion_languages.clone(), &site).await?;
+ SiteLanguage::update(&mut context.pool(), discussion_languages.clone(), &site).await?;
}
let site_form = SiteUpdateForm::builder()
.updated(Some(Some(naive_now())))
.build();
- Site::update(context.pool(), site.id, &site_form)
+ Site::update(&mut context.pool(), site.id, &site_form)
.await
// Ignore errors for all these, so as to not throw errors if no update occurs
// Diesel will throw an error for empty update forms
.reports_email_admins(data.reports_email_admins)
.build();
- let update_local_site = LocalSite::update(context.pool(), &local_site_form)
+ let update_local_site = LocalSite::update(&mut context.pool(), &local_site_form)
.await
.ok();
.search_per_second(data.rate_limit_search_per_second)
.build();
- LocalSiteRateLimit::update(context.pool(), &local_site_rate_limit_form)
+ LocalSiteRateLimit::update(&mut context.pool(), &local_site_rate_limit_form)
.await
.ok();
// Replace the blocked and allowed instances
let allowed = data.allowed_instances.clone();
- FederationAllowList::replace(context.pool(), allowed).await?;
+ FederationAllowList::replace(&mut context.pool(), allowed).await?;
let blocked = data.blocked_instances.clone();
- FederationBlockList::replace(context.pool(), blocked).await?;
+ FederationBlockList::replace(&mut context.pool(), blocked).await?;
// TODO can't think of a better way to do this.
// If the server suddenly requires email verification, or required applications, no old users
.map(|ols| ols.registration_mode == RegistrationMode::RequireApplication)
.unwrap_or(false);
if !old_require_application && new_require_application {
- LocalUser::set_all_users_registration_applications_accepted(context.pool())
+ LocalUser::set_all_users_registration_applications_accepted(&mut context.pool())
.await
.with_lemmy_type(LemmyErrorType::CouldntSetAllRegistrationsAccepted)?;
}
.map(|ols| ols.require_email_verification)
.unwrap_or(false);
if !local_site.require_email_verification && new_require_email_verification {
- LocalUser::set_all_users_email_verified(context.pool())
+ LocalUser::set_all_users_email_verified(&mut context.pool())
.await
.with_lemmy_type(LemmyErrorType::CouldntSetAllEmailVerified)?;
}
let new_taglines = data.taglines.clone();
- let taglines = Tagline::replace(context.pool(), local_site.id, new_taglines).await?;
+ let taglines = Tagline::replace(&mut context.pool(), local_site.id, new_taglines).await?;
- let site_view = SiteView::read_local(context.pool()).await?;
+ let site_view = SiteView::read_local(&mut context.pool()).await?;
let rate_limit_config =
local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);
async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
let data: &Register = self;
- let site_view = SiteView::read_local(context.pool()).await?;
+ let site_view = SiteView::read_local(&mut context.pool()).await?;
let local_site = site_view.local_site;
let require_registration_application =
local_site.registration_mode == RegistrationMode::RequireApplication;
if let Some(captcha_uuid) = &data.captcha_uuid {
let uuid = uuid::Uuid::parse_str(captcha_uuid)?;
let check = CaptchaAnswer::check_captcha(
- context.pool(),
+ &mut context.pool(),
CheckCaptchaAnswer {
uuid,
answer: data.captcha_answer.clone().unwrap_or_default(),
)?;
if let Some(email) = &data.email {
- if LocalUser::is_email_taken(context.pool(), email).await? {
+ if LocalUser::is_email_taken(&mut context.pool(), email).await? {
return Err(LemmyErrorType::EmailAlreadyExists)?;
}
}
.build();
// insert the person
- let inserted_person = Person::create(context.pool(), &person_form)
+ let inserted_person = Person::create(&mut context.pool(), &person_form)
.await
.with_lemmy_type(LemmyErrorType::UserAlreadyExists)?;
.accepted_application(accepted_application)
.build();
- let inserted_local_user = LocalUser::create(context.pool(), &local_user_form).await?;
+ let inserted_local_user = LocalUser::create(&mut context.pool(), &local_user_form).await?;
if local_site.site_setup && require_registration_application {
// Create the registration application
answer: data.answer.clone().expect("must have an answer"),
};
- RegistrationApplication::create(context.pool(), &form).await?;
+ RegistrationApplication::create(&mut context.pool(), &form).await?;
}
// Email the admins
if local_site.application_email_admins {
- send_new_applicant_email_to_admins(&data.username, context.pool(), context.settings())
+ send_new_applicant_email_to_admins(&data.username, &mut context.pool(), context.settings())
.await?;
}
.clone()
.expect("email was provided");
- send_verification_email(&local_user_view, &email, context.pool(), context.settings())
- .await?;
+ send_verification_email(
+ &local_user_view,
+ &email,
+ &mut context.pool(),
+ context.settings(),
+ )
+ .await?;
login_response.verify_email_sent = true;
}
actor: mod_.id().into(),
to: vec![public()],
object: user.id().into(),
- cc: generate_cc(target, context.pool()).await?,
+ cc: generate_cc(target, &mut context.pool()).await?,
target: target.id(),
kind: BlockType::Block,
remove_data,
match target {
SiteOrCommunity::Site(_) => {
- let inboxes = remote_instance_inboxes(context.pool()).await?;
+ let inboxes = remote_instance_inboxes(&mut context.pool()).await?;
send_lemmy_activity(context, block, mod_, inboxes, false).await
}
SiteOrCommunity::Community(c) => {
match target {
SiteOrCommunity::Site(_site) => {
let blocked_person = Person::update(
- context.pool(),
+ &mut context.pool(),
blocked_person.id,
&PersonUpdateForm::builder()
.banned(Some(true))
if self.remove_data.unwrap_or(false) {
remove_user_data(
blocked_person.id,
- context.pool(),
+ &mut context.pool(),
context.settings(),
context.client(),
)
banned: Some(true),
expires,
};
- ModBan::create(context.pool(), &form).await?;
+ ModBan::create(&mut context.pool(), &form).await?;
}
SiteOrCommunity::Community(community) => {
let community_user_ban_form = CommunityPersonBanForm {
person_id: blocked_person.id,
expires: Some(expires),
};
- CommunityPersonBan::ban(context.pool(), &community_user_ban_form).await?;
+ CommunityPersonBan::ban(&mut context.pool(), &community_user_ban_form).await?;
// Also unsubscribe them from the community, if they are subscribed
let community_follower_form = CommunityFollowerForm {
person_id: blocked_person.id,
pending: false,
};
- CommunityFollower::unfollow(context.pool(), &community_follower_form)
+ CommunityFollower::unfollow(&mut context.pool(), &community_follower_form)
.await
.ok();
if self.remove_data.unwrap_or(false) {
- remove_user_data_in_community(community.id, blocked_person.id, context.pool()).await?;
+ remove_user_data_in_community(community.id, blocked_person.id, &mut context.pool())
+ .await?;
}
// write to mod log
banned: Some(true),
expires,
};
- ModBanFromCommunity::create(context.pool(), &form).await?;
+ ModBanFromCommunity::create(&mut context.pool(), &form).await?;
}
}
}
}
-async fn generate_cc(target: &SiteOrCommunity, pool: &DbPool) -> Result<Vec<Url>, LemmyError> {
+async fn generate_cc(
+ target: &SiteOrCommunity,
+ pool: &mut DbPool<'_>,
+) -> Result<Vec<Url>, LemmyError> {
Ok(match target {
SiteOrCommunity::Site(_) => Site::read_remote_sites(pool)
.await?
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
- let person = Person::read(context.pool(), request.person_id).await?;
- let site = SiteOrCommunity::Site(SiteView::read_local(context.pool()).await?.site.into());
+ let person = Person::read(&mut context.pool(), request.person_id).await?;
+ let site = SiteOrCommunity::Site(SiteView::read_local(&mut context.pool()).await?.site.into());
let expires = request.expires.map(naive_from_unix);
// if the action affects a local user, federate to other instances
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
- let community: ApubCommunity = Community::read(context.pool(), request.community_id)
+ let community: ApubCommunity = Community::read(&mut context.pool(), request.community_id)
.await?
.into();
- let banned_person: ApubPerson = Person::read(context.pool(), request.person_id)
+ let banned_person: ApubPerson = Person::read(&mut context.pool(), request.person_id)
.await?
.into();
let expires = request.expires.map(naive_from_unix);
actor: mod_.id().into(),
to: vec![public()],
object: block,
- cc: generate_cc(target, context.pool()).await?,
+ cc: generate_cc(target, &mut context.pool()).await?,
kind: UndoType::Undo,
id: id.clone(),
audience,
let mut inboxes = vec![user.shared_inbox_or_inbox()];
match target {
SiteOrCommunity::Site(_) => {
- inboxes.append(&mut remote_instance_inboxes(context.pool()).await?);
+ inboxes.append(&mut remote_instance_inboxes(&mut context.pool()).await?);
send_lemmy_activity(context, undo, mod_, inboxes, false).await
}
SiteOrCommunity::Community(c) => {
match self.object.target.dereference(context).await? {
SiteOrCommunity::Site(_site) => {
let blocked_person = Person::update(
- context.pool(),
+ &mut context.pool(),
blocked_person.id,
&PersonUpdateForm::builder()
.banned(Some(false))
banned: Some(false),
expires,
};
- ModBan::create(context.pool(), &form).await?;
+ ModBan::create(&mut context.pool(), &form).await?;
}
SiteOrCommunity::Community(community) => {
let community_user_ban_form = CommunityPersonBanForm {
person_id: blocked_person.id,
expires: None,
};
- CommunityPersonBan::unban(context.pool(), &community_user_ban_form).await?;
+ CommunityPersonBan::unban(&mut context.pool(), &community_user_ban_form).await?;
// write to mod log
let form = ModBanFromCommunityForm {
banned: Some(false),
expires,
};
- ModBanFromCommunity::create(context.pool(), &form).await?;
+ ModBanFromCommunity::create(&mut context.pool(), &form).await?;
}
}
async fn receive(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
insert_activity(&self.id, &self, false, false, context).await?;
let (community, collection_type) =
- Community::get_by_collection_url(context.pool(), &self.target.into()).await?;
+ Community::get_by_collection_url(&mut context.pool(), &self.target.into()).await?;
match collection_type {
CollectionType::Moderators => {
let new_mod = ObjectId::<ApubPerson>::from(self.object)
// been added. Skip it here as it would result in a duplicate key error.
let new_mod_id = new_mod.id;
let moderated_communities =
- CommunityModerator::get_person_moderated_communities(context.pool(), new_mod_id).await?;
+ CommunityModerator::get_person_moderated_communities(&mut context.pool(), new_mod_id)
+ .await?;
if !moderated_communities.contains(&community.id) {
let form = CommunityModeratorForm {
community_id: community.id,
person_id: new_mod.id,
};
- CommunityModerator::join(context.pool(), &form).await?;
+ CommunityModerator::join(&mut context.pool(), &form).await?;
// write mod log
let actor = self.actor.dereference(context).await?;
community_id: community.id,
removed: Some(false),
};
- ModAddCommunity::create(context.pool(), &form).await?;
+ ModAddCommunity::create(&mut context.pool(), &form).await?;
}
// TODO: send websocket notification about added mod
}
let form = PostUpdateForm::builder()
.featured_community(Some(true))
.build();
- Post::update(context.pool(), post.id, &form).await?;
+ Post::update(&mut context.pool(), post.id, &form).await?;
}
}
Ok(())
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
- let community: ApubCommunity = Community::read(context.pool(), request.community_id)
+ let community: ApubCommunity = Community::read(&mut context.pool(), request.community_id)
.await?
.into();
- let updated_mod: ApubPerson = Person::read(context.pool(), request.person_id)
+ let updated_mod: ApubPerson = Person::read(&mut context.pool(), request.person_id)
.await?
.into();
if request.added {
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
- let community = Community::read(context.pool(), response.post_view.community.id)
+ let community = Community::read(&mut context.pool(), response.post_view.community.id)
.await?
.into();
let post = response.post_view.post.clone().into();
async fn receive(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
insert_activity(&self.id, &self, false, false, context).await?;
let (community, collection_type) =
- Community::get_by_collection_url(context.pool(), &self.target.into()).await?;
+ Community::get_by_collection_url(&mut context.pool(), &self.target.into()).await?;
match collection_type {
CollectionType::Moderators => {
let remove_mod = ObjectId::<ApubPerson>::from(self.object)
community_id: community.id,
person_id: remove_mod.id,
};
- CommunityModerator::leave(context.pool(), &form).await?;
+ CommunityModerator::leave(&mut context.pool(), &form).await?;
// write mod log
let actor = self.actor.dereference(context).await?;
community_id: community.id,
removed: Some(true),
};
- ModAddCommunity::create(context.pool(), &form).await?;
+ ModAddCommunity::create(&mut context.pool(), &form).await?;
// TODO: send websocket notification about removed mod
}
let form = PostUpdateForm::builder()
.featured_community(Some(false))
.build();
- Post::update(context.pool(), post.id, &form).await?;
+ Post::update(&mut context.pool(), post.id, &form).await?;
}
}
Ok(())
async fn receive(self, context: &Data<Self::DataType>) -> Result<(), Self::Error> {
let form = PostUpdateForm::builder().locked(Some(true)).build();
let post = self.object.dereference(context).await?;
- Post::update(context.pool(), post.id, &form).await?;
+ Post::update(&mut context.pool(), post.id, &form).await?;
Ok(())
}
}
insert_activity(&self.id, &self, false, false, context).await?;
let form = PostUpdateForm::builder().locked(Some(false)).build();
let post = self.object.object.dereference(context).await?;
- Post::update(context.pool(), post.id, &form).await?;
+ Post::update(&mut context.pool(), post.id, &form).await?;
Ok(())
}
}
};
AnnouncableActivities::UndoLockPost(undo)
};
- let community = Community::read(context.pool(), response.post_view.community.id).await?;
+ let community = Community::read(&mut context.pool(), response.post_view.community.id).await?;
send_activity_in_community(
activity,
&local_user_view.person.into(),
// send to user followers
if !is_mod_action {
inboxes.extend(
- &mut PersonFollower::list_followers(context.pool(), actor.id)
+ &mut PersonFollower::list_followers(&mut context.pool(), actor.id)
.await?
.into_iter()
.map(|p| ApubPerson(p).shared_inbox_or_inbox()),
reason: self.summary,
original_post_body: post.body.clone(),
};
- PostReport::report(context.pool(), &report_form).await?;
+ PostReport::report(&mut context.pool(), &report_form).await?;
}
PostOrComment::Comment(comment) => {
let report_form = CommentReportForm {
original_comment_text: comment.content.clone(),
reason: self.summary,
};
- CommentReport::report(context.pool(), &report_form).await?;
+ CommentReport::report(&mut context.pool(), &report_form).await?;
}
};
Ok(())
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
- let community = Community::read(context.pool(), request.community_id).await?;
+ let community = Community::read(&mut context.pool(), request.community_id).await?;
UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
}
}
let community_update_form = self.object.into_update_form();
- Community::update(context.pool(), community.id, &community_update_form).await?;
+ Community::update(&mut context.pool(), community.id, &community_update_form).await?;
Ok(())
}
}
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
- let community = Community::read(context.pool(), request.community_id).await?;
+ let community = Community::read(&mut context.pool(), request.community_id).await?;
UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
}
}
) -> Result<(), LemmyError> {
// TODO: might be helpful to add a comment method to retrieve community directly
let post_id = comment.post_id;
- let post = Post::read(context.pool(), post_id).await?;
+ let post = Post::read(&mut context.pool(), post_id).await?;
let community_id = post.community_id;
- let person: ApubPerson = Person::read(context.pool(), person_id).await?.into();
- let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
+ let person: ApubPerson = Person::read(&mut context.pool(), person_id).await?.into();
+ let community: ApubCommunity = Community::read(&mut context.pool(), community_id)
+ .await?
+ .into();
let id = generate_activity_id(
kind.clone(),
if distinguished != existing_comment.distinguished {
let creator = self.actor.dereference(context).await?;
let (post, _) = self.object.get_parents(context).await?;
- is_mod_or_admin(context.pool(), creator.id, post.community_id).await?;
+ is_mod_or_admin(&mut context.pool(), creator.id, post.community_id).await?;
}
}
person_id: comment.creator_id,
score: 1,
};
- CommentLike::like(context.pool(), &like_form).await?;
+ CommentLike::like(&mut context.pool(), &like_form).await?;
// Calculate initial hot_rank
- CommentAggregates::update_hot_rank(context.pool(), comment.id).await?;
+ CommentAggregates::update_hot_rank(&mut context.pool(), comment.id).await?;
let do_send_email = self.kind == CreateOrUpdateType::Create;
let post_id = comment.post_id;
- let post = Post::read(context.pool(), post_id).await?;
+ let post = Post::read(&mut context.pool(), post_id).await?;
let actor = self.actor.dereference(context).await?;
// Note:
) -> Result<(), LemmyError> {
let post = ApubPost(post.clone());
let community_id = post.community_id;
- let person: ApubPerson = Person::read(context.pool(), person_id).await?.into();
- let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
+ let person: ApubPerson = Person::read(&mut context.pool(), person_id).await?.into();
+ let community: ApubCommunity = Community::read(&mut context.pool(), community_id)
+ .await?
+ .into();
let create_or_update =
CreateOrUpdatePage::new(post, &person, &community, kind, context).await?;
person_id: post.creator_id,
score: 1,
};
- PostLike::like(context.pool(), &like_form).await?;
+ PostLike::like(&mut context.pool(), &like_form).await?;
// Calculate initial hot_rank for post
- PostAggregates::update_hot_rank(context.pool(), post.id).await?;
+ PostAggregates::update_hot_rank(&mut context.pool(), post.id).await?;
Ok(())
}
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let recipient_id = private_message.recipient_id;
- let sender: ApubPerson = Person::read(context.pool(), sender_id).await?.into();
- let recipient: ApubPerson = Person::read(context.pool(), recipient_id).await?.into();
+ let sender: ApubPerson = Person::read(&mut context.pool(), sender_id).await?.into();
+ let recipient: ApubPerson = Person::read(&mut context.pool(), recipient_id)
+ .await?
+ .into();
let id = generate_activity_id(
kind.clone(),
reason,
expires: None,
};
- ModRemoveCommunity::create(context.pool(), &form).await?;
+ ModRemoveCommunity::create(&mut context.pool(), &form).await?;
Community::update(
- context.pool(),
+ &mut context.pool(),
community.id,
&CommunityUpdateForm::builder().removed(Some(true)).build(),
)
removed: Some(true),
reason,
};
- ModRemovePost::create(context.pool(), &form).await?;
+ ModRemovePost::create(&mut context.pool(), &form).await?;
Post::update(
- context.pool(),
+ &mut context.pool(),
post.id,
&PostUpdateForm::builder().removed(Some(true)).build(),
)
removed: Some(true),
reason,
};
- ModRemoveComment::create(context.pool(), &form).await?;
+ ModRemoveComment::create(&mut context.pool(), &form).await?;
Comment::update(
- context.pool(),
+ &mut context.pool(),
comment.id,
&CommentUpdateForm::builder().removed(Some(true)).build(),
)
let actor: ApubPerson = local_user_view.person.into();
delete_user_account(
actor.id,
- context.pool(),
+ &mut context.pool(),
context.settings(),
context.client(),
)
cc: vec![],
};
- let inboxes = remote_instance_inboxes(context.pool()).await?;
+ let inboxes = remote_instance_inboxes(&mut context.pool()).await?;
send_lemmy_activity(context, delete, &actor, inboxes, true).await?;
Ok(())
}
let actor = self.actor.dereference(context).await?;
delete_user_account(
actor.id,
- context.pool(),
+ &mut context.pool(),
context.settings(),
context.client(),
)
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
- let community = Community::read(context.pool(), response.post_view.community.id).await?;
+ let community = Community::read(&mut context.pool(), response.post_view.community.id).await?;
let deletable = DeletableObjects::Post(response.post_view.post.clone().into());
send_apub_delete_in_community(
local_user_view.person,
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
- let community = Community::read(context.pool(), response.post_view.community.id).await?;
+ let community = Community::read(&mut context.pool(), response.post_view.community.id).await?;
let deletable = DeletableObjects::Post(response.post_view.post.clone().into());
send_apub_delete_in_community(
local_user_view.person,
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let community_id = response.comment_view.community.id;
- let community = Community::read(context.pool(), community_id).await?;
- let person = Person::read(context.pool(), response.comment_view.creator.id).await?;
+ let community = Community::read(&mut context.pool(), community_id).await?;
+ let person = Person::read(&mut context.pool(), response.comment_view.creator.id).await?;
let deletable = DeletableObjects::Comment(response.comment_view.comment.clone().into());
send_apub_delete_in_community(person, community, deletable, None, request.deleted, context)
.await
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
- let comment = Comment::read(context.pool(), request.comment_id).await?;
- let community = Community::read(context.pool(), response.comment_view.community.id).await?;
+ let comment = Comment::read(&mut context.pool(), request.comment_id).await?;
+ let community =
+ Community::read(&mut context.pool(), response.comment_view.community.id).await?;
let deletable = DeletableObjects::Comment(comment.into());
send_apub_delete_in_community(
local_user_view.person,
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
- let community = Community::read(context.pool(), request.community_id).await?;
+ let community = Community::read(&mut context.pool(), request.community_id).await?;
let deletable = DeletableObjects::Community(community.clone().into());
send_apub_delete_in_community(
local_user_view.person,
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
- let community = Community::read(context.pool(), request.community_id).await?;
+ let community = Community::read(&mut context.pool(), request.community_id).await?;
let deletable = DeletableObjects::Community(community.clone().into());
send_apub_delete_in_community(
local_user_view.person,
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let recipient_id = pm.recipient_id;
- let recipient: ApubPerson = Person::read(context.pool(), recipient_id).await?.into();
+ let recipient: ApubPerson = Person::read(&mut context.pool(), recipient_id)
+ .await?
+ .into();
let deletable = DeletableObjects::PrivateMessage(pm.into());
let inbox = vec![recipient.shared_inbox_or_inbox()];
}
Community::update(
- context.pool(),
+ &mut context.pool(),
community.id,
&CommunityUpdateForm::builder()
.deleted(Some(deleted))
DeletableObjects::Post(post) => {
if deleted != post.deleted {
Post::update(
- context.pool(),
+ &mut context.pool(),
post.id,
&PostUpdateForm::builder().deleted(Some(deleted)).build(),
)
DeletableObjects::Comment(comment) => {
if deleted != comment.deleted {
Comment::update(
- context.pool(),
+ &mut context.pool(),
comment.id,
&CommentUpdateForm::builder().deleted(Some(deleted)).build(),
)
}
DeletableObjects::PrivateMessage(pm) => {
PrivateMessage::update(
- context.pool(),
+ &mut context.pool(),
pm.id,
&PrivateMessageUpdateForm::builder()
.deleted(Some(deleted))
reason: None,
expires: None,
};
- ModRemoveCommunity::create(context.pool(), &form).await?;
+ ModRemoveCommunity::create(&mut context.pool(), &form).await?;
Community::update(
- context.pool(),
+ &mut context.pool(),
community.id,
&CommunityUpdateForm::builder().removed(Some(false)).build(),
)
removed: Some(false),
reason: None,
};
- ModRemovePost::create(context.pool(), &form).await?;
+ ModRemovePost::create(&mut context.pool(), &form).await?;
Post::update(
- context.pool(),
+ &mut context.pool(),
post.id,
&PostUpdateForm::builder().removed(Some(false)).build(),
)
removed: Some(false),
reason: None,
};
- ModRemoveComment::create(context.pool(), &form).await?;
+ ModRemoveComment::create(&mut context.pool(), &form).await?;
Comment::update(
- context.pool(),
+ &mut context.pool(),
comment.id,
&CommentUpdateForm::builder().removed(Some(false)).build(),
)
// This will throw an error if no follow was requested
let community_id = community.id;
let person_id = person.id;
- CommunityFollower::follow_accepted(context.pool(), community_id, person_id).await?;
+ CommunityFollower::follow_accepted(&mut context.pool(), community_id, person_id).await?;
Ok(())
}
person_id: actor.id,
pending: true,
};
- CommunityFollower::follow(context.pool(), &community_follower_form)
+ CommunityFollower::follow(&mut context.pool(), &community_follower_form)
.await
.ok();
follower_id: actor.id,
pending: false,
};
- PersonFollower::follow(context.pool(), &form).await?;
+ PersonFollower::follow(&mut context.pool(), &form).await?;
}
UserOrCommunity::Community(c) => {
let form = CommunityFollowerForm {
person_id: actor.id,
pending: false,
};
- CommunityFollower::follow(context.pool(), &form).await?;
+ CommunityFollower::follow(&mut context.pool(), &form).await?;
}
}
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
- let community = Community::read(context.pool(), request.community_id).await?;
+ let community = Community::read(&mut context.pool(), request.community_id).await?;
UndoFollow::send(&local_user_view.person.into(), &community.into(), context).await
}
}
) -> Result<(), LemmyError> {
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
let person = local_user_view.person.clone().into();
- let community: ApubCommunity = Community::read(context.pool(), request.community_id)
+ let community: ApubCommunity = Community::read(&mut context.pool(), request.community_id)
.await?
.into();
if community.local {
follower_id: person.id,
pending: false,
};
- PersonFollower::unfollow(context.pool(), &form).await?;
+ PersonFollower::unfollow(&mut context.pool(), &form).await?;
}
UserOrCommunity::Community(c) => {
let form = CommunityFollowerForm {
person_id: person.id,
pending: false,
};
- CommunityFollower::unfollow(context.pool(), &form).await?;
+ CommunityFollower::unfollow(&mut context.pool(), &form).await?;
}
}
}
let person_id = person.id;
let community_id = community.id;
- let is_banned = CommunityPersonBanView::get(context.pool(), person_id, community_id)
+ let is_banned = CommunityPersonBanView::get(&mut context.pool(), person_id, community_id)
.await
.is_ok();
if is_banned {
let mod_ = mod_id.dereference(context).await?;
let is_mod_or_admin =
- CommunityView::is_mod_or_admin(context.pool(), mod_.id, community_id).await?;
+ CommunityView::is_mod_or_admin(&mut context.pool(), mod_.id, community_id).await?;
if is_mod_or_admin {
return Ok(());
}
jwt: &Sensitive<String>,
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
- let community = Community::read(context.pool(), community_id).await?.into();
+ let community = Community::read(&mut context.pool(), community_id)
+ .await?
+ .into();
let local_user_view = local_user_view_from_jwt(jwt, context).await?;
- let actor = Person::read(context.pool(), local_user_view.person.id)
+ let actor = Person::read(&mut context.pool(), local_user_view.person.id)
.await?
.into();
score: vote_type.into(),
};
let person_id = actor.id;
- CommentLike::remove(context.pool(), person_id, comment_id).await?;
- CommentLike::like(context.pool(), &like_form).await?;
+ CommentLike::remove(&mut context.pool(), person_id, comment_id).await?;
+ CommentLike::like(&mut context.pool(), &like_form).await?;
Ok(())
}
score: vote_type.into(),
};
let person_id = actor.id;
- PostLike::remove(context.pool(), person_id, post_id).await?;
- PostLike::like(context.pool(), &like_form).await?;
+ PostLike::remove(&mut context.pool(), person_id, post_id).await?;
+ PostLike::like(&mut context.pool(), &like_form).await?;
Ok(())
}
) -> Result<(), LemmyError> {
let comment_id = comment.id;
let person_id = actor.id;
- CommentLike::remove(context.pool(), person_id, comment_id).await?;
+ CommentLike::remove(&mut context.pool(), person_id, comment_id).await?;
Ok(())
}
) -> Result<(), LemmyError> {
let post_id = post.id;
let person_id = actor.id;
- PostLike::remove(context.pool(), person_id, post_id).await?;
+ PostLike::remove(&mut context.pool(), person_id, post_id).await?;
Ok(())
}
async fn verify(&self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
let community = self.community(context).await?;
verify_person_in_community(&self.actor, &community, context).await?;
- let enable_downvotes = LocalSite::read(context.pool())
+ let enable_downvotes = LocalSite::read(&mut context.pool())
.await
.map(|l| l.enable_downvotes)
.unwrap_or(true);
context: Data<LemmyContext>,
) -> Result<Json<GetCommentsResponse>, LemmyError> {
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), &context).await;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
check_private_instance(&local_user_view, &local_site)?;
let community_id = if let Some(name) = &data.community_name {
// If a parent_id is given, fetch the comment to get the path
let parent_path = if let Some(parent_id) = parent_id {
- Some(Comment::read(context.pool(), parent_id).await?.path)
+ Some(Comment::read(&mut context.pool(), parent_id).await?.path)
} else {
None
};
let post_id = data.post_id;
let local_user = local_user_view.map(|l| l.local_user);
let comments = CommentQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.listing_type(Some(listing_type))
.sort(sort)
.max_depth(max_depth)
context: Data<LemmyContext>,
) -> Result<Json<GetPostsResponse>, LemmyError> {
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), &context).await;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
check_private_instance(&local_user_view, &local_site)?;
let listing_type = listing_type_with_default(data.type_, &local_site, community_id)?;
- let is_mod_or_admin = is_mod_or_admin_opt(context.pool(), local_user_view.as_ref(), community_id)
- .await
- .is_ok();
+ let is_mod_or_admin =
+ is_mod_or_admin_opt(&mut context.pool(), local_user_view.as_ref(), community_id)
+ .await
+ .is_ok();
let posts = PostQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.local_user(local_user_view.map(|l| l.local_user).as_ref())
.listing_type(Some(listing_type))
.sort(sort)
context: Data<LemmyContext>,
) -> Result<Json<GetCommunityResponse>, LemmyError> {
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), &context).await;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
if data.name.is_none() && data.id.is_none() {
return Err(LemmyErrorType::NoIdGiven)?;
}
};
- let is_mod_or_admin =
- is_mod_or_admin_opt(context.pool(), local_user_view.as_ref(), Some(community_id))
- .await
- .is_ok();
+ let is_mod_or_admin = is_mod_or_admin_opt(
+ &mut context.pool(),
+ local_user_view.as_ref(),
+ Some(community_id),
+ )
+ .await
+ .is_ok();
let community_view = CommunityView::read(
- context.pool(),
+ &mut context.pool(),
community_id,
person_id,
Some(is_mod_or_admin),
.await
.with_lemmy_type(LemmyErrorType::CouldntFindCommunity)?;
- let moderators = CommunityModeratorView::for_community(context.pool(), community_id)
+ let moderators = CommunityModeratorView::for_community(&mut context.pool(), community_id)
.await
.with_lemmy_type(LemmyErrorType::CouldntFindCommunity)?;
let site_id = Site::instance_actor_id_from_url(community_view.community.actor_id.clone().into());
- let mut site = Site::read_from_apub_id(context.pool(), &site_id.into()).await?;
+ let mut site = Site::read_from_apub_id(&mut context.pool(), &site_id.into()).await?;
// no need to include metadata for local site (its already available through other endpoints).
// this also prevents us from leaking the federation private key.
if let Some(s) = &site {
}
let community_id = community_view.community.id;
- let discussion_languages = CommunityLanguage::read(context.pool(), community_id).await?;
+ let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?;
Ok(Json(GetCommunityResponse {
community_view,
}
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), &context).await;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
check_private_instance(&local_user_view, &local_site)?;
// You don't need to return settings for the user, since this comes back with GetSite
// `my_user`
- let person_view = PersonView::read(context.pool(), person_details_id).await?;
+ let person_view = PersonView::read(&mut context.pool(), person_details_id).await?;
let sort = data.sort;
let page = data.page;
let local_user = local_user_view.map(|l| l.local_user);
let local_user_clone = local_user.clone();
- let posts_query = PostQuery::builder()
- .pool(context.pool())
+ let posts = PostQuery::builder()
+ .pool(&mut context.pool())
.sort(sort)
.saved_only(saved_only)
.local_user(local_user.as_ref())
.community_id(community_id)
.is_mod_or_admin(is_admin)
.page(page)
- .limit(limit);
-
- // If its saved only, you don't care what creator it was
- // Or, if its not saved, then you only want it for that specific creator
- let posts = if !saved_only.unwrap_or(false) {
- posts_query
- .creator_id(Some(person_details_id))
- .build()
- .list()
- } else {
- posts_query.build().list()
- }
- .await?;
+ .limit(limit)
+ .creator_id(
+ // If its saved only, you don't care what creator it was
+ // Or, if its not saved, then you only want it for that specific creator
+ if !saved_only.unwrap_or(false) {
+ Some(person_details_id)
+ } else {
+ None
+ },
+ )
+ .build()
+ .list()
+ .await?;
- let comments_query = CommentQuery::builder()
- .pool(context.pool())
+ let comments = CommentQuery::builder()
+ .pool(&mut context.pool())
.local_user(local_user_clone.as_ref())
.sort(sort.map(post_to_comment_sort_type))
.saved_only(saved_only)
.show_deleted_and_removed(Some(false))
.community_id(community_id)
.page(page)
- .limit(limit);
-
- // If its saved only, you don't care what creator it was
- // Or, if its not saved, then you only want it for that specific creator
- let comments = if !saved_only.unwrap_or(false) {
- comments_query
- .creator_id(Some(person_details_id))
- .build()
- .list()
- } else {
- comments_query.build().list()
- }
- .await?;
+ .limit(limit)
+ .creator_id(
+ // If its saved only, you don't care what creator it was
+ // Or, if its not saved, then you only want it for that specific creator
+ if !saved_only.unwrap_or(false) {
+ Some(person_details_id)
+ } else {
+ None
+ },
+ )
+ .build()
+ .list()
+ .await?;
- let moderates = CommunityModeratorView::for_person(context.pool(), person_details_id).await?;
+ let moderates =
+ CommunityModeratorView::for_person(&mut context.pool(), person_details_id).await?;
// Return the jwt
Ok(Json(GetPersonDetailsResponse {
context: Data<LemmyContext>,
) -> Result<Json<ResolveObjectResponse>, LemmyError> {
let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
let person_id = local_user_view.person.id;
check_private_instance(&Some(local_user_view), &local_site)?;
let res = search_query_to_object_id(&data.q, &context)
.await
.with_lemmy_type(LemmyErrorType::CouldntFindObject)?;
- convert_response(res, person_id, context.pool())
+ convert_response(res, person_id, &mut context.pool())
.await
.with_lemmy_type(LemmyErrorType::CouldntFindObject)
}
async fn convert_response(
object: SearchableObjects,
user_id: PersonId,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
) -> Result<Json<ResolveObjectResponse>, LemmyError> {
use SearchableObjects::*;
let removed_or_deleted;
context: Data<LemmyContext>,
) -> Result<Json<SearchResponse>, LemmyError> {
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), &context).await;
- let local_site = LocalSite::read(context.pool()).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
check_private_instance(&local_user_view, &local_site)?;
match search_type {
SearchType::Posts => {
posts = PostQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.sort(sort)
.listing_type(listing_type)
.community_id(community_id)
}
SearchType::Comments => {
comments = CommentQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.sort(sort.map(post_to_comment_sort_type))
.listing_type(listing_type)
.search_term(Some(q))
}
SearchType::Communities => {
communities = CommunityQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.sort(sort)
.listing_type(listing_type)
.search_term(Some(q))
}
SearchType::Users => {
users = PersonQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.sort(sort)
.search_term(Some(q))
.page(page)
let local_user_ = local_user.clone();
posts = PostQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.sort(sort)
.listing_type(listing_type)
.community_id(community_id)
let local_user_ = local_user.clone();
comments = CommentQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.sort(sort.map(post_to_comment_sort_type))
.listing_type(listing_type)
.search_term(Some(q))
vec![]
} else {
CommunityQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.sort(sort)
.listing_type(listing_type)
.search_term(Some(q))
vec![]
} else {
PersonQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.sort(sort)
.search_term(Some(q))
.page(page)
}
SearchType::Url => {
posts = PostQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.sort(sort)
.listing_type(listing_type)
.community_id(community_id)
data: &Data<Self::DataType>,
) -> Result<Self::Kind, Self::Error> {
let ordered_items = try_join_all(
- Post::list_featured_for_community(data.pool(), owner.id)
+ Post::list_featured_for_community(&mut data.pool(), owner.id)
.await?
.into_iter()
.map(ApubPost::from)
owner: &Self::Owner,
data: &Data<Self::DataType>,
) -> Result<Self::Kind, LemmyError> {
- let moderators = CommunityModeratorView::for_community(data.pool(), owner.id).await?;
+ let moderators = CommunityModeratorView::for_community(&mut data.pool(), owner.id).await?;
let ordered_items = moderators
.into_iter()
.map(|m| ObjectId::<ApubPerson>::from(m.moderator.actor_id))
) -> Result<Self, LemmyError> {
let community_id = owner.id;
let current_moderators =
- CommunityModeratorView::for_community(data.pool(), community_id).await?;
+ CommunityModeratorView::for_community(&mut data.pool(), community_id).await?;
// Remove old mods from database which arent in the moderators collection anymore
for mod_user in ¤t_moderators {
let mod_id = ObjectId::from(mod_user.moderator.actor_id.clone());
community_id: mod_user.community.id,
person_id: mod_user.moderator.id,
};
- CommunityModerator::leave(data.pool(), &community_moderator_form).await?;
+ CommunityModerator::leave(&mut data.pool(), &community_moderator_form).await?;
}
}
community_id: owner.id,
person_id: mod_user.id,
};
- CommunityModerator::join(data.pool(), &community_moderator_form).await?;
+ CommunityModerator::join(&mut data.pool(), &community_moderator_form).await?;
}
}
let community = parse_lemmy_community(&context).await;
let community_id = community.id;
- let inserted_instance = Instance::read_or_create(context.pool(), "my_domain.tld".to_string())
- .await
- .unwrap();
+ let inserted_instance =
+ Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string())
+ .await
+ .unwrap();
let old_mod = PersonInsertForm::builder()
.name("holly".into())
.instance_id(inserted_instance.id)
.build();
- let old_mod = Person::create(context.pool(), &old_mod).await.unwrap();
+ let old_mod = Person::create(&mut context.pool(), &old_mod).await.unwrap();
let community_moderator_form = CommunityModeratorForm {
community_id: community.id,
person_id: old_mod.id,
};
- CommunityModerator::join(context.pool(), &community_moderator_form)
+ CommunityModerator::join(&mut context.pool(), &community_moderator_form)
.await
.unwrap();
.unwrap();
assert_eq!(context.request_count(), 0);
- let current_moderators = CommunityModeratorView::for_community(context.pool(), community_id)
- .await
- .unwrap();
+ let current_moderators =
+ CommunityModeratorView::for_community(&mut context.pool(), community_id)
+ .await
+ .unwrap();
assert_eq!(current_moderators.len(), 1);
assert_eq!(current_moderators[0].moderator.id, new_mod.id);
- Person::delete(context.pool(), old_mod.id).await.unwrap();
- Person::delete(context.pool(), new_mod.id).await.unwrap();
- Community::delete(context.pool(), community.id)
+ Person::delete(&mut context.pool(), old_mod.id)
+ .await
+ .unwrap();
+ Person::delete(&mut context.pool(), new_mod.id)
+ .await
+ .unwrap();
+ Community::delete(&mut context.pool(), community.id)
.await
.unwrap();
- Site::delete(context.pool(), site.id).await.unwrap();
- Instance::delete(context.pool(), inserted_instance.id)
+ Site::delete(&mut context.pool(), site.id).await.unwrap();
+ Instance::delete(&mut context.pool(), inserted_instance.id)
.await
.unwrap();
}
owner: &Self::Owner,
data: &Data<Self::DataType>,
) -> Result<Self::Kind, LemmyError> {
- let post_list: Vec<ApubPost> = Post::list_for_community(data.pool(), owner.id)
+ let post_list: Vec<ApubPost> = Post::list_for_community(&mut data.pool(), owner.id)
.await?
.into_iter()
.map(Into::into)
.collect();
let mut ordered_items = vec![];
for post in post_list {
- let person = Person::read(data.pool(), post.creator_id).await?.into();
+ let person = Person::read(&mut data.pool(), post.creator_id)
+ .await?
+ .into();
let create =
CreateOrUpdatePage::new(post, &person, owner, CreateOrUpdateType::Create, data).await?;
let announcable = AnnouncableActivities::CreateOrUpdatePost(create);
.splitn(2, '@')
.collect_tuple()
.expect("invalid query");
- let actor = DbActor::read_from_name_and_domain(context.pool(), name, domain).await;
+ let actor = DbActor::read_from_name_and_domain(&mut context.pool(), name, domain).await;
if actor.is_ok() {
Ok(actor?.into())
} else if local_user_view.is_some() {
else {
let identifier = identifier.to_string();
Ok(
- DbActor::read_from_name(context.pool(), &identifier, include_deleted)
+ DbActor::read_from_name(&mut context.pool(), &identifier, include_deleted)
.await?
.into(),
)
async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
let cid = match self {
PostOrComment::Post(p) => p.community_id,
- PostOrComment::Comment(c) => Post::read(context.pool(), c.post_id).await?.community_id,
+ PostOrComment::Comment(c) => {
+ Post::read(&mut context.pool(), c.post_id)
+ .await?
+ .community_id
+ }
};
- Ok(Community::read(context.pool(), cid).await?.into())
+ Ok(Community::read(&mut context.pool(), cid).await?.into())
}
}
context: Data<LemmyContext>,
) -> Result<HttpResponse, LemmyError> {
let id = CommentId(info.comment_id.parse::<i32>()?);
- let comment: ApubComment = Comment::read(context.pool(), id).await?.into();
+ let comment: ApubComment = Comment::read(&mut context.pool(), id).await?.into();
if !comment.local {
return Err(err_object_not_local());
}
context: Data<LemmyContext>,
) -> Result<HttpResponse, LemmyError> {
let community: ApubCommunity =
- Community::read_from_name(context.pool(), &info.community_name, true)
+ Community::read_from_name(&mut context.pool(), &info.community_name, true)
.await?
.into();
info: web::Path<CommunityQuery>,
context: Data<LemmyContext>,
) -> Result<HttpResponse, LemmyError> {
- let community = Community::read_from_name(context.pool(), &info.community_name, false).await?;
+ let community =
+ Community::read_from_name(&mut context.pool(), &info.community_name, false).await?;
let followers = GroupFollowers::new(community, &context).await?;
create_apub_response(&followers)
}
context: Data<LemmyContext>,
) -> Result<HttpResponse, LemmyError> {
let community: ApubCommunity =
- Community::read_from_name(context.pool(), &info.community_name, false)
+ Community::read_from_name(&mut context.pool(), &info.community_name, false)
.await?
.into();
if community.deleted || community.removed {
context: Data<LemmyContext>,
) -> Result<HttpResponse, LemmyError> {
let community: ApubCommunity =
- Community::read_from_name(context.pool(), &info.community_name, false)
+ Community::read_from_name(&mut context.pool(), &info.community_name, false)
.await?
.into();
if community.deleted || community.removed {
context: Data<LemmyContext>,
) -> Result<HttpResponse, LemmyError> {
let community: ApubCommunity =
- Community::read_from_name(context.pool(), &info.community_name, false)
+ Community::read_from_name(&mut context.pool(), &info.community_name, false)
.await?
.into();
if community.deleted || community.removed {
info.id
))?
.into();
- let activity = Activity::read_from_apub_id(context.pool(), &activity_id).await?;
+ let activity = Activity::read_from_apub_id(&mut context.pool(), &activity_id).await?;
let sensitive = activity.sensitive;
if !activity.local {
) -> Result<HttpResponse, LemmyError> {
let user_name = info.into_inner().user_name;
// TODO: this needs to be able to read deleted persons, so that it can send tombstones
- let person: ApubPerson = Person::read_from_name(context.pool(), &user_name, true)
+ let person: ApubPerson = Person::read_from_name(&mut context.pool(), &user_name, true)
.await?
.into();
info: web::Path<PersonQuery>,
context: Data<LemmyContext>,
) -> Result<HttpResponse, LemmyError> {
- let person = Person::read_from_name(context.pool(), &info.user_name, false).await?;
+ let person = Person::read_from_name(&mut context.pool(), &info.user_name, false).await?;
let outbox_id = generate_outbox_url(&person.actor_id)?.into();
let outbox = EmptyOutbox::new(outbox_id)?;
create_apub_response(&outbox)
context: Data<LemmyContext>,
) -> Result<HttpResponse, LemmyError> {
let id = PostId(info.post_id.parse::<i32>()?);
- let post: ApubPost = Post::read(context.pool(), id).await?.into();
+ let post: ApubPost = Post::read(&mut context.pool(), id).await?.into();
if !post.local {
return Err(err_object_not_local());
}
pub(crate) async fn get_apub_site_http(
context: Data<LemmyContext>,
) -> Result<HttpResponse, LemmyError> {
- let site: ApubSite = SiteView::read_local(context.pool()).await?.site.into();
+ let site: ApubSite = SiteView::read_local(&mut context.pool()).await?.site.into();
let apub = site.into_json(&context).await?;
create_apub_response(&apub)
use crate::fetcher::post_or_comment::PostOrComment;
use activitypub_federation::config::{Data, UrlVerifier};
use async_trait::async_trait;
-use futures::future::join3;
use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{
source::{
local_site::LocalSite,
},
traits::Crud,
- utils::DbPool,
+ utils::{ActualDbPool, DbPool},
};
use lemmy_utils::error::{LemmyError, LemmyErrorType, LemmyResult};
use moka::future::Cache;
});
#[derive(Clone)]
-pub struct VerifyUrlData(pub DbPool);
+pub struct VerifyUrlData(pub ActualDbPool);
#[async_trait]
impl UrlVerifier for VerifyUrlData {
async fn verify(&self, url: &Url) -> Result<(), &'static str> {
- let local_site_data = local_site_data_cached(&self.0)
+ let local_site_data = local_site_data_cached(&mut (&self.0).into())
.await
.expect("read local site data");
check_apub_id_valid(url, &local_site_data)?;
blocked_instances: Vec<Instance>,
}
-pub(crate) async fn local_site_data_cached(pool: &DbPool) -> LemmyResult<Arc<LocalSiteData>> {
+pub(crate) async fn local_site_data_cached(
+ pool: &mut DbPool<'_>,
+) -> LemmyResult<Arc<LocalSiteData>> {
static CACHE: Lazy<Cache<(), Arc<LocalSiteData>>> = Lazy::new(|| {
Cache::builder()
.max_capacity(1)
Ok(
CACHE
.try_get_with((), async {
- let (local_site, allowed_instances, blocked_instances) = join3(
- LocalSite::read(pool),
- Instance::allowlist(pool),
- Instance::blocklist(pool),
- )
- .await;
+ let (local_site, allowed_instances, blocked_instances) =
+ lemmy_db_schema::try_join_with_pool!(pool => (
+ // LocalSite may be missing
+ |pool| async {
+ Ok(LocalSite::read(pool).await.ok())
+ },
+ Instance::allowlist,
+ Instance::blocklist
+ ))?;
Ok::<_, diesel::result::Error>(Arc::new(LocalSiteData {
- // LocalSite may be missing
- local_site: local_site.ok(),
- allowed_instances: allowed_instances?,
- blocked_instances: blocked_instances?,
+ local_site,
+ allowed_instances,
+ blocked_instances,
}))
})
.await?,
return Ok(());
}
- let local_site_data = local_site_data_cached(context.pool()).await?;
+ let local_site_data = local_site_data_cached(&mut context.pool()).await?;
check_apub_id_valid(apub_id, &local_site_data).map_err(|err| match err {
"Federation disabled" => LemmyErrorType::FederationDisabled,
"Domain is blocked" => LemmyErrorType::DomainBlocked,
sensitive: Some(sensitive),
updated: None,
};
- Activity::create(data.pool(), &form).await?;
+ Activity::create(&mut data.pool(), &form).await?;
Ok(())
}
community_id: ObjectId<ApubCommunity>,
context: &Data<LemmyContext>,
) -> Result<MentionsAndAddresses, LemmyError> {
- let parent_creator = get_comment_parent_creator(context.pool(), comment).await?;
+ let parent_creator = get_comment_parent_creator(&mut context.pool(), comment).await?;
let mut addressed_ccs: Vec<Url> = vec![community_id.into(), parent_creator.id()];
// Add the mention tag
/// top-level comment, the creator of the post, otherwise the creator of the parent comment.
#[tracing::instrument(skip(pool, comment))]
async fn get_comment_parent_creator(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
comment: &Comment,
) -> Result<ApubPerson, LemmyError> {
let parent_creator_id = if let Some(parent_comment_id) = comment.parent_comment_id() {
context: &Data<Self::DataType>,
) -> Result<Option<Self>, LemmyError> {
Ok(
- Comment::read_from_apub_id(context.pool(), object_id)
+ Comment::read_from_apub_id(&mut context.pool(), object_id)
.await?
.map(Into::into),
)
async fn delete(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
if !self.deleted {
let form = CommentUpdateForm::builder().deleted(Some(true)).build();
- Comment::update(context.pool(), self.id, &form).await?;
+ Comment::update(&mut context.pool(), self.id, &form).await?;
}
Ok(())
}
#[tracing::instrument(skip_all)]
async fn into_json(self, context: &Data<Self::DataType>) -> Result<Note, LemmyError> {
let creator_id = self.creator_id;
- let creator = Person::read(context.pool(), creator_id).await?;
+ let creator = Person::read(&mut context.pool(), creator_id).await?;
let post_id = self.post_id;
- let post = Post::read(context.pool(), post_id).await?;
+ let post = Post::read(&mut context.pool(), post_id).await?;
let community_id = post.community_id;
- let community = Community::read(context.pool(), community_id).await?;
+ let community = Community::read(&mut context.pool(), community_id).await?;
let in_reply_to = if let Some(comment_id) = self.parent_comment_id() {
- let parent_comment = Comment::read(context.pool(), comment_id).await?;
+ let parent_comment = Comment::read(&mut context.pool(), comment_id).await?;
parent_comment.ap_id.into()
} else {
post.ap_id.into()
};
- let language = LanguageTag::new_single(self.language_id, context.pool()).await?;
+ let language = LanguageTag::new_single(self.language_id, &mut context.pool()).await?;
let maa = collect_non_local_mentions(&self, community.actor_id.clone().into(), context).await?;
let note = Note {
let content = read_from_string_or_source(¬e.content, ¬e.media_type, ¬e.source);
- let local_site = LocalSite::read(context.pool()).await.ok();
+ let local_site = LocalSite::read(&mut context.pool()).await.ok();
let slur_regex = &local_site_opt_to_slur_regex(&local_site);
let content_slurs_removed = remove_slurs(&content, slur_regex);
- let language_id = LanguageTag::to_language_id_single(note.language, context.pool()).await?;
+ let language_id =
+ LanguageTag::to_language_id_single(note.language, &mut context.pool()).await?;
let form = CommentInsertForm {
creator_id: creator.id,
language_id,
};
let parent_comment_path = parent_comment.map(|t| t.0.path);
- let comment = Comment::create(context.pool(), &form, parent_comment_path.as_ref()).await?;
+ let comment = Comment::create(&mut context.pool(), &form, parent_comment_path.as_ref()).await?;
Ok(comment.into())
}
}
}
async fn cleanup(data: (ApubPerson, ApubCommunity, ApubPost, ApubSite), context: &LemmyContext) {
- Post::delete(context.pool(), data.2.id).await.unwrap();
- Community::delete(context.pool(), data.1.id).await.unwrap();
- Person::delete(context.pool(), data.0.id).await.unwrap();
- Site::delete(context.pool(), data.3.id).await.unwrap();
- LocalSite::delete(context.pool()).await.unwrap();
+ Post::delete(&mut context.pool(), data.2.id).await.unwrap();
+ Community::delete(&mut context.pool(), data.1.id)
+ .await
+ .unwrap();
+ Person::delete(&mut context.pool(), data.0.id)
+ .await
+ .unwrap();
+ Site::delete(&mut context.pool(), data.3.id).await.unwrap();
+ LocalSite::delete(&mut context.pool()).await.unwrap();
}
#[tokio::test]
let to_apub = comment.into_json(&context).await.unwrap();
assert_json_include!(actual: json, expected: to_apub);
- Comment::delete(context.pool(), comment_id).await.unwrap();
+ Comment::delete(&mut context.pool(), comment_id)
+ .await
+ .unwrap();
cleanup(data, &context).await;
}
assert!(!comment.local);
assert_eq!(context.request_count(), 1);
- Comment::delete(context.pool(), comment.id).await.unwrap();
+ Comment::delete(&mut context.pool(), comment.id)
+ .await
+ .unwrap();
cleanup(data, &context).await;
}
context: &Data<Self::DataType>,
) -> Result<Option<Self>, LemmyError> {
Ok(
- Community::read_from_apub_id(context.pool(), &object_id.into())
+ Community::read_from_apub_id(&mut context.pool(), &object_id.into())
.await?
.map(Into::into),
)
#[tracing::instrument(skip_all)]
async fn delete(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
let form = CommunityUpdateForm::builder().deleted(Some(true)).build();
- Community::update(context.pool(), self.id, &form).await?;
+ Community::update(&mut context.pool(), self.id, &form).await?;
Ok(())
}
#[tracing::instrument(skip_all)]
async fn into_json(self, data: &Data<Self::DataType>) -> Result<Group, LemmyError> {
let community_id = self.id;
- let langs = CommunityLanguage::read(data.pool(), community_id).await?;
- let language = LanguageTag::new_multiple(langs, data.pool()).await?;
+ let langs = CommunityLanguage::read(&mut data.pool(), community_id).await?;
+ let language = LanguageTag::new_multiple(langs, &mut data.pool()).await?;
let group = Group {
kind: GroupType::Group,
let instance_id = fetch_instance_actor_for_object(&group.id, context).await?;
let form = Group::into_insert_form(group.clone(), instance_id);
- let languages = LanguageTag::to_language_id_multiple(group.language, context.pool()).await?;
+ let languages =
+ LanguageTag::to_language_id_multiple(group.language, &mut context.pool()).await?;
- let community = Community::create(context.pool(), &form).await?;
- CommunityLanguage::update(context.pool(), languages, community.id).await?;
+ let community = Community::create(&mut context.pool(), &form).await?;
+ CommunityLanguage::update(&mut context.pool(), languages, community.id).await?;
let community: ApubCommunity = community.into();
) -> Result<Vec<Url>, LemmyError> {
let id = self.id;
- let local_site_data = local_site_data_cached(context.pool()).await?;
- let follows = CommunityFollowerView::get_community_follower_inboxes(context.pool(), id).await?;
-
+ let local_site_data = local_site_data_cached(&mut context.pool()).await?;
+ let follows =
+ CommunityFollowerView::get_community_follower_inboxes(&mut context.pool(), id).await?;
let inboxes: Vec<Url> = follows
.into_iter()
.map(Into::into)
assert!(!community.local);
assert_eq!(community.description.as_ref().unwrap().len(), 132);
- Community::delete(context.pool(), community.id)
+ Community::delete(&mut context.pool(), community.id)
.await
.unwrap();
- Site::delete(context.pool(), site.id).await.unwrap();
+ Site::delete(&mut context.pool(), site.id).await.unwrap();
}
}
data: &Data<Self::DataType>,
) -> Result<Option<Self>, LemmyError> {
Ok(
- Site::read_from_apub_id(data.pool(), &object_id.into())
+ Site::read_from_apub_id(&mut data.pool(), &object_id.into())
.await?
.map(Into::into),
)
#[tracing::instrument(skip_all)]
async fn into_json(self, data: &Data<Self::DataType>) -> Result<Self::Kind, LemmyError> {
let site_id = self.id;
- let langs = SiteLanguage::read(data.pool(), site_id).await?;
- let language = LanguageTag::new_multiple(langs, data.pool()).await?;
+ let langs = SiteLanguage::read(&mut data.pool(), site_id).await?;
+ let language = LanguageTag::new_multiple(langs, &mut data.pool()).await?;
let instance = Instance {
kind: ApplicationType::Application,
check_apub_id_valid_with_strictness(apub.id.inner(), true, data).await?;
verify_domains_match(expected_domain, apub.id.inner())?;
- let local_site_data = local_site_data_cached(data.pool()).await?;
+ let local_site_data = local_site_data_cached(&mut data.pool()).await?;
let slur_regex = &local_site_opt_to_slur_regex(&local_site_data.local_site);
check_slurs(&apub.name, slur_regex)?;
check_slurs_opt(&apub.summary, slur_regex)?;
#[tracing::instrument(skip_all)]
async fn from_json(apub: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, LemmyError> {
let domain = apub.id.inner().domain().expect("group id has domain");
- let instance = DbInstance::read_or_create(data.pool(), domain.to_string()).await?;
+ let instance = DbInstance::read_or_create(&mut data.pool(), domain.to_string()).await?;
let site_form = SiteInsertForm {
name: apub.name.clone(),
private_key: None,
instance_id: instance.id,
};
- let languages = LanguageTag::to_language_id_multiple(apub.language, data.pool()).await?;
+ let languages = LanguageTag::to_language_id_multiple(apub.language, &mut data.pool()).await?;
- let site = Site::create(data.pool(), &site_form).await?;
- SiteLanguage::update(data.pool(), languages, &site).await?;
+ let site = Site::create(&mut data.pool(), &site_form).await?;
+ SiteLanguage::update(&mut data.pool(), languages, &site).await?;
Ok(site.into())
}
}
debug!("Failed to dereference site for {}: {}", &instance_id, e);
let domain = instance_id.domain().expect("has domain");
Ok(
- DbInstance::read_or_create(context.pool(), domain.to_string())
+ DbInstance::read_or_create(&mut context.pool(), domain.to_string())
.await?
.id,
)
}
}
-pub(crate) async fn remote_instance_inboxes(pool: &DbPool) -> Result<Vec<Url>, LemmyError> {
+pub(crate) async fn remote_instance_inboxes(pool: &mut DbPool<'_>) -> Result<Vec<Url>, LemmyError> {
Ok(
Site::read_remote_sites(pool)
.await?
assert_eq!(site.name, "Enterprise");
assert_eq!(site.description.as_ref().unwrap().len(), 15);
- Site::delete(context.pool(), site.id).await.unwrap();
+ Site::delete(&mut context.pool(), site.id).await.unwrap();
}
}
context: &Data<Self::DataType>,
) -> Result<Option<Self>, LemmyError> {
Ok(
- DbPerson::read_from_apub_id(context.pool(), &object_id.into())
+ DbPerson::read_from_apub_id(&mut context.pool(), &object_id.into())
.await?
.map(Into::into),
)
#[tracing::instrument(skip_all)]
async fn delete(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
let form = PersonUpdateForm::builder().deleted(Some(true)).build();
- DbPerson::update(context.pool(), self.id, &form).await?;
+ DbPerson::update(&mut context.pool(), self.id, &form).await?;
Ok(())
}
expected_domain: &Url,
context: &Data<Self::DataType>,
) -> Result<(), LemmyError> {
- let local_site_data = local_site_data_cached(context.pool()).await?;
+ let local_site_data = local_site_data_cached(&mut context.pool()).await?;
let slur_regex = &local_site_opt_to_slur_regex(&local_site_data.local_site);
check_slurs(&person.preferred_username, slur_regex)?;
check_slurs_opt(&person.name, slur_regex)?;
matrix_user_id: person.matrix_user_id,
instance_id,
};
- let person = DbPerson::upsert(context.pool(), &person_form).await?;
+ let person = DbPerson::upsert(&mut context.pool(), &person_form).await?;
Ok(person.into())
}
}
async fn cleanup(data: (ApubPerson, ApubSite), context: &LemmyContext) {
- DbPerson::delete(context.pool(), data.0.id).await.unwrap();
- Site::delete(context.pool(), data.1.id).await.unwrap();
+ DbPerson::delete(&mut context.pool(), data.0.id)
+ .await
+ .unwrap();
+ Site::delete(&mut context.pool(), data.1.id).await.unwrap();
}
}
context: &Data<Self::DataType>,
) -> Result<Option<Self>, LemmyError> {
Ok(
- Post::read_from_apub_id(context.pool(), object_id)
+ Post::read_from_apub_id(&mut context.pool(), object_id)
.await?
.map(Into::into),
)
async fn delete(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
if !self.deleted {
let form = PostUpdateForm::builder().deleted(Some(true)).build();
- Post::update(context.pool(), self.id, &form).await?;
+ Post::update(&mut context.pool(), self.id, &form).await?;
}
Ok(())
}
#[tracing::instrument(skip_all)]
async fn into_json(self, context: &Data<Self::DataType>) -> Result<Page, LemmyError> {
let creator_id = self.creator_id;
- let creator = Person::read(context.pool(), creator_id).await?;
+ let creator = Person::read(&mut context.pool(), creator_id).await?;
let community_id = self.community_id;
- let community = Community::read(context.pool(), community_id).await?;
- let language = LanguageTag::new_single(self.language_id, context.pool()).await?;
+ let community = Community::read(&mut context.pool(), community_id).await?;
+ let language = LanguageTag::new_single(self.language_id, &mut context.pool()).await?;
let page = Page {
kind: PageType::Page,
check_apub_id_valid_with_strictness(page.id.inner(), community.local, context).await?;
verify_person_in_community(&page.creator()?, &community, context).await?;
- let local_site_data = local_site_data_cached(context.pool()).await?;
+ let local_site_data = local_site_data_cached(&mut context.pool()).await?;
let slur_regex = &local_site_opt_to_slur_regex(&local_site_data.local_site);
check_slurs_opt(&page.name, slur_regex)?;
let creator = page.creator()?.dereference(context).await?;
let community = page.community(context).await?;
if community.posting_restricted_to_mods {
- is_mod_or_admin(context.pool(), creator.id, community.id).await?;
+ is_mod_or_admin(&mut context.pool(), creator.id, community.id).await?;
}
let mut name = page
.name
};
check_url_scheme(&url)?;
- let local_site = LocalSite::read(context.pool()).await.ok();
+ let local_site = LocalSite::read(&mut context.pool()).await.ok();
let allow_sensitive = local_site_opt_to_sensitive(&local_site);
let page_is_sensitive = page.sensitive.unwrap_or(false);
let include_image = allow_sensitive || !page_is_sensitive;
let body_slurs_removed =
read_from_string_or_source_opt(&page.content, &page.media_type, &page.source)
.map(|s| remove_slurs(&s, slur_regex));
- let language_id = LanguageTag::to_language_id_single(page.language, context.pool()).await?;
+ let language_id =
+ LanguageTag::to_language_id_single(page.language, &mut context.pool()).await?;
PostInsertForm {
name,
.build()
};
- let post = Post::create(context.pool(), &form).await?;
+ let post = Post::create(&mut context.pool(), &form).await?;
// write mod log entry for lock
if Page::is_locked_changed(&old_post, &page.comments_enabled) {
post_id: post.id,
locked: Some(post.locked),
};
- ModLockPost::create(context.pool(), &form).await?;
+ ModLockPost::create(&mut context.pool(), &form).await?;
}
Ok(post.into())
assert!(!post.featured_community);
assert_eq!(context.request_count(), 0);
- Post::delete(context.pool(), post.id).await.unwrap();
- Person::delete(context.pool(), person.id).await.unwrap();
- Community::delete(context.pool(), community.id)
+ Post::delete(&mut context.pool(), post.id).await.unwrap();
+ Person::delete(&mut context.pool(), person.id)
.await
.unwrap();
- Site::delete(context.pool(), site.id).await.unwrap();
+ Community::delete(&mut context.pool(), community.id)
+ .await
+ .unwrap();
+ Site::delete(&mut context.pool(), site.id).await.unwrap();
}
}
context: &Data<Self::DataType>,
) -> Result<Option<Self>, LemmyError> {
Ok(
- PrivateMessage::read_from_apub_id(context.pool(), object_id)
+ PrivateMessage::read_from_apub_id(&mut context.pool(), object_id)
.await?
.map(Into::into),
)
#[tracing::instrument(skip_all)]
async fn into_json(self, context: &Data<Self::DataType>) -> Result<ChatMessage, LemmyError> {
let creator_id = self.creator_id;
- let creator = Person::read(context.pool(), creator_id).await?;
+ let creator = Person::read(&mut context.pool(), creator_id).await?;
let recipient_id = self.recipient_id;
- let recipient = Person::read(context.pool(), recipient_id).await?;
+ let recipient = Person::read(&mut context.pool(), recipient_id).await?;
let note = ChatMessage {
r#type: ChatMessageType::ChatMessage,
) -> Result<ApubPrivateMessage, LemmyError> {
let creator = note.attributed_to.dereference(context).await?;
let recipient = note.to[0].dereference(context).await?;
- check_person_block(creator.id, recipient.id, context.pool()).await?;
+ check_person_block(creator.id, recipient.id, &mut context.pool()).await?;
let form = PrivateMessageInsertForm {
creator_id: creator.id,
ap_id: Some(note.id.into()),
local: Some(false),
};
- let pm = PrivateMessage::create(context.pool(), &form).await?;
+ let pm = PrivateMessage::create(&mut context.pool(), &form).await?;
Ok(pm.into())
}
}
}
async fn cleanup(data: (ApubPerson, ApubPerson, ApubSite), context: &Data<LemmyContext>) {
- Person::delete(context.pool(), data.0.id).await.unwrap();
- Person::delete(context.pool(), data.1.id).await.unwrap();
- Site::delete(context.pool(), data.2.id).await.unwrap();
+ Person::delete(&mut context.pool(), data.0.id)
+ .await
+ .unwrap();
+ Person::delete(&mut context.pool(), data.1.id)
+ .await
+ .unwrap();
+ Site::delete(&mut context.pool(), data.2.id).await.unwrap();
}
#[tokio::test]
let to_apub = pm.into_json(&context).await.unwrap();
assert_json_include!(actual: json, expected: to_apub);
- PrivateMessage::delete(context.pool(), pm_id).await.unwrap();
+ PrivateMessage::delete(&mut context.pool(), pm_id)
+ .await
+ .unwrap();
cleanup(data, &context).await;
}
assert_eq!(pm.content.len(), 3);
assert_eq!(context.request_count(), 0);
- PrivateMessage::delete(context.pool(), pm.id).await.unwrap();
+ PrivateMessage::delete(&mut context.pool(), pm.id)
+ .await
+ .unwrap();
cleanup(data, &context).await;
}
}
impl InCommunity for CollectionAdd {
async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
let (community, _) =
- Community::get_by_collection_url(context.pool(), &self.clone().target.into()).await?;
+ Community::get_by_collection_url(&mut context.pool(), &self.clone().target.into()).await?;
if let Some(audience) = &self.audience {
verify_community_matches(audience, community.actor_id.clone())?;
}
impl InCommunity for CollectionRemove {
async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
let (community, _) =
- Community::get_by_collection_url(context.pool(), &self.clone().target.into()).await?;
+ Community::get_by_collection_url(&mut context.pool(), &self.clone().target.into()).await?;
if let Some(audience) = &self.audience {
verify_community_matches(audience, community.actor_id.clone())?;
}
impl InCommunity for LockPage {
async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
let post = self.object.dereference(context).await?;
- let community = Community::read(context.pool(), post.community_id).await?;
+ let community = Community::read(&mut context.pool(), post.community_id).await?;
if let Some(audience) = &self.audience {
verify_community_matches(audience, community.actor_id.clone())?;
}
impl InCommunity for CreateOrUpdateNote {
async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
let post = self.object.get_parents(context).await?.0;
- let community = Community::read(context.pool(), post.community_id).await?;
+ let community = Community::read(&mut context.pool(), post.community_id).await?;
if let Some(audience) = &self.audience {
verify_community_matches(audience, community.actor_id.clone())?;
}
let community_id = match DeletableObjects::read_from_db(self.object.id(), context).await? {
DeletableObjects::Community(c) => c.id,
DeletableObjects::Comment(c) => {
- let post = Post::read(context.pool(), c.post_id).await?;
+ let post = Post::read(&mut context.pool(), c.post_id).await?;
post.community_id
}
DeletableObjects::Post(p) => p.community_id,
return Err(anyhow!("Private message is not part of community").into())
}
};
- let community = Community::read(context.pool(), community_id).await?;
+ let community = Community::read(&mut context.pool(), community_id).await?;
if let Some(audience) = &self.audience {
verify_community_matches(audience, community.actor_id.clone())?;
}
) -> Result<GroupFollowers, LemmyError> {
let community_id = community.id;
let community_followers =
- CommunityFollowerView::count_community_followers(context.pool(), community_id).await?;
+ CommunityFollowerView::count_community_followers(&mut context.pool(), community_id).await?;
Ok(GroupFollowers {
id: generate_followers_url(&community.actor_id)?.into(),
check_apub_id_valid_with_strictness(self.id.inner(), true, context).await?;
verify_domains_match(expected_domain, self.id.inner())?;
- let local_site_data = local_site_data_cached(context.pool()).await?;
+ let local_site_data = local_site_data_cached(&mut context.pool()).await?;
let slur_regex = &local_site_opt_to_slur_regex(&local_site_data.local_site);
check_slurs(&self.preferred_username, slur_regex)?;
impl LanguageTag {
pub(crate) async fn new_single(
lang: LanguageId,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
) -> Result<Option<LanguageTag>, LemmyError> {
let lang = Language::read_from_id(pool, lang).await?;
pub(crate) async fn new_multiple(
lang_ids: Vec<LanguageId>,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
) -> Result<Vec<LanguageTag>, LemmyError> {
let mut langs = Vec::<Language>::new();
pub(crate) async fn to_language_id_single(
lang: Option<Self>,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
) -> Result<Option<LanguageId>, LemmyError> {
let identifier = lang.map(|l| l.identifier);
let language = Language::read_id_from_code(pool, identifier.as_deref()).await?;
pub(crate) async fn to_language_id_multiple(
langs: Vec<Self>,
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
) -> Result<Vec<LanguageId>, LemmyError> {
let mut language_ids = Vec::new();
PostOrComment::Post(p) => Ok((p.clone(), None)),
PostOrComment::Comment(c) => {
let post_id = c.post_id;
- let post = Post::read(context.pool(), post_id).await?;
+ let post = Post::read(&mut context.pool(), post_id).await?;
Ok((post.into(), Some(c.clone())))
}
}
impl InCommunity for Note {
async fn community(&self, context: &Data<LemmyContext>) -> Result<ApubCommunity, LemmyError> {
let (post, _) = self.get_parents(context).await?;
- let community = Community::read(context.pool(), post.community_id).await?;
+ let community = Community::read(&mut context.pool(), post.community_id).await?;
if let Some(audience) = &self.audience {
verify_community_matches(audience, community.actor_id.clone())?;
}
use diesel_async::RunQueryDsl;
impl CommentAggregates {
- pub async fn read(pool: &DbPool, comment_id: CommentId) -> Result<Self, Error> {
+ pub async fn read(pool: &mut DbPool<'_>, comment_id: CommentId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
comment_aggregates::table
.filter(comment_aggregates::comment_id.eq(comment_id))
.await
}
- pub async fn update_hot_rank(pool: &DbPool, comment_id: CommentId) -> Result<Self, Error> {
+ pub async fn update_hot_rank(
+ pool: &mut DbPool<'_>,
+ comment_id: CommentId,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
diesel::update(comment_aggregates::table)
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
use diesel_async::RunQueryDsl;
impl CommunityAggregates {
- pub async fn read(pool: &DbPool, community_id: CommunityId) -> Result<Self, Error> {
+ pub async fn read(pool: &mut DbPool<'_>, community_id: CommunityId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
community_aggregates::table
.filter(community_aggregates::community_id.eq(community_id))
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
use diesel_async::RunQueryDsl;
impl PersonAggregates {
- pub async fn read(pool: &DbPool, person_id: PersonId) -> Result<Self, Error> {
+ pub async fn read(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
person_aggregates::table
.filter(person_aggregates::person_id.eq(person_id))
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
use diesel_async::RunQueryDsl;
impl PersonPostAggregates {
- pub async fn upsert(pool: &DbPool, form: &PersonPostAggregatesForm) -> Result<Self, Error> {
+ pub async fn upsert(
+ pool: &mut DbPool<'_>,
+ form: &PersonPostAggregatesForm,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(person_post_aggregates)
.values(form)
.get_result::<Self>(conn)
.await
}
- pub async fn read(pool: &DbPool, person_id_: PersonId, post_id_: PostId) -> Result<Self, Error> {
+ pub async fn read(
+ pool: &mut DbPool<'_>,
+ person_id_: PersonId,
+ post_id_: PostId,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
person_post_aggregates
.filter(post_id.eq(post_id_).and(person_id.eq(person_id_)))
use diesel_async::RunQueryDsl;
impl PostAggregates {
- pub async fn read(pool: &DbPool, post_id: PostId) -> Result<Self, Error> {
+ pub async fn read(pool: &mut DbPool<'_>, post_id: PostId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
post_aggregates::table
.filter(post_aggregates::post_id.eq(post_id))
.await
}
- pub async fn update_hot_rank(pool: &DbPool, post_id: PostId) -> Result<Self, Error> {
+ pub async fn update_hot_rank(pool: &mut DbPool<'_>, post_id: PostId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
diesel::update(post_aggregates::table)
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
#[serial]
async fn test_soft_delete() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
use diesel_async::RunQueryDsl;
impl SiteAggregates {
- pub async fn read(pool: &DbPool) -> Result<Self, Error> {
+ pub async fn read(pool: &mut DbPool<'_>) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
site_aggregates::table.first::<Self>(conn).await
}
};
use serial_test::serial;
- async fn prepare_site_with_community(pool: &DbPool) -> (Instance, Person, Site, Community) {
+ async fn prepare_site_with_community(
+ pool: &mut DbPool<'_>,
+ ) -> (Instance, Person, Site, Community) {
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
.unwrap();
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let (inserted_instance, inserted_person, inserted_site, inserted_community) =
prepare_site_with_community(pool).await;
#[serial]
async fn test_soft_delete() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let (inserted_instance, inserted_person, inserted_site, inserted_community) =
prepare_site_with_community(pool).await;
type InsertForm = ActivityInsertForm;
type UpdateForm = ActivityUpdateForm;
type IdType = i32;
- async fn read(pool: &DbPool, activity_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, activity_id: i32) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
activity.find(activity_id).first::<Self>(conn).await
}
- async fn create(pool: &DbPool, new_activity: &Self::InsertForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, new_activity: &Self::InsertForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(activity)
.values(new_activity)
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
activity_id: i32,
new_activity: &Self::UpdateForm,
) -> Result<Self, Error> {
.get_result::<Self>(conn)
.await
}
- async fn delete(pool: &DbPool, activity_id: i32) -> Result<usize, Error> {
+ async fn delete(pool: &mut DbPool<'_>, activity_id: i32) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(activity.find(activity_id))
.execute(conn)
}
impl Activity {
- pub async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result<Activity, Error> {
+ pub async fn read_from_apub_id(
+ pool: &mut DbPool<'_>,
+ object_id: &DbUrl,
+ ) -> Result<Activity, Error> {
let conn = &mut get_conn(pool).await?;
activity
.filter(ap_id.eq(object_id))
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
ExpressionMethods,
QueryDsl,
};
-use diesel_async::{
- pooled_connection::deadpool::Object as PooledConnection,
- AsyncPgConnection,
- RunQueryDsl,
-};
+use diesel_async::{AsyncPgConnection, RunQueryDsl};
use lemmy_utils::error::{LemmyError, LemmyErrorType};
use tokio::sync::OnceCell;
impl LocalUserLanguage {
pub async fn read(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_local_user_id: LocalUserId,
) -> Result<Vec<LanguageId>, Error> {
use crate::schema::local_user_language::dsl::{
///
/// If no language_id vector is given, it will show all languages
pub async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
language_ids: Vec<LanguageId>,
for_local_user_id: LocalUserId,
) -> Result<(), Error> {
let mut lang_ids = convert_update_languages(conn, language_ids).await?;
// No need to update if languages are unchanged
- let current = LocalUserLanguage::read(pool, for_local_user_id).await?;
+ let current = LocalUserLanguage::read(&mut conn.into(), for_local_user_id).await?;
if current == lang_ids {
return Ok(());
}
}
impl SiteLanguage {
- pub async fn read_local_raw(pool: &DbPool) -> Result<Vec<LanguageId>, Error> {
+ pub async fn read_local_raw(pool: &mut DbPool<'_>) -> Result<Vec<LanguageId>, Error> {
let conn = &mut get_conn(pool).await?;
site::table
.inner_join(local_site::table)
.await
}
- async fn read_raw(
- conn: &mut PooledConnection<AsyncPgConnection>,
- for_site_id: SiteId,
- ) -> Result<Vec<LanguageId>, Error> {
- site_language::table
+ pub async fn read(pool: &mut DbPool<'_>, for_site_id: SiteId) -> Result<Vec<LanguageId>, Error> {
+ let conn = &mut get_conn(pool).await?;
+ let langs = site_language::table
.filter(site_language::site_id.eq(for_site_id))
.order(site_language::language_id)
.select(site_language::language_id)
.load(conn)
- .await
- }
-
- pub async fn read(pool: &DbPool, for_site_id: SiteId) -> Result<Vec<LanguageId>, Error> {
- let conn = &mut get_conn(pool).await?;
- let langs = Self::read_raw(conn, for_site_id).await?;
+ .await?;
convert_read_languages(conn, langs).await
}
pub async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
language_ids: Vec<LanguageId>,
site: &Site,
) -> Result<(), Error> {
let lang_ids = convert_update_languages(conn, language_ids).await?;
// No need to update if languages are unchanged
- let current = SiteLanguage::read(pool, site.id).await?;
+ let current = SiteLanguage::read(&mut conn.into(), site.id).await?;
if current == lang_ids {
return Ok(());
}
impl CommunityLanguage {
/// Returns true if the given language is one of configured languages for given community
pub async fn is_allowed_community_language(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_language_id: Option<LanguageId>,
for_community_id: CommunityId,
) -> Result<(), LemmyError> {
Ok(())
}
- async fn read_raw(
- conn: &mut PooledConnection<AsyncPgConnection>,
+ pub async fn read(
+ pool: &mut DbPool<'_>,
for_community_id: CommunityId,
) -> Result<Vec<LanguageId>, Error> {
use crate::schema::community_language::dsl::{community_id, community_language, language_id};
- community_language
+ let conn = &mut get_conn(pool).await?;
+ let langs = community_language
.filter(community_id.eq(for_community_id))
.order(language_id)
.select(language_id)
.get_results(conn)
- .await
- }
-
- pub async fn read(
- pool: &DbPool,
- for_community_id: CommunityId,
- ) -> Result<Vec<LanguageId>, Error> {
- let conn = &mut get_conn(pool).await?;
- let langs = Self::read_raw(conn, for_community_id).await?;
+ .await?;
convert_read_languages(conn, langs).await
}
pub async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
mut language_ids: Vec<LanguageId>,
for_community_id: CommunityId,
) -> Result<(), Error> {
- let conn = &mut get_conn(pool).await?;
if language_ids.is_empty() {
language_ids = SiteLanguage::read_local_raw(pool).await?;
}
+ let conn = &mut get_conn(pool).await?;
let lang_ids = convert_update_languages(conn, language_ids).await?;
// No need to update if languages are unchanged
- let current = CommunityLanguage::read_raw(conn, for_community_id).await?;
+ let current = CommunityLanguage::read(&mut conn.into(), for_community_id).await?;
if current == lang_ids {
return Ok(());
}
}
pub async fn default_post_language(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
community_id: CommunityId,
local_user_id: LocalUserId,
) -> Result<Option<LanguageId>, Error> {
) -> Result<Vec<LanguageId>, Error> {
if language_ids.is_empty() {
Ok(
- Language::read_all_conn(conn)
+ Language::read_all(&mut conn.into())
.await?
.into_iter()
.map(|l| l.id)
};
use serial_test::serial;
- async fn test_langs1(pool: &DbPool) -> Vec<LanguageId> {
+ async fn test_langs1(pool: &mut DbPool<'_>) -> Vec<LanguageId> {
vec![
Language::read_id_from_code(pool, Some("en"))
.await
.unwrap(),
]
}
- async fn test_langs2(pool: &DbPool) -> Vec<LanguageId> {
+ async fn test_langs2(pool: &mut DbPool<'_>) -> Vec<LanguageId> {
vec![
Language::read_id_from_code(pool, Some("fi"))
.await
]
}
- async fn create_test_site(pool: &DbPool) -> (Site, Instance) {
+ async fn create_test_site(pool: &mut DbPool<'_>) -> (Site, Instance) {
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
.unwrap();
#[serial]
async fn test_convert_update_languages() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
// call with empty vec, returns all languages
let conn = &mut get_conn(pool).await.unwrap();
assert_eq!(184, converted1.len());
// call with nonempty vec, returns same vec
- let test_langs = test_langs1(pool).await;
+ let test_langs = test_langs1(&mut conn.into()).await;
let converted2 = convert_update_languages(conn, test_langs.clone())
.await
.unwrap();
async fn test_convert_read_languages() {
use crate::schema::language::dsl::{id, language};
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
// call with all languages, returns empty vec
let conn = &mut get_conn(pool).await.unwrap();
assert_eq!(0, converted1.len());
// call with nonempty vec, returns same vec
- let test_langs = test_langs1(pool).await;
+ let test_langs = test_langs1(&mut conn.into()).await;
let converted2 = convert_read_languages(conn, test_langs.clone())
.await
.unwrap();
#[serial]
async fn test_site_languages() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let (site, instance) = create_test_site(pool).await;
let site_languages1 = SiteLanguage::read_local_raw(pool).await.unwrap();
#[serial]
async fn test_user_languages() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let (site, instance) = create_test_site(pool).await;
let mut test_langs = test_langs1(pool).await;
#[serial]
async fn test_community_languages() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let (site, instance) = create_test_site(pool).await;
let test_langs = test_langs1(pool).await;
SiteLanguage::update(pool, test_langs.clone(), &site)
#[serial]
async fn test_default_post_language() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let (site, instance) = create_test_site(pool).await;
let test_langs = test_langs1(pool).await;
let test_langs2 = test_langs2(pool).await;
use diesel_async::RunQueryDsl;
impl CaptchaAnswer {
- pub async fn insert(pool: &DbPool, captcha: &CaptchaAnswerForm) -> Result<Self, Error> {
+ pub async fn insert(pool: &mut DbPool<'_>, captcha: &CaptchaAnswerForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(captcha_answer)
.await
}
- pub async fn check_captcha(pool: &DbPool, to_check: CheckCaptchaAnswer) -> Result<bool, Error> {
+ pub async fn check_captcha(
+ pool: &mut DbPool<'_>,
+ to_check: CheckCaptchaAnswer,
+ ) -> Result<bool, Error> {
let conn = &mut get_conn(pool).await?;
// fetch requested captcha
#[serial]
async fn test_captcha_happy_path() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted = CaptchaAnswer::insert(
pool,
#[serial]
async fn test_captcha_repeat_answer_fails() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted = CaptchaAnswer::insert(
pool,
impl Comment {
pub async fn permadelete_for_creator(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_creator_id: PersonId,
) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
}
pub async fn update_removed_for_creator(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_creator_id: PersonId,
new_removed: bool,
) -> Result<Vec<Self>, Error> {
}
pub async fn create(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
comment_form: &CommentInsertForm,
parent_path: Option<&Ltree>,
) -> Result<Comment, Error> {
inserted_comment
}
}
- pub async fn read_from_apub_id(pool: &DbPool, object_id: Url) -> Result<Option<Self>, Error> {
+ pub async fn read_from_apub_id(
+ pool: &mut DbPool<'_>,
+ object_id: Url,
+ ) -> Result<Option<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let object_id: DbUrl = object_id.into();
Ok(
type InsertForm = CommentInsertForm;
type UpdateForm = CommentUpdateForm;
type IdType = CommentId;
- async fn read(pool: &DbPool, comment_id: CommentId) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, comment_id: CommentId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
comment.find(comment_id).first::<Self>(conn).await
}
- async fn delete(pool: &DbPool, comment_id: CommentId) -> Result<usize, Error> {
+ async fn delete(pool: &mut DbPool<'_>, comment_id: CommentId) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(comment.find(comment_id)).execute(conn).await
}
/// This is unimplemented, use [[Comment::create]]
- async fn create(_pool: &DbPool, _comment_form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn create(_pool: &mut DbPool<'_>, _comment_form: &Self::InsertForm) -> Result<Self, Error> {
unimplemented!();
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
comment_id: CommentId,
comment_form: &Self::UpdateForm,
) -> Result<Self, Error> {
impl Likeable for CommentLike {
type Form = CommentLikeForm;
type IdType = CommentId;
- async fn like(pool: &DbPool, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
+ async fn like(pool: &mut DbPool<'_>, comment_like_form: &CommentLikeForm) -> Result<Self, Error> {
use crate::schema::comment_like::dsl::{comment_id, comment_like, person_id};
let conn = &mut get_conn(pool).await?;
insert_into(comment_like)
.await
}
async fn remove(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
person_id_: PersonId,
comment_id_: CommentId,
) -> Result<usize, Error> {
#[async_trait]
impl Saveable for CommentSaved {
type Form = CommentSavedForm;
- async fn save(pool: &DbPool, comment_saved_form: &CommentSavedForm) -> Result<Self, Error> {
+ async fn save(
+ pool: &mut DbPool<'_>,
+ comment_saved_form: &CommentSavedForm,
+ ) -> Result<Self, Error> {
use crate::schema::comment_saved::dsl::{comment_id, comment_saved, person_id};
let conn = &mut get_conn(pool).await?;
insert_into(comment_saved)
.get_result::<Self>(conn)
.await
}
- async fn unsave(pool: &DbPool, comment_saved_form: &CommentSavedForm) -> Result<usize, Error> {
+ async fn unsave(
+ pool: &mut DbPool<'_>,
+ comment_saved_form: &CommentSavedForm,
+ ) -> Result<usize, Error> {
use crate::schema::comment_saved::dsl::{comment_id, comment_saved, person_id};
let conn = &mut get_conn(pool).await?;
diesel::delete(
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
type InsertForm = CommentReplyInsertForm;
type UpdateForm = CommentReplyUpdateForm;
type IdType = CommentReplyId;
- async fn read(pool: &DbPool, comment_reply_id: CommentReplyId) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, comment_reply_id: CommentReplyId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
comment_reply
.find(comment_reply_id)
.await
}
- async fn create(pool: &DbPool, comment_reply_form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn create(
+ pool: &mut DbPool<'_>,
+ comment_reply_form: &Self::InsertForm,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
// since the return here isnt utilized, we dont need to do an update
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
comment_reply_id: CommentReplyId,
comment_reply_form: &Self::UpdateForm,
) -> Result<Self, Error> {
impl CommentReply {
pub async fn mark_all_as_read(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_recipient_id: PersonId,
) -> Result<Vec<CommentReply>, Error> {
let conn = &mut get_conn(pool).await?;
.await
}
- pub async fn read_by_comment(pool: &DbPool, for_comment_id: CommentId) -> Result<Self, Error> {
+ pub async fn read_by_comment(
+ pool: &mut DbPool<'_>,
+ for_comment_id: CommentId,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
comment_reply
.filter(comment_id.eq(for_comment_id))
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
///
/// * `conn` - the postgres connection
/// * `comment_report_form` - the filled CommentReportForm to insert
- async fn report(pool: &DbPool, comment_report_form: &CommentReportForm) -> Result<Self, Error> {
+ async fn report(
+ pool: &mut DbPool<'_>,
+ comment_report_form: &CommentReportForm,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(comment_report)
.values(comment_report_form)
/// * `report_id` - the id of the report to resolve
/// * `by_resolver_id` - the id of the user resolving the report
async fn resolve(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
report_id_: Self::IdType,
by_resolver_id: PersonId,
) -> Result<usize, Error> {
/// * `report_id` - the id of the report to unresolve
/// * `by_resolver_id` - the id of the user unresolving the report
async fn unresolve(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
report_id_: Self::IdType,
by_resolver_id: PersonId,
) -> Result<usize, Error> {
type InsertForm = CommunityInsertForm;
type UpdateForm = CommunityUpdateForm;
type IdType = CommunityId;
- async fn read(pool: &DbPool, community_id: CommunityId) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, community_id: CommunityId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
community::table
.find(community_id)
.await
}
- async fn delete(pool: &DbPool, community_id: CommunityId) -> Result<usize, Error> {
+ async fn delete(pool: &mut DbPool<'_>, community_id: CommunityId) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(community::table.find(community_id))
.execute(conn)
.await
}
- async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
- let conn = &mut get_conn(pool).await?;
+ async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
let is_new_community = match &form.actor_id {
Some(id) => Community::read_from_apub_id(pool, id).await?.is_none(),
None => true,
};
+ let conn = &mut get_conn(pool).await?;
// Can't do separate insert/update commands because InsertForm/UpdateForm aren't convertible
let community_ = insert_into(community::table)
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
community_id: CommunityId,
form: &Self::UpdateForm,
) -> Result<Self, Error> {
impl Joinable for CommunityModerator {
type Form = CommunityModeratorForm;
async fn join(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
community_moderator_form: &CommunityModeratorForm,
) -> Result<Self, Error> {
use crate::schema::community_moderator::dsl::community_moderator;
}
async fn leave(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
community_moderator_form: &CommunityModeratorForm,
) -> Result<usize, Error> {
use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id};
impl Community {
/// Get the community which has a given moderators or featured url, also return the collection type
pub async fn get_by_collection_url(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
url: &DbUrl,
) -> Result<(Community, CollectionType), Error> {
use crate::schema::community::dsl::{featured_url, moderators_url};
impl CommunityModerator {
pub async fn delete_for_community(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_community_id: CommunityId,
) -> Result<usize, Error> {
use crate::schema::community_moderator::dsl::{community_id, community_moderator};
}
pub async fn leave_all_communities(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_person_id: PersonId,
) -> Result<usize, Error> {
use crate::schema::community_moderator::dsl::{community_moderator, person_id};
}
pub async fn get_person_moderated_communities(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_person_id: PersonId,
) -> Result<Vec<CommunityId>, Error> {
use crate::schema::community_moderator::dsl::{community_id, community_moderator, person_id};
impl Bannable for CommunityPersonBan {
type Form = CommunityPersonBanForm;
async fn ban(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
community_person_ban_form: &CommunityPersonBanForm,
) -> Result<Self, Error> {
use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id};
}
async fn unban(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
community_person_ban_form: &CommunityPersonBanForm,
) -> Result<usize, Error> {
use crate::schema::community_person_ban::dsl::{community_id, community_person_ban, person_id};
#[async_trait]
impl Followable for CommunityFollower {
type Form = CommunityFollowerForm;
- async fn follow(pool: &DbPool, form: &CommunityFollowerForm) -> Result<Self, Error> {
+ async fn follow(pool: &mut DbPool<'_>, form: &CommunityFollowerForm) -> Result<Self, Error> {
use crate::schema::community_follower::dsl::{community_follower, community_id, person_id};
let conn = &mut get_conn(pool).await?;
insert_into(community_follower)
.await
}
async fn follow_accepted(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
community_id_: CommunityId,
person_id_: PersonId,
) -> Result<Self, Error> {
.get_result::<Self>(conn)
.await
}
- async fn unfollow(pool: &DbPool, form: &CommunityFollowerForm) -> Result<usize, Error> {
+ async fn unfollow(pool: &mut DbPool<'_>, form: &CommunityFollowerForm) -> Result<usize, Error> {
use crate::schema::community_follower::dsl::{community_follower, community_id, person_id};
let conn = &mut get_conn(pool).await?;
diesel::delete(
#[async_trait]
impl ApubActor for Community {
- async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result<Option<Self>, Error> {
+ async fn read_from_apub_id(
+ pool: &mut DbPool<'_>,
+ object_id: &DbUrl,
+ ) -> Result<Option<Self>, Error> {
let conn = &mut get_conn(pool).await?;
Ok(
community::table
}
async fn read_from_name(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
community_name: &str,
include_deleted: bool,
) -> Result<Community, Error> {
}
async fn read_from_name_and_domain(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
community_name: &str,
for_domain: &str,
) -> Result<Community, Error> {
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
#[async_trait]
impl Blockable for CommunityBlock {
type Form = CommunityBlockForm;
- async fn block(pool: &DbPool, community_block_form: &Self::Form) -> Result<Self, Error> {
+ async fn block(pool: &mut DbPool<'_>, community_block_form: &Self::Form) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(community_block)
.values(community_block_form)
.get_result::<Self>(conn)
.await
}
- async fn unblock(pool: &DbPool, community_block_form: &Self::Form) -> Result<usize, Error> {
+ async fn unblock(
+ pool: &mut DbPool<'_>,
+ community_block_form: &Self::Form,
+ ) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(
community_block
use diesel_async::RunQueryDsl;
impl CustomEmoji {
- pub async fn create(pool: &DbPool, form: &CustomEmojiInsertForm) -> Result<Self, Error> {
+ pub async fn create(pool: &mut DbPool<'_>, form: &CustomEmojiInsertForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(custom_emoji)
.values(form)
.await
}
pub async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
emoji_id: CustomEmojiId,
form: &CustomEmojiUpdateForm,
) -> Result<Self, Error> {
.get_result::<Self>(conn)
.await
}
- pub async fn delete(pool: &DbPool, emoji_id: CustomEmojiId) -> Result<usize, Error> {
+ pub async fn delete(pool: &mut DbPool<'_>, emoji_id: CustomEmojiId) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(custom_emoji.find(emoji_id))
.execute(conn)
impl CustomEmojiKeyword {
pub async fn create(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
form: Vec<CustomEmojiKeywordInsertForm>,
) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
.get_results::<Self>(conn)
.await
}
- pub async fn delete(pool: &DbPool, emoji_id: CustomEmojiId) -> Result<usize, Error> {
+ pub async fn delete(pool: &mut DbPool<'_>, emoji_id: CustomEmojiId) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(custom_emoji_keyword.filter(custom_emoji_id.eq(emoji_id)))
.execute(conn)
use diesel_async::RunQueryDsl;
impl EmailVerification {
- pub async fn create(pool: &DbPool, form: &EmailVerificationForm) -> Result<Self, Error> {
+ pub async fn create(pool: &mut DbPool<'_>, form: &EmailVerificationForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(email_verification)
.values(form)
.await
}
- pub async fn read_for_token(pool: &DbPool, token: &str) -> Result<Self, Error> {
+ pub async fn read_for_token(pool: &mut DbPool<'_>, token: &str) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
email_verification
.filter(verification_token.eq(token))
.await
}
pub async fn delete_old_tokens_for_local_user(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
local_user_id_: LocalUserId,
) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
use diesel_async::{AsyncPgConnection, RunQueryDsl};
impl FederationAllowList {
- pub async fn replace(pool: &DbPool, list_opt: Option<Vec<String>>) -> Result<(), Error> {
+ pub async fn replace(pool: &mut DbPool<'_>, list_opt: Option<Vec<String>>) -> Result<(), Error> {
let conn = &mut get_conn(pool).await?;
conn
.build_transaction()
for domain in list {
// Upsert all of these as instances
- let instance = Instance::read_or_create_with_conn(conn, domain).await?;
+ let instance = Instance::read_or_create(&mut conn.into(), domain).await?;
let form = FederationAllowListForm {
instance_id: instance.id,
#[serial]
async fn test_allowlist_insert_and_clear() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let domains = vec![
"tld1.xyz".to_string(),
"tld2.xyz".to_string(),
use diesel_async::{AsyncPgConnection, RunQueryDsl};
impl FederationBlockList {
- pub async fn replace(pool: &DbPool, list_opt: Option<Vec<String>>) -> Result<(), Error> {
+ pub async fn replace(pool: &mut DbPool<'_>, list_opt: Option<Vec<String>>) -> Result<(), Error> {
let conn = &mut get_conn(pool).await?;
conn
.build_transaction()
for domain in list {
// Upsert all of these as instances
- let instance = Instance::read_or_create_with_conn(conn, domain).await?;
+ let instance = Instance::read_or_create(&mut conn.into(), domain).await?;
let form = FederationBlockListForm {
instance_id: instance.id,
utils::{get_conn, naive_now, DbPool},
};
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
-use diesel_async::{AsyncPgConnection, RunQueryDsl};
+use diesel_async::RunQueryDsl;
impl Instance {
- pub(crate) async fn read_or_create_with_conn(
- conn: &mut AsyncPgConnection,
- domain_: String,
- ) -> Result<Self, Error> {
+ /// Attempt to read Instance column for the given domain. If it doesnt exist, insert a new one.
+ /// There is no need for update as the domain of an existing instance cant change.
+ pub async fn read_or_create(pool: &mut DbPool<'_>, domain_: String) -> Result<Self, Error> {
use crate::schema::instance::domain;
+ let conn = &mut get_conn(pool).await?;
+
// First try to read the instance row and return directly if found
let instance = instance::table
.filter(domain.eq(&domain_))
e => e,
}
}
-
- /// Attempt to read Instance column for the given domain. If it doesnt exist, insert a new one.
- /// There is no need for update as the domain of an existing instance cant change.
- pub async fn read_or_create(pool: &DbPool, domain: String) -> Result<Self, Error> {
- let conn = &mut get_conn(pool).await?;
- Self::read_or_create_with_conn(conn, domain).await
- }
- pub async fn delete(pool: &DbPool, instance_id: InstanceId) -> Result<usize, Error> {
+ pub async fn delete(pool: &mut DbPool<'_>, instance_id: InstanceId) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(instance::table.find(instance_id))
.execute(conn)
.await
}
#[cfg(test)]
- pub async fn delete_all(pool: &DbPool) -> Result<usize, Error> {
+ pub async fn delete_all(pool: &mut DbPool<'_>) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(instance::table).execute(conn).await
}
- pub async fn allowlist(pool: &DbPool) -> Result<Vec<Self>, Error> {
+ pub async fn allowlist(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
instance::table
.inner_join(federation_allowlist::table)
.await
}
- pub async fn blocklist(pool: &DbPool) -> Result<Vec<Self>, Error> {
+ pub async fn blocklist(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
instance::table
.inner_join(federation_blocklist::table)
.await
}
- pub async fn linked(pool: &DbPool) -> Result<Vec<Self>, Error> {
+ pub async fn linked(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
instance::table
.left_join(federation_blocklist::table)
utils::{get_conn, DbPool},
};
use diesel::{result::Error, QueryDsl};
-use diesel_async::{AsyncPgConnection, RunQueryDsl};
+use diesel_async::RunQueryDsl;
impl Language {
- pub async fn read_all(pool: &DbPool) -> Result<Vec<Language>, Error> {
+ pub async fn read_all(pool: &mut DbPool<'_>) -> Result<Vec<Language>, Error> {
let conn = &mut get_conn(pool).await?;
- Self::read_all_conn(conn).await
- }
-
- pub async fn read_all_conn(conn: &mut AsyncPgConnection) -> Result<Vec<Language>, Error> {
language.load::<Self>(conn).await
}
- pub async fn read_from_id(pool: &DbPool, id_: LanguageId) -> Result<Language, Error> {
+ pub async fn read_from_id(pool: &mut DbPool<'_>, id_: LanguageId) -> Result<Language, Error> {
let conn = &mut get_conn(pool).await?;
language.filter(id.eq(id_)).first::<Self>(conn).await
}
/// Attempts to find the given language code and return its ID. If not found, returns none.
pub async fn read_id_from_code(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
code_: Option<&str>,
) -> Result<Option<LanguageId>, Error> {
if let Some(code_) = code_ {
#[serial]
async fn test_languages() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let all = Language::read_all(pool).await.unwrap();
use diesel_async::RunQueryDsl;
impl LocalSite {
- pub async fn create(pool: &DbPool, form: &LocalSiteInsertForm) -> Result<Self, Error> {
+ pub async fn create(pool: &mut DbPool<'_>, form: &LocalSiteInsertForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(local_site)
.values(form)
.get_result::<Self>(conn)
.await
}
- pub async fn read(pool: &DbPool) -> Result<Self, Error> {
+ pub async fn read(pool: &mut DbPool<'_>) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
local_site.first::<Self>(conn).await
}
- pub async fn update(pool: &DbPool, form: &LocalSiteUpdateForm) -> Result<Self, Error> {
+ pub async fn update(pool: &mut DbPool<'_>, form: &LocalSiteUpdateForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
diesel::update(local_site)
.set(form)
.get_result::<Self>(conn)
.await
}
- pub async fn delete(pool: &DbPool) -> Result<usize, Error> {
+ pub async fn delete(pool: &mut DbPool<'_>) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(local_site).execute(conn).await
}
use diesel_async::RunQueryDsl;
impl LocalSiteRateLimit {
- pub async fn read(pool: &DbPool) -> Result<Self, Error> {
+ pub async fn read(pool: &mut DbPool<'_>) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
local_site_rate_limit::table.first::<Self>(conn).await
}
- pub async fn create(pool: &DbPool, form: &LocalSiteRateLimitInsertForm) -> Result<Self, Error> {
+ pub async fn create(
+ pool: &mut DbPool<'_>,
+ form: &LocalSiteRateLimitInsertForm,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(local_site_rate_limit::table)
.values(form)
.get_result::<Self>(conn)
.await
}
- pub async fn update(pool: &DbPool, form: &LocalSiteRateLimitUpdateForm) -> Result<(), Error> {
+ pub async fn update(
+ pool: &mut DbPool<'_>,
+ form: &LocalSiteRateLimitUpdateForm,
+ ) -> Result<(), Error> {
// avoid error "There are no changes to save. This query cannot be built"
if form.is_empty() {
return Ok(());
impl LocalUser {
pub async fn update_password(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
local_user_id: LocalUserId,
new_password: &str,
) -> Result<Self, Error> {
.await
}
- pub async fn set_all_users_email_verified(pool: &DbPool) -> Result<Vec<Self>, Error> {
+ pub async fn set_all_users_email_verified(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
diesel::update(local_user)
.set(email_verified.eq(true))
}
pub async fn set_all_users_registration_applications_accepted(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
diesel::update(local_user)
.await
}
- pub async fn is_email_taken(pool: &DbPool, email_: &str) -> Result<bool, Error> {
+ pub async fn is_email_taken(pool: &mut DbPool<'_>, email_: &str) -> Result<bool, Error> {
use diesel::dsl::{exists, select};
let conn = &mut get_conn(pool).await?;
select(exists(local_user.filter(email.eq(email_))))
type InsertForm = LocalUserInsertForm;
type UpdateForm = LocalUserUpdateForm;
type IdType = LocalUserId;
- async fn read(pool: &DbPool, local_user_id: LocalUserId) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, local_user_id: LocalUserId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
local_user.find(local_user_id).first::<Self>(conn).await
}
- async fn delete(pool: &DbPool, local_user_id: LocalUserId) -> Result<usize, Error> {
+ async fn delete(pool: &mut DbPool<'_>, local_user_id: LocalUserId) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(local_user.find(local_user_id))
.execute(conn)
.await
}
- async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
let mut form_with_encrypted_password = form.clone();
let password_hash =
Ok(local_user_)
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
local_user_id: LocalUserId,
form: &Self::UpdateForm,
) -> Result<Self, Error> {
type InsertForm = ModRemovePostForm;
type UpdateForm = ModRemovePostForm;
type IdType = i32;
- async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_remove_post::dsl::mod_remove_post;
let conn = &mut get_conn(pool).await?;
mod_remove_post.find(from_id).first::<Self>(conn).await
}
- async fn create(pool: &DbPool, form: &ModRemovePostForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &ModRemovePostForm) -> Result<Self, Error> {
use crate::schema::mod_remove_post::dsl::mod_remove_post;
let conn = &mut get_conn(pool).await?;
insert_into(mod_remove_post)
.await
}
- async fn update(pool: &DbPool, from_id: i32, form: &ModRemovePostForm) -> Result<Self, Error> {
+ async fn update(
+ pool: &mut DbPool<'_>,
+ from_id: i32,
+ form: &ModRemovePostForm,
+ ) -> Result<Self, Error> {
use crate::schema::mod_remove_post::dsl::mod_remove_post;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_remove_post.find(from_id))
type InsertForm = ModLockPostForm;
type UpdateForm = ModLockPostForm;
type IdType = i32;
- async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_lock_post::dsl::mod_lock_post;
let conn = &mut get_conn(pool).await?;
mod_lock_post.find(from_id).first::<Self>(conn).await
}
- async fn create(pool: &DbPool, form: &ModLockPostForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &ModLockPostForm) -> Result<Self, Error> {
use crate::schema::mod_lock_post::dsl::mod_lock_post;
let conn = &mut get_conn(pool).await?;
insert_into(mod_lock_post)
.await
}
- async fn update(pool: &DbPool, from_id: i32, form: &ModLockPostForm) -> Result<Self, Error> {
+ async fn update(
+ pool: &mut DbPool<'_>,
+ from_id: i32,
+ form: &ModLockPostForm,
+ ) -> Result<Self, Error> {
use crate::schema::mod_lock_post::dsl::mod_lock_post;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_lock_post.find(from_id))
type InsertForm = ModFeaturePostForm;
type UpdateForm = ModFeaturePostForm;
type IdType = i32;
- async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_feature_post::dsl::mod_feature_post;
let conn = &mut get_conn(pool).await?;
mod_feature_post.find(from_id).first::<Self>(conn).await
}
- async fn create(pool: &DbPool, form: &ModFeaturePostForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &ModFeaturePostForm) -> Result<Self, Error> {
use crate::schema::mod_feature_post::dsl::mod_feature_post;
let conn = &mut get_conn(pool).await?;
insert_into(mod_feature_post)
.await
}
- async fn update(pool: &DbPool, from_id: i32, form: &ModFeaturePostForm) -> Result<Self, Error> {
+ async fn update(
+ pool: &mut DbPool<'_>,
+ from_id: i32,
+ form: &ModFeaturePostForm,
+ ) -> Result<Self, Error> {
use crate::schema::mod_feature_post::dsl::mod_feature_post;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_feature_post.find(from_id))
type InsertForm = ModRemoveCommentForm;
type UpdateForm = ModRemoveCommentForm;
type IdType = i32;
- async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
let conn = &mut get_conn(pool).await?;
mod_remove_comment.find(from_id).first::<Self>(conn).await
}
- async fn create(pool: &DbPool, form: &ModRemoveCommentForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &ModRemoveCommentForm) -> Result<Self, Error> {
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
let conn = &mut get_conn(pool).await?;
insert_into(mod_remove_comment)
.await
}
- async fn update(pool: &DbPool, from_id: i32, form: &ModRemoveCommentForm) -> Result<Self, Error> {
+ async fn update(
+ pool: &mut DbPool<'_>,
+ from_id: i32,
+ form: &ModRemoveCommentForm,
+ ) -> Result<Self, Error> {
use crate::schema::mod_remove_comment::dsl::mod_remove_comment;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_remove_comment.find(from_id))
type InsertForm = ModRemoveCommunityForm;
type UpdateForm = ModRemoveCommunityForm;
type IdType = i32;
- async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_remove_community::dsl::mod_remove_community;
let conn = &mut get_conn(pool).await?;
mod_remove_community.find(from_id).first::<Self>(conn).await
}
- async fn create(pool: &DbPool, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &ModRemoveCommunityForm) -> Result<Self, Error> {
use crate::schema::mod_remove_community::dsl::mod_remove_community;
let conn = &mut get_conn(pool).await?;
insert_into(mod_remove_community)
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
from_id: i32,
form: &ModRemoveCommunityForm,
) -> Result<Self, Error> {
type InsertForm = ModBanFromCommunityForm;
type UpdateForm = ModBanFromCommunityForm;
type IdType = i32;
- async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
let conn = &mut get_conn(pool).await?;
mod_ban_from_community
.await
}
- async fn create(pool: &DbPool, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &ModBanFromCommunityForm) -> Result<Self, Error> {
use crate::schema::mod_ban_from_community::dsl::mod_ban_from_community;
let conn = &mut get_conn(pool).await?;
insert_into(mod_ban_from_community)
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
from_id: i32,
form: &ModBanFromCommunityForm,
) -> Result<Self, Error> {
type InsertForm = ModBanForm;
type UpdateForm = ModBanForm;
type IdType = i32;
- async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_ban::dsl::mod_ban;
let conn = &mut get_conn(pool).await?;
mod_ban.find(from_id).first::<Self>(conn).await
}
- async fn create(pool: &DbPool, form: &ModBanForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &ModBanForm) -> Result<Self, Error> {
use crate::schema::mod_ban::dsl::mod_ban;
let conn = &mut get_conn(pool).await?;
insert_into(mod_ban)
.await
}
- async fn update(pool: &DbPool, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
+ async fn update(pool: &mut DbPool<'_>, from_id: i32, form: &ModBanForm) -> Result<Self, Error> {
use crate::schema::mod_ban::dsl::mod_ban;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_ban.find(from_id))
type UpdateForm = ModHideCommunityForm;
type IdType = i32;
- async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_hide_community::dsl::mod_hide_community;
let conn = &mut get_conn(pool).await?;
mod_hide_community.find(from_id).first::<Self>(conn).await
}
- async fn create(pool: &DbPool, form: &ModHideCommunityForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &ModHideCommunityForm) -> Result<Self, Error> {
use crate::schema::mod_hide_community::dsl::mod_hide_community;
let conn = &mut get_conn(pool).await?;
insert_into(mod_hide_community)
.await
}
- async fn update(pool: &DbPool, from_id: i32, form: &ModHideCommunityForm) -> Result<Self, Error> {
+ async fn update(
+ pool: &mut DbPool<'_>,
+ from_id: i32,
+ form: &ModHideCommunityForm,
+ ) -> Result<Self, Error> {
use crate::schema::mod_hide_community::dsl::mod_hide_community;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_hide_community.find(from_id))
type InsertForm = ModAddCommunityForm;
type UpdateForm = ModAddCommunityForm;
type IdType = i32;
- async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_add_community::dsl::mod_add_community;
let conn = &mut get_conn(pool).await?;
mod_add_community.find(from_id).first::<Self>(conn).await
}
- async fn create(pool: &DbPool, form: &ModAddCommunityForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &ModAddCommunityForm) -> Result<Self, Error> {
use crate::schema::mod_add_community::dsl::mod_add_community;
let conn = &mut get_conn(pool).await?;
insert_into(mod_add_community)
.await
}
- async fn update(pool: &DbPool, from_id: i32, form: &ModAddCommunityForm) -> Result<Self, Error> {
+ async fn update(
+ pool: &mut DbPool<'_>,
+ from_id: i32,
+ form: &ModAddCommunityForm,
+ ) -> Result<Self, Error> {
use crate::schema::mod_add_community::dsl::mod_add_community;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_add_community.find(from_id))
type InsertForm = ModTransferCommunityForm;
type UpdateForm = ModTransferCommunityForm;
type IdType = i32;
- async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
let conn = &mut get_conn(pool).await?;
mod_transfer_community
.await
}
- async fn create(pool: &DbPool, form: &ModTransferCommunityForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &ModTransferCommunityForm) -> Result<Self, Error> {
use crate::schema::mod_transfer_community::dsl::mod_transfer_community;
let conn = &mut get_conn(pool).await?;
insert_into(mod_transfer_community)
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
from_id: i32,
form: &ModTransferCommunityForm,
) -> Result<Self, Error> {
type InsertForm = ModAddForm;
type UpdateForm = ModAddForm;
type IdType = i32;
- async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, from_id: i32) -> Result<Self, Error> {
use crate::schema::mod_add::dsl::mod_add;
let conn = &mut get_conn(pool).await?;
mod_add.find(from_id).first::<Self>(conn).await
}
- async fn create(pool: &DbPool, form: &ModAddForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &ModAddForm) -> Result<Self, Error> {
use crate::schema::mod_add::dsl::mod_add;
let conn = &mut get_conn(pool).await?;
insert_into(mod_add)
.await
}
- async fn update(pool: &DbPool, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
+ async fn update(pool: &mut DbPool<'_>, from_id: i32, form: &ModAddForm) -> Result<Self, Error> {
use crate::schema::mod_add::dsl::mod_add;
let conn = &mut get_conn(pool).await?;
diesel::update(mod_add.find(from_id))
type InsertForm = AdminPurgePersonForm;
type UpdateForm = AdminPurgePersonForm;
type IdType = i32;
- async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, from_id: i32) -> Result<Self, Error> {
use crate::schema::admin_purge_person::dsl::admin_purge_person;
let conn = &mut get_conn(pool).await?;
admin_purge_person.find(from_id).first::<Self>(conn).await
}
- async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
use crate::schema::admin_purge_person::dsl::admin_purge_person;
let conn = &mut get_conn(pool).await?;
insert_into(admin_purge_person)
.await
}
- async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn update(
+ pool: &mut DbPool<'_>,
+ from_id: i32,
+ form: &Self::InsertForm,
+ ) -> Result<Self, Error> {
use crate::schema::admin_purge_person::dsl::admin_purge_person;
let conn = &mut get_conn(pool).await?;
diesel::update(admin_purge_person.find(from_id))
type InsertForm = AdminPurgeCommunityForm;
type UpdateForm = AdminPurgeCommunityForm;
type IdType = i32;
- async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, from_id: i32) -> Result<Self, Error> {
use crate::schema::admin_purge_community::dsl::admin_purge_community;
let conn = &mut get_conn(pool).await?;
admin_purge_community
.await
}
- async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
use crate::schema::admin_purge_community::dsl::admin_purge_community;
let conn = &mut get_conn(pool).await?;
insert_into(admin_purge_community)
.await
}
- async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn update(
+ pool: &mut DbPool<'_>,
+ from_id: i32,
+ form: &Self::InsertForm,
+ ) -> Result<Self, Error> {
use crate::schema::admin_purge_community::dsl::admin_purge_community;
let conn = &mut get_conn(pool).await?;
diesel::update(admin_purge_community.find(from_id))
type InsertForm = AdminPurgePostForm;
type UpdateForm = AdminPurgePostForm;
type IdType = i32;
- async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, from_id: i32) -> Result<Self, Error> {
use crate::schema::admin_purge_post::dsl::admin_purge_post;
let conn = &mut get_conn(pool).await?;
admin_purge_post.find(from_id).first::<Self>(conn).await
}
- async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
use crate::schema::admin_purge_post::dsl::admin_purge_post;
let conn = &mut get_conn(pool).await?;
insert_into(admin_purge_post)
.await
}
- async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn update(
+ pool: &mut DbPool<'_>,
+ from_id: i32,
+ form: &Self::InsertForm,
+ ) -> Result<Self, Error> {
use crate::schema::admin_purge_post::dsl::admin_purge_post;
let conn = &mut get_conn(pool).await?;
diesel::update(admin_purge_post.find(from_id))
type InsertForm = AdminPurgeCommentForm;
type UpdateForm = AdminPurgeCommentForm;
type IdType = i32;
- async fn read(pool: &DbPool, from_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, from_id: i32) -> Result<Self, Error> {
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
let conn = &mut get_conn(pool).await?;
admin_purge_comment.find(from_id).first::<Self>(conn).await
}
- async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
let conn = &mut get_conn(pool).await?;
insert_into(admin_purge_comment)
.await
}
- async fn update(pool: &DbPool, from_id: i32, form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn update(
+ pool: &mut DbPool<'_>,
+ from_id: i32,
+ form: &Self::InsertForm,
+ ) -> Result<Self, Error> {
use crate::schema::admin_purge_comment::dsl::admin_purge_comment;
let conn = &mut get_conn(pool).await?;
diesel::update(admin_purge_comment.find(from_id))
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
type InsertForm = PasswordResetRequestForm;
type UpdateForm = PasswordResetRequestForm;
type IdType = i32;
- async fn read(pool: &DbPool, password_reset_request_id: i32) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, password_reset_request_id: i32) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
password_reset_request
.find(password_reset_request_id)
.first::<Self>(conn)
.await
}
- async fn create(pool: &DbPool, form: &PasswordResetRequestForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &PasswordResetRequestForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(password_reset_request)
.values(form)
.await
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
password_reset_request_id: i32,
form: &PasswordResetRequestForm,
) -> Result<Self, Error> {
impl PasswordResetRequest {
pub async fn create_token(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
from_local_user_id: LocalUserId,
token: &str,
) -> Result<PasswordResetRequest, Error> {
Self::create(pool, &form).await
}
- pub async fn read_from_token(pool: &DbPool, token: &str) -> Result<PasswordResetRequest, Error> {
+ pub async fn read_from_token(
+ pool: &mut DbPool<'_>,
+ token: &str,
+ ) -> Result<PasswordResetRequest, Error> {
let conn = &mut get_conn(pool).await?;
let mut hasher = Sha256::new();
hasher.update(token);
}
pub async fn get_recent_password_resets_count(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
user_id: LocalUserId,
) -> Result<i64, Error> {
let conn = &mut get_conn(pool).await?;
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
type InsertForm = PersonInsertForm;
type UpdateForm = PersonUpdateForm;
type IdType = PersonId;
- async fn read(pool: &DbPool, person_id: PersonId) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
person::table
.filter(person::deleted.eq(false))
.first::<Self>(conn)
.await
}
- async fn delete(pool: &DbPool, person_id: PersonId) -> Result<usize, Error> {
+ async fn delete(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(person::table.find(person_id))
.execute(conn)
.await
}
- async fn create(pool: &DbPool, form: &PersonInsertForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &PersonInsertForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(person::table)
.values(form)
.await
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
person_id: PersonId,
form: &PersonUpdateForm,
) -> Result<Self, Error> {
/// Update or insert the person.
///
/// This is necessary for federation, because Activitypub doesnt distinguish between these actions.
- pub async fn upsert(pool: &DbPool, form: &PersonInsertForm) -> Result<Self, Error> {
+ pub async fn upsert(pool: &mut DbPool<'_>, form: &PersonInsertForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(person::table)
.values(form)
.get_result::<Self>(conn)
.await
}
- pub async fn delete_account(pool: &DbPool, person_id: PersonId) -> Result<Person, Error> {
+ pub async fn delete_account(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Person, Error> {
let conn = &mut get_conn(pool).await?;
// Set the local user info to none
#[async_trait]
impl ApubActor for Person {
- async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result<Option<Self>, Error> {
+ async fn read_from_apub_id(
+ pool: &mut DbPool<'_>,
+ object_id: &DbUrl,
+ ) -> Result<Option<Self>, Error> {
let conn = &mut get_conn(pool).await?;
Ok(
person::table
}
async fn read_from_name(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
from_name: &str,
include_deleted: bool,
) -> Result<Person, Error> {
}
async fn read_from_name_and_domain(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
person_name: &str,
for_domain: &str,
) -> Result<Person, Error> {
#[async_trait]
impl Followable for PersonFollower {
type Form = PersonFollowerForm;
- async fn follow(pool: &DbPool, form: &PersonFollowerForm) -> Result<Self, Error> {
+ async fn follow(pool: &mut DbPool<'_>, form: &PersonFollowerForm) -> Result<Self, Error> {
use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id};
let conn = &mut get_conn(pool).await?;
insert_into(person_follower)
.get_result::<Self>(conn)
.await
}
- async fn follow_accepted(_: &DbPool, _: CommunityId, _: PersonId) -> Result<Self, Error> {
+ async fn follow_accepted(_: &mut DbPool<'_>, _: CommunityId, _: PersonId) -> Result<Self, Error> {
unimplemented!()
}
- async fn unfollow(pool: &DbPool, form: &PersonFollowerForm) -> Result<usize, Error> {
+ async fn unfollow(pool: &mut DbPool<'_>, form: &PersonFollowerForm) -> Result<usize, Error> {
use crate::schema::person_follower::dsl::{follower_id, person_follower, person_id};
let conn = &mut get_conn(pool).await?;
diesel::delete(
impl PersonFollower {
pub async fn list_followers(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_person_id: PersonId,
) -> Result<Vec<Person>, Error> {
let conn = &mut get_conn(pool).await?;
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
#[serial]
async fn follow() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
.unwrap();
impl PersonBlock {
pub async fn read(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_person_id: PersonId,
for_recipient_id: PersonId,
) -> Result<Self, Error> {
#[async_trait]
impl Blockable for PersonBlock {
type Form = PersonBlockForm;
- async fn block(pool: &DbPool, person_block_form: &PersonBlockForm) -> Result<Self, Error> {
+ async fn block(
+ pool: &mut DbPool<'_>,
+ person_block_form: &PersonBlockForm,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(person_block)
.values(person_block_form)
.get_result::<Self>(conn)
.await
}
- async fn unblock(pool: &DbPool, person_block_form: &Self::Form) -> Result<usize, Error> {
+ async fn unblock(pool: &mut DbPool<'_>, person_block_form: &Self::Form) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(
person_block
type InsertForm = PersonMentionInsertForm;
type UpdateForm = PersonMentionUpdateForm;
type IdType = PersonMentionId;
- async fn read(pool: &DbPool, person_mention_id: PersonMentionId) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, person_mention_id: PersonMentionId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
person_mention
.find(person_mention_id)
.await
}
- async fn create(pool: &DbPool, person_mention_form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn create(
+ pool: &mut DbPool<'_>,
+ person_mention_form: &Self::InsertForm,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
// since the return here isnt utilized, we dont need to do an update
// but get_result doesnt return the existing row here
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
person_mention_id: PersonMentionId,
person_mention_form: &Self::UpdateForm,
) -> Result<Self, Error> {
impl PersonMention {
pub async fn mark_all_as_read(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_recipient_id: PersonId,
) -> Result<Vec<PersonMention>, Error> {
let conn = &mut get_conn(pool).await?;
}
pub async fn read_by_comment_and_person(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_comment_id: CommentId,
for_recipient_id: PersonId,
) -> Result<Self, Error> {
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
type InsertForm = PostInsertForm;
type UpdateForm = PostUpdateForm;
type IdType = PostId;
- async fn read(pool: &DbPool, post_id: PostId) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, post_id: PostId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
post.find(post_id).first::<Self>(conn).await
}
- async fn delete(pool: &DbPool, post_id: PostId) -> Result<usize, Error> {
+ async fn delete(pool: &mut DbPool<'_>, post_id: PostId) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(post.find(post_id)).execute(conn).await
}
- async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(post)
.values(form)
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
post_id: PostId,
new_post: &Self::UpdateForm,
) -> Result<Self, Error> {
impl Post {
pub async fn list_for_community(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
the_community_id: CommunityId,
) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
}
pub async fn list_featured_for_community(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
the_community_id: CommunityId,
) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
}
pub async fn permadelete_for_creator(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_creator_id: PersonId,
) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
}
pub async fn update_removed_for_creator(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_creator_id: PersonId,
for_community_id: Option<CommunityId>,
new_removed: bool,
person_id == post_creator_id
}
- pub async fn read_from_apub_id(pool: &DbPool, object_id: Url) -> Result<Option<Self>, Error> {
+ pub async fn read_from_apub_id(
+ pool: &mut DbPool<'_>,
+ object_id: Url,
+ ) -> Result<Option<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let object_id: DbUrl = object_id.into();
Ok(
}
pub async fn fetch_pictrs_posts_for_creator(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_creator_id: PersonId,
) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
/// Sets the url and thumbnails fields to None
pub async fn remove_pictrs_post_images_and_thumbnails_for_creator(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_creator_id: PersonId,
) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
}
pub async fn fetch_pictrs_posts_for_community(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_community_id: CommunityId,
) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
/// Sets the url and thumbnails fields to None
pub async fn remove_pictrs_post_images_and_thumbnails_for_community(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_community_id: CommunityId,
) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
impl Likeable for PostLike {
type Form = PostLikeForm;
type IdType = PostId;
- async fn like(pool: &DbPool, post_like_form: &PostLikeForm) -> Result<Self, Error> {
+ async fn like(pool: &mut DbPool<'_>, post_like_form: &PostLikeForm) -> Result<Self, Error> {
use crate::schema::post_like::dsl::{person_id, post_id, post_like};
let conn = &mut get_conn(pool).await?;
insert_into(post_like)
.get_result::<Self>(conn)
.await
}
- async fn remove(pool: &DbPool, person_id: PersonId, post_id: PostId) -> Result<usize, Error> {
+ async fn remove(
+ pool: &mut DbPool<'_>,
+ person_id: PersonId,
+ post_id: PostId,
+ ) -> Result<usize, Error> {
use crate::schema::post_like::dsl;
let conn = &mut get_conn(pool).await?;
diesel::delete(
#[async_trait]
impl Saveable for PostSaved {
type Form = PostSavedForm;
- async fn save(pool: &DbPool, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
+ async fn save(pool: &mut DbPool<'_>, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
use crate::schema::post_saved::dsl::{person_id, post_id, post_saved};
let conn = &mut get_conn(pool).await?;
insert_into(post_saved)
.get_result::<Self>(conn)
.await
}
- async fn unsave(pool: &DbPool, post_saved_form: &PostSavedForm) -> Result<usize, Error> {
+ async fn unsave(pool: &mut DbPool<'_>, post_saved_form: &PostSavedForm) -> Result<usize, Error> {
use crate::schema::post_saved::dsl::{person_id, post_id, post_saved};
let conn = &mut get_conn(pool).await?;
diesel::delete(
#[async_trait]
impl Readable for PostRead {
type Form = PostReadForm;
- async fn mark_as_read(pool: &DbPool, post_read_form: &PostReadForm) -> Result<Self, Error> {
+ async fn mark_as_read(
+ pool: &mut DbPool<'_>,
+ post_read_form: &PostReadForm,
+ ) -> Result<Self, Error> {
use crate::schema::post_read::dsl::{person_id, post_id, post_read};
let conn = &mut get_conn(pool).await?;
insert_into(post_read)
.await
}
- async fn mark_as_unread(pool: &DbPool, post_read_form: &PostReadForm) -> Result<usize, Error> {
+ async fn mark_as_unread(
+ pool: &mut DbPool<'_>,
+ post_read_form: &PostReadForm,
+ ) -> Result<usize, Error> {
use crate::schema::post_read::dsl::{person_id, post_id, post_read};
let conn = &mut get_conn(pool).await?;
diesel::delete(
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
type Form = PostReportForm;
type IdType = PostReportId;
- async fn report(pool: &DbPool, post_report_form: &PostReportForm) -> Result<Self, Error> {
+ async fn report(pool: &mut DbPool<'_>, post_report_form: &PostReportForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(post_report)
.values(post_report_form)
}
async fn resolve(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
report_id: Self::IdType,
by_resolver_id: PersonId,
) -> Result<usize, Error> {
}
async fn unresolve(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
report_id: Self::IdType,
by_resolver_id: PersonId,
) -> Result<usize, Error> {
type InsertForm = PrivateMessageInsertForm;
type UpdateForm = PrivateMessageUpdateForm;
type IdType = PrivateMessageId;
- async fn read(pool: &DbPool, private_message_id: PrivateMessageId) -> Result<Self, Error> {
+ async fn read(
+ pool: &mut DbPool<'_>,
+ private_message_id: PrivateMessageId,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
private_message
.find(private_message_id)
.await
}
- async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(private_message)
.values(form)
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
private_message_id: PrivateMessageId,
form: &Self::UpdateForm,
) -> Result<Self, Error> {
.get_result::<Self>(conn)
.await
}
- async fn delete(pool: &DbPool, pm_id: Self::IdType) -> Result<usize, Error> {
+ async fn delete(pool: &mut DbPool<'_>, pm_id: Self::IdType) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(private_message.find(pm_id))
.execute(conn)
impl PrivateMessage {
pub async fn mark_all_as_read(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_recipient_id: PersonId,
) -> Result<Vec<PrivateMessage>, Error> {
let conn = &mut get_conn(pool).await?;
}
pub async fn read_from_apub_id(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
object_id: Url,
) -> Result<Option<Self>, LemmyError> {
let conn = &mut get_conn(pool).await?;
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
type Form = PrivateMessageReportForm;
type IdType = PrivateMessageReportId;
- async fn report(pool: &DbPool, pm_report_form: &PrivateMessageReportForm) -> Result<Self, Error> {
+ async fn report(
+ pool: &mut DbPool<'_>,
+ pm_report_form: &PrivateMessageReportForm,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(private_message_report)
.values(pm_report_form)
}
async fn resolve(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
report_id: Self::IdType,
by_resolver_id: PersonId,
) -> Result<usize, Error> {
}
async fn unresolve(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
report_id: Self::IdType,
by_resolver_id: PersonId,
) -> Result<usize, Error> {
type UpdateForm = RegistrationApplicationUpdateForm;
type IdType = i32;
- async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
+ async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
insert_into(registration_application)
.values(form)
.await
}
- async fn read(pool: &DbPool, id_: Self::IdType) -> Result<Self, Error> {
+ async fn read(pool: &mut DbPool<'_>, id_: Self::IdType) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
registration_application.find(id_).first::<Self>(conn).await
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
id_: Self::IdType,
form: &Self::UpdateForm,
) -> Result<Self, Error> {
.await
}
- async fn delete(pool: &DbPool, id_: Self::IdType) -> Result<usize, Error> {
+ async fn delete(pool: &mut DbPool<'_>, id_: Self::IdType) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(registration_application.find(id_))
.execute(conn)
impl RegistrationApplication {
pub async fn find_by_local_user_id(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
local_user_id_: LocalUserId,
) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
impl Secret {
/// Initialize the Secrets from the DB.
/// Warning: You should only call this once.
- pub async fn init(pool: &DbPool) -> Result<Secret, Error> {
+ pub async fn init(pool: &mut DbPool<'_>) -> Result<Secret, Error> {
Self::read_secrets(pool).await
}
- async fn read_secrets(pool: &DbPool) -> Result<Secret, Error> {
+ async fn read_secrets(pool: &mut DbPool<'_>) -> Result<Secret, Error> {
let conn = &mut get_conn(pool).await?;
secret.first::<Secret>(conn).await
}
type IdType = SiteId;
/// Use SiteView::read_local, or Site::read_from_apub_id instead
- async fn read(_pool: &DbPool, _site_id: SiteId) -> Result<Self, Error> {
+ async fn read(_pool: &mut DbPool<'_>, _site_id: SiteId) -> Result<Self, Error> {
unimplemented!()
}
- async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
- let conn = &mut get_conn(pool).await?;
+ async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error> {
let is_new_site = match &form.actor_id {
Some(id_) => Site::read_from_apub_id(pool, id_).await?.is_none(),
None => true,
};
+ let conn = &mut get_conn(pool).await?;
// Can't do separate insert/update commands because InsertForm/UpdateForm aren't convertible
let site_ = insert_into(site)
}
async fn update(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
site_id: SiteId,
new_site: &Self::UpdateForm,
) -> Result<Self, Error> {
.await
}
- async fn delete(pool: &DbPool, site_id: SiteId) -> Result<usize, Error> {
+ async fn delete(pool: &mut DbPool<'_>, site_id: SiteId) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;
diesel::delete(site.find(site_id)).execute(conn).await
}
}
impl Site {
- pub async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result<Option<Self>, Error> {
+ pub async fn read_from_apub_id(
+ pool: &mut DbPool<'_>,
+ object_id: &DbUrl,
+ ) -> Result<Option<Self>, Error> {
let conn = &mut get_conn(pool).await?;
Ok(
site
}
// TODO this needs fixed
- pub async fn read_remote_sites(pool: &DbPool) -> Result<Vec<Self>, Error> {
+ pub async fn read_remote_sites(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
site.order_by(id).offset(1).get_results::<Self>(conn).await
}
impl Tagline {
pub async fn replace(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
for_local_site_id: LocalSiteId,
list_content: Option<Vec<String>>,
) -> Result<Vec<Self>, Error> {
.get_result::<Self>(conn)
.await?;
}
- Self::get_all_conn(conn, for_local_site_id).await
+ Self::get_all(&mut conn.into(), for_local_site_id).await
}) as _
})
.await
} else {
- Self::get_all_conn(conn, for_local_site_id).await
+ Self::get_all(&mut conn.into(), for_local_site_id).await
}
}
diesel::delete(tagline).execute(conn).await
}
- async fn get_all_conn(
- conn: &mut AsyncPgConnection,
+ pub async fn get_all(
+ pool: &mut DbPool<'_>,
for_local_site_id: LocalSiteId,
) -> Result<Vec<Self>, Error> {
+ let conn = &mut get_conn(pool).await?;
tagline
.filter(local_site_id.eq(for_local_site_id))
.get_results::<Self>(conn)
.await
}
- pub async fn get_all(pool: &DbPool, for_local_site_id: LocalSiteId) -> Result<Vec<Self>, Error> {
- let conn = &mut get_conn(pool).await?;
- Self::get_all_conn(conn, for_local_site_id).await
- }
}
type InsertForm;
type UpdateForm;
type IdType;
- async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error>
+ async fn create(pool: &mut DbPool<'_>, form: &Self::InsertForm) -> Result<Self, Error>
where
Self: Sized;
- async fn read(pool: &DbPool, id: Self::IdType) -> Result<Self, Error>
+ async fn read(pool: &mut DbPool<'_>, id: Self::IdType) -> Result<Self, Error>
where
Self: Sized;
/// when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column.
- async fn update(pool: &DbPool, id: Self::IdType, form: &Self::UpdateForm) -> Result<Self, Error>
+ async fn update(
+ pool: &mut DbPool<'_>,
+ id: Self::IdType,
+ form: &Self::UpdateForm,
+ ) -> Result<Self, Error>
where
Self: Sized;
- async fn delete(_pool: &DbPool, _id: Self::IdType) -> Result<usize, Error>
+ async fn delete(_pool: &mut DbPool<'_>, _id: Self::IdType) -> Result<usize, Error>
where
Self: Sized,
Self::IdType: Send,
#[async_trait]
pub trait Followable {
type Form;
- async fn follow(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
+ async fn follow(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error>
where
Self: Sized;
async fn follow_accepted(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
community_id: CommunityId,
person_id: PersonId,
) -> Result<Self, Error>
where
Self: Sized;
- async fn unfollow(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
+ async fn unfollow(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<usize, Error>
where
Self: Sized;
}
#[async_trait]
pub trait Joinable {
type Form;
- async fn join(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
+ async fn join(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error>
where
Self: Sized;
- async fn leave(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
+ async fn leave(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<usize, Error>
where
Self: Sized;
}
pub trait Likeable {
type Form;
type IdType;
- async fn like(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
+ async fn like(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error>
where
Self: Sized;
async fn remove(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
person_id: PersonId,
item_id: Self::IdType,
) -> Result<usize, Error>
#[async_trait]
pub trait Bannable {
type Form;
- async fn ban(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
+ async fn ban(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error>
where
Self: Sized;
- async fn unban(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
+ async fn unban(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<usize, Error>
where
Self: Sized;
}
#[async_trait]
pub trait Saveable {
type Form;
- async fn save(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
+ async fn save(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error>
where
Self: Sized;
- async fn unsave(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
+ async fn unsave(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<usize, Error>
where
Self: Sized;
}
#[async_trait]
pub trait Blockable {
type Form;
- async fn block(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
+ async fn block(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error>
where
Self: Sized;
- async fn unblock(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
+ async fn unblock(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<usize, Error>
where
Self: Sized;
}
#[async_trait]
pub trait Readable {
type Form;
- async fn mark_as_read(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
+ async fn mark_as_read(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error>
where
Self: Sized;
- async fn mark_as_unread(pool: &DbPool, form: &Self::Form) -> Result<usize, Error>
+ async fn mark_as_unread(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<usize, Error>
where
Self: Sized;
}
pub trait Reportable {
type Form;
type IdType;
- async fn report(pool: &DbPool, form: &Self::Form) -> Result<Self, Error>
+ async fn report(pool: &mut DbPool<'_>, form: &Self::Form) -> Result<Self, Error>
where
Self: Sized;
async fn resolve(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
report_id: Self::IdType,
resolver_id: PersonId,
) -> Result<usize, Error>
where
Self: Sized;
async fn unresolve(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
report_id: Self::IdType,
resolver_id: PersonId,
) -> Result<usize, Error>
#[async_trait]
pub trait ApubActor {
- async fn read_from_apub_id(pool: &DbPool, object_id: &DbUrl) -> Result<Option<Self>, Error>
+ async fn read_from_apub_id(
+ pool: &mut DbPool<'_>,
+ object_id: &DbUrl,
+ ) -> Result<Option<Self>, Error>
where
Self: Sized;
/// - actor_name is the name of the community or user to read.
/// - include_deleted, if true, will return communities or users that were deleted/removed
async fn read_from_name(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
actor_name: &str,
include_deleted: bool,
) -> Result<Self, Error>
where
Self: Sized;
async fn read_from_name_and_domain(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
actor_name: &str,
protocol_domain: &str,
) -> Result<Self, Error>
use std::{
env,
env::VarError,
+ ops::{Deref, DerefMut},
sync::Arc,
time::{Duration, SystemTime},
};
pub const FETCH_LIMIT_MAX: i64 = 50;
const POOL_TIMEOUT: Option<Duration> = Some(Duration::from_secs(5));
-pub type DbPool = Pool<AsyncPgConnection>;
+pub type ActualDbPool = Pool<AsyncPgConnection>;
-pub async fn get_conn(pool: &DbPool) -> Result<PooledConnection<AsyncPgConnection>, DieselError> {
- pool.get().await.map_err(|e| QueryBuilderError(e.into()))
+/// References a pool or connection. Functions must take `&mut DbPool<'_>` to allow implicit reborrowing.
+///
+/// https://github.com/rust-lang/rfcs/issues/1403
+pub enum DbPool<'a> {
+ Pool(&'a ActualDbPool),
+ Conn(&'a mut AsyncPgConnection),
+}
+
+pub enum DbConn<'a> {
+ Pool(PooledConnection<AsyncPgConnection>),
+ Conn(&'a mut AsyncPgConnection),
+}
+
+pub async fn get_conn<'a, 'b: 'a>(pool: &'a mut DbPool<'b>) -> Result<DbConn<'a>, DieselError> {
+ Ok(match pool {
+ DbPool::Pool(pool) => DbConn::Pool(pool.get().await.map_err(|e| QueryBuilderError(e.into()))?),
+ DbPool::Conn(conn) => DbConn::Conn(conn),
+ })
+}
+
+impl<'a> Deref for DbConn<'a> {
+ type Target = AsyncPgConnection;
+
+ fn deref(&self) -> &Self::Target {
+ match self {
+ DbConn::Pool(conn) => conn.deref(),
+ DbConn::Conn(conn) => conn.deref(),
+ }
+ }
+}
+
+impl<'a> DerefMut for DbConn<'a> {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ match self {
+ DbConn::Pool(conn) => conn.deref_mut(),
+ DbConn::Conn(conn) => conn.deref_mut(),
+ }
+ }
+}
+
+// Allows functions that take `DbPool<'_>` to be called in a transaction by passing `&mut conn.into()`
+impl<'a> From<&'a mut AsyncPgConnection> for DbPool<'a> {
+ fn from(value: &'a mut AsyncPgConnection) -> Self {
+ DbPool::Conn(value)
+ }
+}
+
+impl<'a, 'b: 'a> From<&'a mut DbConn<'b>> for DbPool<'a> {
+ fn from(value: &'a mut DbConn<'b>) -> Self {
+ DbPool::Conn(value.deref_mut())
+ }
+}
+
+impl<'a> From<&'a ActualDbPool> for DbPool<'a> {
+ fn from(value: &'a ActualDbPool) -> Self {
+ DbPool::Pool(value)
+ }
+}
+
+/// Runs multiple async functions that take `&mut DbPool<'_>` as input and return `Result`. Only works when the `futures` crate is listed in `Cargo.toml`.
+///
+/// `$pool` is the value given to each function.
+///
+/// A `Result` is returned (not in a `Future`, so don't use `.await`). The `Ok` variant contains a tuple with the values returned by the given functions.
+///
+/// The functions run concurrently if `$pool` has the `DbPool::Pool` variant.
+#[macro_export]
+macro_rules! try_join_with_pool {
+ ($pool:ident => ($($func:expr),+)) => {{
+ // Check type
+ let _: &mut $crate::utils::DbPool<'_> = $pool;
+
+ match $pool {
+ // Run concurrently with `try_join`
+ $crate::utils::DbPool::Pool(__pool) => ::futures::try_join!(
+ $(async {
+ let mut __dbpool = $crate::utils::DbPool::Pool(__pool);
+ ($func)(&mut __dbpool).await
+ }),+
+ ),
+ // Run sequentially
+ $crate::utils::DbPool::Conn(__conn) => async {
+ Ok(($({
+ let mut __dbpool = $crate::utils::DbPool::Conn(__conn);
+ // `?` prevents the error type from being inferred in an `async` block, so `match` is used instead
+ match ($func)(&mut __dbpool).await {
+ ::core::result::Result::Ok(__v) => __v,
+ ::core::result::Result::Err(__v) => return ::core::result::Result::Err(__v),
+ }
+ }),+))
+ }.await,
+ }
+ }};
}
pub fn get_database_url_from_env() -> Result<String, VarError> {
}
}
-async fn build_db_pool_settings_opt(settings: Option<&Settings>) -> Result<DbPool, LemmyError> {
+async fn build_db_pool_settings_opt(
+ settings: Option<&Settings>,
+) -> Result<ActualDbPool, LemmyError> {
let db_url = get_database_url(settings);
let pool_size = settings.map(|s| s.database.pool_size).unwrap_or(5);
// We only support TLS with sslmode=require currently
info!("Database migrations complete.");
}
-pub async fn build_db_pool(settings: &Settings) -> Result<DbPool, LemmyError> {
+pub async fn build_db_pool(settings: &Settings) -> Result<ActualDbPool, LemmyError> {
build_db_pool_settings_opt(Some(settings)).await
}
-pub async fn build_db_pool_for_tests() -> DbPool {
+pub async fn build_db_pool_for_tests() -> ActualDbPool {
build_db_pool_settings_opt(None)
.await
.expect("db pool missing")
///
/// * `report_id` - the report id to obtain
pub async fn read(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
report_id: CommentReportId,
my_person_id: PersonId,
) -> Result<Self, Error> {
/// Returns the current unresolved post report count for the communities you mod
pub async fn get_report_count(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
my_person_id: PersonId,
admin: bool,
community_id: Option<CommunityId>,
#[derive(TypedBuilder)]
#[builder(field_defaults(default))]
-pub struct CommentReportQuery<'a> {
+pub struct CommentReportQuery<'a, 'b: 'a> {
#[builder(!default)]
- pool: &'a DbPool,
+ pool: &'a mut DbPool<'b>,
#[builder(!default)]
my_person_id: PersonId,
#[builder(!default)]
unresolved_only: Option<bool>,
}
-impl<'a> CommentReportQuery<'a> {
+impl<'a, 'b: 'a> CommentReportQuery<'a, 'b> {
pub async fn list(self) -> Result<Vec<CommentReportView>, Error> {
let conn = &mut get_conn(self.pool).await?;
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
impl CommentView {
pub async fn read(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
comment_id: CommentId,
my_person_id: Option<PersonId>,
) -> Result<Self, Error> {
#[derive(TypedBuilder)]
#[builder(field_defaults(default))]
-pub struct CommentQuery<'a> {
+pub struct CommentQuery<'a, 'b: 'a> {
#[builder(!default)]
- pool: &'a DbPool,
+ pool: &'a mut DbPool<'b>,
listing_type: Option<ListingType>,
sort: Option<CommentSortType>,
community_id: Option<CommunityId>,
max_depth: Option<i32>,
}
-impl<'a> CommentQuery<'a> {
+impl<'a, 'b: 'a> CommentQuery<'a, 'b> {
pub async fn list(self) -> Result<Vec<CommentView>, Error> {
let conn = &mut get_conn(self.pool).await?;
inserted_community: Community,
}
- async fn init_data(pool: &DbPool) -> Data {
+ async fn init_data(pool: &mut DbPool<'_>) -> Data {
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
.unwrap();
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let data = init_data(pool).await;
let expected_comment_view_no_person = expected_comment_view(&data, pool).await;
#[serial]
async fn test_comment_tree() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let data = init_data(pool).await;
let top_path = data.inserted_comment_0.path.clone();
#[serial]
async fn test_languages() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let data = init_data(pool).await;
// by default, user has all languages enabled and should see all comments
cleanup(data, pool).await;
}
- async fn cleanup(data: Data, pool: &DbPool) {
+ async fn cleanup(data: Data, pool: &mut DbPool<'_>) {
CommentLike::remove(pool, data.inserted_person.id, data.inserted_comment_0.id)
.await
.unwrap();
.unwrap();
}
- async fn expected_comment_view(data: &Data, pool: &DbPool) -> CommentView {
+ async fn expected_comment_view(data: &Data, pool: &mut DbPool<'_>) -> CommentView {
let agg = CommentAggregates::read(pool, data.inserted_comment_0.id)
.await
.unwrap();
type CustomEmojiTuple = (CustomEmoji, Option<CustomEmojiKeyword>);
impl CustomEmojiView {
- pub async fn get(pool: &DbPool, emoji_id: CustomEmojiId) -> Result<Self, Error> {
+ pub async fn get(pool: &mut DbPool<'_>, emoji_id: CustomEmojiId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
let emojis = custom_emoji::table
.find(emoji_id)
}
}
- pub async fn get_all(pool: &DbPool, for_local_site_id: LocalSiteId) -> Result<Vec<Self>, Error> {
+ pub async fn get_all(
+ pool: &mut DbPool<'_>,
+ for_local_site_id: LocalSiteId,
+ ) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let emojis = custom_emoji::table
.filter(custom_emoji::local_site_id.eq(for_local_site_id))
type LocalUserViewTuple = (LocalUser, Person, PersonAggregates);
impl LocalUserView {
- pub async fn read(pool: &DbPool, local_user_id: LocalUserId) -> Result<Self, Error> {
+ pub async fn read(pool: &mut DbPool<'_>, local_user_id: LocalUserId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
let (local_user, person, counts) = local_user::table
})
}
- pub async fn read_person(pool: &DbPool, person_id: PersonId) -> Result<Self, Error> {
+ pub async fn read_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
let (local_user, person, counts) = local_user::table
.filter(person::id.eq(person_id))
})
}
- pub async fn read_from_name(pool: &DbPool, name: &str) -> Result<Self, Error> {
+ pub async fn read_from_name(pool: &mut DbPool<'_>, name: &str) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
let (local_user, person, counts) = local_user::table
.filter(lower(person::name).eq(name.to_lowercase()))
})
}
- pub async fn find_by_email_or_name(pool: &DbPool, name_or_email: &str) -> Result<Self, Error> {
+ pub async fn find_by_email_or_name(
+ pool: &mut DbPool<'_>,
+ name_or_email: &str,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
let (local_user, person, counts) = local_user::table
.inner_join(person::table)
})
}
- pub async fn find_by_email(pool: &DbPool, from_email: &str) -> Result<Self, Error> {
+ pub async fn find_by_email(pool: &mut DbPool<'_>, from_email: &str) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
let (local_user, person, counts) = local_user::table
.inner_join(person::table)
})
}
- pub async fn list_admins_with_emails(pool: &DbPool) -> Result<Vec<Self>, Error> {
+ pub async fn list_admins_with_emails(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let res = local_user::table
.filter(person::admin.eq(true))
///
/// * `report_id` - the report id to obtain
pub async fn read(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
report_id: PostReportId,
my_person_id: PersonId,
) -> Result<Self, Error> {
/// returns the current unresolved post report count for the communities you mod
pub async fn get_report_count(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
my_person_id: PersonId,
admin: bool,
community_id: Option<CommunityId>,
#[derive(TypedBuilder)]
#[builder(field_defaults(default))]
-pub struct PostReportQuery<'a> {
+pub struct PostReportQuery<'a, 'b: 'a> {
#[builder(!default)]
- pool: &'a DbPool,
+ pool: &'a mut DbPool<'b>,
#[builder(!default)]
my_person_id: PersonId,
#[builder(!default)]
unresolved_only: Option<bool>,
}
-impl<'a> PostReportQuery<'a> {
+impl<'a, 'b: 'a> PostReportQuery<'a, 'b> {
pub async fn list(self) -> Result<Vec<PostReportView>, Error> {
let conn = &mut get_conn(self.pool).await?;
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
impl PostView {
pub async fn read(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
post_id: PostId,
my_person_id: Option<PersonId>,
is_mod_or_admin: Option<bool>,
#[derive(TypedBuilder)]
#[builder(field_defaults(default))]
-pub struct PostQuery<'a> {
+pub struct PostQuery<'a, 'b: 'a> {
#[builder(!default)]
- pool: &'a DbPool,
+ pool: &'a mut DbPool<'b>,
listing_type: Option<ListingType>,
sort: Option<SortType>,
creator_id: Option<PersonId>,
limit: Option<i64>,
}
-impl<'a> PostQuery<'a> {
+impl<'a, 'b: 'a> PostQuery<'a, 'b> {
pub async fn list(self) -> Result<Vec<PostView>, Error> {
let conn = &mut get_conn(self.pool).await?;
inserted_post: Post,
}
- async fn init_data(pool: &DbPool) -> Data {
+ async fn init_data(pool: &mut DbPool<'_>) -> Data {
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
.unwrap();
#[serial]
async fn post_listing_with_person() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let data = init_data(pool).await;
let local_user_form = LocalUserUpdateForm::builder()
#[serial]
async fn post_listing_no_person() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let data = init_data(pool).await;
let read_post_listing_multiple_no_person = PostQuery::builder()
#[serial]
async fn post_listing_block_community() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let data = init_data(pool).await;
let community_block = CommunityBlockForm {
#[serial]
async fn post_listing_like() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let data = init_data(pool).await;
let post_like_form = PostLikeForm {
#[serial]
async fn post_listing_person_language() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let data = init_data(pool).await;
let spanish_id = Language::read_id_from_code(pool, Some("es"))
#[serial]
async fn post_listings_deleted() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let data = init_data(pool).await;
// Delete the post
cleanup(data, pool).await;
}
- async fn cleanup(data: Data, pool: &DbPool) {
+ async fn cleanup(data: Data, pool: &mut DbPool<'_>) {
let num_deleted = Post::delete(pool, data.inserted_post.id).await.unwrap();
Community::delete(pool, data.inserted_community.id)
.await
assert_eq!(1, num_deleted);
}
- async fn expected_post_view(data: &Data, pool: &DbPool) -> PostView {
+ async fn expected_post_view(data: &Data, pool: &mut DbPool<'_>) -> PostView {
let (inserted_person, inserted_community, inserted_post) = (
&data.inserted_person,
&data.inserted_community,
/// returns the PrivateMessageReportView for the provided report_id
///
/// * `report_id` - the report id to obtain
- pub async fn read(pool: &DbPool, report_id: PrivateMessageReportId) -> Result<Self, Error> {
+ pub async fn read(
+ pool: &mut DbPool<'_>,
+ report_id: PrivateMessageReportId,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
}
/// Returns the current unresolved post report count for the communities you mod
- pub async fn get_report_count(pool: &DbPool) -> Result<i64, Error> {
+ pub async fn get_report_count(pool: &mut DbPool<'_>) -> Result<i64, Error> {
use diesel::dsl::count;
let conn = &mut get_conn(pool).await?;
#[derive(TypedBuilder)]
#[builder(field_defaults(default))]
-pub struct PrivateMessageReportQuery<'a> {
+pub struct PrivateMessageReportQuery<'a, 'b: 'a> {
#[builder(!default)]
- pool: &'a DbPool,
+ pool: &'a mut DbPool<'b>,
page: Option<i64>,
limit: Option<i64>,
unresolved_only: Option<bool>,
}
-impl<'a> PrivateMessageReportQuery<'a> {
+impl<'a, 'b: 'a> PrivateMessageReportQuery<'a, 'b> {
pub async fn list(self) -> Result<Vec<PrivateMessageReportView>, Error> {
let conn = &mut get_conn(self.pool).await?;
let (person_alias_1, person_alias_2) = diesel::alias!(person as person1, person as person2);
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
type PrivateMessageViewTuple = (PrivateMessage, Person, Person);
impl PrivateMessageView {
- pub async fn read(pool: &DbPool, private_message_id: PrivateMessageId) -> Result<Self, Error> {
+ pub async fn read(
+ pool: &mut DbPool<'_>,
+ private_message_id: PrivateMessageId,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
}
/// Gets the number of unread messages
- pub async fn get_unread_messages(pool: &DbPool, my_person_id: PersonId) -> Result<i64, Error> {
+ pub async fn get_unread_messages(
+ pool: &mut DbPool<'_>,
+ my_person_id: PersonId,
+ ) -> Result<i64, Error> {
use diesel::dsl::count;
let conn = &mut get_conn(pool).await?;
private_message::table
#[derive(TypedBuilder)]
#[builder(field_defaults(default))]
-pub struct PrivateMessageQuery<'a> {
+pub struct PrivateMessageQuery<'a, 'b: 'a> {
#[builder(!default)]
- pool: &'a DbPool,
+ pool: &'a mut DbPool<'b>,
#[builder(!default)]
recipient_id: PersonId,
unread_only: Option<bool>,
limit: Option<i64>,
}
-impl<'a> PrivateMessageQuery<'a> {
+impl<'a, 'b: 'a> PrivateMessageQuery<'a, 'b> {
pub async fn list(self) -> Result<Vec<PrivateMessageView>, Error> {
let conn = &mut get_conn(self.pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
(RegistrationApplication, LocalUser, Person, Option<Person>);
impl RegistrationApplicationView {
- pub async fn read(pool: &DbPool, registration_application_id: i32) -> Result<Self, Error> {
+ pub async fn read(
+ pool: &mut DbPool<'_>,
+ registration_application_id: i32,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
}
/// Returns the current unread registration_application count
- pub async fn get_unread_count(pool: &DbPool, verified_email_only: bool) -> Result<i64, Error> {
+ pub async fn get_unread_count(
+ pool: &mut DbPool<'_>,
+ verified_email_only: bool,
+ ) -> Result<i64, Error> {
let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
#[derive(TypedBuilder)]
#[builder(field_defaults(default))]
-pub struct RegistrationApplicationQuery<'a> {
+pub struct RegistrationApplicationQuery<'a, 'b: 'a> {
#[builder(!default)]
- pool: &'a DbPool,
+ pool: &'a mut DbPool<'b>,
unread_only: Option<bool>,
verified_email_only: Option<bool>,
page: Option<i64>,
limit: Option<i64>,
}
-impl<'a> RegistrationApplicationQuery<'a> {
+impl<'a, 'b: 'a> RegistrationApplicationQuery<'a, 'b> {
pub async fn list(self) -> Result<Vec<RegistrationApplicationView>, Error> {
let conn = &mut get_conn(self.pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
};
impl SiteView {
- pub async fn read_local(pool: &DbPool) -> Result<Self, Error> {
+ pub async fn read_local(pool: &mut DbPool<'_>) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
let (mut site, local_site, local_site_rate_limit, counts) = site::table
.inner_join(local_site::table)
impl CommentReplyView {
pub async fn read(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
comment_reply_id: CommentReplyId,
my_person_id: Option<PersonId>,
) -> Result<Self, Error> {
}
/// Gets the number of unread replies
- pub async fn get_unread_replies(pool: &DbPool, my_person_id: PersonId) -> Result<i64, Error> {
+ pub async fn get_unread_replies(
+ pool: &mut DbPool<'_>,
+ my_person_id: PersonId,
+ ) -> Result<i64, Error> {
use diesel::dsl::count;
let conn = &mut get_conn(pool).await?;
#[derive(TypedBuilder)]
#[builder(field_defaults(default))]
-pub struct CommentReplyQuery<'a> {
+pub struct CommentReplyQuery<'a, 'b: 'a> {
#[builder(!default)]
- pool: &'a DbPool,
+ pool: &'a mut DbPool<'b>,
my_person_id: Option<PersonId>,
recipient_id: Option<PersonId>,
sort: Option<CommentSortType>,
limit: Option<i64>,
}
-impl<'a> CommentReplyQuery<'a> {
+impl<'a, 'b: 'a> CommentReplyQuery<'a, 'b> {
pub async fn list(self) -> Result<Vec<CommentReplyView>, Error> {
let conn = &mut get_conn(self.pool).await?;
type CommunityBlockViewTuple = (Person, Community);
impl CommunityBlockView {
- pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result<Vec<Self>, Error> {
+ pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let res = community_block::table
.inner_join(person::table)
impl CommunityFollowerView {
pub async fn get_community_follower_inboxes(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
community_id: CommunityId,
) -> Result<Vec<DbUrl>, Error> {
let conn = &mut get_conn(pool).await?;
Ok(res)
}
pub async fn count_community_followers(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
community_id: CommunityId,
) -> Result<i64, Error> {
let conn = &mut get_conn(pool).await?;
Ok(res)
}
- pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result<Vec<Self>, Error> {
+ pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let res = community_follower::table
.inner_join(community::table)
impl CommunityModeratorView {
pub async fn is_community_moderator(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
find_community_id: CommunityId,
find_person_id: PersonId,
) -> Result<bool, Error> {
.get_result::<bool>(conn)
.await
}
- pub async fn for_community(pool: &DbPool, community_id: CommunityId) -> Result<Vec<Self>, Error> {
+ pub async fn for_community(
+ pool: &mut DbPool<'_>,
+ community_id: CommunityId,
+ ) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let res = community_moderator::table
.inner_join(community::table)
Ok(res.into_iter().map(Self::from_tuple).collect())
}
- pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result<Vec<Self>, Error> {
+ pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let res = community_moderator::table
.inner_join(community::table)
/// Finds all communities first mods / creators
/// Ideally this should be a group by, but diesel doesn't support it yet
- pub async fn get_community_first_mods(pool: &DbPool) -> Result<Vec<Self>, Error> {
+ pub async fn get_community_first_mods(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let res = community_moderator::table
.inner_join(community::table)
impl CommunityPersonBanView {
pub async fn get(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
from_person_id: PersonId,
from_community_id: CommunityId,
) -> Result<Self, Error> {
impl CommunityView {
pub async fn read(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
community_id: CommunityId,
my_person_id: Option<PersonId>,
is_mod_or_admin: Option<bool>,
}
pub async fn is_mod_or_admin(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
person_id: PersonId,
community_id: CommunityId,
) -> Result<bool, Error> {
#[derive(TypedBuilder)]
#[builder(field_defaults(default))]
-pub struct CommunityQuery<'a> {
+pub struct CommunityQuery<'a, 'b: 'a> {
#[builder(!default)]
- pool: &'a DbPool,
+ pool: &'a mut DbPool<'b>,
listing_type: Option<ListingType>,
sort: Option<SortType>,
local_user: Option<&'a LocalUser>,
limit: Option<i64>,
}
-impl<'a> CommunityQuery<'a> {
+impl<'a, 'b: 'a> CommunityQuery<'a, 'b> {
pub async fn list(self) -> Result<Vec<CommunityView>, Error> {
use SortType::*;
type PersonBlockViewTuple = (Person, Person);
impl PersonBlockView {
- pub async fn for_person(pool: &DbPool, person_id: PersonId) -> Result<Vec<Self>, Error> {
+ pub async fn for_person(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let target_person_alias = diesel::alias!(person as person1);
impl PersonMentionView {
pub async fn read(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
person_mention_id: PersonMentionId,
my_person_id: Option<PersonId>,
) -> Result<Self, Error> {
}
/// Gets the number of unread mentions
- pub async fn get_unread_mentions(pool: &DbPool, my_person_id: PersonId) -> Result<i64, Error> {
+ pub async fn get_unread_mentions(
+ pool: &mut DbPool<'_>,
+ my_person_id: PersonId,
+ ) -> Result<i64, Error> {
use diesel::dsl::count;
let conn = &mut get_conn(pool).await?;
#[derive(TypedBuilder)]
#[builder(field_defaults(default))]
-pub struct PersonMentionQuery<'a> {
+pub struct PersonMentionQuery<'a, 'b: 'a> {
#[builder(!default)]
- pool: &'a DbPool,
+ pool: &'a mut DbPool<'b>,
my_person_id: Option<PersonId>,
recipient_id: Option<PersonId>,
sort: Option<CommentSortType>,
limit: Option<i64>,
}
-impl<'a> PersonMentionQuery<'a> {
+impl<'a, 'b: 'a> PersonMentionQuery<'a, 'b> {
pub async fn list(self) -> Result<Vec<PersonMentionView>, Error> {
let conn = &mut get_conn(self.pool).await?;
type PersonViewTuple = (Person, PersonAggregates);
impl PersonView {
- pub async fn read(pool: &DbPool, person_id: PersonId) -> Result<Self, Error> {
+ pub async fn read(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
let res = person::table
.find(person_id)
Ok(Self::from_tuple(res))
}
- pub async fn is_admin(pool: &DbPool, person_id: PersonId) -> Result<bool, Error> {
+ pub async fn is_admin(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<bool, Error> {
use schema::person::dsl::{admin, id, person};
let conn = &mut get_conn(pool).await?;
let is_admin = person
.await?;
Ok(is_admin)
}
- pub async fn admins(pool: &DbPool) -> Result<Vec<Self>, Error> {
+ pub async fn admins(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let admins = person::table
.inner_join(person_aggregates::table)
Ok(admins.into_iter().map(Self::from_tuple).collect())
}
- pub async fn banned(pool: &DbPool) -> Result<Vec<Self>, Error> {
+ pub async fn banned(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let banned = person::table
.inner_join(person_aggregates::table)
#[derive(TypedBuilder)]
#[builder(field_defaults(default))]
-pub struct PersonQuery<'a> {
+pub struct PersonQuery<'a, 'b: 'a> {
#[builder(!default)]
- pool: &'a DbPool,
+ pool: &'a mut DbPool<'b>,
sort: Option<SortType>,
search_term: Option<String>,
page: Option<i64>,
limit: Option<i64>,
}
-impl<'a> PersonQuery<'a> {
+impl<'a, 'b: 'a> PersonQuery<'a, 'b> {
pub async fn list(self) -> Result<Vec<PersonView>, Error> {
let conn = &mut get_conn(self.pool).await?;
let mut query = person::table
type AdminPurgeCommentViewTuple = (AdminPurgeComment, Option<Person>, Post);
impl AdminPurgeCommentView {
- pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
let show_mod_names = !params.hide_modlog_names;
type AdminPurgeCommunityViewTuple = (AdminPurgeCommunity, Option<Person>);
impl AdminPurgeCommunityView {
- pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
let show_mod_names = !params.hide_modlog_names;
type AdminPurgePersonViewTuple = (AdminPurgePerson, Option<Person>);
impl AdminPurgePersonView {
- pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
type AdminPurgePostViewTuple = (AdminPurgePost, Option<Person>, Community);
impl AdminPurgePostView {
- pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
type ModAddCommunityViewTuple = (ModAddCommunity, Option<Person>, Community, Person);
impl ModAddCommunityView {
- pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
type ModAddViewTuple = (ModAdd, Option<Person>, Person);
impl ModAddView {
- pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
type ModBanFromCommunityViewTuple = (ModBanFromCommunity, Option<Person>, Community, Person);
impl ModBanFromCommunityView {
- pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
type ModBanViewTuple = (ModBan, Option<Person>, Person);
impl ModBanView {
- pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
type ModFeaturePostViewTuple = (ModFeaturePost, Option<Person>, Post, Community);
impl ModFeaturePostView {
- pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
impl ModHideCommunityView {
// Pass in mod_id as admin_id because only admins can do this action
- pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
type ModLockPostViewTuple = (ModLockPost, Option<Person>, Post, Community);
impl ModLockPostView {
- pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
);
impl ModRemoveCommentView {
- pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(lemmy_db_schema::schema::person as person1);
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
type ModRemoveCommunityTuple = (ModRemoveCommunity, Option<Person>, Community);
impl ModRemoveCommunityView {
- pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let admin_person_id_join = params.mod_person_id.unwrap_or(PersonId(-1));
let show_mod_names = !params.hide_modlog_names;
type ModRemovePostViewTuple = (ModRemovePost, Option<Person>, Post, Community);
impl ModRemovePostView {
- pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
type ModTransferCommunityViewTuple = (ModTransferCommunity, Option<Person>, Community, Person);
impl ModTransferCommunityView {
- pub async fn list(pool: &DbPool, params: ModlogListParams) -> Result<Vec<Self>, Error> {
+ pub async fn list(pool: &mut DbPool<'_>, params: ModlogListParams) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
limit: i64,
page: i64,
) -> Result<HttpResponse, LemmyError> {
- let site_view = SiteView::read_local(context.pool()).await?;
+ let site_view = SiteView::read_local(&mut context.pool()).await?;
let posts = PostQuery::builder()
- .pool(context.pool())
+ .pool(&mut context.pool())
.listing_type(Some(listing_type))
.sort(Some(sort_type))
.limit(Some(limit))
let builder = match request_type {
RequestType::User => {
get_feed_user(
- context.pool(),
+ &mut context.pool(),
&info.sort_type()?,
&info.get_limit(),
&info.get_page(),
}
RequestType::Community => {
get_feed_community(
- context.pool(),
+ &mut context.pool(),
&info.sort_type()?,
&info.get_limit(),
&info.get_page(),
}
RequestType::Front => {
get_feed_front(
- context.pool(),
+ &mut context.pool(),
&jwt_secret,
&info.sort_type()?,
&info.get_limit(),
.await
}
RequestType::Inbox => {
- get_feed_inbox(context.pool(), &jwt_secret, ¶m, &protocol_and_hostname).await
+ get_feed_inbox(
+ &mut context.pool(),
+ &jwt_secret,
+ ¶m,
+ &protocol_and_hostname,
+ )
+ .await
}
}
.map_err(ErrorBadRequest)?;
#[tracing::instrument(skip_all)]
async fn get_feed_user(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
sort_type: &SortType,
limit: &i64,
page: &i64,
#[tracing::instrument(skip_all)]
async fn get_feed_community(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
sort_type: &SortType,
limit: &i64,
page: &i64,
#[tracing::instrument(skip_all)]
async fn get_feed_front(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
jwt_secret: &str,
sort_type: &SortType,
limit: &i64,
#[tracing::instrument(skip_all)]
async fn get_feed_inbox(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
jwt_secret: &str,
jwt: &str,
protocol_and_hostname: &str,
context: web::Data<LemmyContext>,
) -> Result<HttpResponse, Error> {
// block access to images if instance is private and unauthorized, public
- let local_site = LocalSite::read(context.pool())
+ let local_site = LocalSite::read(&mut context.pool())
.await
.map_err(error::ErrorBadRequest)?;
if local_site.private_instance {
}
async fn node_info(context: web::Data<LemmyContext>) -> Result<HttpResponse, Error> {
- let site_view = SiteView::read_local(context.pool())
+ let site_view = SiteView::read_local(&mut context.pool())
.await
.map_err(|_| ErrorBadRequest(LemmyError::from(anyhow!("not_found"))))?;
let name = extract_webfinger_name(&info.resource, &context)?;
let name_ = name.clone();
- let user_id: Option<Url> = Person::read_from_name(context.pool(), &name_, false)
+ let user_id: Option<Url> = Person::read_from_name(&mut context.pool(), &name_, false)
.await
.ok()
.map(|c| c.actor_id.into());
- let community_id: Option<Url> = Community::read_from_name(context.pool(), &name, false)
+ let community_id: Option<Url> = Community::read_from_name(&mut context.pool(), &name, false)
.await
.ok()
.map(|c| c.actor_id.into());
use tracing::info;
use url::Url;
-pub async fn run_advanced_migrations(pool: &DbPool, settings: &Settings) -> Result<(), LemmyError> {
+pub async fn run_advanced_migrations(
+ pool: &mut DbPool<'_>,
+ settings: &Settings,
+) -> Result<(), LemmyError> {
let protocol_and_hostname = &settings.get_protocol_and_hostname();
user_updates_2020_04_02(pool, protocol_and_hostname).await?;
community_updates_2020_04_02(pool, protocol_and_hostname).await?;
}
async fn user_updates_2020_04_02(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
protocol_and_hostname: &str,
) -> Result<(), LemmyError> {
use lemmy_db_schema::schema::person::dsl::{actor_id, local, person};
}
async fn community_updates_2020_04_02(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
protocol_and_hostname: &str,
) -> Result<(), LemmyError> {
use lemmy_db_schema::schema::community::dsl::{actor_id, community, local};
}
async fn post_updates_2020_04_03(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
protocol_and_hostname: &str,
) -> Result<(), LemmyError> {
use lemmy_db_schema::schema::post::dsl::{ap_id, local, post};
}
async fn comment_updates_2020_04_03(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
protocol_and_hostname: &str,
) -> Result<(), LemmyError> {
use lemmy_db_schema::schema::comment::dsl::{ap_id, comment, local};
}
async fn private_message_updates_2020_05_05(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
protocol_and_hostname: &str,
) -> Result<(), LemmyError> {
use lemmy_db_schema::schema::private_message::dsl::{ap_id, local, private_message};
}
async fn post_thumbnail_url_updates_2020_07_27(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
protocol_and_hostname: &str,
) -> Result<(), LemmyError> {
use lemmy_db_schema::schema::post::dsl::{post, thumbnail_url};
/// We are setting inbox and follower URLs for local and remote actors alike, because for now
/// all federated instances are also Lemmy and use the same URL scheme.
-async fn apub_columns_2021_02_02(pool: &DbPool) -> Result<(), LemmyError> {
+async fn apub_columns_2021_02_02(pool: &mut DbPool<'_>) -> Result<(), LemmyError> {
let conn = &mut get_conn(pool).await?;
info!("Running apub_columns_2021_02_02");
{
/// Before this point, there is only a single value in the site table which refers to the local
/// Lemmy instance, so thats all we need to update.
async fn instance_actor_2022_01_28(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
protocol_and_hostname: &str,
) -> Result<(), LemmyError> {
info!("Running instance_actor_2021_09_29");
/// key field is empty, generate a new keypair. It would be possible to regenerate only the pubkey,
/// but thats more complicated and has no benefit, as federation is already broken for these actors.
/// https://github.com/LemmyNet/lemmy/issues/2347
-async fn regenerate_public_keys_2022_07_05(pool: &DbPool) -> Result<(), LemmyError> {
+async fn regenerate_public_keys_2022_07_05(pool: &mut DbPool<'_>) -> Result<(), LemmyError> {
let conn = &mut get_conn(pool).await?;
info!("Running regenerate_public_keys_2022_07_05");
.public_key(Some(key_pair.public_key))
.private_key(Some(Some(key_pair.private_key)))
.build();
- Community::update(pool, community_.id, &form).await?;
+ Community::update(&mut conn.into(), community_.id, &form).await?;
}
}
/// If a site already exists, the DB migration should generate a local_site row.
/// This will only be run for brand new sites.
async fn initialize_local_site_2022_10_10(
- pool: &DbPool,
+ pool: &mut DbPool<'_>,
settings: &Settings,
) -> Result<(), LemmyError> {
info!("Running initialize_local_site_2022_10_10");
let pool = build_db_pool(&settings).await?;
// Run the Code-required migrations
- run_advanced_migrations(&pool, &settings).await?;
+ run_advanced_migrations(&mut (&pool).into(), &settings).await?;
// Initialize the secrets
- let secret = Secret::init(&pool)
+ let secret = Secret::init(&mut (&pool).into())
.await
.expect("Couldn't initialize secrets.");
// Make sure the local site is set up.
- let site_view = SiteView::read_local(&pool)
+ let site_view = SiteView::read_local(&mut (&pool).into())
.await
.expect("local site not set up");
let local_site = site_view.local_site;
.retry_count(settings.retry_count)
.debug(*SYNCHRONOUS_FEDERATION)
.http_signature_compat(true)
- .url_verifier(Box::new(VerifyUrlData(context.pool().clone())))
+ .url_verifier(Box::new(VerifyUrlData(context.inner_pool().clone())))
.build()
.await?;
}
async fn collect_db_pool_metrics(context: &PromContext) {
- let pool_status = context.lemmy.pool().status();
+ let pool_status = context.lemmy.inner_pool().status();
context
.db_pool_metrics
.max_size