mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Attempt to fix #596
This commit is contained in:
parent
a0bfb6cb24
commit
5e90a0d8f3
@ -8,12 +8,7 @@ import { isDevelopment } from '@utils/checkEnvironment'
|
|||||||
import { useAppsQuery } from '@utils/queryHooks/apps'
|
import { useAppsQuery } from '@utils/queryHooks/apps'
|
||||||
import { useProfileQuery } from '@utils/queryHooks/profile'
|
import { useProfileQuery } from '@utils/queryHooks/profile'
|
||||||
import { getExpoToken, retrieveExpoToken } from '@utils/slices/appSlice'
|
import { getExpoToken, retrieveExpoToken } from '@utils/slices/appSlice'
|
||||||
import {
|
import { PUSH_ADMIN, PUSH_DEFAULT, usePushFeatures } from '@utils/slices/instances/push/utils'
|
||||||
PUSH_ADMIN,
|
|
||||||
PUSH_DEFAULT,
|
|
||||||
setChannels,
|
|
||||||
usePushFeatures
|
|
||||||
} from '@utils/slices/instances/push/utils'
|
|
||||||
import { updateInstancePush } from '@utils/slices/instances/updatePush'
|
import { updateInstancePush } from '@utils/slices/instances/updatePush'
|
||||||
import { updateInstancePushAlert } from '@utils/slices/instances/updatePushAlert'
|
import { updateInstancePushAlert } from '@utils/slices/instances/updatePushAlert'
|
||||||
import { updateInstancePushDecode } from '@utils/slices/instances/updatePushDecode'
|
import { updateInstancePushDecode } from '@utils/slices/instances/updatePushDecode'
|
||||||
@ -25,7 +20,7 @@ import * as Notifications from 'expo-notifications'
|
|||||||
import * as WebBrowser from 'expo-web-browser'
|
import * as WebBrowser from 'expo-web-browser'
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { AppState, Linking, Platform, ScrollView, View } from 'react-native'
|
import { AppState, Linking, ScrollView, View } from 'react-native'
|
||||||
import { useSelector } from 'react-redux'
|
import { useSelector } from 'react-redux'
|
||||||
|
|
||||||
const TabMePush: React.FC = () => {
|
const TabMePush: React.FC = () => {
|
||||||
@ -50,11 +45,7 @@ const TabMePush: React.FC = () => {
|
|||||||
setPushEnabled(permissions.granted)
|
setPushEnabled(permissions.granted)
|
||||||
setPushCanAskAgain(permissions.canAskAgain)
|
setPushCanAskAgain(permissions.canAskAgain)
|
||||||
layoutAnimation()
|
layoutAnimation()
|
||||||
|
dispatch(retrieveExpoToken())
|
||||||
if (Platform.OS === 'android') {
|
|
||||||
await setChannels(instance)
|
|
||||||
dispatch(retrieveExpoToken())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appsQuery.data?.vapid_key) {
|
if (appsQuery.data?.vapid_key) {
|
||||||
|
@ -27,7 +27,7 @@ const TabMeSettingsLanguage: React.FC<TabMeStackScreenProps<'Tab-Me-Settings-Lan
|
|||||||
|
|
||||||
// Update Android notification channel language
|
// Update Android notification channel language
|
||||||
if (Platform.OS === 'android') {
|
if (Platform.OS === 'android') {
|
||||||
instances.forEach(setChannels)
|
instances.forEach(instance => setChannels(instance, true))
|
||||||
}
|
}
|
||||||
|
|
||||||
navigation.pop(1)
|
navigation.pop(1)
|
||||||
|
@ -2,18 +2,35 @@ import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'
|
|||||||
import { RootState } from '@root/store'
|
import { RootState } from '@root/store'
|
||||||
import { isDevelopment } from '@utils/checkEnvironment'
|
import { isDevelopment } from '@utils/checkEnvironment'
|
||||||
import * as Notifications from 'expo-notifications'
|
import * as Notifications from 'expo-notifications'
|
||||||
|
import { Platform } from 'react-native'
|
||||||
|
import { setChannels } from './instances/push/utils'
|
||||||
|
import { getInstance } from './instancesSlice'
|
||||||
|
|
||||||
export const retrieveExpoToken = createAsyncThunk('app/expoToken', async (): Promise<string> => {
|
export const retrieveExpoToken = createAsyncThunk(
|
||||||
if (isDevelopment) {
|
'app/expoToken',
|
||||||
return 'ExponentPushToken[DEVELOPMENT_1]'
|
async (_, { getState }): Promise<string> => {
|
||||||
|
const instance = getInstance(getState() as RootState)
|
||||||
|
const expoToken = getExpoToken(getState() as RootState)
|
||||||
|
|
||||||
|
if (Platform.OS === 'android') {
|
||||||
|
await setChannels(instance)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expoToken?.length) {
|
||||||
|
return expoToken
|
||||||
|
} else {
|
||||||
|
if (isDevelopment) {
|
||||||
|
return 'ExponentPushToken[DEVELOPMENT_1]'
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await Notifications.getExpoPushTokenAsync({
|
||||||
|
experienceId: '@xmflsct/tooot',
|
||||||
|
applicationId: 'com.xmflsct.app.tooot'
|
||||||
|
})
|
||||||
|
return res.data
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
)
|
||||||
const res = await Notifications.getExpoPushTokenAsync({
|
|
||||||
experienceId: '@xmflsct/tooot',
|
|
||||||
applicationId: 'com.xmflsct.app.tooot'
|
|
||||||
})
|
|
||||||
return res.data
|
|
||||||
})
|
|
||||||
|
|
||||||
export type AppState = {
|
export type AppState = {
|
||||||
expoToken?: string
|
expoToken?: string
|
||||||
|
@ -28,7 +28,7 @@ const subscribe = async ({
|
|||||||
}) => {
|
}) => {
|
||||||
return apiTooot({
|
return apiTooot({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url: `/push/subscribe/${expoToken}/${instanceUrl}/${accountId}`,
|
url: `push/subscribe/${expoToken}/${instanceUrl}/${accountId}`,
|
||||||
body: { accountFull, serverKey, auth }
|
body: { accountFull, serverKey, auth }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ const pushRegister = async (
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (Platform.OS === 'android') {
|
if (Platform.OS === 'android') {
|
||||||
setChannels(instance)
|
setChannels(instance, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve(auth)
|
return Promise.resolve(auth)
|
||||||
|
@ -21,7 +21,7 @@ const pushUnregister = async (state: RootState, expoToken: string) => {
|
|||||||
|
|
||||||
await apiTooot<{ endpoint: string; publicKey: string; auth: string }>({
|
await apiTooot<{ endpoint: string; publicKey: string; auth: string }>({
|
||||||
method: 'delete',
|
method: 'delete',
|
||||||
url: `/push/unsubscribe/${expoToken}/${instance.url}/${instance.account.id}`
|
url: `push/unsubscribe/${expoToken}/${instance.url}/${instance.account.id}`
|
||||||
})
|
})
|
||||||
|
|
||||||
if (Platform.OS === 'android') {
|
if (Platform.OS === 'android') {
|
||||||
|
@ -62,7 +62,7 @@ export const PUSH_ADMIN = (
|
|||||||
}
|
}
|
||||||
}) as { type: 'admin.sign_up' | 'admin.report'; permission: number }[]
|
}) as { type: 'admin.sign_up' | 'admin.report'; permission: number }[]
|
||||||
|
|
||||||
export const setChannels = async (instance: InstanceLatest) => {
|
export const setChannels = async (instance: InstanceLatest, reset: boolean | undefined = false) => {
|
||||||
const account = `@${instance.account.acct}@${instance.uri}`
|
const account = `@${instance.account.acct}@${instance.uri}`
|
||||||
|
|
||||||
const deleteChannel = async (type: string) =>
|
const deleteChannel = async (type: string) =>
|
||||||
@ -82,6 +82,9 @@ export const setChannels = async (instance: InstanceLatest) => {
|
|||||||
const profileQuery = await queryClient.fetchQuery(queryKey, queryFunctionProfile)
|
const profileQuery = await queryClient.fetchQuery(queryKey, queryFunctionProfile)
|
||||||
|
|
||||||
const channelGroup = await Notifications.getNotificationChannelGroupAsync(account)
|
const channelGroup = await Notifications.getNotificationChannelGroupAsync(account)
|
||||||
|
if (channelGroup && !reset) {
|
||||||
|
return
|
||||||
|
}
|
||||||
if (!channelGroup) {
|
if (!channelGroup) {
|
||||||
await Notifications.setNotificationChannelGroupAsync(account, { name: account })
|
await Notifications.setNotificationChannelGroupAsync(account, { name: account })
|
||||||
}
|
}
|
||||||
|
@ -25,14 +25,14 @@ export const updateInstancePushDecode = createAsyncThunk(
|
|||||||
|
|
||||||
await apiTooot({
|
await apiTooot({
|
||||||
method: 'put',
|
method: 'put',
|
||||||
url: `/push/update-decode/${expoToken}/${instance.url}/${instance.account.id}`,
|
url: `push/update-decode/${expoToken}/${instance.url}/${instance.account.id}`,
|
||||||
body: {
|
body: {
|
||||||
auth: !disable ? null : instance.push.keys.auth
|
auth: !disable ? null : instance.push.keys.auth
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (Platform.OS === 'android') {
|
if (Platform.OS === 'android') {
|
||||||
setChannels(instance)
|
setChannels(instance, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.resolve({ disable })
|
return Promise.resolve({ disable })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user