Skip to content

Commit

Permalink
Merge pull request #44 from xmtp/ea/add-can-message
Browse files Browse the repository at this point in the history
feat: add canMessage to client
  • Loading branch information
elisealix22 authored May 25, 2023
2 parents 8368fc7 + a8dd602 commit 1d0c147
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions example/src/HomeHeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export async function createRandom(
return await XMTPModule.createRandom(environment);
}

export async function canMessage(clientAddress: string, peerAddress: string): Promise<boolean> {
return await XMTPModule.canMessage(clientAddress, peerAddress);
}

export async function listConversations(
clientAddress: string
): Promise<Conversation[]> {
Expand Down
6 changes: 6 additions & 0 deletions src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ export class Client {
return new Client(address);
}

async canMessage(
peerAddress: string
): Promise<boolean> {
return await XMTPModule.canMessage(this.address, peerAddress);
}

constructor(address: string) {
this.address = address;
this.conversations = new Conversations(this);
Expand Down

0 comments on commit 1d0c147

Please sign in to comment.