From af3142ac3adb0d1f31d160edcb6d076b293020b1 Mon Sep 17 00:00:00 2001 From: Michael Manfre Date: Thu, 15 Dec 2022 02:50:54 -0500 Subject: Basic Emoji suppport (#157) --- activities/templatetags/emoji_tags.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 activities/templatetags/emoji_tags.py (limited to 'activities/templatetags') 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// links. + """ + if not value: + return "" + + emojis = emoji_from_domain(arg) + + return Emoji.imageify_emojis(value, emojis=emojis) -- cgit v1.2.3