diff options
author | Andrew Godwin | 2022-12-15 19:26:06 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-12-15 19:26:06 -0700 |
commit | 1bcdff79e7e14b2166056d3b16531b32474c374b (patch) | |
tree | 204b0019035a48b3f847551352df1cfe9e30c0c1 /activities/models | |
parent | e0f1bb629c2899c8450ae9f8190b761dfd501f36 (diff) | |
download | takahe-1bcdff79e7e14b2166056d3b16531b32474c374b.tar.gz takahe-1bcdff79e7e14b2166056d3b16531b32474c374b.tar.bz2 takahe-1bcdff79e7e14b2166056d3b16531b32474c374b.zip |
Fix hashtag linking and API mentions of empty
Diffstat (limited to 'activities/models')
-rw-r--r-- | activities/models/hashtag.py | 9 | ||||
-rw-r--r-- | activities/models/post.py | 9 |
2 files changed, 12 insertions, 6 deletions
diff --git a/activities/models/hashtag.py b/activities/models/hashtag.py index 4e1a735..a850ec3 100644 --- a/activities/models/hashtag.py +++ b/activities/models/hashtag.py @@ -179,10 +179,15 @@ class Hashtag(StatorModel): return list(hashtags) @classmethod - def linkify_hashtags(cls, content) -> str: + def linkify_hashtags(cls, content, domain=None) -> str: def replacer(match): hashtag = match.group(1) - return f'<a class="hashtag" href="/tags/{hashtag.lower()}/">#{hashtag}</a>' + if domain: + return f'<a class="hashtag" href="https://{domain.uri_domain}/tags/{hashtag.lower()}/">#{hashtag}</a>' + else: + return ( + f'<a class="hashtag" href="/tags/{hashtag.lower()}/">#{hashtag}</a>' + ) return mark_safe(Hashtag.hashtag_regex.sub(replacer, content)) diff --git a/activities/models/post.py b/activities/models/post.py index df80457..b5821f7 100644 --- a/activities/models/post.py +++ b/activities/models/post.py @@ -348,7 +348,8 @@ class Post(StatorModel): Returns the content formatted for remote consumption """ return Hashtag.linkify_hashtags( - self.linkify_mentions(sanitize_post(self.content)) + self.linkify_mentions(sanitize_post(self.content)), + domain=self.author.domain, ) def safe_content_plain(self): @@ -835,9 +836,9 @@ class Post(StatorModel): "mentions": [ { "id": mention.id, - "username": mention.username, - "url": mention.absolute_profile_uri(), - "acct": mention.handle, + "username": mention.username or "", + "url": mention.absolute_profile_uri() or "", + "acct": mention.handle or "", } for mention in self.mentions.all() if mention.username |