-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
90 lines (85 loc) · 2.74 KB
/
index.js
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* This is the source code of Moon Meet CrossPlatform.
* It is licensed under GNU GPL v. 3.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Rayen Sbai, 2021-2023.
*/
import {AppRegistry} from 'react-native';
import OneSignal from 'react-native-onesignal';
import App from './src/App';
import {name as MoonMeet} from './app.json';
import {ONESIGNAL_APP_ID} from 'secrets/sensitive';
import notifee, {AndroidImportance, AndroidStyle} from '@notifee/react-native';
/**
* Notifee message channel
*/
notifee.isChannelCreated('messages').then(created => {
if (created) {
if (__DEV__) {
console.log('channelId: messages - is already created.');
}
} else {
notifee
.createChannel({
id: 'messages',
name: 'Messages',
lights: true,
vibration: true,
importance: AndroidImportance.HIGH,
})
.then(() => {
if (__DEV__) {
console.log('messages channel created.');
}
});
}
});
/**
*Initialize OneSignal
*/
OneSignal.setAppId(ONESIGNAL_APP_ID);
OneSignal.setLanguage('en');
OneSignal.setNotificationWillShowInForegroundHandler(
async notificationReceivedEvent => {
let NotificationAdditionalData =
notificationReceivedEvent?.getNotification()?.additionalData;
if (NotificationAdditionalData?.type === 'chat') {
if (NotificationAdditionalData?.messageDelivered) {
await notifee.displayNotification({
title: `${NotificationAdditionalData?.senderName}`,
body: `New message from ${NotificationAdditionalData?.senderName}`,
android: {
channelId: 'messages',
largeIcon: NotificationAdditionalData?.senderPhoto,
timestamp: NotificationAdditionalData?.messageTime,
showTimestamp: true,
smallIcon: 'moon_icon',
style: {
type: AndroidStyle.BIGTEXT,
text: `${NotificationAdditionalData?.messageDelivered}`,
},
},
});
} else if (NotificationAdditionalData?.imageDelivered) {
await notifee.displayNotification({
title: `${NotificationAdditionalData?.senderName}`,
body: `${NotificationAdditionalData?.imageDelivered}`,
android: {
channelId: 'messages',
largeIcon: NotificationAdditionalData?.senderPhoto,
timestamp: NotificationAdditionalData?.messageTime,
showTimestamp: true,
smallIcon: 'moon_icon',
},
});
}
notificationReceivedEvent.complete(null);
} else {
notificationReceivedEvent.complete(
notificationReceivedEvent?.getNotification(),
);
}
},
);
AppRegistry.registerComponent(MoonMeet, () => App);