From a9d6885cba4adc6eeef96080863764f92ec8a0da Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Fri, 5 Apr 2024 12:23:43 -0700 Subject: [PATCH 1/2] remove that bad merge --- ios/XMTPModule.swift | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 3c9d0f6c8..ac16661b5 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -690,38 +690,15 @@ public class XMTPModule: Module { } } - AsyncFunction("subscribePushTopics") { (topics: [String]) in - do { - try await XMTPPush.shared.subscribe(topics: topics) - } catch { - print("Error subscribing: \(error)") - } - } AsyncFunction("removeGroupMembers") { (clientAddress: String, id: String, peerAddresses: [String]) in guard let client = await clientsManager.getClient(key: clientAddress) else { throw Error.noClient } - AsyncFunction("decodeMessage") { (clientAddress: String, topic: String, encryptedMessage: String, conversationID: String?) -> String in - guard let encryptedMessageData = Data(base64Encoded: Data(encryptedMessage.utf8))else { - throw Error.noMessage - } guard let group = try await findGroup(clientAddress: clientAddress, id: id) else { throw Error.conversationNotFound("no group found for \(id)") } - let envelope = XMTP.Envelope.with { envelope in - envelope.message = encryptedMessageData - envelope.contentTopic = topic - } - - guard let conversation = try await findConversation(clientAddress: clientAddress, topic: topic, conversationID: conversationID) else { - throw Error.conversationNotFound("no conversation found for \(topic)") - } - let decodedMessage = try conversation.decode(envelope) - return try DecodedMessageWrapper.encode(decodedMessage) - } - } try await group.removeMembers(addresses: peerAddresses) } From baae52cb56981755d01fd9f3495d0502f3742490 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Fri, 5 Apr 2024 12:30:53 -0700 Subject: [PATCH 2/2] get the push controller up to speed --- example/package.json | 3 +- example/src/PushController.tsx | 63 +++++++++++++++++----------------- example/yarn.lock | 12 +++++++ 3 files changed, 45 insertions(+), 33 deletions(-) diff --git a/example/package.json b/example/package.json index 879538764..0cdff1492 100644 --- a/example/package.json +++ b/example/package.json @@ -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", @@ -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", diff --git a/example/src/PushController.tsx b/example/src/PushController.tsx index 7e06f21b2..8292ac020 100644 --- a/example/src/PushController.tsx +++ b/example/src/PushController.tsx @@ -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, @@ -67,8 +66,8 @@ function PushController({ client }: { client: Client }) { }, popInitialNotification: true, requestPermissions: true, - }); - }); - return null; + }) + }) + return null } -export default PushController; +export default PushController diff --git a/example/yarn.lock b/example/yarn.lock index 85f443f16..97e7bae0a 100644 --- a/example/yarn.lock +++ b/example/yarn.lock @@ -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/assets@1.0.0": version "1.0.0" resolved "https://registry.npmjs.org/@react-native/assets/-/assets-1.0.0.tgz" @@ -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== + react-native-qrcode-svg@6.2.0: version "6.2.0" resolved "https://registry.npmjs.org/react-native-qrcode-svg/-/react-native-qrcode-svg-6.2.0.tgz"