Don't send notification if user is liking or replying to his own post

This commit is contained in:
silverpill 2021-11-21 14:38:27 +00:00
parent 481d9a1509
commit 65375ee2cd
3 changed files with 5 additions and 2 deletions

View file

@ -190,7 +190,9 @@ pub async fn create_post(
if let Some(in_reply_to_id) = &db_post.in_reply_to_id {
update_reply_count(&transaction, in_reply_to_id, 1).await?;
let in_reply_to = get_post_by_id(&transaction, in_reply_to_id).await?;
if in_reply_to.author.is_local() {
if in_reply_to.author.is_local() &&
in_reply_to.author.id != db_post.author_id
{
create_reply_notification(
&transaction,
&db_post.author_id,

View file

@ -22,7 +22,7 @@ pub async fn create_reaction(
).await.map_err(catch_unique_violation("reaction"))?;
update_reaction_count(&transaction, post_id, 1).await?;
let post = get_post_by_id(&transaction, post_id).await?;
if post.author.is_local() {
if post.author.is_local() && post.author.id != *author_id {
create_reaction_notification(
&transaction,
author_id,

View file

@ -54,6 +54,7 @@ pub struct UserCreateData {
}
fn validate_username(username: &str) -> Result<(), ValidationError> {
// The username regexp should not allow domain names and IP addresses
let username_regexp = Regex::new(r"^[a-z0-9_]+$").unwrap();
if !username_regexp.is_match(username) {
return Err(ValidationError("invalid username"));