mirror of
https://github.com/tooot-app/app
synced 2025-02-02 11:36:56 +01:00
Fix Sentry errors
This commit is contained in:
parent
44aff1f283
commit
3691b19a87
@ -54,12 +54,12 @@ const handleError =
|
||||
console.error(ctx.bold(' API '), ctx.bold('request'), error)
|
||||
|
||||
shouldReportToSentry && Sentry.captureMessage(config.message)
|
||||
return Promise.reject()
|
||||
return Promise.reject(error)
|
||||
} else {
|
||||
console.error(ctx.bold(' API '), ctx.bold('internal'), error?.message)
|
||||
|
||||
shouldReportToSentry && Sentry.captureMessage(config.message)
|
||||
return Promise.reject()
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
import * as Sentry from '@sentry/react-native'
|
||||
import { mapEnvironment } from '@utils/checkEnvironment'
|
||||
import axios from 'axios'
|
||||
import { ctx, handleError, userAgent } from './helpers'
|
||||
@ -37,7 +36,7 @@ const apiTooot = async <T = unknown>({
|
||||
)
|
||||
|
||||
return axios({
|
||||
timeout: method === 'post' ? 1000 * 60 : 1000 * 15,
|
||||
timeout: method === 'post' ? 1000 * 60 : 1000 * 30,
|
||||
method,
|
||||
baseURL: `https://${TOOOT_API_DOMAIN}/`,
|
||||
url: `${url}`,
|
||||
|
@ -276,7 +276,7 @@ const ComponentInstance: React.FC<Props> = ({
|
||||
style={{ color: colors.blue }}
|
||||
onPress={async () =>
|
||||
WebBrowser.openBrowserAsync('https://tooot.app/privacy-policy', {
|
||||
browserPackage: await browserPackage()
|
||||
...(await browserPackage())
|
||||
})
|
||||
}
|
||||
/>,
|
||||
@ -285,7 +285,7 @@ const ComponentInstance: React.FC<Props> = ({
|
||||
style={{ color: colors.blue }}
|
||||
onPress={async () =>
|
||||
WebBrowser.openBrowserAsync('https://tooot.app/terms-of-service', {
|
||||
browserPackage: await browserPackage()
|
||||
...(await browserPackage())
|
||||
})
|
||||
}
|
||||
/>
|
||||
|
@ -55,10 +55,10 @@ const TimelineDefault: React.FC<Props> = ({
|
||||
const status = item.reblog ? item.reblog : item
|
||||
const ownAccount = status.account?.id === instanceAccount?.id
|
||||
const [spoilerExpanded, setSpoilerExpanded] = useState(
|
||||
instanceAccount?.preferences['reading:expand:spoilers'] || false
|
||||
instanceAccount?.preferences?.['reading:expand:spoilers'] || false
|
||||
)
|
||||
const spoilerHidden = status.spoiler_text?.length
|
||||
? !instanceAccount?.preferences['reading:expand:spoilers'] && !spoilerExpanded
|
||||
? !instanceAccount?.preferences?.['reading:expand:spoilers'] && !spoilerExpanded
|
||||
: false
|
||||
const copiableContent = useRef<{ content: string; complete: boolean }>({
|
||||
content: '',
|
||||
|
@ -42,10 +42,10 @@ const TimelineNotifications: React.FC<Props> = ({ notification, queryKey }) => {
|
||||
: notification.account
|
||||
const ownAccount = notification.account?.id === instanceAccount?.id
|
||||
const [spoilerExpanded, setSpoilerExpanded] = useState(
|
||||
instanceAccount.preferences['reading:expand:spoilers'] || false
|
||||
instanceAccount.preferences?.['reading:expand:spoilers'] || false
|
||||
)
|
||||
const spoilerHidden = notification.status?.spoiler_text?.length
|
||||
? !instanceAccount.preferences['reading:expand:spoilers'] && !spoilerExpanded
|
||||
? !instanceAccount.preferences?.['reading:expand:spoilers'] && !spoilerExpanded
|
||||
: false
|
||||
const copiableContent = useRef<{ content: string; complete: boolean }>({
|
||||
content: '',
|
||||
|
@ -31,10 +31,10 @@ const TimelineAttachment = () => {
|
||||
const account = useSelector(
|
||||
getInstanceAccount,
|
||||
(prev, next) =>
|
||||
prev.preferences['reading:expand:media'] === next.preferences['reading:expand:media']
|
||||
prev.preferences?.['reading:expand:media'] === next.preferences?.['reading:expand:media']
|
||||
)
|
||||
const defaultSensitive = () => {
|
||||
switch (account.preferences['reading:expand:media']) {
|
||||
switch (account.preferences?.['reading:expand:media']) {
|
||||
case 'show_all':
|
||||
return false
|
||||
case 'hide_all':
|
||||
|
@ -47,7 +47,7 @@ const TimelineContent: React.FC<Props> = ({ notificationOwnToot = false, setSpoi
|
||||
mentions={status.mentions}
|
||||
tags={status.tags}
|
||||
numberOfLines={
|
||||
instanceAccount.preferences['reading:expand:spoilers'] || inThread
|
||||
instanceAccount.preferences?.['reading:expand:spoilers'] || inThread
|
||||
? notificationOwnToot
|
||||
? 2
|
||||
: 999
|
||||
|
@ -65,7 +65,7 @@ const TimelineHeaderNotification: React.FC<Props> = ({ notification }) => {
|
||||
`https://${url}/admin/reports/${notification.report.id}`,
|
||||
'tooot://tooot',
|
||||
{
|
||||
browserPackage: await browserPackage(),
|
||||
...(await browserPackage()),
|
||||
dismissButtonStyle: 'done',
|
||||
readerMode: false
|
||||
}
|
||||
|
@ -7,41 +7,40 @@ import { useTranslation } from 'react-i18next'
|
||||
import { View } from 'react-native'
|
||||
|
||||
export interface Props {
|
||||
account: Mastodon.Account
|
||||
account?: Mastodon.Account
|
||||
withoutName?: boolean // For notification follow request etc.
|
||||
}
|
||||
|
||||
const HeaderSharedAccount = React.memo(
|
||||
({ account, withoutName = false }: Props) => {
|
||||
const { t } = useTranslation('componentTimeline')
|
||||
const { colors } = useTheme()
|
||||
const HeaderSharedAccount: React.FC<Props> = ({ account, withoutName = false }) => {
|
||||
if (!account) return null
|
||||
|
||||
return (
|
||||
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
||||
{withoutName ? null : (
|
||||
<CustomText
|
||||
accessibilityHint={t('shared.header.shared.account.name.accessibilityHint')}
|
||||
style={{ marginRight: StyleConstants.Spacing.XS }}
|
||||
numberOfLines={1}
|
||||
>
|
||||
<ParseEmojis
|
||||
content={account?.display_name || account?.username}
|
||||
emojis={account?.emojis}
|
||||
fontBold
|
||||
/>
|
||||
</CustomText>
|
||||
)}
|
||||
const { t } = useTranslation('componentTimeline')
|
||||
const { colors } = useTheme()
|
||||
|
||||
return (
|
||||
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
||||
{withoutName ? null : (
|
||||
<CustomText
|
||||
accessibilityHint={t('shared.header.shared.account.account.accessibilityHint')}
|
||||
style={{ flexShrink: 1, color: colors.secondary }}
|
||||
accessibilityHint={t('shared.header.shared.account.name.accessibilityHint')}
|
||||
style={{ marginRight: StyleConstants.Spacing.XS }}
|
||||
numberOfLines={1}
|
||||
>
|
||||
@{account.acct}
|
||||
<ParseEmojis
|
||||
content={account.display_name || account.username}
|
||||
emojis={account.emojis}
|
||||
fontBold
|
||||
/>
|
||||
</CustomText>
|
||||
</View>
|
||||
)
|
||||
},
|
||||
() => true
|
||||
)
|
||||
)}
|
||||
<CustomText
|
||||
accessibilityHint={t('shared.header.shared.account.account.accessibilityHint')}
|
||||
style={{ flexShrink: 1, color: colors.secondary }}
|
||||
numberOfLines={1}
|
||||
>
|
||||
@{account.acct}
|
||||
</CustomText>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
export default HeaderSharedAccount
|
||||
|
@ -41,7 +41,7 @@ const menuAccount = ({
|
||||
|
||||
const menus: ContextMenu[][] = [[]]
|
||||
|
||||
const instanceAccount = useSelector(getInstanceAccount, (prev, next) => prev.id === next.id)
|
||||
const instanceAccount = useSelector(getInstanceAccount)
|
||||
const ownAccount = instanceAccount?.id === account.id
|
||||
|
||||
const [enabled, setEnabled] = useState(openChange)
|
||||
|
@ -92,7 +92,7 @@ const openLink = async (url: string, navigation?: any) => {
|
||||
await WebBrowser.openBrowserAsync(encodeURI(url), {
|
||||
dismissButtonStyle: 'close',
|
||||
enableBarCollapsing: true,
|
||||
browserPackage: await browserPackage()
|
||||
...(await browserPackage())
|
||||
})
|
||||
break
|
||||
case 'external':
|
||||
|
@ -1,16 +1,18 @@
|
||||
import * as WebBrowser from 'expo-web-browser'
|
||||
import { Platform } from 'react-native'
|
||||
|
||||
const browserPackage = async () => {
|
||||
let browserPackage: string | undefined
|
||||
const browserPackage = async (): Promise<{ browserPackage?: string }> => {
|
||||
if (Platform.OS === 'android') {
|
||||
const tabsSupportingBrowsers = await WebBrowser.getCustomTabsSupportingBrowsersAsync()
|
||||
browserPackage =
|
||||
tabsSupportingBrowsers?.preferredBrowserPackage ||
|
||||
tabsSupportingBrowsers.browserPackages[0] ||
|
||||
tabsSupportingBrowsers.servicePackages[0]
|
||||
return {
|
||||
browserPackage:
|
||||
tabsSupportingBrowsers?.preferredBrowserPackage ||
|
||||
tabsSupportingBrowsers.browserPackages[0] ||
|
||||
tabsSupportingBrowsers.servicePackages[0]
|
||||
}
|
||||
} else {
|
||||
return {}
|
||||
}
|
||||
return browserPackage
|
||||
}
|
||||
|
||||
export default browserPackage
|
||||
|
@ -7,9 +7,8 @@ import { ComposeState } from './types'
|
||||
const assignVisibility = (
|
||||
target: ComposeState['visibility']
|
||||
): Pick<ComposeState, 'visibility' | 'visibilityLock'> => {
|
||||
const accountPreference = getInstanceAccount(store.getState())?.preferences[
|
||||
'posting:default:visibility'
|
||||
]
|
||||
const accountPreference =
|
||||
getInstanceAccount(store.getState())?.preferences?.['posting:default:visibility'] || 'public'
|
||||
|
||||
switch (target) {
|
||||
case 'direct':
|
||||
|
@ -179,7 +179,7 @@ const TabMePush: React.FC = () => {
|
||||
iconBack='ExternalLink'
|
||||
onPress={async () =>
|
||||
WebBrowser.openBrowserAsync('https://tooot.app/how-push-works', {
|
||||
browserPackage: await browserPackage()
|
||||
...(await browserPackage())
|
||||
})
|
||||
}
|
||||
/>
|
||||
|
@ -31,7 +31,7 @@ const Settings: React.FC = () => {
|
||||
`https://${url}/settings/preferences`,
|
||||
'tooot://tooot',
|
||||
{
|
||||
browserPackage: await browserPackage(),
|
||||
...(await browserPackage()),
|
||||
dismissButtonStyle: 'done',
|
||||
readerMode: false
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ const SettingsTooot: React.FC = () => {
|
||||
})
|
||||
} else {
|
||||
WebBrowser.openBrowserAsync('https://social.xmflsct.com/@tooot', {
|
||||
browserPackage: await browserPackage()
|
||||
...(await browserPackage())
|
||||
})
|
||||
}
|
||||
}}
|
||||
|
@ -14,7 +14,7 @@ export type InstanceV11 = {
|
||||
id: Mastodon.Account['id']
|
||||
acct: Mastodon.Account['acct']
|
||||
avatarStatic: Mastodon.Account['avatar_static']
|
||||
preferences: Mastodon.Preferences
|
||||
preferences?: Mastodon.Preferences
|
||||
}
|
||||
version: string
|
||||
configuration?: Mastodon.Instance['configuration']
|
||||
|
@ -1,12 +1,13 @@
|
||||
import apiGeneral from '@api/general'
|
||||
import { handleError } from '@api/helpers'
|
||||
import apiTooot from '@api/tooot'
|
||||
import { displayMessage } from '@components/Message'
|
||||
import navigationRef from '@helpers/navigationRef'
|
||||
import { useAppDispatch } from '@root/store'
|
||||
import * as Sentry from '@sentry/react-native'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { getExpoToken, retrieveExpoToken } from '@utils/slices/appSlice'
|
||||
import { disableAllPushes, getInstances } from '@utils/slices/instancesSlice'
|
||||
import { AxiosError } from 'axios'
|
||||
import * as Notifications from 'expo-notifications'
|
||||
import { useEffect } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
@ -25,16 +26,22 @@ const pushUseConnect = () => {
|
||||
const instances = useSelector(getInstances, (prev, next) => prev.length === next.length)
|
||||
const pushEnabled = instances.filter(instance => instance.push.global)
|
||||
|
||||
const connect = () => {
|
||||
apiTooot({
|
||||
method: 'get',
|
||||
url: `/push/connect/${expoToken}`
|
||||
})
|
||||
.then(() => Notifications.setBadgeCountAsync(0))
|
||||
.catch(error => {
|
||||
handleError({ message: 'Push connect error', captureResponse: true })
|
||||
|
||||
Notifications.setBadgeCountAsync(0)
|
||||
const connectQuery = useQuery<any, AxiosError>(
|
||||
['tooot', { endpoint: 'push/connect' }],
|
||||
() =>
|
||||
apiTooot<Mastodon.Status>({
|
||||
method: 'get',
|
||||
url: `push/connect/${expoToken}`
|
||||
}),
|
||||
{
|
||||
enabled: false,
|
||||
retry: 10,
|
||||
retryOnMount: false,
|
||||
refetchOnMount: false,
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
onSettled: () => Notifications.setBadgeCountAsync(0),
|
||||
onError: error => {
|
||||
if (error?.status == 404) {
|
||||
displayMessage({
|
||||
type: 'danger',
|
||||
@ -72,21 +79,22 @@ const pushUseConnect = () => {
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
Sentry.setContext('Push', { expoToken, pushEnabledCount: pushEnabled.length })
|
||||
|
||||
if (expoToken && pushEnabled.length) {
|
||||
connect()
|
||||
connectQuery.refetch()
|
||||
}
|
||||
|
||||
const appStateListener = AppState.addEventListener('change', state => {
|
||||
if (expoToken && pushEnabled.length && state === 'active') {
|
||||
Notifications.getBadgeCountAsync().then(count => {
|
||||
if (count > 0) {
|
||||
connect()
|
||||
connectQuery.refetch()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -220,7 +220,8 @@ const instancesSlice = createSlice({
|
||||
// Update Instance Configuration
|
||||
.addCase(updateConfiguration.fulfilled, (state, action) => {
|
||||
const activeIndex = findInstanceActive(state.instances)
|
||||
state.instances[activeIndex].version = action.payload?.version || '0'
|
||||
state.instances[activeIndex].version =
|
||||
typeof action.payload.version === 'string' ? action.payload.version : '0'
|
||||
state.instances[activeIndex].configuration = action.payload.configuration
|
||||
})
|
||||
.addCase(updateConfiguration.rejected, (_, action) => {
|
||||
@ -250,6 +251,9 @@ const instancesSlice = createSlice({
|
||||
.addCase(checkEmojis.fulfilled, (state, action) => {
|
||||
if (!action.payload || !action.payload.length) return
|
||||
const activeIndex = findInstanceActive(state.instances)
|
||||
if (!Array.isArray(state.instances[activeIndex].frequentEmojis)) {
|
||||
state.instances[activeIndex].frequentEmojis = []
|
||||
}
|
||||
state.instances[activeIndex].frequentEmojis = state.instances[
|
||||
activeIndex
|
||||
]?.frequentEmojis?.filter(emoji => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user