Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from bluesky-social:main #36

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bskyweb/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
top: 50%;
transform: translateX(-50%) translateY(-50%) translateY(-50px);
}
/* We need this style to prevent web dropdowns from shifting the display when opening */
body {
width: 100%;
}
</style>

{% include "scripts.html" %}
Expand Down
2 changes: 0 additions & 2 deletions src/App.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import * as SplashScreen from 'expo-splash-screen'
import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'

import {useIntentHandler} from '#/lib/hooks/useIntentHandler'
import {QueryProvider} from '#/lib/react-query'
import {
initialize,
Expand Down Expand Up @@ -85,7 +84,6 @@ function InnerApp() {
const theme = useColorModeTheme()
const {_} = useLingui()

useIntentHandler()
const hasCheckedReferrer = useStarterPackEntry()

// init
Expand Down
5 changes: 0 additions & 5 deletions src/App.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {SafeAreaProvider} from 'react-native-safe-area-context'
import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'

import {useIntentHandler} from '#/lib/hooks/useIntentHandler'
import {QueryProvider} from '#/lib/react-query'
import {Provider as StatsigProvider} from '#/lib/statsig/statsig'
import {ThemeProvider} from '#/lib/ThemeContext'
Expand Down Expand Up @@ -42,7 +41,6 @@ import {
import {readLastActiveAccount} from '#/state/session/util'
import {Provider as ShellStateProvider} from '#/state/shell'
import {Provider as ComposerProvider} from '#/state/shell/composer'
import {useComposerKeyboardShortcut} from '#/state/shell/composer/useComposerKeyboardShortcut'
import {Provider as LoggedOutViewProvider} from '#/state/shell/logged-out'
import {Provider as ProgressGuideProvider} from '#/state/shell/progress-guide'
import {Provider as SelectedFeedProvider} from '#/state/shell/selected-feed'
Expand Down Expand Up @@ -72,11 +70,8 @@ function InnerApp() {
const {resumeSession} = useSessionApi()
const theme = useColorModeTheme()
const {_} = useLingui()
useIntentHandler()
const hasCheckedReferrer = useStarterPackEntry()

useComposerKeyboardShortcut()

// init
useEffect(() => {
async function onLaunch(account?: SessionAccount) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {StackActions, useLinkProps} from '@react-navigation/native'

import {BSKY_DOWNLOAD_URL} from '#/lib/constants'
import {useNavigationDeduped} from '#/lib/hooks/useNavigationDeduped'
import {useOpenLink} from '#/lib/hooks/useOpenLink'
import {AllNavigatorParams} from '#/lib/routes/types'
import {shareUrl} from '#/lib/sharing'
import {
Expand All @@ -21,7 +22,6 @@ import {
import {isNative, isWeb} from '#/platform/detection'
import {shouldClickOpenNewTab} from '#/platform/urls'
import {useModalControls} from '#/state/modals'
import {useOpenLink} from '#/state/preferences/in-app-browser'
import {atoms as a, flatten, TextStyleProp, useTheme, web} from '#/alf'
import {Button, ButtonProps} from '#/components/Button'
import {useInteractionState} from '#/components/hooks/useInteractionState'
Expand Down
2 changes: 1 addition & 1 deletion src/components/dms/MessageMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {ChatBskyConvoDefs, RichText} from '@atproto/api'
import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react'

import {useOpenLink} from '#/lib/hooks/useOpenLink'
import {richTextToString} from '#/lib/strings/rich-text-helpers'
import {getTranslatorLink} from '#/locale/helpers'
import {isWeb} from '#/platform/detection'
import {useConvoActive} from '#/state/messages/convo'
import {useLanguagePrefs} from '#/state/preferences'
import {useOpenLink} from '#/state/preferences/in-app-browser'
import {useSession} from '#/state/session'
import * as Toast from '#/view/com/util/Toast'
import {atoms as a, useTheme} from '#/alf'
Expand Down
11 changes: 10 additions & 1 deletion src/lib/hooks/useIntentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ type IntentType = 'compose' | 'verify-email'

const VALID_IMAGE_REGEX = /^[\w.:\-_/]+\|\d+(\.\d+)?\|\d+(\.\d+)?$/

// This needs to stay outside of react to persist between account switches
let previousIntentUrl = ''

export function useIntentHandler() {
const incomingUrl = Linking.useURL()
const composeIntent = useComposeIntent()
Expand Down Expand Up @@ -68,7 +71,13 @@ export function useIntentHandler() {
}
}

if (incomingUrl) handleIncomingURL(incomingUrl)
if (incomingUrl) {
if (previousIntentUrl === incomingUrl) {
return
}
handleIncomingURL(incomingUrl)
previousIntentUrl = incomingUrl
}
}, [incomingUrl, composeIntent, verifyEmailIntent])
}

Expand Down
54 changes: 54 additions & 0 deletions src/lib/hooks/useOpenLink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {useCallback} from 'react'
import {Linking} from 'react-native'
import * as WebBrowser from 'expo-web-browser'

import {
createBskyAppAbsoluteUrl,
isBskyRSSUrl,
isRelativeUrl,
} from '#/lib/strings/url-helpers'
import {isNative} from '#/platform/detection'
import {useModalControls} from '#/state/modals'
import {useInAppBrowser} from '#/state/preferences/in-app-browser'
import {useTheme} from '#/alf'
import {useSheetWrapper} from '#/components/Dialog/sheet-wrapper'

export function useOpenLink() {
const {openModal} = useModalControls()
const enabled = useInAppBrowser()
const t = useTheme()
const sheetWrapper = useSheetWrapper()

const openLink = useCallback(
async (url: string, override?: boolean) => {
if (isBskyRSSUrl(url) && isRelativeUrl(url)) {
url = createBskyAppAbsoluteUrl(url)
}

if (isNative && !url.startsWith('mailto:')) {
if (override === undefined && enabled === undefined) {
openModal({
name: 'in-app-browser-consent',
href: url,
})
return
} else if (override ?? enabled) {
await sheetWrapper(
WebBrowser.openBrowserAsync(url, {
presentationStyle:
WebBrowser.WebBrowserPresentationStyle.PAGE_SHEET,
toolbarColor: t.atoms.bg.backgroundColor,
controlsColor: t.palette.primary_500,
createTask: false,
}),
)
return
}
}
Linking.openURL(url)
},
[enabled, openModal, t, sheetWrapper],
)

return openLink
}
2 changes: 1 addition & 1 deletion src/lib/strings/display-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {ModerationUI} from '@atproto/api'
const CHECK_MARKS_RE = /[\u2705\u2713\u2714\u2611]/gu
const CONTROL_CHARS_RE =
/[\u0000-\u001F\u007F-\u009F\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g
const MULTIPLE_SPACES_RE = /[\s][\s]+/g
const MULTIPLE_SPACES_RE = /[\s][\s\u200B]+/g

export function sanitizeDisplayName(
str: string,
Expand Down
Loading