Send notifications when actor moves to another instance
This commit is contained in:
parent
9b31395853
commit
0063a14264
5 changed files with 22 additions and 0 deletions
|
@ -1162,6 +1162,7 @@ components:
|
|||
- reblog
|
||||
- subscription
|
||||
- subscription_expiration
|
||||
- move
|
||||
example: reply
|
||||
created_at:
|
||||
description: The timestamp of the notification.
|
||||
|
|
|
@ -13,6 +13,7 @@ use crate::activitypub::{
|
|||
use crate::config::Config;
|
||||
use crate::errors::{DatabaseError, ValidationError};
|
||||
use crate::models::{
|
||||
notifications::queries::create_move_notification,
|
||||
relationships::queries::{
|
||||
create_follow_request,
|
||||
get_followers,
|
||||
|
@ -92,6 +93,11 @@ pub async fn handle_move_person(
|
|||
Err(DatabaseError::AlreadyExists(_)) => (), // already following
|
||||
Err(other_error) => return Err(other_error.into()),
|
||||
};
|
||||
create_move_notification(
|
||||
db_client,
|
||||
&new_profile.id,
|
||||
&follower.id,
|
||||
).await?;
|
||||
};
|
||||
tokio::spawn(async move {
|
||||
for activity in activities {
|
||||
|
|
|
@ -50,6 +50,7 @@ impl ApiNotification {
|
|||
EventType::Subscription => "subscription",
|
||||
EventType::SubscriptionStart => "", // not supported
|
||||
EventType::SubscriptionExpiration => "subscription_expiration",
|
||||
EventType::Move => "move",
|
||||
};
|
||||
Self {
|
||||
id: notification.id.to_string(),
|
||||
|
|
|
@ -116,6 +116,17 @@ pub async fn create_subscription_expiration_notification(
|
|||
).await
|
||||
}
|
||||
|
||||
pub async fn create_move_notification(
|
||||
db_client: &impl GenericClient,
|
||||
sender_id: &Uuid,
|
||||
recipient_id: &Uuid,
|
||||
) -> Result<(), DatabaseError> {
|
||||
create_notification(
|
||||
db_client, sender_id, recipient_id, None,
|
||||
EventType::Move,
|
||||
).await
|
||||
}
|
||||
|
||||
pub async fn get_notifications(
|
||||
db_client: &impl GenericClient,
|
||||
recipient_id: &Uuid,
|
||||
|
|
|
@ -22,6 +22,7 @@ pub enum EventType {
|
|||
Subscription,
|
||||
SubscriptionStart,
|
||||
SubscriptionExpiration,
|
||||
Move,
|
||||
}
|
||||
|
||||
impl From<&EventType> for i16 {
|
||||
|
@ -36,6 +37,7 @@ impl From<&EventType> for i16 {
|
|||
EventType::Subscription => 7,
|
||||
EventType::SubscriptionStart => unimplemented!("not supported"),
|
||||
EventType::SubscriptionExpiration => 9,
|
||||
EventType::Move => 10,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +56,7 @@ impl TryFrom<i16> for EventType {
|
|||
7 => Self::Subscription,
|
||||
8 => Self::SubscriptionStart,
|
||||
9 => Self::SubscriptionExpiration,
|
||||
10 => Self::Move,
|
||||
_ => return Err(ConversionError),
|
||||
};
|
||||
Ok(event_type)
|
||||
|
|
Loading…
Reference in a new issue