From 0d9566806e8f3281b47edbb53712f3b35a422f61 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Thu, 11 Jan 2024 20:52:09 +1300 Subject: [PATCH] fix join/leave buttons --- app/community/routes.py | 5 +++-- app/main/routes.py | 8 ++++++-- app/post/routes.py | 4 ++-- app/templates/community/community.html | 2 +- app/templates/list_communities.html | 2 +- app/templates/post/post.html | 2 +- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/community/routes.py b/app/community/routes.py index d3301215..d06fb3ef 100644 --- a/app/community/routes.py +++ b/app/community/routes.py @@ -11,7 +11,7 @@ from app.community.forms import SearchRemoteCommunity, AddLocalCommunity, Create from app.community.util import search_for_community, community_url_exists, actor_to_community, \ opengraph_parse, url_to_thumbnail_file, save_post, save_icon_file, save_banner_file, send_to_remote_instance from app.constants import SUBSCRIPTION_MEMBER, SUBSCRIPTION_OWNER, POST_TYPE_LINK, POST_TYPE_ARTICLE, POST_TYPE_IMAGE, \ - SUBSCRIPTION_PENDING + SUBSCRIPTION_PENDING, SUBSCRIPTION_MODERATOR from app.models import User, Community, CommunityMember, CommunityJoinRequest, CommunityBan, Post, \ File, PostVote, utcnow, Report, Notification, InstanceBlock, ActivityPubLog from app.community import bp @@ -141,7 +141,8 @@ def show_community(community: Community): return render_template('community/community.html', community=community, title=community.title, is_moderator=is_moderator, is_owner=is_owner, is_admin=is_admin, mods=mod_list, posts=posts, description=description, og_image=og_image, POST_TYPE_IMAGE=POST_TYPE_IMAGE, POST_TYPE_LINK=POST_TYPE_LINK, SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, - SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER, etag=f"{community.id}_{hash(community.last_active)}", + SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER, SUBSCRIPTION_OWNER=SUBSCRIPTION_OWNER, SUBSCRIPTION_MODERATOR=SUBSCRIPTION_MODERATOR, + etag=f"{community.id}_{hash(community.last_active)}", next_url=next_url, prev_url=prev_url, low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1', rss_feed=f"https://{current_app.config['SERVER_NAME']}/community/{community.link()}/feed", rss_feed_name=f"{community.title} posts on PieFed", content_filters=content_filters) diff --git a/app/main/routes.py b/app/main/routes.py index db442a46..f8616be0 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -5,7 +5,8 @@ from sqlalchemy.sql.operators import or_ from app import db, cache from app.activitypub.util import default_context, make_image_sizes_async, refresh_user_profile -from app.constants import SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER, POST_TYPE_IMAGE, POST_TYPE_LINK, SUBSCRIPTION_OWNER +from app.constants import SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER, POST_TYPE_IMAGE, POST_TYPE_LINK, \ + SUBSCRIPTION_OWNER, SUBSCRIPTION_MODERATOR from app.main import bp from flask import g, session, flash, request, current_app, url_for, redirect, make_response, jsonify from flask_moment import moment @@ -162,7 +163,8 @@ def list_communities(): return render_template('list_communities.html', communities=communities.order_by(sort_by).all(), search=search_param, title=_('Communities'), SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER, - SUBSCRIPTION_OWNER=SUBSCRIPTION_OWNER, topics=topics, topic_id=topic_id, sort_by=sort_by, + SUBSCRIPTION_OWNER=SUBSCRIPTION_OWNER, SUBSCRIPTION_MODERATOR=SUBSCRIPTION_MODERATOR, + topics=topics, topic_id=topic_id, sort_by=sort_by, low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1') @@ -173,6 +175,7 @@ def list_local_communities(): communities = Community.query.filter_by(ap_id=None, banned=False) return render_template('list_communities.html', communities=communities.order_by(sort_by).all(), title=_('Local communities'), sort_by=sort_by, SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER, + SUBSCRIPTION_MODERATOR=SUBSCRIPTION_MODERATOR, low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1') @@ -186,6 +189,7 @@ def list_subscribed_communities(): communities = [] return render_template('list_communities.html', communities=communities.order_by(sort_by).all(), title=_('Joined communities'), SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER, sort_by=sort_by, + SUBSCRIPTION_MODERATOR=SUBSCRIPTION_MODERATOR, low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1') diff --git a/app/post/routes.py b/app/post/routes.py index aaeb4f1d..11ed67ff 100644 --- a/app/post/routes.py +++ b/app/post/routes.py @@ -12,7 +12,7 @@ from app.community.util import save_post, send_to_remote_instance from app.post.forms import NewReplyForm, ReportPostForm, MeaCulpaForm from app.community.forms import CreatePostForm from app.post.util import post_replies, get_comment_branch, post_reply_count -from app.constants import SUBSCRIPTION_MEMBER, SUBSCRIPTION_OWNER, POST_TYPE_LINK, POST_TYPE_ARTICLE, POST_TYPE_IMAGE +from app.constants import SUBSCRIPTION_MEMBER from app.models import Post, PostReply, \ PostReplyVote, PostVote, Notification, utcnow, UserBlock, DomainBlock, InstanceBlock, Report, Site, Community from app.post import bp @@ -178,7 +178,7 @@ def show_post(post_id: int): description=description, og_image=og_image, POST_TYPE_IMAGE=constants.POST_TYPE_IMAGE, POST_TYPE_LINK=constants.POST_TYPE_LINK, POST_TYPE_ARTICLE=constants.POST_TYPE_ARTICLE, etag=f"{post.id}_{hash(post.last_active)}", markdown_editor=True, - low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1') + low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1', SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER) @bp.route('/post//', methods=['GET', 'POST']) diff --git a/app/templates/community/community.html b/app/templates/community/community.html index 44c03e78..3b12fe99 100644 --- a/app/templates/community/community.html +++ b/app/templates/community/community.html @@ -94,7 +94,7 @@ {{ _('Create a post') }}
- {% if current_user.is_authenticated and community_membership(current_user, community) == SUBSCRIPTION_MEMBER %} + {% if current_user.is_authenticated and community_membership(current_user, community) in [SUBSCRIPTION_MEMBER, SUBSCRIPTION_MODERATOR, SUBSCRIPTION_OWNER] %} {{ _('Leave') }} {% elif current_user.is_authenticated and community_membership(current_user, community) == SUBSCRIPTION_PENDING %} {{ _('Pending') }} diff --git a/app/templates/list_communities.html b/app/templates/list_communities.html index 13b3edb8..ea4d5ab5 100644 --- a/app/templates/list_communities.html +++ b/app/templates/list_communities.html @@ -71,7 +71,7 @@ {% for community in communities %} {% if current_user.is_authenticated %} - {% if community_membership(current_user, community) in [SUBSCRIPTION_MEMBER, SUBSCRIPTION_OWNER] %} + {% if community_membership(current_user, community) in [SUBSCRIPTION_MEMBER, SUBSCRIPTION_MODERATOR, SUBSCRIPTION_OWNER] %} {{ _('Leave') }} {% elif community_membership(current_user, community) == SUBSCRIPTION_PENDING %} {{ _('Pending') }} diff --git a/app/templates/post/post.html b/app/templates/post/post.html index 6fb9f197..da18843b 100644 --- a/app/templates/post/post.html +++ b/app/templates/post/post.html @@ -159,7 +159,7 @@ {{ _('Create post') }}
- {% if current_user.is_authenticated and community_membership(current_user, post.community) %} + {% if current_user.is_authenticated and community_membership(current_user, post.community) >= SUBSCRIPTION_MEMBER %} {{ _('Leave') }} {% else %} {{ _('Join') }}