diff --git a/api/typeDefs/user.js b/api/typeDefs/user.js index 3b755e5f..082782bf 100644 --- a/api/typeDefs/user.js +++ b/api/typeDefs/user.js @@ -84,6 +84,7 @@ export default gql` hideIsContributor: Boolean! hideWalletBalance: Boolean! imgproxyOnly: Boolean! + showImagesAndVideos: Boolean! nostrCrossposting: Boolean! nostrPubkey: String nostrRelays: [String!] @@ -155,6 +156,7 @@ export default gql` hideIsContributor: Boolean! hideWalletBalance: Boolean! imgproxyOnly: Boolean! + showImagesAndVideos: Boolean! nostrCrossposting: Boolean! nostrPubkey: String nostrRelays: [String!] diff --git a/components/image.js b/components/image.js index 05860cb0..493f70c5 100644 --- a/components/image.js +++ b/components/image.js @@ -19,13 +19,25 @@ export function decodeOriginalUrl (imgproxyUrl) { return originalUrl } -function ImageOriginal ({ src, topLevel, rel, tab, children, onClick, ...props }) { +function LinkRaw ({ href, children, src, rel, onClick, ...props }) { + const isRawURL = /^https?:\/\//.test(children?.[0]) + return ( + // eslint-disable-next-line + {isRawURL || !children ? src : children} + + ) +} + +function ImageOriginal ({ src, topLevel, tab, onClick, ...props }) { const me = useMe() const [showImage, setShowImage] = useState(false) const [showVideo, setShowVideo] = useState(false) useEffect(() => { - if (me?.privates?.imgproxyOnly && tab !== 'preview') return // make sure it's not a false negative by trying to load URL as const img = new window.Image() img.onload = () => setShowImage(true) @@ -42,7 +54,9 @@ function ImageOriginal ({ src, topLevel, rel, tab, children, onClick, ...props } } }, [src, showImage]) - if (showImage) { + const showMedia = (tab === 'preview' || (me?.privates?.showImagesAndVideos !== false && !me?.privates?.imgproxyOnly)) + + if (showImage && showMedia) { return ( setShowImage(false)} /> ) - } else if (showVideo) { + } else if (showVideo && showMedia) { return } else { // user is not okay with loading original url automatically or there was an error loading the image // If element parsed by markdown is a raw URL, we use src as the text to not mislead users. // This will not be the case if [text](url) format is used. Then we will show what was chosen as text. - const isRawURL = /^https?:\/\//.test(children?.[0]) - return ( - // eslint-disable-next-line - {isRawURL || !children ? src : children} - - ) + return } } @@ -138,6 +143,7 @@ const Image = memo(({ className, src, srcSet, sizes, width, height, onClick, onE export default function ZoomableImage ({ src, srcSet, ...props }) { const showModal = useShowModal() + const me = useMe() // if `srcSet` is falsy, it means the image was not processed by worker yet const [trustedDomain, setTrustedDomain] = useState(!!srcSet || IMGPROXY_URL_REGEXP.test(src) || MEDIA_DOMAIN_REGEXP.test(src)) @@ -171,12 +177,16 @@ export default function ZoomableImage ({ src, srcSet, ...props }) { if (!src) return null if (trustedDomain) { - return ( - - ) + if (props.tab === 'preview' || !me || me.privates.showImagesAndVideos) { + return ( + + ) + } else { + return + } } return diff --git a/fragments/users.js b/fragments/users.js index 154c8672..73cadf09 100644 --- a/fragments/users.js +++ b/fragments/users.js @@ -26,6 +26,7 @@ export const ME = gql` hideWalletBalance hideWelcomeBanner imgproxyOnly + showImagesAndVideos lastCheckedJobs nostrCrossposting noteAllDescendants @@ -98,6 +99,7 @@ export const SETTINGS_FIELDS = gql` hideTwitter hideIsContributor imgproxyOnly + showImagesAndVideos hideWalletBalance diagnostics noReferralLinks diff --git a/pages/settings/index.js b/pages/settings/index.js index c599cb1a..05e2e415 100644 --- a/pages/settings/index.js +++ b/pages/settings/index.js @@ -116,7 +116,7 @@ export default function Settings ({ ssrData }) { tipRandomMin: settings?.tipRandomMin || 1, tipRandomMax: settings?.tipRandomMax || 10, turboTipping: settings?.turboTipping, - disableFreebies: settings?.disableFreebies, + disableFreebies: settings?.disableFreebies || undefined, zapUndos: settings?.zapUndos || (settings?.tipDefault ? 100 * settings.tipDefault : 2100), zapUndosEnabled: settings?.zapUndos !== null, fiatCurrency: settings?.fiatCurrency || 'USD', @@ -140,6 +140,7 @@ export default function Settings ({ ssrData }) { hideNostr: settings?.hideNostr, hideTwitter: settings?.hideTwitter, imgproxyOnly: settings?.imgproxyOnly, + showImagesAndVideos: settings?.showImagesAndVideos, wildWestMode: settings?.wildWestMode, satsFilter: settings?.satsFilter, nsfwMode: settings?.nsfwMode, @@ -508,6 +509,17 @@ export default function Settings ({ ssrData }) { required append={sats} /> + show images and video + + disable to show images and videos as links instead of embedding them + + + } + name='showImagesAndVideos' + groupClassName='mb-0' + /> wild west mode diff --git a/prisma/migrations/20240903235340_hide_images/migration.sql b/prisma/migrations/20240903235340_hide_images/migration.sql new file mode 100644 index 00000000..f5f60153 --- /dev/null +++ b/prisma/migrations/20240903235340_hide_images/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "users" ADD COLUMN "showImagesAndVideos" BOOLEAN NOT NULL DEFAULT true; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 6752baaa..65b4d0f2 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -63,6 +63,7 @@ model User { turboTipping Boolean @default(false) zapUndos Int? imgproxyOnly Boolean @default(false) + showImagesAndVideos Boolean @default(true) hideWalletBalance Boolean @default(false) disableFreebies Boolean? referrerId Int?
disable to show images and videos as links instead of embedding them