Skip to content

Commit

Permalink
Fail silently for messages that can't decrypt (#69)
Browse files Browse the repository at this point in the history
* add api client with grpc kotlin

* catch the exception in decryption and fail silently
  • Loading branch information
nplasterer authored Apr 25, 2023
1 parent c00314a commit cb42008
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions library/src/main/java/org/xmtp/android/library/Conversations.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.xmtp.android.library

import android.util.Log
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.runBlocking
Expand All @@ -23,13 +24,18 @@ import org.xmtp.android.library.messages.toSignedPublicKeyBundle
import org.xmtp.android.library.messages.walletAddress
import org.xmtp.proto.message.contents.Contact
import org.xmtp.proto.message.contents.Invitation
import java.lang.Exception
import java.util.Date

data class Conversations(
var client: Client,
var conversations: MutableList<Conversation> = mutableListOf(),
) {

companion object {
private const val TAG = "CONVERSATIONS"
}

fun fromInvite(envelope: Envelope): Conversation {
val sealedInvitation = Invitation.SealedInvitation.parseFrom(envelope.message)
val unsealed = sealedInvitation.v1.getInvitation(viewer = client.keys)
Expand Down Expand Up @@ -171,11 +177,16 @@ data class Conversations(
topic = Topic.userIntro(client.address)
).envelopesList
}
val messages = envelopes.map { envelope ->
val message = MessageV1Builder.buildFromBytes(envelope.message.toByteArray())
// Attempt to decrypt, just to make sure we can
message.decrypt(client.privateKeyBundleV1)
message
val messages = envelopes.mapNotNull { envelope ->
try {
val message = MessageV1Builder.buildFromBytes(envelope.message.toByteArray())
// Attempt to decrypt, just to make sure we can
message.decrypt(client.privateKeyBundleV1)
message
} catch (e: Exception) {
Log.d(TAG, e.message.toString())
null
}
}
val seenPeers: MutableMap<String, Date> = mutableMapOf()
for (message in messages) {
Expand Down

0 comments on commit cb42008

Please sign in to comment.