Running clippy --fix (#1647)
This commit is contained in:
parent
8c957ca939
commit
f54209c451
73 changed files with 253 additions and 257 deletions
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -3438,18 +3438,18 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror"
|
name = "thiserror"
|
||||||
version = "1.0.23"
|
version = "1.0.26"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "76cc616c6abf8c8928e2fdcc0dbfab37175edd8fb49a4641066ad1364fdab146"
|
checksum = "93119e4feac1cbe6c798c34d3a53ea0026b0b1de6a120deef895137c0529bfe2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror-impl",
|
"thiserror-impl",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "thiserror-impl"
|
name = "thiserror-impl"
|
||||||
version = "1.0.23"
|
version = "1.0.26"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9be73a2caec27583d0046ef3796c3794f868a5bc813db689eed00c7631275cd1"
|
checksum = "060d69a0afe7796bf42e9e2ff91f5ee691fb15c53d38b4b62a9a53eb23164745"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.24",
|
"proc-macro2 1.0.24",
|
||||||
"quote 1.0.8",
|
"quote 1.0.8",
|
||||||
|
|
|
@ -45,6 +45,6 @@ sha2 = "0.9.3"
|
||||||
async-trait = "0.1.42"
|
async-trait = "0.1.42"
|
||||||
captcha = "0.0.8"
|
captcha = "0.0.8"
|
||||||
anyhow = "1.0.38"
|
anyhow = "1.0.38"
|
||||||
thiserror = "1.0.23"
|
thiserror = "1.0.26"
|
||||||
background-jobs = "0.8.0"
|
background-jobs = "0.8.0"
|
||||||
reqwest = { version = "0.10.10", features = ["json"] }
|
reqwest = { version = "0.10.10", features = ["json"] }
|
||||||
|
|
|
@ -23,12 +23,12 @@ impl Perform for MarkCommentAsRead {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &MarkCommentAsRead = &self;
|
let data: &MarkCommentAsRead = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
let orig_comment = blocking(context.pool(), move |conn| {
|
let orig_comment = blocking(context.pool(), move |conn| {
|
||||||
CommentView::read(&conn, comment_id, None)
|
CommentView::read(conn, comment_id, None)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ impl Perform for SaveComment {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &SaveComment = &self;
|
let data: &SaveComment = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let comment_saved_form = CommentSavedForm {
|
let comment_saved_form = CommentSavedForm {
|
||||||
|
@ -123,7 +123,7 @@ impl Perform for CreateCommentLike {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &CreateCommentLike = &self;
|
let data: &CreateCommentLike = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let mut recipient_ids = Vec::<LocalUserId>::new();
|
let mut recipient_ids = Vec::<LocalUserId>::new();
|
||||||
|
@ -133,7 +133,7 @@ impl Perform for CreateCommentLike {
|
||||||
|
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
let orig_comment = blocking(context.pool(), move |conn| {
|
let orig_comment = blocking(context.pool(), move |conn| {
|
||||||
CommentView::read(&conn, comment_id, None)
|
CommentView::read(conn, comment_id, None)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ impl Perform for CreateCommentReport {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CreateCommentReportResponse, LemmyError> {
|
) -> Result<CreateCommentReportResponse, LemmyError> {
|
||||||
let data: &CreateCommentReport = &self;
|
let data: &CreateCommentReport = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
// check size of report and check for whitespace
|
// check size of report and check for whitespace
|
||||||
|
@ -46,7 +46,7 @@ impl Perform for CreateCommentReport {
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
let comment_view = blocking(context.pool(), move |conn| {
|
let comment_view = blocking(context.pool(), move |conn| {
|
||||||
CommentView::read(&conn, comment_id, None)
|
CommentView::read(conn, comment_id, None)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
@ -95,12 +95,12 @@ impl Perform for ResolveCommentReport {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<ResolveCommentReportResponse, LemmyError> {
|
) -> Result<ResolveCommentReportResponse, LemmyError> {
|
||||||
let data: &ResolveCommentReport = &self;
|
let data: &ResolveCommentReport = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let report_id = data.report_id;
|
let report_id = data.report_id;
|
||||||
let report = blocking(context.pool(), move |conn| {
|
let report = blocking(context.pool(), move |conn| {
|
||||||
CommentReportView::read(&conn, report_id)
|
CommentReportView::read(conn, report_id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ impl Perform for ListCommentReports {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<ListCommentReportsResponse, LemmyError> {
|
) -> Result<ListCommentReportsResponse, LemmyError> {
|
||||||
let data: &ListCommentReports = &self;
|
let data: &ListCommentReports = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl Perform for FollowCommunity {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let data: &FollowCommunity = &self;
|
let data: &FollowCommunity = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
@ -116,7 +116,7 @@ impl Perform for BanFromCommunity {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<BanFromCommunityResponse, LemmyError> {
|
) -> Result<BanFromCommunityResponse, LemmyError> {
|
||||||
let data: &BanFromCommunity = &self;
|
let data: &BanFromCommunity = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
@ -246,7 +246,7 @@ impl Perform for AddModToCommunity {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<AddModToCommunityResponse, LemmyError> {
|
) -> Result<AddModToCommunityResponse, LemmyError> {
|
||||||
let data: &AddModToCommunity = &self;
|
let data: &AddModToCommunity = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
@ -333,7 +333,7 @@ impl Perform for TransferCommunity {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetCommunityResponse, LemmyError> {
|
) -> Result<GetCommunityResponse, LemmyError> {
|
||||||
let data: &TransferCommunity = &self;
|
let data: &TransferCommunity = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let site_creator_id = blocking(context.pool(), move |conn| {
|
let site_creator_id = blocking(context.pool(), move |conn| {
|
||||||
|
|
|
@ -154,7 +154,7 @@ where
|
||||||
for<'de> Data: Deserialize<'de> + 'a,
|
for<'de> Data: Deserialize<'de> + 'a,
|
||||||
Data: Perform,
|
Data: Perform,
|
||||||
{
|
{
|
||||||
let parsed_data: Data = serde_json::from_str(&data)?;
|
let parsed_data: Data = serde_json::from_str(data)?;
|
||||||
let res = parsed_data
|
let res = parsed_data
|
||||||
.perform(&web::Data::new(context), Some(id))
|
.perform(&web::Data::new(context), Some(id))
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -212,7 +212,7 @@ mod tests {
|
||||||
|
|
||||||
// The check should fail, since the validator time is now newer than the jwt issue time
|
// The check should fail, since the validator time is now newer than the jwt issue time
|
||||||
let updated_local_user =
|
let updated_local_user =
|
||||||
LocalUser::update_password(&conn, inserted_local_user.id, &"password111").unwrap();
|
LocalUser::update_password(&conn, inserted_local_user.id, "password111").unwrap();
|
||||||
let check_after = check_validator_time(&updated_local_user.validator_time, &claims);
|
let check_after = check_validator_time(&updated_local_user.validator_time, &claims);
|
||||||
assert!(check_after.is_err());
|
assert!(check_after.is_err());
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ impl Perform for Login {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<LoginResponse, LemmyError> {
|
) -> Result<LoginResponse, LemmyError> {
|
||||||
let data: &Login = &self;
|
let data: &Login = self;
|
||||||
|
|
||||||
// Fetch that username / email
|
// Fetch that username / email
|
||||||
let username_or_email = data.username_or_email.clone();
|
let username_or_email = data.username_or_email.clone();
|
||||||
|
@ -160,7 +160,7 @@ impl Perform for SaveUserSettings {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<LoginResponse, LemmyError> {
|
) -> Result<LoginResponse, LemmyError> {
|
||||||
let data: &SaveUserSettings = &self;
|
let data: &SaveUserSettings = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let avatar = diesel_option_overwrite_to_url(&data.avatar)?;
|
let avatar = diesel_option_overwrite_to_url(&data.avatar)?;
|
||||||
|
@ -279,7 +279,7 @@ impl Perform for ChangePassword {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<LoginResponse, LemmyError> {
|
) -> Result<LoginResponse, LemmyError> {
|
||||||
let data: &ChangePassword = &self;
|
let data: &ChangePassword = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
password_length_check(&data.new_password)?;
|
password_length_check(&data.new_password)?;
|
||||||
|
@ -322,7 +322,7 @@ impl Perform for AddAdmin {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<AddAdminResponse, LemmyError> {
|
) -> Result<AddAdminResponse, LemmyError> {
|
||||||
let data: &AddAdmin = &self;
|
let data: &AddAdmin = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
|
@ -384,7 +384,7 @@ impl Perform for BanPerson {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<BanPersonResponse, LemmyError> {
|
) -> Result<BanPersonResponse, LemmyError> {
|
||||||
let data: &BanPerson = &self;
|
let data: &BanPerson = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
// Make sure user is an admin
|
// Make sure user is an admin
|
||||||
|
@ -460,7 +460,7 @@ impl Perform for GetReplies {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetRepliesResponse, LemmyError> {
|
) -> Result<GetRepliesResponse, LemmyError> {
|
||||||
let data: &GetReplies = &self;
|
let data: &GetReplies = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
|
let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
|
||||||
|
@ -497,7 +497,7 @@ impl Perform for GetPersonMentions {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetPersonMentionsResponse, LemmyError> {
|
) -> Result<GetPersonMentionsResponse, LemmyError> {
|
||||||
let data: &GetPersonMentions = &self;
|
let data: &GetPersonMentions = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
|
let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
|
||||||
|
@ -531,7 +531,7 @@ impl Perform for MarkPersonMentionAsRead {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PersonMentionResponse, LemmyError> {
|
) -> Result<PersonMentionResponse, LemmyError> {
|
||||||
let data: &MarkPersonMentionAsRead = &self;
|
let data: &MarkPersonMentionAsRead = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let person_mention_id = data.person_mention_id;
|
let person_mention_id = data.person_mention_id;
|
||||||
|
@ -574,7 +574,7 @@ impl Perform for MarkAllAsRead {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetRepliesResponse, LemmyError> {
|
) -> Result<GetRepliesResponse, LemmyError> {
|
||||||
let data: &MarkAllAsRead = &self;
|
let data: &MarkAllAsRead = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
@ -629,7 +629,7 @@ impl Perform for PasswordReset {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PasswordResetResponse, LemmyError> {
|
) -> Result<PasswordResetResponse, LemmyError> {
|
||||||
let data: &PasswordReset = &self;
|
let data: &PasswordReset = self;
|
||||||
|
|
||||||
// Fetch that email
|
// Fetch that email
|
||||||
let email = data.email.clone();
|
let email = data.email.clone();
|
||||||
|
@ -672,7 +672,7 @@ impl Perform for PasswordChange {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<LoginResponse, LemmyError> {
|
) -> Result<LoginResponse, LemmyError> {
|
||||||
let data: &PasswordChange = &self;
|
let data: &PasswordChange = self;
|
||||||
|
|
||||||
// Fetch the user_id from the token
|
// Fetch the user_id from the token
|
||||||
let token = data.token.clone();
|
let token = data.token.clone();
|
||||||
|
@ -712,7 +712,7 @@ impl Perform for GetReportCount {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetReportCountResponse, LemmyError> {
|
) -> Result<GetReportCountResponse, LemmyError> {
|
||||||
let data: &GetReportCount = &self;
|
let data: &GetReportCount = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
@ -768,7 +768,7 @@ impl Perform for GetFollowedCommunities {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetFollowedCommunitiesResponse, LemmyError> {
|
) -> Result<GetFollowedCommunitiesResponse, LemmyError> {
|
||||||
let data: &GetFollowedCommunities = &self;
|
let data: &GetFollowedCommunities = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
|
|
@ -25,7 +25,7 @@ impl Perform for CreatePostLike {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &CreatePostLike = &self;
|
let data: &CreatePostLike = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
// Don't do a downvote if site has downvotes disabled
|
// Don't do a downvote if site has downvotes disabled
|
||||||
|
@ -102,7 +102,7 @@ impl Perform for LockPost {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &LockPost = &self;
|
let data: &LockPost = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
|
@ -172,7 +172,7 @@ impl Perform for StickyPost {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &StickyPost = &self;
|
let data: &StickyPost = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
|
@ -246,7 +246,7 @@ impl Perform for SavePost {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &SavePost = &self;
|
let data: &SavePost = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let post_saved_form = PostSavedForm {
|
let post_saved_form = PostSavedForm {
|
||||||
|
|
|
@ -38,7 +38,7 @@ impl Perform for CreatePostReport {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CreatePostReportResponse, LemmyError> {
|
) -> Result<CreatePostReportResponse, LemmyError> {
|
||||||
let data: &CreatePostReport = &self;
|
let data: &CreatePostReport = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
// check size of report and check for whitespace
|
// check size of report and check for whitespace
|
||||||
|
@ -53,7 +53,7 @@ impl Perform for CreatePostReport {
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let post_view = blocking(context.pool(), move |conn| {
|
let post_view = blocking(context.pool(), move |conn| {
|
||||||
PostView::read(&conn, post_id, None)
|
PostView::read(conn, post_id, None)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
@ -104,12 +104,12 @@ impl Perform for ResolvePostReport {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<ResolvePostReportResponse, LemmyError> {
|
) -> Result<ResolvePostReportResponse, LemmyError> {
|
||||||
let data: &ResolvePostReport = &self;
|
let data: &ResolvePostReport = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let report_id = data.report_id;
|
let report_id = data.report_id;
|
||||||
let report = blocking(context.pool(), move |conn| {
|
let report = blocking(context.pool(), move |conn| {
|
||||||
PostReportView::read(&conn, report_id)
|
PostReportView::read(conn, report_id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ impl Perform for ListPostReports {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<ListPostReportsResponse, LemmyError> {
|
) -> Result<ListPostReportsResponse, LemmyError> {
|
||||||
let data: &ListPostReports = &self;
|
let data: &ListPostReports = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
|
|
@ -20,7 +20,7 @@ impl Perform for MarkPrivateMessageAsRead {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PrivateMessageResponse, LemmyError> {
|
) -> Result<PrivateMessageResponse, LemmyError> {
|
||||||
let data: &MarkPrivateMessageAsRead = &self;
|
let data: &MarkPrivateMessageAsRead = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
// Checking permissions
|
// Checking permissions
|
||||||
|
|
|
@ -60,7 +60,7 @@ impl Perform for GetModlog {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetModlogResponse, LemmyError> {
|
) -> Result<GetModlogResponse, LemmyError> {
|
||||||
let data: &GetModlog = &self;
|
let data: &GetModlog = self;
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let mod_person_id = data.mod_person_id;
|
let mod_person_id = data.mod_person_id;
|
||||||
|
@ -134,7 +134,7 @@ impl Perform for Search {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<SearchResponse, LemmyError> {
|
) -> Result<SearchResponse, LemmyError> {
|
||||||
let data: &Search = &self;
|
let data: &Search = self;
|
||||||
|
|
||||||
match search_by_apub_id(&data.q, context).await {
|
match search_by_apub_id(&data.q, context).await {
|
||||||
Ok(r) => return Ok(r),
|
Ok(r) => return Ok(r),
|
||||||
|
@ -191,7 +191,7 @@ impl Perform for Search {
|
||||||
}
|
}
|
||||||
SearchType::Comments => {
|
SearchType::Comments => {
|
||||||
comments = blocking(context.pool(), move |conn| {
|
comments = blocking(context.pool(), move |conn| {
|
||||||
CommentQueryBuilder::create(&conn)
|
CommentQueryBuilder::create(conn)
|
||||||
.sort(sort)
|
.sort(sort)
|
||||||
.listing_type(listing_type)
|
.listing_type(listing_type)
|
||||||
.search_term(q)
|
.search_term(q)
|
||||||
|
@ -347,7 +347,7 @@ impl Perform for TransferSite {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetSiteResponse, LemmyError> {
|
) -> Result<GetSiteResponse, LemmyError> {
|
||||||
let data: &TransferSite = &self;
|
let data: &TransferSite = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
@ -410,7 +410,7 @@ impl Perform for GetSiteConfig {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetSiteConfigResponse, LemmyError> {
|
) -> Result<GetSiteConfigResponse, LemmyError> {
|
||||||
let data: &GetSiteConfig = &self;
|
let data: &GetSiteConfig = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
// Only let admins read this
|
// Only let admins read this
|
||||||
|
@ -431,7 +431,7 @@ impl Perform for SaveSiteConfig {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetSiteConfigResponse, LemmyError> {
|
) -> Result<GetSiteConfigResponse, LemmyError> {
|
||||||
let data: &SaveSiteConfig = &self;
|
let data: &SaveSiteConfig = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
// Only let admins read this
|
// Only let admins read this
|
||||||
|
|
|
@ -16,7 +16,7 @@ impl Perform for UserJoin {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<UserJoinResponse, LemmyError> {
|
) -> Result<UserJoinResponse, LemmyError> {
|
||||||
let data: &UserJoin = &self;
|
let data: &UserJoin = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
if let Some(ws_id) = websocket_id {
|
if let Some(ws_id) = websocket_id {
|
||||||
|
@ -39,7 +39,7 @@ impl Perform for CommunityJoin {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommunityJoinResponse, LemmyError> {
|
) -> Result<CommunityJoinResponse, LemmyError> {
|
||||||
let data: &CommunityJoin = &self;
|
let data: &CommunityJoin = self;
|
||||||
|
|
||||||
if let Some(ws_id) = websocket_id {
|
if let Some(ws_id) = websocket_id {
|
||||||
context.chat_server().do_send(JoinCommunityRoom {
|
context.chat_server().do_send(JoinCommunityRoom {
|
||||||
|
@ -61,7 +61,7 @@ impl Perform for ModJoin {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<ModJoinResponse, LemmyError> {
|
) -> Result<ModJoinResponse, LemmyError> {
|
||||||
let data: &ModJoin = &self;
|
let data: &ModJoin = self;
|
||||||
|
|
||||||
if let Some(ws_id) = websocket_id {
|
if let Some(ws_id) = websocket_id {
|
||||||
context.chat_server().do_send(JoinModRoom {
|
context.chat_server().do_send(JoinModRoom {
|
||||||
|
@ -83,7 +83,7 @@ impl Perform for PostJoin {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostJoinResponse, LemmyError> {
|
) -> Result<PostJoinResponse, LemmyError> {
|
||||||
let data: &PostJoin = &self;
|
let data: &PostJoin = self;
|
||||||
|
|
||||||
if let Some(ws_id) = websocket_id {
|
if let Some(ws_id) = websocket_id {
|
||||||
context.chat_server().do_send(JoinPostRoom {
|
context.chat_server().do_send(JoinPostRoom {
|
||||||
|
|
|
@ -112,7 +112,7 @@ fn do_send_local_notifs(
|
||||||
.filter(|m| m.is_local() && m.name.ne(&person.name))
|
.filter(|m| m.is_local() && m.name.ne(&person.name))
|
||||||
.collect::<Vec<&MentionData>>()
|
.collect::<Vec<&MentionData>>()
|
||||||
{
|
{
|
||||||
if let Ok(mention_user_view) = LocalUserView::read_from_name(&conn, &mention.name) {
|
if let Ok(mention_user_view) = LocalUserView::read_from_name(conn, &mention.name) {
|
||||||
// TODO
|
// TODO
|
||||||
// At some point, make it so you can't tag the parent creator either
|
// At some point, make it so you can't tag the parent creator either
|
||||||
// This can cause two notifications, one for reply and the other for mention
|
// This can cause two notifications, one for reply and the other for mention
|
||||||
|
@ -126,7 +126,7 @@ fn do_send_local_notifs(
|
||||||
|
|
||||||
// Allow this to fail softly, since comment edits might re-update or replace it
|
// Allow this to fail softly, since comment edits might re-update or replace it
|
||||||
// Let the uniqueness handle this fail
|
// Let the uniqueness handle this fail
|
||||||
PersonMention::create(&conn, &user_mention_form).ok();
|
PersonMention::create(conn, &user_mention_form).ok();
|
||||||
|
|
||||||
// Send an email to those local users that have notifications on
|
// Send an email to those local users that have notifications on
|
||||||
if do_send_email {
|
if do_send_email {
|
||||||
|
@ -143,11 +143,11 @@ fn do_send_local_notifs(
|
||||||
// Send notifs to the parent commenter / poster
|
// Send notifs to the parent commenter / poster
|
||||||
match comment.parent_id {
|
match comment.parent_id {
|
||||||
Some(parent_id) => {
|
Some(parent_id) => {
|
||||||
if let Ok(parent_comment) = Comment::read(&conn, parent_id) {
|
if let Ok(parent_comment) = Comment::read(conn, parent_id) {
|
||||||
// Don't send a notif to yourself
|
// Don't send a notif to yourself
|
||||||
if parent_comment.creator_id != person.id {
|
if parent_comment.creator_id != person.id {
|
||||||
// Get the parent commenter local_user
|
// Get the parent commenter local_user
|
||||||
if let Ok(parent_user_view) = LocalUserView::read_person(&conn, parent_comment.creator_id)
|
if let Ok(parent_user_view) = LocalUserView::read_person(conn, parent_comment.creator_id)
|
||||||
{
|
{
|
||||||
recipient_ids.push(parent_user_view.local_user.id);
|
recipient_ids.push(parent_user_view.local_user.id);
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ fn do_send_local_notifs(
|
||||||
// Its a post
|
// Its a post
|
||||||
None => {
|
None => {
|
||||||
if post.creator_id != person.id {
|
if post.creator_id != person.id {
|
||||||
if let Ok(parent_user_view) = LocalUserView::read_person(&conn, post.creator_id) {
|
if let Ok(parent_user_view) = LocalUserView::read_person(conn, post.creator_id) {
|
||||||
recipient_ids.push(parent_user_view.local_user.id);
|
recipient_ids.push(parent_user_view.local_user.id);
|
||||||
|
|
||||||
if do_send_email {
|
if do_send_email {
|
||||||
|
@ -208,7 +208,7 @@ pub fn send_email_to_user(
|
||||||
comment_content,
|
comment_content,
|
||||||
Settings::get().get_protocol_and_hostname()
|
Settings::get().get_protocol_and_hostname()
|
||||||
);
|
);
|
||||||
match send_email(subject, &user_email, &local_user_view.person.name, html) {
|
match send_email(subject, user_email, &local_user_view.person.name, html) {
|
||||||
Ok(_o) => _o,
|
Ok(_o) => _o,
|
||||||
Err(e) => error!("{}", e),
|
Err(e) => error!("{}", e),
|
||||||
};
|
};
|
||||||
|
@ -261,7 +261,7 @@ pub async fn get_local_user_view_from_jwt(
|
||||||
jwt: &str,
|
jwt: &str,
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
) -> Result<LocalUserView, LemmyError> {
|
) -> Result<LocalUserView, LemmyError> {
|
||||||
let claims = Claims::decode(&jwt)
|
let claims = Claims::decode(jwt)
|
||||||
.map_err(|_| ApiError::err("not_logged_in"))?
|
.map_err(|_| ApiError::err("not_logged_in"))?
|
||||||
.claims;
|
.claims;
|
||||||
let local_user_id = LocalUserId(claims.sub);
|
let local_user_id = LocalUserId(claims.sub);
|
||||||
|
@ -304,7 +304,7 @@ pub async fn get_local_user_settings_view_from_jwt(
|
||||||
jwt: &str,
|
jwt: &str,
|
||||||
pool: &DbPool,
|
pool: &DbPool,
|
||||||
) -> Result<LocalUserSettingsView, LemmyError> {
|
) -> Result<LocalUserSettingsView, LemmyError> {
|
||||||
let claims = Claims::decode(&jwt)
|
let claims = Claims::decode(jwt)
|
||||||
.map_err(|_| ApiError::err("not_logged_in"))?
|
.map_err(|_| ApiError::err("not_logged_in"))?
|
||||||
.claims;
|
.claims;
|
||||||
let local_user_id = LocalUserId(claims.sub);
|
let local_user_id = LocalUserId(claims.sub);
|
||||||
|
|
|
@ -39,6 +39,6 @@ uuid = { version = "0.8.2", features = ["serde", "v4"] }
|
||||||
sha2 = "0.9.3"
|
sha2 = "0.9.3"
|
||||||
async-trait = "0.1.42"
|
async-trait = "0.1.42"
|
||||||
anyhow = "1.0.38"
|
anyhow = "1.0.38"
|
||||||
thiserror = "1.0.23"
|
thiserror = "1.0.26"
|
||||||
background-jobs = "0.8.0"
|
background-jobs = "0.8.0"
|
||||||
reqwest = { version = "0.10.10", features = ["json"] }
|
reqwest = { version = "0.10.10", features = ["json"] }
|
||||||
|
|
|
@ -29,7 +29,7 @@ impl PerformCrud for CreateComment {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &CreateComment = &self;
|
let data: &CreateComment = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let content_slurs_removed = remove_slurs(&data.content.to_owned());
|
let content_slurs_removed = remove_slurs(&data.content.to_owned());
|
||||||
|
@ -48,7 +48,7 @@ impl PerformCrud for CreateComment {
|
||||||
// If there's a parent_id, check to make sure that comment is in that post
|
// If there's a parent_id, check to make sure that comment is in that post
|
||||||
if let Some(parent_id) = data.parent_id {
|
if let Some(parent_id) = data.parent_id {
|
||||||
// Make sure the parent comment exists
|
// Make sure the parent comment exists
|
||||||
let parent = blocking(context.pool(), move |conn| Comment::read(&conn, parent_id))
|
let parent = blocking(context.pool(), move |conn| Comment::read(conn, parent_id))
|
||||||
.await?
|
.await?
|
||||||
.map_err(|_| ApiError::err("couldnt_create_comment"))?;
|
.map_err(|_| ApiError::err("couldnt_create_comment"))?;
|
||||||
if parent.post_id != post_id {
|
if parent.post_id != post_id {
|
||||||
|
@ -67,7 +67,7 @@ impl PerformCrud for CreateComment {
|
||||||
// Create the comment
|
// Create the comment
|
||||||
let comment_form2 = comment_form.clone();
|
let comment_form2 = comment_form.clone();
|
||||||
let inserted_comment = blocking(context.pool(), move |conn| {
|
let inserted_comment = blocking(context.pool(), move |conn| {
|
||||||
Comment::create(&conn, &comment_form2)
|
Comment::create(conn, &comment_form2)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(|_| ApiError::err("couldnt_create_comment"))?;
|
.map_err(|_| ApiError::err("couldnt_create_comment"))?;
|
||||||
|
@ -78,7 +78,7 @@ impl PerformCrud for CreateComment {
|
||||||
blocking(context.pool(), move |conn| -> Result<Comment, LemmyError> {
|
blocking(context.pool(), move |conn| -> Result<Comment, LemmyError> {
|
||||||
let apub_id =
|
let apub_id =
|
||||||
generate_apub_endpoint(EndpointType::Comment, &inserted_comment_id.to_string())?;
|
generate_apub_endpoint(EndpointType::Comment, &inserted_comment_id.to_string())?;
|
||||||
Ok(Comment::update_ap_id(&conn, inserted_comment_id, apub_id)?)
|
Ok(Comment::update_ap_id(conn, inserted_comment_id, apub_id)?)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(|_| ApiError::err("couldnt_create_comment"))?;
|
.map_err(|_| ApiError::err("couldnt_create_comment"))?;
|
||||||
|
@ -108,7 +108,7 @@ impl PerformCrud for CreateComment {
|
||||||
score: 1,
|
score: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
let like = move |conn: &'_ _| CommentLike::like(&conn, &like_form);
|
let like = move |conn: &'_ _| CommentLike::like(conn, &like_form);
|
||||||
if blocking(context.pool(), like).await?.is_err() {
|
if blocking(context.pool(), like).await?.is_err() {
|
||||||
return Err(ApiError::err("couldnt_like_comment").into());
|
return Err(ApiError::err("couldnt_like_comment").into());
|
||||||
}
|
}
|
||||||
|
@ -119,7 +119,7 @@ impl PerformCrud for CreateComment {
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let mut comment_view = blocking(context.pool(), move |conn| {
|
let mut comment_view = blocking(context.pool(), move |conn| {
|
||||||
CommentView::read(&conn, inserted_comment.id, Some(person_id))
|
CommentView::read(conn, inserted_comment.id, Some(person_id))
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
|
|
@ -24,12 +24,12 @@ impl PerformCrud for DeleteComment {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &DeleteComment = &self;
|
let data: &DeleteComment = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
let orig_comment = blocking(context.pool(), move |conn| {
|
let orig_comment = blocking(context.pool(), move |conn| {
|
||||||
CommentView::read(&conn, comment_id, None)
|
CommentView::read(conn, comment_id, None)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
@ -110,12 +110,12 @@ impl PerformCrud for RemoveComment {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &RemoveComment = &self;
|
let data: &RemoveComment = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
let orig_comment = blocking(context.pool(), move |conn| {
|
let orig_comment = blocking(context.pool(), move |conn| {
|
||||||
CommentView::read(&conn, comment_id, None)
|
CommentView::read(conn, comment_id, None)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ impl PerformCrud for GetComments {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetCommentsResponse, LemmyError> {
|
) -> Result<GetCommentsResponse, LemmyError> {
|
||||||
let data: &GetComments = &self;
|
let data: &GetComments = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt_opt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt_opt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let show_bot_accounts = local_user_view
|
let show_bot_accounts = local_user_view
|
||||||
|
|
|
@ -28,12 +28,12 @@ impl PerformCrud for EditComment {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommentResponse, LemmyError> {
|
) -> Result<CommentResponse, LemmyError> {
|
||||||
let data: &EditComment = &self;
|
let data: &EditComment = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
let orig_comment = blocking(context.pool(), move |conn| {
|
let orig_comment = blocking(context.pool(), move |conn| {
|
||||||
CommentView::read(&conn, comment_id, None)
|
CommentView::read(conn, comment_id, None)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ impl PerformCrud for CreateCommunity {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let data: &CreateCommunity = &self;
|
let data: &CreateCommunity = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let site = blocking(context.pool(), move |conn| Site::read(conn, 0)).await??;
|
let site = blocking(context.pool(), move |conn| Site::read(conn, 0)).await??;
|
||||||
|
|
|
@ -23,7 +23,7 @@ impl PerformCrud for DeleteCommunity {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let data: &DeleteCommunity = &self;
|
let data: &DeleteCommunity = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
// Fetch the community mods
|
// Fetch the community mods
|
||||||
|
@ -87,7 +87,7 @@ impl PerformCrud for RemoveCommunity {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let data: &RemoveCommunity = &self;
|
let data: &RemoveCommunity = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
// Verify its an admin (only an admin can remove a community)
|
// Verify its an admin (only an admin can remove a community)
|
||||||
|
|
|
@ -24,7 +24,7 @@ impl PerformCrud for GetCommunity {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetCommunityResponse, LemmyError> {
|
) -> Result<GetCommunityResponse, LemmyError> {
|
||||||
let data: &GetCommunity = &self;
|
let data: &GetCommunity = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt_opt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt_opt(&data.auth, context.pool()).await?;
|
||||||
let person_id = local_user_view.map(|u| u.person.id);
|
let person_id = local_user_view.map(|u| u.person.id);
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ impl PerformCrud for ListCommunities {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<ListCommunitiesResponse, LemmyError> {
|
) -> Result<ListCommunitiesResponse, LemmyError> {
|
||||||
let data: &ListCommunities = &self;
|
let data: &ListCommunities = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt_opt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt_opt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let person_id = local_user_view.to_owned().map(|l| l.person.id);
|
let person_id = local_user_view.to_owned().map(|l| l.person.id);
|
||||||
|
|
|
@ -28,7 +28,7 @@ impl PerformCrud for EditCommunity {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let data: &EditCommunity = &self;
|
let data: &EditCommunity = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
check_slurs_opt(&data.title)?;
|
check_slurs_opt(&data.title)?;
|
||||||
|
|
|
@ -124,7 +124,7 @@ where
|
||||||
for<'de> Data: Deserialize<'de> + 'a,
|
for<'de> Data: Deserialize<'de> + 'a,
|
||||||
Data: PerformCrud,
|
Data: PerformCrud,
|
||||||
{
|
{
|
||||||
let parsed_data: Data = serde_json::from_str(&data)?;
|
let parsed_data: Data = serde_json::from_str(data)?;
|
||||||
let res = parsed_data
|
let res = parsed_data
|
||||||
.perform(&web::Data::new(context), Some(id))
|
.perform(&web::Data::new(context), Some(id))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -29,7 +29,7 @@ impl PerformCrud for CreatePost {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &CreatePost = &self;
|
let data: &CreatePost = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
check_slurs(&data.name)?;
|
check_slurs(&data.name)?;
|
||||||
|
|
|
@ -23,7 +23,7 @@ impl PerformCrud for DeletePost {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &DeletePost = &self;
|
let data: &DeletePost = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
|
@ -88,7 +88,7 @@ impl PerformCrud for RemovePost {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &RemovePost = &self;
|
let data: &RemovePost = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
|
|
|
@ -22,7 +22,7 @@ impl PerformCrud for GetPost {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetPostResponse, LemmyError> {
|
) -> Result<GetPostResponse, LemmyError> {
|
||||||
let data: &GetPost = &self;
|
let data: &GetPost = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt_opt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt_opt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let show_bot_accounts = local_user_view
|
let show_bot_accounts = local_user_view
|
||||||
|
@ -92,7 +92,7 @@ impl PerformCrud for GetPosts {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetPostsResponse, LemmyError> {
|
) -> Result<GetPostsResponse, LemmyError> {
|
||||||
let data: &GetPosts = &self;
|
let data: &GetPosts = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt_opt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt_opt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let person_id = local_user_view.to_owned().map(|l| l.person.id);
|
let person_id = local_user_view.to_owned().map(|l| l.person.id);
|
||||||
|
|
|
@ -23,7 +23,7 @@ impl PerformCrud for EditPost {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let data: &EditPost = &self;
|
let data: &EditPost = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
check_slurs_opt(&data.name)?;
|
check_slurs_opt(&data.name)?;
|
||||||
|
|
|
@ -22,7 +22,7 @@ impl PerformCrud for CreatePrivateMessage {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PrivateMessageResponse, LemmyError> {
|
) -> Result<PrivateMessageResponse, LemmyError> {
|
||||||
let data: &CreatePrivateMessage = &self;
|
let data: &CreatePrivateMessage = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let content_slurs_removed = remove_slurs(&data.content.to_owned());
|
let content_slurs_removed = remove_slurs(&data.content.to_owned());
|
||||||
|
@ -54,7 +54,7 @@ impl PerformCrud for CreatePrivateMessage {
|
||||||
&inserted_private_message_id.to_string(),
|
&inserted_private_message_id.to_string(),
|
||||||
)?;
|
)?;
|
||||||
Ok(PrivateMessage::update_ap_id(
|
Ok(PrivateMessage::update_ap_id(
|
||||||
&conn,
|
conn,
|
||||||
inserted_private_message_id,
|
inserted_private_message_id,
|
||||||
apub_id,
|
apub_id,
|
||||||
)?)
|
)?)
|
||||||
|
|
|
@ -21,7 +21,7 @@ impl PerformCrud for DeletePrivateMessage {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PrivateMessageResponse, LemmyError> {
|
) -> Result<PrivateMessageResponse, LemmyError> {
|
||||||
let data: &DeletePrivateMessage = &self;
|
let data: &DeletePrivateMessage = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
// Checking permissions
|
// Checking permissions
|
||||||
|
|
|
@ -18,7 +18,7 @@ impl PerformCrud for GetPrivateMessages {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PrivateMessagesResponse, LemmyError> {
|
) -> Result<PrivateMessagesResponse, LemmyError> {
|
||||||
let data: &GetPrivateMessages = &self;
|
let data: &GetPrivateMessages = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ impl PerformCrud for GetPrivateMessages {
|
||||||
let limit = data.limit;
|
let limit = data.limit;
|
||||||
let unread_only = data.unread_only;
|
let unread_only = data.unread_only;
|
||||||
let messages = blocking(context.pool(), move |conn| {
|
let messages = blocking(context.pool(), move |conn| {
|
||||||
PrivateMessageQueryBuilder::create(&conn, person_id)
|
PrivateMessageQueryBuilder::create(conn, person_id)
|
||||||
.page(page)
|
.page(page)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.unread_only(unread_only)
|
.unread_only(unread_only)
|
||||||
|
|
|
@ -21,7 +21,7 @@ impl PerformCrud for EditPrivateMessage {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<PrivateMessageResponse, LemmyError> {
|
) -> Result<PrivateMessageResponse, LemmyError> {
|
||||||
let data: &EditPrivateMessage = &self;
|
let data: &EditPrivateMessage = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
// Checking permissions
|
// Checking permissions
|
||||||
|
|
|
@ -32,7 +32,7 @@ impl PerformCrud for CreateSite {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<SiteResponse, LemmyError> {
|
) -> Result<SiteResponse, LemmyError> {
|
||||||
let data: &CreateSite = &self;
|
let data: &CreateSite = self;
|
||||||
|
|
||||||
let read_site = move |conn: &'_ _| Site::read_simple(conn);
|
let read_site = move |conn: &'_ _| Site::read_simple(conn);
|
||||||
if blocking(context.pool(), read_site).await?.is_ok() {
|
if blocking(context.pool(), read_site).await?.is_ok() {
|
||||||
|
|
|
@ -22,7 +22,7 @@ impl PerformCrud for GetSite {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetSiteResponse, LemmyError> {
|
) -> Result<GetSiteResponse, LemmyError> {
|
||||||
let data: &GetSite = &self;
|
let data: &GetSite = self;
|
||||||
|
|
||||||
let site_view = match blocking(context.pool(), move |conn| SiteView::read(conn)).await? {
|
let site_view = match blocking(context.pool(), move |conn| SiteView::read(conn)).await? {
|
||||||
Ok(site_view) => Some(site_view),
|
Ok(site_view) => Some(site_view),
|
||||||
|
|
|
@ -29,7 +29,7 @@ impl PerformCrud for EditSite {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
websocket_id: Option<ConnectionId>,
|
websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<SiteResponse, LemmyError> {
|
) -> Result<SiteResponse, LemmyError> {
|
||||||
let data: &EditSite = &self;
|
let data: &EditSite = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
check_slurs_opt(&data.name)?;
|
check_slurs_opt(&data.name)?;
|
||||||
|
|
|
@ -46,7 +46,7 @@ impl PerformCrud for Register {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<LoginResponse, LemmyError> {
|
) -> Result<LoginResponse, LemmyError> {
|
||||||
let data: &Register = &self;
|
let data: &Register = self;
|
||||||
|
|
||||||
// Make sure site has open registration
|
// Make sure site has open registration
|
||||||
if let Ok(site) = blocking(context.pool(), move |conn| Site::read_simple(conn)).await? {
|
if let Ok(site) = blocking(context.pool(), move |conn| Site::read_simple(conn)).await? {
|
||||||
|
@ -151,7 +151,7 @@ impl PerformCrud for Register {
|
||||||
|
|
||||||
// If the local user creation errored, then delete that person
|
// If the local user creation errored, then delete that person
|
||||||
blocking(context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
Person::delete(&conn, inserted_person.id)
|
Person::delete(conn, inserted_person.id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ impl PerformCrud for DeleteAccount {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<LoginResponse, LemmyError> {
|
) -> Result<LoginResponse, LemmyError> {
|
||||||
let data: &DeleteAccount = &self;
|
let data: &DeleteAccount = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
// Verify the password
|
// Verify the password
|
||||||
|
|
|
@ -21,7 +21,7 @@ impl PerformCrud for GetPersonDetails {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<GetPersonDetailsResponse, LemmyError> {
|
) -> Result<GetPersonDetailsResponse, LemmyError> {
|
||||||
let data: &GetPersonDetails = &self;
|
let data: &GetPersonDetails = self;
|
||||||
let local_user_view = get_local_user_view_from_jwt_opt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt_opt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let show_nsfw = local_user_view.as_ref().map(|t| t.local_user.show_nsfw);
|
let show_nsfw = local_user_view.as_ref().map(|t| t.local_user.show_nsfw);
|
||||||
|
|
|
@ -46,7 +46,7 @@ uuid = { version = "0.8.2", features = ["serde", "v4"] }
|
||||||
sha2 = "0.9.3"
|
sha2 = "0.9.3"
|
||||||
async-trait = "0.1.42"
|
async-trait = "0.1.42"
|
||||||
anyhow = "1.0.38"
|
anyhow = "1.0.38"
|
||||||
thiserror = "1.0.23"
|
thiserror = "1.0.26"
|
||||||
background-jobs = "0.8.0"
|
background-jobs = "0.8.0"
|
||||||
reqwest = { version = "0.10.10", features = ["json"] }
|
reqwest = { version = "0.10.10", features = ["json"] }
|
||||||
backtrace = "0.3.56"
|
backtrace = "0.3.56"
|
||||||
|
|
|
@ -57,7 +57,7 @@ impl ApubObjectType for Comment {
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
let maa = collect_non_local_mentions(&self, &community, context).await?;
|
let maa = collect_non_local_mentions(self, &community, context).await?;
|
||||||
|
|
||||||
let mut create = Create::new(
|
let mut create = Create::new(
|
||||||
creator.actor_id.to_owned().into_inner(),
|
creator.actor_id.to_owned().into_inner(),
|
||||||
|
@ -71,8 +71,8 @@ impl ApubObjectType for Comment {
|
||||||
// Set the mention tags
|
// Set the mention tags
|
||||||
.set_many_tags(maa.get_tags()?);
|
.set_many_tags(maa.get_tags()?);
|
||||||
|
|
||||||
send_to_community(create.clone(), &creator, &community, None, context).await?;
|
send_to_community(create.clone(), creator, &community, None, context).await?;
|
||||||
send_comment_mentions(&creator, maa.inboxes, create, context).await?;
|
send_comment_mentions(creator, maa.inboxes, create, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ impl ApubObjectType for Comment {
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
let maa = collect_non_local_mentions(&self, &community, context).await?;
|
let maa = collect_non_local_mentions(self, &community, context).await?;
|
||||||
|
|
||||||
let mut update = Update::new(
|
let mut update = Update::new(
|
||||||
creator.actor_id.to_owned().into_inner(),
|
creator.actor_id.to_owned().into_inner(),
|
||||||
|
@ -104,8 +104,8 @@ impl ApubObjectType for Comment {
|
||||||
// Set the mention tags
|
// Set the mention tags
|
||||||
.set_many_tags(maa.get_tags()?);
|
.set_many_tags(maa.get_tags()?);
|
||||||
|
|
||||||
send_to_community(update.clone(), &creator, &community, None, context).await?;
|
send_to_community(update.clone(), creator, &community, None, context).await?;
|
||||||
send_comment_mentions(&creator, maa.inboxes, update, context).await?;
|
send_comment_mentions(creator, maa.inboxes, update, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ impl ApubObjectType for Comment {
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.actor_id()]);
|
.set_many_ccs(vec![community.actor_id()]);
|
||||||
|
|
||||||
send_to_community(delete, &creator, &community, None, context).await?;
|
send_to_community(delete, creator, &community, None, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +169,7 @@ impl ApubObjectType for Comment {
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.actor_id()]);
|
.set_many_ccs(vec![community.actor_id()]);
|
||||||
|
|
||||||
send_to_community(undo, &creator, &community, None, context).await?;
|
send_to_community(undo, creator, &community, None, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ impl ApubObjectType for Comment {
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.actor_id()]);
|
.set_many_ccs(vec![community.actor_id()]);
|
||||||
|
|
||||||
send_to_community(remove, &mod_, &community, None, context).await?;
|
send_to_community(remove, mod_, &community, None, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ impl ApubObjectType for Comment {
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.actor_id()]);
|
.set_many_ccs(vec![community.actor_id()]);
|
||||||
|
|
||||||
send_to_community(undo, &mod_, &community, None, context).await?;
|
send_to_community(undo, mod_, &community, None, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,7 +260,7 @@ impl ApubLikeableType for Comment {
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.actor_id()]);
|
.set_many_ccs(vec![community.actor_id()]);
|
||||||
|
|
||||||
send_to_community(like, &creator, &community, None, context).await?;
|
send_to_community(like, creator, &community, None, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ impl ApubLikeableType for Comment {
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.actor_id()]);
|
.set_many_ccs(vec![community.actor_id()]);
|
||||||
|
|
||||||
send_to_community(dislike, &creator, &community, None, context).await?;
|
send_to_community(dislike, creator, &community, None, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ impl ApubLikeableType for Comment {
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.actor_id()]);
|
.set_many_ccs(vec![community.actor_id()]);
|
||||||
|
|
||||||
send_to_community(undo, &creator, &community, None, context).await?;
|
send_to_community(undo, creator, &community, None, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -328,7 +328,7 @@ impl CommunityType for Community {
|
||||||
.set_many_ccs(vec![self.actor_id()])
|
.set_many_ccs(vec![self.actor_id()])
|
||||||
.set_target(generate_moderators_url(&self.actor_id)?.into_inner());
|
.set_target(generate_moderators_url(&self.actor_id)?.into_inner());
|
||||||
|
|
||||||
send_to_community(remove, &actor, self, Some(removed_mod.actor_id()), context).await?;
|
send_to_community(remove, actor, self, Some(removed_mod.actor_id()), context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,7 +345,7 @@ impl CommunityType for Community {
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![self.actor_id()]);
|
.set_many_ccs(vec![self.actor_id()]);
|
||||||
|
|
||||||
send_to_community(block, &actor, self, Some(blocked_user.actor_id()), context).await?;
|
send_to_community(block, actor, self, Some(blocked_user.actor_id()), context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,7 +370,7 @@ impl CommunityType for Community {
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![self.actor_id()]);
|
.set_many_ccs(vec![self.actor_id()]);
|
||||||
|
|
||||||
send_to_community(undo, &actor, self, Some(unblocked_user.actor_id()), context).await?;
|
send_to_community(undo, actor, self, Some(unblocked_user.actor_id()), context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ impl UserType for Person {
|
||||||
person_id: self.id,
|
person_id: self.id,
|
||||||
pending: true,
|
pending: true,
|
||||||
};
|
};
|
||||||
blocking(&context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
CommunityFollower::follow(conn, &community_follower_form).ok()
|
CommunityFollower::follow(conn, &community_follower_form).ok()
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -211,7 +211,7 @@ impl ApubLikeableType for Post {
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.actor_id()]);
|
.set_many_ccs(vec![community.actor_id()]);
|
||||||
|
|
||||||
send_to_community(like, &creator, &community, None, context).await?;
|
send_to_community(like, creator, &community, None, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,7 +232,7 @@ impl ApubLikeableType for Post {
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.actor_id()]);
|
.set_many_ccs(vec![community.actor_id()]);
|
||||||
|
|
||||||
send_to_community(dislike, &creator, &community, None, context).await?;
|
send_to_community(dislike, creator, &community, None, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ impl ApubLikeableType for Post {
|
||||||
.set_to(public())
|
.set_to(public())
|
||||||
.set_many_ccs(vec![community.actor_id()]);
|
.set_many_ccs(vec![community.actor_id()]);
|
||||||
|
|
||||||
send_to_community(undo, &creator, &community, None, context).await?;
|
send_to_community(undo, creator, &community, None, context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ pub fn verify_signature(request: &HttpRequest, actor: &dyn ActorType) -> Result<
|
||||||
);
|
);
|
||||||
let public_key = PKey::public_key_from_pem(public_key.as_bytes())?;
|
let public_key = PKey::public_key_from_pem(public_key.as_bytes())?;
|
||||||
let mut verifier = Verifier::new(MessageDigest::sha256(), &public_key)?;
|
let mut verifier = Verifier::new(MessageDigest::sha256(), &public_key)?;
|
||||||
verifier.update(&signing_string.as_bytes())?;
|
verifier.update(signing_string.as_bytes())?;
|
||||||
Ok(verifier.verify(&base64::decode(signature)?)?)
|
Ok(verifier.verify(&base64::decode(signature)?)?)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,7 @@ use anyhow::Context;
|
||||||
use diesel::result::Error::NotFound;
|
use diesel::result::Error::NotFound;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_db_queries::{source::community::Community_, ApubObject, Joinable};
|
use lemmy_db_queries::{source::community::Community_, ApubObject, Joinable};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::source::community::{Community, CommunityModerator, CommunityModeratorForm};
|
||||||
source::community::{Community, CommunityModerator, CommunityModeratorForm},
|
|
||||||
DbUrl,
|
|
||||||
};
|
|
||||||
use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
|
use lemmy_db_views_actor::community_moderator_view::CommunityModeratorView;
|
||||||
use lemmy_utils::{location_info, LemmyError};
|
use lemmy_utils::{location_info, LemmyError};
|
||||||
use lemmy_websocket::LemmyContext;
|
use lemmy_websocket::LemmyContext;
|
||||||
|
@ -102,12 +99,12 @@ async fn update_community_mods(
|
||||||
let new_moderators = fetch_community_mods(context, group, request_counter).await?;
|
let new_moderators = fetch_community_mods(context, group, request_counter).await?;
|
||||||
let community_id = community.id;
|
let community_id = community.id;
|
||||||
let current_moderators = blocking(context.pool(), move |conn| {
|
let current_moderators = blocking(context.pool(), move |conn| {
|
||||||
CommunityModeratorView::for_community(&conn, community_id)
|
CommunityModeratorView::for_community(conn, community_id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
// Remove old mods from database which arent in the moderators collection anymore
|
// Remove old mods from database which arent in the moderators collection anymore
|
||||||
for mod_user in ¤t_moderators {
|
for mod_user in ¤t_moderators {
|
||||||
if !new_moderators.contains(&&mod_user.moderator.actor_id.clone().into()) {
|
if !new_moderators.contains(&mod_user.moderator.actor_id.clone().into()) {
|
||||||
let community_moderator_form = CommunityModeratorForm {
|
let community_moderator_form = CommunityModeratorForm {
|
||||||
community_id: mod_user.community.id,
|
community_id: mod_user.community.id,
|
||||||
person_id: mod_user.moderator.id,
|
person_id: mod_user.moderator.id,
|
||||||
|
@ -122,12 +119,13 @@ async fn update_community_mods(
|
||||||
// Add new mods to database which have been added to moderators collection
|
// Add new mods to database which have been added to moderators collection
|
||||||
for mod_uri in new_moderators {
|
for mod_uri in new_moderators {
|
||||||
let mod_user = get_or_fetch_and_upsert_person(&mod_uri, context, request_counter).await?;
|
let mod_user = get_or_fetch_and_upsert_person(&mod_uri, context, request_counter).await?;
|
||||||
let current_mod_uris: Vec<DbUrl> = current_moderators
|
|
||||||
|
if !current_moderators
|
||||||
.clone()
|
.clone()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|c| c.moderator.actor_id.clone())
|
.map(|c| c.moderator.actor_id.clone())
|
||||||
.collect();
|
.any(|x| x == mod_user.actor_id)
|
||||||
if !current_mod_uris.contains(&mod_user.actor_id) {
|
{
|
||||||
let community_moderator_form = CommunityModeratorForm {
|
let community_moderator_form = CommunityModeratorForm {
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
person_id: mod_user.id,
|
person_id: mod_user.id,
|
||||||
|
|
|
@ -60,7 +60,7 @@ where
|
||||||
if *recursion_counter > MAX_REQUEST_NUMBER {
|
if *recursion_counter > MAX_REQUEST_NUMBER {
|
||||||
return Err(LemmyError::from(anyhow!("Maximum recursion depth reached")).into());
|
return Err(LemmyError::from(anyhow!("Maximum recursion depth reached")).into());
|
||||||
}
|
}
|
||||||
check_is_apub_id_valid(&url, false)?;
|
check_is_apub_id_valid(url, false)?;
|
||||||
|
|
||||||
let timeout = Duration::from_secs(60);
|
let timeout = Duration::from_secs(60);
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ pub async fn search_by_apub_id(
|
||||||
);
|
);
|
||||||
Url::parse(&url)?
|
Url::parse(&url)?
|
||||||
} else {
|
} else {
|
||||||
Url::parse(&query)?
|
Url::parse(query)?
|
||||||
};
|
};
|
||||||
|
|
||||||
let recursion_counter = &mut 0;
|
let recursion_counter = &mut 0;
|
||||||
|
@ -124,7 +124,7 @@ async fn build_response(
|
||||||
SearchAcceptedObjects::Person(p) => {
|
SearchAcceptedObjects::Person(p) => {
|
||||||
let person_uri = p.inner.id(domain)?.context("person has no id")?;
|
let person_uri = p.inner.id(domain)?.context("person has no id")?;
|
||||||
|
|
||||||
let person = get_or_fetch_and_upsert_person(&person_uri, context, recursion_counter).await?;
|
let person = get_or_fetch_and_upsert_person(person_uri, context, recursion_counter).await?;
|
||||||
|
|
||||||
response.users = vec![
|
response.users = vec![
|
||||||
blocking(context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
|
|
|
@ -169,7 +169,7 @@ impl FromApubToForm<NoteExt> for CommentForm {
|
||||||
|
|
||||||
// This post, or the parent comment might not yet exist on this server yet, fetch them.
|
// This post, or the parent comment might not yet exist on this server yet, fetch them.
|
||||||
let post = Box::pin(get_or_fetch_and_insert_post(
|
let post = Box::pin(get_or_fetch_and_insert_post(
|
||||||
&post_ap_id,
|
post_ap_id,
|
||||||
context,
|
context,
|
||||||
request_counter,
|
request_counter,
|
||||||
))
|
))
|
||||||
|
@ -181,7 +181,7 @@ impl FromApubToForm<NoteExt> for CommentForm {
|
||||||
Some(parent_comment_uri) => {
|
Some(parent_comment_uri) => {
|
||||||
let parent_comment_ap_id = &parent_comment_uri?;
|
let parent_comment_ap_id = &parent_comment_uri?;
|
||||||
let parent_comment = Box::pin(get_or_fetch_and_insert_comment(
|
let parent_comment = Box::pin(get_or_fetch_and_insert_comment(
|
||||||
&parent_comment_ap_id,
|
parent_comment_ap_id,
|
||||||
context,
|
context,
|
||||||
request_counter,
|
request_counter,
|
||||||
))
|
))
|
||||||
|
|
|
@ -45,7 +45,7 @@ impl ToApub for Community {
|
||||||
async fn to_apub(&self, pool: &DbPool) -> Result<GroupExt, LemmyError> {
|
async fn to_apub(&self, pool: &DbPool) -> Result<GroupExt, LemmyError> {
|
||||||
let id = self.id;
|
let id = self.id;
|
||||||
let moderators = blocking(pool, move |conn| {
|
let moderators = blocking(pool, move |conn| {
|
||||||
CommunityModeratorView::for_community(&conn, id)
|
CommunityModeratorView::for_community(conn, id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
let moderators: Vec<Url> = moderators
|
let moderators: Vec<Url> = moderators
|
||||||
|
|
|
@ -199,7 +199,7 @@ where
|
||||||
// otherwise parse and insert, assuring that it comes from the right domain
|
// otherwise parse and insert, assuring that it comes from the right domain
|
||||||
else {
|
else {
|
||||||
let to_form = ToForm::from_apub(
|
let to_form = ToForm::from_apub(
|
||||||
&from,
|
from,
|
||||||
context,
|
context,
|
||||||
expected_domain,
|
expected_domain,
|
||||||
request_counter,
|
request_counter,
|
||||||
|
|
|
@ -71,7 +71,7 @@ impl ToApub for Post {
|
||||||
.set_attributed_to(creator.actor_id.into_inner());
|
.set_attributed_to(creator.actor_id.into_inner());
|
||||||
|
|
||||||
if let Some(body) = &self.body {
|
if let Some(body) = &self.body {
|
||||||
set_content_and_source(&mut page, &body)?;
|
set_content_and_source(&mut page, body)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(url) = &self.url {
|
if let Some(url) = &self.url {
|
||||||
|
|
|
@ -39,7 +39,7 @@ where
|
||||||
{
|
{
|
||||||
let actor = activity.actor()?;
|
let actor = activity.actor()?;
|
||||||
let person_uri = actor.as_single_xsd_any_uri().context(location_info!())?;
|
let person_uri = actor.as_single_xsd_any_uri().context(location_info!())?;
|
||||||
get_or_fetch_and_upsert_person(&person_uri, context, request_counter).await
|
get_or_fetch_and_upsert_person(person_uri, context, request_counter).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensure that the ID of an incoming activity comes from the same domain as the actor. Optionally
|
/// Ensure that the ID of an incoming activity comes from the same domain as the actor. Optionally
|
||||||
|
|
|
@ -41,7 +41,7 @@ pub(crate) async fn receive_create_private_message(
|
||||||
let private_message =
|
let private_message =
|
||||||
PrivateMessage::from_apub(¬e, context, expected_domain, request_counter, false).await?;
|
PrivateMessage::from_apub(¬e, context, expected_domain, request_counter, false).await?;
|
||||||
|
|
||||||
let message = blocking(&context.pool(), move |conn| {
|
let message = blocking(context.pool(), move |conn| {
|
||||||
PrivateMessageView::read(conn, private_message.id)
|
PrivateMessageView::read(conn, private_message.id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
@ -88,7 +88,7 @@ pub(crate) async fn receive_update_private_message(
|
||||||
PrivateMessage::from_apub(¬e, context, expected_domain, request_counter, false).await?;
|
PrivateMessage::from_apub(¬e, context, expected_domain, request_counter, false).await?;
|
||||||
|
|
||||||
let private_message_id = private_message.id;
|
let private_message_id = private_message.id;
|
||||||
let message = blocking(&context.pool(), move |conn| {
|
let message = blocking(context.pool(), move |conn| {
|
||||||
PrivateMessageView::read(conn, private_message_id)
|
PrivateMessageView::read(conn, private_message_id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
@ -128,8 +128,8 @@ pub(crate) async fn receive_delete_private_message(
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
let message = blocking(&context.pool(), move |conn| {
|
let message = blocking(context.pool(), move |conn| {
|
||||||
PrivateMessageView::read(&conn, deleted_private_message.id)
|
PrivateMessageView::read(conn, deleted_private_message.id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
@ -173,8 +173,8 @@ pub(crate) async fn receive_undo_delete_private_message(
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
let message = blocking(&context.pool(), move |conn| {
|
let message = blocking(context.pool(), move |conn| {
|
||||||
PrivateMessageView::read(&conn, deleted_private_message.id)
|
PrivateMessageView::read(conn, deleted_private_message.id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ where
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
check_is_apub_id_valid(&person_id, false)?;
|
check_is_apub_id_valid(&person_id, false)?;
|
||||||
// check that the sender is a person, not a community
|
// check that the sender is a person, not a community
|
||||||
get_or_fetch_and_upsert_person(&person_id, &context, request_counter).await?;
|
get_or_fetch_and_upsert_person(&person_id, context, request_counter).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,13 +52,13 @@ pub(crate) async fn get_apub_community_followers(
|
||||||
context: web::Data<LemmyContext>,
|
context: web::Data<LemmyContext>,
|
||||||
) -> Result<HttpResponse<Body>, LemmyError> {
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
||||||
let community = blocking(context.pool(), move |conn| {
|
let community = blocking(context.pool(), move |conn| {
|
||||||
Community::read_from_name(&conn, &info.community_name)
|
Community::read_from_name(conn, &info.community_name)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
let community_id = community.id;
|
let community_id = community.id;
|
||||||
let community_followers = blocking(context.pool(), move |conn| {
|
let community_followers = blocking(context.pool(), move |conn| {
|
||||||
CommunityFollowerView::for_community(&conn, community_id)
|
CommunityFollowerView::for_community(conn, community_id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ pub(crate) async fn get_apub_community_outbox(
|
||||||
context: web::Data<LemmyContext>,
|
context: web::Data<LemmyContext>,
|
||||||
) -> Result<HttpResponse<Body>, LemmyError> {
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
||||||
let community = blocking(context.pool(), move |conn| {
|
let community = blocking(context.pool(), move |conn| {
|
||||||
Community::read_from_name(&conn, &info.community_name)
|
Community::read_from_name(conn, &info.community_name)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ pub(crate) async fn get_apub_community_inbox(
|
||||||
context: web::Data<LemmyContext>,
|
context: web::Data<LemmyContext>,
|
||||||
) -> Result<HttpResponse<Body>, LemmyError> {
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
||||||
let community = blocking(context.pool(), move |conn| {
|
let community = blocking(context.pool(), move |conn| {
|
||||||
Community::read_from_name(&conn, &info.community_name)
|
Community::read_from_name(conn, &info.community_name)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ pub(crate) async fn get_apub_community_moderators(
|
||||||
context: web::Data<LemmyContext>,
|
context: web::Data<LemmyContext>,
|
||||||
) -> Result<HttpResponse<Body>, LemmyError> {
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
||||||
let community = blocking(context.pool(), move |conn| {
|
let community = blocking(context.pool(), move |conn| {
|
||||||
Community::read_from_name(&conn, &info.community_name)
|
Community::read_from_name(conn, &info.community_name)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ pub(crate) async fn get_apub_community_moderators(
|
||||||
// ignore that for now
|
// ignore that for now
|
||||||
let cid = community.id;
|
let cid = community.id;
|
||||||
let moderators = blocking(context.pool(), move |conn| {
|
let moderators = blocking(context.pool(), move |conn| {
|
||||||
CommunityModeratorView::for_community(&conn, cid)
|
CommunityModeratorView::for_community(conn, cid)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub(crate) async fn get_activity(
|
||||||
))?
|
))?
|
||||||
.into();
|
.into();
|
||||||
let activity = blocking(context.pool(), move |conn| {
|
let activity = blocking(context.pool(), move |conn| {
|
||||||
Activity::read_from_apub_id(&conn, &activity_id)
|
Activity::read_from_apub_id(conn, &activity_id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ pub(crate) async fn get_apub_person_outbox(
|
||||||
context: web::Data<LemmyContext>,
|
context: web::Data<LemmyContext>,
|
||||||
) -> Result<HttpResponse<Body>, LemmyError> {
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
||||||
let person = blocking(context.pool(), move |conn| {
|
let person = blocking(context.pool(), move |conn| {
|
||||||
Person::find_by_name(&conn, &info.user_name)
|
Person::find_by_name(conn, &info.user_name)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
// TODO: populate the person outbox
|
// TODO: populate the person outbox
|
||||||
|
@ -62,7 +62,7 @@ pub(crate) async fn get_apub_person_inbox(
|
||||||
context: web::Data<LemmyContext>,
|
context: web::Data<LemmyContext>,
|
||||||
) -> Result<HttpResponse<Body>, LemmyError> {
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
||||||
let person = blocking(context.pool(), move |conn| {
|
let person = blocking(context.pool(), move |conn| {
|
||||||
Person::find_by_name(&conn, &info.user_name)
|
Person::find_by_name(conn, &info.user_name)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
|
|
@ -84,12 +84,12 @@ pub async fn community_inbox(
|
||||||
|
|
||||||
// Check if the activity is actually meant for us
|
// Check if the activity is actually meant for us
|
||||||
let path = path.into_inner();
|
let path = path.into_inner();
|
||||||
let community = blocking(&context.pool(), move |conn| {
|
let community = blocking(context.pool(), move |conn| {
|
||||||
Community::read_from_name(&conn, &path)
|
Community::read_from_name(conn, &path)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
let to_and_cc = get_activity_to_and_cc(&activity);
|
let to_and_cc = get_activity_to_and_cc(&activity);
|
||||||
if !to_and_cc.contains(&&community.actor_id()) {
|
if !to_and_cc.contains(&community.actor_id()) {
|
||||||
return Err(anyhow!("Activity delivered to wrong community").into());
|
return Err(anyhow!("Activity delivered to wrong community").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,8 +117,8 @@ pub(crate) async fn community_receive_message(
|
||||||
// Only persons can send activities to the community, so we can get the actor as person
|
// Only persons can send activities to the community, so we can get the actor as person
|
||||||
// unconditionally.
|
// unconditionally.
|
||||||
let actor_id = actor.actor_id();
|
let actor_id = actor.actor_id();
|
||||||
let person = blocking(&context.pool(), move |conn| {
|
let person = blocking(context.pool(), move |conn| {
|
||||||
Person::read_from_apub_id(&conn, &actor_id.into())
|
Person::read_from_apub_id(conn, &actor_id.into())
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
check_community_or_site_ban(&person, to_community.id, context.pool()).await?;
|
check_community_or_site_ban(&person, to_community.id, context.pool()).await?;
|
||||||
|
@ -142,7 +142,7 @@ pub(crate) async fn community_receive_message(
|
||||||
any_base.clone(),
|
any_base.clone(),
|
||||||
person,
|
person,
|
||||||
&to_community,
|
&to_community,
|
||||||
&context,
|
context,
|
||||||
))
|
))
|
||||||
.await?;
|
.await?;
|
||||||
false
|
false
|
||||||
|
@ -282,8 +282,8 @@ async fn handle_follow(
|
||||||
};
|
};
|
||||||
|
|
||||||
// This will fail if they're already a follower, but ignore the error.
|
// This will fail if they're already a follower, but ignore the error.
|
||||||
blocking(&context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
CommunityFollower::follow(&conn, &community_follower_form).ok()
|
CommunityFollower::follow(conn, &community_follower_form).ok()
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -304,7 +304,7 @@ async fn handle_undo(
|
||||||
.is_single_kind(&FollowType::Follow.to_string());
|
.is_single_kind(&FollowType::Follow.to_string());
|
||||||
let any_base = activity.into_any_base()?;
|
let any_base = activity.into_any_base()?;
|
||||||
if inner_kind {
|
if inner_kind {
|
||||||
handle_undo_follow(any_base, actor_url, to_community, &context).await?;
|
handle_undo_follow(any_base, actor_url, to_community, context).await?;
|
||||||
Ok(false)
|
Ok(false)
|
||||||
} else {
|
} else {
|
||||||
receive_undo_for_community(context, any_base, None, &actor_url, request_counter).await?;
|
receive_undo_for_community(context, any_base, None, &actor_url, request_counter).await?;
|
||||||
|
@ -326,8 +326,8 @@ async fn handle_undo_follow(
|
||||||
let follow = Follow::from_any_base(object)?.context(location_info!())?;
|
let follow = Follow::from_any_base(object)?.context(location_info!())?;
|
||||||
verify_activity_domains_valid(&follow, &person_url, false)?;
|
verify_activity_domains_valid(&follow, &person_url, false)?;
|
||||||
|
|
||||||
let person = blocking(&context.pool(), move |conn| {
|
let person = blocking(context.pool(), move |conn| {
|
||||||
Person::read_from_apub_id(&conn, &person_url.into())
|
Person::read_from_apub_id(conn, &person_url.into())
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
|
@ -337,8 +337,8 @@ async fn handle_undo_follow(
|
||||||
};
|
};
|
||||||
|
|
||||||
// This will fail if they aren't a follower, but ignore the error.
|
// This will fail if they aren't a follower, but ignore the error.
|
||||||
blocking(&context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
CommunityFollower::unfollow(&conn, &community_follower_form).ok()
|
CommunityFollower::unfollow(conn, &community_follower_form).ok()
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ pub(crate) async fn is_activity_already_known(
|
||||||
) -> Result<bool, LemmyError> {
|
) -> Result<bool, LemmyError> {
|
||||||
let activity_id = activity_id.to_owned().into();
|
let activity_id = activity_id.to_owned().into();
|
||||||
let existing = blocking(pool, move |conn| {
|
let existing = blocking(pool, move |conn| {
|
||||||
Activity::read_from_apub_id(&conn, &activity_id)
|
Activity::read_from_apub_id(conn, &activity_id)
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
match existing {
|
match existing {
|
||||||
|
@ -86,7 +86,7 @@ where
|
||||||
.single_xsd_any_uri()
|
.single_xsd_any_uri()
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
check_is_apub_id_valid(&actor_id, false)?;
|
check_is_apub_id_valid(&actor_id, false)?;
|
||||||
let actor = get_or_fetch_and_upsert_actor(&actor_id, &context, request_counter).await?;
|
let actor = get_or_fetch_and_upsert_actor(&actor_id, context, request_counter).await?;
|
||||||
verify_signature(&request, actor.as_ref())?;
|
verify_signature(&request, actor.as_ref())?;
|
||||||
Ok(actor)
|
Ok(actor)
|
||||||
}
|
}
|
||||||
|
@ -98,8 +98,8 @@ pub(crate) async fn is_addressed_to_local_person(
|
||||||
) -> Result<bool, LemmyError> {
|
) -> Result<bool, LemmyError> {
|
||||||
for url in to_and_cc {
|
for url in to_and_cc {
|
||||||
let url = url.to_owned();
|
let url = url.to_owned();
|
||||||
let person = blocking(&pool, move |conn| {
|
let person = blocking(pool, move |conn| {
|
||||||
Person::read_from_apub_id(&conn, &url.into())
|
Person::read_from_apub_id(conn, &url.into())
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
if let Ok(u) = person {
|
if let Ok(u) = person {
|
||||||
|
@ -119,9 +119,9 @@ pub(crate) async fn is_addressed_to_community_followers(
|
||||||
) -> Result<Option<Community>, LemmyError> {
|
) -> Result<Option<Community>, LemmyError> {
|
||||||
for url in to_and_cc {
|
for url in to_and_cc {
|
||||||
let url = url.to_owned().into();
|
let url = url.to_owned().into();
|
||||||
let community = blocking(&pool, move |conn| {
|
let community = blocking(pool, move |conn| {
|
||||||
// ignore errors here, because the current url might not actually be a followers url
|
// ignore errors here, because the current url might not actually be a followers url
|
||||||
Community::read_from_followers_url(&conn, &url).ok()
|
Community::read_from_followers_url(conn, &url).ok()
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
if let Some(c) = community {
|
if let Some(c) = community {
|
||||||
|
|
|
@ -102,13 +102,13 @@ pub async fn person_inbox(
|
||||||
|
|
||||||
// Check if the activity is actually meant for us
|
// Check if the activity is actually meant for us
|
||||||
let username = path.into_inner();
|
let username = path.into_inner();
|
||||||
let person = blocking(&context.pool(), move |conn| {
|
let person = blocking(context.pool(), move |conn| {
|
||||||
Person::find_by_name(&conn, &username)
|
Person::find_by_name(conn, &username)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
let to_and_cc = get_activity_to_and_cc(&activity);
|
let to_and_cc = get_activity_to_and_cc(&activity);
|
||||||
// TODO: we should also accept activities that are sent to community followers
|
// TODO: we should also accept activities that are sent to community followers
|
||||||
if !to_and_cc.contains(&&person.actor_id()) {
|
if !to_and_cc.contains(&person.actor_id()) {
|
||||||
return Err(anyhow!("Activity delivered to wrong person").into());
|
return Err(anyhow!("Activity delivered to wrong person").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ pub(crate) async fn person_receive_message(
|
||||||
match kind {
|
match kind {
|
||||||
PersonValidTypes::Accept => {
|
PersonValidTypes::Accept => {
|
||||||
receive_accept(
|
receive_accept(
|
||||||
&context,
|
context,
|
||||||
any_base,
|
any_base,
|
||||||
actor,
|
actor,
|
||||||
to_person.expect("person provided"),
|
to_person.expect("person provided"),
|
||||||
|
@ -159,11 +159,11 @@ pub(crate) async fn person_receive_message(
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
PersonValidTypes::Announce => {
|
PersonValidTypes::Announce => {
|
||||||
Box::pin(receive_announce(&context, any_base, actor, request_counter)).await?
|
Box::pin(receive_announce(context, any_base, actor, request_counter)).await?
|
||||||
}
|
}
|
||||||
PersonValidTypes::Create => {
|
PersonValidTypes::Create => {
|
||||||
Box::pin(receive_create(
|
Box::pin(receive_create(
|
||||||
&context,
|
context,
|
||||||
any_base,
|
any_base,
|
||||||
actor_url,
|
actor_url,
|
||||||
request_counter,
|
request_counter,
|
||||||
|
@ -172,7 +172,7 @@ pub(crate) async fn person_receive_message(
|
||||||
}
|
}
|
||||||
PersonValidTypes::Update => {
|
PersonValidTypes::Update => {
|
||||||
Box::pin(receive_update(
|
Box::pin(receive_update(
|
||||||
&context,
|
context,
|
||||||
any_base,
|
any_base,
|
||||||
actor_url,
|
actor_url,
|
||||||
request_counter,
|
request_counter,
|
||||||
|
@ -217,7 +217,7 @@ async fn is_for_person_inbox(
|
||||||
let community = is_addressed_to_community_followers(&to_and_cc, context.pool()).await?;
|
let community = is_addressed_to_community_followers(&to_and_cc, context.pool()).await?;
|
||||||
if let Some(c) = community {
|
if let Some(c) = community {
|
||||||
let community_id = c.id;
|
let community_id = c.id;
|
||||||
let has_local_followers = blocking(&context.pool(), move |conn| {
|
let has_local_followers = blocking(context.pool(), move |conn| {
|
||||||
CommunityFollower::has_local_followers(conn, community_id)
|
CommunityFollower::has_local_followers(conn, community_id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
@ -261,7 +261,7 @@ async fn receive_accept(
|
||||||
let community_id = community.id;
|
let community_id = community.id;
|
||||||
let person_id = person.id;
|
let person_id = person.id;
|
||||||
// This will throw an error if no follow was requested
|
// This will throw an error if no follow was requested
|
||||||
blocking(&context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
CommunityFollower::follow_accepted(conn, community_id, person_id)
|
CommunityFollower::follow_accepted(conn, community_id, person_id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
@ -377,7 +377,7 @@ async fn receive_create(
|
||||||
if verify_is_addressed_to_public(&create).is_ok() {
|
if verify_is_addressed_to_public(&create).is_ok() {
|
||||||
receive_create_comment(create, context, request_counter).await
|
receive_create_comment(create, context, request_counter).await
|
||||||
} else {
|
} else {
|
||||||
receive_create_private_message(&context, create, expected_domain, request_counter).await
|
receive_create_private_message(context, create, expected_domain, request_counter).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,7 +394,7 @@ async fn receive_update(
|
||||||
if verify_is_addressed_to_public(&update).is_ok() {
|
if verify_is_addressed_to_public(&update).is_ok() {
|
||||||
receive_update_comment(update, context, request_counter).await
|
receive_update_comment(update, context, request_counter).await
|
||||||
} else {
|
} else {
|
||||||
receive_update_private_message(&context, update, expected_domain, request_counter).await
|
receive_update_private_message(context, update, expected_domain, request_counter).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,7 +436,7 @@ async fn receive_remove(
|
||||||
Community::read_from_apub_id(conn, &object_uri.into())
|
Community::read_from_apub_id(conn, &object_uri.into())
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
receive_remove_community(&context, community).await
|
receive_remove_community(context, community).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn receive_undo(
|
async fn receive_undo(
|
||||||
|
|
|
@ -128,7 +128,7 @@ pub(in crate::inbox) async fn receive_create_for_community(
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let create = Create::from_any_base(activity)?.context(location_info!())?;
|
let create = Create::from_any_base(activity)?.context(location_info!())?;
|
||||||
verify_activity_domains_valid(&create, &expected_domain, true)?;
|
verify_activity_domains_valid(&create, expected_domain, true)?;
|
||||||
verify_is_addressed_to_public(&create)?;
|
verify_is_addressed_to_public(&create)?;
|
||||||
|
|
||||||
let kind = create
|
let kind = create
|
||||||
|
@ -151,7 +151,7 @@ pub(in crate::inbox) async fn receive_update_for_community(
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let update = Update::from_any_base(activity.to_owned())?.context(location_info!())?;
|
let update = Update::from_any_base(activity.to_owned())?.context(location_info!())?;
|
||||||
verify_activity_domains_valid(&update, &expected_domain, false)?;
|
verify_activity_domains_valid(&update, expected_domain, false)?;
|
||||||
verify_is_addressed_to_public(&update)?;
|
verify_is_addressed_to_public(&update)?;
|
||||||
verify_modification_actor_instance(&update, &announce, context, request_counter).await?;
|
verify_modification_actor_instance(&update, &announce, context, request_counter).await?;
|
||||||
|
|
||||||
|
@ -179,14 +179,14 @@ pub(in crate::inbox) async fn receive_like_for_community(
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let like = Like::from_any_base(activity)?.context(location_info!())?;
|
let like = Like::from_any_base(activity)?.context(location_info!())?;
|
||||||
verify_activity_domains_valid(&like, &expected_domain, false)?;
|
verify_activity_domains_valid(&like, expected_domain, false)?;
|
||||||
verify_is_addressed_to_public(&like)?;
|
verify_is_addressed_to_public(&like)?;
|
||||||
|
|
||||||
let object_id = like
|
let object_id = like
|
||||||
.object()
|
.object()
|
||||||
.as_single_xsd_any_uri()
|
.as_single_xsd_any_uri()
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
match fetch_post_or_comment_by_id(&object_id, context, request_counter).await? {
|
match fetch_post_or_comment_by_id(object_id, context, request_counter).await? {
|
||||||
PostOrComment::Post(post) => receive_like_post(like, *post, context, request_counter).await,
|
PostOrComment::Post(post) => receive_like_post(like, *post, context, request_counter).await,
|
||||||
PostOrComment::Comment(comment) => {
|
PostOrComment::Comment(comment) => {
|
||||||
receive_like_comment(like, *comment, context, request_counter).await
|
receive_like_comment(like, *comment, context, request_counter).await
|
||||||
|
@ -210,14 +210,14 @@ pub(in crate::inbox) async fn receive_dislike_for_community(
|
||||||
}
|
}
|
||||||
|
|
||||||
let dislike = Dislike::from_any_base(activity)?.context(location_info!())?;
|
let dislike = Dislike::from_any_base(activity)?.context(location_info!())?;
|
||||||
verify_activity_domains_valid(&dislike, &expected_domain, false)?;
|
verify_activity_domains_valid(&dislike, expected_domain, false)?;
|
||||||
verify_is_addressed_to_public(&dislike)?;
|
verify_is_addressed_to_public(&dislike)?;
|
||||||
|
|
||||||
let object_id = dislike
|
let object_id = dislike
|
||||||
.object()
|
.object()
|
||||||
.as_single_xsd_any_uri()
|
.as_single_xsd_any_uri()
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
match fetch_post_or_comment_by_id(&object_id, context, request_counter).await? {
|
match fetch_post_or_comment_by_id(object_id, context, request_counter).await? {
|
||||||
PostOrComment::Post(post) => {
|
PostOrComment::Post(post) => {
|
||||||
receive_dislike_post(dislike, *post, context, request_counter).await
|
receive_dislike_post(dislike, *post, context, request_counter).await
|
||||||
}
|
}
|
||||||
|
@ -248,11 +248,11 @@ pub(in crate::inbox) async fn receive_delete_for_community(
|
||||||
|
|
||||||
match find_object_by_id(context, object).await {
|
match find_object_by_id(context, object).await {
|
||||||
Ok(Object::Post(p)) => {
|
Ok(Object::Post(p)) => {
|
||||||
verify_activity_domains_valid(&delete, &expected_domain, true)?;
|
verify_activity_domains_valid(&delete, expected_domain, true)?;
|
||||||
receive_delete_post(context, *p).await
|
receive_delete_post(context, *p).await
|
||||||
}
|
}
|
||||||
Ok(Object::Comment(c)) => {
|
Ok(Object::Comment(c)) => {
|
||||||
verify_activity_domains_valid(&delete, &expected_domain, true)?;
|
verify_activity_domains_valid(&delete, expected_domain, true)?;
|
||||||
receive_delete_comment(context, *c).await
|
receive_delete_comment(context, *c).await
|
||||||
}
|
}
|
||||||
Ok(Object::Community(c)) => {
|
Ok(Object::Community(c)) => {
|
||||||
|
@ -281,7 +281,7 @@ pub(in crate::inbox) async fn receive_remove_for_community(
|
||||||
.object()
|
.object()
|
||||||
.as_single_xsd_any_uri()
|
.as_single_xsd_any_uri()
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
let remove_mod = get_or_fetch_and_upsert_person(&remove_mod, context, request_counter).await?;
|
let remove_mod = get_or_fetch_and_upsert_person(remove_mod, context, request_counter).await?;
|
||||||
let form = CommunityModeratorForm {
|
let form = CommunityModeratorForm {
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
person_id: remove_mod.id,
|
person_id: remove_mod.id,
|
||||||
|
@ -388,11 +388,11 @@ pub(in crate::inbox) async fn receive_undo_delete_for_community(
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
match find_object_by_id(context, object).await {
|
match find_object_by_id(context, object).await {
|
||||||
Ok(Object::Post(p)) => {
|
Ok(Object::Post(p)) => {
|
||||||
verify_activity_domains_valid(&delete, &expected_domain, true)?;
|
verify_activity_domains_valid(&delete, expected_domain, true)?;
|
||||||
receive_undo_delete_post(context, *p).await
|
receive_undo_delete_post(context, *p).await
|
||||||
}
|
}
|
||||||
Ok(Object::Comment(c)) => {
|
Ok(Object::Comment(c)) => {
|
||||||
verify_activity_domains_valid(&delete, &expected_domain, true)?;
|
verify_activity_domains_valid(&delete, expected_domain, true)?;
|
||||||
receive_undo_delete_comment(context, *c).await
|
receive_undo_delete_comment(context, *c).await
|
||||||
}
|
}
|
||||||
Ok(Object::Community(c)) => {
|
Ok(Object::Community(c)) => {
|
||||||
|
@ -413,7 +413,7 @@ pub(in crate::inbox) async fn receive_undo_remove_for_community(
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let remove = Remove::from_any_base(undo.object().to_owned().one().context(location_info!())?)?
|
let remove = Remove::from_any_base(undo.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
verify_activity_domains_valid(&remove, &expected_domain, false)?;
|
verify_activity_domains_valid(&remove, expected_domain, false)?;
|
||||||
verify_is_addressed_to_public(&remove)?;
|
verify_is_addressed_to_public(&remove)?;
|
||||||
verify_undo_remove_actor_instance(&undo, &remove, &announce, context).await?;
|
verify_undo_remove_actor_instance(&undo, &remove, &announce, context).await?;
|
||||||
|
|
||||||
|
@ -439,14 +439,14 @@ pub(in crate::inbox) async fn receive_undo_like_for_community(
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let like = Like::from_any_base(undo.object().to_owned().one().context(location_info!())?)?
|
let like = Like::from_any_base(undo.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
verify_activity_domains_valid(&like, &expected_domain, false)?;
|
verify_activity_domains_valid(&like, expected_domain, false)?;
|
||||||
verify_is_addressed_to_public(&like)?;
|
verify_is_addressed_to_public(&like)?;
|
||||||
|
|
||||||
let object_id = like
|
let object_id = like
|
||||||
.object()
|
.object()
|
||||||
.as_single_xsd_any_uri()
|
.as_single_xsd_any_uri()
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
match fetch_post_or_comment_by_id(&object_id, context, request_counter).await? {
|
match fetch_post_or_comment_by_id(object_id, context, request_counter).await? {
|
||||||
PostOrComment::Post(post) => {
|
PostOrComment::Post(post) => {
|
||||||
receive_undo_like_post(&like, *post, context, request_counter).await
|
receive_undo_like_post(&like, *post, context, request_counter).await
|
||||||
}
|
}
|
||||||
|
@ -474,7 +474,7 @@ pub(in crate::inbox) async fn receive_add_for_community(
|
||||||
.object()
|
.object()
|
||||||
.as_single_xsd_any_uri()
|
.as_single_xsd_any_uri()
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
let new_mod = get_or_fetch_and_upsert_person(&new_mod, context, request_counter).await?;
|
let new_mod = get_or_fetch_and_upsert_person(new_mod, context, request_counter).await?;
|
||||||
|
|
||||||
// If we had to refetch the community while parsing the activity, then the new mod has already
|
// If we had to refetch the community while parsing the activity, then the new mod has already
|
||||||
// been added. Skip it here as it would result in a duplicate key error.
|
// been added. Skip it here as it would result in a duplicate key error.
|
||||||
|
@ -515,14 +515,14 @@ pub(in crate::inbox) async fn receive_undo_dislike_for_community(
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let dislike = Dislike::from_any_base(undo.object().to_owned().one().context(location_info!())?)?
|
let dislike = Dislike::from_any_base(undo.object().to_owned().one().context(location_info!())?)?
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
verify_activity_domains_valid(&dislike, &expected_domain, false)?;
|
verify_activity_domains_valid(&dislike, expected_domain, false)?;
|
||||||
verify_is_addressed_to_public(&dislike)?;
|
verify_is_addressed_to_public(&dislike)?;
|
||||||
|
|
||||||
let object_id = dislike
|
let object_id = dislike
|
||||||
.object()
|
.object()
|
||||||
.as_single_xsd_any_uri()
|
.as_single_xsd_any_uri()
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
match fetch_post_or_comment_by_id(&object_id, context, request_counter).await? {
|
match fetch_post_or_comment_by_id(object_id, context, request_counter).await? {
|
||||||
PostOrComment::Post(post) => {
|
PostOrComment::Post(post) => {
|
||||||
receive_undo_dislike_post(&dislike, *post, context, request_counter).await
|
receive_undo_dislike_post(&dislike, *post, context, request_counter).await
|
||||||
}
|
}
|
||||||
|
@ -548,8 +548,7 @@ pub(crate) async fn receive_block_user_for_community(
|
||||||
.object()
|
.object()
|
||||||
.as_single_xsd_any_uri()
|
.as_single_xsd_any_uri()
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
let blocked_user =
|
let blocked_user = get_or_fetch_and_upsert_person(blocked_user, context, request_counter).await?;
|
||||||
get_or_fetch_and_upsert_person(&blocked_user, context, request_counter).await?;
|
|
||||||
|
|
||||||
let community_user_ban_form = CommunityPersonBanForm {
|
let community_user_ban_form = CommunityPersonBanForm {
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
|
@ -587,7 +586,7 @@ pub(crate) async fn receive_undo_block_user_for_community(
|
||||||
let block = Block::from_any_base(object)?.context(location_info!())?;
|
let block = Block::from_any_base(object)?.context(location_info!())?;
|
||||||
let community = extract_community_from_cc(&block, context).await?;
|
let community = extract_community_from_cc(&block, context).await?;
|
||||||
|
|
||||||
verify_activity_domains_valid(&block, &expected_domain, false)?;
|
verify_activity_domains_valid(&block, expected_domain, false)?;
|
||||||
verify_is_addressed_to_public(&block)?;
|
verify_is_addressed_to_public(&block)?;
|
||||||
verify_undo_remove_actor_instance(&undo, &block, &announce, context).await?;
|
verify_undo_remove_actor_instance(&undo, &block, &announce, context).await?;
|
||||||
|
|
||||||
|
@ -595,8 +594,7 @@ pub(crate) async fn receive_undo_block_user_for_community(
|
||||||
.object()
|
.object()
|
||||||
.as_single_xsd_any_uri()
|
.as_single_xsd_any_uri()
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
let blocked_user =
|
let blocked_user = get_or_fetch_and_upsert_person(blocked_user, context, request_counter).await?;
|
||||||
get_or_fetch_and_upsert_person(&blocked_user, context, request_counter).await?;
|
|
||||||
|
|
||||||
let community_user_ban_form = CommunityPersonBanForm {
|
let community_user_ban_form = CommunityPersonBanForm {
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
|
@ -646,8 +644,8 @@ where
|
||||||
.flatten()
|
.flatten()
|
||||||
.context(location_info!())?;
|
.context(location_info!())?;
|
||||||
let community_id: DbUrl = community_id.to_owned().into();
|
let community_id: DbUrl = community_id.to_owned().into();
|
||||||
let community = blocking(&context.pool(), move |conn| {
|
let community = blocking(context.pool(), move |conn| {
|
||||||
Community::read_from_apub_id(&conn, &community_id)
|
Community::read_from_apub_id(conn, &community_id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
Ok(community)
|
Ok(community)
|
||||||
|
@ -672,8 +670,8 @@ where
|
||||||
.as_single_xsd_any_uri()
|
.as_single_xsd_any_uri()
|
||||||
.context(location_info!())?
|
.context(location_info!())?
|
||||||
.to_owned();
|
.to_owned();
|
||||||
let actor = blocking(&context.pool(), move |conn| {
|
let actor = blocking(context.pool(), move |conn| {
|
||||||
Person::read_from_apub_id(&conn, &actor.into())
|
Person::read_from_apub_id(conn, &actor.into())
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
|
|
|
@ -137,8 +137,8 @@ async fn extract_local_community_from_destinations(
|
||||||
) -> Result<Option<Community>, LemmyError> {
|
) -> Result<Option<Community>, LemmyError> {
|
||||||
for url in to_and_cc {
|
for url in to_and_cc {
|
||||||
let url = url.to_owned();
|
let url = url.to_owned();
|
||||||
let community = blocking(&pool, move |conn| {
|
let community = blocking(pool, move |conn| {
|
||||||
Community::read_from_apub_id(&conn, &url.into())
|
Community::read_from_apub_id(conn, &url.into())
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
if let Ok(c) = community {
|
if let Ok(c) = community {
|
||||||
|
|
|
@ -314,7 +314,7 @@ mod tests {
|
||||||
let example_url = "https://example.com";
|
let example_url = "https://example.com";
|
||||||
assert!(matches!(
|
assert!(matches!(
|
||||||
diesel_option_overwrite_to_url(&Some(example_url.to_string())),
|
diesel_option_overwrite_to_url(&Some(example_url.to_string())),
|
||||||
Ok(Some(Some(url))) if url == Url::parse(&example_url).unwrap().into()
|
Ok(Some(Some(url))) if url == Url::parse(example_url).unwrap().into()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ impl Activity_ for Activity {
|
||||||
sensitive,
|
sensitive,
|
||||||
updated: None,
|
updated: None,
|
||||||
};
|
};
|
||||||
let result = Activity::create(&conn, &activity_form);
|
let result = Activity::create(conn, &activity_form);
|
||||||
match result {
|
match result {
|
||||||
Ok(s) => Ok(s),
|
Ok(s) => Ok(s),
|
||||||
Err(e) => Err(IoError::new(
|
Err(e) => Err(IoError::new(
|
||||||
|
|
|
@ -70,7 +70,7 @@ impl LocalUser_ for LocalUser {
|
||||||
hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password");
|
hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password");
|
||||||
edited_user.password_encrypted = password_hash;
|
edited_user.password_encrypted = password_hash;
|
||||||
|
|
||||||
Self::create(&conn, &edited_user)
|
Self::create(conn, &edited_user)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_password(
|
fn update_password(
|
||||||
|
|
|
@ -53,7 +53,7 @@ impl PasswordResetRequest_ for PasswordResetRequest {
|
||||||
token_encrypted: token_hash,
|
token_encrypted: token_hash,
|
||||||
};
|
};
|
||||||
|
|
||||||
Self::create(&conn, &form)
|
Self::create(conn, &form)
|
||||||
}
|
}
|
||||||
fn read_from_token(conn: &PgConnection, token: &str) -> Result<PasswordResetRequest, Error> {
|
fn read_from_token(conn: &PgConnection, token: &str) -> Result<PasswordResetRequest, Error> {
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
|
|
|
@ -88,10 +88,10 @@ async fn get_feed_data(
|
||||||
listing_type: ListingType,
|
listing_type: ListingType,
|
||||||
sort_type: SortType,
|
sort_type: SortType,
|
||||||
) -> Result<HttpResponse, LemmyError> {
|
) -> Result<HttpResponse, LemmyError> {
|
||||||
let site_view = blocking(context.pool(), move |conn| SiteView::read(&conn)).await??;
|
let site_view = blocking(context.pool(), move |conn| SiteView::read(conn)).await??;
|
||||||
|
|
||||||
let posts = blocking(context.pool(), move |conn| {
|
let posts = blocking(context.pool(), move |conn| {
|
||||||
PostQueryBuilder::create(&conn)
|
PostQueryBuilder::create(conn)
|
||||||
.listing_type(listing_type)
|
.listing_type(listing_type)
|
||||||
.sort(sort_type)
|
.sort(sort_type)
|
||||||
.list()
|
.list()
|
||||||
|
@ -169,10 +169,10 @@ fn get_feed_user(
|
||||||
sort_type: &SortType,
|
sort_type: &SortType,
|
||||||
user_name: String,
|
user_name: String,
|
||||||
) -> Result<ChannelBuilder, LemmyError> {
|
) -> Result<ChannelBuilder, LemmyError> {
|
||||||
let site_view = SiteView::read(&conn)?;
|
let site_view = SiteView::read(conn)?;
|
||||||
let person = Person::find_by_name(&conn, &user_name)?;
|
let person = Person::find_by_name(conn, &user_name)?;
|
||||||
|
|
||||||
let posts = PostQueryBuilder::create(&conn)
|
let posts = PostQueryBuilder::create(conn)
|
||||||
.listing_type(ListingType::All)
|
.listing_type(ListingType::All)
|
||||||
.sort(*sort_type)
|
.sort(*sort_type)
|
||||||
.creator_id(person.id)
|
.creator_id(person.id)
|
||||||
|
@ -195,10 +195,10 @@ fn get_feed_community(
|
||||||
sort_type: &SortType,
|
sort_type: &SortType,
|
||||||
community_name: String,
|
community_name: String,
|
||||||
) -> Result<ChannelBuilder, LemmyError> {
|
) -> Result<ChannelBuilder, LemmyError> {
|
||||||
let site_view = SiteView::read(&conn)?;
|
let site_view = SiteView::read(conn)?;
|
||||||
let community = Community::read_from_name(&conn, &community_name)?;
|
let community = Community::read_from_name(conn, &community_name)?;
|
||||||
|
|
||||||
let posts = PostQueryBuilder::create(&conn)
|
let posts = PostQueryBuilder::create(conn)
|
||||||
.listing_type(ListingType::All)
|
.listing_type(ListingType::All)
|
||||||
.sort(*sort_type)
|
.sort(*sort_type)
|
||||||
.community_id(community.id)
|
.community_id(community.id)
|
||||||
|
@ -225,14 +225,14 @@ fn get_feed_front(
|
||||||
sort_type: &SortType,
|
sort_type: &SortType,
|
||||||
jwt: String,
|
jwt: String,
|
||||||
) -> Result<ChannelBuilder, LemmyError> {
|
) -> Result<ChannelBuilder, LemmyError> {
|
||||||
let site_view = SiteView::read(&conn)?;
|
let site_view = SiteView::read(conn)?;
|
||||||
let local_user_id = LocalUserId(Claims::decode(&jwt)?.claims.sub);
|
let local_user_id = LocalUserId(Claims::decode(&jwt)?.claims.sub);
|
||||||
let local_user = LocalUser::read(&conn, local_user_id)?;
|
let local_user = LocalUser::read(conn, local_user_id)?;
|
||||||
let person_id = local_user.person_id;
|
let person_id = local_user.person_id;
|
||||||
let show_bot_accounts = local_user.show_bot_accounts;
|
let show_bot_accounts = local_user.show_bot_accounts;
|
||||||
let show_read_posts = local_user.show_read_posts;
|
let show_read_posts = local_user.show_read_posts;
|
||||||
|
|
||||||
let posts = PostQueryBuilder::create(&conn)
|
let posts = PostQueryBuilder::create(conn)
|
||||||
.listing_type(ListingType::Subscribed)
|
.listing_type(ListingType::Subscribed)
|
||||||
.my_person_id(person_id)
|
.my_person_id(person_id)
|
||||||
.show_bot_accounts(show_bot_accounts)
|
.show_bot_accounts(show_bot_accounts)
|
||||||
|
@ -257,22 +257,22 @@ fn get_feed_front(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_feed_inbox(conn: &PgConnection, jwt: String) -> Result<ChannelBuilder, LemmyError> {
|
fn get_feed_inbox(conn: &PgConnection, jwt: String) -> Result<ChannelBuilder, LemmyError> {
|
||||||
let site_view = SiteView::read(&conn)?;
|
let site_view = SiteView::read(conn)?;
|
||||||
let local_user_id = LocalUserId(Claims::decode(&jwt)?.claims.sub);
|
let local_user_id = LocalUserId(Claims::decode(&jwt)?.claims.sub);
|
||||||
let local_user = LocalUser::read(&conn, local_user_id)?;
|
let local_user = LocalUser::read(conn, local_user_id)?;
|
||||||
let person_id = local_user.person_id;
|
let person_id = local_user.person_id;
|
||||||
let show_bot_accounts = local_user.show_bot_accounts;
|
let show_bot_accounts = local_user.show_bot_accounts;
|
||||||
|
|
||||||
let sort = SortType::New;
|
let sort = SortType::New;
|
||||||
|
|
||||||
let replies = CommentQueryBuilder::create(&conn)
|
let replies = CommentQueryBuilder::create(conn)
|
||||||
.recipient_id(person_id)
|
.recipient_id(person_id)
|
||||||
.my_person_id(person_id)
|
.my_person_id(person_id)
|
||||||
.show_bot_accounts(show_bot_accounts)
|
.show_bot_accounts(show_bot_accounts)
|
||||||
.sort(sort)
|
.sort(sort)
|
||||||
.list()?;
|
.list()?;
|
||||||
|
|
||||||
let mentions = PersonMentionQueryBuilder::create(&conn)
|
let mentions = PersonMentionQueryBuilder::create(conn)
|
||||||
.recipient_id(person_id)
|
.recipient_id(person_id)
|
||||||
.my_person_id(person_id)
|
.my_person_id(person_id)
|
||||||
.sort(sort)
|
.sort(sort)
|
||||||
|
|
|
@ -18,7 +18,7 @@ rand = "0.8.3"
|
||||||
percent-encoding = "2.1.0"
|
percent-encoding = "2.1.0"
|
||||||
serde = { version = "1.0.123", features = ["derive"] }
|
serde = { version = "1.0.123", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.61", features = ["preserve_order"] }
|
serde_json = { version = "1.0.61", features = ["preserve_order"] }
|
||||||
thiserror = "1.0.23"
|
thiserror = "1.0.26"
|
||||||
comrak = { version = "0.9.0", default-features = false }
|
comrak = { version = "0.9.0", default-features = false }
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
openssl = "0.10.32"
|
openssl = "0.10.32"
|
||||||
|
|
|
@ -21,7 +21,7 @@ impl Claims {
|
||||||
..Validation::default()
|
..Validation::default()
|
||||||
};
|
};
|
||||||
decode::<Claims>(
|
decode::<Claims>(
|
||||||
&jwt,
|
jwt,
|
||||||
&DecodingKey::from_secret(Settings::get().jwt_secret().as_ref()),
|
&DecodingKey::from_secret(Settings::get().jwt_secret().as_ref()),
|
||||||
&v,
|
&v,
|
||||||
)
|
)
|
||||||
|
|
|
@ -134,7 +134,7 @@ pub async fn fetch_iframely_and_pictrs_data(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// Try to generate a small thumbnail if iframely is not supported
|
// Try to generate a small thumbnail if iframely is not supported
|
||||||
None => match fetch_pictrs(client, &url).await {
|
None => match fetch_pictrs(client, url).await {
|
||||||
Ok(res) => Some(res.files[0].file.to_owned()),
|
Ok(res) => Some(res.files[0].file.to_owned()),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("pictrs err: {}", e);
|
error!("pictrs err: {}", e);
|
||||||
|
|
|
@ -71,7 +71,7 @@ fn test_slur_filter() {
|
||||||
"faggot test kike tranny cocksucker retardeds. Capitalized Niggerz. This is a bunch of other safe text.";
|
"faggot test kike tranny cocksucker retardeds. Capitalized Niggerz. This is a bunch of other safe text.";
|
||||||
let slur_free = "No slurs here";
|
let slur_free = "No slurs here";
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
remove_slurs(&test),
|
remove_slurs(test),
|
||||||
"*removed* test *removed* *removed* *removed* *removed*. Capitalized *removed*. This is a bunch of other safe text."
|
"*removed* test *removed* *removed* *removed* *removed*. Capitalized *removed*. This is a bunch of other safe text."
|
||||||
.to_string()
|
.to_string()
|
||||||
);
|
);
|
||||||
|
|
|
@ -14,7 +14,7 @@ lazy_static! {
|
||||||
slurs.push('|');
|
slurs.push('|');
|
||||||
slurs.push_str(&additional_slurs);
|
slurs.push_str(&additional_slurs);
|
||||||
};
|
};
|
||||||
RegexBuilder::new(&&slurs).case_insensitive(true).build().expect("compile regex")
|
RegexBuilder::new(&slurs).case_insensitive(true).build().expect("compile regex")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -461,7 +461,7 @@ impl ChatServer {
|
||||||
message: "Unknown op type".to_string(),
|
message: "Unknown op type".to_string(),
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if let Ok(user_operation_crud) = UserOperationCrud::from_str(&op) {
|
if let Ok(user_operation_crud) = UserOperationCrud::from_str(op) {
|
||||||
let fut = (message_handler_crud)(context, msg.id, user_operation_crud.clone(), data);
|
let fut = (message_handler_crud)(context, msg.id, user_operation_crud.clone(), data);
|
||||||
match user_operation_crud {
|
match user_operation_crud {
|
||||||
UserOperationCrud::Register => rate_limiter.register().wrap(ip, fut).await,
|
UserOperationCrud::Register => rate_limiter.register().wrap(ip, fut).await,
|
||||||
|
@ -470,7 +470,7 @@ impl ChatServer {
|
||||||
_ => rate_limiter.message().wrap(ip, fut).await,
|
_ => rate_limiter.message().wrap(ip, fut).await,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let user_operation = UserOperation::from_str(&op)?;
|
let user_operation = UserOperation::from_str(op)?;
|
||||||
let fut = (message_handler)(context, msg.id, user_operation.clone(), data);
|
let fut = (message_handler)(context, msg.id, user_operation.clone(), data);
|
||||||
rate_limiter.message().wrap(ip, fut).await
|
rate_limiter.message().wrap(ip, fut).await
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,13 +28,13 @@ use lemmy_utils::{apub::generate_actor_keypair, settings::structs::Settings, Lem
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
pub fn run_advanced_migrations(conn: &PgConnection) -> Result<(), LemmyError> {
|
pub fn run_advanced_migrations(conn: &PgConnection) -> Result<(), LemmyError> {
|
||||||
user_updates_2020_04_02(&conn)?;
|
user_updates_2020_04_02(conn)?;
|
||||||
community_updates_2020_04_02(&conn)?;
|
community_updates_2020_04_02(conn)?;
|
||||||
post_updates_2020_04_03(&conn)?;
|
post_updates_2020_04_03(conn)?;
|
||||||
comment_updates_2020_04_03(&conn)?;
|
comment_updates_2020_04_03(conn)?;
|
||||||
private_message_updates_2020_05_05(&conn)?;
|
private_message_updates_2020_05_05(conn)?;
|
||||||
post_thumbnail_url_updates_2020_07_27(&conn)?;
|
post_thumbnail_url_updates_2020_07_27(conn)?;
|
||||||
apub_columns_2021_02_02(&conn)?;
|
apub_columns_2021_02_02(conn)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
|
||||||
..PersonForm::default()
|
..PersonForm::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
Person::update(&conn, cperson.id, &form)?;
|
Person::update(conn, cperson.id, &form)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("{} person rows updated.", incorrect_persons.len());
|
info!("{} person rows updated.", incorrect_persons.len());
|
||||||
|
@ -106,7 +106,7 @@ fn community_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
|
||||||
shared_inbox_url: None,
|
shared_inbox_url: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
Community::update(&conn, ccommunity.id, &form)?;
|
Community::update(conn, ccommunity.id, &form)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("{} community rows updated.", incorrect_communities.len());
|
info!("{} community rows updated.", incorrect_communities.len());
|
||||||
|
@ -127,7 +127,7 @@ fn post_updates_2020_04_03(conn: &PgConnection) -> Result<(), LemmyError> {
|
||||||
|
|
||||||
for cpost in &incorrect_posts {
|
for cpost in &incorrect_posts {
|
||||||
let apub_id = generate_apub_endpoint(EndpointType::Post, &cpost.id.to_string())?;
|
let apub_id = generate_apub_endpoint(EndpointType::Post, &cpost.id.to_string())?;
|
||||||
Post::update_ap_id(&conn, cpost.id, apub_id)?;
|
Post::update_ap_id(conn, cpost.id, apub_id)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("{} post rows updated.", incorrect_posts.len());
|
info!("{} post rows updated.", incorrect_posts.len());
|
||||||
|
@ -148,7 +148,7 @@ fn comment_updates_2020_04_03(conn: &PgConnection) -> Result<(), LemmyError> {
|
||||||
|
|
||||||
for ccomment in &incorrect_comments {
|
for ccomment in &incorrect_comments {
|
||||||
let apub_id = generate_apub_endpoint(EndpointType::Comment, &ccomment.id.to_string())?;
|
let apub_id = generate_apub_endpoint(EndpointType::Comment, &ccomment.id.to_string())?;
|
||||||
Comment::update_ap_id(&conn, ccomment.id, apub_id)?;
|
Comment::update_ap_id(conn, ccomment.id, apub_id)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("{} comment rows updated.", incorrect_comments.len());
|
info!("{} comment rows updated.", incorrect_comments.len());
|
||||||
|
@ -169,7 +169,7 @@ fn private_message_updates_2020_05_05(conn: &PgConnection) -> Result<(), LemmyEr
|
||||||
|
|
||||||
for cpm in &incorrect_pms {
|
for cpm in &incorrect_pms {
|
||||||
let apub_id = generate_apub_endpoint(EndpointType::PrivateMessage, &cpm.id.to_string())?;
|
let apub_id = generate_apub_endpoint(EndpointType::PrivateMessage, &cpm.id.to_string())?;
|
||||||
PrivateMessage::update_ap_id(&conn, cpm.id, apub_id)?;
|
PrivateMessage::update_ap_id(conn, cpm.id, apub_id)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
info!("{} private message rows updated.", incorrect_pms.len());
|
info!("{} private message rows updated.", incorrect_pms.len());
|
||||||
|
|
|
@ -41,7 +41,7 @@ fn reindex_aggregates_tables(conn: &PgConnection) {
|
||||||
"comment_aggregates",
|
"comment_aggregates",
|
||||||
"community_aggregates",
|
"community_aggregates",
|
||||||
] {
|
] {
|
||||||
reindex_table(&conn, &table_name);
|
reindex_table(conn, table_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ fn reindex_table(conn: &PgConnection, table_name: &str) {
|
||||||
/// Clear old activities (this table gets very large)
|
/// Clear old activities (this table gets very large)
|
||||||
fn clear_old_activities(conn: &PgConnection) {
|
fn clear_old_activities(conn: &PgConnection) {
|
||||||
info!("Clearing old activities...");
|
info!("Clearing old activities...");
|
||||||
Activity::delete_olds(&conn).expect("clear old activities");
|
Activity::delete_olds(conn).expect("clear old activities");
|
||||||
info!("Done.");
|
info!("Done.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue