From 64cea557bebdb0a5b4f17362d8e66845b0a77113 Mon Sep 17 00:00:00 2001
From: Michael Manfre
Date: Mon, 5 Dec 2022 23:44:26 -0500
Subject: Collapse linkify mentions (#123)

---
 activities/models/post.py | 6 ++++++
 1 file changed, 6 insertions(+)

(limited to 'activities')

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()
-- 
cgit v1.2.3