summaryrefslogtreecommitdiffstats
path: root/activities
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-28 22:14:52 -0700
committerAndrew Godwin2022-11-28 22:14:52 -0700
commit0bced8fe174de24ebd3823c93997cb2d2347dfe9 (patch)
treeddc86664e442810b37dcb4835fa17ed0a139a9c3 /activities
parent1ad9bfcb06aec3678c345fd97103f2c73396cd44 (diff)
downloadtakahe-0bced8fe174de24ebd3823c93997cb2d2347dfe9.tar.gz
takahe-0bced8fe174de24ebd3823c93997cb2d2347dfe9.tar.bz2
takahe-0bced8fe174de24ebd3823c93997cb2d2347dfe9.zip
A few hashtag fixups
Diffstat (limited to 'activities')
-rw-r--r--activities/models/hashtag.py3
-rw-r--r--activities/models/post.py14
-rw-r--r--activities/views/timelines.py2
3 files changed, 17 insertions, 2 deletions
diff --git a/activities/models/hashtag.py b/activities/models/hashtag.py
index a5754f7..7085b15 100644
--- a/activities/models/hashtag.py
+++ b/activities/models/hashtag.py
@@ -8,6 +8,7 @@ from django.db import models
from django.utils import timezone
from django.utils.safestring import mark_safe
+from core.html import strip_html
from core.models import Config
from stator.models import State, StateField, StateGraph, StatorModel
@@ -174,7 +175,7 @@ class Hashtag(StatorModel):
Return a parsed and sanitized of hashtags found in content without
leading '#'.
"""
- hashtag_hits = cls.hashtag_regex.findall(content)
+ hashtag_hits = cls.hashtag_regex.findall(strip_html(content))
hashtags = sorted({tag[1].lower() for tag in hashtag_hits})
return list(hashtags)
diff --git a/activities/models/post.py b/activities/models/post.py
index f3b1879..eecce04 100644
--- a/activities/models/post.py
+++ b/activities/models/post.py
@@ -77,6 +77,17 @@ class PostStates(StateGraph):
class PostQuerySet(models.QuerySet):
+ def public(self, include_replies: bool = False):
+ query = self.filter(
+ visibility__in=[
+ Post.Visibilities.public,
+ Post.Visibilities.local_only,
+ ],
+ )
+ if not include_replies:
+ return query.filter(in_reply_to__isnull=True)
+ return query
+
def local_public(self, include_replies: bool = False):
query = self.filter(
visibility__in=[
@@ -104,6 +115,9 @@ class PostManager(models.Manager):
def get_queryset(self):
return PostQuerySet(self.model, using=self._db)
+ def public(self, include_replies: bool = False):
+ return self.get_queryset().public(include_replies=include_replies)
+
def local_public(self, include_replies: bool = False):
return self.get_queryset().local_public(include_replies=include_replies)
diff --git a/activities/views/timelines.py b/activities/views/timelines.py
index ffe329c..694039e 100644
--- a/activities/views/timelines.py
+++ b/activities/views/timelines.py
@@ -80,7 +80,7 @@ class Tag(ListView):
def get_queryset(self):
return (
- Post.objects.local_public()
+ Post.objects.public()
.tagged_with(self.hashtag)
.select_related("author")
.prefetch_related("attachments")