Hide votes for posts and comments under 24 hours old
This commit is contained in:
parent
120e299f46
commit
4e2047624b
7 changed files with 53 additions and 17 deletions
1
env
1
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!
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -46,9 +46,16 @@
|
|||
{# this is distinct from "comment.level", which is the global depth of this comment #}
|
||||
{% macro single_comment(c, level) %}
|
||||
|
||||
|
||||
{% if c.should_hide_score %}
|
||||
{% set ups="?" %}
|
||||
{% set downs="?" %}
|
||||
{% set score="?" %}
|
||||
{% else %}
|
||||
{% set ups=c.upvotes %}
|
||||
{% set downs=c.downvotes %}
|
||||
{% set score=ups-downs %}
|
||||
{% 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 @@
|
|||
|
||||
<label class="btn btn-secondary format m-0" for="file-edit-reply-{{c.id}}">
|
||||
<div id="filename-edit-reply-{{c.id}}"><i class="far fa-image"></i></div>
|
||||
<input autocomplete="off" id="file-edit-reply-{{c.id}}" type="file" multiple="multiple" name="file" accept="image/*, video/*" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-edit-reply-{{c.id}}','file-edit-reply-{{c.id}}')" hidden>
|
||||
<input autocomplete="off" id="file-edit-reply-{{c.id}}" type="file" multiple="multiple" name="file" accept="image\/*, video\/*" {% if request.headers.get('cf-ipcountry')=="T1" %}disabled{% endif %} onchange="changename('filename-edit-reply-{{c.id}}','file-edit-reply-{{c.id}}')" hidden>
|
||||
</label>
|
||||
</div>
|
||||
<a id="edit-btn-{{c.id}}" role="button" form="comment-edit-form-{{c.id}}" class="btn btn-primary ml-2 fl-r commentmob" onclick="comment_edit('{{c.id}}')">Save Edit</a>
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
{% extends "default.html" %}
|
||||
|
||||
|
||||
{% if p.should_hide_score %}
|
||||
{% set ups="?" %}
|
||||
{% set downs="?" %}
|
||||
{% set score="?" %}
|
||||
{% else %}
|
||||
{% set ups=p.upvotes %}
|
||||
{% set downs=p.downvotes %}
|
||||
{% set score=ups-downs %}
|
||||
{% set score=p.score %}
|
||||
{% endif %}
|
||||
|
||||
{% if v %}
|
||||
{% set voted=p.voted if p.voted else 0 %}
|
||||
|
|
|
@ -47,9 +47,15 @@
|
|||
{% for p in listing %}
|
||||
<div class="card-container">
|
||||
|
||||
{% if p.should_hide_score %}
|
||||
{% set ups="?" %}
|
||||
{% set downs="?" %}
|
||||
{% set score="?" %}
|
||||
{% else %}
|
||||
{% set ups=p.upvotes %}
|
||||
{% set downs=p.downvotes %}
|
||||
{% set score=ups-downs %}
|
||||
{% set score=p.score %}
|
||||
{% endif %}
|
||||
|
||||
{% if v %}
|
||||
{% set voted= p.voted %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue