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.