forked from UjjwalTiwari25/Truecaller-clone-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (41 loc) · 1.29 KB
/
index.js
File metadata and controls
53 lines (41 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @format
*/
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import { findUser } from './src/service/authService';
import { storage } from './src/state/storage';
import notifee from '@notifee/react-native'
notifee.onForegroundEvent(({type,details })=>{})
notifee.onBackgroundEvent(({type,details })=>{})
async function onDisplayNotification(user){
await notifee.requestPermission()
const channelId=await notifee.createChannel({
id:'default',
name:'Default Channel'
})
await notifee.displayNotification({
title:`Call From ${user?.name|| "Unknown"} `,
body:`${user?.phoneNumber}`,
android:{
channelId,
smallIcon:'ic_stat_name',
},
});
}
const handleIncomingCall=async data=>{
const accessToken=storage.getString('accessToken')
if(accessToken){
const phoneNumber=data.phoneNumber
const cleanedNumber=phoneNumber.replace(/[^\d]/g,'')
const last10Digit=cleanedNumber.slice(-10)
const user =await findUser(last10Digit)
onDisplayNotification(user)
}
}
AppRegistry.registerComponent(appName, () => App);
AppRegistry.registerHeadlessTask(
'CallBackgroundMessaging',
()=> handleIncomingCall,
)