File tree Expand file tree Collapse file tree 4 files changed +23
-1
lines changed
messaging/open_groups/api
thoughtcrime/securesms/api/batch Expand file tree Collapse file tree 4 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,11 @@ class CommunityApiBatcher @Inject constructor(
4545 return null
4646 }
4747
48+ // Shouldn't batch APIs that return large amount of data
49+ if (req.api is CommunityFileDownloadApi ) {
50+ return null
51+ }
52+
4853 // Only batch requests that require signing
4954 if (! req.api.requiresSigning) {
5055 return null
Original file line number Diff line number Diff line change 11package org.session.libsession.messaging.open_groups.api
22
33import android.net.Uri
4+ import android.util.Base64
45import dagger.assisted.Assisted
56import dagger.assisted.AssistedFactory
67import dagger.assisted.AssistedInject
@@ -26,6 +27,18 @@ class CommunityFileDownloadApi @AssistedInject constructor(
2627 baseUrl : String ,
2728 response : HttpResponse
2829 ): HttpBody {
30+ // If the response body is text, it's very likely they were base64 encoded
31+ // before being sent over the network. Try to decode it.
32+ if (response.body is HttpBody .Text ) {
33+ val bytes = runCatching {
34+ Base64 .decode(response.body.text, Base64 .DEFAULT )
35+ }.getOrNull()
36+
37+ if (bytes != null ) {
38+ return HttpBody .Bytes (bytes)
39+ }
40+ }
41+
2942 return response.body
3043 }
3144
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ class SwarmDirectory @Inject constructor(
3232 }
3333
3434 suspend fun fetchSwarm (publicKey : String ): List <Snode > {
35- val pool = snodeDirectory.getSnodePool ()
35+ val pool = snodeDirectory.ensurePoolPopulated ()
3636 require(pool.isNotEmpty()) {
3737 " Snode pool is empty"
3838 }
Original file line number Diff line number Diff line change @@ -3,6 +3,10 @@ package org.thoughtcrime.securesms.api.batch
33import org.thoughtcrime.securesms.api.ApiExecutorContext
44
55interface Batcher <Req , Res , T > {
6+
7+ /* *
8+ * Returns a key that identifies requests that can be batched together.
9+ */
610 fun batchKey (req : Req ): Any?
711
812 fun transformRequestForBatching (ctx : ApiExecutorContext , req : Req ): T
You can’t perform that action at this time.
0 commit comments