@@ -2,7 +2,6 @@ package org.xmtp.android.library
2
2
3
3
import android.util.Log
4
4
import kotlinx.coroutines.flow.Flow
5
- import kotlinx.coroutines.flow.collect
6
5
import kotlinx.coroutines.flow.flow
7
6
import kotlinx.coroutines.runBlocking
8
7
import org.web3j.crypto.Hash
@@ -89,20 +88,22 @@ data class ConversationV1(
89
88
sentAt : Date ? = null,
90
89
): String {
91
90
val preparedMessage = prepareMessage(content = text, options = sendOptions)
92
- preparedMessage.send()
93
- return preparedMessage.messageId
91
+ return send(preparedMessage)
94
92
}
95
93
96
94
fun <T > send (content : T , options : SendOptions ? = null): String {
97
95
val preparedMessage = prepareMessage(content = content, options = options)
98
- preparedMessage.send()
99
- return preparedMessage.messageId
96
+ return send(preparedMessage)
100
97
}
101
98
102
99
fun send (encodedContent : EncodedContent , options : SendOptions ? = null): String {
103
100
val preparedMessage = prepareMessage(encodedContent = encodedContent, options = options)
104
- preparedMessage.send()
105
- return preparedMessage.messageId
101
+ return send(preparedMessage)
102
+ }
103
+
104
+ fun send (prepared : PreparedMessage ): String {
105
+ client.publish(envelopes = prepared.envelopes)
106
+ return prepared.messageId
106
107
}
107
108
108
109
fun <T > prepareMessage (content : T , options : SendOptions ? ): PreparedMessage {
@@ -147,36 +148,28 @@ data class ConversationV1(
147
148
148
149
val isEphemeral: Boolean = options != null && options.ephemeral
149
150
150
- val messageEnvelope =
151
+ val env =
151
152
EnvelopeBuilder .buildFromString(
152
153
topic = if (isEphemeral) ephemeralTopic else topic.description,
153
154
timestamp = date,
154
155
message = MessageBuilder .buildFromMessageV1(v1 = message).toByteArray()
155
156
)
156
- return PreparedMessage (
157
- messageEnvelope = messageEnvelope,
158
- conversation = Conversation .V1 (this )
159
- ) {
160
- val envelopes = mutableListOf (messageEnvelope)
161
- if (client.contacts.needsIntroduction(peerAddress) && ! isEphemeral) {
162
- envelopes.addAll(
163
- listOf (
164
- EnvelopeBuilder .buildFromTopic(
165
- topic = Topic .userIntro(peerAddress),
166
- timestamp = date,
167
- message = MessageBuilder .buildFromMessageV1(v1 = message).toByteArray()
168
- ),
169
- EnvelopeBuilder .buildFromTopic(
170
- topic = Topic .userIntro(client.address),
171
- timestamp = date,
172
- message = MessageBuilder .buildFromMessageV1(v1 = message).toByteArray()
173
- )
174
- )
157
+
158
+ val envelopes = mutableListOf (env)
159
+ if (client.contacts.needsIntroduction(peerAddress) && ! isEphemeral) {
160
+ envelopes.addAll(
161
+ listOf (
162
+ env.toBuilder().apply {
163
+ contentTopic = Topic .userIntro(peerAddress).description
164
+ }.build(),
165
+ env.toBuilder().apply {
166
+ contentTopic = Topic .userIntro(client.address).description
167
+ }.build(),
175
168
)
176
- client.contacts.hasIntroduced[peerAddress] = true
177
- }
178
- client.publish(envelopes = envelopes)
169
+ )
170
+ client.contacts.hasIntroduced[peerAddress] = true
179
171
}
172
+ return PreparedMessage (envelopes)
180
173
}
181
174
182
175
private fun generateId (envelope : Envelope ): String =
0 commit comments