Ignore Announce() activity if repost already exists but with a different object ID
This commit is contained in:
parent
1b588a86e0
commit
fcab5b000a
2 changed files with 12 additions and 3 deletions
|
@ -65,8 +65,16 @@ pub async fn handle_announce(
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let repost_data = PostCreateData::repost(post_id, Some(repost_object_id));
|
let repost_data = PostCreateData::repost(post_id, Some(repost_object_id));
|
||||||
create_post(db_client, &author.id, repost_data).await?;
|
match create_post(db_client, &author.id, repost_data).await {
|
||||||
Ok(Some(NOTE))
|
Ok(_) => Ok(Some(NOTE)),
|
||||||
|
Err(DatabaseError::AlreadyExists("post")) => {
|
||||||
|
// Ignore activity if repost already exists (with a different
|
||||||
|
// object ID, or due to race condition in a handler).
|
||||||
|
log::warn!("repost already exists");
|
||||||
|
Ok(None)
|
||||||
|
},
|
||||||
|
Err(other_error) => Err(other_error.into()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -82,6 +82,7 @@ pub async fn create_post(
|
||||||
&data.created_at,
|
&data.created_at,
|
||||||
],
|
],
|
||||||
).await.map_err(catch_unique_violation("post"))?;
|
).await.map_err(catch_unique_violation("post"))?;
|
||||||
|
// Return NotFound error if reply/repost is not allowed
|
||||||
let post_row = maybe_post_row.ok_or(DatabaseError::NotFound("post"))?;
|
let post_row = maybe_post_row.ok_or(DatabaseError::NotFound("post"))?;
|
||||||
let db_post: DbPost = post_row.try_get("post")?;
|
let db_post: DbPost = post_row.try_get("post")?;
|
||||||
// Create links to attachments
|
// Create links to attachments
|
||||||
|
@ -175,7 +176,7 @@ pub async fn create_post(
|
||||||
).await?;
|
).await?;
|
||||||
notified_users.push(in_reply_to_author.id);
|
notified_users.push(in_reply_to_author.id);
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
if let Some(repost_of_id) = &db_post.repost_of_id {
|
if let Some(repost_of_id) = &db_post.repost_of_id {
|
||||||
update_repost_count(&transaction, repost_of_id, 1).await?;
|
update_repost_count(&transaction, repost_of_id, 1).await?;
|
||||||
let repost_of_author = get_post_author(&transaction, repost_of_id).await?;
|
let repost_of_author = get_post_author(&transaction, repost_of_id).await?;
|
||||||
|
|
Loading…
Reference in a new issue