mirror of
				https://github.com/tooot-app/app
				synced 2025-06-05 22:19:13 +02:00 
			
		
		
		
	Basic notification working
This commit is contained in:
		
							
								
								
									
										34
									
								
								src/utils/slices/instances/connectPush.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/utils/slices/instances/connectPush.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
import apiGeneral from '@api/general'
 | 
			
		||||
import { createAsyncThunk } from '@reduxjs/toolkit'
 | 
			
		||||
import { RootState } from '@root/store'
 | 
			
		||||
import * as Notifications from 'expo-notifications'
 | 
			
		||||
import { PUSH_SERVER } from '../instancesSlice'
 | 
			
		||||
 | 
			
		||||
export const connectInstancesPush = createAsyncThunk(
 | 
			
		||||
  'instances/connectPush',
 | 
			
		||||
  async (_, { getState }): Promise<any> => {
 | 
			
		||||
    const state = getState() as RootState
 | 
			
		||||
    const pushEnabled = state.instances.instances.filter(
 | 
			
		||||
      instance => instance.push.global.value
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    if (pushEnabled.length) {
 | 
			
		||||
      const expoToken = (
 | 
			
		||||
        await Notifications.getExpoPushTokenAsync({
 | 
			
		||||
          experienceId: '@xmflsct/tooot'
 | 
			
		||||
        })
 | 
			
		||||
      ).data
 | 
			
		||||
 | 
			
		||||
      return apiGeneral({
 | 
			
		||||
        method: 'post',
 | 
			
		||||
        domain: PUSH_SERVER,
 | 
			
		||||
        url: 'v1/connect',
 | 
			
		||||
        body: {
 | 
			
		||||
          expoToken
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
    } else {
 | 
			
		||||
      return Promise.resolve()
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
)
 | 
			
		||||
		Reference in New Issue
	
	Block a user