mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-08 22:17:34 +01:00
parent
30722020c8
commit
459eb02112
@ -16,7 +16,8 @@
|
|||||||
|
|
||||||
from flask import Blueprint, request, render_template, abort, flash, redirect, url_for
|
from flask import Blueprint, request, render_template, abort, flash, redirect, url_for
|
||||||
from flask_babel import gettext, lazy_gettext
|
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.markdown import get_user_mentions, render_markdown
|
||||||
from app.tasks.webhooktasks import post_discord_webhook
|
from app.tasks.webhooktasks import post_discord_webhook
|
||||||
@ -391,12 +392,18 @@ def user_comments(username):
|
|||||||
if user is None:
|
if user is None:
|
||||||
abort(404)
|
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 = [
|
# Filter replies the current user can see
|
||||||
reply
|
query = ThreadReply.query.options(selectinload(ThreadReply.thread)).filter_by(author=user)
|
||||||
for reply in all_replies
|
if current_user != user and not (current_user.is_authenticated and current_user.rank.at_least(UserRank.APPROVER)):
|
||||||
if reply.thread.check_perm(current_user, Permission.SEE_THREAD)
|
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)
|
||||||
|
@ -12,55 +12,67 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<h1>{{ _("Comments by %(user)s", user=self.link()) }}</h1>
|
<h1>{{ _("Comments by %(user)s", user=self.link()) }}</h1>
|
||||||
|
|
||||||
|
{% if pagination.total %}
|
||||||
|
{% from "macros/pagination.html" import render_pagination %}
|
||||||
|
{{ render_pagination(pagination, url_set_query) }}
|
||||||
|
|
||||||
<ul class="comments mt-5 mb-0">
|
<ul class="comments mt-5 mb-0">
|
||||||
{% for r in replies %}
|
{% for r in pagination.items %}
|
||||||
<li class="row my-2 mx-0">
|
<li class="row my-2 mx-0">
|
||||||
<div class="col-md-1 p-1">
|
<div class="col-md-1 p-1">
|
||||||
<a href="{{ url_for('users.profile', username=r.author.username) }}">
|
<a href="{{ url_for('users.profile', username=r.author.username) }}">
|
||||||
<img class="img-fluid user-photo img-thumbnail img-thumbnail-1"
|
<img class="img-fluid user-photo img-thumbnail img-thumbnail-1"
|
||||||
src="{{ r.author.get_profile_pic_url() }}" loading="lazy">
|
src="{{ r.author.get_profile_pic_url() }}" loading="lazy">
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="col pr-0">
|
<div class="col pr-0">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
|
|
||||||
<a class="author {{ r.author.rank.name }} me-3"
|
<a class="author {{ r.author.rank.name }} me-3"
|
||||||
href="{{ url_for('users.profile', username=r.author.username) }}">
|
href="{{ url_for('users.profile', username=r.author.username) }}">
|
||||||
{{ r.author.display_name }}
|
{{ r.author.display_name }}
|
||||||
</a>
|
|
||||||
|
|
||||||
{% if r.author.username != r.author.display_name %}
|
|
||||||
<span class="text-muted small me-2">
|
|
||||||
({{ r.author.username }})
|
|
||||||
</span>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if r == r.thread.first_reply %}
|
|
||||||
<a class="badge bg-primary" href="{{ r.thread.get_view_url() }}">
|
|
||||||
{{ r.thread.title }}
|
|
||||||
</a>
|
</a>
|
||||||
{% else %}
|
|
||||||
<i class="fas fa-reply me-2"></i>
|
{% if r.author.username != r.author.display_name %}
|
||||||
<a class="badge bg-dark" href="{{ r.thread.get_view_url() }}">
|
<span class="text-muted small me-2">
|
||||||
{{ _("Reply to <b>%(title)s</b>", title=r.thread.title) }}
|
({{ r.author.username }})
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if r == r.thread.first_reply %}
|
||||||
|
<a class="badge bg-primary" href="{{ r.thread.get_view_url() }}">
|
||||||
|
{{ r.thread.title }}
|
||||||
|
</a>
|
||||||
|
{% else %}
|
||||||
|
<i class="fas fa-reply me-2"></i>
|
||||||
|
<a class="badge bg-dark" href="{{ r.thread.get_view_url() }}">
|
||||||
|
{{ _("Reply to <b>%(title)s</b>", title=r.thread.title) }}
|
||||||
|
</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<a name="reply-{{ r.id }}" class="text-muted float-end"
|
||||||
|
href="{{ url_for('threads.view', id=r.thread.id) }}#reply-{{ r.id }}">
|
||||||
|
{{ r.created_at | datetime }}
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
</div>
|
||||||
|
|
||||||
<a name="reply-{{ r.id }}" class="text-muted float-end"
|
<div class="card-body markdown">
|
||||||
href="{{ url_for('threads.view', id=r.thread.id) }}#reply-{{ r.id }}">
|
{{ r.comment | markdown }}
|
||||||
{{ r.created_at | datetime }}
|
</div>
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="card-body markdown">
|
|
||||||
{{ r.comment | markdown }}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</li>
|
||||||
</li>
|
{% endfor %}
|
||||||
{% endfor %}
|
</ul>
|
||||||
</ul>
|
|
||||||
|
{{ render_pagination(pagination, url_set_query) }}
|
||||||
|
{% else %}
|
||||||
|
<p>
|
||||||
|
<i>
|
||||||
|
{{ _("No results") }}
|
||||||
|
</i>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user