Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
use crate::{
|
2022-11-12 13:52:57 +00:00
|
|
|
activities::{
|
|
|
|
generate_activity_id,
|
|
|
|
send_lemmy_activity,
|
|
|
|
verify_is_public,
|
|
|
|
verify_person_in_community,
|
|
|
|
},
|
2021-10-29 10:32:42 +00:00
|
|
|
activity_lists::AnnouncableActivities,
|
2021-07-17 16:20:44 +00:00
|
|
|
insert_activity,
|
2021-10-18 21:36:44 +00:00
|
|
|
objects::community::ApubCommunity,
|
2022-05-06 23:53:33 +00:00
|
|
|
protocol::{
|
2022-11-12 13:52:57 +00:00
|
|
|
activities::community::announce::{AnnounceActivity, RawAnnouncableActivities},
|
|
|
|
Id,
|
2022-05-06 23:53:33 +00:00
|
|
|
IdOrNestedObject,
|
|
|
|
},
|
2022-06-02 14:33:41 +00:00
|
|
|
ActorType,
|
2021-08-19 21:24:33 +00:00
|
|
|
};
|
2022-06-02 14:33:41 +00:00
|
|
|
use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
|
2021-11-19 17:47:06 +00:00
|
|
|
use activitystreams_kinds::{activity::AnnounceType, public};
|
2022-06-02 14:33:41 +00:00
|
|
|
use lemmy_utils::error::LemmyError;
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
use lemmy_websocket::LemmyContext;
|
2022-11-12 13:52:57 +00:00
|
|
|
use serde_json::Value;
|
2022-03-24 16:05:27 +00:00
|
|
|
use tracing::debug;
|
2022-06-02 14:33:41 +00:00
|
|
|
use url::Url;
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
|
2022-11-12 13:52:57 +00:00
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
impl ActivityHandler for RawAnnouncableActivities {
|
|
|
|
type DataType = LemmyContext;
|
|
|
|
type Error = LemmyError;
|
|
|
|
|
|
|
|
fn id(&self) -> &Url {
|
|
|
|
&self.id
|
|
|
|
}
|
|
|
|
|
|
|
|
fn actor(&self) -> &Url {
|
|
|
|
&self.actor
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
|
|
async fn verify(
|
|
|
|
&self,
|
|
|
|
_data: &Data<Self::DataType>,
|
|
|
|
_request_counter: &mut i32,
|
|
|
|
) -> Result<(), Self::Error> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
|
|
async fn receive(
|
|
|
|
self,
|
|
|
|
data: &Data<Self::DataType>,
|
|
|
|
request_counter: &mut i32,
|
|
|
|
) -> Result<(), Self::Error> {
|
|
|
|
let activity: AnnouncableActivities = self.clone().try_into()?;
|
|
|
|
// This is only for sending, not receiving so we reject it.
|
|
|
|
if let AnnouncableActivities::Page(_) = activity {
|
|
|
|
return Err(LemmyError::from_message("Cant receive page"));
|
|
|
|
}
|
|
|
|
let community = activity.get_community(data, &mut 0).await?;
|
|
|
|
let actor_id = ObjectId::new(activity.actor().clone());
|
|
|
|
|
|
|
|
// verify and receive activity
|
|
|
|
activity.verify(data, request_counter).await?;
|
|
|
|
activity.receive(data, request_counter).await?;
|
|
|
|
|
|
|
|
// send to community followers
|
|
|
|
if community.local {
|
|
|
|
verify_person_in_community(&actor_id, &community, data, &mut 0).await?;
|
|
|
|
AnnounceActivity::send(self, &community, data).await?;
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-28 11:46:48 +00:00
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
pub(crate) trait GetCommunity {
|
|
|
|
async fn get_community(
|
|
|
|
&self,
|
|
|
|
context: &LemmyContext,
|
|
|
|
request_counter: &mut i32,
|
|
|
|
) -> Result<ApubCommunity, LemmyError>;
|
|
|
|
}
|
|
|
|
|
2021-07-27 22:18:50 +00:00
|
|
|
impl AnnounceActivity {
|
2021-11-18 17:04:28 +00:00
|
|
|
pub(crate) fn new(
|
2022-11-12 13:52:57 +00:00
|
|
|
object: RawAnnouncableActivities,
|
2021-10-18 21:36:44 +00:00
|
|
|
community: &ApubCommunity,
|
2021-07-27 22:18:50 +00:00
|
|
|
context: &LemmyContext,
|
2021-11-11 19:49:15 +00:00
|
|
|
) -> Result<AnnounceActivity, LemmyError> {
|
|
|
|
Ok(AnnounceActivity {
|
2021-09-25 15:44:52 +00:00
|
|
|
actor: ObjectId::new(community.actor_id()),
|
2021-10-25 17:22:34 +00:00
|
|
|
to: vec![public()],
|
2022-05-06 23:53:33 +00:00
|
|
|
object: IdOrNestedObject::NestedObject(object),
|
2021-11-05 00:24:10 +00:00
|
|
|
cc: vec![community.followers_url.clone().into()],
|
2021-07-27 22:18:50 +00:00
|
|
|
kind: AnnounceType::Announce,
|
2021-09-22 15:57:09 +00:00
|
|
|
id: generate_activity_id(
|
|
|
|
&AnnounceType::Announce,
|
|
|
|
&context.settings().get_protocol_and_hostname(),
|
|
|
|
)?,
|
2021-11-11 19:49:15 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
2021-11-11 19:49:15 +00:00
|
|
|
pub async fn send(
|
2022-11-12 13:52:57 +00:00
|
|
|
object: RawAnnouncableActivities,
|
2021-11-11 19:49:15 +00:00
|
|
|
community: &ApubCommunity,
|
|
|
|
context: &LemmyContext,
|
|
|
|
) -> Result<(), LemmyError> {
|
|
|
|
let announce = AnnounceActivity::new(object.clone(), community, context)?;
|
2021-11-15 21:37:19 +00:00
|
|
|
let inboxes = community.get_follower_inboxes(context).await?;
|
2022-06-08 15:45:39 +00:00
|
|
|
send_lemmy_activity(context, announce, community, inboxes.clone(), false).await?;
|
2021-11-11 19:49:15 +00:00
|
|
|
|
2021-11-18 15:20:35 +00:00
|
|
|
// Pleroma and Mastodon can't handle activities like Announce/Create/Page. So for
|
|
|
|
// compatibility, we also send Announce/Page so that they can follow Lemmy communities.
|
2022-11-12 13:52:57 +00:00
|
|
|
let object_parsed = object.try_into()?;
|
|
|
|
if let AnnouncableActivities::CreateOrUpdatePost(c) = object_parsed {
|
|
|
|
// Hack: need to convert Page into a format which can be sent as activity, which requires
|
|
|
|
// adding actor field.
|
|
|
|
let announcable_page = RawAnnouncableActivities {
|
|
|
|
id: c.object.id.clone().into_inner(),
|
|
|
|
actor: c.actor.clone().into_inner(),
|
2022-11-14 14:30:44 +00:00
|
|
|
other: serde_json::to_value(c.object)?
|
|
|
|
.as_object()
|
|
|
|
.expect("is object")
|
|
|
|
.clone(),
|
2022-11-12 13:52:57 +00:00
|
|
|
};
|
|
|
|
let announce_compat = AnnounceActivity::new(announcable_page, community, context)?;
|
|
|
|
send_lemmy_activity(context, announce_compat, community, inboxes, false).await?;
|
|
|
|
}
|
2021-11-11 19:49:15 +00:00
|
|
|
Ok(())
|
2021-07-27 22:18:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
impl ActivityHandler for AnnounceActivity {
|
2021-10-06 20:20:05 +00:00
|
|
|
type DataType = LemmyContext;
|
2022-06-02 14:33:41 +00:00
|
|
|
type Error = LemmyError;
|
|
|
|
|
|
|
|
fn id(&self) -> &Url {
|
|
|
|
&self.id
|
|
|
|
}
|
|
|
|
|
|
|
|
fn actor(&self) -> &Url {
|
|
|
|
self.actor.inner()
|
|
|
|
}
|
2021-12-06 14:54:47 +00:00
|
|
|
|
|
|
|
#[tracing::instrument(skip_all)]
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
async fn verify(
|
|
|
|
&self,
|
2022-10-28 13:38:22 +00:00
|
|
|
_context: &Data<LemmyContext>,
|
2022-05-06 23:53:33 +00:00
|
|
|
_request_counter: &mut i32,
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
) -> Result<(), LemmyError> {
|
2021-11-06 17:44:34 +00:00
|
|
|
verify_is_public(&self.to, &self.cc)?;
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-12-06 14:54:47 +00:00
|
|
|
#[tracing::instrument(skip_all)]
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
async fn receive(
|
2021-08-12 12:48:09 +00:00
|
|
|
self,
|
2021-10-06 20:20:05 +00:00
|
|
|
context: &Data<LemmyContext>,
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
request_counter: &mut i32,
|
|
|
|
) -> Result<(), LemmyError> {
|
2022-11-12 13:52:57 +00:00
|
|
|
let object: AnnouncableActivities = self
|
|
|
|
.object
|
|
|
|
.object(context, request_counter)
|
|
|
|
.await?
|
|
|
|
.try_into()?;
|
|
|
|
// This is only for sending, not receiving so we reject it.
|
|
|
|
if let AnnouncableActivities::Page(_) = object {
|
|
|
|
return Err(LemmyError::from_message("Cant receive page"));
|
|
|
|
}
|
|
|
|
|
2022-05-06 23:53:33 +00:00
|
|
|
// we have to verify this here in order to avoid fetching the object twice over http
|
|
|
|
object.verify(context, request_counter).await?;
|
|
|
|
|
2022-11-12 13:52:57 +00:00
|
|
|
let object_value = serde_json::to_value(&object)?;
|
|
|
|
let insert = insert_activity(object.id(), object_value, false, true, context.pool()).await?;
|
|
|
|
if !insert {
|
|
|
|
debug!(
|
|
|
|
"Received duplicate activity in announce {}",
|
|
|
|
object.id().to_string()
|
|
|
|
);
|
|
|
|
return Ok(());
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
}
|
2022-05-06 23:53:33 +00:00
|
|
|
object.receive(context, request_counter).await
|
Apub inbox rewrite (#1652)
* start to implement apub inbox routing lib
* got something that almost works
* it compiles!
* implemented some more
* move library code to separate crate (most of it)
* convert private message handlers
* convert all comment receivers (except undo comment)
* convert post receiver
* add verify trait
* convert community receivers
* add cc field for all activities which i forgot before
* convert inbox functions, add missing checks
* convert undo like/dislike receivers
* convert undo_delete and undo_remove receivers
* move block/unblock activities
* convert remaining activity receivers
* reimplement http signature verification and other checks
* also use actor type for routing, VerifyActivity and SendActivity traits
* cleanup and restructure apub_receive code
* wip: try to fix activity routing
* implement a (very bad) derive macro for activityhandler
* working activity routing!
* rework pm verify(), fix tests and confirm manually
also remove inbox username check which was broken
* rework following verify(), fix tests and test manually
* fix post/comment create/update, rework voting
* Rewrite remove/delete post/comment, fix tests, test manually
* Rework and fix (un)block user, announce, update post
* some code cleanup
* rework delete/remove activity receivers (still quite messy)
* rewrite, test and fix add/remove mod, update community handlers
* add docs for ActivityHandler derive macro
* dont try to compile macro comments
2021-07-17 16:08:46 +00:00
|
|
|
}
|
|
|
|
}
|
2022-11-12 13:52:57 +00:00
|
|
|
|
|
|
|
impl Id for RawAnnouncableActivities {
|
|
|
|
fn object_id(&self) -> &Url {
|
|
|
|
ActivityHandler::id(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryFrom<RawAnnouncableActivities> for AnnouncableActivities {
|
|
|
|
type Error = serde_json::error::Error;
|
|
|
|
|
|
|
|
fn try_from(value: RawAnnouncableActivities) -> Result<Self, Self::Error> {
|
|
|
|
let mut map = value.other.clone();
|
|
|
|
map.insert("id".to_string(), Value::String(value.id.to_string()));
|
|
|
|
map.insert("actor".to_string(), Value::String(value.actor.to_string()));
|
|
|
|
serde_json::from_value(Value::Object(map))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryFrom<AnnouncableActivities> for RawAnnouncableActivities {
|
|
|
|
type Error = serde_json::error::Error;
|
|
|
|
|
|
|
|
fn try_from(value: AnnouncableActivities) -> Result<Self, Self::Error> {
|
|
|
|
serde_json::from_value(serde_json::to_value(value)?)
|
|
|
|
}
|
|
|
|
}
|