use crate::{
activities::{generate_activity_id, send_lemmy_activity, verify_activity, verify_is_public},
activity_lists::AnnouncableActivities,
- http::{is_activity_already_known, ActivityCommonFields},
+ http::ActivityCommonFields,
insert_activity,
objects::community::ApubCommunity,
- protocol::activities::community::announce::AnnounceActivity,
+ protocol::activities::{community::announce::AnnounceActivity, CreateOrUpdateType},
};
-use activitystreams::{activity::kind::AnnounceType, public};
+use activitystreams_kinds::{activity::AnnounceType, public};
use lemmy_apub_lib::{
data::Data,
object_id::ObjectId,
};
use lemmy_utils::LemmyError;
use lemmy_websocket::LemmyContext;
-use url::Url;
#[async_trait::async_trait(?Send)]
pub(crate) trait GetCommunity {
}
impl AnnounceActivity {
- fn new(
+ pub(crate) fn new(
object: AnnouncableActivities,
community: &ApubCommunity,
context: &LemmyContext,
pub async fn send(
object: AnnouncableActivities,
community: &ApubCommunity,
- additional_inboxes: Vec<Url>,
context: &LemmyContext,
) -> Result<(), LemmyError> {
let announce = AnnounceActivity::new(object.clone(), community, context)?;
- let inboxes = community
- .get_follower_inboxes(additional_inboxes.clone(), context)
- .await?;
+ let inboxes = community.get_follower_inboxes(context).await?;
send_lemmy_activity(
context,
&announce,
)
.await?;
- // Pleroma (and likely Mastodon) can't handle activities like Announce/Create/Page, so for
- // compatibility, we also send Announce/Page and Announce/Note (for new and updated
- // posts/comments).
+ // 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.
use AnnouncableActivities::*;
let object = match object {
- CreateOrUpdatePost(c) => Page(c.object),
- CreateOrUpdateComment(c) => Note(c.object),
+ CreateOrUpdatePost(c) if c.kind == CreateOrUpdateType::Create => Page(c.object),
_ => return Ok(()),
};
let announce_compat = AnnounceActivity::new(object, community, context)?;
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)?;
+ // TODO: this can probably be implemented in a cleaner way
+ match self.object {
+ // Dont insert these into activities table, as they are not activities.
+ AnnouncableActivities::Page(_) => {}
+ _ => {
+ 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, object_value, false, true, context.pool()).await?;
+ }
}
- insert_activity(&object_data.id, &self.object, false, true, context.pool()).await?;
self.object.receive(context, request_counter).await
}
}