From 69566283699516e29a81fdefd9d7155085a20cf0 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Sun, 9 Jul 2023 16:32:09 +0800 Subject: [PATCH] Add posting visibility setting Also respect visibility setting when replying *if* replied-to post is public --- src/components/compose.jsx | 6 +++- src/pages/settings.jsx | 62 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/components/compose.jsx b/src/components/compose.jsx index 94c51da1..0da82f4e 100644 --- a/src/components/compose.jsx +++ b/src/components/compose.jsx @@ -178,7 +178,11 @@ function Compose({ oninputTextarea(); } focusTextarea(); - setVisibility(visibility); + setVisibility( + visibility === 'public' && prefs['posting:default:visibility'] + ? prefs['posting:default:visibility'] + : visibility, + ); setLanguage(language || prefs.postingDefaultLanguage || DEFAULT_LANG); setSensitive(sensitive); } else if (editStatus) { diff --git a/src/pages/settings.jsx b/src/pages/settings.jsx index 9dbad5da..58079033 100644 --- a/src/pages/settings.jsx +++ b/src/pages/settings.jsx @@ -7,6 +7,7 @@ import logo from '../assets/logo.svg'; import Icon from '../components/icon'; import RelativeTime from '../components/relative-time'; import targetLanguages from '../data/lingva-target-languages'; +import { api } from '../utils/api'; import getTranslateTargetLanguage from '../utils/get-translate-target-language'; import localeCode2Text from '../utils/localeCode2Text'; import states from '../utils/states'; @@ -25,6 +26,23 @@ function Settings({ onClose }) { const systemTargetLanguageText = localeCode2Text(systemTargetLanguage); const currentTextSize = store.local.get('textSize') || DEFAULT_TEXT_SIZE; + const [prefs, setPrefs] = useState(store.account.get('preferences') || {}); + // Get preferences every time Settings is opened + // NOTE: Disabled for now because I don't expect this to change often. Also for some reason, the /api/v1/preferences endpoint is cached for a while and return old prefs if refresh immediately after changing them. + // useEffect(() => { + // const { masto } = api(); + // (async () => { + // try { + // const preferences = await masto.v1.preferences.fetch(); + // setPrefs(preferences); + // store.account.set('preferences', preferences); + // } catch (e) { + // // Silently fail + // console.error(e); + // } + // })(); + // }, []); + return (
{!!onClose && ( @@ -144,6 +162,50 @@ function Settings({ onClose }) { +

Posting

+
+
    +
  • +
    + +
    +
    + +
    +
  • +
+

Experiments