From 5fdb24b6a2cef7964a049e789ed90f883221d657 Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Wed, 16 Jul 2025 20:24:52 +0200 Subject: feat: activity --- src/entity/user.rs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/entity/user.rs') diff --git a/src/entity/user.rs b/src/entity/user.rs index 47a761a..1abf50f 100644 --- a/src/entity/user.rs +++ b/src/entity/user.rs @@ -3,12 +3,14 @@ pub mod followers; use std::fmt::Display; use activitypub_federation::{ + activity_queue::queue_activity, + activity_sending::SendActivityTask, config::Data, fetch::object_id::ObjectId, http_signatures::generate_actor_keypair, kinds::actor::{ApplicationType, GroupType, OrganizationType, PersonType, ServiceType}, - protocol::public_key::PublicKey, - traits::{Actor, Object}, + protocol::{context::WithContext, public_key::PublicKey}, + traits::{Activity, Actor, Object}, }; use async_trait::async_trait; use serde::{Deserialize, Serialize}; @@ -21,7 +23,7 @@ use uuid::Uuid; use crate::{error::AppError, state::AppHandle}; #[derive(PartialEq, Clone, Debug)] -pub(crate) struct User { +pub struct User { pub id: String, pub username: String, pub ap_id: ObjectId, @@ -166,6 +168,30 @@ impl User { ).fetch_one(&services.postgres).await?; Self::try_from(user) } + + pub(crate) async fn send( + &self, + activity: A, + recipients: Vec, + use_queue: bool, + data: &Data, + ) -> Result<(), AppError> + where + A: Activity + Serialize + std::fmt::Debug + Send + Sync, + ::Error: From + From, + { + let activity = WithContext::new_default(activity); + // Send through queue in some cases and bypass it in others to test both code paths + if use_queue { + queue_activity(&activity, self, recipients, data).await?; + } else { + let sends = SendActivityTask::prepare(&activity, self, recipients, data).await?; + for send in sends { + send.sign_and_send(data).await?; + } + } + Ok(()) + } } #[derive(Clone, Debug, Deserialize, Serialize)] -- cgit v1.2.3