forked from rDrama/rDrama
add "hot" comment sorting
parent
0ba14cb771
commit
e3a3cbd358
|
@ -121,7 +121,7 @@ class User(Base):
|
||||||
mfa_secret = deferred(Column(String))
|
mfa_secret = deferred(Column(String))
|
||||||
is_private = Column(Boolean, default=False)
|
is_private = Column(Boolean, default=False)
|
||||||
stored_subscriber_count = Column(Integer, default=0)
|
stored_subscriber_count = Column(Integer, default=0)
|
||||||
defaultsortingcomments = Column(String, default="top")
|
defaultsortingcomments = Column(String, default="hot")
|
||||||
defaultsorting = Column(String, default="hot")
|
defaultsorting = Column(String, default="hot")
|
||||||
defaulttime = Column(String, default=DEFAULT_TIME_FILTER)
|
defaulttime = Column(String, default=DEFAULT_TIME_FILTER)
|
||||||
is_nofollow = Column(Boolean, default=False)
|
is_nofollow = Column(Boolean, default=False)
|
||||||
|
|
|
@ -2,6 +2,7 @@ import time
|
||||||
from files.classes.comment import Comment
|
from files.classes.comment import Comment
|
||||||
from files.classes.submission import Submission
|
from files.classes.submission import Submission
|
||||||
from files.helpers.const import *
|
from files.helpers.const import *
|
||||||
|
from sqlalchemy.sql import func
|
||||||
|
|
||||||
def apply_time_filter(t, objects, Class):
|
def apply_time_filter(t, objects, Class):
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
|
@ -21,8 +22,12 @@ def apply_time_filter(t, objects, Class):
|
||||||
return objects.filter(Class.created_utc >= cutoff)
|
return objects.filter(Class.created_utc >= cutoff)
|
||||||
|
|
||||||
def sort_comments(sort, comments):
|
def sort_comments(sort, comments):
|
||||||
|
if sort == 'hot':
|
||||||
if sort == 'new':
|
ti = int(time.time()) + 3600
|
||||||
|
if SITE_NAME == 'rDrama': metric = Comment.realupvotes
|
||||||
|
else: metric = Comment.upvotes - Comment.downvotes
|
||||||
|
return comments.order_by(-1000000*(metric + 1)/(func.power(((ti - Comment.created_utc)/1000), 1.23)), Comment.created_utc.desc())
|
||||||
|
elif sort == 'new':
|
||||||
return comments.order_by(Comment.id.desc())
|
return comments.order_by(Comment.id.desc())
|
||||||
elif sort == 'old':
|
elif sort == 'old':
|
||||||
return comments.order_by(Comment.id)
|
return comments.order_by(Comment.id)
|
||||||
|
@ -30,13 +35,19 @@ def sort_comments(sort, comments):
|
||||||
return comments.order_by((Comment.upvotes+1)/(Comment.downvotes+1) + (Comment.downvotes+1)/(Comment.upvotes+1), Comment.downvotes.desc(), Comment.id.desc())
|
return comments.order_by((Comment.upvotes+1)/(Comment.downvotes+1) + (Comment.downvotes+1)/(Comment.upvotes+1), Comment.downvotes.desc(), Comment.id.desc())
|
||||||
elif sort == "bottom":
|
elif sort == "bottom":
|
||||||
return comments.order_by(Comment.upvotes - Comment.downvotes)
|
return comments.order_by(Comment.upvotes - Comment.downvotes)
|
||||||
elif SITE_NAME == 'rDrama':
|
|
||||||
return comments.order_by(Comment.realupvotes.desc(), Comment.id.desc())
|
|
||||||
else:
|
else:
|
||||||
return comments.order_by(Comment.downvotes - Comment.upvotes, Comment.id.desc())
|
return comments.order_by(Comment.downvotes - Comment.upvotes, Comment.id.desc())
|
||||||
|
|
||||||
def sort_posts(sort, posts):
|
def sort_posts(sort, posts):
|
||||||
if sort == "new":
|
if sort == 'hot':
|
||||||
|
ti = int(time.time()) + 3600
|
||||||
|
if SITE_NAME == 'rDrama':
|
||||||
|
return posts.order_by(-1000000*(Submission.realupvotes + 1 + Submission.comment_count/5)/(func.power(((ti - Submission.created_utc)/1000), 1.23)), Submission.created_utc.desc())
|
||||||
|
else:
|
||||||
|
return posts.order_by(-1000000*(Submission.upvotes - Submission.downvotes + 1)/(func.power(((ti - Submission.created_utc)/1000), 1.23)), Submission.created_utc.desc())
|
||||||
|
elif sort == "bump":
|
||||||
|
return posts.filter(Submission.comment_count > 1).order_by(Submission.bump_utc.desc(), Submission.created_utc.desc())
|
||||||
|
elif sort == "new":
|
||||||
return posts.order_by(Submission.created_utc.desc())
|
return posts.order_by(Submission.created_utc.desc())
|
||||||
elif sort == "old":
|
elif sort == "old":
|
||||||
return posts.order_by(Submission.created_utc)
|
return posts.order_by(Submission.created_utc)
|
||||||
|
|
|
@ -69,7 +69,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None, sub=None):
|
||||||
top_comment = c
|
top_comment = c
|
||||||
|
|
||||||
if v: defaultsortingcomments = v.defaultsortingcomments
|
if v: defaultsortingcomments = v.defaultsortingcomments
|
||||||
else: defaultsortingcomments = "top"
|
else: defaultsortingcomments = "hot"
|
||||||
sort=request.values.get("sort", defaultsortingcomments)
|
sort=request.values.get("sort", defaultsortingcomments)
|
||||||
|
|
||||||
if v:
|
if v:
|
||||||
|
|
|
@ -115,15 +115,6 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, ccmode="false"
|
||||||
if not (v and v.shadowbanned):
|
if not (v and v.shadowbanned):
|
||||||
posts = posts.join(Submission.author).filter(User.shadowbanned == None)
|
posts = posts.join(Submission.author).filter(User.shadowbanned == None)
|
||||||
|
|
||||||
if sort == 'hot':
|
|
||||||
ti = int(time.time()) + 3600
|
|
||||||
if SITE_NAME == 'rDrama':
|
|
||||||
posts = posts.order_by(-1000000*(Submission.realupvotes + 1 + Submission.comment_count/5)/(func.power(((ti - Submission.created_utc)/1000), 1.23)), Submission.created_utc.desc())
|
|
||||||
else:
|
|
||||||
posts = posts.order_by(-1000000*(Submission.upvotes - Submission.downvotes + 1)/(func.power(((ti - Submission.created_utc)/1000), 1.23)), Submission.created_utc.desc())
|
|
||||||
elif sort == "bump":
|
|
||||||
posts = posts.filter(Submission.comment_count > 1).order_by(Submission.bump_utc.desc(), Submission.created_utc.desc())
|
|
||||||
else:
|
|
||||||
posts = sort_posts(sort, posts)
|
posts = sort_posts(sort, posts)
|
||||||
|
|
||||||
if v: size = v.frontsize or 0
|
if v: size = v.frontsize or 0
|
||||||
|
|
|
@ -148,7 +148,7 @@ def post_id(pid, anything=None, v=None, sub=None):
|
||||||
|
|
||||||
if post.new or 'megathread' in post.title.lower(): defaultsortingcomments = 'new'
|
if post.new or 'megathread' in post.title.lower(): defaultsortingcomments = 'new'
|
||||||
elif v: defaultsortingcomments = v.defaultsortingcomments
|
elif v: defaultsortingcomments = v.defaultsortingcomments
|
||||||
else: defaultsortingcomments = "top"
|
else: defaultsortingcomments = "hot"
|
||||||
sort = request.values.get("sort", defaultsortingcomments)
|
sort = request.values.get("sort", defaultsortingcomments)
|
||||||
|
|
||||||
if post.club and not (v and (v.paid_dues or v.id == post.author_id)): abort(403)
|
if post.club and not (v and (v.paid_dues or v.id == post.author_id)): abort(403)
|
||||||
|
|
|
@ -240,7 +240,7 @@ def settings_profile_post(v):
|
||||||
|
|
||||||
defaultsortingcomments = request.values.get("defaultsortingcomments")
|
defaultsortingcomments = request.values.get("defaultsortingcomments")
|
||||||
if defaultsortingcomments:
|
if defaultsortingcomments:
|
||||||
if defaultsortingcomments in {"new", "old", "controversial", "top", "bottom"}:
|
if defaultsortingcomments in {"new", "old", "controversial", "top", "hot", "bottom"}:
|
||||||
v.defaultsortingcomments = defaultsortingcomments
|
v.defaultsortingcomments = defaultsortingcomments
|
||||||
updated = True
|
updated = True
|
||||||
else: abort(400)
|
else: abort(400)
|
||||||
|
|
|
@ -71,7 +71,7 @@
|
||||||
<p>Change the default sorting for comments.</p>
|
<p>Change the default sorting for comments.</p>
|
||||||
<div class="input-group mb2">
|
<div class="input-group mb2">
|
||||||
<select autocomplete="off" id='defaultsortingcomments' class="form-control" form="profile-settings" name="defaultsortingcomments" onchange="post_toast(this,'/settings/profile?defaultsortingcomments='+document.getElementById('defaultsortingcomments').value)">
|
<select autocomplete="off" id='defaultsortingcomments' class="form-control" form="profile-settings" name="defaultsortingcomments" onchange="post_toast(this,'/settings/profile?defaultsortingcomments='+document.getElementById('defaultsortingcomments').value)">
|
||||||
{% for entry in ["new", "old", "top", "bottom", "controversial"] %}
|
{% for entry in ["new", "old", "top", "hot", "bottom", "controversial"] %}
|
||||||
<option value="{{entry}}"{{' selected' if v.defaultsortingcomments==entry}}>{{entry}}</option>
|
<option value="{{entry}}"{{' selected' if v.defaultsortingcomments==entry}}>{{entry}}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
|
|
|
@ -952,6 +952,7 @@
|
||||||
<div class="comments-count py-3">
|
<div class="comments-count py-3">
|
||||||
<div class="dropdown dropdown-actions">
|
<div class="dropdown dropdown-actions">
|
||||||
<button class="btn btn-secondary dropdown-toggle" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
<button class="btn btn-secondary dropdown-toggle" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
{% if sort=="hot" %}<i class="fas fa-fire mr-1"></i>{% endif %}
|
||||||
{% if sort=="top" %}<i class="fas fa-arrow-alt-circle-up mr-1"></i>{% endif %}
|
{% if sort=="top" %}<i class="fas fa-arrow-alt-circle-up mr-1"></i>{% endif %}
|
||||||
{% if sort=="bottom" %}<i class="fas fa-arrow-alt-circle-down mr-1"></i>{% endif %}
|
{% if sort=="bottom" %}<i class="fas fa-arrow-alt-circle-down mr-1"></i>{% endif %}
|
||||||
{% if sort=="new" %}<i class="fas fa-sparkles mr-1"></i>{% endif %}
|
{% if sort=="new" %}<i class="fas fa-sparkles mr-1"></i>{% endif %}
|
||||||
|
@ -960,6 +961,7 @@
|
||||||
{{sort | capitalize}}
|
{{sort | capitalize}}
|
||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(0px, 31px, 0px);">
|
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px; transform: translate3d(0px, 31px, 0px);">
|
||||||
|
{% if sort != "hot" %}<a class="dropdown-item" href="?sort=hot"><i class="fas fa-fire mr-2"></i>Hot</a>{% endif %}
|
||||||
{% if sort != "top" %}<a class="dropdown-item" href="?sort=top"><i class="fas fa-arrow-alt-circle-up mr-2"></i>Top</a>{% endif %}
|
{% if sort != "top" %}<a class="dropdown-item" href="?sort=top"><i class="fas fa-arrow-alt-circle-up mr-2"></i>Top</a>{% endif %}
|
||||||
{% if sort != "bottom" %}<a class="dropdown-item" href="?sort=bottom"><i class="fas fa-arrow-alt-circle-down mr-2"></i>Bottom</a>{% endif %}
|
{% if sort != "bottom" %}<a class="dropdown-item" href="?sort=bottom"><i class="fas fa-arrow-alt-circle-down mr-2"></i>Bottom</a>{% endif %}
|
||||||
{% if sort != "new" %}<a class="dropdown-item" href="?sort=new"><i class="fas fa-sparkles mr-2"></i>New</a>{% endif %}
|
{% if sort != "new" %}<a class="dropdown-item" href="?sort=new"><i class="fas fa-sparkles mr-2"></i>New</a>{% endif %}
|
||||||
|
|
|
@ -940,7 +940,7 @@ CREATE TABLE public.users (
|
||||||
stored_subscriber_count integer DEFAULT 0 NOT NULL,
|
stored_subscriber_count integer DEFAULT 0 NOT NULL,
|
||||||
original_username character varying(30),
|
original_username character varying(30),
|
||||||
customtitle character varying(1000),
|
customtitle character varying(1000),
|
||||||
defaultsorting character varying(15) DEFAULT 'hot'::character varying NOT NULL,
|
defaultsorting character varying(15) NOT NULL,
|
||||||
defaulttime character varying(5) NOT NULL,
|
defaulttime character varying(5) NOT NULL,
|
||||||
namecolor character varying(6) NOT NULL,
|
namecolor character varying(6) NOT NULL,
|
||||||
titlecolor character varying(6) NOT NULL,
|
titlecolor character varying(6) NOT NULL,
|
||||||
|
@ -949,7 +949,7 @@ CREATE TABLE public.users (
|
||||||
hidevotedon boolean DEFAULT false NOT NULL,
|
hidevotedon boolean DEFAULT false NOT NULL,
|
||||||
newtab boolean DEFAULT false NOT NULL,
|
newtab boolean DEFAULT false NOT NULL,
|
||||||
flairchanged integer,
|
flairchanged integer,
|
||||||
defaultsortingcomments character varying(15) DEFAULT 'top'::character varying NOT NULL,
|
defaultsortingcomments character varying(15) NOT NULL,
|
||||||
theme character varying(15) NOT NULL,
|
theme character varying(15) NOT NULL,
|
||||||
song character varying(50),
|
song character varying(50),
|
||||||
slurreplacer boolean DEFAULT true NOT NULL,
|
slurreplacer boolean DEFAULT true NOT NULL,
|
||||||
|
@ -2679,4 +2679,3 @@ ALTER TABLE ONLY public.comment_option_votes
|
||||||
--
|
--
|
||||||
-- PostgreSQL database dump complete
|
-- PostgreSQL database dump complete
|
||||||
--
|
--
|
||||||
|
|
||||||
|
|
|
@ -3,19 +3,19 @@ INSERT INTO public.users (username, passhash, created_utc, admin_level, over_18,
|
||||||
customtitleplain, theme, themecolor, reddit, css, profilecss, coins, agendaposter,
|
customtitleplain, theme, themecolor, reddit, css, profilecss, coins, agendaposter,
|
||||||
post_count, comment_count, background, verified, truecoins, cardview, profileurl, highres, last_viewed_post_notifs, last_viewed_log_notifs, pronouns, marsify, house) VALUES
|
post_count, comment_count, background, verified, truecoins, cardview, profileurl, highres, last_viewed_post_notifs, last_viewed_log_notifs, pronouns, marsify, house) VALUES
|
||||||
('AutoJanny', '', extract(epoch from now()), 0, true, true, '', '', 0, false,
|
('AutoJanny', '', extract(epoch from now()), 0, true, true, '', '', 0, false,
|
||||||
0, 'AutoJanny', '', 'hot', 'top', 'day', 'ff66ac', 'ff66ac',
|
0, 'AutoJanny', '', 'hot', 'hot', 'day', 'ff66ac', 'ff66ac',
|
||||||
'', 'dark', 'ff66ac', 'old.reddit.com', '', '', 0, 0,
|
'', 'dark', 'ff66ac', 'old.reddit.com', '', '', 0, 0,
|
||||||
0, 0, '', 'Verified', 0, false, '/i/pfps/1.webp', '/i/pfps/1.webp', 0, 0, 'clean/itup', 0, ''),
|
0, 0, '', 'Verified', 0, false, '/i/pfps/1.webp', '/i/pfps/1.webp', 0, 0, 'clean/itup', 0, ''),
|
||||||
('Snappy', '', extract(epoch from now()), 0, true, true, '', '', 0, false,
|
('Snappy', '', extract(epoch from now()), 0, true, true, '', '', 0, false,
|
||||||
0, 'Snappy', '', 'hot', 'top', 'day', '62ca56', 'e4432d',
|
0, 'Snappy', '', 'hot', 'hot', 'day', '62ca56', 'e4432d',
|
||||||
'', 'dark', '30409f', 'old.reddit.com', '', '', 0, 0,
|
'', 'dark', '30409f', 'old.reddit.com', '', '', 0, 0,
|
||||||
0, 0, '', 'Verified', 0, false, '/i/pfps/2.webp', '/i/pfps/2.webp', 0, 0,'beep/boop', 0, ''),
|
0, 0, '', 'Verified', 0, false, '/i/pfps/2.webp', '/i/pfps/2.webp', 0, 0,'beep/boop', 0, ''),
|
||||||
('longpostbot', '', extract(epoch from now()), 0, true, true, '', '', 0, false,
|
('longpostbot', '', extract(epoch from now()), 0, true, true, '', '', 0, false,
|
||||||
0, 'longpostbot', '', 'hot', 'top', 'day', '62ca56', 'e4432d',
|
0, 'longpostbot', '', 'hot', 'hot', 'day', '62ca56', 'e4432d',
|
||||||
'', 'dark', '30409f', 'old.reddit.com', '', '', 0, 0,
|
'', 'dark', '30409f', 'old.reddit.com', '', '', 0, 0,
|
||||||
0, 0, '', 'Verified', 0, false, '/i/pfps/3.webp', '/i/pfps/3.webp', 0, 0, 'tl/dr', 0, ''),
|
0, 0, '', 'Verified', 0, false, '/i/pfps/3.webp', '/i/pfps/3.webp', 0, 0, 'tl/dr', 0, ''),
|
||||||
('zozbot', '', extract(epoch from now()), 0, true, true, '', '', 0, false,
|
('zozbot', '', extract(epoch from now()), 0, true, true, '', '', 0, false,
|
||||||
0, 'zozbot', '', 'hot', 'top', 'day', '62ca56', 'e4432d',
|
0, 'zozbot', '', 'hot', 'hot', 'day', '62ca56', 'e4432d',
|
||||||
'', 'dark', '30409f', 'old.reddit.com', '', '', 0, 0,
|
'', 'dark', '30409f', 'old.reddit.com', '', '', 0, 0,
|
||||||
0, 0, '', 'Verified', 0, false, '/i/pfps/4.webp', '/i/pfps/4.webp', 0, 0,'zoz/zle', 0, '');
|
0, 0, '', 'Verified', 0, false, '/i/pfps/4.webp', '/i/pfps/4.webp', 0, 0,'zoz/zle', 0, '');
|
||||||
--
|
--
|
||||||
|
|
Loading…
Reference in New Issue