Skip to content

Commit 489b4c8

Browse files
Fix community file download and restoring account (session-foundation#1862)
1 parent 603b3ee commit 489b4c8

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

app/src/main/java/org/session/libsession/messaging/open_groups/api/CommunityApiBatcher.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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

app/src/main/java/org/session/libsession/messaging/open_groups/api/CommunityFileDownloadApi.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.session.libsession.messaging.open_groups.api
22

33
import android.net.Uri
4+
import android.util.Base64
45
import dagger.assisted.Assisted
56
import dagger.assisted.AssistedFactory
67
import 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

app/src/main/java/org/session/libsession/network/snode/SwarmDirectory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

app/src/main/java/org/thoughtcrime/securesms/api/batch/Batcher.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ package org.thoughtcrime.securesms.api.batch
33
import org.thoughtcrime.securesms.api.ApiExecutorContext
44

55
interface 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

0 commit comments

Comments
 (0)