mirror of
https://github.com/tooot-app/app
synced 2025-04-24 07:07:24 +02:00
Refine push
This commit is contained in:
parent
db41e85d07
commit
adddae9d72
@ -1,5 +1,6 @@
|
|||||||
import Button from '@components/Button'
|
import Button from '@components/Button'
|
||||||
import Icon from '@components/Icon'
|
import Icon from '@components/Icon'
|
||||||
|
import { Loading } from '@components/Loading'
|
||||||
import { MenuContainer, MenuRow } from '@components/Menu'
|
import { MenuContainer, MenuRow } from '@components/Menu'
|
||||||
import { displayMessage } from '@components/Message'
|
import { displayMessage } from '@components/Message'
|
||||||
import CustomText from '@components/Text'
|
import CustomText from '@components/Text'
|
||||||
@ -7,7 +8,6 @@ import * as Sentry from '@sentry/react-native'
|
|||||||
import apiInstance from '@utils/api/instance'
|
import apiInstance from '@utils/api/instance'
|
||||||
import apiTooot, { TOOOT_API_DOMAIN } from '@utils/api/tooot'
|
import apiTooot, { TOOOT_API_DOMAIN } from '@utils/api/tooot'
|
||||||
import browserPackage from '@utils/helpers/browserPackage'
|
import browserPackage from '@utils/helpers/browserPackage'
|
||||||
import { isDevelopment } from '@utils/helpers/checkEnvironment'
|
|
||||||
import { PUSH_ADMIN, PUSH_DEFAULT, setChannels } from '@utils/push/constants'
|
import { PUSH_ADMIN, PUSH_DEFAULT, setChannels } from '@utils/push/constants'
|
||||||
import { updateExpoToken } from '@utils/push/updateExpoToken'
|
import { updateExpoToken } from '@utils/push/updateExpoToken'
|
||||||
import { useAppsQuery } from '@utils/queryHooks/apps'
|
import { useAppsQuery } from '@utils/queryHooks/apps'
|
||||||
@ -35,24 +35,7 @@ const TabMePush: React.FC = () => {
|
|||||||
const [accountDomain] = useAccountStorage.string('auth.account.domain')
|
const [accountDomain] = useAccountStorage.string('auth.account.domain')
|
||||||
const [accountId] = useAccountStorage.string('auth.account.id')
|
const [accountId] = useAccountStorage.string('auth.account.id')
|
||||||
|
|
||||||
const appsQuery = useAppsQuery({
|
const appsQuery = useAppsQuery()
|
||||||
options: {
|
|
||||||
enabled: false,
|
|
||||||
onSuccess: async data => {
|
|
||||||
if (data.vapid_key) {
|
|
||||||
await checkPush()
|
|
||||||
if (isDevelopment) {
|
|
||||||
setPushAvailable(true)
|
|
||||||
} else {
|
|
||||||
setPushAvailable(!!expoToken?.length)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
useEffect(() => {
|
|
||||||
appsQuery.refetch()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const checkPush = async () => {
|
const checkPush = async () => {
|
||||||
const permissions = await Notifications.getPermissionsAsync()
|
const permissions = await Notifications.getPermissionsAsync()
|
||||||
@ -61,11 +44,9 @@ const TabMePush: React.FC = () => {
|
|||||||
layoutAnimation()
|
layoutAnimation()
|
||||||
await updateExpoToken()
|
await updateExpoToken()
|
||||||
}
|
}
|
||||||
|
useEffect(() => {
|
||||||
const [pushAvailable, setPushAvailable] = useState<boolean>()
|
checkPush()
|
||||||
const [pushEnabled, setPushEnabled] = useState<boolean>()
|
}, [])
|
||||||
const [pushCanAskAgain, setPushCanAskAgain] = useState<boolean>()
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const subscription = AppState.addEventListener('change', checkPush)
|
const subscription = AppState.addEventListener('change', checkPush)
|
||||||
return () => {
|
return () => {
|
||||||
@ -73,6 +54,9 @@ const TabMePush: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
const [pushEnabled, setPushEnabled] = useState<boolean>()
|
||||||
|
const [pushCanAskAgain, setPushCanAskAgain] = useState<boolean>()
|
||||||
|
|
||||||
const alerts = () =>
|
const alerts = () =>
|
||||||
push?.alerts
|
push?.alerts
|
||||||
? PUSH_DEFAULT().map(alert => (
|
? PUSH_DEFAULT().map(alert => (
|
||||||
@ -133,11 +117,11 @@ const TabMePush: React.FC = () => {
|
|||||||
const pushPath = `${expoToken}/${domain}/${accountId}`
|
const pushPath = `${expoToken}/${domain}/${accountId}`
|
||||||
const accountFull = `@${accountAcct}@${accountDomain}`
|
const accountFull = `@${accountAcct}@${accountDomain}`
|
||||||
|
|
||||||
return (
|
return appsQuery.isFetched ? (
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
{!!appsQuery.data?.vapid_key ? (
|
{!!appsQuery.data?.vapid_key ? (
|
||||||
<>
|
<>
|
||||||
{!!pushAvailable ? (
|
{!!expoToken?.length ? (
|
||||||
<>
|
<>
|
||||||
{pushEnabled === false ? (
|
{pushEnabled === false ? (
|
||||||
<MenuContainer>
|
<MenuContainer>
|
||||||
@ -249,6 +233,7 @@ const TabMePush: React.FC = () => {
|
|||||||
method: 'delete',
|
method: 'delete',
|
||||||
url: 'push/subscription'
|
url: 'push/subscription'
|
||||||
})
|
})
|
||||||
|
return Promise.reject()
|
||||||
})
|
})
|
||||||
|
|
||||||
setAccountStorage([
|
setAccountStorage([
|
||||||
@ -352,6 +337,8 @@ const TabMePush: React.FC = () => {
|
|||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
) : (
|
||||||
|
<Loading style={{ flex: 1 }} />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user