diff options
author | Michael Manfre | 2022-12-05 23:44:26 -0500 |
---|---|---|
committer | GitHub | 2022-12-05 21:44:26 -0700 |
commit | 64cea557bebdb0a5b4f17362d8e66845b0a77113 (patch) | |
tree | 7f5ff24cfa18f3aebf8c8ef91b79465363953be1 /activities/models | |
parent | 5b82c76defd8016df137087e5ce55b44cf017399 (diff) | |
download | takahe-64cea557bebdb0a5b4f17362d8e66845b0a77113.tar.gz takahe-64cea557bebdb0a5b4f17362d8e66845b0a77113.tar.bz2 takahe-64cea557bebdb0a5b4f17362d8e66845b0a77113.zip |
Collapse linkify mentions (#123)
Diffstat (limited to 'activities/models')
-rw-r--r-- | activities/models/post.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/activities/models/post.py b/activities/models/post.py index daf61e8..55d2f65 100644 --- a/activities/models/post.py +++ b/activities/models/post.py @@ -276,6 +276,8 @@ class Post(StatorModel): possible_matches[mention.username] = url possible_matches[f"{mention.username}@{mention.domain_id}"] = url + collapse_name: dict[str, str] = {} + def replacer(match): precursor = match.group(1) handle = match.group(2).lower() @@ -284,6 +286,10 @@ class Post(StatorModel): else: short_handle = handle if handle in possible_matches: + if short_handle not in collapse_name: + collapse_name[short_handle] = handle + elif collapse_name.get(short_handle) != handle: + short_handle = handle return f'{precursor}<a href="{possible_matches[handle]}">@{short_handle}</a>' else: return match.group() |