Send notification when user's post is reposted
This commit is contained in:
parent
2111bae373
commit
683996aaf3
5 changed files with 33 additions and 1 deletions
|
@ -88,11 +88,12 @@ The following activities are supported:
|
|||
|
||||
- Accept(Follow)
|
||||
- Reject(Follow)
|
||||
- Undo(Follow)
|
||||
- Create(Note)
|
||||
- Delete(Note)
|
||||
- Like(Note)
|
||||
- Announce(Note)
|
||||
- Follow(Person)
|
||||
- Undo(Follow)
|
||||
- Update(Person)
|
||||
|
||||
And these additional standards:
|
||||
|
|
|
@ -34,6 +34,7 @@ impl ApiNotification {
|
|||
EventType::Reply => "reply",
|
||||
EventType::Reaction => "favourite",
|
||||
EventType::Mention => "mention",
|
||||
EventType::Repost => "reblog",
|
||||
};
|
||||
Self {
|
||||
id: notification.id.to_string(),
|
||||
|
|
|
@ -77,6 +77,18 @@ pub async fn create_mention_notification(
|
|||
).await
|
||||
}
|
||||
|
||||
pub async fn create_repost_notification(
|
||||
db_client: &impl GenericClient,
|
||||
sender_id: &Uuid,
|
||||
recipient_id: &Uuid,
|
||||
post_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
create_notification(
|
||||
db_client, sender_id, recipient_id, Some(post_id),
|
||||
EventType::Repost,
|
||||
).await
|
||||
}
|
||||
|
||||
pub async fn get_notifications(
|
||||
db_client: &impl GenericClient,
|
||||
recipient_id: &Uuid,
|
||||
|
|
|
@ -30,6 +30,7 @@ pub enum EventType {
|
|||
Reply,
|
||||
Reaction,
|
||||
Mention,
|
||||
Repost,
|
||||
}
|
||||
|
||||
impl From<&EventType> for i16 {
|
||||
|
@ -40,6 +41,7 @@ impl From<&EventType> for i16 {
|
|||
EventType::Reply => 3,
|
||||
EventType::Reaction => 4,
|
||||
EventType::Mention => 5,
|
||||
EventType::Repost => 6,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +56,7 @@ impl TryFrom<i16> for EventType {
|
|||
3 => Self::Reply,
|
||||
4 => Self::Reaction,
|
||||
5 => Self::Mention,
|
||||
6 => Self::Repost,
|
||||
_ => return Err(ConversionError),
|
||||
};
|
||||
Ok(event_type)
|
||||
|
|
|
@ -16,6 +16,7 @@ use crate::models::cleanup::{
|
|||
use crate::models::notifications::queries::{
|
||||
create_mention_notification,
|
||||
create_reply_notification,
|
||||
create_repost_notification,
|
||||
};
|
||||
use crate::models::profiles::queries::update_post_count;
|
||||
use crate::models::profiles::types::DbActorProfile;
|
||||
|
@ -251,12 +252,26 @@ pub async fn create_post(
|
|||
}
|
||||
if let Some(repost_of_id) = &db_post.repost_of_id {
|
||||
update_repost_count(&transaction, repost_of_id, 1).await?;
|
||||
let repost_of = get_post_by_id(&transaction, repost_of_id).await?;
|
||||
if repost_of.author.is_local() &&
|
||||
repost_of.author.id != db_post.author_id &&
|
||||
!notified_users.contains(&repost_of.author.id)
|
||||
{
|
||||
create_repost_notification(
|
||||
&transaction,
|
||||
&db_post.author_id,
|
||||
&repost_of.author.id,
|
||||
&db_post.id,
|
||||
).await?;
|
||||
notified_users.push(repost_of.author.id);
|
||||
};
|
||||
};
|
||||
// Notify mentioned users
|
||||
for profile in db_mentions.iter() {
|
||||
if profile.is_local() &&
|
||||
profile.id != db_post.author_id &&
|
||||
// Don't send mention notification to the author of parent post
|
||||
// or to the author of reposted post
|
||||
!notified_users.contains(&profile.id)
|
||||
{
|
||||
create_mention_notification(
|
||||
|
|
Loading…
Reference in a new issue