From 78ca5bbc0b428d03c3f21f8f8a299abd0728ddbf Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Fri, 9 Aug 2024 12:43:12 +0800 Subject: [PATCH] Fix prefs bug - Some prefs returned can be uppercased, so make them lowercase - `postingDefaultLanguage` probably doesn't work anymore every since masto.js upgrade. Sorry! - Add additional checks to make sure prefs from server are not in unexpected forms --- src/components/compose.jsx | 26 +++++++++++++++++++------- src/components/media-post.jsx | 2 +- src/components/status.jsx | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/components/compose.jsx b/src/components/compose.jsx index ac01fe42..e2bee583 100644 --- a/src/components/compose.jsx +++ b/src/components/compose.jsx @@ -289,10 +289,14 @@ function Compose({ focusTextarea(); setVisibility( visibility === 'public' && prefs['posting:default:visibility'] - ? prefs['posting:default:visibility'] + ? prefs['posting:default:visibility'].toLowerCase() : visibility, ); - setLanguage(language || prefs.postingDefaultLanguage || DEFAULT_LANG); + setLanguage( + language || + prefs['posting:default:language']?.toLowerCase() || + DEFAULT_LANG, + ); setSensitive(sensitive && !!spoilerText); } else if (editStatus) { const { visibility, language, sensitive, poll, mediaAttachments } = @@ -316,7 +320,11 @@ function Compose({ focusTextarea(); spoilerTextRef.current.value = spoilerText; setVisibility(visibility); - setLanguage(language || presf.postingDefaultLanguage || DEFAULT_LANG); + setLanguage( + language || + prefs['posting:default:language']?.toLowerCase() || + DEFAULT_LANG, + ); setSensitive(sensitive); if (composablePoll) setPoll(composablePoll); setMediaAttachments(mediaAttachments); @@ -331,13 +339,13 @@ function Compose({ focusTextarea(); console.log('Apply prefs', prefs); if (prefs['posting:default:visibility']) { - setVisibility(prefs['posting:default:visibility']); + setVisibility(prefs['posting:default:visibility'].toLowerCase()); } if (prefs['posting:default:language']) { - setLanguage(prefs['posting:default:language']); + setLanguage(prefs['posting:default:language'].toLowerCase()); } if (prefs['posting:default:sensitive']) { - setSensitive(prefs['posting:default:sensitive']); + setSensitive(!!prefs['posting:default:sensitive']); } } if (draftStatus) { @@ -360,7 +368,11 @@ function Compose({ focusTextarea(); if (spoilerText) spoilerTextRef.current.value = spoilerText; if (visibility) setVisibility(visibility); - setLanguage(language || prefs.postingDefaultLanguage || DEFAULT_LANG); + setLanguage( + language || + prefs['posting:default:language']?.toLowerCase() || + DEFAULT_LANG, + ); if (sensitive !== null) setSensitive(sensitive); if (composablePoll) setPoll(composablePoll); if (mediaAttachments) setMediaAttachments(mediaAttachments); diff --git a/src/components/media-post.jsx b/src/components/media-post.jsx index 91ed67d7..1de082b9 100644 --- a/src/components/media-post.jsx +++ b/src/components/media-post.jsx @@ -108,7 +108,7 @@ function MediaPost({ const readingExpandMedia = useMemo(() => { // default | show_all | hide_all const prefs = store.account.get('preferences') || {}; - return prefs['reading:expand:media'] || 'default'; + return prefs['reading:expand:media']?.toLowerCase() || 'default'; }, []); const showSpoilerMedia = readingExpandMedia === 'show_all'; diff --git a/src/components/status.jsx b/src/components/status.jsx index 555f86b7..03c52a3b 100644 --- a/src/components/status.jsx +++ b/src/components/status.jsx @@ -407,7 +407,7 @@ function Status({ // default | show_all | hide_all // Ignore hide_all because it means hide *ALL* media including non-sensitive ones const prefs = store.account.get('preferences') || {}; - return prefs['reading:expand:media'] || 'default'; + return prefs['reading:expand:media']?.toLowerCase() || 'default'; }, []); // FOR TESTING: // const readingExpandSpoilers = true;