feat: add home feed preferences settings modal and tuners

This commit is contained in:
Eric Bailey 2023-06-16 14:59:29 -05:00
parent 17e7590bcd
commit 896aea9837
8 changed files with 304 additions and 16 deletions

View file

@ -115,6 +115,12 @@ export class PostsFeedModel {
}
get feedTuners() {
const areRepliesEnabled = this.rootStore.preferences.homeFeedRepliesEnabled
const repliesThreshold = this.rootStore.preferences.homeFeedRepliesThreshold
const areRepostsEnabled = this.rootStore.preferences.homeFeedRepostsEnabled
const areQuotePostsEnabled =
this.rootStore.preferences.homeFeedQuotePostsEnabled
if (this.feedType === 'custom') {
return [
FeedTuner.dedupReposts,
@ -124,7 +130,13 @@ export class PostsFeedModel {
]
}
if (this.feedType === 'home') {
return [FeedTuner.dedupReposts, FeedTuner.likedRepliesOnly]
return [
areRepostsEnabled && FeedTuner.dedupReposts,
!areRepostsEnabled && FeedTuner.removeReposts,
areRepliesEnabled && FeedTuner.likedRepliesOnly({repliesThreshold}),
!areRepliesEnabled && FeedTuner.removeReplies,
!areQuotePostsEnabled && FeedTuner.removeQuotePosts,
].filter(Boolean)
}
return []
}

View file

@ -51,6 +51,10 @@ export class PreferencesModel {
contentLabels = new LabelPreferencesModel()
savedFeeds: string[] = []
pinnedFeeds: string[] = []
homeFeedRepliesEnabled: boolean = true
homeFeedRepliesThreshold: number = 2
homeFeedRepostsEnabled: boolean = true
homeFeedQuotePostsEnabled: boolean = true
// used to linearize async modifications to state
lock = new AwaitLock()
@ -65,6 +69,10 @@ export class PreferencesModel {
contentLabels: this.contentLabels,
savedFeeds: this.savedFeeds,
pinnedFeeds: this.pinnedFeeds,
homeFeedRepliesEnabled: this.homeFeedRepliesEnabled,
homeFeedRepliesThreshold: this.homeFeedRepliesThreshold,
homeFeedRepostsEnabled: this.homeFeedRepostsEnabled,
homeFeedQuotePostsEnabled: this.homeFeedQuotePostsEnabled,
}
}
@ -102,6 +110,30 @@ export class PreferencesModel {
) {
this.pinnedFeeds = v.pinnedFeeds
}
if (
hasProp(v, 'homeFeedRepliesEnabled') &&
typeof v.homeFeedRepliesEnabled === 'boolean'
) {
this.homeFeedRepliesEnabled = v.homeFeedRepliesEnabled
}
if (
hasProp(v, 'homeFeedRepliesThreshold') &&
typeof v.homeFeedRepliesThreshold === 'number'
) {
this.homeFeedRepliesThreshold = v.homeFeedRepliesThreshold
}
if (
hasProp(v, 'homeFeedRepostsEnabled') &&
typeof v.homeFeedRepostsEnabled === 'boolean'
) {
this.homeFeedRepostsEnabled = v.homeFeedRepostsEnabled
}
if (
hasProp(v, 'homeFeedQuotePostsEnabled') &&
typeof v.homeFeedQuotePostsEnabled === 'boolean'
) {
this.homeFeedQuotePostsEnabled = v.homeFeedQuotePostsEnabled
}
}
}
@ -380,4 +412,20 @@ export class PreferencesModel {
this.pinnedFeeds.filter(uri => uri !== v),
)
}
toggleHomeFeedRepliesEnabled() {
this.homeFeedRepliesEnabled = !this.homeFeedRepliesEnabled
}
setHomeFeedRepliesThreshold(threshold: number) {
this.homeFeedRepliesThreshold = threshold
}
toggleHomeFeedRepostsEnabled() {
this.homeFeedRepostsEnabled = !this.homeFeedRepostsEnabled
}
toggleHomeFeedQuotePostsEnabled() {
this.homeFeedQuotePostsEnabled = !this.homeFeedQuotePostsEnabled
}
}

View file

@ -111,6 +111,10 @@ export interface ContentLanguagesSettingsModal {
name: 'content-languages-settings'
}
export interface PreferencesHomeFeed {
name: 'preferences-home-feed'
}
export type Modal =
// Account
| AddAppPasswordModal
@ -121,6 +125,7 @@ export type Modal =
// Curation
| ContentFilteringSettingsModal
| ContentLanguagesSettingsModal
| PreferencesHomeFeed
// Moderation
| ReportAccountModal