From 6ced314a231e6fc4eb129ebed2c61356c46df219 Mon Sep 17 00:00:00 2001 From: Naomi Plasterer Date: Thu, 19 Dec 2024 17:50:06 -0800 Subject: [PATCH] add support for streaming hmac keys --- .../android/library/PrivatePreferences.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/library/src/main/java/org/xmtp/android/library/PrivatePreferences.kt b/library/src/main/java/org/xmtp/android/library/PrivatePreferences.kt index cefd859a..c3a32718 100644 --- a/library/src/main/java/org/xmtp/android/library/PrivatePreferences.kt +++ b/library/src/main/java/org/xmtp/android/library/PrivatePreferences.kt @@ -4,11 +4,15 @@ import android.util.Log import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow +import org.xmtp.proto.keystore.api.v1.Keystore +import org.xmtp.proto.keystore.api.v1.Keystore.GetConversationHmacKeysResponse.HmacKeys import uniffi.xmtpv3.FfiConsent import uniffi.xmtpv3.FfiConsentCallback import uniffi.xmtpv3.FfiConsentEntityType import uniffi.xmtpv3.FfiConsentState import uniffi.xmtpv3.FfiDeviceSyncKind +import uniffi.xmtpv3.FfiPreferenceCallback +import uniffi.xmtpv3.FfiPreferenceUpdate import uniffi.xmtpv3.FfiSubscribeException import uniffi.xmtpv3.FfiXmtpClient @@ -96,6 +100,26 @@ data class PrivatePreferences( var client: Client, private val ffiClient: FfiXmtpClient, ) { + suspend fun streamHmacKeys(): Flow = callbackFlow { + val preferenceCallback = object : FfiPreferenceCallback { + override fun onPreferenceUpdate(preference: List) { + preference.iterator().forEach { + when(it) { + is FfiPreferenceUpdate.Hmac -> it.key + } + } + } + + override fun onError(error: FfiSubscribeException) { + Log.e("XMTP hmac key stream", error.message.toString()) + } + } + + val stream = ffiClient.conversations().streamPreferences(preferenceCallback) + + awaitClose { stream.end() } + } + suspend fun streamConsent(): Flow = callbackFlow { val consentCallback = object : FfiConsentCallback { override fun onConsentUpdate(consent: List) {