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..10fe4cc03 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..ba977281a 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);