Skip to content

Commit

Permalink
fix: add allowed_content_curation flag to feed config (#2123)
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelchris authored Aug 13, 2024
1 parent 357151c commit 5923413
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 11 deletions.
44 changes: 44 additions & 0 deletions __tests__/integrations/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ describe('FeedPreferencesConfigGenerator', () => {
defaultEnabledState: true,
options: { type: PostType.Article },
},
{
title: 'News',
group: 'content_curation',
description: '',
defaultEnabledState: true,
options: { type: 'news' },
},
]);
await con.getRepository(FeedAdvancedSettings).save([
{ feedId: '1', advancedSettingsId: 1, enabled: false },
Expand Down Expand Up @@ -222,6 +229,43 @@ describe('FeedPreferencesConfigGenerator', () => {
});
});

it('should generate feed config with blocked content curation', async () => {
await con
.getRepository(FeedAdvancedSettings)
.save([{ feedId: '1', advancedSettingsId: 3, enabled: false }]);
const generator: FeedConfigGenerator = new FeedPreferencesConfigGenerator(
config,
{
includeContentCuration: true,
},
);

const actual = await generator.generate(ctx, {
user_id: '1',
page_size: 2,
offset: 3,
});
expect(actual).toEqual({
config: {
allowed_content_curations: [
'release',
'opinion',
'listicle',
'comparison',
'tutorial',
'story',
'meme',
],
feed_config_name: FeedConfigName.Personalise,
fresh_page_size: '1',
offset: 3,
page_size: 2,
total_pages: 20,
user_id: '1',
},
});
});

it('should generate feed config with blocked tags and sources', async () => {
const generator: FeedConfigGenerator = new FeedPreferencesConfigGenerator(
config,
Expand Down
21 changes: 15 additions & 6 deletions src/integrations/feed/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,21 @@ type Options = {
includeBlockedSources?: boolean;
includeSourceMemberships?: boolean;
includePostTypes?: boolean;
includeBlockedContentCuration?: boolean;
includeContentCuration?: boolean;
feedId?: string;
};

type BaseConfig = Partial<Omit<FeedConfig, 'user_id' | 'page_size' | 'offset'>>;
const AllowedContentCurationTypes = [
'news',
'release',
'opinion',
'listicle',
'comparison',
'tutorial',
'story',
'meme',
] as const;

function getDefaultConfig(
baseConfig: BaseConfig,
Expand Down Expand Up @@ -83,11 +93,10 @@ const addFiltersToConfig = ({
baseConfig.allowed_post_types || postTypes
).filter((x) => !filters.excludeTypes.includes(x));
}
if (
filters.blockedContentCuration?.length &&
opts.includeBlockedContentCuration
) {
baseConfig.blocked_content_curations = filters.blockedContentCuration;
if (filters.blockedContentCuration?.length && opts.includeContentCuration) {
baseConfig.allowed_content_curations = AllowedContentCurationTypes.filter(
(type) => !filters.blockedContentCuration.includes(type),
);
}

return baseConfig;
Expand Down
4 changes: 2 additions & 2 deletions src/integrations/feed/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const opts = {
includeBlockedSources: true,
includeSourceMemberships: true,
includePostTypes: true,
includeBlockedContentCuration: true,
includeContentCuration: true,
};

export const baseFeedConfig: Partial<FeedConfig> = {
Expand All @@ -75,7 +75,7 @@ export const feedGenerators: Partial<Record<FeedVersion, FeedGenerator>> =
includePostTypes: true,
includeBlockedSources: true,
includeBlockedTags: true,
includeBlockedContentCuration: true,
includeContentCuration: true,
},
),
'popular',
Expand Down
2 changes: 1 addition & 1 deletion src/integrations/feed/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export type FeedConfig = {
blocked_tags?: string[];
blocked_sources?: string[];
allowed_post_types?: string[];
blocked_content_curations?: string[];
allowed_content_curations?: string[];
squad_ids?: string[];
providers?: Record<string, FeedProvider>;
source_types?: ('machine' | 'squad')[];
Expand Down
4 changes: 2 additions & 2 deletions src/schema/feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ export const resolvers: IResolvers<any, Context> = traceResolvers({
includePostTypes: true,
includeBlockedSources: true,
includeBlockedTags: true,
includeBlockedContentCuration: true,
includeContentCuration: true,
feedId: feedId,
},
),
Expand Down Expand Up @@ -1347,7 +1347,7 @@ export const resolvers: IResolvers<any, Context> = traceResolvers({
includePostTypes: true,
includeBlockedSources: true,
includeBlockedTags: true,
includeBlockedContentCuration: true,
includeContentCuration: true,
feedFilters: filters,
},
),
Expand Down

0 comments on commit 5923413

Please sign in to comment.