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)
|
- Accept(Follow)
|
||||||
- Reject(Follow)
|
- Reject(Follow)
|
||||||
|
- Undo(Follow)
|
||||||
- Create(Note)
|
- Create(Note)
|
||||||
- Delete(Note)
|
- Delete(Note)
|
||||||
- Like(Note)
|
- Like(Note)
|
||||||
|
- Announce(Note)
|
||||||
- Follow(Person)
|
- Follow(Person)
|
||||||
- Undo(Follow)
|
|
||||||
- Update(Person)
|
- Update(Person)
|
||||||
|
|
||||||
And these additional standards:
|
And these additional standards:
|
||||||
|
|
|
@ -34,6 +34,7 @@ impl ApiNotification {
|
||||||
EventType::Reply => "reply",
|
EventType::Reply => "reply",
|
||||||
EventType::Reaction => "favourite",
|
EventType::Reaction => "favourite",
|
||||||
EventType::Mention => "mention",
|
EventType::Mention => "mention",
|
||||||
|
EventType::Repost => "reblog",
|
||||||
};
|
};
|
||||||
Self {
|
Self {
|
||||||
id: notification.id.to_string(),
|
id: notification.id.to_string(),
|
||||||
|
|
|
@ -77,6 +77,18 @@ pub async fn create_mention_notification(
|
||||||
).await
|
).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(
|
pub async fn get_notifications(
|
||||||
db_client: &impl GenericClient,
|
db_client: &impl GenericClient,
|
||||||
recipient_id: &Uuid,
|
recipient_id: &Uuid,
|
||||||
|
|
|
@ -30,6 +30,7 @@ pub enum EventType {
|
||||||
Reply,
|
Reply,
|
||||||
Reaction,
|
Reaction,
|
||||||
Mention,
|
Mention,
|
||||||
|
Repost,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&EventType> for i16 {
|
impl From<&EventType> for i16 {
|
||||||
|
@ -40,6 +41,7 @@ impl From<&EventType> for i16 {
|
||||||
EventType::Reply => 3,
|
EventType::Reply => 3,
|
||||||
EventType::Reaction => 4,
|
EventType::Reaction => 4,
|
||||||
EventType::Mention => 5,
|
EventType::Mention => 5,
|
||||||
|
EventType::Repost => 6,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,6 +56,7 @@ impl TryFrom<i16> for EventType {
|
||||||
3 => Self::Reply,
|
3 => Self::Reply,
|
||||||
4 => Self::Reaction,
|
4 => Self::Reaction,
|
||||||
5 => Self::Mention,
|
5 => Self::Mention,
|
||||||
|
6 => Self::Repost,
|
||||||
_ => return Err(ConversionError),
|
_ => return Err(ConversionError),
|
||||||
};
|
};
|
||||||
Ok(event_type)
|
Ok(event_type)
|
||||||
|
|
|
@ -16,6 +16,7 @@ use crate::models::cleanup::{
|
||||||
use crate::models::notifications::queries::{
|
use crate::models::notifications::queries::{
|
||||||
create_mention_notification,
|
create_mention_notification,
|
||||||
create_reply_notification,
|
create_reply_notification,
|
||||||
|
create_repost_notification,
|
||||||
};
|
};
|
||||||
use crate::models::profiles::queries::update_post_count;
|
use crate::models::profiles::queries::update_post_count;
|
||||||
use crate::models::profiles::types::DbActorProfile;
|
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 {
|
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 = 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
|
// Notify mentioned users
|
||||||
for profile in db_mentions.iter() {
|
for profile in db_mentions.iter() {
|
||||||
if profile.is_local() &&
|
if profile.is_local() &&
|
||||||
profile.id != db_post.author_id &&
|
profile.id != db_post.author_id &&
|
||||||
// Don't send mention notification to the author of parent post
|
// Don't send mention notification to the author of parent post
|
||||||
|
// or to the author of reposted post
|
||||||
!notified_users.contains(&profile.id)
|
!notified_users.contains(&profile.id)
|
||||||
{
|
{
|
||||||
create_mention_notification(
|
create_mention_notification(
|
||||||
|
|
Loading…
Reference in a new issue