Skip to content

Commit cfe0b2e

Browse files
committed
fix up the example app
1 parent 7b49242 commit cfe0b2e

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
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/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

0 commit comments

Comments
 (0)