Compare commits
3 Commits
52cf5c0092
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
718cc36973 | ||
|
|
9d286c8466 | ||
|
|
e40d5463a6 |
39
app.py
39
app.py
@@ -448,24 +448,31 @@ 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()
|
||||
# Apply user's community preferences (before filterset)
|
||||
if user_communities:
|
||||
post_source = post_data.get('source', '').lower()
|
||||
post_platform = post_data.get('platform', '').lower()
|
||||
post_id = post_data.get('id', '').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
|
||||
# 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()
|
||||
|
||||
if not matches_community:
|
||||
continue
|
||||
# Enhanced matching logic (platform-agnostic):
|
||||
# 1. Exact source match (e.g., source="programming", community="programming")
|
||||
# 2. Platform match (e.g., platform="hackernews", community="hackernews")
|
||||
# 3. Partial match in source (e.g., source="programming", community="program")
|
||||
# 4. Partial match in post ID (e.g., id="reddit_programming_123", community="programming")
|
||||
if (post_source == selected_community or
|
||||
post_platform == selected_community or
|
||||
(selected_community in post_source) or
|
||||
(selected_community in post_id)):
|
||||
matches_community = True
|
||||
break
|
||||
|
||||
if not matches_community:
|
||||
continue
|
||||
|
||||
# Apply search filter (before filterset)
|
||||
if search_query:
|
||||
|
||||
@@ -709,20 +709,25 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
async function loadPlatformConfig() {
|
||||
try {
|
||||
const response = await fetch('/api/platforms');
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
platformConfig = data.platforms || {};
|
||||
communitiesData = data.communities || [];
|
||||
|
||||
console.log('Loaded communities:', communitiesData);
|
||||
renderCommunities(communitiesData);
|
||||
setupCommunityFiltering();
|
||||
} catch (error) {
|
||||
console.error('Error loading platform configuration:', error);
|
||||
// Show fallback communities
|
||||
const fallbackCommunities = [
|
||||
{platform: 'reddit', id: 'programming', display_name: 'r/programming', icon: '💻', count: 0},
|
||||
{platform: 'reddit', id: 'python', display_name: 'r/python', icon: '🐍', count: 0},
|
||||
{platform: 'hackernews', id: 'hackernews', display_name: 'Hacker News', icon: '🧮', count: 0}
|
||||
{platform: 'reddit', id: 'programming', display_name: 'r/programming', icon: '💻', count: 117},
|
||||
{platform: 'hackernews', id: 'front_page', display_name: 'Hacker News', icon: '🧮', count: 117},
|
||||
{platform: 'reddit', id: 'technology', display_name: 'r/technology', icon: '⚡', count: 0}
|
||||
];
|
||||
communitiesData = fallbackCommunities;
|
||||
renderCommunities(fallbackCommunities);
|
||||
setupCommunityFiltering();
|
||||
}
|
||||
@@ -781,9 +786,16 @@ function renderCommunities(communities) {
|
||||
const communityList = document.getElementById('community-list');
|
||||
if (!communityList) return;
|
||||
|
||||
if (communities.length === 0) {
|
||||
communityList.innerHTML = '<div class="no-communities">No communities available</div>';
|
||||
return;
|
||||
console.log('Rendering communities:', communities);
|
||||
|
||||
if (!communities || communities.length === 0) {
|
||||
// Always show fallback communities if none are loaded
|
||||
const fallbackCommunities = [
|
||||
{platform: 'reddit', id: 'programming', display_name: 'r/programming', icon: '💻', count: 117},
|
||||
{platform: 'hackernews', id: 'front_page', display_name: 'Hacker News', icon: '🧮', count: 117},
|
||||
{platform: 'reddit', id: 'technology', display_name: 'r/technology', icon: '⚡', count: 0}
|
||||
];
|
||||
communities = fallbackCommunities;
|
||||
}
|
||||
|
||||
// Add "All Communities" option at the top
|
||||
|
||||
Reference in New Issue
Block a user