@@ -84,7 +84,7 @@ data class ConversationV2(
84
84
val result = runBlocking {
85
85
client.apiClient.envelopes(
86
86
topic = topic,
87
- pagination = pagination
87
+ pagination = pagination,
88
88
)
89
89
}
90
90
@@ -133,7 +133,7 @@ data class ConversationV2(
133
133
topic,
134
134
message.v2,
135
135
keyMaterial,
136
- client
136
+ client,
137
137
)
138
138
}
139
139
@@ -155,7 +155,7 @@ data class ConversationV2(
155
155
topic = topic,
156
156
message.v2,
157
157
keyMaterial = keyMaterial,
158
- client = client
158
+ client = client,
159
159
)
160
160
}
161
161
@@ -184,7 +184,12 @@ data class ConversationV2(
184
184
}
185
185
186
186
fun send (encodedContent : EncodedContent , options : SendOptions ? ): String {
187
- val preparedMessage = prepareMessage(encodedContent = encodedContent, options = options)
187
+ val codec = Client .codecRegistry.find(options?.contentType)
188
+ val preparedMessage = prepareMessage(
189
+ encodedContent = encodedContent,
190
+ options = options,
191
+ shouldPush = shouldPush(codec, encodedContent.content),
192
+ )
188
193
return send(preparedMessage)
189
194
}
190
195
@@ -202,16 +207,26 @@ data class ConversationV2(
202
207
client = client,
203
208
encodedContent = encodedContent,
204
209
topic = topic,
205
- keyMaterial = keyMaterial
210
+ keyMaterial = keyMaterial,
211
+ shouldPush = shouldPush(codec, content),
206
212
)
207
213
val envelope = EnvelopeBuilder .buildFromString(
208
214
topic = topic,
209
215
timestamp = Date (),
210
- message = MessageBuilder .buildFromMessageV2(v2 = message).toByteArray()
216
+ message = MessageBuilder .buildFromMessageV2(v2 = message).toByteArray(),
211
217
)
212
218
return envelope.toByteArray()
213
219
}
214
220
221
+ fun <Codec : ContentCodec <T >, T > shouldPush (codec : Codec , content : Any? ): Boolean {
222
+ val contentType = content as ? T
223
+ if (contentType != null ) {
224
+ return codec.shouldPush(content = content)
225
+ } else {
226
+ throw XMTPException (" Codec invalid content" )
227
+ }
228
+ }
229
+
215
230
fun <T > prepareMessage (content : T , options : SendOptions ? ): PreparedMessage {
216
231
val codec = Client .codecRegistry.find(options?.contentType)
217
232
@@ -235,23 +250,28 @@ data class ConversationV2(
235
250
if (compression != null ) {
236
251
encoded = encoded.compress(compression)
237
252
}
238
- return prepareMessage(encoded, options = options)
253
+ return prepareMessage(encoded, options = options, shouldPush = shouldPush(codec, content) )
239
254
}
240
255
241
- fun prepareMessage (encodedContent : EncodedContent , options : SendOptions ? ): PreparedMessage {
256
+ fun prepareMessage (
257
+ encodedContent : EncodedContent ,
258
+ options : SendOptions ? ,
259
+ shouldPush : Boolean ,
260
+ ): PreparedMessage {
242
261
val message = MessageV2Builder .buildEncode(
243
262
client = client,
244
263
encodedContent = encodedContent,
245
264
topic = topic,
246
- keyMaterial = keyMaterial
265
+ keyMaterial = keyMaterial,
266
+ shouldPush = shouldPush,
247
267
)
248
268
249
269
val newTopic = if (options?.ephemeral == true ) ephemeralTopic else topic
250
270
251
271
val envelope = EnvelopeBuilder .buildFromString(
252
272
topic = newTopic,
253
273
timestamp = Date (),
254
- message = MessageBuilder .buildFromMessageV2(v2 = message).toByteArray()
274
+ message = MessageBuilder .buildFromMessageV2(v2 = message).toByteArray(),
255
275
)
256
276
return PreparedMessage (listOf (envelope))
257
277
}
0 commit comments