From bce5e6cdf657b7674e4733e9401d4499992c5ad1 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Sat, 7 May 2022 13:51:03 -0700 Subject: [PATCH] Add sage-like functionality a la 4chan When reply to a post, you can uncheck "bump" and it will not bump the thread to the top of the board. This is useful for the OP, too, because it allows for "permasage" functionality which is useful for moderators. Finally, there is also "autosink" functionality. After a per-board threshhold of posts, a thread will stop bumping. Signed-off-by: Alek Ratzloff --- board/forms.py | 2 +- board/models.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/board/forms.py b/board/forms.py index 1dc56b4..54e94bc 100644 --- a/board/forms.py +++ b/board/forms.py @@ -29,7 +29,7 @@ class ReplyForm(PostForm): class Meta: model = Post - fields = ["name", "text", "image"] + fields = ["name", "text", "bump", "image"] def __init__(self, *args, op, reply, **kwargs): super(ReplyForm, self).__init__(*args, **kwargs) diff --git a/board/models.py b/board/models.py index db589f9..c3286cf 100644 --- a/board/models.py +++ b/board/models.py @@ -47,6 +47,9 @@ class Board(models.Model): # The amount of time that users from the same IP address are allowed to make # consecutive posts post_cooldown = models.DurationField(default=timedelta(seconds=60)) + # Auto-sink threshhold. This is the number of replies that a thread can have + # before it stops being bumped. + autosink = models.IntegerField(default=300) @property def threads(self): @@ -89,6 +92,9 @@ class Post(models.Model): width_field="image_width", height_field="image_height", ) + # Bump - if this post is an OP, determines whether the OP can be bumped. If + # this post is not an OP, determines whether the thread SHOULD be bumped. + bump = models.BooleanField(default=True) # Thumbnail thumbnail = models.ImageField(upload_to=thumbs_upload, editable=False, null=True) # Original image name @@ -172,8 +178,13 @@ def post_created(sender, instance, created, **kwargs): if created: if instance.op: # Update the bump - instance.op.last_bump = timezone.now() - instance.op.save() + if ( + instance.bump + and instance.op.bump + and instance.op.replies.count() < instance.board.autosink + ): + instance.op.last_bump = timezone.now() + instance.op.save() else: # Prune threads for the board instance.board.prune_threads()