diff --git a/app/post/routes.py b/app/post/routes.py index b25acc21..685567d9 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -25,6 +25,7 @@ from app.models import Post, PostReply, \ Topic, User, Instance, NotificationSubscription, UserFollower, Poll, PollChoice, PollChoiceVote, PostBookmark, \ PostReplyBookmark, CommunityBlock, File from app.post import bp +from app.shared.tasks import task_selector from app.utils import get_setting, render_template, allowlist_html, markdown_to_html, validation_required, \ shorten_string, markdown_to_text, gibberish, ap_datetime, return_304, \ request_etag_matches, ip_address, user_ip_banned, instance_banned, \ @@ -473,6 +474,43 @@ def add_reply(post_id: int, comment_id: int): inoculation=inoculation[randint(0, len(inoculation) - 1)] if g.site.show_inoculation_block else None) +@bp.route('/post//comment//reply_inline', methods=['GET', 'POST']) +@login_required +def add_reply_inline(post_id: int, comment_id: int): + if current_user.banned or current_user.ban_comments: + return _('You have been banned.') + post = Post.query.get_or_404(post_id) + + if not post.comments_enabled: + return _('Comments have been disabled.') + + in_reply_to = PostReply.query.get_or_404(comment_id) + + if in_reply_to.author.has_blocked_user(current_user.id): + return _('You cannot reply to %(name)s', name=in_reply_to.author.display_name()) + + if request.method == 'GET': + return render_template('post/add_reply_inline.html', post_id=post_id, comment_id=comment_id, languages=languages_for_form()) + else: + content = request.form.get('body', '').strip() + language_id = int(request.form.get('language_id')) + + if content == '': + abort(406) # stop htmx from replacing the form with anything + reply = PostReply.new(current_user, post, in_reply_to=in_reply_to, body=piefed_markdown_to_lemmy_markdown(content), + body_html=markdown_to_html(content), notify_author=True, + language_id=language_id) + + current_user.language_id = language_id + reply.ap_id = reply.profile_id() + db.session.commit() + + # Federate the reply + task_selector('make_reply', user_id=current_user.id, reply_id=reply.id, parent_id=in_reply_to.id) + + return render_template('post/add_reply_inline_result.html', post_reply=reply) + + @bp.route('/post//options_menu', methods=['GET']) def post_options(post_id: int): post = Post.query.get_or_404(post_id) diff --git a/app/templates/post/_post_full.html b/app/templates/post/_post_full.html index cd06b01d..bc8cf622 100644 --- a/app/templates/post/_post_full.html +++ b/app/templates/post/_post_full.html @@ -10,9 +10,6 @@ {{ post.image.alt_text if post.image.alt_text else '' }} - {% elif post.type == POST_TYPE_IMAGE and post.url -%} -

{{ post.url|shorten_url }} -

{% endif -%}
{% if post.reports > 0 and current_user.is_authenticated and post.community.is_moderator(current_user) -%} @@ -21,6 +18,8 @@ {% if post.edited_at -%} edited {% endif -%}
{% if post.type == POST_TYPE_IMAGE -%} +

{{ post.url|shorten_url }} +

{% if post.image_id -%} {% if low_bandwidth -%} @@ -40,7 +39,7 @@ {% endif -%}
{% elif post.type == POST_TYPE_LINK -%} -

{{ post.url|shorten_url }} +

{{ post.url|shorten_url }} {% if post.domain.post_warning -%} diff --git a/app/templates/post/_post_reply_teaser.html b/app/templates/post/_post_reply_teaser.html index 9fa1df2c..6b18f020 100644 --- a/app/templates/post/_post_reply_teaser.html +++ b/app/templates/post/_post_reply_teaser.html @@ -68,7 +68,15 @@

