diff --git a/app/admin/forms.py b/app/admin/forms.py index 33fb5ed3..a0d6c009 100644 --- a/app/admin/forms.py +++ b/app/admin/forms.py @@ -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()]) diff --git a/app/admin/routes.py b/app/admin/routes.py index fcb95c1d..c31d50b3 100644 --- a/app/admin/routes.py +++ b/app/admin/routes.py @@ -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(), diff --git a/app/community/routes.py b/app/community/routes.py index d34dc10c..c9ee7fa4 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -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) diff --git a/app/templates/admin/federation.html b/app/templates/admin/federation.html index d3cf0f4e..709a9fb3 100644 --- a/app/templates/admin/federation.html +++ b/app/templates/admin/federation.html @@ -17,7 +17,10 @@
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 LemmyVerse. NSFW communities and communities from banned instances are excluded.
+Use this to "pre-load" known threadiverse communities, as ranked by posts and activity. The list of communities pulls from the same list as LemmyVerse. NSFW communities and communities from banned instances are excluded.
+ {% if current_app_debug %} +*** This instance is in development mode. Loading more than 6 communities here could cause timeouts, depending on how your networking is setup. ***
+ {% endif %} {{ render_form(preload_form) }}