mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Push error tolerance
This commit is contained in:
@ -2,11 +2,15 @@ import apiGeneral from '@api/general'
|
||||
import { createAsyncThunk } from '@reduxjs/toolkit'
|
||||
import { RootState } from '@root/store'
|
||||
import * as Notifications from 'expo-notifications'
|
||||
import { TFunction } from 'react-i18next'
|
||||
import { PUSH_SERVER } from '../instancesSlice'
|
||||
|
||||
export const connectInstancesPush = createAsyncThunk(
|
||||
'instances/connectPush',
|
||||
async (_, { getState }): Promise<any> => {
|
||||
async (
|
||||
{ mode, t }: { mode: 'light' | 'dark'; t: TFunction<'common'> },
|
||||
{ getState }
|
||||
): Promise<any> => {
|
||||
const state = getState() as RootState
|
||||
const pushEnabled = state.instances.instances.filter(
|
||||
instance => instance.push.global.value
|
||||
|
@ -110,16 +110,30 @@ const pushRegister = async (
|
||||
removeKeys: instancePush.decode.value === false
|
||||
})
|
||||
|
||||
return Promise.resolve(serverRes.body.keys)
|
||||
if (Platform.OS === 'android') {
|
||||
Notifications.setNotificationChannelAsync('follow', {
|
||||
name: 'Follow',
|
||||
importance: Notifications.AndroidImportance.DEFAULT
|
||||
})
|
||||
Notifications.setNotificationChannelAsync('favourite', {
|
||||
name: 'Favourite',
|
||||
importance: Notifications.AndroidImportance.DEFAULT
|
||||
})
|
||||
Notifications.setNotificationChannelAsync('reblog', {
|
||||
name: 'Reblog',
|
||||
importance: Notifications.AndroidImportance.DEFAULT
|
||||
})
|
||||
Notifications.setNotificationChannelAsync('mention', {
|
||||
name: 'Mention',
|
||||
importance: Notifications.AndroidImportance.DEFAULT
|
||||
})
|
||||
Notifications.setNotificationChannelAsync('poll', {
|
||||
name: 'Poll',
|
||||
importance: Notifications.AndroidImportance.DEFAULT
|
||||
})
|
||||
}
|
||||
|
||||
// if (Platform.OS === 'android') {
|
||||
// Notifications.setNotificationChannelAsync('default', {
|
||||
// name: 'default',
|
||||
// importance: Notifications.AndroidImportance.MAX,
|
||||
// vibrationPattern: [0, 250, 250, 250],
|
||||
// lightColor: '#FF231F7C'
|
||||
// })
|
||||
// }
|
||||
return Promise.resolve(serverRes.body.keys)
|
||||
}
|
||||
|
||||
export default pushRegister
|
||||
|
@ -1,9 +1,12 @@
|
||||
import analytics from '@components/analytics'
|
||||
import { displayMessage } from '@components/Message'
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||
import { RootState } from '@root/store'
|
||||
import { ComposeStateDraft } from '@screens/Compose/utils/types'
|
||||
import { findIndex } from 'lodash'
|
||||
import { Appearance } from 'react-native'
|
||||
import addInstance from './instances/add'
|
||||
import { connectInstancesPush } from './instances/connectPush'
|
||||
import removeInstance from './instances/remove'
|
||||
import { updateAccountPreferences } from './instances/updateAccountPreferences'
|
||||
import { updateInstancePush } from './instances/updatePush'
|
||||
@ -264,6 +267,22 @@ const instancesSlice = createSlice({
|
||||
action.meta.arg.changed
|
||||
].loading = true
|
||||
})
|
||||
|
||||
// If Expo token does not exist on the server, disable all existing ones
|
||||
.addCase(connectInstancesPush.rejected, (state, action) => {
|
||||
state.instances = state.instances.map(instance => {
|
||||
let newInstance = instance
|
||||
newInstance.push.global.value = false
|
||||
displayMessage({
|
||||
mode: action.meta.arg.mode,
|
||||
type: 'error',
|
||||
autoHide: false,
|
||||
message: action.meta.arg.t('meSettingsPush:error.message'),
|
||||
description: action.meta.arg.t('meSettingsPush:error.description')
|
||||
})
|
||||
return newInstance
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user