{% if post_reply.post.comments_enabled -%} {% if not post_reply.post.deleted and not post_reply.deleted -%} - reply + {% if current_user.is_authenticated -%} + reply + {% else -%} + reply + {% endif -%} {% else -%} reply {% endif -%} @@ -114,6 +122,7 @@ {% endif -%}
+
{% if not post_reply.author.indexable -%}{% endif -%} {% if children -%} diff --git a/app/templates/post/add_reply_inline.html b/app/templates/post/add_reply_inline.html new file mode 100644 index 00000000..36e7fe7a --- /dev/null +++ b/app/templates/post/add_reply_inline.html @@ -0,0 +1,24 @@ +
+
+
+ +
+
+
+ +
+ +
+
+
\ No newline at end of file diff --git a/app/templates/post/add_reply_inline_result.html b/app/templates/post/add_reply_inline_result.html new file mode 100644 index 00000000..3020065c --- /dev/null +++ b/app/templates/post/add_reply_inline_result.html @@ -0,0 +1,132 @@ +{% macro render_username(user, add_domain=True, htmx_redirect_back_to=None) -%} + + {% if user.deleted -%} + {% if current_user.is_authenticated and current_user.is_admin() -%} + [deleted] + {% else -%} + [deleted] + {% endif -%} + {% else -%} + + {% if user.avatar_id and not low_bandwidth and not collapsed -%} + + {% endif -%} + {{ user.display_name() }}{% if add_domain and not user.is_local() %}@{{ user.ap_domain }}{% endif %} + +
+ {% if user.created_recently() -%} + + {% endif -%} + {% if user.bot -%} + + {% endif -%} + {% if user.id != current_user.id -%} + {% if user.reputation < -10 -%} + + + {% elif user.reputation < 0 -%} + + {% endif -%} + {% endif -%} + {% if current_user.is_authenticated -%} + {% set user_note = user.get_note(current_user) %} + {% if user_note -%} + [{{ user_note | truncate(12, True) }}] + {% endif -%} + {% endif -%} + {% endif -%} +
+{% endmacro -%} +{% set collapsed = false -%} +
+
+
+
+ by + {{ render_username(post_reply.author, htmx_redirect_back_to=request.path + '#comment_' + str(post_reply.id)) }} + {% if post_reply.author.id == post_reply.post.author.id -%} + [OP] + {% endif -%} +
+
+ {% if post_reply.edited_at -%}, edited {% endif -%} +
+
+ {% if post_reply.reports and current_user.is_authenticated and post_reply.post.community.is_moderator(current_user) -%} + + {% endif -%} +
+
+ {% if post_reply.deleted -%} + + {% endif -%} +
+
+ +
+
+ +
+
+ {{ post_reply.body_html | community_links | person_links | safe }} +
+
+
+
+ reply +
+
+ {% with comment=post_reply, community=post_reply.post.community -%} + {% include "post/_comment_voting_buttons.html" -%} + {% endwith -%} +
+
+ {% if collapsed -%} + + {% else -%} + + {% endif -%} +
+
+ {% if current_user.is_authenticated and current_user.verified -%} + {% with comment=dict(comment=post_reply) -%} + {% include "post/_reply_notification_toggle.html" -%} + {% endwith -%} + {% endif -%} +
+ +
+
+
+
+ diff --git a/app/utils.py b/app/utils.py index fe5cb3bc..28ee7b6b 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1143,7 +1143,7 @@ def remove_tracking_from_link(url): def show_ban_message(): - flash('You have been banned.', 'error') + flash(_('You have been banned.'), 'error') logout_user() resp = make_response(redirect(url_for('main.index'))) resp.set_cookie('sesion', '17489047567495', expires=datetime(year=2099, month=12, day=30)) diff --git a/docs/project_management/roadmap.md b/docs/project_management/roadmap.md index ecf936e1..1efc9a7c 100644 --- a/docs/project_management/roadmap.md +++ b/docs/project_management/roadmap.md @@ -2,7 +2,7 @@ The following are our goals for 2025. We brainstormed ideas then [ranked them by voting](https://piefed.social/c/piefed_2025?sort=top). -[Inline commenting](https://piefed.social/post/411646) +✅ [Inline commenting](https://piefed.social/post/411646) [Cross-posting](https://piefed.social/post/411644)