diff --git a/env b/env index 5932616c2..37e8d612f 100644 --- a/env +++ b/env @@ -33,6 +33,7 @@ DEBIAN_FRONTEND=noninteractive MENTION_LIMIT=100 MULTIMEDIA_EMBEDDING_ENABLED=False RESULTS_PER_PAGE_COMMENTS=200 +SCORE_HIDING_TIME_HOURS=24 # Profiling system; uncomment to enable # Stores and exposes sensitive data! diff --git a/files/__main__.py b/files/__main__.py index f575f263a..2523be385 100644 --- a/files/__main__.py +++ b/files/__main__.py @@ -79,6 +79,7 @@ app.config['SQLALCHEMY_DATABASE_URI'] = app.config['DATABASE_URL'] app.config['MENTION_LIMIT'] = int(environ.get('MENTION_LIMIT', 100)) app.config['MULTIMEDIA_EMBEDDING_ENABLED'] = environ.get('MULTIMEDIA_EMBEDDING_ENABLED', "false").lower() == "true" app.config['RESULTS_PER_PAGE_COMMENTS'] = int(environ.get('RESULTS_PER_PAGE_COMMENTS',50)) +app.config['SCORE_HIDING_TIME_HOURS'] = int(environ.get('SCORE_HIDING_TIME_HOURS')) r=redis.Redis(host=environ.get("REDIS_URL", "redis://localhost"), decode_responses=True, ssl_cert_reqs=None) diff --git a/files/classes/comment.py b/files/classes/comment.py index a4c50077b..cb39a4b20 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -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"" + @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 diff --git a/files/classes/submission.py b/files/classes/submission.py index c4fddcead..48583f545 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -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"" + @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): diff --git a/files/templates/comments.html b/files/templates/comments.html index 83f177459..295c63ebb 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -46,9 +46,16 @@ {# this is distinct from "comment.level", which is the global depth of this comment #} {% macro single_comment(c, level) %} -{% set ups=c.upvotes %} -{% set downs=c.downvotes %} -{% set score=ups-downs %} + +{% if c.should_hide_score %} + {% set ups="?" %} + {% set downs="?" %} + {% set score="?" %} +{% else %} + {% set ups=c.upvotes %} + {% set downs=c.downvotes %} + {% set score=c.score %} +{% endif %} {% if v and (v.shadowbanned or v.admin_level > 1) %} {% set replies=c.replies_ignoring_shadowbans %} @@ -108,8 +115,6 @@ {% else %} -{% set score=c.score %} - {% if v %} {% set voted=c.voted %} {% if not voted and v.id == c.author_id %} @@ -301,7 +306,7 @@ Save Edit diff --git a/files/templates/submission.html b/files/templates/submission.html index 2bdc5e95f..1b2f7d184 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -1,9 +1,15 @@ {% extends "default.html" %} -{% set ups=p.upvotes %} -{% set downs=p.downvotes %} -{% set score=ups-downs %} +{% if p.should_hide_score %} + {% set ups="?" %} + {% set downs="?" %} + {% set score="?" %} +{% else %} + {% set ups=p.upvotes %} + {% set downs=p.downvotes %} + {% set score=p.score %} +{% endif %} {% if v %} {% set voted=p.voted if p.voted else 0 %} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 909ed853f..ab279c381 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -47,9 +47,15 @@ {% for p in listing %}
- {% set ups=p.upvotes %} - {% set downs=p.downvotes %} - {% set score=ups-downs %} + {% if p.should_hide_score %} + {% set ups="?" %} + {% set downs="?" %} + {% set score="?" %} + {% else %} + {% set ups=p.upvotes %} + {% set downs=p.downvotes %} + {% set score=p.score %} + {% endif %} {% if v %} {% set voted= p.voted %}