cross-posting of bot-generated posts #206

This commit is contained in:
rimu 2024-10-05 18:58:07 +13:00
parent 488bfab901
commit 0c646c5cf4
9 changed files with 108 additions and 3 deletions

View file

@ -673,6 +673,19 @@ def add_post(actor, type):
if community.posting_warning:
flash(community.posting_warning)
# The source query parameter is used when cross-posting - load the source post's content into the form
if post_type == POST_TYPE_LINK and request.args.get('source'):
source_post = Post.query.get(request.args.get('source'))
if source_post.deleted:
abort(404)
form.title.data = source_post.title
form.body.data = source_post.body
form.nsfw.data = source_post.nsfw
form.nsfl.data = source_post.nsfl
form.language_id.data = source_post.language_id
form.link_url.data = source_post.url
# empty post to pass since add_post.html extends edit_post.html
# and that one checks for a post.image_id for editing image posts
post = None

View file

@ -42,3 +42,8 @@ class ReportPostForm(FlaskForm):
class MeaCulpaForm(FlaskForm):
submit = SubmitField(_l('I changed my mind'))
class CrossPostForm(FlaskForm):
which_community = SelectField(_l('Community to post this link to'), validators=[DataRequired()], coerce=int, render_kw={'class': 'form-select'})
submit = SubmitField(_l('Next'))

View file

@ -13,7 +13,7 @@ from app.activitypub.signature import HttpSignature, post_request, default_conte
from app.activitypub.util import notify_about_post_reply, inform_followers_of_post_update
from app.community.util import save_post, send_to_remote_instance
from app.inoculation import inoculation
from app.post.forms import NewReplyForm, ReportPostForm, MeaCulpaForm
from app.post.forms import NewReplyForm, ReportPostForm, MeaCulpaForm, CrossPostForm
from app.community.forms import CreateLinkForm, CreateImageForm, CreateDiscussionForm, CreateVideoForm, CreatePollForm, EditImageForm
from app.post.util import post_replies, get_comment_branch, tags_to_string, url_needs_archive, \
generate_archive_link, body_has_no_archive_link
@ -1738,3 +1738,50 @@ def post_reply_view_voting_activity(comment_id: int):
joined_communities=joined_communities(current_user.get_id()),
menu_topics=menu_topics(), site=g.site
)
@bp.route('/post/<int:post_id>/cross-post', methods=['GET', 'POST'])
@login_required
def post_cross_post(post_id: int):
post = Post.query.get_or_404(post_id)
form = CrossPostForm()
which_community = {}
joined = joined_communities(current_user.get_id())
moderating = moderating_communities(current_user.get_id())
comms = []
already_added = set()
for community in moderating:
if community.id not in already_added:
comms.append((community.id, community.display_name()))
already_added.add(community.id)
if len(comms) > 0:
which_community['Moderating'] = comms
comms = []
for community in joined:
if community.id not in already_added:
comms.append((community.id, community.display_name()))
already_added.add(community.id)
if len(comms) > 0:
which_community['Joined communities'] = comms
form.which_community.choices = which_community
if form.validate_on_submit():
community = Community.query.get_or_404(form.which_community.data)
return redirect(url_for('community.add_post', actor=community.link(), type='link', source=str(post.id)))
else:
breadcrumbs = []
breadcrumb = namedtuple("Breadcrumb", ['text', 'url'])
breadcrumb.text = _('Home')
breadcrumb.url = '/'
breadcrumbs.append(breadcrumb)
breadcrumb = namedtuple("Breadcrumb", ['text', 'url'])
breadcrumb.text = _('Communities')
breadcrumb.url = '/communities'
breadcrumbs.append(breadcrumb)
return render_template('post/post_cross_post.html', title=_('Cross post'), form=form, post=post,
breadcrumbs=breadcrumbs,
moderating_communities=moderating,
joined_communities=joined,
menu_topics=menu_topics(), site=g.site
)

View file

