diff --git a/README.md b/README.md index 7071cd32..a3292129 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # [tooot](https://tooot.app/) app for Mastodon -[![GPL-3.0](https://img.shields.io/github/license/tooot-app/push?style=flat-square)](LICENSE) ![GitHub issues](https://img.shields.io/github/issues/tooot-app/app?style=flat-square) ![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/tooot-app/app?include_prereleases&style=flat-square) ![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/tooot-app/app?style=flat-square) +[![GPL-3.0](https://img.shields.io/github/license/tooot-app/push?style=flat-square)](LICENSE) ![GitHub issues](https://img.shields.io/github/issues/tooot-app/app?style=flat-square) ![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/tooot-app/app?include_prereleases&style=flat-square) ![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/tooot-app/app?style=flat-square) [![Crowdin](https://badges.crowdin.net/tooot/localized.svg)](https://crowdin.tooot.app/project/tooot) ![GitHub Workflow Status](https://img.shields.io/github/workflow/status/tooot-app/app/build?style=flat-square) ![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/tooot-app/app/build/candidate?label=build%20candidate&style=flat-square) ![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/tooot-app/app/build/release?label=build%20release&style=flat-square) diff --git a/package.json b/package.json index 2766fc3b..70b1b477 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,8 @@ "redux-persist": "^6.0.0", "rn-placeholder": "^3.0.3", "sentry-expo": "^3.0.5", - "tslib": "^2.1.0" + "tslib": "^2.1.0", + "valid-url": "^1.0.9" }, "devDependencies": { "@babel/core": "~7.13.10", @@ -103,6 +104,7 @@ "@types/react-redux": "^7.1.16", "@types/react-test-renderer": "^17.0.1", "@types/react-timeago": "^4.1.2", + "@types/valid-url": "^1.0.3", "@welldone-software/why-did-you-render": "^6.1.1", "babel-jest": "~26.6.3", "babel-plugin-module-resolver": "^4.1.0", diff --git a/src/components/GracefullyImage.tsx b/src/components/GracefullyImage.tsx index ed2deccd..8800c95f 100644 --- a/src/components/GracefullyImage.tsx +++ b/src/components/GracefullyImage.tsx @@ -1,4 +1,3 @@ -import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import React, { useCallback, useMemo, useRef, useState } from 'react' import { diff --git a/src/components/Parse/Emojis.tsx b/src/components/Parse/Emojis.tsx index ab9ffffd..ba18c002 100644 --- a/src/components/Parse/Emojis.tsx +++ b/src/components/Parse/Emojis.tsx @@ -7,6 +7,7 @@ import React, { useMemo } from 'react' import { StyleSheet, Text } from 'react-native' import FastImage from 'react-native-fast-image' import { useSelector } from 'react-redux' +import validUrl from 'valid-url' const regexEmoji = new RegExp(/(:[A-Za-z0-9_]+:)/) @@ -67,25 +68,30 @@ const ParseEmojis = React.memo( const emojiIndex = emojis.findIndex(emoji => { return emojiShortcode === `:${emoji.shortcode}:` }) - return emojiIndex === -1 ? ( - {emojiShortcode} - ) : ( - - {/* When emoji starts a paragraph, lineHeight will break */} - {i === 0 ? : null} - - - ) + if (emojiIndex === -1) { + return {emojiShortcode} + } else { + if (i === 0) { + return + } else { + const uri = reduceMotionEnabled + ? emojis[emojiIndex].static_url + : emojis[emojiIndex].url + if (validUrl.isHttpsUri(uri)) { + return ( + + ) + } else { + return null + } + } + } } else { - return {str} + return {str} } }) ) : ( diff --git a/src/screens/Compose/Root/Footer/Emojis.tsx b/src/screens/Compose/Root/Footer/Emojis.tsx index d2cee289..890d2f6c 100644 --- a/src/screens/Compose/Root/Footer/Emojis.tsx +++ b/src/screens/Compose/Root/Footer/Emojis.tsx @@ -1,13 +1,14 @@ import analytics from '@components/analytics' import haptics from '@components/haptics' +import { useAccessibility } from '@utils/accessibility/AccessibilityManager' import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' import React, { useCallback, useContext, useMemo } from 'react' import { Pressable, SectionList, StyleSheet, Text, View } from 'react-native' -import ComposeContext from '../../utils/createContext' -import updateText from '../../updateText' import FastImage from 'react-native-fast-image' -import { useAccessibility } from '@utils/accessibility/AccessibilityManager' +import validUrl from 'valid-url' +import updateText from '../../updateText' +import ComposeContext from '../../utils/createContext' const SingleEmoji = ({ emoji }: { emoji: Mastodon.Emoji }) => { const { reduceMotionEnabled } = useAccessibility() @@ -21,21 +22,21 @@ const SingleEmoji = ({ emoji }: { emoji: Mastodon.Emoji }) => { newText: `:${emoji.shortcode}:`, type: 'emoji' }) - // composeDispatch({ - // type: 'emoji', - // payload: { ...composeState.emoji, active: false } - // }) haptics('Light') }, [composeState]) - const children = useMemo( - () => ( - - ), - [] - ) + const children = useMemo(() => { + const uri = reduceMotionEnabled ? emoji.static_url : emoji.url + if (validUrl.isHttpsUri(uri)) { + return ( + + ) + } else { + return null + } + }, []) return ( ) diff --git a/yarn.lock b/yarn.lock index c8b46619..89ec14b4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2798,6 +2798,11 @@ resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.0.tgz#7036640b4e21cc2f259ae826ce843d277dad8cff" integrity sha512-RJJrrySY7A8havqpGObOB4W92QXKJo63/jFLLgpvOtsGUqbQZ9Sbgl35KMm1DjC6j7AvmmU2bIno+3IyEaemaw== +"@types/valid-url@^1.0.3": + version "1.0.3" + resolved "https://registry.yarnpkg.com/@types/valid-url/-/valid-url-1.0.3.tgz#a124389fb953559c7f889795a98620e91adb3687" + integrity sha512-+33x29mg+ecU88ODdWpqaie2upIuRkhujVLA7TuJjM823cNMbeggfI6NhxewaRaRF8dy+g33e4uIg/m5Mb3xDQ== + "@types/yargs-parser@*": version "20.2.0" resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-20.2.0.tgz#dd3e6699ba3237f0348cd085e4698780204842f9" @@ -10463,6 +10468,11 @@ v8-to-istanbul@^7.0.0: convert-source-map "^1.6.0" source-map "^0.7.3" +valid-url@^1.0.9: + version "1.0.9" + resolved "https://registry.yarnpkg.com/valid-url/-/valid-url-1.0.9.tgz#1c14479b40f1397a75782f115e4086447433a200" + integrity sha1-HBRHm0DxOXp1eC8RXkCGRHQzogA= + validate-npm-package-license@^3.0.1: version "3.0.4" resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz#fc91f6b9c7ba15c857f4cb2c5defeec39d4f410a"