Skip to content

Commit

Permalink
Update consent to a batched call (#299)
Browse files Browse the repository at this point in the history
* update the library

* bump the libraries

* get the batch consent setup for performance
  • Loading branch information
nplasterer authored Sep 20, 2024
1 parent 8e37581 commit 51d4748
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 30 deletions.
4 changes: 2 additions & 2 deletions library/src/main/java/libxmtp-version.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 7e70ad48
Version: 34d32499
Branch: main
Date: 2024-09-13 15:56:37 +0000
Date: 2024-09-19 21:05:16 +0000
17 changes: 10 additions & 7 deletions library/src/main/java/org/xmtp/android/library/Contacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.xmtp.android.library.messages.Topic
import org.xmtp.android.library.messages.walletAddress
import org.xmtp.proto.message.api.v1.MessageApiOuterClass
import org.xmtp.proto.message.contents.PrivatePreferences.PrivatePreferencesAction
import uniffi.xmtpv3.FfiConsent
import uniffi.xmtpv3.FfiConsentEntityType
import uniffi.xmtpv3.FfiConsentState
import java.util.Date
Expand Down Expand Up @@ -89,6 +90,14 @@ data class ConsentListEntry(
}
}

fun toFfiConsent(): FfiConsent {
return FfiConsent(
EntryType.toFfiConsentEntityType(entryType),
ConsentState.toFfiConsentState(consentType),
value
)
}

val key: String
get() = "${entryType.name}-$value"
}
Expand Down Expand Up @@ -230,13 +239,7 @@ class ConsentList(
}

suspend fun setV3ConsentState(entries: List<ConsentListEntry>) {
entries.iterator().forEach {
client.v3Client?.setConsentState(
ConsentState.toFfiConsentState(it.consentType),
EntryType.toFfiConsentEntityType(it.entryType),
it.value
)
}
client.v3Client?.setConsentStates(entries.map { it.toFfiConsent() })
}

