diff options
author | Michael Manfre | 2022-12-15 02:50:54 -0500 |
---|---|---|
committer | GitHub | 2022-12-15 00:50:54 -0700 |
commit | af3142ac3adb0d1f31d160edcb6d076b293020b1 (patch) | |
tree | 73cfd5d447f6444602c2ff401399d567c673949b /activities/templatetags | |
parent | 69f1b3168ac3f29fc4bafba0418769248b10062a (diff) | |
download | takahe-af3142ac3adb0d1f31d160edcb6d076b293020b1.tar.gz takahe-af3142ac3adb0d1f31d160edcb6d076b293020b1.tar.bz2 takahe-af3142ac3adb0d1f31d160edcb6d076b293020b1.zip |
Basic Emoji suppport (#157)
Diffstat (limited to 'activities/templatetags')
-rw-r--r-- | activities/templatetags/emoji_tags.py | 27 |
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) |