Skip to content

Commit

Permalink
Merge pull request #288 from xmtp/cv/fix-npe-null-key-material-android
Browse files Browse the repository at this point in the history
fix: prevents NPE on null key material on android
  • Loading branch information
cameronvoell authored Feb 27, 2024
2 parents 763d037 + a614a28 commit c12f56f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ class XMTPModule : Module() {
val data = TopicData.parseFrom(Base64.decode(topicData, NO_WRAP))
val conversation = client.conversations.importTopicData(data)
conversations[conversation.cacheKey(clientAddress)] = conversation
if (conversation.keyMaterial == null) {
logV("Null key material before encode conversation")
}
ConversationWrapper.encode(client, conversation)
}

Expand Down Expand Up @@ -381,6 +384,9 @@ class XMTPModule : Module() {
val conversationList = client.conversations.list()
conversationList.map { conversation ->
conversations[conversation.cacheKey(clientAddress)] = conversation
if (conversation.keyMaterial == null) {
logV("Null key material before encode conversation")
}
ConversationWrapper.encode(client, conversation)
}
}
Expand Down Expand Up @@ -561,6 +567,9 @@ class XMTPModule : Module() {
},
)
)
if (conversation.keyMaterial == null) {
logV("Null key material before encode conversation")
}
ConversationWrapper.encode(client, conversation)
}

Expand Down Expand Up @@ -713,13 +722,21 @@ class XMTPModule : Module() {
subscriptions[getConversationsKey(clientAddress)] = CoroutineScope(Dispatchers.IO).launch {
try {
client.conversations.stream().collect { conversation ->
sendEvent(
"conversation",
mapOf(
"clientAddress" to clientAddress,
"conversation" to ConversationWrapper.encodeToObj(client, conversation)
run {
if (conversation.keyMaterial == null) {
logV("Null key material before encode conversation")
}
sendEvent(
"conversation",
mapOf(
"clientAddress" to clientAddress,
"conversation" to ConversationWrapper.encodeToObj(
client,
conversation
)
)
)
)
}
}
} catch (e: Exception) {
Log.e("XMTPModule", "Error in conversations subscription: $e")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ConversationWrapper {
"peerAddress" to conversation.peerAddress,
"version" to if (conversation.version == Conversation.Version.V1) "v1" else "v2",
"conversationID" to (conversation.conversationId ?: ""),
"keyMaterial" to Base64.encodeToString(conversation.keyMaterial, Base64.NO_WRAP)
"keyMaterial" to (conversation.keyMaterial?.let { Base64.encodeToString(it, Base64.NO_WRAP) } ?: "")
)
}

Expand Down

0 comments on commit c12f56f

Please sign in to comment.