context: &Data<LemmyContext>,
request_counter: &mut i32,
) -> Result<(), LemmyError> {
- // TODO: this is pretty ugly, but i cant think of a much better way
- let object = serde_json::to_string(&self.object)?;
- let object_data: ActivityCommonFields = serde_json::from_str(&object)?;
+ let object_value = serde_json::to_value(&self.object)?;
+ let object_data: ActivityCommonFields = serde_json::from_value(object_value.to_owned())?;
if is_activity_already_known(context.pool(), &object_data.id).await? {
return Ok(());
}
- insert_activity(&object_data.id, &self.object, false, true, context.pool()).await?;
+ insert_activity(&object_data.id, object_value, false, true, context.pool()).await?;
self.object.receive(context, request_counter).await
}
}
context: &LemmyContext,
) -> Result<(), LemmyError> {
// if this is a local community, we need to do an announce from the community instead
+ let object_value = serde_json::to_value(&activity)?;
if community.local {
- insert_activity(activity_id, &activity, true, false, context.pool()).await?;
+ insert_activity(activity_id, object_value, true, false, context.pool()).await?;
AnnounceActivity::send(activity, community, additional_inboxes, context).await?;
} else {
let mut inboxes = additional_inboxes;
let serialised_activity = serde_json::to_string(&activity)?;
- insert_activity(
- activity_id,
- &serialised_activity,
- true,
- sensitive,
- context.pool(),
- )
- .await?;
+ let object_value = serde_json::to_value(&activity)?;
+ insert_activity(activity_id, object_value, true, sensitive, context.pool()).await?;
send_activity(
serialised_activity,
self.inner
}
}
-
-#[derive(Serialize, Deserialize)]
-pub(crate) struct WithContextJson {
- #[serde(rename = "@context")]
- context: OneOrMany<AnyBase>,
- inner: serde_json::Value,
-}
-
-impl WithContextJson {
- pub(crate) fn new(inner: serde_json::Value) -> WithContextJson {
- WithContextJson {
- context: CONTEXT.clone(),
- inner,
- }
- }
-}
use crate::{
activity_lists::SharedInboxActivities,
check_is_apub_id_valid,
- context::{WithContext, WithContextJson},
+ context::WithContext,
fetcher::user_or_community::UserOrCommunity,
http::{community::receive_group_inbox, person::receive_person_inbox},
insert_activity,
// Log the activity, so we avoid receiving and parsing it twice. Note that this could still happen
// if we receive the same activity twice in very quick succession.
- insert_activity(&activity_data.id, &activity, false, true, context.pool()).await?;
+ let object_value = serde_json::to_value(&activity)?;
+ insert_activity(&activity_data.id, object_value, false, true, context.pool()).await?;
info!("Receiving activity {}", activity_data.id.to_string());
activity
fn create_json_apub_response(data: serde_json::Value) -> HttpResponse<Body> {
HttpResponse::Ok()
.content_type(APUB_JSON_CONTENT_TYPE)
- .json(WithContextJson::new(data))
+ .json(data)
}
fn create_apub_tombstone_response<T>(data: &T) -> HttpResponse<Body>
use lemmy_db_schema::{newtypes::DbUrl, source::activity::Activity, DbPool};
use lemmy_utils::{location_info, settings::structs::Settings, LemmyError};
use lemmy_websocket::LemmyContext;
-use serde::Serialize;
use std::net::IpAddr;
use url::{ParseError, Url};
/// Store a sent or received activity in the database, for logging purposes. These records are not
/// persistent.
-async fn insert_activity<T>(
+async fn insert_activity(
ap_id: &Url,
- activity: &T,
+ activity: serde_json::Value,
local: bool,
sensitive: bool,
pool: &DbPool,
-) -> Result<(), LemmyError>
-where
- T: Serialize + std::fmt::Debug + Send + 'static,
-{
- let data = serde_json::to_value(activity)?;
+) -> Result<(), LemmyError> {
let ap_id = ap_id.to_owned().into();
blocking(pool, move |conn| {
- Activity::insert(conn, ap_id, data, local, sensitive)
+ Activity::insert(conn, ap_id, activity, local, sensitive)
})
.await??;
Ok(())