Skip to content

Commit

Permalink
Revert "Revert "Can message hash map""
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer authored Apr 25, 2024
1 parent f465bdd commit a5af7a6
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 30 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ repositories {
dependencies {
implementation project(':expo-modules-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
implementation "org.xmtp:android:0.10.5"
implementation "org.xmtp:android:0.10.6"
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 @@ -374,10 +374,12 @@ class XMTPModule : Module() {
client.canMessage(peerAddress)
}

AsyncFunction("canGroupMessage") { clientAddress: String, peerAddresses: List<String> ->
logV("canGroupMessage")
val client = clients[clientAddress] ?: throw XMTPException("No client")
client.canMessageV3(peerAddresses)
AsyncFunction("canGroupMessage") Coroutine { clientAddress: String, peerAddresses: List<String> ->
withContext(Dispatchers.IO) {
logV("canGroupMessage")
val client = clients[clientAddress] ?: throw XMTPException("No client")
client.canMessageV3(peerAddresses)
}
}

AsyncFunction("staticCanMessage") { peerAddress: String, environment: String, appVersion: String? ->
Expand Down
24 changes: 12 additions & 12 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ PODS:
- hermes-engine/Pre-built (= 0.71.14)
- hermes-engine/Pre-built (0.71.14)
- libevent (2.1.12)
- LibXMTP (0.4.4-beta3)
- LibXMTP (0.4.4-beta5)
- Logging (1.0.0)
- MessagePacker (0.4.7)
- MMKV (1.3.4):
- MMKVCore (~> 1.3.4)
- MMKVCore (1.3.4)
- MMKV (1.3.5):
- MMKVCore (~> 1.3.5)
- MMKVCore (1.3.5)
- OpenSSL-Universal (1.1.2200)
- RCT-Folly (2021.07.22.00):
- boost
Expand Down Expand Up @@ -449,16 +449,16 @@ PODS:
- GenericJSON (~> 2.0)
- Logging (~> 1.0.0)
- secp256k1.swift (~> 0.1)
- XMTP (0.10.5):
- XMTP (0.10.6):
- Connect-Swift (= 0.12.0)
- GzipSwift
- LibXMTP (= 0.4.4-beta3)
- LibXMTP (= 0.4.4-beta5)
- web3.swift
- XMTPReactNative (0.1.0):
- ExpoModulesCore
- MessagePacker
- secp256k1.swift
- XMTP (= 0.10.5)
- XMTP (= 0.10.6)
- Yoga (1.14.0)

DEPENDENCIES:
Expand Down Expand Up @@ -711,11 +711,11 @@ SPEC CHECKSUMS:
GzipSwift: 893f3e48e597a1a4f62fafcb6514220fcf8287fa
hermes-engine: d7cc127932c89c53374452d6f93473f1970d8e88
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
LibXMTP: 1422d36d715fe868b5800692f3d9b8a218a41e9d
LibXMTP: e2fb601691981900099551ff3e05621bd73dccf1
Logging: 9ef4ecb546ad3169398d5a723bc9bea1c46bef26
MessagePacker: ab2fe250e86ea7aedd1a9ee47a37083edd41fd02
MMKV: ed58ad794b3f88c24d604a5b74f3fba17fcbaf74
MMKVCore: a67a1cede26175c413176f404a7cedec43f96a0b
MMKV: 506311d0494023c2f7e0b62cc1f31b7370fa3cfb
MMKVCore: 9e2e5fd529b64a9fe15f1a7afb3d73b2e27b4db9
OpenSSL-Universal: 6e1ae0555546e604dbc632a2b9a24a9c46c41ef6
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
RCTRequired: e9df143e880d0e879e7a498dc06923d728809c79
Expand Down Expand Up @@ -763,8 +763,8 @@ SPEC CHECKSUMS:
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SwiftProtobuf: 407a385e97fd206c4fbe880cc84123989167e0d1
web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959
XMTP: ec7fa7f9a2bd3990a7142c2f454e04c5b83b834a
XMTPReactNative: 42d61df711ce3c094d9fac9e3f44671f5466e93e
XMTP: 0e31bcf8e904389ec831cc058601553045fda477
XMTPReactNative: 7a3f29770f0d496a00d2c6457ce63d878528360e
Yoga: e71803b4c1fff832ccf9b92541e00f9b873119b9

PODFILE CHECKSUM: 95d6ace79946933ecf80684613842ee553dd76a2
Expand Down
25 changes: 21 additions & 4 deletions example/src/tests/groupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,27 @@ test('canMessage', async () => {

const [caro, chux] = await createClients(2)

const canMessageV3 = await caro.canGroupMessage([chux.address])
if (!canMessageV3) {
throw new Error('should be able to message v3 client')
}
const canMessageV3 = await caro.canGroupMessage([
chux.address,
alix.address,
'0x0000000000000000000000000000000000000000',
])

assert(
canMessageV3['0x0000000000000000000000000000000000000000'] === false,
`should not be able to message 0x0000000000000000000000000000000000000000`
)

assert(
canMessageV3[chux.address.toLowerCase()] === true,
`should be able to message ${chux.address}`
)

assert(
canMessageV3[alix.address.toLowerCase()] === true,
`should be able to message ${alix.address}`
)

return true
})

Expand Down
2 changes: 1 addition & 1 deletion ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public class XMTPModule: Module {
return try await client.canMessage(peerAddress)
}

AsyncFunction("canGroupMessage") { (clientAddress: String, peerAddresses: [String]) -> Bool in
AsyncFunction("canGroupMessage") { (clientAddress: String, peerAddresses: [String]) -> [String: Bool] 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 @@ -26,5 +26,5 @@ Pod::Spec.new do |s|
s.source_files = "**/*.{h,m,swift}"
s.dependency 'secp256k1.swift'
s.dependency "MessagePacker"
s.dependency "XMTP", "= 0.10.5"
s.dependency "XMTP", "= 0.10.6"
end
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export async function canMessage(
export async function canGroupMessage(
clientAddress: string,
peerAddresses: string[]
): Promise<boolean> {
): Promise<{ [key: string]: boolean }> {
return await XMTPModule.canGroupMessage(clientAddress, peerAddresses)
}

Expand Down
16 changes: 10 additions & 6 deletions src/lib/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import { DecodedMessage } from '../index'

declare const Buffer

export type GetMessageContentTypeFromClient<C> =
C extends Client<infer T> ? T : never
export type GetMessageContentTypeFromClient<C> = C extends Client<infer T>

Check warning on line 22 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `·C·extends·Client<infer·T>⏎··?·T⏎·` with `⏎··C·extends·Client<infer·T>·?·T`
? T
: never

export type ExtractDecodedType<C> =
C extends XMTPModule.ContentCodec<infer T> ? T : never
export type ExtractDecodedType<C> = C extends XMTPModule.ContentCodec<infer T>

Check warning on line 26 in src/lib/Client.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `·C·extends·XMTPModule.ContentCodec<infer·T>⏎··?·T⏎·` with `⏎··C·extends·XMTPModule.ContentCodec<infer·T>·?·T`
? T
: never

export class Client<
ContentTypes extends DefaultContentTypes = DefaultContentTypes,
Expand Down Expand Up @@ -210,9 +212,11 @@ export class Client<
* This method checks if the specified peers are using clients that support group messaging.
*
* @param {string[]} addresses - The addresses of the peers to check for messaging eligibility.
* @returns {Promise<boolean[]>} A Promise resolving to true for peers where group messaging is allowed, and false otherwise.
* @returns {Promise<{ [key: string]: boolean }>} A Promise resolving to a hash of addresses and booleans if they can message on the V3 network.
*/
async canGroupMessage(addresses: string[]): Promise<boolean> {
async canGroupMessage(
addresses: string[]
): Promise<{ [key: string]: boolean }> {
return await XMTPModule.canGroupMessage(this.address, addresses)
}

Expand Down

0 comments on commit a5af7a6

Please sign in to comment.