summaryrefslogtreecommitdiffstats
path: root/activities/templatetags
diff options
context:
space:
mode:
Diffstat (limited to 'activities/templatetags')
-rw-r--r--activities/templatetags/emoji_tags.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/activities/templatetags/emoji_tags.py b/activities/templatetags/emoji_tags.py
new file mode 100644
index 0000000..ad221db
--- /dev/null
+++ b/activities/templatetags/emoji_tags.py
@@ -0,0 +1,27 @@
+from cachetools import TTLCache, cached
+from django import template
+
+from activities.models import Emoji
+from users.models import Domain
+
+register = template.Library()
+
+
+@cached(cache=TTLCache(maxsize=1000, ttl=60))
+def emoji_from_domain(domain: Domain | None) -> list[Emoji]:
+ if not domain:
+ return list(Emoji.locals.values())
+ return list(Emoji.objects.usable(domain))
+
+
+@register.filter
+def imageify_emojis(value: str, arg: Domain | None = None):
+ """
+ Convert hashtags in content in to /tags/<hashtag>/ links.
+ """
+ if not value:
+ return ""
+
+ emojis = emoji_from_domain(arg)
+
+ return Emoji.imageify_emojis(value, emojis=emojis)