Skip to content

Commit

Permalink
chore(increase-timeout): increase background handler timeout to 24 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
Cali93 committed Sep 7, 2023
1 parent 28769cb commit 127d764
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 30 deletions.
1 change: 1 addition & 0 deletions dapps/web3inbox/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.walletconnect.w3i.rnexample">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<application
android:name=".MainApplication"
Expand Down
5 changes: 5 additions & 0 deletions dapps/web3inbox/firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"react-native": {
"messaging_android_headless_task_timeout": 86400000
}
}
76 changes: 46 additions & 30 deletions dapps/web3inbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import App from './App';
import {name as appName} from './app.json';
import crypto from 'react-native-quick-crypto';
import messaging from '@react-native-firebase/messaging';
import notifee, {AndroidVisibility, EventType} from '@notifee/react-native';
import notifee, {
AndroidImportance,
AndroidVisibility,
EventType,
} from '@notifee/react-native';
import {NotifyClient} from '@walletconnect/notify-client';
import {Core} from '@walletconnect/core';

Expand Down Expand Up @@ -56,31 +60,47 @@ async function registerClient(deviceToken, clientId) {
.catch(error => console.log('error', error));
}

PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);

messaging()
.getToken()
.then(async token => {
const authStatus = await messaging().requestPermission(
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
);
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
console.log({enabled});

if (enabled) {
notifyClient = await NotifyClient.init({
core,
projectId,
relayUrl,
});
const clientId = await notifyClient.core.crypto.getClientId();
await registerClient(token, clientId);
}
});
.then(token => console.log({token}));

messaging().onTokenRefresh(async token => {
console.log({token});
const authStatus2 = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
);
console.log({authStatus2});
const authStatus = await messaging().requestPermission(
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
);
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;

if (enabled) {
notifyClient = await NotifyClient.init({
core,
projectId,
relayUrl,
});
const clientId = await notifyClient.core.crypto.getClientId();
return registerClient(token, clientId);
}

return;
});

notifee.createChannel({
id: 'default',
name: 'Default Channel',
lights: false,
vibration: true,
importance: AndroidImportance.HIGH,
visibility: AndroidVisibility.PUBLIC,
});

messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log(remoteMessage);
if (!notifyClient) {
notifyClient = await NotifyClient.init({
core,
Expand All @@ -102,22 +122,18 @@ messaging().setBackgroundMessageHandler(async remoteMessage => {
JSON.stringify(decryptedMessage),
);

const channelId = await notifee.createChannel({
id: 'default',
name: 'Default Channel',
});

// Display a notification
await notifee.displayNotification({
return notifee.displayNotification({
title: decryptedMessage.title,
body: decryptedMessage.body,
android: {
channelId,
channelId: 'default',
importance: AndroidImportance.HIGH,
visibility: AndroidVisibility.PUBLIC,
smallIcon: 'ic_launcher', // optional, defaults to 'ic_launcher'.
// pressAction is needed if you want the notification to open the app when pressed
pressAction: {
id: 'mark-as-read',
id: 'default',
},
},
});
Expand Down
1 change: 1 addition & 0 deletions dapps/web3inbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"android": "react-native run-android --appId=com.walletconnect.w3i.rnexample",
"android:build": "cd android && ./gradlew clean && ./gradlew assembleRelease",
"android:debug": "cd android && ./gradlew clean && ./gradlew assembleDebug",
"ios": "react-native run-ios",
"lint": "eslint .",
"start": "react-native start",
Expand Down

0 comments on commit 127d764

Please sign in to comment.