diff --git a/app/blueprints/threads/__init__.py b/app/blueprints/threads/__init__.py index e907c454..56a5ec18 100644 --- a/app/blueprints/threads/__init__.py +++ b/app/blueprints/threads/__init__.py @@ -16,7 +16,8 @@ from flask import Blueprint, request, render_template, abort, flash, redirect, url_for from flask_babel import gettext, lazy_gettext -from sqlalchemy.orm import selectinload +from sqlalchemy import or_ +from sqlalchemy.orm import selectinload, joinedload from app.markdown import get_user_mentions, render_markdown from app.tasks.webhooktasks import post_discord_webhook @@ -391,12 +392,18 @@ def user_comments(username): if user is None: abort(404) - all_replies = ThreadReply.query.options(selectinload(ThreadReply.thread)).filter_by(author=user) + page = get_int_or_abort(request.args.get("page"), 1) + num = min(40, get_int_or_abort(request.args.get("n"), 40)) - visible_replies = [ - reply - for reply in all_replies - if reply.thread.check_perm(current_user, Permission.SEE_THREAD) - ] + # Filter replies the current user can see + query = ThreadReply.query.options(selectinload(ThreadReply.thread)).filter_by(author=user) + if current_user != user and not (current_user.is_authenticated and current_user.rank.at_least(UserRank.APPROVER)): + if user.username == "ContentDB": + # The ContentDB user simply has too many comments, don't bother checking more than thread privacy + query = query.filter(ThreadReply.thread.has(private=False)) + else: + query = query.filter(or_(ThreadReply.thread.has(private=False), Thread.watchers.contains(current_user))) - return render_template("threads/user_comments.html", user=user, replies=visible_replies) + pagination = query.order_by(db.desc(ThreadReply.created_at)).paginate(page=page, per_page=num) + + return render_template("threads/user_comments.html", user=user, pagination=pagination) diff --git a/app/templates/threads/user_comments.html b/app/templates/threads/user_comments.html index 8d3a4d0f..a82389d4 100644 --- a/app/templates/threads/user_comments.html +++ b/app/templates/threads/user_comments.html @@ -12,55 +12,67 @@ {% block content %}
+ {% for r in pagination.items %} +-
+
+
+
+
+
+
+
+
-
- {{ r.author.display_name }}
-
-
- {% if r.author.username != r.author.display_name %}
-
- ({{ r.author.username }})
-
- {% endif %}
-
- {% if r == r.thread.first_reply %}
-
- {{ r.thread.title }}
+
+ {{ r.author.display_name }}
- {% else %}
-
-
- {{ _("Reply to %(title)s", title=r.thread.title) }}
+
+ {% if r.author.username != r.author.display_name %}
+
+ ({{ r.author.username }})
+
+ {% endif %}
+
+ {% if r == r.thread.first_reply %}
+
+ {{ r.thread.title }}
+
+ {% else %}
+
+
+ {{ _("Reply to %(title)s", title=r.thread.title) }}
+
+ {% endif %}
+
+
+ {{ r.created_at | datetime }}
- {% endif %}
+
-
- {{ r.created_at | datetime }}
-
-
-
-
- {{ r.comment | markdown }}
+
+ {{ r.comment | markdown }}
+
-
+ + {{ _("No results") }} + +
+{% endif %} {% endblock %}