Make deliverer accept any serializable object

This commit is contained in:
silverpill 2022-07-13 23:40:33 +00:00
parent 9a38fb25bf
commit fd4d56c82b
12 changed files with 16 additions and 16 deletions

View file

@ -44,7 +44,7 @@ pub fn prepare_accept_follow(
user: &User,
source_actor: &Actor,
follow_activity_id: &str,
) -> OutgoingActivity {
) -> OutgoingActivity<Activity> {
let activity = build_accept_follow(
&instance.url(),
&user.profile,

View file

@ -64,7 +64,7 @@ pub async fn prepare_announce_note(
user: &User,
post: &Post,
repost_id: &Uuid,
) -> Result<OutgoingActivity, DatabaseError> {
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
assert_ne!(&post.id, repost_id);
let (recipients, _) = get_announce_note_recipients(
db_client,

View file

@ -215,7 +215,7 @@ pub async fn prepare_create_note(
instance: Instance,
author: &User,
post: &Post,
) -> Result<OutgoingActivity, DatabaseError> {
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
assert_eq!(author.id, post.author.id);
let subscribers = if matches!(post.visibility, Visibility::Subscribers) {
get_subscribers(db_client, &author.id).await?

View file

@ -41,7 +41,7 @@ pub async fn prepare_delete_note(
instance: Instance,
author: &User,
post: &Post,
) -> Result<OutgoingActivity, DatabaseError> {
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
assert_eq!(author.id, post.author.id);
let activity = build_delete_note(&instance.url(), post);
let recipients = get_note_recipients(db_client, author, post).await?;

View file

@ -49,7 +49,7 @@ pub async fn prepare_delete_person(
db_client: &impl GenericClient,
instance: Instance,
user: &User,
) -> Result<OutgoingActivity, DatabaseError> {
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
let activity = build_delete_person(&instance.url(), user);
let recipients = get_delete_person_recipients(db_client, &user.id).await?;
Ok(OutgoingActivity {

View file

@ -43,7 +43,7 @@ pub fn prepare_follow(
user: &User,
target_actor: &Actor,
follow_request_id: &Uuid,
) -> OutgoingActivity {
) -> OutgoingActivity<Activity> {
let activity = build_follow(
&instance.url(),
&user.profile,

View file

@ -54,7 +54,7 @@ pub async fn prepare_like_note(
user: &User,
post: &Post,
reaction_id: &Uuid,
) -> Result<OutgoingActivity, DatabaseError> {
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
let (recipients, primary_recipient) = get_like_note_recipients(
db_client,
&instance.url(),

View file

@ -47,7 +47,7 @@ pub async fn prepare_undo_announce_note(
user: &User,
post: &Post,
repost_id: &Uuid,
) -> Result<OutgoingActivity, DatabaseError> {
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
assert_ne!(&post.id, repost_id);
let (recipients, primary_recipient) = get_announce_note_recipients(
db_client,

View file

@ -53,7 +53,7 @@ pub fn prepare_undo_follow(
user: &User,
target_actor: &Actor,
follow_request_id: &Uuid,
) -> OutgoingActivity {
) -> OutgoingActivity<Activity> {
let activity = build_undo_follow(
&instance.url(),
&user.profile,

View file

@ -40,7 +40,7 @@ pub async fn prepare_undo_like_note(
user: &User,
post: &Post,
reaction_id: &Uuid,
) -> Result<OutgoingActivity, DatabaseError> {
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
let (recipients, primary_recipient) = get_like_note_recipients(
db_client,
&instance.url(),

View file

@ -55,7 +55,7 @@ pub async fn prepare_update_person(
db_client: &impl GenericClient,
instance: Instance,
user: &User,
) -> Result<OutgoingActivity, DatabaseError> {
) -> Result<OutgoingActivity<Activity>, DatabaseError> {
let activity = build_update_person(&instance.url(), user)
.map_err(|_| ConversionError)?;
let recipients = get_update_person_recipients(db_client, &user.id).await?;

View file

@ -1,11 +1,11 @@
use actix_web::http::Method;
use rsa::RsaPrivateKey;
use serde::Serialize;
use crate::config::Instance;
use crate::http_signatures::create::{create_http_signature, SignatureError};
use crate::models::users::types::User;
use crate::utils::crypto::deserialize_private_key;
use super::activity::Activity;
use super::actor::Actor;
use super::constants::{ACTIVITY_CONTENT_TYPE, ACTOR_KEY_SUFFIX};
use super::identifiers::local_actor_id;
@ -77,7 +77,7 @@ async fn send_activity(
async fn deliver_activity_worker(
instance: Instance,
sender: User,
activity: Activity,
activity: impl Serialize,
recipients: Vec<Actor>,
) -> Result<(), DelivererError> {
let actor_key = deserialize_private_key(&sender.private_key)?;
@ -114,14 +114,14 @@ async fn deliver_activity_worker(
Ok(())
}
pub struct OutgoingActivity {
pub struct OutgoingActivity<A: Serialize> {
pub instance: Instance,
pub sender: User,
pub activity: Activity,
pub activity: A,
pub recipients: Vec<Actor>,
}
impl OutgoingActivity {
impl<A: Serialize + 'static> OutgoingActivity<A> {
pub async fn deliver(self) -> Result<(), DelivererError> {
deliver_activity_worker(
self.instance,