Always limit Following replies to the people you follow (#4868)
* Limit feed replies to people you follow * Remove dead codezio/stable
parent
f056cb646e
commit
7f292abf51
|
@ -299,15 +299,7 @@ export class FeedTuner {
|
||||||
return slices
|
return slices
|
||||||
}
|
}
|
||||||
|
|
||||||
static thresholdRepliesOnly({
|
static followedRepliesOnly({userDid}: {userDid: string}) {
|
||||||
userDid,
|
|
||||||
minLikes,
|
|
||||||
followedOnly,
|
|
||||||
}: {
|
|
||||||
userDid: string
|
|
||||||
minLikes: number
|
|
||||||
followedOnly: boolean
|
|
||||||
}) {
|
|
||||||
return (
|
return (
|
||||||
tuner: FeedTuner,
|
tuner: FeedTuner,
|
||||||
slices: FeedViewPostsSlice[],
|
slices: FeedViewPostsSlice[],
|
||||||
|
@ -322,9 +314,7 @@ export class FeedTuner {
|
||||||
if (slice.isRepost) {
|
if (slice.isRepost) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (slice.likeCount < minLikes) {
|
if (!slice.isFollowingAllAuthors(userDid)) {
|
||||||
slices.splice(i, 1)
|
|
||||||
} else if (followedOnly && !slice.isFollowingAllAuthors(userDid)) {
|
|
||||||
slices.splice(i, 1)
|
slices.splice(i, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,11 +38,8 @@ export function useFeedTuners(feedDesc: FeedDescriptor) {
|
||||||
feedTuners.push(FeedTuner.removeReplies)
|
feedTuners.push(FeedTuner.removeReplies)
|
||||||
} else {
|
} else {
|
||||||
feedTuners.push(
|
feedTuners.push(
|
||||||
FeedTuner.thresholdRepliesOnly({
|
FeedTuner.followedRepliesOnly({
|
||||||
userDid: currentAccount?.did || '',
|
userDid: currentAccount?.did || '',
|
||||||
minLikes: preferences?.feedViewPrefs.hideRepliesByLikeCount || 0,
|
|
||||||
followedOnly:
|
|
||||||
!!preferences?.feedViewPrefs.hideRepliesByUnfollowed,
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -66,10 +63,8 @@ export function useFeedTuners(feedDesc: FeedDescriptor) {
|
||||||
feedTuners.push(FeedTuner.removeReplies)
|
feedTuners.push(FeedTuner.removeReplies)
|
||||||
} else {
|
} else {
|
||||||
feedTuners.push(
|
feedTuners.push(
|
||||||
FeedTuner.thresholdRepliesOnly({
|
FeedTuner.followedRepliesOnly({
|
||||||
userDid: currentAccount?.did || '',
|
userDid: currentAccount?.did || '',
|
||||||
minLikes: preferences?.feedViewPrefs.hideRepliesByLikeCount || 0,
|
|
||||||
followedOnly: !!preferences?.feedViewPrefs.hideRepliesByUnfollowed,
|
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@ import {
|
||||||
export const DEFAULT_HOME_FEED_PREFS: UsePreferencesQueryResponse['feedViewPrefs'] =
|
export const DEFAULT_HOME_FEED_PREFS: UsePreferencesQueryResponse['feedViewPrefs'] =
|
||||||
{
|
{
|
||||||
hideReplies: false,
|
hideReplies: false,
|
||||||
hideRepliesByUnfollowed: true,
|
hideRepliesByUnfollowed: true, // Legacy, ignored
|
||||||
hideRepliesByLikeCount: 0,
|
hideRepliesByLikeCount: 0, // Legacy, ignored
|
||||||
hideReposts: false,
|
hideReposts: false,
|
||||||
hideQuotePosts: false,
|
hideQuotePosts: false,
|
||||||
lab_mergeFeedEnabled: false, // experimental
|
lab_mergeFeedEnabled: false, // experimental
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
import React, {useState} from 'react'
|
import React from 'react'
|
||||||
import {StyleSheet, View} from 'react-native'
|
import {StyleSheet, View} from 'react-native'
|
||||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||||
import {msg, Plural, Trans} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {Slider} from '@miblanchard/react-native-slider'
|
|
||||||
import debounce from 'lodash.debounce'
|
|
||||||
|
|
||||||
import {usePalette} from '#/lib/hooks/usePalette'
|
import {usePalette} from '#/lib/hooks/usePalette'
|
||||||
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
|
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
|
||||||
import {CommonNavigatorParams, NativeStackScreenProps} from '#/lib/routes/types'
|
import {CommonNavigatorParams, NativeStackScreenProps} from '#/lib/routes/types'
|
||||||
import {colors, s} from '#/lib/styles'
|
import {colors, s} from '#/lib/styles'
|
||||||
import {isWeb} from '#/platform/detection'
|
|
||||||
import {
|
import {
|
||||||
usePreferencesQuery,
|
usePreferencesQuery,
|
||||||
useSetFeedViewPreferencesMutation,
|
useSetFeedViewPreferencesMutation,
|
||||||
|
@ -21,61 +18,6 @@ import {Text} from '#/view/com/util/text/Text'
|
||||||
import {ScrollView} from '#/view/com/util/Views'
|
import {ScrollView} from '#/view/com/util/Views'
|
||||||
import {atoms as a} from '#/alf'
|
import {atoms as a} from '#/alf'
|
||||||
|
|
||||||
function RepliesThresholdInput({
|
|
||||||
enabled,
|
|
||||||
initialValue,
|
|
||||||
}: {
|
|
||||||
enabled: boolean
|
|
||||||
initialValue: number
|
|
||||||
}) {
|
|
||||||
const pal = usePalette('default')
|
|
||||||
const [value, setValue] = useState(initialValue)
|
|
||||||
const {mutate: setFeedViewPref} = useSetFeedViewPreferencesMutation()
|
|
||||||
const preValue = React.useRef(initialValue)
|
|
||||||
const save = React.useMemo(
|
|
||||||
() =>
|
|
||||||
debounce(
|
|
||||||
threshold =>
|
|
||||||
setFeedViewPref({
|
|
||||||
hideRepliesByLikeCount: threshold,
|
|
||||||
}),
|
|
||||||
500,
|
|
||||||
), // debouce for 500ms
|
|
||||||
[setFeedViewPref],
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View style={[!enabled && styles.dimmed]}>
|
|
||||||
<Slider
|
|
||||||
value={value}
|
|
||||||
onValueChange={(v: number | number[]) => {
|
|
||||||
let threshold = Array.isArray(v) ? v[0] : v
|
|
||||||
if (threshold > preValue.current) threshold = Math.floor(threshold)
|
|
||||||
else threshold = Math.ceil(threshold)
|
|
||||||
|
|
||||||
preValue.current = threshold
|
|
||||||
|
|
||||||
setValue(threshold)
|
|
||||||
save(threshold)
|
|
||||||
}}
|
|
||||||
minimumValue={0}
|
|
||||||
maximumValue={25}
|
|
||||||
containerStyle={isWeb ? undefined : s.flex1}
|
|
||||||
disabled={!enabled}
|
|
||||||
thumbTintColor={colors.blue3}
|
|
||||||
/>
|
|
||||||
<Text type="xs" style={pal.text}>
|
|
||||||
<Plural
|
|
||||||
value={value}
|
|
||||||
_0="Show all replies"
|
|
||||||
one="Show replies with at least # like"
|
|
||||||
other="Show replies with at least # likes"
|
|
||||||
/>
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
type Props = NativeStackScreenProps<
|
type Props = NativeStackScreenProps<
|
||||||
CommonNavigatorParams,
|
CommonNavigatorParams,
|
||||||
'PreferencesFollowingFeed'
|
'PreferencesFollowingFeed'
|
||||||
|
@ -137,51 +79,6 @@ export function PreferencesFollowingFeed({}: Props) {
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<View
|
|
||||||
style={[pal.viewLight, styles.card, !showReplies && styles.dimmed]}>
|
|
||||||
<Text type="title-sm" style={[pal.text, s.pb5]}>
|
|
||||||
<Trans>Reply Filters</Trans>
|
|
||||||
</Text>
|
|
||||||
<Text style={[pal.text, s.pb10]}>
|
|
||||||
<Trans>
|
|
||||||
Enable this setting to only see replies between people you
|
|
||||||
follow.
|
|
||||||
</Trans>
|
|
||||||
</Text>
|
|
||||||
<ToggleButton
|
|
||||||
type="default-light"
|
|
||||||
label={_(msg`Followed users only`)}
|
|
||||||
isSelected={Boolean(
|
|
||||||
variables?.hideRepliesByUnfollowed ??
|
|
||||||
preferences?.feedViewPrefs?.hideRepliesByUnfollowed,
|
|
||||||
)}
|
|
||||||
onPress={
|
|
||||||
showReplies
|
|
||||||
? () =>
|
|
||||||
setFeedViewPref({
|
|
||||||
hideRepliesByUnfollowed: !(
|
|
||||||
variables?.hideRepliesByUnfollowed ??
|
|
||||||
preferences?.feedViewPrefs?.hideRepliesByUnfollowed
|
|
||||||
),
|
|
||||||
})
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
style={[s.mb10]}
|
|
||||||
/>
|
|
||||||
<Text style={[pal.text]}>
|
|
||||||
<Trans>
|
|
||||||
Adjust the number of likes a reply must have to be shown in your
|
|
||||||
feed.
|
|
||||||
</Trans>
|
|
||||||
</Text>
|
|
||||||
{preferences && (
|
|
||||||
<RepliesThresholdInput
|
|
||||||
enabled={showReplies}
|
|
||||||
initialValue={preferences.feedViewPrefs.hideRepliesByLikeCount}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
|
|
||||||
<View style={[pal.viewLight, styles.card]}>
|
<View style={[pal.viewLight, styles.card]}>
|
||||||
<Text type="title-sm" style={[pal.text, s.pb5]}>
|
<Text type="title-sm" style={[pal.text, s.pb5]}>
|
||||||
<Trans>Show Reposts</Trans>
|
<Trans>Show Reposts</Trans>
|
||||||
|
|
Loading…
Reference in New Issue