From e702c21f60f9ba63000c6a1f4957772a4be6c12a Mon Sep 17 00:00:00 2001 From: Daniela Henkel Date: Tue, 9 Sep 2025 16:59:41 +0200 Subject: [PATCH] tweak to disable "via repost" notifications --- src/screens/Settings/DeerSettings.tsx | 25 +++++++++ src/state/persisted/schema.ts | 2 + .../disable-via-repost-notification.tsx | 52 +++++++++++++++++++ src/state/preferences/index.tsx | 5 +- src/state/queries/post.ts | 7 ++- 5 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 src/state/preferences/disable-via-repost-notification.tsx diff --git a/src/screens/Settings/DeerSettings.tsx b/src/screens/Settings/DeerSettings.tsx index 082d1a3ed..936c24851 100644 --- a/src/screens/Settings/DeerSettings.tsx +++ b/src/screens/Settings/DeerSettings.tsx @@ -33,6 +33,10 @@ import { useDirectFetchRecords, useSetDirectFetchRecords, } from '#/state/preferences/direct-fetch-records' +import { + useDisableViaRepostNotification, + useSetDisableViaRepostNotification, +} from '#/state/preferences/disable-via-repost-notification' import { useHideFeedsPromoTab, useSetHideFeedsPromoTab, @@ -227,6 +231,9 @@ export function DeerSettingsScreen({}: Props) { const hideFeedsPromoTab = useHideFeedsPromoTab() const setHideFeedsPromoTab = useSetHideFeedsPromoTab() + const disableViaRepostNotification = useDisableViaRepostNotification() + const setDisableViaRepostNotification = useSetDisableViaRepostNotification() + const constellationInstance = useConstellationInstance() const setConstellationInstanceControl = Dialog.useDialogControl() @@ -504,6 +511,24 @@ export function DeerSettingsScreen({}: Props) { + + setDisableViaRepostNotification(value)} + style={[a.w_full]}> + + Disable via repost notifications + + + + + + Forcefully disables the notifications other people receive when + you like/repost a post someone else has reposted for privacy. + + diff --git a/src/state/persisted/schema.ts b/src/state/persisted/schema.ts index 58e7bd742..7b296ff0d 100644 --- a/src/state/persisted/schema.ts +++ b/src/state/persisted/schema.ts @@ -134,6 +134,7 @@ const schema = z.object({ constellationInstance: z.string().optional(), showLinkInHandle: z.boolean().optional(), hideFeedsPromoTab: z.boolean().optional(), + disableViaRepostNotification: z.boolean().optional(), deerVerification: z .object({ enabled: z.boolean(), @@ -204,6 +205,7 @@ export const defaults: Schema = { constellationInstance: 'https://constellation.microcosm.blue/', showLinkInHandle: false, hideFeedsPromoTab: false, + disableViaRepostNotification: false, deerVerification: { enabled: false, // https://social.daniela.lol/profile/did:plc:p2cp5gopk7mgjegy6wadk3ep/post/3lndyqyyr4k2k diff --git a/src/state/preferences/disable-via-repost-notification.tsx b/src/state/preferences/disable-via-repost-notification.tsx new file mode 100644 index 000000000..516aa57ad --- /dev/null +++ b/src/state/preferences/disable-via-repost-notification.tsx @@ -0,0 +1,52 @@ +import React from 'react' + +import * as persisted from '#/state/persisted' + +// Preference: disableViaRepostNotification – when true, disables notifications sent when liking/reposting a post someone else reposted + +type StateContext = persisted.Schema['disableViaRepostNotification'] +// Same setter signature used across other preference modules +type SetContext = (v: persisted.Schema['disableViaRepostNotification']) => void + +const stateContext = React.createContext( + persisted.defaults.disableViaRepostNotification, +) +const setContext = React.createContext( + (_: persisted.Schema['disableViaRepostNotification']) => {}, +) + +export function Provider({children}: React.PropsWithChildren<{}>) { + const [state, setState] = React.useState( + persisted.get('disableViaRepostNotification'), + ) + + const setStateWrapped = React.useCallback( + (value: persisted.Schema['disableViaRepostNotification']) => { + setState(value) + persisted.write('disableViaRepostNotification', value) + }, + [setState], + ) + + React.useEffect(() => { + return persisted.onUpdate('disableViaRepostNotification', next => { + setState(next) + }) + }, [setStateWrapped]) + + return ( + + + {children} + + + ) +} + +export function useDisableViaRepostNotification() { + return React.useContext(stateContext) +} + +export function useSetDisableViaRepostNotification() { + return React.useContext(setContext) +} diff --git a/src/state/preferences/index.tsx b/src/state/preferences/index.tsx index f6c0b32b9..cf80c779d 100644 --- a/src/state/preferences/index.tsx +++ b/src/state/preferences/index.tsx @@ -7,6 +7,7 @@ import {Provider as ConstellationInstanceProvider} from './constellation-instanc import {Provider as DeerVerificationProvider} from './deer-verification' import {Provider as DirectFetchRecordsProvider} from './direct-fetch-records' import {Provider as DisableHapticsProvider} from './disable-haptics' +import {Provider as DisableViaRepostNotificationProvider} from './disable-via-repost-notification' import {Provider as ExternalEmbedsProvider} from './external-embeds-prefs' import {Provider as GoLinksProvider} from './go-links-enabled' import {Provider as HiddenPostsProvider} from './hidden-posts' @@ -69,7 +70,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) { - {children} + + {children} + diff --git a/src/state/queries/post.ts b/src/state/queries/post.ts index e92847e75..3e92aa8ff 100644 --- a/src/state/queries/post.ts +++ b/src/state/queries/post.ts @@ -7,6 +7,7 @@ import {type LogEvents, toClout} from '#/lib/statsig/statsig' import {logger} from '#/logger' import {updatePostShadow} from '#/state/cache/post-shadow' import {type Shadow} from '#/state/cache/types' +import {useDisableViaRepostNotification} from '#/state/preferences/disable-via-repost-notification' import {useAgent, useSession} from '#/state/session' import * as userActionHistory from '#/state/userActionHistory' import {useIsThreadMuted, useSetThreadMute} from '../cache/thread-mutes' @@ -110,6 +111,7 @@ export function usePostLikeMutationQueue( const initialLikeUri = post.viewer?.like const likeMutation = usePostLikeMutation(feedDescriptor, logContext, post) const unlikeMutation = usePostUnlikeMutation(feedDescriptor, logContext) + const disableViaRepostNotification = useDisableViaRepostNotification() const queueToggle = useToggleMutationQueue({ initialState: initialLikeUri, @@ -118,7 +120,7 @@ export function usePostLikeMutationQueue( const {uri: likeUri} = await likeMutation.mutateAsync({ uri: postUri, cid: postCid, - via: viaRepost, + via: disableViaRepostNotification ? undefined : viaRepost, }) userActionHistory.like([postUri]) return likeUri @@ -227,6 +229,7 @@ export function usePostRepostMutationQueue( const initialRepostUri = post.viewer?.repost const repostMutation = usePostRepostMutation(feedDescriptor, logContext) const unrepostMutation = usePostUnrepostMutation(feedDescriptor, logContext) + const disableViaRepostNotification = useDisableViaRepostNotification() const queueToggle = useToggleMutationQueue({ initialState: initialRepostUri, @@ -235,7 +238,7 @@ export function usePostRepostMutationQueue( const {uri: repostUri} = await repostMutation.mutateAsync({ uri: postUri, cid: postCid, - via: viaRepost, + via: disableViaRepostNotification ? undefined : viaRepost, }) return repostUri } else { -- 2.51.2