diff --git a/files/classes/comment.py b/files/classes/comment.py index ba167086c..042630195 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -10,6 +10,7 @@ from files.__main__ import Base from .flags import CommentFlag from os import environ import time +from files.helpers.const import AUTOPOLLER_ACCOUNT site = environ.get("DOMAIN").strip() @@ -169,7 +170,7 @@ class Comment(Base): def replies(self): r = self.__dict__.get("replies", None) 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 @replies.setter @@ -187,7 +188,7 @@ class Comment(Base): @property def replies3(self): 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 @property diff --git a/files/classes/submission.py b/files/classes/submission.py index 5b1e82289..b69702faa 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -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" 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, v=v, @@ -215,27 +228,6 @@ class Submission(Base): if domain.startswith("www."): domain = domain.split("www.")[1] 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 @lazy diff --git a/files/routes/comments.py b/files/routes/comments.py index d4b39ff22..e80655a7f 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -9,7 +9,6 @@ from files.routes.front import comment_idlist from pusher_push_notifications import PushNotifications from flask import * from files.__main__ import app, limiter -from urllib.parse import ParseResult, urlunparse, urlparse 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.parent_submission == post.id + Comment.parent_submission == post.id, + Comment.author_id != AUTOPOLLER_ACCOUNT ).join( votes, 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): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') 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_html = sanitize(body_md) @@ -263,6 +269,17 @@ def api_comment(v): g.db.add(c) 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"): pill = re.match("based and (.{1,20}?)(-| )pilled", body, re.IGNORECASE) diff --git a/files/routes/posts.py b/files/routes/posts.py index d328afc02..c9c4ea33c 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -763,7 +763,6 @@ def submit_post(v): ) g.db.add(c) - g.db.flush() vote = Vote(user_id=v.id, vote_type=1, @@ -772,8 +771,6 @@ def submit_post(v): g.db.add(vote) g.db.flush() - g.db.refresh(new_post) - if request.files.get('file') and request.headers.get("cf-ipcountry") != "T1": file = request.files['file'] diff --git a/files/templates/comments.html b/files/templates/comments.html index 2d2ee9375..09baa78e8 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -66,6 +66,26 @@ {% include "expanded_image_modal.html" %} + + + + + {% macro single_comment(c, level=1) %} {% if p and not (v and v.id==c.author_id) and (not v or v.highlightcomments) %} @@ -245,6 +265,13 @@
{{c.realbody(v) | safe}} + {% for c in c.options %} +
+ + +
+ {% endfor %} + {% if not c.parent_submission and c.author_id!=NOTIFICATIONS_ACCOUNT and c.author_id!=AUTOJANNY_ACCOUNT and c.author_id!=v.id %} Reply

diff --git a/files/templates/submission.html b/files/templates/submission.html
index 3666c58ce..ea7f53e01 100644
--- a/files/templates/submission.html
+++ b/files/templates/submission.html
@@ -15,22 +15,6 @@
 
 
 
-
 
 {% if v and v.id == p.author_id %}