mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 20:31:19 +00:00
parent
d3d4e76a19
commit
166ec196b0
38 changed files with 155 additions and 221 deletions
|
@ -58,8 +58,7 @@ impl Perform for MarkCommentAsRead {
|
||||||
Comment::update_read(conn, comment_id, read)
|
Comment::update_read(conn, comment_id, read)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
|
||||||
|
|
||||||
// Refetch it
|
// Refetch it
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
|
@ -102,14 +101,12 @@ impl Perform for SaveComment {
|
||||||
let save_comment = move |conn: &'_ _| CommentSaved::save(conn, &comment_saved_form);
|
let save_comment = move |conn: &'_ _| CommentSaved::save(conn, &comment_saved_form);
|
||||||
blocking(context.pool(), save_comment)
|
blocking(context.pool(), save_comment)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_save_comment"))?;
|
|
||||||
} else {
|
} else {
|
||||||
let unsave_comment = move |conn: &'_ _| CommentSaved::unsave(conn, &comment_saved_form);
|
let unsave_comment = move |conn: &'_ _| CommentSaved::unsave(conn, &comment_saved_form);
|
||||||
blocking(context.pool(), unsave_comment)
|
blocking(context.pool(), unsave_comment)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_save_comment"))?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let comment_id = data.comment_id;
|
let comment_id = data.comment_id;
|
||||||
|
@ -192,8 +189,7 @@ impl Perform for CreateCommentLike {
|
||||||
let like = move |conn: &'_ _| CommentLike::like(conn, &like_form2);
|
let like = move |conn: &'_ _| CommentLike::like(conn, &like_form2);
|
||||||
blocking(context.pool(), like)
|
blocking(context.pool(), like)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_like_comment"))?;
|
|
||||||
|
|
||||||
Vote::send(
|
Vote::send(
|
||||||
&object,
|
&object,
|
||||||
|
|
|
@ -61,8 +61,7 @@ impl Perform for CreateCommentReport {
|
||||||
CommentReport::report(conn, &report_form)
|
CommentReport::report(conn, &report_form)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_create_report"))?;
|
|
||||||
|
|
||||||
let comment_report_view = blocking(context.pool(), move |conn| {
|
let comment_report_view = blocking(context.pool(), move |conn| {
|
||||||
CommentReportView::read(conn, report.id, person_id)
|
CommentReportView::read(conn, report.id, person_id)
|
||||||
|
@ -129,8 +128,7 @@ impl Perform for ResolveCommentReport {
|
||||||
|
|
||||||
blocking(context.pool(), resolve_fun)
|
blocking(context.pool(), resolve_fun)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_resolve_report"))?;
|
|
||||||
|
|
||||||
let report_id = data.report_id;
|
let report_id = data.report_id;
|
||||||
let comment_report_view = blocking(context.pool(), move |conn| {
|
let comment_report_view = blocking(context.pool(), move |conn| {
|
||||||
|
|
|
@ -85,15 +85,13 @@ impl Perform for FollowCommunity {
|
||||||
let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form);
|
let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form);
|
||||||
blocking(context.pool(), follow)
|
blocking(context.pool(), follow)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
|
||||||
.map_err(|e| e.with_message("community_follower_already_exists"))?;
|
|
||||||
} else {
|
} else {
|
||||||
let unfollow =
|
let unfollow =
|
||||||
move |conn: &'_ _| CommunityFollower::unfollow(conn, &community_follower_form);
|
move |conn: &'_ _| CommunityFollower::unfollow(conn, &community_follower_form);
|
||||||
blocking(context.pool(), unfollow)
|
blocking(context.pool(), unfollow)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
|
||||||
.map_err(|e| e.with_message("community_follower_already_exists"))?;
|
|
||||||
}
|
}
|
||||||
} else if data.follow {
|
} else if data.follow {
|
||||||
// Dont actually add to the community followers here, because you need
|
// Dont actually add to the community followers here, because you need
|
||||||
|
@ -106,8 +104,7 @@ impl Perform for FollowCommunity {
|
||||||
let unfollow = move |conn: &'_ _| CommunityFollower::unfollow(conn, &community_follower_form);
|
let unfollow = move |conn: &'_ _| CommunityFollower::unfollow(conn, &community_follower_form);
|
||||||
blocking(context.pool(), unfollow)
|
blocking(context.pool(), unfollow)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
|
||||||
.map_err(|e| e.with_message("community_follower_already_exists"))?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
@ -153,8 +150,7 @@ impl Perform for BlockCommunity {
|
||||||
let block = move |conn: &'_ _| CommunityBlock::block(conn, &community_block_form);
|
let block = move |conn: &'_ _| CommunityBlock::block(conn, &community_block_form);
|
||||||
blocking(context.pool(), block)
|
blocking(context.pool(), block)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "community_block_already_exists"))?;
|
||||||
.map_err(|e| e.with_message("community_block_already_exists"))?;
|
|
||||||
|
|
||||||
// Also, unfollow the community, and send a federated unfollow
|
// Also, unfollow the community, and send a federated unfollow
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
|
@ -176,8 +172,7 @@ impl Perform for BlockCommunity {
|
||||||
let unblock = move |conn: &'_ _| CommunityBlock::unblock(conn, &community_block_form);
|
let unblock = move |conn: &'_ _| CommunityBlock::unblock(conn, &community_block_form);
|
||||||
blocking(context.pool(), unblock)
|
blocking(context.pool(), unblock)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "community_block_already_exists"))?;
|
||||||
.map_err(|e| e.with_message("community_block_already_exists"))?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let community_view = blocking(context.pool(), move |conn| {
|
let community_view = blocking(context.pool(), move |conn| {
|
||||||
|
@ -235,8 +230,7 @@ impl Perform for BanFromCommunity {
|
||||||
let ban = move |conn: &'_ _| CommunityPersonBan::ban(conn, &community_user_ban_form);
|
let ban = move |conn: &'_ _| CommunityPersonBan::ban(conn, &community_user_ban_form);
|
||||||
blocking(context.pool(), ban)
|
blocking(context.pool(), ban)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "community_user_already_banned"))?;
|
||||||
.map_err(|e| e.with_message("community_user_already_banned"))?;
|
|
||||||
|
|
||||||
// Also unsubscribe them from the community, if they are subscribed
|
// Also unsubscribe them from the community, if they are subscribed
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
|
@ -264,8 +258,7 @@ impl Perform for BanFromCommunity {
|
||||||
let unban = move |conn: &'_ _| CommunityPersonBan::unban(conn, &community_user_ban_form);
|
let unban = move |conn: &'_ _| CommunityPersonBan::unban(conn, &community_user_ban_form);
|
||||||
blocking(context.pool(), unban)
|
blocking(context.pool(), unban)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "community_user_already_banned"))?;
|
||||||
.map_err(|e| e.with_message("community_user_already_banned"))?;
|
|
||||||
UndoBlockUser::send(
|
UndoBlockUser::send(
|
||||||
&SiteOrCommunity::Community(community),
|
&SiteOrCommunity::Community(community),
|
||||||
&banned_person,
|
&banned_person,
|
||||||
|
@ -352,14 +345,12 @@ impl Perform for AddModToCommunity {
|
||||||
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
|
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
|
||||||
blocking(context.pool(), join)
|
blocking(context.pool(), join)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
|
||||||
.map_err(|e| e.with_message("community_moderator_already_exists"))?;
|
|
||||||
} else {
|
} else {
|
||||||
let leave = move |conn: &'_ _| CommunityModerator::leave(conn, &community_moderator_form);
|
let leave = move |conn: &'_ _| CommunityModerator::leave(conn, &community_moderator_form);
|
||||||
blocking(context.pool(), leave)
|
blocking(context.pool(), leave)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
|
||||||
.map_err(|e| e.with_message("community_moderator_already_exists"))?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
|
@ -481,8 +472,7 @@ impl Perform for TransferCommunity {
|
||||||
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
|
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
|
||||||
blocking(context.pool(), join)
|
blocking(context.pool(), join)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
|
||||||
.map_err(|e| e.with_message("community_moderator_already_exists"))?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
|
@ -503,16 +493,14 @@ impl Perform for TransferCommunity {
|
||||||
CommunityView::read(conn, community_id, Some(person_id))
|
CommunityView::read(conn, community_id, Some(person_id))
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_find_community"))?;
|
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let moderators = blocking(context.pool(), move |conn| {
|
let moderators = blocking(context.pool(), move |conn| {
|
||||||
CommunityModeratorView::for_community(conn, community_id)
|
CommunityModeratorView::for_community(conn, community_id)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_find_community"))?;
|
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(GetCommunityResponse {
|
Ok(GetCommunityResponse {
|
||||||
|
|
|
@ -80,8 +80,7 @@ impl Perform for Login {
|
||||||
LocalUserView::find_by_email_or_name(conn, &username_or_email)
|
LocalUserView::find_by_email_or_name(conn, &username_or_email)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_find_that_username_or_email"))?;
|
|
||||||
|
|
||||||
// Verify the password
|
// Verify the password
|
||||||
let valid: bool = verify(
|
let valid: bool = verify(
|
||||||
|
@ -263,8 +262,7 @@ impl Perform for SaveUserSettings {
|
||||||
Person::update(conn, person_id, &person_form)
|
Person::update(conn, person_id, &person_form)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "user_already_exists"))?;
|
||||||
.map_err(|e| e.with_message("user_already_exists"))?;
|
|
||||||
|
|
||||||
let local_user_form = LocalUserForm {
|
let local_user_form = LocalUserForm {
|
||||||
person_id: Some(person_id),
|
person_id: Some(person_id),
|
||||||
|
@ -300,7 +298,7 @@ impl Perform for SaveUserSettings {
|
||||||
"user_already_exists"
|
"user_already_exists"
|
||||||
};
|
};
|
||||||
|
|
||||||
return Err(LemmyError::from(e).with_message(err_type));
|
return Err(LemmyError::from_error_message(e, err_type));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -397,8 +395,7 @@ impl Perform for AddAdmin {
|
||||||
Person::add_admin(conn, added_person_id, added)
|
Person::add_admin(conn, added_person_id, added)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_user"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_user"))?;
|
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let form = ModAddForm {
|
let form = ModAddForm {
|
||||||
|
@ -447,8 +444,7 @@ impl Perform for BanPerson {
|
||||||
let ban_person = move |conn: &'_ _| Person::ban_person(conn, banned_person_id, ban, expires);
|
let ban_person = move |conn: &'_ _| Person::ban_person(conn, banned_person_id, ban, expires);
|
||||||
let person = blocking(context.pool(), ban_person)
|
let person = blocking(context.pool(), ban_person)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_user"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_user"))?;
|
|
||||||
|
|
||||||
// Remove their data if that's desired
|
// Remove their data if that's desired
|
||||||
let remove_data = data.remove_data.unwrap_or(false);
|
let remove_data = data.remove_data.unwrap_or(false);
|
||||||
|
@ -573,14 +569,12 @@ impl Perform for BlockPerson {
|
||||||
let block = move |conn: &'_ _| PersonBlock::block(conn, &person_block_form);
|
let block = move |conn: &'_ _| PersonBlock::block(conn, &person_block_form);
|
||||||
blocking(context.pool(), block)
|
blocking(context.pool(), block)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "person_block_already_exists"))?;
|
||||||
.map_err(|e| e.with_message("person_block_already_exists"))?;
|
|
||||||
} else {
|
} else {
|
||||||
let unblock = move |conn: &'_ _| PersonBlock::unblock(conn, &person_block_form);
|
let unblock = move |conn: &'_ _| PersonBlock::unblock(conn, &person_block_form);
|
||||||
blocking(context.pool(), unblock)
|
blocking(context.pool(), unblock)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "person_block_already_exists"))?;
|
||||||
.map_err(|e| e.with_message("person_block_already_exists"))?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO does any federated stuff need to be done here?
|
// TODO does any federated stuff need to be done here?
|
||||||
|
@ -704,8 +698,7 @@ impl Perform for MarkPersonMentionAsRead {
|
||||||
move |conn: &'_ _| PersonMention::update_read(conn, person_mention_id, read);
|
move |conn: &'_ _| PersonMention::update_read(conn, person_mention_id, read);
|
||||||
blocking(context.pool(), update_mention)
|
blocking(context.pool(), update_mention)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
|
||||||
|
|
||||||
let person_mention_id = read_person_mention.id;
|
let person_mention_id = read_person_mention.id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
@ -754,8 +747,7 @@ impl Perform for MarkAllAsRead {
|
||||||
let mark_as_read = move |conn: &'_ _| Comment::update_read(conn, reply_id, true);
|
let mark_as_read = move |conn: &'_ _| Comment::update_read(conn, reply_id, true);
|
||||||
blocking(context.pool(), mark_as_read)
|
blocking(context.pool(), mark_as_read)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark all user mentions as read
|
// Mark all user mentions as read
|
||||||
|
@ -763,15 +755,13 @@ impl Perform for MarkAllAsRead {
|
||||||
move |conn: &'_ _| PersonMention::mark_all_as_read(conn, person_id);
|
move |conn: &'_ _| PersonMention::mark_all_as_read(conn, person_id);
|
||||||
blocking(context.pool(), update_person_mentions)
|
blocking(context.pool(), update_person_mentions)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
|
||||||
|
|
||||||
// Mark all private_messages as read
|
// Mark all private_messages as read
|
||||||
let update_pm = move |conn: &'_ _| PrivateMessage::mark_all_as_read(conn, person_id);
|
let update_pm = move |conn: &'_ _| PrivateMessage::mark_all_as_read(conn, person_id);
|
||||||
blocking(context.pool(), update_pm)
|
blocking(context.pool(), update_pm)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_private_message"))?;
|
|
||||||
|
|
||||||
Ok(GetRepliesResponse { replies: vec![] })
|
Ok(GetRepliesResponse { replies: vec![] })
|
||||||
}
|
}
|
||||||
|
@ -795,8 +785,7 @@ impl Perform for PasswordReset {
|
||||||
LocalUserView::find_by_email(conn, &email)
|
LocalUserView::find_by_email(conn, &email)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_find_that_username_or_email"))?;
|
|
||||||
|
|
||||||
// Email the pure token to the user.
|
// Email the pure token to the user.
|
||||||
send_password_reset_email(&local_user_view, context.pool(), &context.settings()).await?;
|
send_password_reset_email(&local_user_view, context.pool(), &context.settings()).await?;
|
||||||
|
@ -836,8 +825,7 @@ impl Perform for PasswordChange {
|
||||||
LocalUser::update_password(conn, local_user_id, &password)
|
LocalUser::update_password(conn, local_user_id, &password)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_user"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_user"))?;
|
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(LoginResponse {
|
Ok(LoginResponse {
|
||||||
|
@ -948,8 +936,7 @@ impl Perform for VerifyEmail {
|
||||||
EmailVerification::read_for_token(conn, &token)
|
EmailVerification::read_for_token(conn, &token)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "token_not_found"))?;
|
||||||
.map_err(|e| e.with_message("token_not_found"))?;
|
|
||||||
|
|
||||||
let form = LocalUserForm {
|
let form = LocalUserForm {
|
||||||
// necessary in case this is a new signup
|
// necessary in case this is a new signup
|
||||||
|
|
|
@ -81,8 +81,7 @@ impl Perform for CreatePostLike {
|
||||||
let like = move |conn: &'_ _| PostLike::like(conn, &like_form2);
|
let like = move |conn: &'_ _| PostLike::like(conn, &like_form2);
|
||||||
blocking(context.pool(), like)
|
blocking(context.pool(), like)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_post"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_like_post"))?;
|
|
||||||
|
|
||||||
Vote::send(
|
Vote::send(
|
||||||
&object,
|
&object,
|
||||||
|
@ -321,14 +320,12 @@ impl Perform for SavePost {
|
||||||
let save = move |conn: &'_ _| PostSaved::save(conn, &post_saved_form);
|
let save = move |conn: &'_ _| PostSaved::save(conn, &post_saved_form);
|
||||||
blocking(context.pool(), save)
|
blocking(context.pool(), save)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_post"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_save_post"))?;
|
|
||||||
} else {
|
} else {
|
||||||
let unsave = move |conn: &'_ _| PostSaved::unsave(conn, &post_saved_form);
|
let unsave = move |conn: &'_ _| PostSaved::unsave(conn, &post_saved_form);
|
||||||
blocking(context.pool(), unsave)
|
blocking(context.pool(), unsave)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_post"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_save_post"))?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
|
|
|
@ -72,8 +72,7 @@ impl Perform for CreatePostReport {
|
||||||
PostReport::report(conn, &report_form)
|
PostReport::report(conn, &report_form)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_create_report"))?;
|
|
||||||
|
|
||||||
let post_report_view = blocking(context.pool(), move |conn| {
|
let post_report_view = blocking(context.pool(), move |conn| {
|
||||||
PostReportView::read(conn, report.id, person_id)
|
PostReportView::read(conn, report.id, person_id)
|
||||||
|
@ -138,8 +137,7 @@ impl Perform for ResolvePostReport {
|
||||||
|
|
||||||
blocking(context.pool(), resolve_fun)
|
blocking(context.pool(), resolve_fun)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_resolve_report"))?;
|
|
||||||
|
|
||||||
let post_report_view = blocking(context.pool(), move |conn| {
|
let post_report_view = blocking(context.pool(), move |conn| {
|
||||||
PostReportView::read(conn, report_id, person_id)
|
PostReportView::read(conn, report_id, person_id)
|
||||||
|
|
|
@ -40,8 +40,7 @@ impl Perform for MarkPrivateMessageAsRead {
|
||||||
PrivateMessage::update_read(conn, private_message_id, read)
|
PrivateMessage::update_read(conn, private_message_id, read)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_private_message"))?;
|
|
||||||
|
|
||||||
// No need to send an apub update
|
// No need to send an apub update
|
||||||
let op = UserOperation::MarkPrivateMessageAsRead;
|
let op = UserOperation::MarkPrivateMessageAsRead;
|
||||||
|
|
|
@ -416,11 +416,9 @@ impl Perform for ResolveObject {
|
||||||
|
|
||||||
let res = search_by_apub_id(&self.q, context)
|
let res = search_by_apub_id(&self.q, context)
|
||||||
.await
|
.await
|
||||||
.map_err(LemmyError::from)
|
|
||||||
.map_err(|e| e.with_message("couldnt_find_object"))?;
|
.map_err(|e| e.with_message("couldnt_find_object"))?;
|
||||||
convert_response(res, local_user_view.map(|l| l.person.id), context.pool())
|
convert_response(res, local_user_view.map(|l| l.person.id), context.pool())
|
||||||
.await
|
.await
|
||||||
.map_err(LemmyError::from)
|
|
||||||
.map_err(|e| e.with_message("couldnt_find_object"))
|
.map_err(|e| e.with_message("couldnt_find_object"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -565,7 +563,6 @@ impl Perform for SaveSiteConfig {
|
||||||
|
|
||||||
// Make sure docker doesn't have :ro at the end of the volume, so its not a read-only filesystem
|
// 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)
|
let config_hjson = Settings::save_config_file(&data.config_hjson)
|
||||||
.map_err(LemmyError::from)
|
|
||||||
.map_err(|e| e.with_message("couldnt_update_site"))?;
|
.map_err(|e| e.with_message("couldnt_update_site"))?;
|
||||||
|
|
||||||
Ok(GetSiteConfigResponse { config_hjson })
|
Ok(GetSiteConfigResponse { config_hjson })
|
||||||
|
|
|
@ -87,8 +87,7 @@ pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> {
|
||||||
pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError> {
|
pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError> {
|
||||||
blocking(pool, move |conn| Post::read(conn, post_id))
|
blocking(pool, move |conn| Post::read(conn, post_id))
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))
|
||||||
.map_err(|e| e.with_message("couldnt_find_post"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
|
@ -103,8 +102,7 @@ pub async fn mark_post_as_read(
|
||||||
PostRead::mark_as_read(conn, &post_read_form)
|
PostRead::mark_as_read(conn, &post_read_form)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_mark_post_as_read"))
|
||||||
.map_err(|e| e.with_message("couldnt_mark_post_as_read"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
|
@ -119,8 +117,7 @@ pub async fn mark_post_as_unread(
|
||||||
PostRead::mark_as_unread(conn, &post_read_form)
|
PostRead::mark_as_unread(conn, &post_read_form)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_mark_post_as_read"))
|
||||||
.map_err(|e| e.with_message("couldnt_mark_post_as_read"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
|
@ -130,7 +127,6 @@ pub async fn get_local_user_view_from_jwt(
|
||||||
secret: &Secret,
|
secret: &Secret,
|
||||||
) -> Result<LocalUserView, LemmyError> {
|
) -> Result<LocalUserView, LemmyError> {
|
||||||
let claims = Claims::decode(jwt, &secret.jwt_secret)
|
let claims = Claims::decode(jwt, &secret.jwt_secret)
|
||||||
.map_err(LemmyError::from)
|
|
||||||
.map_err(|e| e.with_message("not_logged_in"))?
|
.map_err(|e| e.with_message("not_logged_in"))?
|
||||||
.claims;
|
.claims;
|
||||||
let local_user_id = LocalUserId(claims.sub);
|
let local_user_id = LocalUserId(claims.sub);
|
||||||
|
@ -183,7 +179,6 @@ pub async fn get_local_user_settings_view_from_jwt(
|
||||||
secret: &Secret,
|
secret: &Secret,
|
||||||
) -> Result<LocalUserSettingsView, LemmyError> {
|
) -> Result<LocalUserSettingsView, LemmyError> {
|
||||||
let claims = Claims::decode(jwt.as_ref(), &secret.jwt_secret)
|
let claims = Claims::decode(jwt.as_ref(), &secret.jwt_secret)
|
||||||
.map_err(LemmyError::from)
|
|
||||||
.map_err(|e| e.with_message("not_logged_in"))?
|
.map_err(|e| e.with_message("not_logged_in"))?
|
||||||
.claims;
|
.claims;
|
||||||
let local_user_id = LocalUserId(claims.sub);
|
let local_user_id = LocalUserId(claims.sub);
|
||||||
|
@ -237,8 +232,7 @@ pub async fn check_community_deleted_or_removed(
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let community = blocking(pool, move |conn| Community::read(conn, community_id))
|
let community = blocking(pool, move |conn| Community::read(conn, community_id))
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_find_community"))?;
|
|
||||||
if community.deleted || community.removed {
|
if community.deleted || community.removed {
|
||||||
Err(LemmyError::from_message("deleted"))
|
Err(LemmyError::from_message("deleted"))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -75,8 +75,7 @@ impl PerformCrud for CreateComment {
|
||||||
// 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(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_create_comment"))?;
|
|
||||||
|
|
||||||
// Strange issue where sometimes the post ID is incorrect
|
// Strange issue where sometimes the post ID is incorrect
|
||||||
if parent.post_id != post_id {
|
if parent.post_id != post_id {
|
||||||
|
@ -98,8 +97,7 @@ impl PerformCrud for CreateComment {
|
||||||
Comment::create(conn, &comment_form2)
|
Comment::create(conn, &comment_form2)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_create_comment"))?;
|
|
||||||
|
|
||||||
// Necessary to update the ap_id
|
// Necessary to update the ap_id
|
||||||
let inserted_comment_id = inserted_comment.id;
|
let inserted_comment_id = inserted_comment.id;
|
||||||
|
@ -115,7 +113,6 @@ impl PerformCrud for CreateComment {
|
||||||
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(LemmyError::from)
|
|
||||||
.map_err(|e| e.with_message("couldnt_create_comment"))?;
|
.map_err(|e| e.with_message("couldnt_create_comment"))?;
|
||||||
|
|
||||||
// Scan the comment for user mentions, add those rows
|
// Scan the comment for user mentions, add those rows
|
||||||
|
@ -142,8 +139,7 @@ impl PerformCrud for CreateComment {
|
||||||
let like = move |conn: &'_ _| CommentLike::like(conn, &like_form);
|
let like = move |conn: &'_ _| CommentLike::like(conn, &like_form);
|
||||||
blocking(context.pool(), like)
|
blocking(context.pool(), like)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_like_comment"))?;
|
|
||||||
|
|
||||||
let apub_comment: ApubComment = updated_comment.into();
|
let apub_comment: ApubComment = updated_comment.into();
|
||||||
CreateOrUpdateComment::send(
|
CreateOrUpdateComment::send(
|
||||||
|
@ -178,8 +174,7 @@ impl PerformCrud for CreateComment {
|
||||||
Comment::update_read(conn, comment_id, true)
|
Comment::update_read(conn, comment_id, true)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
|
||||||
}
|
}
|
||||||
// If its a reply, mark the parent as read
|
// If its a reply, mark the parent as read
|
||||||
if let Some(parent_id) = data.parent_id {
|
if let Some(parent_id) = data.parent_id {
|
||||||
|
@ -192,8 +187,7 @@ impl PerformCrud for CreateComment {
|
||||||
Comment::update_read(conn, parent_id, true)
|
Comment::update_read(conn, parent_id, true)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_parent_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_parent_comment"))?;
|
|
||||||
}
|
}
|
||||||
// If the parent has PersonMentions mark them as read too
|
// If the parent has PersonMentions mark them as read too
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
|
@ -206,8 +200,7 @@ impl PerformCrud for CreateComment {
|
||||||
PersonMention::update_read(conn, mention.id, true)
|
PersonMention::update_read(conn, mention.id, true)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_person_mentions"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_person_mentions"))?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,8 +68,7 @@ impl PerformCrud for DeleteComment {
|
||||||
Comment::update_deleted(conn, comment_id, deleted)
|
Comment::update_deleted(conn, comment_id, deleted)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
|
||||||
|
|
||||||
let post_id = updated_comment.post_id;
|
let post_id = updated_comment.post_id;
|
||||||
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
let post = blocking(context.pool(), move |conn| Post::read(conn, post_id)).await??;
|
||||||
|
@ -155,8 +154,7 @@ impl PerformCrud for RemoveComment {
|
||||||
Comment::update_removed(conn, comment_id, removed)
|
Comment::update_removed(conn, comment_id, removed)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let form = ModRemoveCommentForm {
|
let form = ModRemoveCommentForm {
|
||||||
|
|
|
@ -41,8 +41,7 @@ impl PerformCrud for GetComment {
|
||||||
CommentView::read(conn, id, person_id)
|
CommentView::read(conn, id, person_id)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_find_comment"))?;
|
|
||||||
|
|
||||||
Ok(Self::Response {
|
Ok(Self::Response {
|
||||||
comment_view,
|
comment_view,
|
||||||
|
@ -103,8 +102,7 @@ impl PerformCrud for GetComments {
|
||||||
.list()
|
.list()
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_get_comments"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_get_comments"))?;
|
|
||||||
|
|
||||||
// Blank out deleted or removed info
|
// Blank out deleted or removed info
|
||||||
for cv in comments
|
for cv in comments
|
||||||
|
|
|
@ -70,8 +70,7 @@ impl PerformCrud for EditComment {
|
||||||
Comment::update_content(conn, comment_id, &content_slurs_removed)
|
Comment::update_content(conn, comment_id, &content_slurs_removed)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
|
||||||
|
|
||||||
// Do the mentions / recipients
|
// Do the mentions / recipients
|
||||||
let updated_comment_content = updated_comment.content.to_owned();
|
let updated_comment_content = updated_comment.content.to_owned();
|
||||||
|
|
|
@ -107,8 +107,7 @@ impl PerformCrud for CreateCommunity {
|
||||||
Community::create(conn, &community_form)
|
Community::create(conn, &community_form)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "community_already_exists"))?;
|
||||||
.map_err(|e| e.with_message("community_already_exists"))?;
|
|
||||||
|
|
||||||
// The community creator becomes a moderator
|
// The community creator becomes a moderator
|
||||||
let community_moderator_form = CommunityModeratorForm {
|
let community_moderator_form = CommunityModeratorForm {
|
||||||
|
@ -117,11 +116,9 @@ impl PerformCrud for CreateCommunity {
|
||||||
};
|
};
|
||||||
|
|
||||||
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
|
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
|
||||||
if blocking(context.pool(), join).await?.is_err() {
|
blocking(context.pool(), join)
|
||||||
return Err(LemmyError::from_message(
|
.await?
|
||||||
"community_moderator_already_exists",
|
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Follow your own community
|
// Follow your own community
|
||||||
let community_follower_form = CommunityFollowerForm {
|
let community_follower_form = CommunityFollowerForm {
|
||||||
|
@ -131,11 +128,9 @@ impl PerformCrud for CreateCommunity {
|
||||||
};
|
};
|
||||||
|
|
||||||
let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form);
|
let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form);
|
||||||
if blocking(context.pool(), follow).await?.is_err() {
|
blocking(context.pool(), follow)
|
||||||
return Err(LemmyError::from_message(
|
.await?
|
||||||
"community_follower_already_exists",
|
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let community_view = blocking(context.pool(), move |conn| {
|
let community_view = blocking(context.pool(), move |conn| {
|
||||||
|
|
|
@ -46,8 +46,7 @@ impl PerformCrud for DeleteCommunity {
|
||||||
Community::update_deleted(conn, community_id, deleted)
|
Community::update_deleted(conn, community_id, deleted)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_community"))?;
|
|
||||||
|
|
||||||
let res = send_community_ws_message(
|
let res = send_community_ws_message(
|
||||||
data.community_id,
|
data.community_id,
|
||||||
|
@ -98,8 +97,7 @@ impl PerformCrud for RemoveCommunity {
|
||||||
Community::update_removed(conn, community_id, removed)
|
Community::update_removed(conn, community_id, removed)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_community"))?;
|
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
let expires = data.expires.map(naive_from_unix);
|
let expires = data.expires.map(naive_from_unix);
|
||||||
|
|
|
@ -46,7 +46,6 @@ impl PerformCrud for GetCommunity {
|
||||||
let name = data.name.to_owned().unwrap_or_else(|| "main".to_string());
|
let name = data.name.to_owned().unwrap_or_else(|| "main".to_string());
|
||||||
resolve_actor_identifier::<Community>(&name, context.pool())
|
resolve_actor_identifier::<Community>(&name, context.pool())
|
||||||
.await
|
.await
|
||||||
.map_err(LemmyError::from)
|
|
||||||
.map_err(|e| e.with_message("couldnt_find_community"))?
|
.map_err(|e| e.with_message("couldnt_find_community"))?
|
||||||
.id
|
.id
|
||||||
}
|
}
|
||||||
|
@ -56,8 +55,7 @@ impl PerformCrud for GetCommunity {
|
||||||
CommunityView::read(conn, community_id, person_id)
|
CommunityView::read(conn, community_id, person_id)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_find_community"))?;
|
|
||||||
|
|
||||||
// Blank out deleted or removed info for non-logged in users
|
// Blank out deleted or removed info for non-logged in users
|
||||||
if person_id.is_none() && (community_view.community.deleted || community_view.community.removed)
|
if person_id.is_none() && (community_view.community.deleted || community_view.community.removed)
|
||||||
|
@ -69,8 +67,7 @@ impl PerformCrud for GetCommunity {
|
||||||
CommunityModeratorView::for_community(conn, community_id)
|
CommunityModeratorView::for_community(conn, community_id)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_find_community"))?;
|
|
||||||
|
|
||||||
let online = context
|
let online = context
|
||||||
.chat_server()
|
.chat_server()
|
||||||
|
|
|
@ -76,8 +76,7 @@ impl PerformCrud for EditCommunity {
|
||||||
Community::update(conn, community_id, &community_form)
|
Community::update(conn, community_id, &community_form)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_community"))?;
|
|
||||||
|
|
||||||
UpdateCommunity::send(
|
UpdateCommunity::send(
|
||||||
updated_community.into(),
|
updated_community.into(),
|
||||||
|
@ -139,8 +138,7 @@ impl PerformCrud for HideCommunity {
|
||||||
Community::update(conn, community_id, &community_form)
|
Community::update(conn, community_id, &community_form)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community_hidden_status"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_community_hidden_status"))?;
|
|
||||||
|
|
||||||
blocking(context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
ModHideCommunity::create(conn, &mod_hide_community_form)
|
ModHideCommunity::create(conn, &mod_hide_community_form)
|
||||||
|
|
|
@ -99,7 +99,7 @@ impl PerformCrud for CreatePost {
|
||||||
"couldnt_create_post"
|
"couldnt_create_post"
|
||||||
};
|
};
|
||||||
|
|
||||||
return Err(LemmyError::from(e).with_message(err_type));
|
return Err(LemmyError::from_error_message(e, err_type));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -114,7 +114,6 @@ impl PerformCrud for CreatePost {
|
||||||
Ok(Post::update_ap_id(conn, inserted_post_id, apub_id)?)
|
Ok(Post::update_ap_id(conn, inserted_post_id, apub_id)?)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
|
||||||
.map_err(|e| e.with_message("couldnt_create_post"))?;
|
.map_err(|e| e.with_message("couldnt_create_post"))?;
|
||||||
|
|
||||||
// They like their own post by default
|
// They like their own post by default
|
||||||
|
@ -127,9 +126,9 @@ impl PerformCrud for CreatePost {
|
||||||
};
|
};
|
||||||
|
|
||||||
let like = move |conn: &'_ _| PostLike::like(conn, &like_form);
|
let like = move |conn: &'_ _| PostLike::like(conn, &like_form);
|
||||||
if blocking(context.pool(), like).await?.is_err() {
|
blocking(context.pool(), like)
|
||||||
return Err(LemmyError::from_message("couldnt_like_post"));
|
.await?
|
||||||
}
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_post"))?;
|
||||||
|
|
||||||
// Mark the post as read
|
// Mark the post as read
|
||||||
mark_post_as_read(person_id, post_id, context.pool()).await?;
|
mark_post_as_read(person_id, post_id, context.pool()).await?;
|
||||||
|
|
|
@ -53,8 +53,7 @@ impl PerformCrud for GetPost {
|
||||||
PostView::read(conn, id, person_id)
|
PostView::read(conn, id, person_id)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_find_post"))?;
|
|
||||||
|
|
||||||
// Mark the post as read
|
// Mark the post as read
|
||||||
if let Some(person_id) = person_id {
|
if let Some(person_id) = person_id {
|
||||||
|
@ -78,8 +77,7 @@ impl PerformCrud for GetPost {
|
||||||
CommunityView::read(conn, community_id, person_id)
|
CommunityView::read(conn, community_id, person_id)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_find_community"))?;
|
|
||||||
|
|
||||||
// Blank out deleted or removed info for non-logged in users
|
// Blank out deleted or removed info for non-logged in users
|
||||||
if person_id.is_none() {
|
if person_id.is_none() {
|
||||||
|
@ -179,8 +177,7 @@ impl PerformCrud for GetPosts {
|
||||||
.list()
|
.list()
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_get_posts"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_get_posts"))?;
|
|
||||||
|
|
||||||
// Blank out deleted or removed info for non-logged in users
|
// Blank out deleted or removed info for non-logged in users
|
||||||
if person_id.is_none() {
|
if person_id.is_none() {
|
||||||
|
|
|
@ -103,7 +103,7 @@ impl PerformCrud for EditPost {
|
||||||
"couldnt_update_post"
|
"couldnt_update_post"
|
||||||
};
|
};
|
||||||
|
|
||||||
return Err(LemmyError::from(e).with_message(err_type));
|
return Err(LemmyError::from_error_message(e, err_type));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,10 @@ impl PerformCrud for CreatePrivateMessage {
|
||||||
{
|
{
|
||||||
Ok(private_message) => private_message,
|
Ok(private_message) => private_message,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return Err(LemmyError::from(e).with_message("couldnt_create_private_message"));
|
return Err(LemmyError::from_error_message(
|
||||||
|
e,
|
||||||
|
"couldnt_create_private_message",
|
||||||
|
));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -78,7 +81,6 @@ impl PerformCrud for CreatePrivateMessage {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
|
||||||
.map_err(|e| e.with_message("couldnt_create_private_message"))?;
|
.map_err(|e| e.with_message("couldnt_create_private_message"))?;
|
||||||
|
|
||||||
CreateOrUpdatePrivateMessage::send(
|
CreateOrUpdatePrivateMessage::send(
|
||||||
|
|
|
@ -41,8 +41,7 @@ impl PerformCrud for DeletePrivateMessage {
|
||||||
PrivateMessage::update_deleted(conn, private_message_id, deleted)
|
PrivateMessage::update_deleted(conn, private_message_id, deleted)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_private_message"))?;
|
|
||||||
|
|
||||||
// Send the apub update
|
// Send the apub update
|
||||||
send_apub_delete_private_message(
|
send_apub_delete_private_message(
|
||||||
|
|
|
@ -44,8 +44,7 @@ impl PerformCrud for EditPrivateMessage {
|
||||||
PrivateMessage::update_content(conn, private_message_id, &content_slurs_removed)
|
PrivateMessage::update_content(conn, private_message_id, &content_slurs_removed)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_private_message"))?;
|
|
||||||
|
|
||||||
// Send the apub update
|
// Send the apub update
|
||||||
CreateOrUpdatePrivateMessage::send(
|
CreateOrUpdatePrivateMessage::send(
|
||||||
|
|
|
@ -85,9 +85,9 @@ impl PerformCrud for CreateSite {
|
||||||
};
|
};
|
||||||
|
|
||||||
let create_site = move |conn: &'_ _| Site::create(conn, &site_form);
|
let create_site = move |conn: &'_ _| Site::create(conn, &site_form);
|
||||||
if blocking(context.pool(), create_site).await?.is_err() {
|
blocking(context.pool(), create_site)
|
||||||
return Err(LemmyError::from_message("site_already_exists"));
|
.await?
|
||||||
}
|
.map_err(|e| LemmyError::from_error_message(e, "site_already_exists"))?;
|
||||||
|
|
||||||
let site_view = blocking(context.pool(), SiteView::read_local).await??;
|
let site_view = blocking(context.pool(), SiteView::read_local).await??;
|
||||||
|
|
||||||
|
|
|
@ -101,31 +101,27 @@ impl PerformCrud for GetSite {
|
||||||
CommunityFollowerView::for_person(conn, person_id)
|
CommunityFollowerView::for_person(conn, person_id)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
|
||||||
.map_err(|e| e.with_message("system_err_login"))?;
|
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let community_blocks = blocking(context.pool(), move |conn| {
|
let community_blocks = blocking(context.pool(), move |conn| {
|
||||||
CommunityBlockView::for_person(conn, person_id)
|
CommunityBlockView::for_person(conn, person_id)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
|
||||||
.map_err(|e| e.with_message("system_err_login"))?;
|
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let person_blocks = blocking(context.pool(), move |conn| {
|
let person_blocks = blocking(context.pool(), move |conn| {
|
||||||
PersonBlockView::for_person(conn, person_id)
|
PersonBlockView::for_person(conn, person_id)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
|
||||||
.map_err(|e| e.with_message("system_err_login"))?;
|
|
||||||
|
|
||||||
let moderates = blocking(context.pool(), move |conn| {
|
let moderates = blocking(context.pool(), move |conn| {
|
||||||
CommunityModeratorView::for_person(conn, person_id)
|
CommunityModeratorView::for_person(conn, person_id)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
|
||||||
.map_err(|e| e.with_message("system_err_login"))?;
|
|
||||||
|
|
||||||
Some(MyUserInfo {
|
Some(MyUserInfo {
|
||||||
local_user_view,
|
local_user_view,
|
||||||
|
|
|
@ -77,8 +77,7 @@ impl PerformCrud for EditSite {
|
||||||
Site::update(conn, local_site.id, &site_form)
|
Site::update(conn, local_site.id, &site_form)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_site"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_site"))?;
|
|
||||||
|
|
||||||
// TODO can't think of a better way to do this.
|
// TODO can't think of a better way to do this.
|
||||||
// If the server suddenly requires email verification, or required applications, no old users
|
// If the server suddenly requires email verification, or required applications, no old users
|
||||||
|
@ -90,8 +89,7 @@ impl PerformCrud for EditSite {
|
||||||
LocalUser::set_all_users_registration_applications_accepted(conn)
|
LocalUser::set_all_users_registration_applications_accepted(conn)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_set_all_registrations_accepted"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_set_all_registrations_accepted"))?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !local_site.require_email_verification && update_site.require_email_verification {
|
if !local_site.require_email_verification && update_site.require_email_verification {
|
||||||
|
@ -99,8 +97,7 @@ impl PerformCrud for EditSite {
|
||||||
LocalUser::set_all_users_email_verified(conn)
|
LocalUser::set_all_users_email_verified(conn)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_set_all_email_verified"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_set_all_email_verified"))?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let site_view = blocking(context.pool(), SiteView::read_local).await??;
|
let site_view = blocking(context.pool(), SiteView::read_local).await??;
|
||||||
|
|
|
@ -141,8 +141,7 @@ impl PerformCrud for Register {
|
||||||
Person::create(conn, &person_form)
|
Person::create(conn, &person_form)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "user_already_exists"))?;
|
||||||
.map_err(|e| e.with_message("user_already_exists"))?;
|
|
||||||
|
|
||||||
// Create the local user
|
// Create the local user
|
||||||
let local_user_form = LocalUserForm {
|
let local_user_form = LocalUserForm {
|
||||||
|
@ -175,7 +174,7 @@ impl PerformCrud for Register {
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
return Err(LemmyError::from(e).with_message(err_type));
|
return Err(LemmyError::from_error_message(e, err_type));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -240,8 +239,7 @@ impl PerformCrud for Register {
|
||||||
let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form);
|
let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form);
|
||||||
blocking(context.pool(), follow)
|
blocking(context.pool(), follow)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
|
||||||
.map_err(|e| e.with_message("community_follower_already_exists"))?;
|
|
||||||
|
|
||||||
// If its an admin, add them as a mod and follower to main
|
// If its an admin, add them as a mod and follower to main
|
||||||
if no_admins {
|
if no_admins {
|
||||||
|
@ -253,8 +251,7 @@ impl PerformCrud for Register {
|
||||||
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
|
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
|
||||||
blocking(context.pool(), join)
|
blocking(context.pool(), join)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
|
||||||
.map_err(|e| e.with_message("community_moderator_already_exists"))?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut login_response = LoginResponse {
|
let mut login_response = LoginResponse {
|
||||||
|
|
|
@ -35,15 +35,13 @@ impl PerformCrud for DeleteAccount {
|
||||||
let permadelete = move |conn: &'_ _| Comment::permadelete_for_creator(conn, person_id);
|
let permadelete = move |conn: &'_ _| Comment::permadelete_for_creator(conn, person_id);
|
||||||
blocking(context.pool(), permadelete)
|
blocking(context.pool(), permadelete)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_comment"))?;
|
|
||||||
|
|
||||||
// Posts
|
// Posts
|
||||||
let permadelete = move |conn: &'_ _| Post::permadelete_for_creator(conn, person_id);
|
let permadelete = move |conn: &'_ _| Post::permadelete_for_creator(conn, person_id);
|
||||||
blocking(context.pool(), permadelete)
|
blocking(context.pool(), permadelete)
|
||||||
.await?
|
.await?
|
||||||
.map_err(LemmyError::from)
|
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_post"))?;
|
||||||
.map_err(|e| e.with_message("couldnt_update_post"))?;
|
|
||||||
|
|
||||||
blocking(context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
Person::delete_account(conn, person_id)
|
Person::delete_account(conn, person_id)
|
||||||
|
|
|
@ -53,7 +53,6 @@ impl PerformCrud for GetPersonDetails {
|
||||||
|
|
||||||
resolve_actor_identifier::<Person>(&name, context.pool())
|
resolve_actor_identifier::<Person>(&name, context.pool())
|
||||||
.await
|
.await
|
||||||
.map_err(LemmyError::from)
|
|
||||||
.map_err(|e| e.with_message("couldnt_find_that_username_or_email"))?
|
.map_err(|e| e.with_message("couldnt_find_that_username_or_email"))?
|
||||||
.id
|
.id
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ use crate::{
|
||||||
objects::{community::ApubCommunity, person::ApubPerson},
|
objects::{community::ApubCommunity, person::ApubPerson},
|
||||||
};
|
};
|
||||||
use activitystreams_kinds::public;
|
use activitystreams_kinds::public;
|
||||||
|
use anyhow::anyhow;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
activity_queue::send_activity,
|
activity_queue::send_activity,
|
||||||
|
@ -44,8 +45,8 @@ async fn verify_person(
|
||||||
.dereference(context, context.client(), request_counter)
|
.dereference(context, context.client(), request_counter)
|
||||||
.await?;
|
.await?;
|
||||||
if person.banned {
|
if person.banned {
|
||||||
let error = LemmyError::from(anyhow::anyhow!("Person {} is banned", person_id));
|
let err = anyhow!("Person {} is banned", person_id);
|
||||||
return Err(error.with_message("banned"));
|
return Err(LemmyError::from_error_message(err, "banned"));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use anyhow::anyhow;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use lemmy_apub_lib::{
|
use lemmy_apub_lib::{
|
||||||
object_id::ObjectId,
|
object_id::ObjectId,
|
||||||
|
@ -83,9 +84,6 @@ where
|
||||||
return object.map(|o| o.actor_id().into());
|
return object.map(|o| o.actor_id().into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let error = LemmyError::from(anyhow::anyhow!(
|
let err = anyhow!("Failed to resolve actor for {}", identifier);
|
||||||
"Failed to resolve actor for {}",
|
Err(LemmyError::from_error_message(err, "failed_to_resolve"))
|
||||||
identifier
|
|
||||||
));
|
|
||||||
Err(error.with_message("failed_to_resolve"))
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ use actix_web::{
|
||||||
HttpRequest,
|
HttpRequest,
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
};
|
};
|
||||||
use anyhow::Context;
|
use anyhow::{anyhow, Context};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
|
@ -181,11 +181,14 @@ fn assert_activity_not_local(id: &Url, hostname: &str) -> Result<(), LemmyError>
|
||||||
let activity_domain = id.domain().context(location_info!())?;
|
let activity_domain = id.domain().context(location_info!())?;
|
||||||
|
|
||||||
if activity_domain == hostname {
|
if activity_domain == hostname {
|
||||||
let error = LemmyError::from(anyhow::anyhow!(
|
let err = anyhow!(
|
||||||
"Error: received activity which was sent by local instance: {:?}",
|
"Error: received activity which was sent by local instance: {:?}",
|
||||||
id
|
id
|
||||||
|
);
|
||||||
|
return Err(LemmyError::from_error_message(
|
||||||
|
err,
|
||||||
|
"received_local_activity",
|
||||||
));
|
));
|
||||||
return Err(error.with_message("received_local_activity"));
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::fetcher::post_or_comment::PostOrComment;
|
use crate::fetcher::post_or_comment::PostOrComment;
|
||||||
use anyhow::Context;
|
use anyhow::{anyhow, Context};
|
||||||
use lemmy_api_common::blocking;
|
use lemmy_api_common::blocking;
|
||||||
use lemmy_db_schema::{newtypes::DbUrl, source::activity::Activity, DbPool};
|
use lemmy_db_schema::{newtypes::DbUrl, source::activity::Activity, DbPool};
|
||||||
use lemmy_utils::{location_info, settings::structs::Settings, LemmyError};
|
use lemmy_utils::{location_info, settings::structs::Settings, LemmyError};
|
||||||
|
@ -41,28 +41,24 @@ pub(crate) fn check_is_apub_id_valid(
|
||||||
return if domain == local_instance {
|
return if domain == local_instance {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
let error = LemmyError::from(anyhow::anyhow!(
|
let err = anyhow!(
|
||||||
"Trying to connect with {}, but federation is disabled",
|
"Trying to connect with {}, but federation is disabled",
|
||||||
domain
|
domain
|
||||||
));
|
);
|
||||||
Err(error.with_message("federation_disabled"))
|
Err(LemmyError::from_error_message(err, "federation_disabled"))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let host = apub_id.host_str().context(location_info!())?;
|
let host = apub_id.host_str().context(location_info!())?;
|
||||||
let host_as_ip = host.parse::<IpAddr>();
|
let host_as_ip = host.parse::<IpAddr>();
|
||||||
if host == "localhost" || host_as_ip.is_ok() {
|
if host == "localhost" || host_as_ip.is_ok() {
|
||||||
let error = LemmyError::from(anyhow::anyhow!("invalid hostname {}: {}", host, apub_id));
|
let err = anyhow!("invalid hostname {}: {}", host, apub_id);
|
||||||
return Err(error.with_message("invalid_hostname"));
|
return Err(LemmyError::from_error_message(err, "invalid_hostname"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if apub_id.scheme() != settings.get_protocol_string() {
|
if apub_id.scheme() != settings.get_protocol_string() {
|
||||||
let error = LemmyError::from(anyhow::anyhow!(
|
let err = anyhow!("invalid apub id scheme {}: {}", apub_id.scheme(), apub_id);
|
||||||
"invalid apub id scheme {}: {}",
|
return Err(LemmyError::from_error_message(err, "invalid_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
|
// TODO: might be good to put the part above in one method, and below in another
|
||||||
|
@ -70,8 +66,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
|
// -> 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 let Some(blocked) = settings.to_owned().federation.blocked_instances {
|
||||||
if blocked.contains(&domain) {
|
if blocked.contains(&domain) {
|
||||||
let error = LemmyError::from(anyhow::anyhow!("{} is in federation blocklist", domain));
|
let err = anyhow!("{} is in federation blocklist", domain);
|
||||||
return Err(error.with_message("federation_blocked"));
|
return Err(LemmyError::from_error_message(err, "federation_blocked"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,8 +80,11 @@ pub(crate) fn check_is_apub_id_valid(
|
||||||
allowed.push(local_instance);
|
allowed.push(local_instance);
|
||||||
|
|
||||||
if !allowed.contains(&domain) {
|
if !allowed.contains(&domain) {
|
||||||
let error = LemmyError::from(anyhow::anyhow!("{} not in federation allowlist", domain));
|
let err = anyhow!("{} not in federation allowlist", domain);
|
||||||
return Err(error.with_message("federation_not_allowed"));
|
return Err(LemmyError::from_error_message(
|
||||||
|
err,
|
||||||
|
"federation_not_allowed",
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ pub fn diesel_option_overwrite_to_url(
|
||||||
Some("") => Ok(Some(None)),
|
Some("") => Ok(Some(None)),
|
||||||
Some(str_url) => match Url::parse(str_url) {
|
Some(str_url) => match Url::parse(str_url) {
|
||||||
Ok(url) => Ok(Some(Some(url.into()))),
|
Ok(url) => Ok(Some(Some(url.into()))),
|
||||||
Err(e) => Err(LemmyError::from(e).with_message("invalid_url")),
|
Err(e) => Err(LemmyError::from_error_message(e, "invalid_url")),
|
||||||
},
|
},
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,6 @@ pub fn send_email(
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => Ok(()),
|
Ok(_) => Ok(()),
|
||||||
Err(e) => Err(LemmyError::from(e).with_message("email_send_failed")),
|
Err(e) => Err(LemmyError::from_error_message(e, "email_send_failed")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ pub struct LemmyError {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LemmyError {
|
impl LemmyError {
|
||||||
|
/// Create LemmyError from a message, including stack trace
|
||||||
pub fn from_message(message: &'static str) -> Self {
|
pub fn from_message(message: &'static str) -> Self {
|
||||||
let inner = anyhow::anyhow!("{}", message);
|
let inner = anyhow::anyhow!("{}", message);
|
||||||
LemmyError {
|
LemmyError {
|
||||||
|
@ -67,12 +68,27 @@ impl LemmyError {
|
||||||
context: SpanTrace::capture(),
|
context: SpanTrace::capture(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a LemmyError from error and message, including stack trace
|
||||||
|
pub fn from_error_message<E>(error: E, message: &'static str) -> Self
|
||||||
|
where
|
||||||
|
E: Into<anyhow::Error>,
|
||||||
|
{
|
||||||
|
LemmyError {
|
||||||
|
message: Some(message),
|
||||||
|
inner: error.into(),
|
||||||
|
context: SpanTrace::capture(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add message to existing LemmyError (or overwrite existing error)
|
||||||
pub fn with_message(self, message: &'static str) -> Self {
|
pub fn with_message(self, message: &'static str) -> Self {
|
||||||
LemmyError {
|
LemmyError {
|
||||||
message: Some(message),
|
message: Some(message),
|
||||||
..self
|
..self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_json(&self) -> Result<String, Self> {
|
pub fn to_json(&self) -> Result<String, Self> {
|
||||||
let api_error = match self.message {
|
let api_error = match self.message {
|
||||||
Some(error) => ApiError { error },
|
Some(error) => ApiError { error },
|
||||||
|
|
|
@ -79,14 +79,16 @@ impl RateLimiter {
|
||||||
time_passed,
|
time_passed,
|
||||||
rate_limit.allowance
|
rate_limit.allowance
|
||||||
);
|
);
|
||||||
let error = LemmyError::from(anyhow::anyhow!(
|
Err(LemmyError::from_error_message(
|
||||||
|
anyhow::anyhow!(
|
||||||
"Too many requests. type: {}, IP: {}, {} per {} seconds",
|
"Too many requests. type: {}, IP: {}, {} per {} seconds",
|
||||||
type_.as_ref(),
|
type_.as_ref(),
|
||||||
ip,
|
ip,
|
||||||
rate,
|
rate,
|
||||||
per
|
per
|
||||||
));
|
),
|
||||||
Err(error.with_message("too_many_requests"))
|
"too_many_requests",
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
if !check_only {
|
if !check_only {
|
||||||
rate_limit.allowance -= 1.0;
|
rate_limit.allowance -= 1.0;
|
||||||
|
|
|
@ -62,8 +62,10 @@ pub(crate) fn slur_check<'a>(
|
||||||
|
|
||||||
pub fn check_slurs(text: &str, slur_regex: &Option<Regex>) -> Result<(), LemmyError> {
|
pub fn check_slurs(text: &str, slur_regex: &Option<Regex>) -> Result<(), LemmyError> {
|
||||||
if let Err(slurs) = slur_check(text, slur_regex) {
|
if let Err(slurs) = slur_check(text, slur_regex) {
|
||||||
let error = LemmyError::from(anyhow::anyhow!("{}", slurs_vec_to_str(slurs)));
|
Err(LemmyError::from_error_message(
|
||||||
Err(error.with_message("slurs"))
|
anyhow::anyhow!("{}", slurs_vec_to_str(slurs)),
|
||||||
|
"slurs",
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue