Skip to content

Commit

Permalink
do send_activity after http response
Browse files Browse the repository at this point in the history
  • Loading branch information
phiresky committed Jul 5, 2023
1 parent 1e99e8b commit edda90c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod site;

#[async_trait::async_trait(?Send)]
pub trait Perform {
type Response: serde::ser::Serialize + Send;
type Response: serde::ser::Serialize + Send + Clone + Sync;

async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError>;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/api_common/src/custom_emoji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct DeleteCustomEmoji {
pub auth: Sensitive<String>,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The response for deleting a custom emoji.
Expand Down
2 changes: 1 addition & 1 deletion crates/api_common/src/site.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ pub struct PurgeComment {
pub auth: Sensitive<String>,
}

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))]
/// The response for purged items.
Expand Down
2 changes: 1 addition & 1 deletion crates/api_crud/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod user;

#[async_trait::async_trait(?Send)]
pub trait PerformCrud {
type Response: serde::ser::Serialize + Send;
type Response: serde::ser::Serialize + Send + Clone + Sync;

async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError>;
}
2 changes: 1 addition & 1 deletion crates/apub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ where

#[async_trait::async_trait]
pub trait SendActivity: Sync {
type Response: Sync + Send;
type Response: Sync + Send + Clone;

async fn send_activity(
_request: &Self,
Expand Down
18 changes: 14 additions & 4 deletions src/api_routes_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,13 @@ where
+ 'static,
{
let res = data.perform(&context).await?;
SendActivity::send_activity(&data, &res, &apub_data).await?;
Ok(HttpResponse::Ok().json(res))
let res_clone = res.clone();
tokio::spawn(async move {
if let Err(e) = SendActivity::send_activity(&data, &res_clone, &apub_data).await {
tracing::warn!("could not send_activity crud: {e}");
}
});
Ok(HttpResponse::Ok().json(&res))
}

async fn route_get<'a, Data>(
Expand Down Expand Up @@ -432,8 +437,13 @@ where
+ 'static,
{
let res = data.perform(&context).await?;
SendActivity::send_activity(&data, &res, &apub_data).await?;
Ok(HttpResponse::Ok().json(res))
let res_clone = res.clone();
tokio::spawn(async move {
if let Err(e) = SendActivity::send_activity(&data, &res_clone, &apub_data).await {
tracing::warn!("could not send_activity crud: {e}");
}
});
Ok(HttpResponse::Ok().json(&res))
}

async fn route_get_crud<'a, Data>(
Expand Down

0 comments on commit edda90c

Please sign in to comment.