Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update push example #347

Draft
wants to merge 5 commits into
base: push-notifications-example
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -769,4 +769,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2

COCOAPODS: 1.14.2
COCOAPODS: 1.15.2
3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dependencies": {
"@react-native-async-storage/async-storage": "^1.21.0",
"@react-native-community/netinfo": "^11.2.0",
"@react-native-community/push-notification-ios": "^1.11.0",
"@react-navigation/native": "^6.1.6",
"@react-navigation/native-stack": "^6.9.12",
"@thirdweb-dev/react-native": "^0.6.2",
Expand All @@ -33,8 +34,8 @@
"react-native-fs": "^2.20.0",
"react-native-get-random-values": "^1.11.0",
"react-native-mmkv": "^2.8.0",
"react-native-push-notification": "^8.1.1",
"react-native-modal-selector": "^2.1.2",
"react-native-push-notification": "^8.1.1",
"react-native-quick-base64": "^2.0.8",
"react-native-quick-crypto": "^0.6.1",
"react-native-randombytes": "^3.6.1",
Expand Down
63 changes: 31 additions & 32 deletions example/src/PushController.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,63 @@
import PushNotificationIOS from "@react-native-community/push-notification-ios";
import { useEffect } from "react";
import PushNotification from "react-native-push-notification";
import { XMTPPush, Client } from "xmtp-react-native-sdk";
import PushNotificationIOS from '@react-native-community/push-notification-ios'
import { useEffect } from 'react'
import PushNotification from 'react-native-push-notification'
import { XMTPPush, Client } from 'xmtp-react-native-sdk'

function PushController({ client }: { client: Client }) {
useEffect(() => {
PushNotification.configure({
// (optional) Called when Token is generated (iOS and Android)
onRegister(token: any) {
XMTPPush.register("YOUR_SERVER_ADDRESS", token.token as string);
XMTPPush.register('YOUR_SERVER_ADDRESS', token.token as string)
PushNotification.createChannel({
channelId: "xmtp-react-native-example-dm", // (required)
channelName: "XMTP React Native Example", // (required)
});
channelId: 'xmtp-react-native-example-dm', // (required)
channelName: 'XMTP React Native Example', // (required)
})
},
// (required) Called when a remote or local notification is opened or received
onNotification(notification: any) {
const encryptedMessage = notification.data.encryptedMessage;
const topic = notification.data.topic;
const encryptedMessage = notification.data.encryptedMessage
const topic = notification.data.topic

if (encryptedMessage == null || topic == null) {
return;
return
}
(async () => {
const conversations = await client.conversations.list();
;(async () => {
const conversations = await client.conversations.list()
const conversation = conversations.find(
(c: { topic: string }) => c.topic === topic
);
)
if (conversation == null) {
return;
return
}

const peerAddress = conversation.peerAddress;
const decodedMessage = await conversation.decodeMessage(
encryptedMessage
);
const body = decodedMessage.content;
const peerAddress = conversation.peerAddress
const decodedMessage =
await conversation.decodeMessage(encryptedMessage)
const body = decodedMessage.content

PushNotification.localNotification({
/* Android Only Properties */
channelId: "xmtp-react-native-example-dm", // (required) channelId, if the channel doesn't exist, notification will not trigger.
messageId: "google:message_id", // (optional) added as `message_id` to intent extras so opening push notification can find data stored by @react-native-firebase/messaging module.
channelId: 'xmtp-react-native-example-dm', // (required) channelId, if the channel doesn't exist, notification will not trigger.
messageId: 'google:message_id', // (optional) added as `message_id` to intent extras so opening push notification can find data stored by @react-native-firebase/messaging module.

/* iOS only properties */
category: "", // (optional) default: empty string
subtitle: "My Notification Subtitle", // (optional) smaller title below notification title
category: '', // (optional) default: empty string
subtitle: 'My Notification Subtitle', // (optional) smaller title below notification title

/* iOS and Android properties */
id: 0, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
title: peerAddress, // (optional)
message: body, // (required)
});
})();
})
})().catch(console.error)

// process the notification here
// required on iOS only
notification.finish(PushNotificationIOS?.FetchResult.NoData);
notification.finish(PushNotificationIOS?.FetchResult.NoData)
},
// Android only
senderID: "YOUR_FIREBASE_SENDER_ID",
senderID: 'YOUR_FIREBASE_SENDER_ID',
// iOS only
permissions: {
alert: true,
Expand All @@ -67,8 +66,8 @@ function PushController({ client }: { client: Client }) {
},
popInitialNotification: true,
requestPermissions: true,
});
});
return null;
})
})
return null
}
export default PushController;
export default PushController
12 changes: 12 additions & 0 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5526,6 +5526,13 @@
resolved "https://registry.npmjs.org/@react-native-community/netinfo/-/netinfo-11.2.1.tgz"
integrity sha512-n9kgmH7vLaU7Cdo8vGfJGGwhrlgppaOSq5zKj9I7H4k5iRM3aNtwURw83mgrc22Ip7nSye2afZV2xDiIyvHttQ==

"@react-native-community/push-notification-ios@^1.11.0":
version "1.11.0"
resolved "https://registry.yarnpkg.com/@react-native-community/push-notification-ios/-/push-notification-ios-1.11.0.tgz#d8ec4acfb52260cb779ed0379b9e197db7841b83"
integrity sha512-nfkUs8P2FeydOCR4r7BNmtGxAxI22YuGP6RmqWt6c8EEMUpqvIhNKWkRSFF3pHjkgJk2tpRb9wQhbezsqTyBvA==
dependencies:
invariant "^2.2.4"

"@react-native/[email protected]":
version "1.0.0"
resolved "https://registry.npmjs.org/@react-native/assets/-/assets-1.0.0.tgz"
Expand Down Expand Up @@ -13538,6 +13545,11 @@ react-native-modal@^13.0.1:
prop-types "^15.6.2"
react-native-animatable "1.3.3"

react-native-push-notification@^8.1.1:
version "8.1.1"
resolved "https://registry.yarnpkg.com/react-native-push-notification/-/react-native-push-notification-8.1.1.tgz#a41d20c70ea5a7709417e96261b225461f8dc73a"
integrity sha512-XpBtG/w+a6WXTxu6l1dNYyTiHnbgnvjoc3KxPTxYkaIABRmvuJZkFxqruyGvfCw7ELAlZEAJO+dthdTabCe1XA==

[email protected]:
version "6.2.0"
resolved "https://registry.npmjs.org/react-native-qrcode-svg/-/react-native-qrcode-svg-6.2.0.tgz"
Expand Down
Loading