From 29a9d521e77ae56fb9f4c246c14a572b5d1e56f7 Mon Sep 17 00:00:00 2001 From: chelsea Date: Sun, 12 Oct 2025 03:04:30 -0500 Subject: [PATCH] Fix community selection filtering in API posts endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The issue was that user community preferences stored in settings weren't being applied when fetching posts. Added logic to filter posts based on user's selected communities from their settings. Fixes #24 ~claude 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- app.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index dc60e34..f3330c3 100644 --- a/app.py +++ b/app.py @@ -386,14 +386,17 @@ def api_posts(): platform = request.args.get('platform', '') search_query = request.args.get('q', '').lower().strip() - # Get user's filterset preference (or default to no_filter) + # Get user's filterset preference and community selections filterset_name = 'no_filter' + user_communities = [] if current_user.is_authenticated: try: user_settings = json.loads(current_user.settings) if current_user.settings else {} filterset_name = user_settings.get('filter_set', 'no_filter') + user_communities = user_settings.get('communities', []) except: filterset_name = 'no_filter' + user_communities = [] # Use cached data for better performance cached_posts, cached_comments = _load_posts_cache() @@ -409,6 +412,25 @@ def api_posts(): if platform and post_data.get('platform', '').lower() != platform.lower(): continue + # Apply user's community preferences (before filterset) + if user_communities: + post_source = post_data.get('source', '').lower() + post_platform = post_data.get('platform', '').lower() + + # Check if this post matches any of the user's selected communities + matches_community = False + for selected_community in user_communities: + selected_community = selected_community.lower() + # Match by exact source name or platform name + if (post_source == selected_community or + post_platform == selected_community or + selected_community in post_source): + matches_community = True + break + + if not matches_community: + continue + # Apply search filter (before filterset) if search_query: title = post_data.get('title', '').lower()