From db0b545f244db661a93d4fd1f141e5ec66a0d2d9 Mon Sep 17 00:00:00 2001 From: Alain St-Denis Date: Tue, 21 Feb 2023 10:03:25 -0500 Subject: [PATCH] Try matching against Hashtag objects href property in remove_tag_links. --- federation/entities/activitypub/models.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/federation/entities/activitypub/models.py b/federation/entities/activitypub/models.py index 61adea4..dcdf2ac 100644 --- a/federation/entities/activitypub/models.py +++ b/federation/entities/activitypub/models.py @@ -821,10 +821,17 @@ class Note(Object, RawContentMixin): """ super().post_receive() - if getattr(self, 'target_id'): self.entity_type = 'Comment' + if not self.raw_content or self._media_type == "text/markdown": + # Skip when markdown + return + hrefs = [tag.href.lower() for tag in self.tag_objects] # noinspection PyUnusedLocal def remove_tag_links(attrs, new=False): + # Hashtag object hrefs + href = (None, "href") + if attrs.get(href, "").lower() in hrefs: + return # Mastodon rel = (None, "rel") @@ -832,16 +839,11 @@ class Note(Object, RawContentMixin): return # Friendica - href = (None, "href") - if attrs.get(href).endswith(f'tag={attrs.get("_text")}'): + if attrs.get(href, "").endswith(f'tag={attrs.get("_text")}'): return return attrs - if not self.raw_content or self._media_type == "text/markdown": - # Skip when markdown - return - self.raw_content = bleach.linkify( self.raw_content, callbacks=[remove_tag_links], @@ -849,6 +851,8 @@ class Note(Object, RawContentMixin): skip_tags=["code", "pre"], ) + if getattr(self, 'target_id'): self.entity_type = 'Comment' + def add_tag_objects(self) -> None: """ Populate tags to the object.tag list.