Skip to content

Commit

Permalink
feat: get it working performantly
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jul 1, 2024
1 parent 5dd425b commit 2785b4d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.util.Log
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.launch
import org.web3j.crypto.Hash
import org.xmtp.android.library.Util.Companion.envelopeFromFFi
import org.xmtp.android.library.codecs.ContentCodec
Expand Down Expand Up @@ -51,7 +51,7 @@ data class ConversationV1(
}
}
val stream = client.subscribe(listOf(topic.description), streamCallback)
awaitClose { runBlocking { stream.end() } }
awaitClose { launch { stream.end() } }
}

/**
Expand Down Expand Up @@ -283,7 +283,7 @@ data class ConversationV1(
}
}
val stream = client.subscribe(listOf(ephemeralTopic), streamCallback)
awaitClose { runBlocking { stream.end() } }
awaitClose { launch { stream.end() } }
}

fun streamDecryptedMessages(): Flow<DecryptedMessage> = callbackFlow {
Expand All @@ -293,6 +293,6 @@ data class ConversationV1(
}
}
val stream = client.subscribe(listOf(topic.description), streamCallback)
awaitClose { runBlocking { stream.end() } }
awaitClose { launch { stream.end() } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.util.Log
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.launch
import org.web3j.crypto.Hash
import org.xmtp.android.library.codecs.ContentCodec
import org.xmtp.android.library.codecs.EncodedContent
Expand Down Expand Up @@ -149,7 +149,7 @@ data class ConversationV2(
}
}
val stream = client.subscribe(listOf(topic), streamCallback)
awaitClose { runBlocking { stream.end() } }
awaitClose { launch { stream.end() } }
}

/**
Expand Down Expand Up @@ -284,7 +284,7 @@ data class ConversationV2(
}
}
val stream = client.subscribe(listOf(ephemeralTopic), streamCallback)
awaitClose { runBlocking { stream.end() } }
awaitClose { launch { stream.end() } }
}

fun streamDecryptedMessages(): Flow<DecryptedMessage> = callbackFlow {
Expand All @@ -294,6 +294,6 @@ data class ConversationV2(
}
}
val stream = client.subscribe(listOf(topic), streamCallback)
awaitClose { runBlocking { stream.end() } }
awaitClose { launch { stream.end() } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.xmtp.android.library.GRPCApiClient.Companion.makeQueryRequest
import org.xmtp.android.library.Util.Companion.envelopeFromFFi
import org.xmtp.android.library.libxmtp.MessageV3
Expand Down Expand Up @@ -592,7 +591,7 @@ data class Conversations(
subscriptionCallback
)

awaitClose { runBlocking { stream.end() } }
awaitClose { launch { stream.end() } }
}

fun streamAll(): Flow<Conversation> {
Expand Down Expand Up @@ -701,7 +700,7 @@ data class Conversations(

stream = client.subscribe2(subscriptionRequest, subscriptionCallback)

awaitClose { runBlocking { stream.end() } }
awaitClose { launch { stream.end() } }
}

fun streamAllMessages(includeGroups: Boolean = false): Flow<DecodedMessage> {
Expand Down Expand Up @@ -767,6 +766,6 @@ data class Conversations(

stream = client.subscribe2(subscriptionRequest, subscriptionCallback)

awaitClose { runBlocking { stream.end() } }
awaitClose { launch { stream.end() } }
}
}

0 comments on commit 2785b4d

Please sign in to comment.