diff --git a/android/build.gradle b/android/build.gradle index bcf63beee..d135b80e2 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.7" 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/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index 7bc4df43b..1e4bc02b3 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.suspendCancellableCoroutine import org.json.JSONObject import org.xmtp.android.library.Client import org.xmtp.android.library.ClientOptions +import org.xmtp.android.library.ConsentState import org.xmtp.android.library.Conversation import org.xmtp.android.library.PreparedMessage import org.xmtp.android.library.SendOptions @@ -488,6 +489,43 @@ 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) + } + + AsyncFunction("blockContacts") { clientAddress: String, addresses: List -> + val client = clients[clientAddress] ?: throw XMTPException("No client") + client.contacts.block(addresses) + } + + AsyncFunction("allowContacts") { clientAddress: String, addresses: List -> + val client = clients[clientAddress] ?: throw XMTPException("No client") + client.contacts.allow(addresses) + } + + AsyncFunction("refreshConsentList") { clientAddress: String -> + val client = clients[clientAddress] ?: throw XMTPException("No client") + client.contacts.refreshConsentList() + } + + AsyncFunction("conversationConsentState") { clientAddress: String, conversationTopic: String -> + val conversation = findConversation(clientAddress, conversationTopic) + ?: throw XMTPException("no conversation found for $conversationTopic") + when (conversation.consentState()) { + ConsentState.ALLOWED -> "allowed" + ConsentState.BLOCKED -> "blocked" + ConsentState.UNKNOWN -> "unknown" + } + } } // diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index b64754b66..1ac1075e2 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.3-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.3-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: 3181e5c8e9d9885a97e5c5b22ac523bf9a713656 + XMTPReactNative: 27185719aae360bc307cc6faf7bcf879cf681d97 + XMTPRust: 3c958736a4f4ee798e425b5644551f1c948da4b0 Yoga: 065f0b74dba4832d6e328238de46eb72c5de9556 PODFILE CHECKSUM: 522d88edc2d5fac4825e60a121c24abc18983367 -COCOAPODS: 1.12.1 +COCOAPODS: 1.13.0 diff --git a/example/src/HomeScreen.tsx b/example/src/HomeScreen.tsx index f120debc0..0f60ac520 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={ (); + + conversation.consentState().then(result => { + setConsentState(result); + }) + const blockContact = () => client?.contacts.block([conversation.peerAddress]); + return ( @@ -79,6 +86,13 @@ function ConversationItem({ conversation }: { conversation: Conversation }) { ({messages?.length} messages) +