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

add staticCanMessage method #158

Merged
merged 19 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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 android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ repositories {
dependencies {
implementation project(':expo-modules-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
implementation "org.xmtp:android:0.6.12"
implementation "org.xmtp:android:0.6.16"
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.facebook.react:react-native:0.71.3'
implementation "com.daveanthonythomas.moshipack:moshipack:1.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,17 @@ class XMTPModule : Module() {
client.canMessage(peerAddress)
}

AsyncFunction("staticCanMessage") { peerAddress: String, environment: String, appVersion: String? ->
try {
logV("staticCanMessage")
val options = ClientOptions(api = apiEnvironments(environment, appVersion))
Client.canMessage(peerAddress = peerAddress, options = options)
true
kele-leanes marked this conversation as resolved.
Show resolved Hide resolved
} catch (e: Exception) {
throw XMTPException("Failed to create client: $e")
kele-leanes marked this conversation as resolved.
Show resolved Hide resolved
}
}

AsyncFunction("encryptAttachment") { clientAddress: String, fileJson: String ->
logV("encryptAttachment")
val client = clients[clientAddress] ?: throw XMTPException("No client")
Expand Down
10 changes: 5 additions & 5 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -415,15 +415,15 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.6.9-alpha0):
- XMTP (0.6.13-alpha0):
- Connect-Swift (= 0.3.0)
- GzipSwift
- web3.swift
- XMTPRust (= 0.3.6-beta0)
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- XMTP (= 0.6.9-alpha0)
- XMTP (= 0.6.13-alpha0)
- XMTPRust (0.3.6-beta0)
- Yoga (1.14.0)

Expand Down Expand Up @@ -680,11 +680,11 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: b02b5075dcf60c9f5f403000b3b0c202a11b6ae1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: 245855791631fa66f022d0d3ce9d9aebd7ca3146
XMTPReactNative: 2ef288363bc42f97014ea4744264a1679774f36d
XMTP: 7ef0bd61b7f32209e175b6089e71bf82f0238530
XMTPReactNative: 778f5b7ee88c2d80926e989f4c8c1963da749a50
XMTPRust: 3c958736a4f4ee798e425b5644551f1c948da4b0
Yoga: 065f0b74dba4832d6e328238de46eb72c5de9556

PODFILE CHECKSUM: 522d88edc2d5fac4825e60a121c24abc18983367

COCOAPODS: 1.13.0
COCOAPODS: 1.11.3
8 changes: 8 additions & 0 deletions example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,3 +620,11 @@ test("canManagePreferences", async () => {
return true
});

test("is address in the XMTP network", async () => {
const alix = await XMTP.Client.createRandom({ env: "local" });

const isAddressAvailable = await XMTP.publicCanMessage(alix.address, 'local');
kele-leanes marked this conversation as resolved.
Show resolved Hide resolved

return isAddressAvailable
kele-leanes marked this conversation as resolved.
Show resolved Hide resolved
});

10 changes: 10 additions & 0 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ public class XMTPModule: Module {
return try await client.canMessage(peerAddress)
}

AsyncFunction("staticCanMessage") { (peerAddress: String, environment: String, appVersion: String?) -> Bool in
do {
let options = createClientConfig(env: environment, appVersion: appVersion)
return try await XMTP.Client.canMessage(peerAddress, options: options)
} catch {
print("ERRO! canMessage method: \(error)")
throw error
}
}

AsyncFunction("encryptAttachment") { (clientAddress: String, fileJson: String) -> String in
guard let client = await clientsManager.getClient(key: clientAddress) else {
throw Error.noClient
Expand Down
2 changes: 1 addition & 1 deletion ios/XMTPReactNative.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ Pod::Spec.new do |s|

s.source_files = "**/*.{h,m,swift}"
s.dependency "MessagePacker"
s.dependency "XMTP", "= 0.6.9-alpha0"
s.dependency "XMTP", "= 0.6.13-alpha0"
end
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ export async function canMessage(
return await XMTPModule.canMessage(clientAddress, peerAddress);
}

export async function staticCanMessage(
peerAddress: string,
environment: "local" | "dev" | "production",
appVersion?: string | undefined,
): Promise<boolean> {
return await XMTPModule.staticCanMessage(peerAddress, environment, appVersion);
}

export async function encryptAttachment(
clientAddress: string,
file: DecryptedLocalAttachment,
Expand Down
Loading