From d081c3aa2e93696395a51d125790da2b8a10d941 Mon Sep 17 00:00:00 2001 From: Vika Date: Sat, 4 Oct 2025 00:06:45 +0300 Subject: [PATCH] Tweak to auto-like what you repost I heard it's common etiquette. Nevertheless, it is disabled by default to avoid surprising users. --- src/components/PostControls/index.tsx | 14 ++ src/screens/Settings/RunesSettings.tsx | 18 ++ src/state/persisted/schema.ts | 4 + src/state/preferences/auto-like-on-repost.tsx | 61 ++++++ src/state/preferences/index.tsx | 193 +++++++++--------- 5 files changed, 195 insertions(+), 95 deletions(-) create mode 100644 src/state/preferences/auto-like-on-repost.tsx diff --git a/src/components/PostControls/index.tsx b/src/components/PostControls/index.tsx index 47c1134ab..faad388aa 100644 --- a/src/components/PostControls/index.tsx +++ b/src/components/PostControls/index.tsx @@ -34,6 +34,7 @@ import {useFormatPostStatCount} from '#/components/PostControls/util' import * as Skele from '#/components/Skeleton' import * as Toast from '#/components/Toast' import {useAnalytics} from '#/analytics' +import {useAutoLikeOnRepost} from '../../state/preferences/auto-like-on-repost.tsx' import {BookmarkButton} from './BookmarkButton' import { PostControlButton, @@ -114,6 +115,8 @@ let PostControls = ({ const disableReplyMetrics = useDisableReplyMetrics() const disableQuotesMetrics = useDisableQuotesMetrics() + const autoLikeOnRepost = useAutoLikeOnRepost() + const onPressToggleLike = async () => { if (isBlocked) { Toast.show(l`Cannot interact with a blocked user`, { @@ -162,6 +165,17 @@ let PostControls = ({ reqId, }) await queueRepost() + setHasLikeIconBeenToggled(true) + if (!post.viewer?.like && autoLikeOnRepost) { + sendInteraction({ + item: post.uri, + event: 'app.bsky.feed.defs#interactionLike', + feedContext, + reqId, + }) + captureAction(ProgressGuideAction.Like) + await queueLike() + } } else { await queueUnrepost() } diff --git a/src/screens/Settings/RunesSettings.tsx b/src/screens/Settings/RunesSettings.tsx index b36813654..f9550d5ed 100644 --- a/src/screens/Settings/RunesSettings.tsx +++ b/src/screens/Settings/RunesSettings.tsx @@ -172,6 +172,10 @@ import * as Layout from '#/components/Layout' import {InlineLinkText} from '#/components/Link' import {Text} from '#/components/Typography' import {IS_WEB} from '#/env' +import { + useAutoLikeOnRepost, + useSetAutoLikeOnRepost, +} from '../../state/preferences/auto-like-on-repost.tsx' import {SearchProfileCard} from '../Search/components/SearchProfileCard' type Props = NativeStackScreenProps @@ -829,6 +833,9 @@ export function RunesSettingsScreen({}: Props) { const setOpenRouterModelControl = Dialog.useDialogControl() const openRouterConfigured = useOpenRouterConfigured() + const autoLikeOnRepost = useAutoLikeOnRepost() + const setAutoLikeOnRepost = useSetAutoLikeOnRepost() + return ( @@ -1096,6 +1103,17 @@ export function RunesSettingsScreen({}: Props) { longer to load and use more bandwidth. + setAutoLikeOnRepost(value)} + style={[a.w_full]}> + + Auto-like what you repost + + + @@ -333,6 +335,8 @@ export const defaults: Schema = { postName: 'skeet', postsName: 'skeets', }, + + autoLikeOnRepost: false, } export function tryParse(rawData: string): Schema | undefined { diff --git a/src/state/preferences/auto-like-on-repost.tsx b/src/state/preferences/auto-like-on-repost.tsx new file mode 100644 index 000000000..c19c542c7 --- /dev/null +++ b/src/state/preferences/auto-like-on-repost.tsx @@ -0,0 +1,61 @@ +import { + createContext, + useCallback, + useContext, + useEffect, + useState, +} from 'react' + +import * as persisted from '#/state/persisted' + +type StateContext = persisted.Schema['autoLikeOnRepost'] +type SetContext = (v: persisted.Schema['autoLikeOnRepost']) => void + +const stateContext = createContext( + persisted.defaults.autoLikeOnRepost, +) +stateContext.displayName = 'AutoLikeOnRepostStateContext' +const setContext = createContext( + (_: persisted.Schema['autoLikeOnRepost']) => {}, +) +setContext.displayName = 'AutoLikeOnRepostStateContext' + +export function Provider({children}: React.PropsWithChildren<{}>) { + const [state, setState] = useState(persisted.get('autoLikeOnRepost')) + + const setStateWrapped = useCallback( + (autoLikeOnRepost: persisted.Schema['autoLikeOnRepost']) => { + setState(autoLikeOnRepost) + persisted.write('autoLikeOnRepost', autoLikeOnRepost) + }, + [setState], + ) + + useEffect(() => { + return persisted.onUpdate('autoLikeOnRepost', nextAutoLikeOnRepost => { + setState(nextAutoLikeOnRepost) + }) + }, [setStateWrapped]) + + return ( + + + {children} + + + ) +} + +export function useAutoLikeOnRepost() { + return useContext(stateContext) +} + +export function useSetAutoLikeOnRepost() { + return useContext(setContext) +} + +export function getAutoLikeOnRepost() { + return ( + persisted.get('autoLikeOnRepost') || persisted.defaults.autoLikeOnRepost! + ) +} diff --git a/src/state/preferences/index.tsx b/src/state/preferences/index.tsx index ee4021fc5..d2c38a1d8 100644 --- a/src/state/preferences/index.tsx +++ b/src/state/preferences/index.tsx @@ -1,4 +1,5 @@ import {Provider as AltTextRequiredProvider} from './alt-text-required' +import {Provider as AutoLikeOnRepostProvider} from './auto-like-on-repost' import {Provider as AutoplayProvider} from './autoplay' import {Provider as ConstellationProvider} from './constellation-enabled' import {Provider as ConstellationInstanceProvider} from './constellation-instance' @@ -91,101 +92,103 @@ export function Provider({children}: React.PropsWithChildren<{}>) { return ( - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - { - children - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + { + children + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ) -- 2.51.2