diff --git a/app/community/routes.py b/app/community/routes.py index 1e4c94d7..7f48d7fb 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -352,6 +352,36 @@ def unsubscribe(actor): abort(404) +@bp.route('//join_then_add', methods=['GET', 'POST']) +@login_required +@validation_required +def join_then_add(actor): + community = actor_to_community(actor) + if not current_user.subscribed(community.id): + if not community.is_local(): + # send ActivityPub message to remote community, asking to follow. Accept message will be sent to our shared inbox + join_request = CommunityJoinRequest(user_id=current_user.id, community_id=community.id) + db.session.add(join_request) + db.session.commit() + follow = { + "actor": f"https://{current_app.config['SERVER_NAME']}/u/{current_user.user_name}", + "to": [community.ap_profile_id], + "object": community.ap_profile_id, + "type": "Follow", + "id": f"https://{current_app.config['SERVER_NAME']}/activities/follow/{join_request.id}" + } + success = post_request(community.ap_inbox_url, follow, current_user.private_key, + current_user.profile_id() + '#main-key') + member = CommunityMember(user_id=current_user.id, community_id=community.id) + db.session.add(member) + db.session.commit() + flash('You joined ' + community.title) + if not community.user_is_banned(current_user): + return redirect(url_for('community.add_post', actor=community.link())) + else: + abort(401) + + @bp.route('//submit', methods=['GET', 'POST']) @login_required @validation_required diff --git a/app/static/js/scripts.js b/app/static/js/scripts.js index f56738f7..32d3c7ba 100644 --- a/app/static/js/scripts.js +++ b/app/static/js/scripts.js @@ -9,6 +9,7 @@ document.addEventListener("DOMContentLoaded", function () { setupMobileNav(); setupLightDark(); setupKeyboardShortcuts(); + setupTopicChooser(); }); @@ -487,6 +488,26 @@ function setupKeyboardShortcuts() { }); } +function setupTopicChooser() { + // at /topic/news/submit, clicking on an anchor element needs to save the clicked community id to a hidden field and then submit the form + var chooseTopicLinks = document.querySelectorAll('a.choose_topic_for_post'); + chooseTopicLinks.forEach(function(link) { + link.addEventListener('click', function(event) { + event.preventDefault(); + var communityIdInput = document.getElementById('community_id'); + var communityForm = document.getElementById('choose_community'); + + // Set the value of the hidden input field + if (communityIdInput) { + communityIdInput.value = this.getAttribute('data-id'); + } + if (communityForm) { + communityForm.submit(); + } + }); + }); +} + function formatTime(seconds) { const hours = Math.floor(seconds / 3600); const minutes = Math.floor((seconds % 3600) / 60); diff --git a/app/static/structure.css b/app/static/structure.css index 3648d938..0cbff03e 100644 --- a/app/static/structure.css +++ b/app/static/structure.css @@ -1164,4 +1164,12 @@ fieldset legend { top: 0; } +#choose_community table th { + white-space: nowrap; + overflow: hidden; +} +#choose_community table th img { + vertical-align: middle; +} + /*# sourceMappingURL=structure.css.map */ diff --git a/app/static/structure.scss b/app/static/structure.scss index f1c3f7da..7dc9d2f8 100644 --- a/app/static/structure.scss +++ b/app/static/structure.scss @@ -849,3 +849,13 @@ fieldset { .skip-link:focus { top: 0; } + +#choose_community { + table th { + white-space: nowrap; + overflow: hidden; + img { + vertical-align: middle; + } + } +} diff --git a/app/templates/community/community.html b/app/templates/community/community.html index fa79dc53..28cc9672 100644 --- a/app/templates/community/community.html +++ b/app/templates/community/community.html @@ -105,7 +105,7 @@
{% if current_user.is_authenticated and community_membership(current_user, community) in [SUBSCRIPTION_MEMBER, SUBSCRIPTION_MODERATOR, SUBSCRIPTION_OWNER] %} diff --git a/app/templates/topic/show_topic.html b/app/templates/topic/show_topic.html index 49a09092..977ae796 100644 --- a/app/templates/topic/show_topic.html +++ b/app/templates/topic/show_topic.html @@ -52,6 +52,18 @@