dfssdf
This commit is contained in:
parent
e6953d0f95
commit
b059516006
6 changed files with 63 additions and 45 deletions
|
@ -10,6 +10,7 @@ from files.__main__ import Base
|
||||||
from .flags import CommentFlag
|
from .flags import CommentFlag
|
||||||
from os import environ
|
from os import environ
|
||||||
import time
|
import time
|
||||||
|
from files.helpers.const import AUTOPOLLER_ACCOUNT
|
||||||
|
|
||||||
site = environ.get("DOMAIN").strip()
|
site = environ.get("DOMAIN").strip()
|
||||||
|
|
||||||
|
@ -169,7 +170,7 @@ class Comment(Base):
|
||||||
def replies(self):
|
def replies(self):
|
||||||
r = self.__dict__.get("replies", None)
|
r = self.__dict__.get("replies", None)
|
||||||
if r: r = [x for x in r if not x.author.shadowbanned]
|
if r: r = [x for x in r if not x.author.shadowbanned]
|
||||||
if not r and r != []: r = sorted([x for x in self.child_comments if not x.author.shadowbanned], key=lambda x: x.score, reverse=True)
|
if not r and r != []: r = sorted([x for x in self.child_comments if not x.author.shadowbanned and x.author_id != AUTOPOLLER_ACCOUNT], key=lambda x: x.score, reverse=True)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
@replies.setter
|
@replies.setter
|
||||||
|
@ -187,7 +188,7 @@ class Comment(Base):
|
||||||
@property
|
@property
|
||||||
def replies3(self):
|
def replies3(self):
|
||||||
r = self.__dict__.get("replies", None)
|
r = self.__dict__.get("replies", None)
|
||||||
if not r and r != []: r = sorted([x for x in self.child_comments], key=lambda x: x.score, reverse=True)
|
if not r and r != []: r = sorted([x for x in self.child_comments if x.author_id != AUTOPOLLER_ACCOUNT], key=lambda x: x.score, reverse=True)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -195,7 +195,20 @@ class Submission(Base):
|
||||||
if self.is_banned and not (v and (v.admin_level >= 3 or self.author_id == v.id)): template = "submission_banned.html"
|
if self.is_banned and not (v and (v.admin_level >= 3 or self.author_id == v.id)): template = "submission_banned.html"
|
||||||
else: template = "submission.html"
|
else: template = "submission.html"
|
||||||
|
|
||||||
self.tree_comments(comment=comment)
|
comments = self.__dict__.get('preloaded_comments', [])
|
||||||
|
if comments:
|
||||||
|
pinned_comment = []
|
||||||
|
index = {}
|
||||||
|
for c in comments:
|
||||||
|
if c.is_pinned and c.parent_fullname==self.fullname:
|
||||||
|
pinned_comment += [c]
|
||||||
|
continue
|
||||||
|
if c.parent_fullname in index: index[c.parent_fullname].append(c)
|
||||||
|
else: index[c.parent_fullname] = [c]
|
||||||
|
|
||||||
|
for c in comments: c.__dict__["replies"] = index.get(c.fullname, [])
|
||||||
|
if comment: self.__dict__["replies"] = [comment]
|
||||||
|
else: self.__dict__["replies"] = pinned_comment + index.get(self.fullname, [])
|
||||||
|
|
||||||
return render_template(template,
|
return render_template(template,
|
||||||
v=v,
|
v=v,
|
||||||
|
@ -215,27 +228,6 @@ class Submission(Base):
|
||||||
if domain.startswith("www."): domain = domain.split("www.")[1]
|
if domain.startswith("www."): domain = domain.split("www.")[1]
|
||||||
return domain.replace("old.reddit.com", "reddit.com")
|
return domain.replace("old.reddit.com", "reddit.com")
|
||||||
|
|
||||||
def tree_comments(self, comment=None, v=None):
|
|
||||||
|
|
||||||
comments = self.__dict__.get('preloaded_comments', [])
|
|
||||||
if not comments: return
|
|
||||||
|
|
||||||
pinned_comment=[]
|
|
||||||
|
|
||||||
index = {}
|
|
||||||
for c in comments:
|
|
||||||
|
|
||||||
if c.is_pinned and c.parent_fullname==self.fullname:
|
|
||||||
pinned_comment += [c]
|
|
||||||
continue
|
|
||||||
|
|
||||||
if c.parent_fullname in index: index[c.parent_fullname].append(c)
|
|
||||||
else: index[c.parent_fullname] = [c]
|
|
||||||
|
|
||||||
for c in comments: c.__dict__["replies"] = index.get(c.fullname, [])
|
|
||||||
|
|
||||||
if comment: self.__dict__["replies"] = [comment]
|
|
||||||
else: self.__dict__["replies"] = pinned_comment + index.get(self.fullname, [])
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@lazy
|
@lazy
|
||||||
|
|
|
@ -9,7 +9,6 @@ from files.routes.front import comment_idlist
|
||||||
from pusher_push_notifications import PushNotifications
|
from pusher_push_notifications import PushNotifications
|
||||||
from flask import *
|
from flask import *
|
||||||
from files.__main__ import app, limiter
|
from files.__main__ import app, limiter
|
||||||
from urllib.parse import ParseResult, urlunparse, urlparse
|
|
||||||
|
|
||||||
|
|
||||||
site = environ.get("DOMAIN").strip()
|
site = environ.get("DOMAIN").strip()
|
||||||
|
@ -90,7 +89,8 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
|
||||||
comments = comments.filter(Comment.author_id.notin_(shadowbanned))
|
comments = comments.filter(Comment.author_id.notin_(shadowbanned))
|
||||||
|
|
||||||
comments=comments.filter(
|
comments=comments.filter(
|
||||||
Comment.parent_submission == post.id
|
Comment.parent_submission == post.id,
|
||||||
|
Comment.author_id != AUTOPOLLER_ACCOUNT
|
||||||
).join(
|
).join(
|
||||||
votes,
|
votes,
|
||||||
votes.c.comment_id == Comment.id,
|
votes.c.comment_id == Comment.id,
|
||||||
|
@ -152,6 +152,12 @@ def api_comment(v):
|
||||||
for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE):
|
for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE):
|
||||||
if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'})')
|
if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'})')
|
||||||
body = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', body)
|
body = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', body)
|
||||||
|
|
||||||
|
options = []
|
||||||
|
for i in re.finditer('\s*\$\$([^\$\n]+)\$\$\s*', body):
|
||||||
|
options.append(i.group(1))
|
||||||
|
body = body.replace(i.group(0), "")
|
||||||
|
|
||||||
body_md = CustomRenderer().render(mistletoe.Document(body))
|
body_md = CustomRenderer().render(mistletoe.Document(body))
|
||||||
body_html = sanitize(body_md)
|
body_html = sanitize(body_md)
|
||||||
|
|
||||||
|
@ -263,6 +269,17 @@ def api_comment(v):
|
||||||
g.db.add(c)
|
g.db.add(c)
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
|
|
||||||
|
for option in options:
|
||||||
|
c_option = Comment(author_id=AUTOPOLLER_ACCOUNT,
|
||||||
|
parent_submission=parent_submission,
|
||||||
|
parent_comment_id=c.id,
|
||||||
|
level=level+1,
|
||||||
|
body=option
|
||||||
|
)
|
||||||
|
|
||||||
|
g.db.add(c_option)
|
||||||
|
|
||||||
|
|
||||||
if 'pcmemes.net' in request.host and c.body.lower().startswith("based"):
|
if 'pcmemes.net' in request.host and c.body.lower().startswith("based"):
|
||||||
pill = re.match("based and (.{1,20}?)(-| )pilled", body, re.IGNORECASE)
|
pill = re.match("based and (.{1,20}?)(-| )pilled", body, re.IGNORECASE)
|
||||||
|
|
||||||
|
|
|
@ -763,7 +763,6 @@ def submit_post(v):
|
||||||
)
|
)
|
||||||
|
|
||||||
g.db.add(c)
|
g.db.add(c)
|
||||||
g.db.flush()
|
|
||||||
|
|
||||||
vote = Vote(user_id=v.id,
|
vote = Vote(user_id=v.id,
|
||||||
vote_type=1,
|
vote_type=1,
|
||||||
|
@ -772,8 +771,6 @@ def submit_post(v):
|
||||||
g.db.add(vote)
|
g.db.add(vote)
|
||||||
g.db.flush()
|
g.db.flush()
|
||||||
|
|
||||||
g.db.refresh(new_post)
|
|
||||||
|
|
||||||
if request.files.get('file') and request.headers.get("cf-ipcountry") != "T1":
|
if request.files.get('file') and request.headers.get("cf-ipcountry") != "T1":
|
||||||
|
|
||||||
file = request.files['file']
|
file = request.files['file']
|
||||||
|
|
|
@ -66,6 +66,26 @@
|
||||||
|
|
||||||
{% include "expanded_image_modal.html" %}
|
{% include "expanded_image_modal.html" %}
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function poll_vote(cid) {
|
||||||
|
{% if v %}
|
||||||
|
var type = document.getElementById(cid).checked;
|
||||||
|
var scoretext = document.getElementById('poll-' + cid);
|
||||||
|
var score = Number(scoretext.textContent);
|
||||||
|
if (type == true) scoretext.textContent = score + 1;
|
||||||
|
else scoretext.textContent = score - 1;
|
||||||
|
post('/vote/poll/' + cid + '?vote=' + type);
|
||||||
|
{% else %}
|
||||||
|
var myToast = new bootstrap.Toast(document.getElementById('toast-post-error'));
|
||||||
|
myToast.show();
|
||||||
|
document.getElementById('toast-post-error-text').innerText = "Only logged-in users can vote!";
|
||||||
|
{% endif %}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{% macro single_comment(c, level=1) %}
|
{% macro single_comment(c, level=1) %}
|
||||||
|
|
||||||
{% if p and not (v and v.id==c.author_id) and (not v or v.highlightcomments) %}
|
{% if p and not (v and v.id==c.author_id) and (not v or v.highlightcomments) %}
|
||||||
|
@ -245,6 +265,13 @@
|
||||||
<div id="comment-text-{{c.id}}" class="comment-text mb-0">
|
<div id="comment-text-{{c.id}}" class="comment-text mb-0">
|
||||||
{{c.realbody(v) | safe}}
|
{{c.realbody(v) | safe}}
|
||||||
|
|
||||||
|
{% for c in c.options %}
|
||||||
|
<div class="custom-control">
|
||||||
|
<input type="checkbox" class="custom-control-input" id="{{c.id}}" name="option" {% if c.poll_voted(v) %}checked{% endif %} onchange="poll_vote('{{c.id}}')">
|
||||||
|
<label class="custom-control-label" for="{{c.id}}">{{c.body}} - <a href="/votes?link=t3_{{c.id}}"><span id="poll-{{c.id}}">{{c.upvotes}}</span> votes</a></label>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
{% if not c.parent_submission and c.author_id!=NOTIFICATIONS_ACCOUNT and c.author_id!=AUTOJANNY_ACCOUNT and c.author_id!=v.id %}
|
{% if not c.parent_submission and c.author_id!=NOTIFICATIONS_ACCOUNT and c.author_id!=AUTOJANNY_ACCOUNT and c.author_id!=v.id %}
|
||||||
<a class="btn btn-primary" href="javascript:void(0)" onclick="document.getElementById('reply-m-{{c.id}}').classList.toggle('d-none')">Reply</a>
|
<a class="btn btn-primary" href="javascript:void(0)" onclick="document.getElementById('reply-m-{{c.id}}').classList.toggle('d-none')">Reply</a>
|
||||||
<pre></pre>
|
<pre></pre>
|
||||||
|
|
|
@ -15,22 +15,6 @@
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js"></script>
|
||||||
<script src="/assets/js/new_comments_count.js?v=10"></script>
|
<script src="/assets/js/new_comments_count.js?v=10"></script>
|
||||||
<script>
|
|
||||||
function poll_vote(cid) {
|
|
||||||
{% if v %}
|
|
||||||
var type = document.getElementById(cid).checked;
|
|
||||||
var scoretext = document.getElementById('poll-' + cid);
|
|
||||||
var score = Number(scoretext.textContent);
|
|
||||||
if (type == true) scoretext.textContent = score + 1;
|
|
||||||
else scoretext.textContent = score - 1;
|
|
||||||
post('/vote/poll/' + cid + '?vote=' + type);
|
|
||||||
{% else %}
|
|
||||||
var myToast = new bootstrap.Toast(document.getElementById('toast-post-error'));
|
|
||||||
myToast.show();
|
|
||||||
document.getElementById('toast-post-error-text').innerText = "Only logged-in users can vote!";
|
|
||||||
{% endif %}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{% if v and v.id == p.author_id %}
|
{% if v and v.id == p.author_id %}
|
||||||
<script>
|
<script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue