Hide votes for posts and comments under 24 hours old

This commit is contained in:
Inire 2022-10-27 21:40:30 +11:00 committed by Ben Rog-Wilhelm
parent 120e299f46
commit 4e2047624b
7 changed files with 53 additions and 17 deletions

View file

@ -5,7 +5,7 @@ from urllib.parse import urlencode, urlparse, parse_qs
from flask import *
from sqlalchemy import *
from sqlalchemy.orm import relationship
from files.__main__ import Base
from files.__main__ import Base, app
from files.classes.votes import CommentVote
from files.helpers.const import *
from files.helpers.lazy import lazy
@ -73,6 +73,13 @@ class Comment(Base):
return f"<Comment(id={self.id})>"
@property
@lazy
def should_hide_score(self):
comment_age_seconds = int(time.time()) - self.created_utc
comment_age_hours = comment_age_seconds / (60*60)
return comment_age_hours < app.config['SCORE_HIDING_TIME_HOURS']
@property
@lazy
def top_comment(self):
@ -103,9 +110,12 @@ class Comment(Base):
def age_string(self):
notif_utc = self.__dict__.get("notif_utc")
if notif_utc: timestamp = notif_utc
elif self.created_utc: timestamp = self.created_utc
else: return None
if notif_utc:
timestamp = notif_utc
elif self.created_utc:
timestamp = self.created_utc
else:
return None
age = int(time.time()) - timestamp

View file

@ -6,7 +6,7 @@ from urllib.parse import urlparse
from flask import render_template
from sqlalchemy import *
from sqlalchemy.orm import relationship, deferred
from files.__main__ import Base
from files.__main__ import Base, app
from files.helpers.const import *
from files.helpers.lazy import lazy
from files.helpers.assetcache import assetcache_path
@ -84,6 +84,13 @@ class Submission(Base):
def __repr__(self):
return f"<Submission(id={self.id})>"
@property
@lazy
def should_hide_score(self):
submission_age_seconds = int(time.time()) - self.created_utc
submission_age_hours = submission_age_seconds / (60*60)
return submission_age_hours < app.config['SCORE_HIDING_TIME_HOURS']
@property
@lazy
def controversial(self):