Skip to content

Commit 8a3cbb3

Browse files
authored
Merge branch 'main' into gg/bugfix/missing_classes_while_running_R8
2 parents 8487d36 + 80559d7 commit 8a3cbb3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2553
-1029
lines changed

example/src/main/java/org/xmtp/android/example/MainViewModel.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import kotlinx.coroutines.flow.emptyFlow
1515
import kotlinx.coroutines.flow.flowOn
1616
import kotlinx.coroutines.flow.mapLatest
1717
import kotlinx.coroutines.launch
18+
import kotlinx.coroutines.runBlocking
1819
import org.xmtp.android.example.extension.flowWhileShared
1920
import org.xmtp.android.example.extension.stateFlow
2021
import org.xmtp.android.example.pushnotifications.PushNotificationTokenManager
@@ -70,7 +71,7 @@ class MainViewModel : ViewModel() {
7071

7172
@WorkerThread
7273
private fun fetchMostRecentMessage(conversation: Conversation): DecodedMessage? {
73-
return conversation.messages(limit = 1).firstOrNull()
74+
return runBlocking { conversation.messages(limit = 1).firstOrNull() }
7475
}
7576

7677
@OptIn(ExperimentalCoroutinesApi::class)

example/src/main/java/org/xmtp/android/example/conversation/ConversationDetailViewModel.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import kotlinx.coroutines.flow.emptyFlow
1515
import kotlinx.coroutines.flow.flowOn
1616
import kotlinx.coroutines.flow.mapLatest
1717
import kotlinx.coroutines.launch
18+
import kotlinx.coroutines.runBlocking
1819
import org.xmtp.android.example.ClientManager
1920
import org.xmtp.android.example.extension.flowWhileShared
2021
import org.xmtp.android.example.extension.stateFlow
@@ -77,7 +78,12 @@ class ConversationDetailViewModel(private val savedStateHandle: SavedStateHandle
7778
stateFlow(viewModelScope, null) { subscriptionCount ->
7879
if (conversation == null) {
7980
conversation =
80-
ClientManager.client.fetchConversation(conversationTopic, includeGroups = false)
81+
runBlocking {
82+
ClientManager.client.fetchConversation(
83+
conversationTopic,
84+
includeGroups = false
85+
)
86+
}
8187
}
8288
if (conversation != null) {
8389
conversation!!.streamMessages()

example/src/main/java/org/xmtp/android/example/message/MessageViewHolder.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ import org.xmtp.android.example.R
1111
import org.xmtp.android.example.conversation.ConversationDetailViewModel
1212
import org.xmtp.android.example.databinding.ListItemMessageBinding
1313
import org.xmtp.android.example.extension.margins
14-
import org.xmtp.proto.mls.message.contents.TranscriptMessages
1514
import uniffi.xmtpv3.org.xmtp.android.library.codecs.GroupMembershipChanges
15+
import java.text.SimpleDateFormat
16+
import java.util.Locale
1617

1718
class MessageViewHolder(
1819
private val binding: ListItemMessageBinding,
@@ -45,6 +46,9 @@ class MessageViewHolder(
4546
binding.messageContainer.layoutParams = params
4647
if (item.message.content<Any>() is String) {
4748
binding.messageBody.text = item.message.body
49+
val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
50+
binding.messageDate.text = sdf.format(item.message.sent)
51+
4852
} else if (item.message.content<Any>() is GroupMembershipChanges) {
4953
val changes = item.message.content() as? GroupMembershipChanges
5054
binding.messageBody.text =

example/src/main/java/org/xmtp/android/example/pushnotifications/PushNotificationsService.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import com.google.firebase.messaging.RemoteMessage
1414
import kotlinx.coroutines.Dispatchers
1515
import kotlinx.coroutines.GlobalScope
1616
import kotlinx.coroutines.launch
17+
import kotlinx.coroutines.runBlocking
1718
import org.xmtp.android.example.ClientManager
1819
import org.xmtp.android.example.R
1920
import org.xmtp.android.example.conversation.ConversationDetailActivity
@@ -56,7 +57,8 @@ class PushNotificationsService : FirebaseMessagingService() {
5657
GlobalScope.launch(Dispatchers.Main) {
5758
ClientManager.createClient(keysData, applicationContext)
5859
}
59-
val conversation = ClientManager.client.fetchConversation(topic, includeGroups = true)
60+
val conversation =
61+
runBlocking { ClientManager.client.fetchConversation(topic, includeGroups = true) }
6062
if (conversation == null) {
6163
Log.e(TAG, "No keys or conversation persisted")
6264
return

example/src/main/res/layout/list_item_message.xml

+18-6
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,25 @@
1515
app:cardCornerRadius="8dp"
1616
app:layout_constraintTop_toTopOf="parent"
1717
tools:ignore="MissingConstraints">
18-
19-
<TextView
20-
android:id="@+id/messageBody"
18+
<LinearLayout
2119
android:layout_width="wrap_content"
22-
android:layout_height="wrap_content"
23-
android:textSize="16sp"
24-
android:layout_margin="8dp" />
20+
android:layout_height="wrap_content">
21+
<TextView
22+
android:id="@+id/messageBody"
23+
android:layout_width="wrap_content"
24+
android:layout_height="wrap_content"
25+
android:textSize="16sp"
26+
android:layout_margin="8dp" />
27+
<TextView
28+
android:id="@+id/messageDate"
29+
android:layout_width="wrap_content"
30+
android:layout_height="wrap_content"
31+
android:textSize="16sp"
32+
android:layout_margin="8dp"
33+
/>
34+
</LinearLayout>
35+
36+
2537

2638
</androidx.cardview.widget.CardView>
2739

library/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ dependencies {
8686
implementation 'org.web3j:crypto:5.0.0'
8787
implementation "net.java.dev.jna:jna:5.13.0@aar"
8888
api 'com.google.protobuf:protobuf-kotlin-lite:3.22.3'
89-
api 'org.xmtp:proto-kotlin:3.40.1'
89+
api 'org.xmtp:proto-kotlin:3.43.2'
9090

9191
testImplementation 'junit:junit:4.13.2'
9292
androidTestImplementation 'app.cash.turbine:turbine:0.12.1'

library/src/androidTest/java/org/xmtp/android/library/AttachmentTest.kt

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.xmtp.android.library
22

33
import androidx.test.ext.junit.runners.AndroidJUnit4
44
import com.google.protobuf.kotlin.toByteStringUtf8
5+
import kotlinx.coroutines.runBlocking
56
import org.junit.Assert.assertEquals
67
import org.junit.Test
78
import org.junit.runner.RunWith
@@ -24,14 +25,17 @@ class AttachmentTest {
2425

2526
val fixtures = fixtures()
2627
val aliceClient = fixtures.aliceClient
27-
val aliceConversation =
28+
val aliceConversation = runBlocking {
2829
aliceClient.conversations.newConversation(fixtures.bob.walletAddress)
30+
}
2931

30-
aliceConversation.send(
31-
content = attachment,
32-
options = SendOptions(contentType = ContentTypeAttachment),
33-
)
34-
val messages = aliceConversation.messages()
32+
runBlocking {
33+
aliceConversation.send(
34+
content = attachment,
35+
options = SendOptions(contentType = ContentTypeAttachment),
36+
)
37+
}
38+
val messages = runBlocking { aliceConversation.messages() }
3539
assertEquals(messages.size, 1)
3640
if (messages.size == 1) {
3741
val content: Attachment? = messages[0].content()

library/src/androidTest/java/org/xmtp/android/library/ClientTest.kt

+88-29
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ package org.xmtp.android.library
22

33
import androidx.test.ext.junit.runners.AndroidJUnit4
44
import androidx.test.platform.app.InstrumentationRegistry
5+
import kotlinx.coroutines.runBlocking
56
import org.junit.Assert.assertEquals
6-
import org.junit.Assert.assertNull
77
import org.junit.Assert.fail
8-
import org.junit.Ignore
98
import org.junit.Test
109
import org.junit.runner.RunWith
1110
import org.xmtp.android.library.messages.PrivateKeyBuilder
@@ -27,8 +26,8 @@ class ClientTest {
2726
fun testHasPrivateKeyBundleV1() {
2827
val fakeWallet = PrivateKeyBuilder()
2928
val client = Client().create(account = fakeWallet)
30-
assertEquals(1, client.privateKeyBundleV1?.preKeysList?.size)
31-
val preKey = client.privateKeyBundleV1?.preKeysList?.get(0)
29+
assertEquals(1, client.privateKeyBundleV1.preKeysList?.size)
30+
val preKey = client.privateKeyBundleV1.preKeysList?.get(0)
3231
assert(preKey?.publicKey?.hasSignature() ?: false)
3332
}
3433

@@ -51,15 +50,15 @@ class ClientTest {
5150
val fakeWallet = PrivateKeyBuilder()
5251
val client = Client().create(account = fakeWallet)
5352
val bundle = client.privateKeyBundle
54-
val clientFromV1Bundle = Client().buildFromBundle(bundle!!)
53+
val clientFromV1Bundle = Client().buildFromBundle(bundle)
5554
assertEquals(client.address, clientFromV1Bundle.address)
5655
assertEquals(
57-
client.privateKeyBundleV1?.identityKey,
58-
clientFromV1Bundle.privateKeyBundleV1?.identityKey,
56+
client.privateKeyBundleV1.identityKey,
57+
clientFromV1Bundle.privateKeyBundleV1.identityKey,
5958
)
6059
assertEquals(
61-
client.privateKeyBundleV1?.preKeysList,
62-
clientFromV1Bundle.privateKeyBundleV1?.preKeysList,
60+
client.privateKeyBundleV1.preKeysList,
61+
clientFromV1Bundle.privateKeyBundleV1.preKeysList,
6362
)
6463
}
6564

@@ -68,15 +67,15 @@ class ClientTest {
6867
val fakeWallet = PrivateKeyBuilder()
6968
val client = Client().create(account = fakeWallet)
7069
val bundleV1 = client.v1keys
71-
val clientFromV1Bundle = Client().buildFromV1Bundle(bundleV1!!)
70+
val clientFromV1Bundle = Client().buildFromV1Bundle(bundleV1)
7271
assertEquals(client.address, clientFromV1Bundle.address)
7372
assertEquals(
74-
client.privateKeyBundleV1?.identityKey,
75-
clientFromV1Bundle.privateKeyBundleV1?.identityKey,
73+
client.privateKeyBundleV1.identityKey,
74+
clientFromV1Bundle.privateKeyBundleV1.identityKey,
7675
)
7776
assertEquals(
78-
client.privateKeyBundleV1?.preKeysList,
79-
clientFromV1Bundle.privateKeyBundleV1?.preKeysList,
77+
client.privateKeyBundleV1.preKeysList,
78+
clientFromV1Bundle.privateKeyBundleV1.preKeysList,
8079
)
8180
}
8281

@@ -91,21 +90,22 @@ class ClientTest {
9190
)
9291
val client =
9392
Client().create(account = fakeWallet, options = options)
94-
assertEquals(
95-
client.address.lowercase(),
96-
client.libXMTPClient?.accountAddress()?.lowercase()
97-
)
93+
assert(client.canMessageV3(listOf(client.address)))
9894

9995
val bundle = client.privateKeyBundle
100-
val clientFromV1Bundle = Client().buildFromBundle(bundle, account = fakeWallet, options = options)
96+
val clientFromV1Bundle =
97+
Client().buildFromBundle(bundle, account = fakeWallet, options = options)
10198
assertEquals(client.address, clientFromV1Bundle.address)
10299
assertEquals(
103100
client.privateKeyBundleV1.identityKey,
104101
clientFromV1Bundle.privateKeyBundleV1.identityKey,
105102
)
103+
104+
assert(clientFromV1Bundle.canMessageV3(listOf(client.address)))
105+
106106
assertEquals(
107-
client.libXMTPClient?.accountAddress(),
108-
clientFromV1Bundle.libXMTPClient?.accountAddress()
107+
client.address,
108+
clientFromV1Bundle.address
109109
)
110110
}
111111

@@ -122,16 +122,78 @@ class ClientTest {
122122
appContext = context
123123
)
124124
)
125-
val v3Client = client.libXMTPClient
126-
assertEquals(client.address.lowercase(), v3Client?.accountAddress()?.lowercase())
125+
assert(client.canMessageV3(listOf(client.address)))
126+
}
127+
128+
@Test
129+
fun testCanDeleteDatabase() {
130+
val context = InstrumentationRegistry.getInstrumentation().targetContext
131+
val fakeWallet = PrivateKeyBuilder()
132+
val fakeWallet2 = PrivateKeyBuilder()
133+
var client =
134+
Client().create(
135+
account = fakeWallet,
136+
options = ClientOptions(
137+
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
138+
enableAlphaMls = true,
139+
appContext = context
140+
)
141+
)
142+
val client2 =
143+
Client().create(
144+
account = fakeWallet2,
145+
options = ClientOptions(
146+
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
147+
enableAlphaMls = true,
148+
appContext = context
149+
)
150+
)
151+
152+
runBlocking {
153+
client.conversations.newGroup(listOf(client2.address))
154+
client.conversations.syncGroups()
155+
assertEquals(client.conversations.listGroups().size, 1)
156+
}
157+
158+
client.deleteLocalDatabase()
159+
160+
client =
161+
Client().create(
162+
account = fakeWallet,
163+
options = ClientOptions(
164+
ClientOptions.Api(XMTPEnvironment.LOCAL, false),
165+
enableAlphaMls = true,
166+
appContext = context
167+
)
168+
)
169+
170+
runBlocking {
171+
client.conversations.syncGroups()
172+
assertEquals(client.conversations.listGroups().size, 0)
173+
}
174+
}
175+
176+
@Test
177+
fun testCreatesAV3DevClient() {
178+
val context = InstrumentationRegistry.getInstrumentation().targetContext
179+
val fakeWallet = PrivateKeyBuilder()
180+
val client =
181+
Client().create(
182+
account = fakeWallet,
183+
options = ClientOptions(
184+
ClientOptions.Api(XMTPEnvironment.DEV, true),
185+
enableAlphaMls = true,
186+
appContext = context
187+
)
188+
)
189+
assert(client.canMessageV3(listOf(client.address)))
127190
}
128191

129192
@Test
130193
fun testDoesNotCreateAV3Client() {
131194
val fakeWallet = PrivateKeyBuilder()
132195
val client = Client().create(account = fakeWallet)
133-
val v3Client = client.libXMTPClient
134-
assertNull(v3Client)
196+
assert(!client.canMessageV3(listOf(client.address)))
135197
}
136198

137199
@Test
@@ -145,13 +207,12 @@ class ClientTest {
145207
}
146208

147209
@Test
148-
@Ignore("CI Issues")
149210
fun testPublicCanMessage() {
150211
val aliceWallet = PrivateKeyBuilder()
151212
val notOnNetwork = PrivateKeyBuilder()
152213
val opts = ClientOptions(ClientOptions.Api(XMTPEnvironment.LOCAL, false))
153214
val aliceClient = Client().create(aliceWallet, opts)
154-
aliceClient.ensureUserContactPublished()
215+
runBlocking { aliceClient.ensureUserContactPublished() }
155216

156217
val canMessage = Client.canMessage(aliceWallet.address, opts)
157218
val cannotMessage = Client.canMessage(notOnNetwork.address, opts)
@@ -161,7 +222,6 @@ class ClientTest {
161222
}
162223

163224
@Test
164-
@Ignore("CI Issues")
165225
fun testPreEnableIdentityCallback() {
166226
val fakeWallet = PrivateKeyBuilder()
167227
val expectation = CompletableFuture<Unit>()
@@ -184,7 +244,6 @@ class ClientTest {
184244
}
185245

186246
@Test
187-
@Ignore("CI Issues")
188247
fun testPreCreateIdentityCallback() {
189248
val fakeWallet = PrivateKeyBuilder()
190249
val expectation = CompletableFuture<Unit>()

0 commit comments

Comments
 (0)