mirror of https://github.com/LemmyNet/lemmy.git
Make message a static string
parent
d8310a151f
commit
492433f322
|
@ -57,7 +57,7 @@ impl Perform for MarkCommentAsRead {
|
|||
|
||||
// Verify that only the recipient can mark as read
|
||||
if local_user_view.person.id != orig_comment.get_recipient_id() {
|
||||
return Err(LemmyError::from_message("no_comment_edit_allowed".into()));
|
||||
return Err(LemmyError::from_message("no_comment_edit_allowed"));
|
||||
}
|
||||
|
||||
// Do the mark as read
|
||||
|
@ -67,7 +67,7 @@ impl Perform for MarkCommentAsRead {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
||||
|
||||
// Refetch it
|
||||
let comment_id = data.comment_id;
|
||||
|
@ -111,13 +111,13 @@ impl Perform for SaveComment {
|
|||
blocking(context.pool(), save_comment)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_save_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_save_comment"))?;
|
||||
} else {
|
||||
let unsave_comment = move |conn: &'_ _| CommentSaved::unsave(conn, &comment_saved_form);
|
||||
blocking(context.pool(), unsave_comment)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_save_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_save_comment"))?;
|
||||
}
|
||||
|
||||
let comment_id = data.comment_id;
|
||||
|
@ -208,7 +208,7 @@ impl Perform for CreateCommentLike {
|
|||
blocking(context.pool(), like)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_like_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_like_comment"))?;
|
||||
|
||||
Vote::send(
|
||||
&object,
|
||||
|
|
|
@ -35,10 +35,10 @@ impl Perform for CreateCommentReport {
|
|||
// check size of report and check for whitespace
|
||||
let reason = data.reason.trim();
|
||||
if reason.is_empty() {
|
||||
return Err(LemmyError::from_message("report_reason_required".into()));
|
||||
return Err(LemmyError::from_message("report_reason_required"));
|
||||
}
|
||||
if reason.chars().count() > 1000 {
|
||||
return Err(LemmyError::from_message("report_too_long".into()));
|
||||
return Err(LemmyError::from_message("report_too_long"));
|
||||
}
|
||||
|
||||
let person_id = local_user_view.person.id;
|
||||
|
@ -62,7 +62,7 @@ impl Perform for CreateCommentReport {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_create_report".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_create_report"))?;
|
||||
|
||||
let comment_report_view = blocking(context.pool(), move |conn| {
|
||||
CommentReportView::read(conn, report.id, person_id)
|
||||
|
@ -130,7 +130,7 @@ impl Perform for ResolveCommentReport {
|
|||
blocking(context.pool(), resolve_fun)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_resolve_report".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_resolve_report"))?;
|
||||
|
||||
let report_id = data.report_id;
|
||||
let comment_report_view = blocking(context.pool(), move |conn| {
|
||||
|
|
|
@ -92,14 +92,14 @@ impl Perform for FollowCommunity {
|
|||
blocking(context.pool(), follow)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("community_follower_already_exists".into()))?;
|
||||
.map_err(|e| e.with_message("community_follower_already_exists"))?;
|
||||
} else {
|
||||
let unfollow =
|
||||
move |conn: &'_ _| CommunityFollower::unfollow(conn, &community_follower_form);
|
||||
blocking(context.pool(), unfollow)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("community_follower_already_exists".into()))?;
|
||||
.map_err(|e| e.with_message("community_follower_already_exists"))?;
|
||||
}
|
||||
} else if data.follow {
|
||||
// Dont actually add to the community followers here, because you need
|
||||
|
@ -113,7 +113,7 @@ impl Perform for FollowCommunity {
|
|||
blocking(context.pool(), unfollow)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("community_follower_already_exists".into()))?;
|
||||
.map_err(|e| e.with_message("community_follower_already_exists"))?;
|
||||
}
|
||||
|
||||
let community_id = data.community_id;
|
||||
|
@ -160,7 +160,7 @@ impl Perform for BlockCommunity {
|
|||
blocking(context.pool(), block)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("community_block_already_exists".into()))?;
|
||||
.map_err(|e| e.with_message("community_block_already_exists"))?;
|
||||
|
||||
// Also, unfollow the community, and send a federated unfollow
|
||||
let community_follower_form = CommunityFollowerForm {
|
||||
|
@ -183,7 +183,7 @@ impl Perform for BlockCommunity {
|
|||
blocking(context.pool(), unblock)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("community_block_already_exists".into()))?;
|
||||
.map_err(|e| e.with_message("community_block_already_exists"))?;
|
||||
}
|
||||
|
||||
let community_view = blocking(context.pool(), move |conn| {
|
||||
|
@ -239,7 +239,7 @@ impl Perform for BanFromCommunity {
|
|||
blocking(context.pool(), ban)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("community_user_already_banned".into()))?;
|
||||
.map_err(|e| e.with_message("community_user_already_banned"))?;
|
||||
|
||||
// Also unsubscribe them from the community, if they are subscribed
|
||||
let community_follower_form = CommunityFollowerForm {
|
||||
|
@ -265,7 +265,7 @@ impl Perform for BanFromCommunity {
|
|||
blocking(context.pool(), unban)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("community_user_already_banned".into()))?;
|
||||
.map_err(|e| e.with_message("community_user_already_banned"))?;
|
||||
UndoBlockUserFromCommunity::send(
|
||||
&community,
|
||||
&banned_person,
|
||||
|
@ -371,13 +371,13 @@ impl Perform for AddModToCommunity {
|
|||
blocking(context.pool(), join)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("community_moderator_already_exists".into()))?;
|
||||
.map_err(|e| e.with_message("community_moderator_already_exists"))?;
|
||||
} else {
|
||||
let leave = move |conn: &'_ _| CommunityModerator::leave(conn, &community_moderator_form);
|
||||
blocking(context.pool(), leave)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("community_moderator_already_exists".into()))?;
|
||||
.map_err(|e| e.with_message("community_moderator_already_exists"))?;
|
||||
}
|
||||
|
||||
// Mod tables
|
||||
|
@ -486,7 +486,7 @@ impl Perform for TransferCommunity {
|
|||
.map(|a| a.person.id)
|
||||
.any(|x| x == local_user_view.person.id)
|
||||
{
|
||||
return Err(LemmyError::from_message("not_an_admin".into()));
|
||||
return Err(LemmyError::from_message("not_an_admin"));
|
||||
}
|
||||
|
||||
// You have to re-do the community_moderator table, reordering it.
|
||||
|
@ -517,7 +517,7 @@ impl Perform for TransferCommunity {
|
|||
blocking(context.pool(), join)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("community_moderator_already_exists".into()))?;
|
||||
.map_err(|e| e.with_message("community_moderator_already_exists"))?;
|
||||
}
|
||||
|
||||
// Mod tables
|
||||
|
@ -539,7 +539,7 @@ impl Perform for TransferCommunity {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_find_community".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_find_community"))?;
|
||||
|
||||
let community_id = data.community_id;
|
||||
let moderators = blocking(context.pool(), move |conn| {
|
||||
|
@ -547,7 +547,7 @@ impl Perform for TransferCommunity {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_find_community".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_find_community"))?;
|
||||
|
||||
// Return the jwt
|
||||
Ok(GetCommunityResponse {
|
||||
|
|
|
@ -77,7 +77,7 @@ impl Perform for Login {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_find_that_username_or_email".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_find_that_username_or_email"))?;
|
||||
|
||||
// Verify the password
|
||||
let valid: bool = verify(
|
||||
|
@ -86,7 +86,7 @@ impl Perform for Login {
|
|||
)
|
||||
.unwrap_or(false);
|
||||
if !valid {
|
||||
return Err(LemmyError::from_message("password_incorrect".into()));
|
||||
return Err(LemmyError::from_message("password_incorrect"));
|
||||
}
|
||||
|
||||
// Return the jwt
|
||||
|
@ -170,7 +170,7 @@ impl Perform for SaveUserSettings {
|
|||
|
||||
if let Some(Some(bio)) = &bio {
|
||||
if bio.chars().count() > 300 {
|
||||
return Err(LemmyError::from_message("bio_length_overflow".into()));
|
||||
return Err(LemmyError::from_message("bio_length_overflow"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,13 +179,13 @@ impl Perform for SaveUserSettings {
|
|||
display_name.trim(),
|
||||
context.settings().actor_name_max_length,
|
||||
) {
|
||||
return Err(LemmyError::from_message("invalid_username".into()));
|
||||
return Err(LemmyError::from_message("invalid_username"));
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(Some(matrix_user_id)) = &matrix_user_id {
|
||||
if !is_valid_matrix_id(matrix_user_id) {
|
||||
return Err(LemmyError::from_message("invalid_matrix_id".into()));
|
||||
return Err(LemmyError::from_message("invalid_matrix_id"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -223,7 +223,7 @@ impl Perform for SaveUserSettings {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("user_already_exists".into()))?;
|
||||
.map_err(|e| e.with_message("user_already_exists"))?;
|
||||
|
||||
let local_user_form = LocalUserForm {
|
||||
person_id,
|
||||
|
@ -257,7 +257,7 @@ impl Perform for SaveUserSettings {
|
|||
"user_already_exists"
|
||||
};
|
||||
|
||||
return Err(LemmyError::from(e).with_message(err_type.into()));
|
||||
return Err(LemmyError::from(e).with_message(err_type));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -290,7 +290,7 @@ impl Perform for ChangePassword {
|
|||
|
||||
// Make sure passwords match
|
||||
if data.new_password != data.new_password_verify {
|
||||
return Err(LemmyError::from_message("passwords_dont_match".into()));
|
||||
return Err(LemmyError::from_message("passwords_dont_match"));
|
||||
}
|
||||
|
||||
// Check the old password
|
||||
|
@ -300,7 +300,7 @@ impl Perform for ChangePassword {
|
|||
)
|
||||
.unwrap_or(false);
|
||||
if !valid {
|
||||
return Err(LemmyError::from_message("password_incorrect".into()));
|
||||
return Err(LemmyError::from_message("password_incorrect"));
|
||||
}
|
||||
|
||||
let local_user_id = local_user_view.local_user.id;
|
||||
|
@ -345,7 +345,7 @@ impl Perform for AddAdmin {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_user".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_user"))?;
|
||||
|
||||
// Mod tables
|
||||
let form = ModAddForm {
|
||||
|
@ -404,7 +404,7 @@ impl Perform for BanPerson {
|
|||
blocking(context.pool(), ban_person)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_user".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_user"))?;
|
||||
|
||||
// Remove their data if that's desired
|
||||
if data.remove_data.unwrap_or(false) {
|
||||
|
@ -495,7 +495,7 @@ impl Perform for BlockPerson {
|
|||
|
||||
// Don't let a person block themselves
|
||||
if target_id == person_id {
|
||||
return Err(LemmyError::from_message("cant_block_yourself".into()));
|
||||
return Err(LemmyError::from_message("cant_block_yourself"));
|
||||
}
|
||||
|
||||
let person_block_form = PersonBlockForm {
|
||||
|
@ -508,13 +508,13 @@ impl Perform for BlockPerson {
|
|||
blocking(context.pool(), block)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("person_block_already_exists".into()))?;
|
||||
.map_err(|e| e.with_message("person_block_already_exists"))?;
|
||||
} else {
|
||||
let unblock = move |conn: &'_ _| PersonBlock::unblock(conn, &person_block_form);
|
||||
blocking(context.pool(), unblock)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("person_block_already_exists".into()))?;
|
||||
.map_err(|e| e.with_message("person_block_already_exists"))?;
|
||||
}
|
||||
|
||||
// TODO does any federated stuff need to be done here?
|
||||
|
@ -629,7 +629,7 @@ impl Perform for MarkPersonMentionAsRead {
|
|||
.await??;
|
||||
|
||||
if local_user_view.person.id != read_person_mention.recipient_id {
|
||||
return Err(LemmyError::from_message("couldnt_update_comment".into()));
|
||||
return Err(LemmyError::from_message("couldnt_update_comment"));
|
||||
}
|
||||
|
||||
let person_mention_id = read_person_mention.id;
|
||||
|
@ -639,7 +639,7 @@ impl Perform for MarkPersonMentionAsRead {
|
|||
blocking(context.pool(), update_mention)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
||||
|
||||
let person_mention_id = read_person_mention.id;
|
||||
let person_id = local_user_view.person.id;
|
||||
|
@ -689,7 +689,7 @@ impl Perform for MarkAllAsRead {
|
|||
blocking(context.pool(), mark_as_read)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
||||
}
|
||||
|
||||
// Mark all user mentions as read
|
||||
|
@ -698,14 +698,14 @@ impl Perform for MarkAllAsRead {
|
|||
blocking(context.pool(), update_person_mentions)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
||||
|
||||
// Mark all private_messages as read
|
||||
let update_pm = move |conn: &'_ _| PrivateMessage::mark_all_as_read(conn, person_id);
|
||||
blocking(context.pool(), update_pm)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_private_message".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_private_message"))?;
|
||||
|
||||
Ok(GetRepliesResponse { replies: vec![] })
|
||||
}
|
||||
|
@ -730,7 +730,7 @@ impl Perform for PasswordReset {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_find_that_username_or_email".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_find_that_username_or_email"))?;
|
||||
|
||||
// Generate a random token
|
||||
let token = generate_random_string();
|
||||
|
@ -756,8 +756,9 @@ impl Perform for PasswordReset {
|
|||
html,
|
||||
&context.settings(),
|
||||
)
|
||||
.map_err(LemmyError::from_message)
|
||||
.map_err(|e| e.with_message("email_send_failed".into()))?;
|
||||
.map_err(|e| anyhow::anyhow!("{}", e))
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("email_send_failed"))?;
|
||||
|
||||
Ok(PasswordResetResponse {})
|
||||
}
|
||||
|
@ -786,7 +787,7 @@ impl Perform for PasswordChange {
|
|||
|
||||
// Make sure passwords match
|
||||
if data.password != data.password_verify {
|
||||
return Err(LemmyError::from_message("passwords_dont_match".into()));
|
||||
return Err(LemmyError::from_message("passwords_dont_match"));
|
||||
}
|
||||
|
||||
// Update the user with the new password
|
||||
|
@ -796,7 +797,7 @@ impl Perform for PasswordChange {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_user".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_user"))?;
|
||||
|
||||
// Return the jwt
|
||||
Ok(LoginResponse {
|
||||
|
|
|
@ -85,7 +85,7 @@ impl Perform for CreatePostLike {
|
|||
blocking(context.pool(), like)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_like_post".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_like_post"))?;
|
||||
|
||||
Vote::send(
|
||||
&object,
|
||||
|
@ -325,13 +325,13 @@ impl Perform for SavePost {
|
|||
blocking(context.pool(), save)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_save_post".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_save_post"))?;
|
||||
} else {
|
||||
let unsave = move |conn: &'_ _| PostSaved::unsave(conn, &post_saved_form);
|
||||
blocking(context.pool(), unsave)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_save_post".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_save_post"))?;
|
||||
}
|
||||
|
||||
let post_id = data.post_id;
|
||||
|
|
|
@ -44,10 +44,10 @@ impl Perform for CreatePostReport {
|
|||
// check size of report and check for whitespace
|
||||
let reason = data.reason.trim();
|
||||
if reason.is_empty() {
|
||||
return Err(LemmyError::from_message("report_reason_required".into()));
|
||||
return Err(LemmyError::from_message("report_reason_required"));
|
||||
}
|
||||
if reason.chars().count() > 1000 {
|
||||
return Err(LemmyError::from_message("report_too_long".into()));
|
||||
return Err(LemmyError::from_message("report_too_long"));
|
||||
}
|
||||
|
||||
let person_id = local_user_view.person.id;
|
||||
|
@ -73,7 +73,7 @@ impl Perform for CreatePostReport {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_create_report".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_create_report"))?;
|
||||
|
||||
let post_report_view = blocking(context.pool(), move |conn| {
|
||||
PostReportView::read(conn, report.id, person_id)
|
||||
|
@ -139,7 +139,7 @@ impl Perform for ResolvePostReport {
|
|||
blocking(context.pool(), resolve_fun)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_resolve_report".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_resolve_report"))?;
|
||||
|
||||
let post_report_view = blocking(context.pool(), move |conn| {
|
||||
PostReportView::read(conn, report_id, person_id)
|
||||
|
|
|
@ -30,9 +30,7 @@ impl Perform for MarkPrivateMessageAsRead {
|
|||
})
|
||||
.await??;
|
||||
if local_user_view.person.id != orig_private_message.recipient_id {
|
||||
return Err(LemmyError::from_message(
|
||||
"couldnt_update_private_message".into(),
|
||||
));
|
||||
return Err(LemmyError::from_message("couldnt_update_private_message"));
|
||||
}
|
||||
|
||||
// Doing the update
|
||||
|
@ -43,7 +41,7 @@ impl Perform for MarkPrivateMessageAsRead {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_private_message".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_private_message"))?;
|
||||
|
||||
// No need to send an apub update
|
||||
let op = UserOperation::MarkPrivateMessageAsRead;
|
||||
|
|
|
@ -389,11 +389,11 @@ impl Perform for ResolveObject {
|
|||
let res = search_by_apub_id(&self.q, context)
|
||||
.await
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_find_object".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_find_object"))?;
|
||||
convert_response(res, local_user_view.map(|l| l.person.id), context.pool())
|
||||
.await
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_find_object".into()))
|
||||
.map_err(|e| e.with_message("couldnt_find_object"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -456,7 +456,7 @@ impl Perform for TransferSite {
|
|||
|
||||
// Make sure user is the creator
|
||||
if read_site.creator_id != local_user_view.person.id {
|
||||
return Err(LemmyError::from_message("not_an_admin".into()));
|
||||
return Err(LemmyError::from_message("not_an_admin"));
|
||||
}
|
||||
|
||||
let new_creator_id = data.person_id;
|
||||
|
@ -464,7 +464,7 @@ impl Perform for TransferSite {
|
|||
blocking(context.pool(), transfer_site)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_site".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_site"))?;
|
||||
|
||||
// Mod tables
|
||||
let form = ModAddForm {
|
||||
|
@ -548,7 +548,7 @@ impl Perform for SaveSiteConfig {
|
|||
// Make sure docker doesn't have :ro at the end of the volume, so its not a read-only filesystem
|
||||
let config_hjson = Settings::save_config_file(&data.config_hjson)
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_site".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_site"))?;
|
||||
|
||||
Ok(GetSiteConfigResponse { config_hjson })
|
||||
}
|
||||
|
|
|
@ -55,14 +55,14 @@ pub async fn is_mod_or_admin(
|
|||
})
|
||||
.await?;
|
||||
if !is_mod_or_admin {
|
||||
return Err(LemmyError::from_message("not_a_mod_or_admin".into()));
|
||||
return Err(LemmyError::from_message("not_a_mod_or_admin"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> {
|
||||
if !local_user_view.person.admin {
|
||||
return Err(LemmyError::from_message("not_an_admin".into()));
|
||||
return Err(LemmyError::from_message("not_an_admin"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError
|
|||
blocking(pool, move |conn| Post::read(conn, post_id))
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_find_post".into()))
|
||||
.map_err(|e| e.with_message("couldnt_find_post"))
|
||||
}
|
||||
|
||||
pub async fn mark_post_as_read(
|
||||
|
@ -86,7 +86,7 @@ pub async fn mark_post_as_read(
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_mark_post_as_read".into()))
|
||||
.map_err(|e| e.with_message("couldnt_mark_post_as_read"))
|
||||
}
|
||||
|
||||
pub async fn mark_post_as_unread(
|
||||
|
@ -101,7 +101,7 @@ pub async fn mark_post_as_unread(
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_mark_post_as_read".into()))
|
||||
.map_err(|e| e.with_message("couldnt_mark_post_as_read"))
|
||||
}
|
||||
|
||||
pub async fn get_local_user_view_from_jwt(
|
||||
|
@ -111,19 +111,19 @@ pub async fn get_local_user_view_from_jwt(
|
|||
) -> Result<LocalUserView, LemmyError> {
|
||||
let claims = Claims::decode(jwt, &secret.jwt_secret)
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("not_logged_in".into()))?
|
||||
.map_err(|e| e.with_message("not_logged_in"))?
|
||||
.claims;
|
||||
let local_user_id = LocalUserId(claims.sub);
|
||||
let local_user_view =
|
||||
blocking(pool, move |conn| LocalUserView::read(conn, local_user_id)).await??;
|
||||
// Check for a site ban
|
||||
if local_user_view.person.banned {
|
||||
return Err(LemmyError::from_message("site_ban".into()));
|
||||
return Err(LemmyError::from_message("site_ban"));
|
||||
}
|
||||
|
||||
// Check for user deletion
|
||||
if local_user_view.person.deleted {
|
||||
return Err(LemmyError::from_message("deleted".into()));
|
||||
return Err(LemmyError::from_message("deleted"));
|
||||
}
|
||||
|
||||
check_validator_time(&local_user_view.local_user.validator_time, &claims)?;
|
||||
|
@ -138,7 +138,7 @@ pub fn check_validator_time(
|
|||
) -> Result<(), LemmyError> {
|
||||
let user_validation_time = validator_time.timestamp();
|
||||
if user_validation_time > claims.iat {
|
||||
Err(LemmyError::from_message("not_logged_in".into()))
|
||||
Err(LemmyError::from_message("not_logged_in"))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ pub async fn get_local_user_settings_view_from_jwt(
|
|||
) -> Result<LocalUserSettingsView, LemmyError> {
|
||||
let claims = Claims::decode(jwt, &secret.jwt_secret)
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("not_logged_in".into()))?
|
||||
.map_err(|e| e.with_message("not_logged_in"))?
|
||||
.claims;
|
||||
let local_user_id = LocalUserId(claims.sub);
|
||||
let local_user_view = blocking(pool, move |conn| {
|
||||
|
@ -171,7 +171,7 @@ pub async fn get_local_user_settings_view_from_jwt(
|
|||
.await??;
|
||||
// Check for a site ban
|
||||
if local_user_view.person.banned {
|
||||
return Err(LemmyError::from_message("site_ban".into()));
|
||||
return Err(LemmyError::from_message("site_ban"));
|
||||
}
|
||||
|
||||
check_validator_time(&local_user_view.local_user.validator_time, &claims)?;
|
||||
|
@ -200,7 +200,7 @@ pub async fn check_community_ban(
|
|||
let is_banned =
|
||||
move |conn: &'_ _| CommunityPersonBanView::get(conn, person_id, community_id).is_ok();
|
||||
if blocking(pool, is_banned).await? {
|
||||
Err(LemmyError::from_message("community_ban".into()))
|
||||
Err(LemmyError::from_message("community_ban"))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -213,9 +213,9 @@ pub async fn check_community_deleted_or_removed(
|
|||
let community = blocking(pool, move |conn| Community::read(conn, community_id))
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_find_community".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_find_community"))?;
|
||||
if community.deleted || community.removed {
|
||||
Err(LemmyError::from_message("deleted".into()))
|
||||
Err(LemmyError::from_message("deleted"))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ pub async fn check_community_deleted_or_removed(
|
|||
|
||||
pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> {
|
||||
if post.deleted || post.removed {
|
||||
Err(LemmyError::from_message("deleted".into()))
|
||||
Err(LemmyError::from_message("deleted"))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ pub async fn check_person_block(
|
|||
) -> Result<(), LemmyError> {
|
||||
let is_blocked = move |conn: &'_ _| PersonBlock::read(conn, potential_blocker_id, my_id).is_ok();
|
||||
if blocking(pool, is_blocked).await? {
|
||||
Err(LemmyError::from_message("person_block".into()))
|
||||
Err(LemmyError::from_message("person_block"))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ pub async fn check_downvotes_enabled(score: i16, pool: &DbPool) -> Result<(), Le
|
|||
if score == -1 {
|
||||
let site = blocking(pool, Site::read_simple).await??;
|
||||
if !site.enable_downvotes {
|
||||
return Err(LemmyError::from_message("downvotes_disabled".into()));
|
||||
return Err(LemmyError::from_message("downvotes_disabled"));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -297,7 +297,7 @@ pub async fn build_federated_instances(
|
|||
/// Checks the password length
|
||||
pub fn password_length_check(pass: &str) -> Result<(), LemmyError> {
|
||||
if !(10..=60).contains(&pass.len()) {
|
||||
Err(LemmyError::from_message("invalid_password".into()))
|
||||
Err(LemmyError::from_message("invalid_password"))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -306,9 +306,7 @@ pub fn password_length_check(pass: &str) -> Result<(), LemmyError> {
|
|||
/// Checks the site description length
|
||||
pub fn site_description_length_check(description: &str) -> Result<(), LemmyError> {
|
||||
if description.len() > 150 {
|
||||
Err(LemmyError::from_message(
|
||||
"site_description_length_overflow".into(),
|
||||
))
|
||||
Err(LemmyError::from_message("site_description_length_overflow"))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -317,7 +315,7 @@ pub fn site_description_length_check(description: &str) -> Result<(), LemmyError
|
|||
/// Checks for a honeypot. If this field is filled, fail the rest of the function
|
||||
pub fn honeypot_check(honeypot: &Option<String>) -> Result<(), LemmyError> {
|
||||
if honeypot.is_some() {
|
||||
Err(LemmyError::from_message("honeypot_fail".into()))
|
||||
Err(LemmyError::from_message("honeypot_fail"))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ impl PerformCrud for CreateComment {
|
|||
|
||||
// Check if post is locked, no new comments
|
||||
if post.locked {
|
||||
return Err(LemmyError::from_message("locked".into()));
|
||||
return Err(LemmyError::from_message("locked"));
|
||||
}
|
||||
|
||||
// If there's a parent_id, check to make sure that comment is in that post
|
||||
|
@ -79,13 +79,13 @@ impl PerformCrud for CreateComment {
|
|||
let parent = blocking(context.pool(), move |conn| Comment::read(conn, parent_id))
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_create_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_create_comment"))?;
|
||||
|
||||
check_person_block(local_user_view.person.id, parent.creator_id, context.pool()).await?;
|
||||
|
||||
// Strange issue where sometimes the post ID is incorrect
|
||||
if parent.post_id != post_id {
|
||||
return Err(LemmyError::from_message("couldnt_create_comment".into()));
|
||||
return Err(LemmyError::from_message("couldnt_create_comment"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ impl PerformCrud for CreateComment {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_create_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_create_comment"))?;
|
||||
|
||||
// Necessary to update the ap_id
|
||||
let inserted_comment_id = inserted_comment.id;
|
||||
|
@ -121,7 +121,7 @@ impl PerformCrud for CreateComment {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_create_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_create_comment"))?;
|
||||
|
||||
// Scan the comment for user mentions, add those rows
|
||||
let post_id = post.id;
|
||||
|
@ -148,7 +148,7 @@ impl PerformCrud for CreateComment {
|
|||
blocking(context.pool(), like)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_like_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_like_comment"))?;
|
||||
|
||||
let apub_comment: ApubComment = updated_comment.into();
|
||||
CreateOrUpdateComment::send(
|
||||
|
@ -184,7 +184,7 @@ impl PerformCrud for CreateComment {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
||||
}
|
||||
// If its a reply, mark the parent as read
|
||||
if let Some(parent_id) = data.parent_id {
|
||||
|
@ -198,7 +198,7 @@ impl PerformCrud for CreateComment {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_parent_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_parent_comment"))?;
|
||||
}
|
||||
// If the parent has PersonMentions mark them as read too
|
||||
let person_id = local_user_view.person.id;
|
||||
|
@ -212,7 +212,7 @@ impl PerformCrud for CreateComment {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_person_mentions".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_person_mentions"))?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ impl PerformCrud for DeleteComment {
|
|||
|
||||
// Dont delete it if its already been deleted.
|
||||
if orig_comment.comment.deleted == data.deleted {
|
||||
return Err(LemmyError::from_message("couldnt_update_comment".into()));
|
||||
return Err(LemmyError::from_message("couldnt_update_comment"));
|
||||
}
|
||||
|
||||
check_community_ban(
|
||||
|
@ -59,7 +59,7 @@ impl PerformCrud for DeleteComment {
|
|||
|
||||
// Verify that only the creator can delete
|
||||
if local_user_view.person.id != orig_comment.creator.id {
|
||||
return Err(LemmyError::from_message("no_comment_edit_allowed".into()));
|
||||
return Err(LemmyError::from_message("no_comment_edit_allowed"));
|
||||
}
|
||||
|
||||
// Do the delete
|
||||
|
@ -69,7 +69,7 @@ impl PerformCrud for DeleteComment {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
||||
|
||||
let post_id = updated_comment.post_id;
|
||||
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
||||
|
@ -152,7 +152,7 @@ impl PerformCrud for RemoveComment {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
||||
|
||||
// Mod tables
|
||||
let form = ModRemoveCommentForm {
|
||||
|
|
|
@ -37,7 +37,7 @@ impl PerformCrud for GetComment {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_find_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_find_comment"))?;
|
||||
|
||||
Ok(Self::Response {
|
||||
comment_view,
|
||||
|
@ -95,7 +95,7 @@ impl PerformCrud for GetComments {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_get_comments".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_get_comments"))?;
|
||||
|
||||
// Blank out deleted or removed info
|
||||
for cv in comments
|
||||
|
|
|
@ -59,7 +59,7 @@ impl PerformCrud for EditComment {
|
|||
|
||||
// Verify that only the creator can edit
|
||||
if local_user_view.person.id != orig_comment.creator.id {
|
||||
return Err(LemmyError::from_message("no_comment_edit_allowed".into()));
|
||||
return Err(LemmyError::from_message("no_comment_edit_allowed"));
|
||||
}
|
||||
|
||||
// Do the update
|
||||
|
@ -71,7 +71,7 @@ impl PerformCrud for EditComment {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
||||
|
||||
// Do the mentions / recipients
|
||||
let updated_comment_content = updated_comment.content.to_owned();
|
||||
|
|
|
@ -56,7 +56,7 @@ impl PerformCrud for CreateCommunity {
|
|||
let site = blocking(context.pool(), move |conn| Site::read(conn, 0)).await??;
|
||||
if site.community_creation_admin_only && is_admin(&local_user_view).is_err() {
|
||||
return Err(LemmyError::from_message(
|
||||
"only_admins_can_create_communities".into(),
|
||||
"only_admins_can_create_communities",
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ impl PerformCrud for CreateCommunity {
|
|||
check_slurs_opt(&data.description, &context.settings().slur_regex())?;
|
||||
|
||||
if !is_valid_actor_name(&data.name, context.settings().actor_name_max_length) {
|
||||
return Err(LemmyError::from_message("invalid_community_name".into()));
|
||||
return Err(LemmyError::from_message("invalid_community_name"));
|
||||
}
|
||||
|
||||
// Double check for duplicate community actor_ids
|
||||
|
@ -77,7 +77,7 @@ impl PerformCrud for CreateCommunity {
|
|||
let community_actor_id_wrapped = ObjectId::<ApubCommunity>::new(community_actor_id.clone());
|
||||
let community_dupe = community_actor_id_wrapped.dereference_local(context).await;
|
||||
if community_dupe.is_ok() {
|
||||
return Err(LemmyError::from_message("community_already_exists".into()));
|
||||
return Err(LemmyError::from_message("community_already_exists"));
|
||||
}
|
||||
|
||||
// Check to make sure the icon and banners are urls
|
||||
|
@ -108,7 +108,7 @@ impl PerformCrud for CreateCommunity {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("community_already_exists".into()))?;
|
||||
.map_err(|e| e.with_message("community_already_exists"))?;
|
||||
|
||||
// The community creator becomes a moderator
|
||||
let community_moderator_form = CommunityModeratorForm {
|
||||
|
@ -119,7 +119,7 @@ impl PerformCrud for CreateCommunity {
|
|||
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
|
||||
if blocking(context.pool(), join).await?.is_err() {
|
||||
return Err(LemmyError::from_message(
|
||||
"community_moderator_already_exists".into(),
|
||||
"community_moderator_already_exists",
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ impl PerformCrud for CreateCommunity {
|
|||
let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form);
|
||||
if blocking(context.pool(), follow).await?.is_err() {
|
||||
return Err(LemmyError::from_message(
|
||||
"community_follower_already_exists".into(),
|
||||
"community_follower_already_exists",
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ impl PerformCrud for DeleteCommunity {
|
|||
|
||||
// Make sure deleter is the top mod
|
||||
if local_user_view.person.id != community_mods[0].moderator.id {
|
||||
return Err(LemmyError::from_message("no_community_edit_allowed".into()));
|
||||
return Err(LemmyError::from_message("no_community_edit_allowed"));
|
||||
}
|
||||
|
||||
// Do the delete
|
||||
|
@ -47,7 +47,7 @@ impl PerformCrud for DeleteCommunity {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_community".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_community"))?;
|
||||
|
||||
// Send apub messages
|
||||
send_apub_delete(
|
||||
|
@ -95,7 +95,7 @@ impl PerformCrud for RemoveCommunity {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_community".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_community"))?;
|
||||
|
||||
// Mod tables
|
||||
let expires = data.expires.map(naive_from_unix);
|
||||
|
|
|
@ -47,7 +47,7 @@ impl PerformCrud for GetCommunity {
|
|||
.dereference(context, &mut 0)
|
||||
.await
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_find_community".into()))?
|
||||
.map_err(|e| e.with_message("couldnt_find_community"))?
|
||||
.id
|
||||
}
|
||||
};
|
||||
|
@ -57,7 +57,7 @@ impl PerformCrud for GetCommunity {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_find_community".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_find_community"))?;
|
||||
|
||||
// Blank out deleted or removed info for non-logged in users
|
||||
if person_id.is_none() && (community_view.community.deleted || community_view.community.removed)
|
||||
|
@ -70,7 +70,7 @@ impl PerformCrud for GetCommunity {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_find_community".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_find_community"))?;
|
||||
|
||||
let online = context
|
||||
.chat_server()
|
||||
|
|
|
@ -42,7 +42,7 @@ impl PerformCrud for EditCommunity {
|
|||
})
|
||||
.await??;
|
||||
if !mods.contains(&local_user_view.person.id) {
|
||||
return Err(LemmyError::from_message("not_a_moderator".into()));
|
||||
return Err(LemmyError::from_message("not_a_moderator"));
|
||||
}
|
||||
|
||||
let community_id = data.community_id;
|
||||
|
@ -72,7 +72,7 @@ impl PerformCrud for EditCommunity {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_community".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_community"))?;
|
||||
|
||||
UpdateCommunity::send(
|
||||
updated_community.into(),
|
||||
|
|
|
@ -55,7 +55,7 @@ impl PerformCrud for CreatePost {
|
|||
honeypot_check(&data.honeypot)?;
|
||||
|
||||
if !is_valid_post_title(&data.name) {
|
||||
return Err(LemmyError::from_message("invalid_post_title".into()));
|
||||
return Err(LemmyError::from_message("invalid_post_title"));
|
||||
}
|
||||
|
||||
check_community_ban(local_user_view.person.id, data.community_id, context.pool()).await?;
|
||||
|
@ -93,7 +93,7 @@ impl PerformCrud for CreatePost {
|
|||
"couldnt_create_post"
|
||||
};
|
||||
|
||||
return Err(LemmyError::from(e).with_message(err_type.into()));
|
||||
return Err(LemmyError::from(e).with_message(err_type));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -109,7 +109,7 @@ impl PerformCrud for CreatePost {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_create_post".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_create_post"))?;
|
||||
|
||||
// They like their own post by default
|
||||
let person_id = local_user_view.person.id;
|
||||
|
@ -122,7 +122,7 @@ impl PerformCrud for CreatePost {
|
|||
|
||||
let like = move |conn: &'_ _| PostLike::like(conn, &like_form);
|
||||
if blocking(context.pool(), like).await?.is_err() {
|
||||
return Err(LemmyError::from_message("couldnt_like_post".into()));
|
||||
return Err(LemmyError::from_message("couldnt_like_post"));
|
||||
}
|
||||
|
||||
// Mark the post as read
|
||||
|
|
|
@ -39,7 +39,7 @@ impl PerformCrud for DeletePost {
|
|||
|
||||
// Dont delete it if its already been deleted.
|
||||
if orig_post.deleted == data.deleted {
|
||||
return Err(LemmyError::from_message("couldnt_update_post".into()));
|
||||
return Err(LemmyError::from_message("couldnt_update_post"));
|
||||
}
|
||||
|
||||
check_community_ban(
|
||||
|
@ -52,7 +52,7 @@ impl PerformCrud for DeletePost {
|
|||
|
||||
// Verify that only the creator can delete
|
||||
if !Post::is_post_creator(local_user_view.person.id, orig_post.creator_id) {
|
||||
return Err(LemmyError::from_message("no_post_edit_allowed".into()));
|
||||
return Err(LemmyError::from_message("no_post_edit_allowed"));
|
||||
}
|
||||
|
||||
// Update the post
|
||||
|
|
|
@ -48,7 +48,7 @@ impl PerformCrud for GetPost {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_find_post".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_find_post"))?;
|
||||
|
||||
// Mark the post as read
|
||||
if let Some(person_id) = person_id {
|
||||
|
@ -73,7 +73,7 @@ impl PerformCrud for GetPost {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_find_community".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_find_community"))?;
|
||||
|
||||
// Blank out deleted or removed info for non-logged in users
|
||||
if person_id.is_none() {
|
||||
|
@ -170,7 +170,7 @@ impl PerformCrud for GetPosts {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_get_posts".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_get_posts"))?;
|
||||
|
||||
// Blank out deleted or removed info for non-logged in users
|
||||
if person_id.is_none() {
|
||||
|
|
|
@ -46,7 +46,7 @@ impl PerformCrud for EditPost {
|
|||
|
||||
if let Some(name) = &data.name {
|
||||
if !is_valid_post_title(name) {
|
||||
return Err(LemmyError::from_message("invalid_post_title".into()));
|
||||
return Err(LemmyError::from_message("invalid_post_title"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ impl PerformCrud for EditPost {
|
|||
|
||||
// Verify that only the creator can edit
|
||||
if !Post::is_post_creator(local_user_view.person.id, orig_post.creator_id) {
|
||||
return Err(LemmyError::from_message("no_post_edit_allowed".into()));
|
||||
return Err(LemmyError::from_message("no_post_edit_allowed"));
|
||||
}
|
||||
|
||||
// Fetch post links and Pictrs cached image
|
||||
|
@ -103,7 +103,7 @@ impl PerformCrud for EditPost {
|
|||
"couldnt_update_post"
|
||||
};
|
||||
|
||||
return Err(LemmyError::from(e).with_message(err_type.into()));
|
||||
return Err(LemmyError::from(e).with_message(err_type));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ impl PerformCrud for CreatePrivateMessage {
|
|||
{
|
||||
Ok(private_message) => private_message,
|
||||
Err(e) => {
|
||||
return Err(LemmyError::from(e).with_message("couldnt_create_private_message".into()));
|
||||
return Err(LemmyError::from(e).with_message("couldnt_create_private_message"));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -82,7 +82,7 @@ impl PerformCrud for CreatePrivateMessage {
|
|||
)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_create_private_message".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_create_private_message"))?;
|
||||
|
||||
CreateOrUpdatePrivateMessage::send(
|
||||
updated_private_message.into(),
|
||||
|
|
|
@ -37,9 +37,7 @@ impl PerformCrud for DeletePrivateMessage {
|
|||
})
|
||||
.await??;
|
||||
if local_user_view.person.id != orig_private_message.creator_id {
|
||||
return Err(LemmyError::from_message(
|
||||
"no_private_message_edit_allowed".into(),
|
||||
));
|
||||
return Err(LemmyError::from_message("no_private_message_edit_allowed"));
|
||||
}
|
||||
|
||||
// Doing the update
|
||||
|
@ -50,7 +48,7 @@ impl PerformCrud for DeletePrivateMessage {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_private_message".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_private_message"))?;
|
||||
|
||||
// Send the apub update
|
||||
if data.deleted {
|
||||
|
|
|
@ -34,9 +34,7 @@ impl PerformCrud for EditPrivateMessage {
|
|||
})
|
||||
.await??;
|
||||
if local_user_view.person.id != orig_private_message.creator_id {
|
||||
return Err(LemmyError::from_message(
|
||||
"no_private_message_edit_allowed".into(),
|
||||
));
|
||||
return Err(LemmyError::from_message("no_private_message_edit_allowed"));
|
||||
}
|
||||
|
||||
// Doing the update
|
||||
|
@ -47,7 +45,7 @@ impl PerformCrud for EditPrivateMessage {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_private_message".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_private_message"))?;
|
||||
|
||||
// Send the apub update
|
||||
CreateOrUpdatePrivateMessage::send(
|
||||
|
|
|
@ -35,7 +35,7 @@ impl PerformCrud for CreateSite {
|
|||
|
||||
let read_site = Site::read_simple;
|
||||
if blocking(context.pool(), read_site).await?.is_ok() {
|
||||
return Err(LemmyError::from_message("site_already_exists".into()));
|
||||
return Err(LemmyError::from_message("site_already_exists"));
|
||||
};
|
||||
|
||||
let local_user_view =
|
||||
|
@ -72,7 +72,7 @@ impl PerformCrud for CreateSite {
|
|||
|
||||
let create_site = move |conn: &'_ _| Site::create(conn, &site_form);
|
||||
if blocking(context.pool(), create_site).await?.is_err() {
|
||||
return Err(LemmyError::from_message("site_already_exists".into()));
|
||||
return Err(LemmyError::from_message("site_already_exists"));
|
||||
}
|
||||
|
||||
let site_view = blocking(context.pool(), SiteView::read).await??;
|
||||
|
|
|
@ -102,7 +102,7 @@ impl PerformCrud for GetSite {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("system_err_login".into()))?;
|
||||
.map_err(|e| e.with_message("system_err_login"))?;
|
||||
|
||||
let person_id = local_user_view.person.id;
|
||||
let community_blocks = blocking(context.pool(), move |conn| {
|
||||
|
@ -110,7 +110,7 @@ impl PerformCrud for GetSite {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("system_err_login".into()))?;
|
||||
.map_err(|e| e.with_message("system_err_login"))?;
|
||||
|
||||
let person_id = local_user_view.person.id;
|
||||
let person_blocks = blocking(context.pool(), move |conn| {
|
||||
|
@ -118,14 +118,14 @@ impl PerformCrud for GetSite {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("system_err_login".into()))?;
|
||||
.map_err(|e| e.with_message("system_err_login"))?;
|
||||
|
||||
let moderates = blocking(context.pool(), move |conn| {
|
||||
CommunityModeratorView::for_person(conn, person_id)
|
||||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("system_err_login".into()))?;
|
||||
.map_err(|e| e.with_message("system_err_login"))?;
|
||||
|
||||
Some(MyUserInfo {
|
||||
local_user_view,
|
||||
|
|
|
@ -67,7 +67,7 @@ impl PerformCrud for EditSite {
|
|||
blocking(context.pool(), update_site)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_site".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_site"))?;
|
||||
|
||||
let site_view = blocking(context.pool(), SiteView::read).await??;
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ impl PerformCrud for Register {
|
|||
// Make sure site has open registration
|
||||
if let Ok(site) = blocking(context.pool(), Site::read_simple).await? {
|
||||
if !site.open_registration {
|
||||
return Err(LemmyError::from_message("registration_closed".into()));
|
||||
return Err(LemmyError::from_message("registration_closed"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ impl PerformCrud for Register {
|
|||
|
||||
// Make sure passwords match
|
||||
if data.password != data.password_verify {
|
||||
return Err(LemmyError::from_message("passwords_dont_match".into()));
|
||||
return Err(LemmyError::from_message("passwords_dont_match"));
|
||||
}
|
||||
|
||||
// Check if there are admins. False if admins exist
|
||||
|
@ -86,7 +86,7 @@ impl PerformCrud for Register {
|
|||
})
|
||||
.await?;
|
||||
if !check {
|
||||
return Err(LemmyError::from_message("captcha_incorrect".into()));
|
||||
return Err(LemmyError::from_message("captcha_incorrect"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ impl PerformCrud for Register {
|
|||
|
||||
let actor_keypair = generate_actor_keypair()?;
|
||||
if !is_valid_actor_name(&data.username, context.settings().actor_name_max_length) {
|
||||
return Err(LemmyError::from_message("invalid_username".into()));
|
||||
return Err(LemmyError::from_message("invalid_username"));
|
||||
}
|
||||
let actor_id = generate_local_apub_endpoint(
|
||||
EndpointType::Person,
|
||||
|
@ -122,7 +122,7 @@ impl PerformCrud for Register {
|
|||
})
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("user_already_exists".into()))?;
|
||||
.map_err(|e| e.with_message("user_already_exists"))?;
|
||||
|
||||
// Create the local user
|
||||
// TODO some of these could probably use the DB defaults
|
||||
|
@ -164,7 +164,7 @@ impl PerformCrud for Register {
|
|||
})
|
||||
.await??;
|
||||
|
||||
return Err(LemmyError::from(e).with_message(err_type.into()));
|
||||
return Err(LemmyError::from(e).with_message(err_type));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -215,7 +215,7 @@ impl PerformCrud for Register {
|
|||
blocking(context.pool(), follow)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("community_follower_already_exists".into()))?;
|
||||
.map_err(|e| e.with_message("community_follower_already_exists"))?;
|
||||
|
||||
// If its an admin, add them as a mod and follower to main
|
||||
if no_admins {
|
||||
|
@ -228,7 +228,7 @@ impl PerformCrud for Register {
|
|||
blocking(context.pool(), join)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("community_moderator_already_exists".into()))?;
|
||||
.map_err(|e| e.with_message("community_moderator_already_exists"))?;
|
||||
}
|
||||
|
||||
// Return the jwt
|
||||
|
|
|
@ -27,7 +27,7 @@ impl PerformCrud for DeleteAccount {
|
|||
)
|
||||
.unwrap_or(false);
|
||||
if !valid {
|
||||
return Err(LemmyError::from_message("password_incorrect".into()));
|
||||
return Err(LemmyError::from_message("password_incorrect"));
|
||||
}
|
||||
|
||||
// Comments
|
||||
|
@ -36,14 +36,14 @@ impl PerformCrud for DeleteAccount {
|
|||
blocking(context.pool(), permadelete)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_comment".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
||||
|
||||
// Posts
|
||||
let permadelete = move |conn: &'_ _| Post::permadelete_for_creator(conn, person_id);
|
||||
blocking(context.pool(), permadelete)
|
||||
.await?
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_update_post".into()))?;
|
||||
.map_err(|e| e.with_message("couldnt_update_post"))?;
|
||||
|
||||
blocking(context.pool(), move |conn| {
|
||||
Person::delete_account(conn, person_id)
|
||||
|
|
|
@ -55,7 +55,7 @@ impl PerformCrud for GetPersonDetails {
|
|||
.await;
|
||||
person
|
||||
.map_err(LemmyError::from)
|
||||
.map_err(|e| e.with_message("couldnt_find_that_username_or_email".into()))?
|
||||
.map_err(|e| e.with_message("couldnt_find_that_username_or_email"))?
|
||||
.id
|
||||
}
|
||||
};
|
||||
|
|
|
@ -145,7 +145,7 @@ pub(in crate::activities) async fn receive_remove_action(
|
|||
DeletableObjects::Community(community) => {
|
||||
if community.local {
|
||||
return Err(LemmyError::from_message(
|
||||
"Only local admin can remove community".into(),
|
||||
"Only local admin can remove community",
|
||||
));
|
||||
}
|
||||
let form = ModRemoveCommunityForm {
|
||||
|
|
|
@ -112,7 +112,7 @@ impl UndoDelete {
|
|||
DeletableObjects::Community(community) => {
|
||||
if community.local {
|
||||
return Err(LemmyError::from_message(
|
||||
"Only local admin can restore community".into(),
|
||||
"Only local admin can restore community",
|
||||
));
|
||||
}
|
||||
let deleted_community = blocking(context.pool(), move |conn| {
|
||||
|
|
|
@ -43,10 +43,8 @@ async fn verify_person(
|
|||
) -> Result<(), LemmyError> {
|
||||
let person = person_id.dereference(context, request_counter).await?;
|
||||
if person.banned {
|
||||
return Err(LemmyError::from_message(format!(
|
||||
"Person {} is banned",
|
||||
person_id
|
||||
)));
|
||||
let error = LemmyError::from(anyhow::anyhow!("Person {} is banned", person_id));
|
||||
return Err(error.with_message("banned"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -62,18 +60,14 @@ pub(crate) async fn verify_person_in_community(
|
|||
) -> Result<(), LemmyError> {
|
||||
let person = person_id.dereference(context, request_counter).await?;
|
||||
if person.banned {
|
||||
return Err(LemmyError::from_message(
|
||||
"Person is banned from site".to_string(),
|
||||
));
|
||||
return Err(LemmyError::from_message("Person is banned from site"));
|
||||
}
|
||||
let person_id = person.id;
|
||||
let community_id = community.id;
|
||||
let is_banned =
|
||||
move |conn: &'_ _| CommunityPersonBanView::get(conn, person_id, community_id).is_ok();
|
||||
if blocking(context.pool(), is_banned).await? {
|
||||
return Err(LemmyError::from_message(
|
||||
"Person is banned from community".to_string(),
|
||||
));
|
||||
return Err(LemmyError::from_message("Person is banned from community"));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
@ -107,7 +101,7 @@ pub(crate) async fn verify_mod_action(
|
|||
})
|
||||
.await?;
|
||||
if !is_mod_or_admin {
|
||||
return Err(LemmyError::from_message("Not a mod".into()));
|
||||
return Err(LemmyError::from_message("Not a mod"));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -120,14 +114,14 @@ fn verify_add_remove_moderator_target(
|
|||
community: &ApubCommunity,
|
||||
) -> Result<(), LemmyError> {
|
||||
if target != &generate_moderators_url(&community.actor_id)?.into() {
|
||||
return Err(LemmyError::from_message("Unkown target url".into()));
|
||||
return Err(LemmyError::from_message("Unkown target url"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn verify_is_public(to: &[Url], cc: &[Url]) -> Result<(), LemmyError> {
|
||||
if ![to, cc].iter().any(|set| set.contains(&public())) {
|
||||
return Err(LemmyError::from_message("Object is not public".into()));
|
||||
return Err(LemmyError::from_message("Object is not public"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@ -135,7 +129,7 @@ pub(crate) fn verify_is_public(to: &[Url], cc: &[Url]) -> Result<(), LemmyError>
|
|||
pub(crate) fn check_community_deleted_or_removed(community: &Community) -> Result<(), LemmyError> {
|
||||
if community.deleted || community.removed {
|
||||
Err(LemmyError::from_message(
|
||||
"New post or comment cannot be created in deleted or removed community".into(),
|
||||
"New post or comment cannot be created in deleted or removed community",
|
||||
))
|
||||
} else {
|
||||
Ok(())
|
||||
|
|
|
@ -96,7 +96,7 @@ impl ActivityHandler for CreateOrUpdatePost {
|
|||
self.object.stickied == Some(true) || self.object.comments_enabled == Some(false);
|
||||
if community.local && is_stickied_or_locked {
|
||||
return Err(LemmyError::from_message(
|
||||
"New post cannot be stickied or locked".into(),
|
||||
"New post cannot be stickied or locked",
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ pub async fn search_by_apub_id(
|
|||
.await?,
|
||||
))
|
||||
}
|
||||
_ => Err(LemmyError::from_message("invalid query".into())),
|
||||
_ => Err(LemmyError::from_message("invalid query")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,8 +110,9 @@ where
|
|||
return object.map(|o| o.actor_id().into());
|
||||
}
|
||||
}
|
||||
Err(LemmyError::from_message(format!(
|
||||
let error = LemmyError::from(anyhow::anyhow!(
|
||||
"Failed to resolve actor for {}",
|
||||
identifier
|
||||
)))
|
||||
));
|
||||
Err(error.with_message("failed_to_resolve"))
|
||||
}
|
||||
|
|
|
@ -181,10 +181,11 @@ fn assert_activity_not_local(id: &Url, hostname: &str) -> Result<(), LemmyError>
|
|||
let activity_domain = id.domain().context(location_info!())?;
|
||||
|
||||
if activity_domain == hostname {
|
||||
return Err(LemmyError::from_message(format!(
|
||||
let error = LemmyError::from(anyhow::anyhow!(
|
||||
"Error: received activity which was sent by local instance: {:?}",
|
||||
id
|
||||
)));
|
||||
));
|
||||
return Err(error.with_message("received_local_activity"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -40,28 +40,28 @@ pub(crate) fn check_is_apub_id_valid(
|
|||
return if domain == local_instance {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(LemmyError::from_message(format!(
|
||||
let error = LemmyError::from(anyhow::anyhow!(
|
||||
"Trying to connect with {}, but federation is disabled",
|
||||
domain
|
||||
)))
|
||||
));
|
||||
Err(error.with_message("federation_disabled"))
|
||||
};
|
||||
}
|
||||
|
||||
let host = apub_id.host_str().context(location_info!())?;
|
||||
let host_as_ip = host.parse::<IpAddr>();
|
||||
if host == "localhost" || host_as_ip.is_ok() {
|
||||
return Err(LemmyError::from_message(format!(
|
||||
"invalid hostname {}: {}",
|
||||
host, apub_id
|
||||
)));
|
||||
let error = LemmyError::from(anyhow::anyhow!("invalid hostname {}: {}", host, apub_id));
|
||||
return Err(error.with_message("invalid_hostname"));
|
||||
}
|
||||
|
||||
if apub_id.scheme() != settings.get_protocol_string() {
|
||||
return Err(LemmyError::from_message(format!(
|
||||
let error = LemmyError::from(anyhow::anyhow!(
|
||||
"invalid apub id scheme {}: {}",
|
||||
apub_id.scheme(),
|
||||
apub_id
|
||||
)));
|
||||
));
|
||||
return Err(error.with_message("invalid_scheme"));
|
||||
}
|
||||
|
||||
// TODO: might be good to put the part above in one method, and below in another
|
||||
|
@ -69,10 +69,8 @@ pub(crate) fn check_is_apub_id_valid(
|
|||
// -> no that doesnt make sense, we still need the code below for blocklist and strict allowlist
|
||||
if let Some(blocked) = settings.to_owned().federation.blocked_instances {
|
||||
if blocked.contains(&domain) {
|
||||
return Err(LemmyError::from_message(format!(
|
||||
"{} is in federation blocklist",
|
||||
domain
|
||||
)));
|
||||
let error = LemmyError::from(anyhow::anyhow!("{} is in federation blocklist", domain));
|
||||
return Err(error.with_message("federation_blocked"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,10 +83,8 @@ pub(crate) fn check_is_apub_id_valid(
|
|||
allowed.push(local_instance);
|
||||
|
||||
if !allowed.contains(&domain) {
|
||||
return Err(LemmyError::from_message(format!(
|
||||
"{} not in federation allowlist",
|
||||
domain
|
||||
)));
|
||||
let error = LemmyError::from(anyhow::anyhow!("{} not in federation allowlist", domain));
|
||||
return Err(error.with_message("federation_not_allowed"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ impl ApubObject for ApubComment {
|
|||
)
|
||||
.await?;
|
||||
if post.locked {
|
||||
return Err(LemmyError::from_message("Post is locked".into()));
|
||||
return Err(LemmyError::from_message("Post is locked"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -116,9 +116,7 @@ impl ApubObject for ApubPrivateMessage {
|
|||
.dereference(context, request_counter)
|
||||
.await?;
|
||||
if person.banned {
|
||||
return Err(LemmyError::from_message(
|
||||
"Person is banned from site".into(),
|
||||
));
|
||||
return Err(LemmyError::from_message("Person is banned from site"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ impl TryFrom<i16> for VoteType {
|
|||
match value {
|
||||
1 => Ok(VoteType::Like),
|
||||
-1 => Ok(VoteType::Dislike),
|
||||
_ => Err(LemmyError::from_message("invalid vote value".into())),
|
||||
_ => Err(LemmyError::from_message("invalid vote value")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ impl Page {
|
|||
break Ok(c);
|
||||
}
|
||||
} else {
|
||||
return Err(LemmyError::from_message("No community found in cc".into()));
|
||||
return Err(LemmyError::from_message("No community found in cc"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ pub fn diesel_option_overwrite_to_url(
|
|||
Some("") => Ok(Some(None)),
|
||||
Some(str_url) => match Url::parse(str_url) {
|
||||
Ok(url) => Ok(Some(Some(url.into()))),
|
||||
Err(e) => Err(LemmyError::from(e).with_message("invalid_url".into())),
|
||||
Err(e) => Err(LemmyError::from(e).with_message("invalid_url")),
|
||||
},
|
||||
None => Ok(None),
|
||||
}
|
||||
|
|
|
@ -45,17 +45,17 @@ macro_rules! location_info {
|
|||
|
||||
#[derive(serde::Serialize)]
|
||||
struct ApiError {
|
||||
error: String,
|
||||
error: &'static str,
|
||||
}
|
||||
|
||||
pub struct LemmyError {
|
||||
pub message: Option<String>,
|
||||
pub message: Option<&'static str>,
|
||||
pub inner: anyhow::Error,
|
||||
pub context: SpanTrace,
|
||||
}
|
||||
|
||||
impl LemmyError {
|
||||
pub fn from_message(message: String) -> Self {
|
||||
pub fn from_message(message: &'static str) -> Self {
|
||||
let inner = anyhow::anyhow!("{}", message);
|
||||
LemmyError {
|
||||
message: Some(message),
|
||||
|
@ -63,7 +63,7 @@ impl LemmyError {
|
|||
context: SpanTrace::capture(),
|
||||
}
|
||||
}
|
||||
pub fn with_message(self, message: String) -> Self {
|
||||
pub fn with_message(self, message: &'static str) -> Self {
|
||||
LemmyError {
|
||||
message: Some(message),
|
||||
..self
|
||||
|
@ -111,9 +111,7 @@ impl actix_web::error::ResponseError for LemmyError {
|
|||
|
||||
fn error_response(&self) -> HttpResponse {
|
||||
if let Some(message) = &self.message {
|
||||
HttpResponse::build(self.status_code()).json(ApiError {
|
||||
error: message.clone(),
|
||||
})
|
||||
HttpResponse::build(self.status_code()).json(ApiError { error: message })
|
||||
} else {
|
||||
HttpResponse::build(self.status_code())
|
||||
.content_type("text/plain")
|
||||
|
|
|
@ -79,13 +79,14 @@ impl RateLimiter {
|
|||
time_passed,
|
||||
rate_limit.allowance
|
||||
);
|
||||
Err(LemmyError::from_message(format!(
|
||||
let error = LemmyError::from(anyhow::anyhow!(
|
||||
"Too many requests. type: {}, IP: {}, {} per {} seconds",
|
||||
type_.as_ref(),
|
||||
ip,
|
||||
rate,
|
||||
per
|
||||
)))
|
||||
));
|
||||
Err(error.with_message("too_many_requests"))
|
||||
} else {
|
||||
if !check_only {
|
||||
rate_limit.allowance -= 1.0;
|
||||
|
|
|
@ -62,7 +62,8 @@ pub(crate) fn slur_check<'a>(
|
|||
|
||||
pub fn check_slurs(text: &str, slur_regex: &Option<Regex>) -> Result<(), LemmyError> {
|
||||
if let Err(slurs) = slur_check(text, slur_regex) {
|
||||
Err(LemmyError::from_message(slurs_vec_to_str(slurs)))
|
||||
let error = LemmyError::from(anyhow::anyhow!("{}", slurs_vec_to_str(slurs)));
|
||||
Err(error.with_message("slurs"))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -476,7 +476,7 @@ impl ChatServer {
|
|||
let data = &json["data"].to_string();
|
||||
let op = &json["op"]
|
||||
.as_str()
|
||||
.ok_or_else(|| LemmyError::from_message("missing op".into()))?;
|
||||
.ok_or_else(|| LemmyError::from_message("missing op"))?;
|
||||
|
||||
if let Ok(user_operation_crud) = UserOperationCrud::from_str(op) {
|
||||
let fut = (message_handler_crud)(context, msg.id, user_operation_crud.clone(), data);
|
||||
|
|
Loading…
Reference in New Issue