Skip to content

Commit 887f1f4

Browse files
author
Ezequiel Leanes
authored
feat: integrate `shouldPush' for React Native (#184)
* Add shouldPush property to SendOptions * Add shouldPush property to DecryptedMessage class * Add shouldPush parameter to ConversationV2 and MessageV2Builder
1 parent 4b1aba5 commit 887f1f4

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

library/src/main/java/org/xmtp/android/library/ConversationV2.kt

+1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ data class ConversationV2(
250250
topic = topic,
251251
keyMaterial = keyMaterial,
252252
codec = codec,
253+
shouldPush = options?.shouldPush
253254
)
254255

255256
val newTopic = if (options?.ephemeral == true) ephemeralTopic else topic

library/src/main/java/org/xmtp/android/library/SendOptions.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ import org.xmtp.proto.message.contents.Content
55
data class SendOptions(
66
var compression: EncodedContentCompression? = null,
77
var contentType: Content.ContentTypeId? = null,
8-
var ephemeral: Boolean = false
8+
var ephemeral: Boolean = false,
9+
var shouldPush: Boolean? = null
910
)

library/src/main/java/org/xmtp/android/library/messages/DecryptedMessage.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ data class DecryptedMessage(
88
var encodedContent: EncodedContent,
99
var senderAddress: String,
1010
var sentAt: Date,
11-
var topic: String = ""
11+
var topic: String = "",
12+
var shouldPush: Boolean?
1213
)

library/src/main/java/org/xmtp/android/library/messages/MessageV2.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class MessageV2Builder(val senderHmac: ByteArray? = null, val shouldPush: Boolea
138138
topic: String,
139139
keyMaterial: ByteArray,
140140
codec: Codec,
141+
shouldPush: Boolean? = null
141142
): MessageV2Builder {
142143
val payload = encodedContent.toByteArray()
143144
val date = Date()
@@ -160,12 +161,13 @@ class MessageV2Builder(val senderHmac: ByteArray? = null, val shouldPush: Boolea
160161
Crypto.deriveKey(keyMaterial, ByteArray(0), infoEncoded),
161162
headerBytes
162163
)
164+
val calculatedShouldPush = shouldPush ?: shouldPush(codec = codec, content = codec.decode(encodedContent))
163165

164166
return buildFromCipherText(
165167
headerBytes,
166168
ciphertext,
167169
senderHmacGenerated,
168-
shouldPush(codec = codec, content = codec.decode(encodedContent)),
170+
calculatedShouldPush,
169171
)
170172
}
171173
}

0 commit comments

Comments
 (0)