mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36: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)'))
|
blocked_actors = TextAreaField(_l('Discard all posts and comments by users with these words in their name (one per line)'))
|
||||||
submit = SubmitField(_l('Save'))
|
submit = SubmitField(_l('Save'))
|
||||||
|
|
||||||
|
|
||||||
class PreLoadCommunitiesForm(FlaskForm):
|
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'))
|
pre_load_submit = SubmitField(_l('Add Communities'))
|
||||||
|
|
||||||
|
|
||||||
class EditCommunityForm(FlaskForm):
|
class EditCommunityForm(FlaskForm):
|
||||||
title = StringField(_l('Title'), validators=[DataRequired()])
|
title = StringField(_l('Title'), validators=[DataRequired()])
|
||||||
url = StringField(_l('Url'), validators=[DataRequired()])
|
url = StringField(_l('Url'), validators=[DataRequired()])
|
||||||
|
|
|
@ -283,19 +283,22 @@ def admin_federation():
|
||||||
for c in community_urls_to_join:
|
for c in community_urls_to_join:
|
||||||
# get the relevant url bits
|
# get the relevant url bits
|
||||||
server, community = extract_domain_and_actor(c)
|
server, community = extract_domain_and_actor(c)
|
||||||
# message = {'server': server, 'community': community}
|
|
||||||
# find the community
|
# find the community
|
||||||
new_community = search_for_community('!' + community + '@' + server)
|
new_community = search_for_community('!' + community + '@' + server)
|
||||||
# message = {'server': server, 'community': community, 'new_community': new_community}
|
# subscribe to the community using alt_profile
|
||||||
# subscribe to the community
|
# capture the messages returned by do_subscibe
|
||||||
# since this is using the alt_user_name, capture the messages
|
# and show to user if instance is in debug mode
|
||||||
# returned by do_subscibe as well
|
if current_app.debug:
|
||||||
message = do_subscribe(new_community.ap_id, main_user_name=False)
|
message = do_subscribe(new_community.ap_id, main_user_name=False)
|
||||||
pre_load_messages.append(message)
|
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'community_urls_to_join == {community_urls_to_join}')) # testing
|
|
||||||
flash(_(f'Results: {pre_load_messages}'))
|
flash(_(f'Results: {pre_load_messages}'))
|
||||||
|
else:
|
||||||
|
flash(_('Subscription process launched to background, check admin/activities for details'))
|
||||||
|
|
||||||
return redirect(url_for('admin.admin_federation'))
|
return redirect(url_for('admin.admin_federation'))
|
||||||
|
|
||||||
# this is the main settings form
|
# this is the main settings form
|
||||||
|
@ -334,7 +337,7 @@ def admin_federation():
|
||||||
form.blocked_actors.data = get_setting('actor_blocked_words', '88')
|
form.blocked_actors.data = get_setting('actor_blocked_words', '88')
|
||||||
|
|
||||||
return render_template('admin/federation.html', title=_('Federation settings'),
|
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()),
|
moderating_communities=moderating_communities(current_user.get_id()),
|
||||||
joined_communities=joined_communities(current_user.get_id()),
|
joined_communities=joined_communities(current_user.get_id()),
|
||||||
menu_topics=menu_topics(),
|
menu_topics=menu_topics(),
|
||||||
|
|
|
@ -10,7 +10,7 @@ from flask_babel import _
|
||||||
from slugify import slugify
|
from slugify import slugify
|
||||||
from sqlalchemy import or_, desc, text
|
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.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.activitypub.util import notify_about_post, make_image_sizes, resolve_remote_post, extract_domain_and_actor
|
||||||
from app.chat.util import send_message
|
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
|
# this is separated out from the route, so it can be used by the
|
||||||
# admin.admin_federation.preload_form as well
|
# admin.admin_federation.preload_form as well
|
||||||
|
@celery.task
|
||||||
def do_subscribe(actor, main_user_name=True):
|
def do_subscribe(actor, main_user_name=True):
|
||||||
remote = False
|
remote = False
|
||||||
actor = actor.strip()
|
actor = actor.strip()
|
||||||
|
@ -457,6 +458,13 @@ def do_subscribe(actor, main_user_name=True):
|
||||||
flash('You joined ' + community.title)
|
flash('You joined ' + community.title)
|
||||||
else:
|
else:
|
||||||
pre_load_message['status'] = 'joined'
|
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)
|
referrer = request.headers.get('Referer', None)
|
||||||
cache.delete_memoized(community_membership, current_user, community)
|
cache.delete_memoized(community_membership, current_user, community)
|
||||||
cache.delete_memoized(joined_communities, current_user.id)
|
cache.delete_memoized(joined_communities, current_user.id)
|
||||||
|
|
|
@ -17,7 +17,10 @@
|
||||||
<hr />
|
<hr />
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="column">
|
<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) }}
|
{{ render_form(preload_form) }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue