mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-24 03:43:42 -08:00
cross-posting of bot-generated posts #206
This commit is contained in:
parent
488bfab901
commit
0c646c5cf4
9 changed files with 108 additions and 3 deletions
|
@ -673,6 +673,19 @@ def add_post(actor, type):
|
||||||
if community.posting_warning:
|
if community.posting_warning:
|
||||||
flash(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
|
# 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
|
# and that one checks for a post.image_id for editing image posts
|
||||||
post = None
|
post = None
|
||||||
|
|
|
@ -42,3 +42,8 @@ class ReportPostForm(FlaskForm):
|
||||||
|
|
||||||
class MeaCulpaForm(FlaskForm):
|
class MeaCulpaForm(FlaskForm):
|
||||||
submit = SubmitField(_l('I changed my mind'))
|
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'))
|
||||||
|
|
|
@ -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.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.community.util import save_post, send_to_remote_instance
|
||||||
from app.inoculation import inoculation
|
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.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, \
|
from app.post.util import post_replies, get_comment_branch, tags_to_string, url_needs_archive, \
|
||||||
generate_archive_link, body_has_no_archive_link
|
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()),
|
joined_communities=joined_communities(current_user.get_id()),
|
||||||
menu_topics=menu_topics(), site=g.site
|
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
|
||||||
|
)
|
||||||
|
|
|
@ -286,6 +286,10 @@ h1 {
|
||||||
content: "\e9be";
|
content: "\e9be";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fe-cross-post::before {
|
||||||
|
content: "\e9ba";
|
||||||
|
}
|
||||||
|
|
||||||
.fe-image {
|
.fe-image {
|
||||||
position: relative;
|
position: relative;
|
||||||
top: 2px;
|
top: 2px;
|
||||||
|
|
|
@ -314,6 +314,10 @@ h1 .fe-bell, h1 .fe-no-bell {
|
||||||
content: "\e9be";
|
content: "\e9be";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fe-cross-post::before {
|
||||||
|
content: "\e9ba";
|
||||||
|
}
|
||||||
|
|
||||||
.fe-image {
|
.fe-image {
|
||||||
position: relative;
|
position: relative;
|
||||||
top: 2px;
|
top: 2px;
|
||||||
|
@ -1003,7 +1007,7 @@ time {
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: 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;
|
display: flex;
|
||||||
width: 44px;
|
width: 44px;
|
||||||
height: 44px;
|
height: 44px;
|
||||||
|
|
|
@ -600,7 +600,7 @@ time {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post_options_link, .preview_image {
|
.post_cross_post_link, .post_options_link, .preview_image {
|
||||||
display: flex;
|
display: flex;
|
||||||
width: $min-touch-target;
|
width: $min-touch-target;
|
||||||
height: $min-touch-target;
|
height: $min-touch-target;
|
||||||
|
|
25
app/templates/post/post_cross_post.html
Normal file
25
app/templates/post/post_cross_post.html
Normal 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 %}
|
|
@ -38,6 +38,10 @@
|
||||||
{{ _("I made a mistake with this post and have changed my mind about the topic") }}</a></li>
|
{{ _("I made a mistake with this post and have changed my mind about the topic") }}</a></li>
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
{% if post.user_id != current_user.id -%}
|
{% 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>
|
<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>
|
{{ _('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>
|
<li><a href="{{ url_for('post.post_block_community', post_id=post.id) }}" class="no-underline"><span class="fe fe-block"></span>
|
||||||
|
|
|
@ -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>
|
<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 -%}
|
||||||
{% 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>
|
<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>
|
||||||
</div>
|
</div>
|
Loading…
Add table
Reference in a new issue