From 0e32cf1c7aed47e76601a1ce170e7ba4bc540594 Mon Sep 17 00:00:00 2001 From: Ido Shamun Date: Mon, 23 Dec 2024 18:36:47 +0200 Subject: [PATCH] refactor: adjustments to popular and my feed settings (#2565) --- __tests__/feeds.ts | 6 +++ src/integrations/feed/configs.ts | 62 ++++++++++++++++++++++++----- src/integrations/feed/generators.ts | 4 +- 3 files changed, 60 insertions(+), 12 deletions(-) diff --git a/__tests__/feeds.ts b/__tests__/feeds.ts index 3ec0d2ed1..a8e4bd2ce 100644 --- a/__tests__/feeds.ts +++ b/__tests__/feeds.ts @@ -441,6 +441,9 @@ describe('query anonymousFeed', () => { fresh_page_size: '4', offset: 0, user_id: '1', + source_types: ['machine', 'squad'], + allowed_languages: ['en'], + min_day_range: 14, }) .reply(200, { data: [{ post_id: 'p1' }, { post_id: 'p4' }], @@ -527,6 +530,9 @@ describe('query anonymousFeed', () => { blocked_tags: ['python', 'java'], blocked_sources: ['a', 'b'], user_id: '1', + source_types: ['machine', 'squad'], + allowed_languages: ['en'], + min_day_range: 14, }) .reply(200, { data: [{ post_id: 'p1' }, { post_id: 'p4' }], diff --git a/src/integrations/feed/configs.ts b/src/integrations/feed/configs.ts index 071901450..e4050e0c2 100644 --- a/src/integrations/feed/configs.ts +++ b/src/integrations/feed/configs.ts @@ -73,6 +73,16 @@ export class SimpleFeedConfigGenerator implements FeedConfigGenerator { } } +const mergeSingleFilter = ( + base: string[] | undefined, + filter: string[] | undefined, +): string[] | undefined => { + if (!filter) { + return base; + } + return base ? Array.from(new Set([...base, ...filter])) : filter; +}; + const addFiltersToConfig = ({ config, filters, @@ -85,16 +95,28 @@ const addFiltersToConfig = ({ const baseConfig = { ...config, ...filters.flags }; if (filters.includeTags?.length && opts.includeAllowedTags) { - baseConfig.allowed_tags = filters.includeTags; + baseConfig.allowed_tags = mergeSingleFilter( + baseConfig.allowed_tags, + filters.includeTags, + ); } if (filters.blockedTags?.length && opts.includeBlockedTags) { - baseConfig.blocked_tags = filters.blockedTags; + baseConfig.blocked_tags = mergeSingleFilter( + baseConfig.blocked_tags, + filters.blockedTags, + ); } if (filters.excludeSources?.length && opts.includeBlockedSources) { - baseConfig.blocked_sources = filters.excludeSources; + baseConfig.blocked_sources = mergeSingleFilter( + baseConfig.blocked_sources, + filters.excludeSources, + ); } if (filters.sourceIds?.length && opts.includeSourceMemberships) { - baseConfig.squad_ids = filters.sourceIds; + baseConfig.squad_ids = mergeSingleFilter( + baseConfig.squad_ids, + filters.sourceIds, + ); } if (filters.excludeTypes?.length && opts.includePostTypes) { baseConfig.allowed_post_types = ( @@ -107,24 +129,42 @@ const addFiltersToConfig = ({ ); } if (filters.blockedContentCuration?.length && opts.includeContentCuration) { - baseConfig.allowed_content_curations = AllowedContentCurationTypes.filter( - (type) => !filters.blockedContentCuration!.includes(type), + baseConfig.allowed_content_curations = mergeSingleFilter( + baseConfig.allowed_content_curations, + AllowedContentCurationTypes.filter( + (type) => !filters.blockedContentCuration!.includes(type), + ), ); } if (filters.blockedWords?.length && opts.includeBlockedWords) { - baseConfig.blocked_title_words = filters.blockedWords; + baseConfig.blocked_title_words = mergeSingleFilter( + baseConfig.blocked_title_words, + filters.blockedWords, + ); } if (filters.followingSources?.length && opts.includeFollowedSources) { - baseConfig.followed_sources = filters.followingSources; + baseConfig.followed_sources = mergeSingleFilter( + baseConfig.followed_sources, + filters.followingSources, + ); } if (filters.followingSources?.length && opts.includeAllowedSources) { - baseConfig.allowed_sources = filters.followingSources; + baseConfig.allowed_sources = mergeSingleFilter( + baseConfig.allowed_sources, + filters.followingSources, + ); } if (filters.followingUsers?.length && opts.includeFollowedUsers) { - baseConfig.followed_user_ids = filters.followingUsers; + baseConfig.followed_user_ids = mergeSingleFilter( + baseConfig.followed_user_ids, + filters.followingUsers, + ); } if (filters.followingUsers?.length && opts.includeAllowedUsers) { - baseConfig.allowed_author_ids = filters.followingUsers; + baseConfig.allowed_author_ids = mergeSingleFilter( + baseConfig.allowed_author_ids, + filters.followingUsers, + ); } return baseConfig; diff --git a/src/integrations/feed/generators.ts b/src/integrations/feed/generators.ts index 7ac656d1a..90989df28 100644 --- a/src/integrations/feed/generators.ts +++ b/src/integrations/feed/generators.ts @@ -86,6 +86,8 @@ const opts: Options = { includePostTypes: true, includeContentCuration: true, includeBlockedWords: true, + includeFollowedSources: true, + includeFollowedUsers: true, }; export const feedGenerators: Partial> = @@ -93,7 +95,7 @@ export const feedGenerators: Partial> = popular: new FeedGenerator( popularFeedClient, new FeedPreferencesConfigGenerator( - {}, + { ...baseFeedConfig, min_day_range: 14 }, { includePostTypes: true, includeBlockedSources: true,