fun allow(address: String): ConsentListEntry {
Expand Down
84 changes: 63 additions & 21 deletions library/src/main/java/xmtpv3.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1269,11 +1269,8 @@ internal interface UniffiLib : Library {
`ptr`: Pointer, `walletAddress`: RustBuffer.ByValue,
): Long

fun uniffi_xmtpv3_fn_method_ffixmtpclient_set_consent_state(
`ptr`: Pointer,
`state`: RustBuffer.ByValue,
`entityType`: RustBuffer.ByValue,
`entity`: RustBuffer.ByValue,
fun uniffi_xmtpv3_fn_method_ffixmtpclient_set_consent_states(
`ptr`: Pointer, `records`: RustBuffer.ByValue,
): Long

fun uniffi_xmtpv3_fn_method_ffixmtpclient_signature_request(
Expand Down Expand Up @@ -1912,7 +1909,7 @@ internal interface UniffiLib : Library {
fun uniffi_xmtpv3_checksum_method_ffixmtpclient_revoke_wallet(
): Short

fun uniffi_xmtpv3_checksum_method_ffixmtpclient_set_consent_state(
fun uniffi_xmtpv3_checksum_method_ffixmtpclient_set_consent_states(
): Short

fun uniffi_xmtpv3_checksum_method_ffixmtpclient_signature_request(
Expand Down Expand Up @@ -2247,7 +2244,7 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) {
if (lib.uniffi_xmtpv3_checksum_method_ffixmtpclient_revoke_wallet() != 12211.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffixmtpclient_set_consent_state() != 36178.toShort()) {
if (lib.uniffi_xmtpv3_checksum_method_ffixmtpclient_set_consent_states() != 64566.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_xmtpv3_checksum_method_ffixmtpclient_signature_request() != 18270.toShort()) {
Expand Down Expand Up @@ -6248,11 +6245,7 @@ public interface FfiXmtpClientInterface {
*/
suspend fun `revokeWallet`(`walletAddress`: kotlin.String): FfiSignatureRequest

suspend fun `setConsentState`(
`state`: FfiConsentState,
`entityType`: FfiConsentEntityType,
`entity`: kotlin.String,
)
suspend fun `setConsentStates`(`records`: List<FfiConsent>)

fun `signatureRequest`(): FfiSignatureRequest?

Expand Down Expand Up @@ -6830,18 +6823,12 @@ open class FfiXmtpClient : Disposable, AutoCloseable, FfiXmtpClientInterface {

@Throws(GenericException::class)
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
override suspend fun `setConsentState`(
`state`: FfiConsentState,
`entityType`: FfiConsentEntityType,
`entity`: kotlin.String,
) {
override suspend fun `setConsentStates`(`records`: List<FfiConsent>) {
return uniffiRustCallAsync(
callWithPointer { thisPtr ->
UniffiLib.INSTANCE.uniffi_xmtpv3_fn_method_ffixmtpclient_set_consent_state(
UniffiLib.INSTANCE.uniffi_xmtpv3_fn_method_ffixmtpclient_set_consent_states(
thisPtr,
FfiConverterTypeFfiConsentState.lower(`state`),
FfiConverterTypeFfiConsentEntityType.lower(`entityType`),
FfiConverterString.lower(`entity`),
FfiConverterSequenceTypeFfiConsent.lower(`records`),
)
},
{ future, callback, continuation ->
Expand Down Expand Up @@ -6909,6 +6896,38 @@ public object FfiConverterTypeFfiXmtpClient : FfiConverter<FfiXmtpClient, Pointe
}


data class FfiConsent(
var `entityType`: FfiConsentEntityType,
var `state`: FfiConsentState,
var `entity`: kotlin.String,
) {

companion object
}

public object FfiConverterTypeFfiConsent : FfiConverterRustBuffer<FfiConsent> {
override fun read(buf: ByteBuffer): FfiConsent {
return FfiConsent(
FfiConverterTypeFfiConsentEntityType.read(buf),
FfiConverterTypeFfiConsentState.read(buf),
FfiConverterString.read(buf),
)
}

override fun allocationSize(value: FfiConsent) = (
FfiConverterTypeFfiConsentEntityType.allocationSize(value.`entityType`) +
FfiConverterTypeFfiConsentState.allocationSize(value.`state`) +
FfiConverterString.allocationSize(value.`entity`)
)

override fun write(value: FfiConsent, buf: ByteBuffer) {
FfiConverterTypeFfiConsentEntityType.write(value.`entityType`, buf)
FfiConverterTypeFfiConsentState.write(value.`state`, buf)
FfiConverterString.write(value.`entity`, buf)
}
}


data class FfiCreateGroupOptions(
var `permissions`: FfiGroupPermissionsOptions?,
var `groupName`: kotlin.String?,
Expand Down Expand Up @@ -8527,6 +8546,29 @@ public object FfiConverterSequenceTypeFfiGroup : FfiConverterRustBuffer<List<Ffi
}


public object FfiConverterSequenceTypeFfiConsent : FfiConverterRustBuffer<List<FfiConsent>> {
override fun read(buf: ByteBuffer): List<FfiConsent> {
val len = buf.getInt()
return List<FfiConsent>(len) {
FfiConverterTypeFfiConsent.read(buf)
}
}

override fun allocationSize(value: List<FfiConsent>): ULong {
val sizeForLength = 4UL
val sizeForItems = value.map { FfiConverterTypeFfiConsent.allocationSize(it) }.sum()
return sizeForLength + sizeForItems
}

override fun write(value: List<FfiConsent>, buf: ByteBuffer) {
buf.putInt(value.size)
value.iterator().forEach {
FfiConverterTypeFfiConsent.write(it, buf)
}
}
}


public object FfiConverterSequenceTypeFfiEnvelope : FfiConverterRustBuffer<List<FfiEnvelope>> {
override fun read(buf: ByteBuffer): List<FfiEnvelope> {
val len = buf.getInt()
Expand Down
Binary file modified library/src/main/jniLibs/arm64-v8a/libuniffi_xmtpv3.so
Binary file not shown.
Binary file modified library/src/main/jniLibs/armeabi-v7a/libuniffi_xmtpv3.so
Binary file not shown.
Binary file modified library/src/main/jniLibs/x86/libuniffi_xmtpv3.so
Binary file not shown.
Binary file modified library/src/main/jniLibs/x86_64/libuniffi_xmtpv3.so
Binary file not shown.

0 comments on commit 51d4748

Please sign in to comment.