From aeb34199f509d6c5f24f495cb5515677ac1ddffd Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 18 Nov 2021 16:20:35 +0100 Subject: [PATCH] Dont announce comments, edited posts to Pleroma/Mastodon followers --- .../apub/src/activities/community/announce.rs | 10 ++++------ crates/apub/src/activity_lists.rs | 5 +---- crates/apub/src/protocol/activities/mod.rs | 2 +- crates/apub/src/protocol/objects/note.rs | 20 +------------------ 4 files changed, 7 insertions(+), 30 deletions(-) diff --git a/crates/apub/src/activities/community/announce.rs b/crates/apub/src/activities/community/announce.rs index 4eebcce38..7db646bb2 100644 --- a/crates/apub/src/activities/community/announce.rs +++ b/crates/apub/src/activities/community/announce.rs @@ -4,7 +4,7 @@ use crate::{ http::{is_activity_already_known, ActivityCommonFields}, insert_activity, objects::community::ApubCommunity, - protocol::activities::community::announce::AnnounceActivity, + protocol::activities::{community::announce::AnnounceActivity, CreateOrUpdateType}, }; use activitystreams::{activity::kind::AnnounceType, public}; use lemmy_apub_lib::{ @@ -61,13 +61,11 @@ impl AnnounceActivity { ) .await?; - // Pleroma (and likely Mastodon) can't handle activities like Announce/Create/Page. So for - // compatibility to allow them to follow Lemmy communities, 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)?; diff --git a/crates/apub/src/activity_lists.rs b/crates/apub/src/activity_lists.rs index 00d2d439f..d9b976496 100644 --- a/crates/apub/src/activity_lists.rs +++ b/crates/apub/src/activity_lists.rs @@ -26,7 +26,7 @@ use crate::{ }, voting::{undo_vote::UndoVote, vote::Vote}, }, - objects::{note::Note, page::Page}, + objects::page::Page, }, }; use lemmy_apub_lib::traits::ActivityHandler; @@ -84,8 +84,6 @@ pub enum AnnouncableActivities { RemoveMod(RemoveMod), // For compatibility with Pleroma/Mastodon (send only) Page(Page), - // For compatibility with Pleroma/Mastodon (send only) - Note(Note), } #[async_trait::async_trait(?Send)] @@ -109,7 +107,6 @@ impl GetCommunity for AnnouncableActivities { AddMod(a) => a.get_community(context, request_counter).await?, RemoveMod(a) => a.get_community(context, request_counter).await?, Page(_) => unimplemented!(), - Note(_) => unimplemented!(), }; Ok(community) } diff --git a/crates/apub/src/protocol/activities/mod.rs b/crates/apub/src/protocol/activities/mod.rs index 23575c279..63bd7656b 100644 --- a/crates/apub/src/protocol/activities/mod.rs +++ b/crates/apub/src/protocol/activities/mod.rs @@ -8,7 +8,7 @@ pub mod following; pub mod private_message; pub mod voting; -#[derive(Clone, Debug, ToString, Deserialize, Serialize)] +#[derive(Clone, Debug, ToString, Deserialize, Serialize, PartialEq)] pub enum CreateOrUpdateType { Create, Update, diff --git a/crates/apub/src/protocol/objects/note.rs b/crates/apub/src/protocol/objects/note.rs index fdd6ddd96..883a1a994 100644 --- a/crates/apub/src/protocol/objects/note.rs +++ b/crates/apub/src/protocol/objects/note.rs @@ -4,15 +4,9 @@ use crate::{ protocol::Source, }; use activitystreams::{link::Mention, object::kind::NoteType, unparsed::Unparsed}; -use anyhow::anyhow; use chrono::{DateTime, FixedOffset}; use lemmy_api_common::blocking; -use lemmy_apub_lib::{ - data::Data, - object_id::ObjectId, - traits::ActivityHandler, - values::MediaTypeHtml, -}; +use lemmy_apub_lib::{object_id::ObjectId, values::MediaTypeHtml}; use lemmy_db_schema::{newtypes::CommentId, source::post::Post, traits::Crud}; use lemmy_utils::LemmyError; use lemmy_websocket::LemmyContext; @@ -89,15 +83,3 @@ impl Note { } } } - -// For Pleroma/Mastodon compat. Unimplemented because its only used for sending. -#[async_trait::async_trait(?Send)] -impl ActivityHandler for Note { - type DataType = LemmyContext; - async fn verify(&self, _: &Data, _: &mut i32) -> Result<(), LemmyError> { - Err(anyhow!("Announce/Page can only be sent, not received").into()) - } - async fn receive(self, _: &Data, _: &mut i32) -> Result<(), LemmyError> { - unimplemented!() - } -}