Skip to content

Commit

Permalink
add support for streaming hmac keys
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Dec 20, 2024
1 parent 82766ee commit 6ced314
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -96,6 +100,26 @@ data class PrivatePreferences(
var client: Client,
private val ffiClient: FfiXmtpClient,
) {
suspend fun streamHmacKeys(): Flow<Keystore.GetConversationHmacKeysResponse> = callbackFlow {
val preferenceCallback = object : FfiPreferenceCallback {
override fun onPreferenceUpdate(preference: List<FfiPreferenceUpdate>) {
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<ConsentRecord> = callbackFlow {
val consentCallback = object : FfiConsentCallback {
override fun onConsentUpdate(consent: List<FfiConsent>) {
Expand Down

0 comments on commit 6ced314

Please sign in to comment.