Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions __tests__/__snapshots__/settings.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Object {
"flags": Object {
"clickbaitShieldEnabled": null,
"defaultWriteTab": null,
"highlightsFirstEnabled": null,
"sidebarBookmarksExpanded": null,
"sidebarCustomFeedsExpanded": null,
"sidebarOtherExpanded": null,
Expand Down Expand Up @@ -48,6 +49,7 @@ Object {
"flags": Object {
"clickbaitShieldEnabled": null,
"defaultWriteTab": null,
"highlightsFirstEnabled": null,
"sidebarBookmarksExpanded": null,
"sidebarCustomFeedsExpanded": null,
"sidebarOtherExpanded": null,
Expand Down Expand Up @@ -87,6 +89,7 @@ Object {
"flags": Object {
"clickbaitShieldEnabled": null,
"defaultWriteTab": null,
"highlightsFirstEnabled": null,
"sidebarBookmarksExpanded": null,
"sidebarCustomFeedsExpanded": null,
"sidebarOtherExpanded": null,
Expand Down Expand Up @@ -126,6 +129,7 @@ Object {
"flags": Object {
"clickbaitShieldEnabled": null,
"defaultWriteTab": null,
"highlightsFirstEnabled": null,
"sidebarBookmarksExpanded": null,
"sidebarCustomFeedsExpanded": null,
"sidebarOtherExpanded": null,
Expand Down
39 changes: 39 additions & 0 deletions __tests__/integrations/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
Keyword,
PostType,
postTypes,
Settings,
Source,
SourceMember,
User,
Expand Down Expand Up @@ -772,6 +773,44 @@ describe('FeedPreferencesConfigGenerator', () => {
expect(actual.config.experience_level).toBe('MORE_THAN_6_YEARS');
expect(actual.config.country).toBe('US');
});

it('should set highlights_first when user enabled it in settings', async () => {
await con.getRepository(Settings).save({
userId: '1',
flags: { highlightsFirstEnabled: true },
});

const generator: FeedConfigGenerator = new FeedPreferencesConfigGenerator(
config,
);

const actual = await generator.generate(ctx, {
user_id: '1',
page_size: 2,
offset: 3,
});

expect(actual.config.highlights_first).toBe(true);
});

it('should not set highlights_first when setting is disabled', async () => {
await con.getRepository(Settings).save({
userId: '1',
flags: { highlightsFirstEnabled: false },
});

const generator: FeedConfigGenerator = new FeedPreferencesConfigGenerator(
config,
);

const actual = await generator.generate(ctx, {
user_id: '1',
page_size: 2,
offset: 3,
});

expect(actual.config.highlights_first).toBeUndefined();
});
});

describe('FeedLofnConfigGenerator', () => {
Expand Down
21 changes: 21 additions & 0 deletions __tests__/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('mutation updateUserSettings', () => {
sidebarSquadExpanded
sidebarBookmarksExpanded
clickbaitShieldEnabled
highlightsFirstEnabled
defaultWriteTab
}
}
Expand Down Expand Up @@ -157,6 +158,7 @@ describe('mutation updateUserSettings', () => {
sidebarSquadExpanded: null,
sidebarBookmarksExpanded: null,
clickbaitShieldEnabled: null,
highlightsFirstEnabled: null,
defaultWriteTab: null,
});
});
Expand All @@ -176,6 +178,7 @@ describe('mutation updateUserSettings', () => {
sidebarSquadExpanded: null,
sidebarBookmarksExpanded: null,
clickbaitShieldEnabled: null,
highlightsFirstEnabled: null,
defaultWriteTab: null,
});

Expand Down Expand Up @@ -312,10 +315,27 @@ describe('mutation updateUserSettings', () => {
sidebarSquadExpanded: null,
sidebarBookmarksExpanded: null,
clickbaitShieldEnabled: null,
highlightsFirstEnabled: null,
defaultWriteTab: null,
});
});

it('should persist highlightsFirstEnabled in user settings flags', async () => {
loggedUser = '1';

const repo = con.getRepository(Settings);
await repo.save(repo.create({ userId: '1' }));

const res = await client.mutate(MUTATION, {
variables: { data: { flags: { highlightsFirstEnabled: true } } },
});

expect(res.data.updateUserSettings.flags.highlightsFirstEnabled).toBe(true);

const updated = await repo.findOneByOrFail({ userId: '1' });
expect(updated.flags.highlightsFirstEnabled).toBe(true);
});

it('should update but not remove user settings flags', async () => {
loggedUser = '1';

Expand Down Expand Up @@ -347,6 +367,7 @@ describe('mutation updateUserSettings', () => {
sidebarSquadExpanded: null,
sidebarBookmarksExpanded: null,
clickbaitShieldEnabled: null,
highlightsFirstEnabled: null,
defaultWriteTab: null,
});
});
Expand Down
2 changes: 2 additions & 0 deletions src/entity/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type SettingsFlags = Partial<{
sidebarBookmarksExpanded: boolean;
clickbaitShieldEnabled: boolean;
browsingContextEnabled: boolean;
highlightsFirstEnabled: boolean;
prompt: object;
timezoneMismatchIgnore: string;
lastPrompt: string;
Expand All @@ -71,6 +72,7 @@ export type SettingsFlagsPublic = Pick<
| 'sidebarBookmarksExpanded'
| 'clickbaitShieldEnabled'
| 'browsingContextEnabled'
| 'highlightsFirstEnabled'
| 'prompt'
| 'timezoneMismatchIgnore'
| 'lastPrompt'
Expand Down
13 changes: 11 additions & 2 deletions src/integrations/feed/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
FeedVersion,
} from './types';
import { AnonymousFeedFilters, feedToFilters } from '../../common';
import { postTypes } from '../../entity';
import { postTypes, Settings } from '../../entity';
import { User } from '../../entity/user/User';
import { runInSpan } from '../../telemetry';
import { ILofnClient } from '../lofn';
Expand Down Expand Up @@ -215,14 +215,20 @@ export class FeedPreferencesConfigGenerator implements FeedConfigGenerator {
const userId = opts.user_id;
const feedId = this.opts.feedId || userId;

const [filters, user] = await Promise.all([
const [filters, user, settings] = await Promise.all([
feedToFilters(ctx.con, feedId, userId),
userId
? ctx.con.getRepository(User).findOne({
select: ['id', 'experienceLevel', 'flags'],
where: { id: userId },
})
: null,
userId
? ctx.con.getRepository(Settings).findOne({
select: ['userId', 'flags'],
where: { userId },
})
: null,
]);

const config = addFiltersToConfig({
Expand All @@ -237,6 +243,9 @@ export class FeedPreferencesConfigGenerator implements FeedConfigGenerator {
if (user?.flags?.country) {
config.country = user.flags.country;
}
if (settings?.flags?.highlightsFirstEnabled) {
config.highlights_first = true;
}

return { config };
});
Expand Down
1 change: 1 addition & 0 deletions src/integrations/feed/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export type FeedConfig = {
blocked_sources?: string[];
allowed_post_types?: string[];
highlights_limit?: number;
highlights_first?: boolean;
allowed_content_curations?: string[];
blocked_title_words?: string[];
allowed_author_ids?: string[];
Expand Down
2 changes: 2 additions & 0 deletions src/schema/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const typeDefs = /* GraphQL */ `
sidebarBookmarksExpanded: Boolean
clickbaitShieldEnabled: Boolean
browsingContextEnabled: Boolean
highlightsFirstEnabled: Boolean
timezoneMismatchIgnore: String
lastPrompt: String
defaultWriteTab: DefaultWriteTab
Expand All @@ -95,6 +96,7 @@ export const typeDefs = /* GraphQL */ `
sidebarBookmarksExpanded: Boolean
clickbaitShieldEnabled: Boolean
browsingContextEnabled: Boolean
highlightsFirstEnabled: Boolean
prompt: JSONObject
timezoneMismatchIgnore: String
lastPrompt: String
Expand Down
Loading