@@ -22,6 +22,7 @@ import org.xmtp.android.library.messages.toPublicKeyBundle
22
22
import org.xmtp.android.library.messages.walletAddress
23
23
import org.xmtp.proto.message.api.v1.MessageApiOuterClass.QueryRequest
24
24
import org.xmtp.proto.message.contents.Contact
25
+ import org.xmtp.proto.message.contents.InvitationV1Kt.context
25
26
import org.xmtp.proto.message.contents.PrivateKeyOuterClass
26
27
import java.util.Date
27
28
@@ -140,6 +141,51 @@ class LocalInstrumentedTest {
140
141
assertEquals(" now" , nowMessage2.body)
141
142
}
142
143
144
+ @Test
145
+ fun testListingConversations () {
146
+ val alice = Client ().create(
147
+ PrivateKeyBuilder (),
148
+ ClientOptions (api = ClientOptions .Api (env = XMTPEnvironment .LOCAL , isSecure = false ))
149
+ )
150
+ val bob = Client ().create(
151
+ PrivateKeyBuilder (),
152
+ ClientOptions (api = ClientOptions .Api (env = XMTPEnvironment .LOCAL , isSecure = false ))
153
+ )
154
+
155
+ // First Bob starts a conversation with Alice
156
+ val c1 = bob.conversations.newConversation(
157
+ alice.address,
158
+ context = context {
159
+ conversationId = " example.com/alice-bob-1"
160
+ metadata[" title" ] = " First Chat"
161
+ }
162
+ )
163
+ c1.send(" hello Alice!" )
164
+ delayToPropagate()
165
+
166
+ // So Alice should see just that one conversation.
167
+ var aliceConvoList = alice.conversations.list()
168
+ assertEquals(1 , aliceConvoList.size)
169
+ assertEquals(" example.com/alice-bob-1" , aliceConvoList[0 ].conversationId)
170
+
171
+ // And later when Bob starts a second conversation with Alice
172
+ val c2 = bob.conversations.newConversation(
173
+ alice.address,
174
+ context = context {
175
+ conversationId = " example.com/alice-bob-2"
176
+ metadata[" title" ] = " Second Chat"
177
+ }
178
+ )
179
+ c2.send(" hello again Alice!" )
180
+ delayToPropagate()
181
+
182
+ // Then Alice should see both conversations, the newer one first.
183
+ aliceConvoList = alice.conversations.list()
184
+ assertEquals(2 , aliceConvoList.size)
185
+ assertEquals(" example.com/alice-bob-2" , aliceConvoList[0 ].conversationId)
186
+ assertEquals(" example.com/alice-bob-1" , aliceConvoList[1 ].conversationId)
187
+ }
188
+
143
189
@Test
144
190
fun testCanPaginateV1Messages () {
145
191
val bob = PrivateKeyBuilder ()
@@ -247,4 +293,9 @@ class LocalInstrumentedTest {
247
293
248
294
assertEquals(result.responsesOrBuilderList.size, 1 )
249
295
}
296
+
297
+ // A delay to allow messages to propagate before making assertions.
298
+ private fun delayToPropagate () {
299
+ Thread .sleep(500 )
300
+ }
250
301
}
0 commit comments