chore: set background push action
This commit is contained in:
parent
1ee5388440
commit
0baa1e72af
|
@ -1,7 +1,10 @@
|
||||||
import notifee, { AndroidCategory, AndroidImportance, AndroidVisibility } from '@notifee/react-native';
|
import notifee, { AndroidCategory, AndroidImportance, AndroidVisibility } from '@notifee/react-native';
|
||||||
import messaging from '@react-native-firebase/messaging';
|
import messaging from '@react-native-firebase/messaging';
|
||||||
import { Alert } from 'react-native';
|
|
||||||
import ejson from 'ejson';
|
import ejson from 'ejson';
|
||||||
|
import { Alert } from 'react-native';
|
||||||
|
|
||||||
|
import i18n from '../../i18n';
|
||||||
|
import { BACKGROUND_PUSH_COLOR } from '../constants';
|
||||||
|
|
||||||
export const backgroundNotificationHandler = async (): Promise<void> => {
|
export const backgroundNotificationHandler = async (): Promise<void> => {
|
||||||
// 1. get info on the device and the Power Manager settings
|
// 1. get info on the device and the Power Manager settings
|
||||||
|
@ -62,13 +65,6 @@ export const backgroundNotificationHandler = async (): Promise<void> => {
|
||||||
importance: AndroidImportance.HIGH
|
importance: AndroidImportance.HIGH
|
||||||
});
|
});
|
||||||
|
|
||||||
notifee.registerForegroundService(
|
|
||||||
notification =>
|
|
||||||
new Promise(() => {
|
|
||||||
console.log('registerForegroundService', notification);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
notifee.onBackgroundEvent(
|
notifee.onBackgroundEvent(
|
||||||
event =>
|
event =>
|
||||||
new Promise(() => {
|
new Promise(() => {
|
||||||
|
@ -77,45 +73,55 @@ export const backgroundNotificationHandler = async (): Promise<void> => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const setBackgroundNotificationHandler = async (): Promise<void> => {
|
function getNumbersAndLettersOnly(inputString: string) {
|
||||||
|
// Replace all characters that are NOT (A-Z, a-z, or 0-9) with an empty string
|
||||||
|
return inputString.replace(/[^A-Za-z0-9]/g, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
const setBackgroundNotificationHandler = (): void => {
|
||||||
messaging().setBackgroundMessageHandler(async (n: any) => {
|
messaging().setBackgroundMessageHandler(async (n: any) => {
|
||||||
const notification = ejson.parse(n.data.ejson);
|
const notification = ejson.parse(n.data.ejson);
|
||||||
console.log('setBackgroundMessageHandler', notification, n);
|
console.log('setBackgroundMessageHandler', n);
|
||||||
if (notification) {
|
if (notification?.notificationType === 'videoconf') {
|
||||||
await notifee.displayNotification({
|
if (notification.status === 0) {
|
||||||
title: notification.sender?.name || notification.sender.username || 'Rocket.Chat',
|
await notifee.displayNotification({
|
||||||
body: 'Incoming call',
|
id: getNumbersAndLettersOnly(notification.rid + notification.caller._id),
|
||||||
android: {
|
title: i18n.t('conference_call'),
|
||||||
channelId: 'video-conf-call',
|
body: `${i18n.t('Incoming_call_from')} ${notification.caller.name}`,
|
||||||
category: AndroidCategory.CALL,
|
data: notification,
|
||||||
visibility: AndroidVisibility.PUBLIC,
|
android: {
|
||||||
importance: AndroidImportance.HIGH,
|
channelId: 'video-conf-call',
|
||||||
smallIcon: 'ic_notification',
|
category: AndroidCategory.CALL,
|
||||||
timestamp: Date.now(),
|
visibility: AndroidVisibility.PUBLIC,
|
||||||
color: '#F5455C',
|
importance: AndroidImportance.HIGH,
|
||||||
actions: [
|
smallIcon: 'ic_notification',
|
||||||
{
|
timestamp: Date.now(),
|
||||||
title: 'Accept',
|
color: BACKGROUND_PUSH_COLOR,
|
||||||
pressAction: {
|
actions: [
|
||||||
id: 'accept',
|
{
|
||||||
launchActivity: 'default'
|
title: i18n.t('accept'),
|
||||||
|
pressAction: {
|
||||||
|
id: 'accept',
|
||||||
|
launchActivity: 'default'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: i18n.t('decline'),
|
||||||
|
pressAction: {
|
||||||
|
id: 'decline'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
],
|
||||||
{
|
lightUpScreen: true
|
||||||
title: 'Decline',
|
}
|
||||||
pressAction: {
|
});
|
||||||
id: 'reject'
|
}
|
||||||
}
|
if (notification.status === 4) {
|
||||||
}
|
const notification = ejson.parse(n.data.ejson);
|
||||||
],
|
await notifee.cancelNotification(getNumbersAndLettersOnly(notification.rid + notification.caller._id));
|
||||||
fullScreenAction: {
|
}
|
||||||
id: 'full-screen',
|
|
||||||
launchActivity: 'chat.rocket.reactnative.CustomCallActivity'
|
|
||||||
},
|
|
||||||
lightUpScreen: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue