From 7e9f7985615ca7f592fa06ae522cc78ce9da6d3e Mon Sep 17 00:00:00 2001 From: Elise Alix Date: Thu, 25 May 2023 13:43:26 -0400 Subject: [PATCH 1/2] feat: add canMessage to client --- .../java/expo/modules/xmtpreactnativesdk/XMTPModule.kt | 6 ++++++ example/src/HomeHeaderView.tsx | 6 ++++++ ios/XMTPModule.swift | 8 ++++++++ src/index.ts | 4 ++++ src/lib/Client.ts | 6 ++++++ 5 files changed, 30 insertions(+) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index d740a24dc..2950ef364 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -129,6 +129,12 @@ class XMTPModule : Module() { // // Client API + AsyncFunction("canMessage") { clientAddress: String, peerAddress: String -> + val client = clients[clientAddress] ?: throw XMTPException("No client") + + client.canMessage(peerAddress) + } + AsyncFunction("listConversations") { clientAddress: String -> val client = clients[clientAddress] ?: throw XMTPException("No client") val conversationList = client.conversations.list() diff --git a/example/src/HomeHeaderView.tsx b/example/src/HomeHeaderView.tsx index 7e800845c..0cdb4fbaf 100644 --- a/example/src/HomeHeaderView.tsx +++ b/example/src/HomeHeaderView.tsx @@ -24,6 +24,12 @@ function NewConversationView({ async function startConverstation() { setIsCreating(true); try { + const canMessage = await client.canMessage(address); + if (!canMessage) { + setIsCreating(false); + setErr(`${address} is not on the XMTP Network yet`); + return; + } const conversation = await client.conversations.newConversation(address); setIsCreating(false); onSuccess(); diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 94235d3b2..1299a0954 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -134,6 +134,14 @@ public class XMTPModule: Module { // // Client API + AsyncFunction("canMessage") { (clientAddress: String, peerAddress: String) -> Bool in + guard let client = clients[clientAddress] else { + throw Error.noClient + } + + return try await client.canMessage(peerAddress) + } + AsyncFunction("listConversations") { (clientAddress: String) -> [String] in guard let client = clients[clientAddress] else { throw Error.noClient diff --git a/src/index.ts b/src/index.ts index b3689b240..585173d44 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,6 +25,10 @@ export async function createRandom( return await XMTPModule.createRandom(environment); } +export async function canMessage(clientAddress: string, peerAddress: string): Promise { + return await XMTPModule.canMessage(clientAddress, peerAddress) +} + export async function listConversations( clientAddress: string ): Promise { diff --git a/src/lib/Client.ts b/src/lib/Client.ts index 63be66f82..123c68b09 100644 --- a/src/lib/Client.ts +++ b/src/lib/Client.ts @@ -49,6 +49,12 @@ export class Client { return new Client(address); } + async canMessage( + peerAddress: string + ): Promise { + return await XMTPModule.canMessage(this.address, peerAddress); + } + constructor(address: string) { this.address = address; this.conversations = new Conversations(this); From a8dd6024bddd0e0ca6dfbd0ba85b5d974632100f Mon Sep 17 00:00:00 2001 From: Elise Alix Date: Thu, 25 May 2023 15:37:58 -0400 Subject: [PATCH 2/2] add missing semi --- example/src/HomeHeaderView.tsx | 2 +- src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example/src/HomeHeaderView.tsx b/example/src/HomeHeaderView.tsx index 0cdb4fbaf..10fe4cc03 100644 --- a/example/src/HomeHeaderView.tsx +++ b/example/src/HomeHeaderView.tsx @@ -27,7 +27,7 @@ function NewConversationView({ const canMessage = await client.canMessage(address); if (!canMessage) { setIsCreating(false); - setErr(`${address} is not on the XMTP Network yet`); + setErr(`${address} is not on the XMTP network yet`); return; } const conversation = await client.conversations.newConversation(address); diff --git a/src/index.ts b/src/index.ts index 585173d44..ba977281a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,7 +26,7 @@ export async function createRandom( } export async function canMessage(clientAddress: string, peerAddress: string): Promise { - return await XMTPModule.canMessage(clientAddress, peerAddress) + return await XMTPModule.canMessage(clientAddress, peerAddress); } export async function listConversations(