From: Nutomic Date: Wed, 27 Apr 2022 16:12:13 +0000 (+0200) Subject: Accept comments with hashtags from Friendica (#2236) X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%7B?a=commitdiff_plain;h=c71888247948a69fc7a772ca397603d0b44e5222;p=lemmy.git Accept comments with hashtags from Friendica (#2236) --- diff --git a/crates/apub/assets/friendica/objects/note.json b/crates/apub/assets/friendica/objects/note_1.json similarity index 100% rename from crates/apub/assets/friendica/objects/note.json rename to crates/apub/assets/friendica/objects/note_1.json diff --git a/crates/apub/assets/friendica/objects/note_2.json b/crates/apub/assets/friendica/objects/note_2.json new file mode 100644 index 00000000..4a86cdfe --- /dev/null +++ b/crates/apub/assets/friendica/objects/note_2.json @@ -0,0 +1,70 @@ +{ + "@context": [ + "https://www.w3.org/ns/activitystreams", + "https://w3id.org/security/v1", + { + "vcard": "http://www.w3.org/2006/vcard/ns#", + "dfrn": "http://purl.org/macgirvin/dfrn/1.0/", + "diaspora": "https://diasporafoundation.org/ns/", + "litepub": "http://litepub.social/ns#", + "toot": "http://joinmastodon.org/ns#", + "schema": "http://schema.org#", + "manuallyApprovesFollowers": "as:manuallyApprovesFollowers", + "sensitive": "as:sensitive", + "Hashtag": "as:Hashtag", + "directMessage": "litepub:directMessage", + "discoverable": "toot:discoverable", + "PropertyValue": "schema:PropertyValue", + "value": "schema:value" + } + ], + "id": "https://nerdica.net/objects/a85d7459-7262-66e9-f901-f05552414769", + "type": "Note", + "summary": "", + "inReplyTo": "https://lemmy.ml/comment/167904", + "diaspora:guid": "a85d7459-7262-66e9-f901-f05552414769", + "published": "2022-04-25T18:35:37Z", + "url": "https://nerdica.net/display/a85d7459-7262-66e9-f901-f05552414769", + "attributedTo": "https://nerdica.net/profile/liwott", + "sensitive": false, + "context": "https://lemmy.ml/post/243881#context", + "content": "Note that on #Friendica we canquote-share, and we can also do it in comments. As I discovered recently by playing in the below post
♲ @Liwott@lemmy.ml:

Do your commenting tests here.


While posting tests can obsviously be made on this community without further precision, commenting requires a post to comment on. This is what this post is for.
\nthese make it through to #Lemmy when we do it in a comment, but not in a top-level post (which is already a great start !). So, in Friendica, all that's missing is the backlink !
Also the Linked Data nature of the underlying data would make it possible to create all different kinds of associations, not just a plain cross-ref link.
This seems interesting, but I must say I don't directly see an application of this in the context of microblogging/commenting. Maybe you can inspire us here? 😀", + "contentMap": { + "en": "Note that on #Friendica we can quote-share, and we can also do it in comments. As I discovered recently by playing in the below post
\n
\n\t
\n\t\t\t\t\t\n\t\t\t\t\"\"\n\t\t\t\n\t\t\t\t
\n\t\t\t

\n\t\t\t\t\n\t\t\t\t\tLiwott\n\t\t\t\t\n\t\t\t

\n\t\t\t

\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t2022-04-23 14:34:19\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t

\n\t\t
\n\t\t
\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t
\n\t
\n\t

Do your commenting tests here.


While posting tests can obsviously be made on this community without further precision, commenting requires a post to comment on. This is what this post is for.
\n
\nthese make it through to #Lemmy when we do it in a comment, but not in a top-level post (which is already a great start !). So, in Friendica, all that's missing is the backlink !
Also the Linked Data nature of the underlying data would make it possible to createall different kinds of associations, not just a plain cross-ref link.
This seems interesting, but I must say I don't directly see an application of this in the context of microblogging/commenting. Maybe you can inspire us here? 😀" + }, + "source": { + "content": "Note that on #[url=https://nerdica.net/search?tag=Friendica]Friendica[/url] we can quote-share, and we can also do it in comments. As I discovered recently by playing in the below post\n[share author='Liwott' profile='https://lemmy.ml/u/Liwott' avatar='' link='https://lemmy.ml/post/241819' posted='2022-04-23 14:34:19' guid='44b525e5-4101b003e005e70a-d472d963'][h3]Do your commenting tests here.[/h3]\nWhile posting tests can obsviously bemade on this community without further precision, commenting requires a post to comment on. This is what this post is for.[/share]\nthese make it through to #[url=https://nerdica.net/search?tag=Lemmy]Lemmy[/url] when we do it in a comment, but not in a top-level post (which is already a great start !).So, in Friendica, all that's missing is the backlink !\n[quote]Also the Linked Data nature of the underlying data would make it possible to create all different kinds of associations, not just a plain cross-ref link.[/quote]\nThis seems interesting, but I must say I don't directly see an application ofthis in the context of microblogging/commenting. Maybe you can inspire us here? :)", + "mediaType": "text/bbcode" + }, + "diaspora:comment": "{\"author\":\"liwott@nerdica.net\",\"guid\":\"a85d7459-7262-66e9-f901-f05552414769\",\"created_at\":\"2022-04-25T18:35:37Z\",\"edited_at\":\"2022-04-25T18:35:37Z\",\"parent_guid\":\"44b525e5-532e8d03ea8f5dff-c45ad734\",\"text\":\"Note that on #Friendica we can quote-share, and we can also do it in comments. As I discovered recently by playing in the below post\\n\\n- - - - - -\\n\\n**\\u2672 [Liwott](https:\\/\\/lemmy.ml\\/u\\/Liwott)** - [2022-04-23 14:34:19 GMT](https:\\/\\/lemmy.ml\\/post\\/241819)\\n\\n> ### Do your commenting tests here.\\n> \\n> \\n> While posting tests can obsviously be made on this community without further precision, commenting requires a post to comment on. This is what this post is for.\\n\\nthese make it through to #Lemmy when we do it in a comment, but not in a top-level post (which is already a great start !). So, in Friendica, all that's missingis the backlink !> Also the Linked Data nature of the underlying data would make it possible to create all different kinds of associations, not just a plain cross-ref link.\\n\\nThis seems interesting, but I must say I don't directly see an application of this in the context of microblogging\\/commenting. Maybe you can inspire us here? \\ud83d\\ude00\",\"author_signature\":\"Ho9NYtWzEkREWyvyjUnUOuYvPBI35I4SGAb+cXBMp\\/n2Tu5gJipmKuIcMpyrxYNtIqXRwr\\/BUOGkd99s5\\/uBWCcL8jCbx3i4wTVYzdgPAZaykd7EqdwULNRTtf8eKL2Wvdo7tYtYm\\/Yo5dajM5HI2NuOgQR8CgLInmEmBlKLZ8EkzAC+z2EwMhx7JBmKzeEabAmclJgR8IfYWX34KPYqBFcZ9w8V\\/D3lcPGs3olJcvwqHSnY7vgL1X9f2XVAQ38pmGg2ggaKhKa5QligOhkPC57NYPh\\/1SR9Plpyf0QPQRCuCs5vkEloe47rxaWZ62gfKqul0dXmGchIcIYhms4DN7DaGapOXaQPuIfh4FIvEb9qh9mJ7haHa9+0uD9TUToG+wilifdtGwZoZnF9zMfGSLiaDlD\\/UZHA1jXMa3uhfGE+MUT1dnJcZqfE+jwJUb4BPuYxTm7UClvERg8sfDFWqlMaNpPtJlay2PL\\/nwCxuQ54M5v6lgyb8NylIrjFyUttiBnNC6HYsy4YoPnN7r\\/0EV3Av1KtnJt84xrJbDo4fvR1TPs4Hmx5BoH1cvHCH2Tld2OgKUCHd5g9Pr3RVPEGGillZSqDWCP6317BQ0EDftTwABjPXoitQX2ZaHXXqXLWCRoLk6MsEWM0jsoGzv+GP4coZWreCD1XRI5an1W4998=\",\"thread_parent_guid\":\"44b525e5-cb6ed8649810a557-1ccd7106\"}", + "attachment": [], + "tag": [ + { + "type": "Hashtag", + "href": "https://nerdica.net/search?tag=Friendica", + "name": "#Friendica" + }, + { + "type": "Hashtag", + "href": "https://nerdica.net/search?tag=Lemmy", + "name": "#Lemmy" + }, + { + "type": "Mention", + "href": "https://lemmy.ml/u/Liwott", + "name": "@Liwott@lemmy.ml" + } + ], + "to": [ + "https://lemmy.ml/u/humanetech", + "https://www.w3.org/ns/activitystreams#Public", + "https://lemmy.ml/c/fediversefutures" + ], + "cc": [ + "https://lemmy.ml/u/Liwott", + "https://nerdica.net/followers/liwott", + "https://lemmy.ml/u/poVoq", + "https://mastodon.social/users/humanetech", + "https://lemmy.ml/u/KelsonV" + ] +} \ No newline at end of file diff --git a/crates/apub/src/activities/create_or_update/comment.rs b/crates/apub/src/activities/create_or_update/comment.rs index 603a19a9..ed95b931 100644 --- a/crates/apub/src/activities/create_or_update/comment.rs +++ b/crates/apub/src/activities/create_or_update/comment.rs @@ -9,6 +9,7 @@ use crate::{ verify_person_in_community, }, activity_lists::AnnouncableActivities, + mentions::MentionOrValue, objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson}, protocol::activities::{create_or_update::comment::CreateOrUpdateComment, CreateOrUpdateType}, }; @@ -70,6 +71,13 @@ impl CreateOrUpdateComment { let tagged_users: Vec> = create_or_update .tag .iter() + .filter_map(|t| { + if let MentionOrValue::Mention(t) = t { + Some(t) + } else { + None + } + }) .map(|t| t.href.clone()) .map(ObjectId::new) .collect(); diff --git a/crates/apub/src/mentions.rs b/crates/apub/src/mentions.rs index 5912d808..78d568e5 100644 --- a/crates/apub/src/mentions.rs +++ b/crates/apub/src/mentions.rs @@ -16,8 +16,16 @@ use lemmy_utils::{ }; use lemmy_websocket::LemmyContext; use serde::{Deserialize, Serialize}; +use serde_json::Value; use url::Url; +#[derive(Clone, Debug, Deserialize, Serialize)] +#[serde(untagged)] +pub enum MentionOrValue { + Mention(Mention), + Value(Value), +} + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Mention { pub href: Url, @@ -28,7 +36,7 @@ pub struct Mention { pub struct MentionsAndAddresses { pub ccs: Vec, - pub tags: Vec, + pub tags: Vec, } /// This takes a comment, and builds a list of to_addresses, inboxes, @@ -81,6 +89,7 @@ pub async fn collect_non_local_mentions( } } + let tags = tags.into_iter().map(MentionOrValue::Mention).collect(); Ok(MentionsAndAddresses { ccs: addressed_ccs, tags, diff --git a/crates/apub/src/protocol/activities/create_or_update/comment.rs b/crates/apub/src/protocol/activities/create_or_update/comment.rs index d63aabf8..cf0697b1 100644 --- a/crates/apub/src/protocol/activities/create_or_update/comment.rs +++ b/crates/apub/src/protocol/activities/create_or_update/comment.rs @@ -1,5 +1,5 @@ use crate::{ - mentions::Mention, + mentions::MentionOrValue, objects::person::ApubPerson, protocol::{activities::CreateOrUpdateType, objects::note::Note, Unparsed}, }; @@ -17,7 +17,7 @@ pub struct CreateOrUpdateComment { #[serde(deserialize_with = "crate::deserialize_one_or_many")] pub(crate) cc: Vec, #[serde(default)] - pub(crate) tag: Vec, + pub(crate) tag: Vec, #[serde(rename = "type")] pub(crate) kind: CreateOrUpdateType, pub(crate) id: Url, diff --git a/crates/apub/src/protocol/objects/mod.rs b/crates/apub/src/protocol/objects/mod.rs index d61bf13c..864c13d9 100644 --- a/crates/apub/src/protocol/objects/mod.rs +++ b/crates/apub/src/protocol/objects/mod.rs @@ -75,7 +75,8 @@ mod tests { test_json::("assets/friendica/objects/person_2.json").unwrap(); test_json::("assets/friendica/objects/page_1.json").unwrap(); test_json::("assets/friendica/objects/page_2.json").unwrap(); - test_json::("assets/friendica/objects/note.json").unwrap(); + test_json::("assets/friendica/objects/note_1.json").unwrap(); + test_json::("assets/friendica/objects/note_2.json").unwrap(); } #[test] diff --git a/crates/apub/src/protocol/objects/note.rs b/crates/apub/src/protocol/objects/note.rs index dc7b99b8..b1c4b5d0 100644 --- a/crates/apub/src/protocol/objects/note.rs +++ b/crates/apub/src/protocol/objects/note.rs @@ -1,6 +1,6 @@ use crate::{ fetcher::post_or_comment::PostOrComment, - mentions::Mention, + mentions::MentionOrValue, objects::{comment::ApubComment, person::ApubPerson, post::ApubPost}, protocol::Source, }; @@ -38,7 +38,7 @@ pub struct Note { pub(crate) published: Option>, pub(crate) updated: Option>, #[serde(default)] - pub(crate) tag: Vec, + pub(crate) tag: Vec, } impl Note {