mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 11:26:56 -08:00
making do_subscribe a celery task, messages to user updates
This commit is contained in:
parent
cf2400e5d5
commit
cf5bb65a9f
4 changed files with 29 additions and 13 deletions
|
@ -51,10 +51,12 @@ class FederationForm(FlaskForm):
|
|||
blocked_actors = TextAreaField(_l('Discard all posts and comments by users with these words in their name (one per line)'))
|
||||
submit = SubmitField(_l('Save'))
|
||||
|
||||
|
||||
class PreLoadCommunitiesForm(FlaskForm):
|
||||
communities_num = IntegerField(_l('Number of Communities to add'))
|
||||
communities_num = IntegerField(_l('Number of Communities to add'), default=25)
|
||||
pre_load_submit = SubmitField(_l('Add Communities'))
|
||||
|
||||
|
||||
class EditCommunityForm(FlaskForm):
|
||||
title = StringField(_l('Title'), validators=[DataRequired()])
|
||||
url = StringField(_l('Url'), validators=[DataRequired()])
|
||||
|
|
|
@ -283,19 +283,22 @@ def admin_federation():
|
|||
for c in community_urls_to_join:
|
||||
# get the relevant url bits
|
||||
server, community = extract_domain_and_actor(c)
|
||||
# message = {'server': server, 'community': community}
|
||||
# find the community
|
||||
new_community = search_for_community('!' + community + '@' + server)
|
||||
# message = {'server': server, 'community': community, 'new_community': new_community}
|
||||
# subscribe to the community
|
||||
# since this is using the alt_user_name, capture the messages
|
||||
# returned by do_subscibe as well
|
||||
message = do_subscribe(new_community.ap_id, main_user_name=False)
|
||||
pre_load_messages.append(message)
|
||||
# subscribe to the community using alt_profile
|
||||
# capture the messages returned by do_subscibe
|
||||
# and show to user if instance is in debug mode
|
||||
if current_app.debug:
|
||||
message = do_subscribe(new_community.ap_id, main_user_name=False)
|
||||
pre_load_messages.append(message)
|
||||
else:
|
||||
message_we_wont_do_anything_with = do_subscribe.delay(new_community.ap_id, main_user_name=False)
|
||||
|
||||
if current_app.debug:
|
||||
flash(_(f'Results: {pre_load_messages}'))
|
||||
else:
|
||||
flash(_('Subscription process launched to background, check admin/activities for details'))
|
||||
|
||||
# flash(_(f'community_urls_to_join == {community_urls_to_join}')) # testing
|
||||
flash(_(f'Results: {pre_load_messages}'))
|
||||
return redirect(url_for('admin.admin_federation'))
|
||||
|
||||
# this is the main settings form
|
||||
|
@ -334,7 +337,7 @@ def admin_federation():
|
|||
form.blocked_actors.data = get_setting('actor_blocked_words', '88')
|
||||
|
||||
return render_template('admin/federation.html', title=_('Federation settings'),
|
||||
form=form, preload_form=preload_form,
|
||||
form=form, preload_form=preload_form, current_app_debug=current_app.debug,
|
||||
moderating_communities=moderating_communities(current_user.get_id()),
|
||||
joined_communities=joined_communities(current_user.get_id()),
|
||||
menu_topics=menu_topics(),
|
||||
|
|
|
@ -10,7 +10,7 @@ from flask_babel import _
|
|||
from slugify import slugify
|
||||
from sqlalchemy import or_, desc, text
|
||||
|
||||
from app import db, constants, cache
|
||||
from app import db, constants, cache, celery
|
||||
from app.activitypub.signature import RsaKeys, post_request, default_context, post_request_in_background
|
||||
from app.activitypub.util import notify_about_post, make_image_sizes, resolve_remote_post, extract_domain_and_actor
|
||||
from app.chat.util import send_message
|
||||
|
@ -394,6 +394,7 @@ def subscribe(actor):
|
|||
|
||||
# this is separated out from the route, so it can be used by the
|
||||
# admin.admin_federation.preload_form as well
|
||||
@celery.task
|
||||
def do_subscribe(actor, main_user_name=True):
|
||||
remote = False
|
||||
actor = actor.strip()
|
||||
|
@ -457,6 +458,13 @@ def do_subscribe(actor, main_user_name=True):
|
|||
flash('You joined ' + community.title)
|
||||
else:
|
||||
pre_load_message['status'] = 'joined'
|
||||
else:
|
||||
if main_user_name:
|
||||
# user already subscribed or pending and its not the preload request
|
||||
pass
|
||||
else:
|
||||
pre_load_message['status'] = 'already subscribed, or subsciption pending'
|
||||
|
||||
referrer = request.headers.get('Referer', None)
|
||||
cache.delete_memoized(community_membership, current_user, community)
|
||||
cache.delete_memoized(joined_communities, current_user.id)
|
||||
|
|
|
@ -17,7 +17,10 @@
|
|||
<hr />
|
||||
<div class="row">
|
||||
<div class="column">
|
||||
<p>Use this to "pre-load" the top 50 known threadiverse communities, as rnaked by posts and activity. The list of communities pulls from the same list as <a href="https://lemmyverse.net/communities">LemmyVerse</a>. NSFW communities and communities from banned instances are excluded.</p>
|
||||
<p>Use this to "pre-load" known threadiverse communities, as ranked by posts and activity. The list of communities pulls from the same list as <a href="https://lemmyverse.net/communities">LemmyVerse</a>. NSFW communities and communities from banned instances are excluded.</p>
|
||||
{% if current_app_debug %}
|
||||
<p>*** This instance is in development mode. Loading more than 6 communities here could cause timeouts, depending on how your networking is setup. ***</p>
|
||||
{% endif %}
|
||||
{{ render_form(preload_form) }}
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue