mirror of
				https://github.com/tooot-app/app
				synced 2025-06-05 22:19:13 +02:00 
			
		
		
		
	Should fix #484
This commit is contained in:
		| @@ -64,7 +64,7 @@ const AttachmentVideo: React.FC<Props> = ({ | |||||||
|   }, []) |   }, []) | ||||||
|   const _handleAppStateChange = async (nextAppState: AppStateStatus) => { |   const _handleAppStateChange = async (nextAppState: AppStateStatus) => { | ||||||
|     if (appState.current.match(/active/) && nextAppState.match(/inactive/)) { |     if (appState.current.match(/active/) && nextAppState.match(/inactive/)) { | ||||||
|       await videoPlayer.current?.stopAsync() |       // await videoPlayer.current?.stopAsync() | ||||||
|     } else if (gifv && appState.current.match(/background/) && nextAppState.match(/active/)) { |     } else if (gifv && appState.current.match(/background/) && nextAppState.match(/active/)) { | ||||||
|       await videoPlayer.current?.setIsMutedAsync(true) |       await videoPlayer.current?.setIsMutedAsync(true) | ||||||
|       await videoPlayer.current?.playAsync() |       await videoPlayer.current?.playAsync() | ||||||
|   | |||||||
							
								
								
									
										21
									
								
								src/store.ts
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								src/store.ts
									
									
									
									
									
								
							| @@ -4,7 +4,7 @@ import { AnyAction, configureStore, Reducer } from '@reduxjs/toolkit' | |||||||
| import contextsMigration from '@utils/migrations/contexts/migration' | import contextsMigration from '@utils/migrations/contexts/migration' | ||||||
| import instancesMigration from '@utils/migrations/instances/migration' | import instancesMigration from '@utils/migrations/instances/migration' | ||||||
| import settingsMigration from '@utils/migrations/settings/migration' | import settingsMigration from '@utils/migrations/settings/migration' | ||||||
| import appSlice from '@utils/slices/appSlice' | import appSlice, { AppState } from '@utils/slices/appSlice' | ||||||
| import contextsSlice, { ContextsState } from '@utils/slices/contextsSlice' | import contextsSlice, { ContextsState } from '@utils/slices/contextsSlice' | ||||||
| import instancesSlice, { InstancesState } from '@utils/slices/instancesSlice' | import instancesSlice, { InstancesState } from '@utils/slices/instancesSlice' | ||||||
| import settingsSlice, { SettingsState } from '@utils/slices/settingsSlice' | import settingsSlice, { SettingsState } from '@utils/slices/settingsSlice' | ||||||
| @@ -26,6 +26,13 @@ const secureStorage = createSecureStore() | |||||||
|  |  | ||||||
| const prefix = 'tooot' | const prefix = 'tooot' | ||||||
|  |  | ||||||
|  | const appPersistConfig = { | ||||||
|  |   key: 'app', | ||||||
|  |   prefix, | ||||||
|  |   storage: AsyncStorage, | ||||||
|  |   version: 0 | ||||||
|  | } | ||||||
|  |  | ||||||
| const contextsPersistConfig = { | const contextsPersistConfig = { | ||||||
|   key: 'contexts', |   key: 'contexts', | ||||||
|   prefix, |   prefix, | ||||||
| @@ -55,19 +62,19 @@ const settingsPersistConfig = { | |||||||
|  |  | ||||||
| const store = configureStore({ | const store = configureStore({ | ||||||
|   reducer: { |   reducer: { | ||||||
|  |     app: persistReducer(appPersistConfig, appSlice) as Reducer<AppState, AnyAction>, | ||||||
|     contexts: persistReducer(contextsPersistConfig, contextsSlice) as Reducer< |     contexts: persistReducer(contextsPersistConfig, contextsSlice) as Reducer< | ||||||
|       ContextsState, |       ContextsState, | ||||||
|       AnyAction |       AnyAction | ||||||
|     >, |     >, | ||||||
|     instances: persistReducer( |     instances: persistReducer(instancesPersistConfig, instancesSlice) as Reducer< | ||||||
|       instancesPersistConfig, |       InstancesState, | ||||||
|       instancesSlice |       AnyAction | ||||||
|     ) as Reducer<InstancesState, AnyAction>, |     >, | ||||||
|     settings: persistReducer(settingsPersistConfig, settingsSlice) as Reducer< |     settings: persistReducer(settingsPersistConfig, settingsSlice) as Reducer< | ||||||
|       SettingsState, |       SettingsState, | ||||||
|       AnyAction |       AnyAction | ||||||
|     >, |     > | ||||||
|     app: appSlice |  | ||||||
|   }, |   }, | ||||||
|   middleware: getDefaultMiddleware => |   middleware: getDefaultMiddleware => | ||||||
|     getDefaultMiddleware({ |     getDefaultMiddleware({ | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								src/utils/migrations/app/v0.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								src/utils/migrations/app/v0.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | |||||||
|  | export type AppV0 = { | ||||||
|  |   expoToken?: string | ||||||
|  |   versionUpdate: boolean | ||||||
|  | } | ||||||
| @@ -33,53 +33,55 @@ const pushUseConnect = ({ t, instances }: Params) => { | |||||||
|       method: 'get', |       method: 'get', | ||||||
|       url: `push/connect/${expoToken}`, |       url: `push/connect/${expoToken}`, | ||||||
|       sentry: true |       sentry: true | ||||||
|     }).catch(error => { |  | ||||||
|       Sentry.setExtras({ |  | ||||||
|         API: 'tooot', |  | ||||||
|         ...(error?.response && { response: error.response }), |  | ||||||
|         ...(error?.request && { request: error.request }) |  | ||||||
|       }) |  | ||||||
|       Sentry.captureException(error) |  | ||||||
|       Notifications.setBadgeCountAsync(0) |  | ||||||
|       if (error?.status == 404) { |  | ||||||
|         displayMessage({ |  | ||||||
|           theme, |  | ||||||
|           type: 'error', |  | ||||||
|           duration: 'long', |  | ||||||
|           message: t('pushError.message'), |  | ||||||
|           description: t('pushError.description'), |  | ||||||
|           onPress: () => { |  | ||||||
|             navigationRef.navigate('Screen-Tabs', { |  | ||||||
|               screen: 'Tab-Me', |  | ||||||
|               params: { |  | ||||||
|                 screen: 'Tab-Me-Root' |  | ||||||
|               } |  | ||||||
|             }) |  | ||||||
|             navigationRef.navigate('Screen-Tabs', { |  | ||||||
|               screen: 'Tab-Me', |  | ||||||
|               params: { |  | ||||||
|                 screen: 'Tab-Me-Settings' |  | ||||||
|               } |  | ||||||
|             }) |  | ||||||
|           } |  | ||||||
|         }) |  | ||||||
|  |  | ||||||
|         dispatch(disableAllPushes()) |  | ||||||
|  |  | ||||||
|         instances.forEach(instance => { |  | ||||||
|           if (instance.push.global.value) { |  | ||||||
|             apiGeneral<{}>({ |  | ||||||
|               method: 'delete', |  | ||||||
|               domain: instance.url, |  | ||||||
|               url: 'api/v1/push/subscription', |  | ||||||
|               headers: { |  | ||||||
|                 Authorization: `Bearer ${instance.token}` |  | ||||||
|               } |  | ||||||
|             }).catch(() => console.log('error!!!')) |  | ||||||
|           } |  | ||||||
|         }) |  | ||||||
|       } |  | ||||||
|     }) |     }) | ||||||
|  |       .then(() => Notifications.setBadgeCountAsync(0)) | ||||||
|  |       .catch(error => { | ||||||
|  |         Sentry.setExtras({ | ||||||
|  |           API: 'tooot', | ||||||
|  |           ...(error?.response && { response: error.response }), | ||||||
|  |           ...(error?.request && { request: error.request }) | ||||||
|  |         }) | ||||||
|  |         Sentry.captureException(error) | ||||||
|  |         Notifications.setBadgeCountAsync(0) | ||||||
|  |         if (error?.status == 404) { | ||||||
|  |           displayMessage({ | ||||||
|  |             theme, | ||||||
|  |             type: 'error', | ||||||
|  |             duration: 'long', | ||||||
|  |             message: t('pushError.message'), | ||||||
|  |             description: t('pushError.description'), | ||||||
|  |             onPress: () => { | ||||||
|  |               navigationRef.navigate('Screen-Tabs', { | ||||||
|  |                 screen: 'Tab-Me', | ||||||
|  |                 params: { | ||||||
|  |                   screen: 'Tab-Me-Root' | ||||||
|  |                 } | ||||||
|  |               }) | ||||||
|  |               navigationRef.navigate('Screen-Tabs', { | ||||||
|  |                 screen: 'Tab-Me', | ||||||
|  |                 params: { | ||||||
|  |                   screen: 'Tab-Me-Settings' | ||||||
|  |                 } | ||||||
|  |               }) | ||||||
|  |             } | ||||||
|  |           }) | ||||||
|  |  | ||||||
|  |           dispatch(disableAllPushes()) | ||||||
|  |  | ||||||
|  |           instances.forEach(instance => { | ||||||
|  |             if (instance.push.global.value) { | ||||||
|  |               apiGeneral<{}>({ | ||||||
|  |                 method: 'delete', | ||||||
|  |                 domain: instance.url, | ||||||
|  |                 url: 'api/v1/push/subscription', | ||||||
|  |                 headers: { | ||||||
|  |                   Authorization: `Bearer ${instance.token}` | ||||||
|  |                 } | ||||||
|  |               }).catch(() => console.log('error!!!')) | ||||||
|  |             } | ||||||
|  |           }) | ||||||
|  |         } | ||||||
|  |       }) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   const pushEnabled = instances.filter(instance => instance.push.global.value) |   const pushEnabled = instances.filter(instance => instance.push.global.value) | ||||||
| @@ -89,7 +91,6 @@ const pushUseConnect = ({ t, instances }: Params) => { | |||||||
|       if (expoToken && pushEnabled.length && state === 'active') { |       if (expoToken && pushEnabled.length && state === 'active') { | ||||||
|         Notifications.getBadgeCountAsync().then(count => { |         Notifications.getBadgeCountAsync().then(count => { | ||||||
|           if (count > 0) { |           if (count > 0) { | ||||||
|             Notifications.setBadgeCountAsync(0) |  | ||||||
|             connect() |             connect() | ||||||
|           } |           } | ||||||
|         }) |         }) | ||||||
| @@ -102,7 +103,6 @@ const pushUseConnect = ({ t, instances }: Params) => { | |||||||
|   }, [expoToken, pushEnabled.length]) |   }, [expoToken, pushEnabled.length]) | ||||||
|  |  | ||||||
|   return useEffect(() => { |   return useEffect(() => { | ||||||
|     Notifications.setBadgeCountAsync(0) |  | ||||||
|     if (expoToken && pushEnabled.length) { |     if (expoToken && pushEnabled.length) { | ||||||
|       connect() |       connect() | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user