@ -286,6 +286,10 @@ h1 {
content: "\e9be";
}
.fe-cross-post::before {
content: "\e9ba";
}
.fe-image {
position: relative;
top: 2px;

View file

@ -314,6 +314,10 @@ h1 .fe-bell, h1 .fe-no-bell {
content: "\e9be";
}
.fe-cross-post::before {
content: "\e9ba";
}
.fe-image {
position: relative;
top: 2px;
@ -1003,7 +1007,7 @@ time {
justify-content: center;
align-items: center;
}
.post_utilities_bar .post_options_link, .post_utilities_bar .preview_image {
.post_utilities_bar .post_cross_post_link, .post_utilities_bar .post_options_link, .post_utilities_bar .preview_image {
display: flex;
width: 44px;
height: 44px;

View file

@ -600,7 +600,7 @@ time {
align-items: center;
}
.post_options_link, .preview_image {
.post_cross_post_link, .post_options_link, .preview_image {
display: flex;
width: $min-touch-target;
height: $min-touch-target;

View file

@ -0,0 +1,25 @@
{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %}
{% extends 'themes/' + theme() + '/base.html' %}
{% else %}
{% extends "base.html" %}
{% endif %} %}
{% from 'bootstrap/form.html' import render_form %}
{% block app_content %}
<div class="row">
<div class="col-12 col-md-8 position-relative main_pane">
<nav aria-label="breadcrumb" id="breadcrumb_nav" title="Navigation">
<ol class="breadcrumb">
{% for breadcrumb in breadcrumbs -%}
<li class="breadcrumb-item">{% if breadcrumb.url -%}<a href="{{ breadcrumb.url }}">{% endif -%}{{ breadcrumb.text }}{% if breadcrumb.url -%}</a>{% endif -%}</li>
{% endfor -%}
<li class="breadcrumb-item"><a href="/c/{{ post.community.link() }}" title="{{ post.community.ap_domain }}">{{ post.community.title }}@{{ post.community.ap_domain }}</a></li>
<li class="breadcrumb-item active">{{ post.title|shorten(15) }}</li>
</ol>
</nav>
<h1 class="mt-2">{{ _('Cross-post %(post_name)s', post_name=post.title) }}</h1>
{{ render_form(form) }}
</div>
</div>
{% endblock %}

View file

@ -38,6 +38,10 @@
{{ _("I made a mistake with this post and have changed my mind about the topic") }}</a></li>
{% endif -%}
{% if post.user_id != current_user.id -%}
{% if post.type == POST_TYPE_LINK and post.author.bot and (post.cross_posts is none or len(post.cross_posts) == 0) -%}
<li><a class="no-underline" aria-label="{{ _('Cross-post') }}" href="{{ url_for('post.post_cross_post', post_id=post.id) }}"><span class="fe fe-cross-post"></span>
{{ _('Cross-post to another community') }}</a></li>
{% endif -%}
<li><a href="{{ url_for('post.post_block_user', post_id=post.id) }}" class="no-underline"><span class="fe fe-block"></span>
{{ _('Block post author @%(author_name)s', author_name=post.author.user_name) }}</a></li>
<li><a href="{{ url_for('post.post_block_community', post_id=post.id) }}" class="no-underline"><span class="fe fe-block"></span>

View file

@ -11,6 +11,9 @@
<a href="{{ post.url }}" rel="nofollow ugc" class="preview_image" target="_blank" aria-label="{{ _('View image') }}" aria-hidden="true"><span class="fe fe-magnify"></span></a>
{% endif -%}
{% endif -%}
{% if current_user.is_authenticated and post.type == POST_TYPE_LINK and post.author.bot and (post.cross_posts is none or len(post.cross_posts) == 0) -%}
<a class="post_cross_post_link" rel="nofollow" aria-label="{{ _('Cross-post') }}" href="{{ url_for('post.post_cross_post', post_id=post.id) }}"><span class="fe fe-cross-post"></span></a>
{% endif -%}
<a class="post_options_link" href="{{ url_for('post.post_options', post_id=post.id) }}" rel="nofollow" aria-label="{{ _('Options') }}"><span class="fe fe-options" title="Options"> </span></a>
</div>
</div>