merge main
This commit is contained in:
+3
-11
@@ -12,7 +12,8 @@ import {
|
|||||||
isExternalUrl,
|
isExternalUrl,
|
||||||
linkRequiresWarning,
|
linkRequiresWarning,
|
||||||
} from '#/lib/strings/url-helpers'
|
} from '#/lib/strings/url-helpers'
|
||||||
import {isNative, isWeb} from '#/platform/detection'
|
import {isNative} from '#/platform/detection'
|
||||||
|
import {shouldClickOpenNewTab} from '#/platform/urls'
|
||||||
import {useModalControls} from '#/state/modals'
|
import {useModalControls} from '#/state/modals'
|
||||||
import {useOpenLink} from '#/state/preferences/in-app-browser'
|
import {useOpenLink} from '#/state/preferences/in-app-browser'
|
||||||
import {useNavigationDeduped} from 'lib/hooks/useNavigationDeduped'
|
import {useNavigationDeduped} from 'lib/hooks/useNavigationDeduped'
|
||||||
@@ -116,16 +117,7 @@ export function useLink({
|
|||||||
if (isExternal) {
|
if (isExternal) {
|
||||||
openLink(href)
|
openLink(href)
|
||||||
} else {
|
} else {
|
||||||
/**
|
const shouldOpenInNewTab = shouldClickOpenNewTab(e)
|
||||||
* A `GestureResponderEvent`, but cast to `any` to avoid using a bunch
|
|
||||||
* of @ts-ignore below.
|
|
||||||
*/
|
|
||||||
const event = e as any
|
|
||||||
const isMiddleClick = isWeb && event.button === 1
|
|
||||||
const isMetaKey =
|
|
||||||
isWeb &&
|
|
||||||
(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey)
|
|
||||||
const shouldOpenInNewTab = isMetaKey || isMiddleClick
|
|
||||||
|
|
||||||
if (isBskyDownloadUrl(href)) {
|
if (isBskyDownloadUrl(href)) {
|
||||||
shareUrl(BSKY_DOWNLOAD_URL)
|
shareUrl(BSKY_DOWNLOAD_URL)
|
||||||
|
|||||||
@@ -72,14 +72,17 @@ export function useNotificationsRegistration() {
|
|||||||
|
|
||||||
export function useRequestNotificationsPermission() {
|
export function useRequestNotificationsPermission() {
|
||||||
const gate = useGate()
|
const gate = useGate()
|
||||||
|
const {currentAccount} = useSession()
|
||||||
|
|
||||||
return async (context: 'StartOnboarding' | 'AfterOnboarding' | 'Login') => {
|
return async (
|
||||||
|
context: 'StartOnboarding' | 'AfterOnboarding' | 'Login' | 'Home',
|
||||||
|
) => {
|
||||||
const permissions = await Notifications.getPermissionsAsync()
|
const permissions = await Notifications.getPermissionsAsync()
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!isNative ||
|
!isNative ||
|
||||||
permissions?.status === 'granted' ||
|
permissions?.status === 'granted' ||
|
||||||
permissions?.status === 'denied'
|
(permissions?.status === 'denied' && !permissions.canAskAgain)
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -95,6 +98,9 @@ export function useRequestNotificationsPermission() {
|
|||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (context === 'Home' && !currentAccount) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const res = await Notifications.requestPermissionsAsync()
|
const res = await Notifications.requestPermissionsAsync()
|
||||||
logEvent('notifications:request', {
|
logEvent('notifications:request', {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export type LogEvents = {
|
|||||||
}
|
}
|
||||||
'notifications:openApp': {}
|
'notifications:openApp': {}
|
||||||
'notifications:request': {
|
'notifications:request': {
|
||||||
context: 'StartOnboarding' | 'AfterOnboarding' | 'Login'
|
context: 'StartOnboarding' | 'AfterOnboarding' | 'Login' | 'Home'
|
||||||
status: 'granted' | 'denied' | 'undetermined'
|
status: 'granted' | 'denied' | 'undetermined'
|
||||||
}
|
}
|
||||||
'state:background:sampled': {
|
'state:background:sampled': {
|
||||||
|
|||||||
+18
-1
@@ -116,7 +116,7 @@ export function sanitizeAppLanguageSetting(appLanguage: string): AppLanguage {
|
|||||||
const langs = appLanguage.split(',').filter(Boolean)
|
const langs = appLanguage.split(',').filter(Boolean)
|
||||||
|
|
||||||
for (const lang of langs) {
|
for (const lang of langs) {
|
||||||
switch (lang) {
|
switch (fixLegacyLanguageCode(lang)) {
|
||||||
case 'en':
|
case 'en':
|
||||||
return AppLanguage.en
|
return AppLanguage.en
|
||||||
case 'ca':
|
case 'ca':
|
||||||
@@ -157,3 +157,20 @@ export function sanitizeAppLanguageSetting(appLanguage: string): AppLanguage {
|
|||||||
}
|
}
|
||||||
return AppLanguage.en
|
return AppLanguage.en
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function fixLegacyLanguageCode(code: string | null): string | null {
|
||||||
|
// handle some legacy code conversions, see https://xml.coverpages.org/iso639a.html
|
||||||
|
if (code === 'in') {
|
||||||
|
// indonesian
|
||||||
|
return 'id'
|
||||||
|
}
|
||||||
|
if (code === 'iw') {
|
||||||
|
// hebrew
|
||||||
|
return 'he'
|
||||||
|
}
|
||||||
|
if (code === 'ji') {
|
||||||
|
// yiddish
|
||||||
|
return 'yi'
|
||||||
|
}
|
||||||
|
return code
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import {Platform} from 'react-native'
|
|||||||
import {isReducedMotion} from 'react-native-reanimated'
|
import {isReducedMotion} from 'react-native-reanimated'
|
||||||
import {getLocales} from 'expo-localization'
|
import {getLocales} from 'expo-localization'
|
||||||
|
|
||||||
|
import {fixLegacyLanguageCode} from '#/locale/helpers'
|
||||||
import {dedupArray} from 'lib/functions'
|
import {dedupArray} from 'lib/functions'
|
||||||
|
|
||||||
export const isIOS = Platform.OS === 'ios'
|
export const isIOS = Platform.OS === 'ios'
|
||||||
@@ -17,7 +18,7 @@ export const isMobileWeb =
|
|||||||
|
|
||||||
export const deviceLocales = dedupArray(
|
export const deviceLocales = dedupArray(
|
||||||
getLocales?.()
|
getLocales?.()
|
||||||
.map?.(locale => locale.languageCode)
|
.map?.(locale => fixLegacyLanguageCode(locale.languageCode))
|
||||||
.filter(code => typeof code === 'string'),
|
.filter(code => typeof code === 'string'),
|
||||||
) as string[]
|
) as string[]
|
||||||
|
|
||||||
|
|||||||
+14
-1
@@ -1,4 +1,5 @@
|
|||||||
import {Linking} from 'react-native'
|
import {GestureResponderEvent, Linking} from 'react-native'
|
||||||
|
|
||||||
import {isNative, isWeb} from './detection'
|
import {isNative, isWeb} from './detection'
|
||||||
|
|
||||||
export async function getInitialURL(): Promise<string | undefined> {
|
export async function getInitialURL(): Promise<string | undefined> {
|
||||||
@@ -23,3 +24,15 @@ export function clearHash() {
|
|||||||
window.location.hash = ''
|
window.location.hash = ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function shouldClickOpenNewTab(e: GestureResponderEvent) {
|
||||||
|
/**
|
||||||
|
* A `GestureResponderEvent`, but cast to `any` to avoid using a bunch
|
||||||
|
* of @ts-ignore below.
|
||||||
|
*/
|
||||||
|
const event = e as any
|
||||||
|
const isMiddleClick = isWeb && event.button === 1
|
||||||
|
const isMetaKey =
|
||||||
|
isWeb && (event.metaKey || event.altKey || event.ctrlKey || event.shiftKey)
|
||||||
|
return isMetaKey || isMiddleClick
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,7 +13,13 @@ export async function write(value: Schema) {
|
|||||||
export async function read(): Promise<Schema | undefined> {
|
export async function read(): Promise<Schema | undefined> {
|
||||||
const rawData = await AsyncStorage.getItem(BSKY_STORAGE)
|
const rawData = await AsyncStorage.getItem(BSKY_STORAGE)
|
||||||
const objData = rawData ? JSON.parse(rawData) : undefined
|
const objData = rawData ? JSON.parse(rawData) : undefined
|
||||||
|
|
||||||
|
// new user
|
||||||
|
if (!objData) return undefined
|
||||||
|
|
||||||
|
// existing user, validate
|
||||||
const parsed = schema.safeParse(objData)
|
const parsed = schema.safeParse(objData)
|
||||||
|
|
||||||
if (parsed.success) {
|
if (parsed.success) {
|
||||||
return objData
|
return objData
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -305,7 +305,13 @@ export const ComposePost = observer(function ComposePost({
|
|||||||
localThumb: undefined,
|
localThumb: undefined,
|
||||||
} as apilib.ExternalEmbedDraft)
|
} as apilib.ExternalEmbedDraft)
|
||||||
}
|
}
|
||||||
setError(cleanError(e.message))
|
let err = cleanError(e.message)
|
||||||
|
if (err.includes('not locate record')) {
|
||||||
|
err = _(
|
||||||
|
msg`We're sorry! The post you are replying to has been deleted.`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
setError(err)
|
||||||
setIsProcessing(false)
|
setIsProcessing(false)
|
||||||
return
|
return
|
||||||
} finally {
|
} finally {
|
||||||
@@ -785,11 +791,12 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
errorLine: {
|
errorLine: {
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
backgroundColor: colors.red1,
|
backgroundColor: colors.red1,
|
||||||
borderRadius: 6,
|
borderRadius: 6,
|
||||||
marginHorizontal: 16,
|
marginHorizontal: 16,
|
||||||
paddingHorizontal: 8,
|
paddingHorizontal: 12,
|
||||||
paddingVertical: 6,
|
paddingVertical: 10,
|
||||||
marginBottom: 8,
|
marginBottom: 8,
|
||||||
},
|
},
|
||||||
reminderLine: {
|
reminderLine: {
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {Pressable, StyleProp, StyleSheet, View, ViewStyle} from 'react-native'
|
import {
|
||||||
|
Linking,
|
||||||
|
Pressable,
|
||||||
|
StyleProp,
|
||||||
|
StyleSheet,
|
||||||
|
View,
|
||||||
|
ViewStyle,
|
||||||
|
} from 'react-native'
|
||||||
import {AtUri} from '@atproto/api'
|
import {AtUri} from '@atproto/api'
|
||||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||||
import {msg, Plural, Trans} from '@lingui/macro'
|
import {msg, Plural, Trans} from '@lingui/macro'
|
||||||
@@ -26,6 +33,7 @@ import {RichText} from '#/components/RichText'
|
|||||||
import {Text} from '../util/text/Text'
|
import {Text} from '../util/text/Text'
|
||||||
import {UserAvatar} from '../util/UserAvatar'
|
import {UserAvatar} from '../util/UserAvatar'
|
||||||
import hairlineWidth = StyleSheet.hairlineWidth
|
import hairlineWidth = StyleSheet.hairlineWidth
|
||||||
|
import {shouldClickOpenNewTab} from '#/platform/urls'
|
||||||
|
|
||||||
export function FeedSourceCard({
|
export function FeedSourceCard({
|
||||||
feedUri,
|
feedUri,
|
||||||
@@ -203,17 +211,30 @@ export function FeedSourceCardLoaded({
|
|||||||
style,
|
style,
|
||||||
{borderTopWidth: hideTopBorder ? 0 : hairlineWidth},
|
{borderTopWidth: hideTopBorder ? 0 : hairlineWidth},
|
||||||
]}
|
]}
|
||||||
onPress={() => {
|
onPress={e => {
|
||||||
|
const shouldOpenInNewTab = shouldClickOpenNewTab(e)
|
||||||
if (feed.type === 'feed') {
|
if (feed.type === 'feed') {
|
||||||
navigation.push('ProfileFeed', {
|
if (shouldOpenInNewTab) {
|
||||||
name: feed.creatorDid,
|
Linking.openURL(
|
||||||
rkey: new AtUri(feed.uri).rkey,
|
`/profile/${feed.creatorDid}/feed/${new AtUri(feed.uri).rkey}`,
|
||||||
})
|
)
|
||||||
|
} else {
|
||||||
|
navigation.push('ProfileFeed', {
|
||||||
|
name: feed.creatorDid,
|
||||||
|
rkey: new AtUri(feed.uri).rkey,
|
||||||
|
})
|
||||||
|
}
|
||||||
} else if (feed.type === 'list') {
|
} else if (feed.type === 'list') {
|
||||||
navigation.push('ProfileList', {
|
if (shouldOpenInNewTab) {
|
||||||
name: feed.creatorDid,
|
Linking.openURL(
|
||||||
rkey: new AtUri(feed.uri).rkey,
|
`/profile/${feed.creatorDid}/lists/${new AtUri(feed.uri).rkey}`,
|
||||||
})
|
)
|
||||||
|
} else {
|
||||||
|
navigation.push('ProfileList', {
|
||||||
|
name: feed.creatorDid,
|
||||||
|
rkey: new AtUri(feed.uri).rkey,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
key={feed.uri}>
|
key={feed.uri}>
|
||||||
|
|||||||
@@ -49,8 +49,7 @@ export function FeedErrorMessage({
|
|||||||
if (
|
if (
|
||||||
typeof knownError !== 'undefined' &&
|
typeof knownError !== 'undefined' &&
|
||||||
knownError !== KnownError.Unknown &&
|
knownError !== KnownError.Unknown &&
|
||||||
(savedFeedConfig?.type === 'feed' ||
|
feedDesc.startsWith('feedgen')
|
||||||
knownError === KnownError.FeedNSFPublic)
|
|
||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<FeedgenErrorMessage
|
<FeedgenErrorMessage
|
||||||
@@ -272,7 +271,7 @@ function detectKnownError(
|
|||||||
) {
|
) {
|
||||||
return KnownError.FeedgenMisconfigured
|
return KnownError.FeedgenMisconfigured
|
||||||
}
|
}
|
||||||
if (error.includes('feed provided an invalid response')) {
|
if (error.includes('invalid response')) {
|
||||||
return KnownError.FeedgenBadResponse
|
return KnownError.FeedgenBadResponse
|
||||||
}
|
}
|
||||||
return KnownError.FeedgenUnknown
|
return KnownError.FeedgenUnknown
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
} from '#/state/shell'
|
} from '#/state/shell'
|
||||||
import {useSelectedFeed, useSetSelectedFeed} from '#/state/shell/selected-feed'
|
import {useSelectedFeed, useSetSelectedFeed} from '#/state/shell/selected-feed'
|
||||||
import {useOTAUpdates} from 'lib/hooks/useOTAUpdates'
|
import {useOTAUpdates} from 'lib/hooks/useOTAUpdates'
|
||||||
|
import {useRequestNotificationsPermission} from 'lib/notifications/notifications'
|
||||||
import {HomeTabNavigatorParams, NativeStackScreenProps} from 'lib/routes/types'
|
import {HomeTabNavigatorParams, NativeStackScreenProps} from 'lib/routes/types'
|
||||||
import {
|
import {
|
||||||
useSetUsedStarterPack,
|
useSetUsedStarterPack,
|
||||||
@@ -71,12 +72,17 @@ function HomeScreenReady({
|
|||||||
const maybeFoundIndex = allFeeds.indexOf(rawSelectedFeed)
|
const maybeFoundIndex = allFeeds.indexOf(rawSelectedFeed)
|
||||||
const selectedIndex = Math.max(0, maybeFoundIndex)
|
const selectedIndex = Math.max(0, maybeFoundIndex)
|
||||||
const selectedFeed = allFeeds[selectedIndex]
|
const selectedFeed = allFeeds[selectedIndex]
|
||||||
|
const requestNotificationsPermission = useRequestNotificationsPermission()
|
||||||
const usedStarterPack = useUsedStarterPack()
|
const usedStarterPack = useUsedStarterPack()
|
||||||
const setUsedStarterPack = useSetUsedStarterPack()
|
const setUsedStarterPack = useSetUsedStarterPack()
|
||||||
|
|
||||||
useSetTitle(pinnedFeedInfos[selectedIndex]?.displayName)
|
useSetTitle(pinnedFeedInfos[selectedIndex]?.displayName)
|
||||||
useOTAUpdates()
|
useOTAUpdates()
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
requestNotificationsPermission('Home')
|
||||||
|
}, [requestNotificationsPermission])
|
||||||
|
|
||||||
const pagerRef = React.useRef<PagerRef>(null)
|
const pagerRef = React.useRef<PagerRef>(null)
|
||||||
const lastPagerReportedIndexRef = React.useRef(selectedIndex)
|
const lastPagerReportedIndexRef = React.useRef(selectedIndex)
|
||||||
React.useLayoutEffect(() => {
|
React.useLayoutEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user