diff options
author | rtkay123 <dev@kanjala.com> | 2025-07-16 20:24:52 +0200 |
---|---|---|
committer | rtkay123 <dev@kanjala.com> | 2025-07-16 20:24:52 +0200 |
commit | 5fdb24b6a2cef7964a049e789ed90f883221d657 (patch) | |
tree | 84b69fdb8faa859797b38b45f952b9c6d7c50165 /src/entity/user.rs | |
parent | 0a3040fba40d42c62ea70b7ccbade28e43ebaad5 (diff) | |
download | sellershut-5fdb24b6a2cef7964a049e789ed90f883221d657.tar.bz2 sellershut-5fdb24b6a2cef7964a049e789ed90f883221d657.zip |
feat: activity
Diffstat (limited to 'src/entity/user.rs')
-rw-r--r-- | src/entity/user.rs | 32 |
1 files changed, 29 insertions, 3 deletions
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<User>, @@ -166,6 +168,30 @@ impl User { ).fetch_one(&services.postgres).await?; Self::try_from(user) } + + pub(crate) async fn send<A>( + &self, + activity: A, + recipients: Vec<Url>, + use_queue: bool, + data: &Data<AppHandle>, + ) -> Result<(), AppError> + where + A: Activity + Serialize + std::fmt::Debug + Send + Sync, + <A as Activity>::Error: From<anyhow::Error> + From<serde_json::Error>, + { + 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)] |