Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevents NPE on null key material on android #288

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading