From 405742ee1d63343d35408fa864e8305ff8622f2e Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 25 Oct 2023 20:17:21 -0700 Subject: [PATCH 01/15] bump to the latest android and ios build --- android/build.gradle | 2 +- example/ios/Podfile.lock | 26 +++++++++++++------------- ios/XMTPReactNative.podspec | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index bcf63beee..878f185d3 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -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.5" + implementation "org.xmtp:android:0.6.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" diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index b64754b66..80dda0e56 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -1,8 +1,8 @@ PODS: - BigInt (5.0.0) - boost (1.76.0) - - Connect-Swift (0.8.0): - - SwiftProtobuf (~> 1.23.0) + - Connect-Swift (0.9.0): + - SwiftProtobuf (~> 1.24.0) - DoubleConversion (1.1.6) - EXApplication (5.1.1): - ExpoModulesCore @@ -409,22 +409,22 @@ PODS: - RNSVG (13.9.0): - React-Core - secp256k1.swift (0.1.4) - - SwiftProtobuf (1.23.0) + - SwiftProtobuf (1.24.0) - web3.swift (1.6.0): - BigInt (~> 5.0.0) - GenericJSON (~> 2.0) - Logging (~> 1.0.0) - secp256k1.swift (~> 0.1) - - XMTP (0.6.0-alpha0): + - XMTP (0.6.2-alpha0): - Connect-Swift - GzipSwift - web3.swift - - XMTPRust (= 0.3.5-beta0) + - XMTPRust (= 0.3.6-beta0) - XMTPReactNative (0.1.0): - ExpoModulesCore - MessagePacker - - XMTP (= 0.6.0-alpha0) - - XMTPRust (0.3.5-beta0) + - XMTP (= 0.6.2-alpha0) + - XMTPRust (0.3.6-beta0) - Yoga (1.14.0) DEPENDENCIES: @@ -617,7 +617,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: BigInt: 74b4d88367b0e819d9f77393549226d36faeb0d8 boost: 57d2868c099736d80fcd648bf211b4431e51a558 - Connect-Swift: ed4000df7d6cdd794f2530e844e649a672d032ee + Connect-Swift: 1d8dcd7b25e8c110f262b88b5c9eb8849d05e56c DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54 EXApplication: d8f53a7eee90a870a75656280e8d4b85726ea903 EXConstants: f348da07e21b23d2b085e270d7b74f282df1a7d9 @@ -678,13 +678,13 @@ SPEC CHECKSUMS: RNScreens: 218801c16a2782546d30bd2026bb625c0302d70f RNSVG: 53c661b76829783cdaf9b7a57258f3d3b4c28315 secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634 - SwiftProtobuf: b70d65f419fbfe61a2d58003456ca5da58e337d6 + SwiftProtobuf: bcfd2bc231cf9ae552cdc7c4e877bd3b41fe57b1 web3.swift: 2263d1e12e121b2c42ffb63a5a7beb1acaf33959 - XMTP: 12be6af818fa6ab3343ec95a7fb0ac772f2e6877 - XMTPReactNative: b2378747146547c703be3b4bba186bbf03f392d0 - XMTPRust: e555ea9eb92b7575a522508533c00851b38dd316 + XMTP: cdc893b31f190f0565aad0bfe01e8d75562fbb53 + XMTPReactNative: fae42c24d34e2eb98d91910fe6ec14f365018b2f + XMTPRust: 3c958736a4f4ee798e425b5644551f1c948da4b0 Yoga: 065f0b74dba4832d6e328238de46eb72c5de9556 PODFILE CHECKSUM: 522d88edc2d5fac4825e60a121c24abc18983367 -COCOAPODS: 1.12.1 +COCOAPODS: 1.13.0 diff --git a/ios/XMTPReactNative.podspec b/ios/XMTPReactNative.podspec index f3f5c4ed3..cb7fe61a6 100644 --- a/ios/XMTPReactNative.podspec +++ b/ios/XMTPReactNative.podspec @@ -25,5 +25,5 @@ Pod::Spec.new do |s| s.source_files = "**/*.{h,m,swift}" s.dependency "MessagePacker" - s.dependency "XMTP", "= 0.6.0-alpha0" + s.dependency "XMTP", "= 0.6.2-alpha0" end From e16673e133c00b1e4694b61f02fdb5beff58a3f4 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 25 Oct 2023 20:49:20 -0700 Subject: [PATCH 02/15] add the typescript and kotlin side of the implementation --- .../modules/xmtpreactnativesdk/XMTPModule.kt | 29 ++++++++++++++++ src/index.ts | 34 +++++++++++++++++++ src/lib/Client.ts | 2 ++ 3 files changed, 65 insertions(+) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 7bc4df43b..6f558fdbf 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -19,8 +19,10 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking import kotlinx.coroutines.suspendCancellableCoroutine import org.json.JSONObject +import org.xmtp.android.library.AllowList import org.xmtp.android.library.Client import org.xmtp.android.library.ClientOptions import org.xmtp.android.library.Conversation @@ -488,6 +490,33 @@ class XMTPModule : Module() { val decodedMessage = conversation.decode(envelope) DecodedMessageWrapper.encode(decodedMessage) } + + AsyncFunction("isAllowed") { clientAddress: String, address: String -> + logV("isAllowed") + val client = clients[clientAddress] ?: throw XMTPException("No client") + client.contacts.isAllowed(address) + } + + Function("isBlocked") { clientAddress: String, address: String -> + logV("isBlocked") + val client = clients[clientAddress] ?: throw XMTPException("No client") + client.contacts.isBlocked(address) + } + + Function("blockContacts") { clientAddress: String, addresses: List -> + val client = clients[clientAddress] ?: throw XMTPException("No client") + client.contacts.block(addresses) + } + + Function("allowContacts") { clientAddress: String, addresses: List -> + val client = clients[clientAddress] ?: throw XMTPException("No client") + client.contacts.allow(addresses) + } + + Function("refreshAllowList") { clientAddress: String -> + val client = clients[clientAddress] ?: throw XMTPException("No client") + client.contacts.refreshAllowList() + } } // diff --git a/src/index.ts b/src/index.ts index 22ed13739..d858bfc71 100644 --- a/src/index.ts +++ b/src/index.ts @@ -261,6 +261,40 @@ export async function decodeMessage( ); } +export async function isAllowed( + clientAddress: string, + address: string, +): Promise { + return await XMTPModule.isAllowed(clientAddress, address); +} + +export async function isBlocked( + clientAddress: string, + address: string, +): Promise { + return await XMTPModule.isBlocked(clientAddress, address); +} + +export function blockContacts( + clientAddress: string, + addresses: string[], +) { + XMTPModule.blockContacts(clientAddress, addresses); +} + +export function allowContacts( + clientAddress: string, + addresses: string[], +) { + XMTPModule.allowContacts(clientAddress, addresses); +} + +export function refreshAllowList( + clientAddress: string +) { + XMTPModule.refreshAllowList(clientAddress); +} + export const emitter = new EventEmitter(XMTPModule ?? NativeModulesProxy.XMTP); export { Client } from "./lib/Client"; diff --git a/src/lib/Client.ts b/src/lib/Client.ts index 1b6f2897a..c97f13277 100644 --- a/src/lib/Client.ts +++ b/src/lib/Client.ts @@ -1,6 +1,7 @@ import { Signer, utils } from "ethers"; import Conversations from "./Conversations"; +import Contacts from "./Contacts"; import type { DecryptedLocalAttachment, DecodedMessage, @@ -15,6 +16,7 @@ declare const Buffer; export class Client { address: string; conversations: Conversations; + contacts: Contacts; static async create( signer: Signer, From cb4914573f937003509292f7a3ff11afca9f5f97 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 25 Oct 2023 20:59:07 -0700 Subject: [PATCH 03/15] feat: add the swift side of PPPP --- ios/XMTPModule.swift | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 17c13e2ec..bd6ae9c77 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -516,6 +516,41 @@ public class XMTPModule: Module { let decodedMessage = try conversation.decode(envelope) return try DecodedMessageWrapper.encode(decodedMessage) } + + AsyncFunction("isAllowed") { (clientAddress: String, address: String) -> Bool in + guard let client = await clientsManager.getClient(key: clientAddress) else { + throw Error.noClient + } + return await client.contacts.isAllowed(address: address) + } + + AsyncFunction("isBlocked") { (clientAddress: String, address: String) -> Bool in + guard let client = await clientsManager.getClient(key: clientAddress) else { + throw Error.noClient + } + return await client.contacts.isBlocked(address: address) + } + + AsyncFunction("blockContacts") { (clientAddress: String, addresses: [String]) in + guard let client = await clientsManager.getClient(key: clientAddress) else { + throw Error.noClient + } + return try await client.contacts.block(addresses: addresses) + } + + AsyncFunction("allowContacts") { (clientAddress: String, addresses: [String]) in + guard let client = await clientsManager.getClient(key: clientAddress) else { + throw Error.noClient + } + return try await client.contacts.allow(addresses: addresses) + } + + AsyncFunction("refreshAllowList") { (clientAddress: String) in + guard let client = await clientsManager.getClient(key: clientAddress) else { + throw Error.noClient + } + return try await client.contacts.refreshAllowList() + } } // From b9e554261810fbc047b4fd2b5e153b16025c1422 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 25 Oct 2023 21:24:17 -0700 Subject: [PATCH 04/15] add tests for it --- .../modules/xmtpreactnativesdk/XMTPModule.kt | 17 +++++++-- example/src/tests.ts | 38 +++++++++++++++++++ ios/Wrappers/ConversationWrapper.swift | 2 +- ios/XMTPModule.swift | 15 +++++++- src/index.ts | 7 ++++ src/lib/Conversation.ts | 4 ++ 6 files changed, 77 insertions(+), 6 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 6f558fdbf..fa68faf5b 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -23,6 +23,7 @@ import kotlinx.coroutines.runBlocking import kotlinx.coroutines.suspendCancellableCoroutine import org.json.JSONObject import org.xmtp.android.library.AllowList +import org.xmtp.android.library.AllowState import org.xmtp.android.library.Client import org.xmtp.android.library.ClientOptions import org.xmtp.android.library.Conversation @@ -503,20 +504,30 @@ class XMTPModule : Module() { client.contacts.isBlocked(address) } - Function("blockContacts") { clientAddress: String, addresses: List -> + AsyncFunction("blockContacts") { clientAddress: String, addresses: List -> val client = clients[clientAddress] ?: throw XMTPException("No client") client.contacts.block(addresses) } - Function("allowContacts") { clientAddress: String, addresses: List -> + AsyncFunction("allowContacts") { clientAddress: String, addresses: List -> val client = clients[clientAddress] ?: throw XMTPException("No client") client.contacts.allow(addresses) } - Function("refreshAllowList") { clientAddress: String -> + AsyncFunction("refreshAllowList") { clientAddress: String -> val client = clients[clientAddress] ?: throw XMTPException("No client") client.contacts.refreshAllowList() } + + AsyncFunction("conversationAllowState") { clientAddress: String, conversationTopic: String -> + val conversation = findConversation(clientAddress, conversationTopic) + ?: throw XMTPException("no conversation found for $conversationTopic") + when (conversation.allowState()) { + AllowState.ALLOW -> "allowed" + AllowState.BLOCK -> "blocked" + AllowState.UNKNOWN -> "unknown" + } + } } // diff --git a/example/src/tests.ts b/example/src/tests.ts index e0ed091c7..8fd7f73ab 100644 --- a/example/src/tests.ts +++ b/example/src/tests.ts @@ -549,3 +549,41 @@ test("can stream all messages", async () => { return true; }); +test("canManagePreferences", async () => { + const bo = await XMTP.Client.createRandom({ env: "local" }); + const alix = await XMTP.Client.createRandom({ env: "local" }); + await delayToPropogate(); + + const alixConversation = await bo.conversations.newConversation( + alix.address, + ); + await delayToPropogate(); + + const initialState = await bo.contacts.isAllowed(alixConversation.clientAddress) + if (!initialState) { + throw new Error(`conversations created by bob should be allowed by default not ${initialState}`); + } + + bo.contacts.block([alixConversation.clientAddress]); + await delayToPropogate(); + + const blockedState = await bo.contacts.isBlocked(alixConversation.clientAddress); + const allowedState = await bo.contacts.isAllowed(alixConversation.clientAddress); + if (!blockedState) { + throw new Error(`conversations blocked by bob should be blocked not ${blockedState}`); + } + + if (allowedState) { + throw new Error(`conversations blocked by bob should be blocked not ${allowedState}`); + } + + const convoState = await alixConversation.allowState(); + await delayToPropogate(); + + if (convoState != "blocked") { + throw new Error(`conversations blocked by bob should be blocked not ${convoState}`); + } + + return true +}); + diff --git a/ios/Wrappers/ConversationWrapper.swift b/ios/Wrappers/ConversationWrapper.swift index 894abc836..6f40de0c3 100644 --- a/ios/Wrappers/ConversationWrapper.swift +++ b/ios/Wrappers/ConversationWrapper.swift @@ -24,7 +24,7 @@ struct ConversationWrapper { "context": context, "peerAddress": conversation.peerAddress, "version": conversation.version == .v1 ? "v1" : "v2", - "conversationID": conversation.conversationID ?? "" + "conversationID": conversation.conversationID ?? "", ] } diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index bd6ae9c77..19b51662e 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -545,12 +545,23 @@ public class XMTPModule: Module { return try await client.contacts.allow(addresses: addresses) } - AsyncFunction("refreshAllowList") { (clientAddress: String) in + AsyncFunction("refreshAllowList") { (clientAddress: String) in guard let client = await clientsManager.getClient(key: clientAddress) else { throw Error.noClient } return try await client.contacts.refreshAllowList() - } + } + + AsyncFunction("conversationAllowState") { (clientAddress: String, conversationTopic: String) -> String in + guard let conversation = try await findConversation(clientAddress: clientAddress, topic: topic) else { + throw Error.conversationNotFound(topic) + } + switch (conversation.allowState()) { + case .allowed -> return "allowed" + case .blocked -> return "blocked" + case .unknown -> return "unknown" + } + } } // diff --git a/src/index.ts b/src/index.ts index d858bfc71..2d3d4cd27 100644 --- a/src/index.ts +++ b/src/index.ts @@ -261,6 +261,13 @@ export async function decodeMessage( ); } +export async function conversationAllowState( + clientAddress: string, + conversationTopic: string +): Promise<"allowed" | "blocked" | "unknown"> { + return await XMTPModule.conversationAllowState(clientAddress, conversationTopic); +} + export async function isAllowed( clientAddress: string, address: string, diff --git a/src/lib/Conversation.ts b/src/lib/Conversation.ts index c400f285a..ca25ec33b 100644 --- a/src/lib/Conversation.ts +++ b/src/lib/Conversation.ts @@ -114,6 +114,10 @@ export class Conversation { } } + async allowState(): Promise<"allowed" | "blocked" | "unknown"> { + return await XMTP.conversationAllowState(this.clientAddress, this.topic); + } + streamMessages( callback: (message: DecodedMessage) => Promise, ): () => void { From 71d379326d43ac928af497a61824876920b1d66e Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 25 Oct 2023 21:48:36 -0700 Subject: [PATCH 05/15] fix up the iOS code --- example/src/tests.ts | 24 ++++++++++++++++-------- ios/XMTPModule.swift | 22 +++++++++++----------- src/lib/Client.ts | 1 + 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/example/src/tests.ts b/example/src/tests.ts index 8fd7f73ab..53f6f04c8 100644 --- a/example/src/tests.ts +++ b/example/src/tests.ts @@ -19,9 +19,9 @@ function test(name: string, perform: () => Promise) { tests.push({ name, run: perform }); } -// test("can fail", async () => { -// return false; -// }); +test("can fail", async () => { + return false; +}); test("can make a client", async () => { const client = await XMTP.Client.createRandom({ @@ -559,9 +559,17 @@ test("canManagePreferences", async () => { ); await delayToPropogate(); - const initialState = await bo.contacts.isAllowed(alixConversation.clientAddress) + await bo.contacts.refreshAllowList(); + await delayToPropogate(); + + const initialConvoState = await alixConversation.allowState(); + if (initialConvoState != "allowed") { + throw new Error(`conversations created by bo should be allowed by default not ${initialConvoState}`); + } + + const initialState = await bo.contacts.isAllowed(alixConversation.clientAddress); if (!initialState) { - throw new Error(`conversations created by bob should be allowed by default not ${initialState}`); + throw new Error(`contacts created by bo should be allowed by default not ${initialState}`); } bo.contacts.block([alixConversation.clientAddress]); @@ -570,18 +578,18 @@ test("canManagePreferences", async () => { const blockedState = await bo.contacts.isBlocked(alixConversation.clientAddress); const allowedState = await bo.contacts.isAllowed(alixConversation.clientAddress); if (!blockedState) { - throw new Error(`conversations blocked by bob should be blocked not ${blockedState}`); + throw new Error(`contacts blocked by bo should be blocked not ${blockedState}`); } if (allowedState) { - throw new Error(`conversations blocked by bob should be blocked not ${allowedState}`); + throw new Error(`contacts blocked by bo should be blocked not ${allowedState}`); } const convoState = await alixConversation.allowState(); await delayToPropogate(); if (convoState != "blocked") { - throw new Error(`conversations blocked by bob should be blocked not ${convoState}`); + throw new Error(`conversations blocked by bo should be blocked not ${convoState}`); } return true diff --git a/ios/XMTPModule.swift b/ios/XMTPModule.swift index 19b51662e..ca4ef9baf 100644 --- a/ios/XMTPModule.swift +++ b/ios/XMTPModule.swift @@ -521,45 +521,45 @@ public class XMTPModule: Module { guard let client = await clientsManager.getClient(key: clientAddress) else { throw Error.noClient } - return await client.contacts.isAllowed(address: address) + return await client.contacts.isAllowed(address) } AsyncFunction("isBlocked") { (clientAddress: String, address: String) -> Bool in guard let client = await clientsManager.getClient(key: clientAddress) else { throw Error.noClient } - return await client.contacts.isBlocked(address: address) + return await client.contacts.isBlocked(address) } AsyncFunction("blockContacts") { (clientAddress: String, addresses: [String]) in guard let client = await clientsManager.getClient(key: clientAddress) else { throw Error.noClient } - return try await client.contacts.block(addresses: addresses) + try await client.contacts.block(addresses: addresses) } AsyncFunction("allowContacts") { (clientAddress: String, addresses: [String]) in guard let client = await clientsManager.getClient(key: clientAddress) else { throw Error.noClient } - return try await client.contacts.allow(addresses: addresses) + try await client.contacts.allow(addresses: addresses) } AsyncFunction("refreshAllowList") { (clientAddress: String) in guard let client = await clientsManager.getClient(key: clientAddress) else { throw Error.noClient } - return try await client.contacts.refreshAllowList() + try await client.contacts.refreshAllowList() } AsyncFunction("conversationAllowState") { (clientAddress: String, conversationTopic: String) -> String in - guard let conversation = try await findConversation(clientAddress: clientAddress, topic: topic) else { - throw Error.conversationNotFound(topic) + guard let conversation = try await findConversation(clientAddress: clientAddress, topic: conversationTopic) else { + throw Error.conversationNotFound(conversationTopic) } - switch (conversation.allowState()) { - case .allowed -> return "allowed" - case .blocked -> return "blocked" - case .unknown -> return "unknown" + switch (await conversation.allowState()) { + case .allowed: return "allowed" + case .blocked: return "blocked" + case .unknown: return "unknown" } } } diff --git a/src/lib/Client.ts b/src/lib/Client.ts index c97f13277..0f338ff0f 100644 --- a/src/lib/Client.ts +++ b/src/lib/Client.ts @@ -86,6 +86,7 @@ export class Client { constructor(address: string) { this.address = address; this.conversations = new Conversations(this); + this.contacts = new Contacts(this); } async exportKeyBundle(): Promise { From c9a8f102f439f0cc5f468990acf23e6a893fee58 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 25 Oct 2023 21:58:59 -0700 Subject: [PATCH 06/15] was using wrong address --- example/src/tests.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/example/src/tests.ts b/example/src/tests.ts index 53f6f04c8..757dc8483 100644 --- a/example/src/tests.ts +++ b/example/src/tests.ts @@ -559,24 +559,21 @@ test("canManagePreferences", async () => { ); await delayToPropogate(); - await bo.contacts.refreshAllowList(); - await delayToPropogate(); - const initialConvoState = await alixConversation.allowState(); if (initialConvoState != "allowed") { throw new Error(`conversations created by bo should be allowed by default not ${initialConvoState}`); } - const initialState = await bo.contacts.isAllowed(alixConversation.clientAddress); + const initialState = await bo.contacts.isAllowed(alixConversation.peerAddress); if (!initialState) { throw new Error(`contacts created by bo should be allowed by default not ${initialState}`); } - bo.contacts.block([alixConversation.clientAddress]); + bo.contacts.block([alixConversation.peerAddress]); await delayToPropogate(); - const blockedState = await bo.contacts.isBlocked(alixConversation.clientAddress); - const allowedState = await bo.contacts.isAllowed(alixConversation.clientAddress); + const blockedState = await bo.contacts.isBlocked(alixConversation.peerAddress); + const allowedState = await bo.contacts.isAllowed(alixConversation.peerAddress); if (!blockedState) { throw new Error(`contacts blocked by bo should be blocked not ${blockedState}`); } From afed9a4bc50b1ba2856baf377cf56c5c10af012c Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 25 Oct 2023 22:03:41 -0700 Subject: [PATCH 07/15] remove fake test --- example/src/tests.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/example/src/tests.ts b/example/src/tests.ts index 757dc8483..9b551c2a2 100644 --- a/example/src/tests.ts +++ b/example/src/tests.ts @@ -19,10 +19,6 @@ function test(name: string, perform: () => Promise) { tests.push({ name, run: perform }); } -test("can fail", async () => { - return false; -}); - test("can make a client", async () => { const client = await XMTP.Client.createRandom({ env: "local", From 9d652b6aab9f70adf0b0681ea06d2bf75c8be07e Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 25 Oct 2023 22:04:28 -0700 Subject: [PATCH 08/15] optimize android imports --- .../src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index fa68faf5b..4de2be440 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -19,10 +19,8 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking import kotlinx.coroutines.suspendCancellableCoroutine import org.json.JSONObject -import org.xmtp.android.library.AllowList import org.xmtp.android.library.AllowState import org.xmtp.android.library.Client import org.xmtp.android.library.ClientOptions From b125af92b15d0fd64f718c39c298c14d25dd953d Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Wed, 25 Oct 2023 22:05:46 -0700 Subject: [PATCH 09/15] remove comma accidentally added --- ios/Wrappers/ConversationWrapper.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Wrappers/ConversationWrapper.swift b/ios/Wrappers/ConversationWrapper.swift index 6f40de0c3..894abc836 100644 --- a/ios/Wrappers/ConversationWrapper.swift +++ b/ios/Wrappers/ConversationWrapper.swift @@ -24,7 +24,7 @@ struct ConversationWrapper { "context": context, "peerAddress": conversation.peerAddress, "version": conversation.version == .v1 ? "v1" : "v2", - "conversationID": conversation.conversationID ?? "", + "conversationID": conversation.conversationID ?? "" ] } From 555fa885a64f74db7eb5b4c47b71e6a0cef6f6fb Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 26 Oct 2023 07:45:49 -0700 Subject: [PATCH 10/15] forgot to commit the contacts file --- src/lib/Contacts.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/lib/Contacts.ts diff --git a/src/lib/Contacts.ts b/src/lib/Contacts.ts new file mode 100644 index 000000000..d8505f787 --- /dev/null +++ b/src/lib/Contacts.ts @@ -0,0 +1,32 @@ +import { Client } from "./Client"; +import * as XMTPModule from "../index"; + +export default class Contacts { + client: Client; + + constructor(client: Client) { + this.client = client; + } + + async isAllowed(address: string): Promise { + const result = await XMTPModule.isAllowed(this.client.address, address); + return result; + } + + async isBlocked(address: string): Promise { + const result = await XMTPModule.isBlocked(this.client.address, address); + return result; + } + + block(addresses: string[]) { + XMTPModule.blockContacts(this.client.address, addresses); + } + + allow(addresses: string[]) { + XMTPModule.allowContacts(this.client.address, addresses); + } + + refreshAllowList() { + XMTPModule.refreshAllowList(this.client.address); + } +} From e318c990c5c31c44cf8648bf4da9b42f584f0495 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 26 Oct 2023 08:24:22 -0700 Subject: [PATCH 11/15] add an example to the example app --- example/src/HomeScreen.tsx | 24 ++++++++++++++++++++---- example/src/hooks.tsx | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/example/src/HomeScreen.tsx b/example/src/HomeScreen.tsx index f120debc0..5f0664c92 100644 --- a/example/src/HomeScreen.tsx +++ b/example/src/HomeScreen.tsx @@ -10,8 +10,8 @@ import { Text, View, } from "react-native"; -import React, { useContext } from "react"; -import { Conversation } from "xmtp-react-native-sdk"; +import React, { useContext, useState } from "react"; +import { Conversation, Client } from "xmtp-react-native-sdk"; import { NavigationContext } from "@react-navigation/native"; import { NativeStackNavigationProp } from "@react-navigation/native-stack/src/types"; import moment from "moment"; @@ -33,7 +33,7 @@ export default function HomeScreen() { data={conversations || []} keyExtractor={(item) => item.topic} renderItem={({ item: conversation }) => ( - + )} ListHeaderComponent={ ("Not Set"); + + conversation.allowState().then(result => { + setAllowState(result); + }) + const blockContact = () => client?.contacts.block([conversation.peerAddress]); + return ( @@ -79,6 +86,13 @@ function ConversationItem({ conversation }: { conversation: Conversation }) { ({messages?.length} messages) +