Create and Note always need to tag parent creator, for mastodon notifications

asonix/mastodon-compat
Felix Ableitner 2021-11-15 23:54:25 +01:00
parent 12c51ab435
commit 659572e00e
4 changed files with 19 additions and 3 deletions

View File

@ -50,7 +50,7 @@ impl CreateOrUpdateComment {
)?;
let maa = collect_non_local_mentions(&comment, &community, context).await?;
let create_or_update = CreateOrUpdateComment {
let mut create_or_update = CreateOrUpdateComment {
actor: ObjectId::new(actor.actor_id()),
to: vec![public()],
object: comment.into_apub(context).await?,
@ -61,6 +61,11 @@ impl CreateOrUpdateComment {
unparsed: Default::default(),
};
// To make mention notifications work on Mastodon/Pleroma, it is necessary that tag and cc
// are set on both the activity and the object.
create_or_update.object.tag = Some(create_or_update.tag.clone());
create_or_update.object.cc = create_or_update.cc.clone();
let activity = AnnouncableActivities::CreateOrUpdateComment(create_or_update);
send_activity_in_community(activity, &id, actor, &community, maa.inboxes, context).await
}

View File

@ -26,6 +26,7 @@ use crate::{
fetcher::webfinger::WebfingerResponse,
objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson},
};
use lemmy_utils::settings::structs::Settings;
pub mod create_or_update;
@ -68,7 +69,15 @@ pub async fn collect_non_local_mentions(
let mut inboxes = vec![parent_creator.shared_inbox_or_inbox_url()];
// Add the mention tag
let mut tags = Vec::new();
let mut parent_creator_tag = Mention::new();
parent_creator_tag
.set_href(parent_creator.actor_id.clone().into())
.set_name(format!(
"@{}@{}",
&parent_creator.name,
&Settings::get().hostname
));
let mut tags = vec![parent_creator_tag];
// Get the person IDs for any mentions
let mentions = scrape_text_for_mentions(&comment.content)

View File

@ -117,6 +117,7 @@ impl ApubObject for ApubComment {
in_reply_to,
published: Some(convert_datetime(self.published)),
updated: self.updated.map(convert_datetime),
tag: None,
unparsed: Default::default(),
};

View File

@ -3,7 +3,7 @@ use crate::{
objects::{comment::ApubComment, person::ApubPerson, post::ApubPost},
protocol::Source,
};
use activitystreams::{object::kind::NoteType, unparsed::Unparsed};
use activitystreams::{link::Mention, object::kind::NoteType, unparsed::Unparsed};
use anyhow::anyhow;
use chrono::{DateTime, FixedOffset};
use lemmy_api_common::blocking;
@ -38,6 +38,7 @@ pub struct Note {
pub(crate) in_reply_to: ObjectId<PostOrComment>,
pub(crate) published: Option<DateTime<FixedOffset>>,
pub(crate) updated: Option<DateTime<FixedOffset>>,
pub(crate) tag: Option<Vec<Mention>>,
#[serde(flatten)]
pub(crate) unparsed: Unparsed,
}