mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-12-27 01:54:43 +01:00
Wrap only cryptoService.decryptEvent with runBlocking instead of the whole methods
This commit is contained in:
parent
51b42929bd
commit
5cfe218634
@ -213,15 +213,15 @@ internal fun ThreadSummaryEntity.Companion.createOrUpdate(
|
||||
}
|
||||
}
|
||||
|
||||
// note: runBlocking should be used here while we are in realm single thread executor, to avoid thread switching
|
||||
private fun decryptIfNeeded(cryptoService: CryptoService?, eventEntity: EventEntity, roomId: String) = runBlocking {
|
||||
cryptoService ?: return@runBlocking
|
||||
private fun decryptIfNeeded(cryptoService: CryptoService?, eventEntity: EventEntity, roomId: String) {
|
||||
cryptoService ?: return
|
||||
val event = eventEntity.asDomain()
|
||||
if (event.isEncrypted() && event.mxDecryptionResult == null && event.eventId != null) {
|
||||
try {
|
||||
Timber.i("###THREADS ThreadSummaryHelper request decryption for eventId:${event.eventId}")
|
||||
// Event from sync does not have roomId, so add it to the event first
|
||||
val result = cryptoService.decryptEvent(event.copy(roomId = roomId), "")
|
||||
// note: runBlocking should be used here while we are in realm single thread executor, to avoid thread switching
|
||||
val result = runBlocking { cryptoService.decryptEvent(event.copy(roomId = roomId), "") }
|
||||
event.mxDecryptionResult = OlmDecryptionResult(
|
||||
payload = result.clearEvent,
|
||||
senderKey = result.senderCurve25519Key,
|
||||
|
@ -119,8 +119,7 @@ internal class TimelineEventDecryptor @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
// note: runBlocking should be used here while we are in realm single thread executor, to avoid thread switching
|
||||
private fun processDecryptRequest(request: DecryptionRequest, realm: Realm) = runBlocking {
|
||||
private fun processDecryptRequest(request: DecryptionRequest, realm: Realm) {
|
||||
val event = request.event
|
||||
val timelineId = request.timelineId
|
||||
|
||||
@ -128,10 +127,11 @@ internal class TimelineEventDecryptor @Inject constructor(
|
||||
// Here we have requested a decryption to an event that is not encrypted
|
||||
// We will simply make this event thread aware
|
||||
threadAwareNonEncryptedEvents(request, realm)
|
||||
return@runBlocking
|
||||
return
|
||||
}
|
||||
try {
|
||||
val result = cryptoService.decryptEvent(request.event, timelineId)
|
||||
// note: runBlocking should be used here while we are in realm single thread executor, to avoid thread switching
|
||||
val result = runBlocking { cryptoService.decryptEvent(request.event, timelineId) }
|
||||
Timber.v("Successfully decrypted event ${event.eventId}")
|
||||
realm.executeTransaction {
|
||||
val eventId = event.eventId ?: return@executeTransaction
|
||||
|
@ -423,7 +423,8 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle
|
||||
roomId = roomId,
|
||||
eventEntity = eventEntity,
|
||||
direction = PaginationDirection.FORWARDS,
|
||||
roomMemberContentsByUser = roomMemberContentsByUser)
|
||||
roomMemberContentsByUser = roomMemberContentsByUser
|
||||
)
|
||||
if (lightweightSettingsStorage.areThreadMessagesEnabled()) {
|
||||
eventEntity.rootThreadEventId?.let {
|
||||
// This is a thread event
|
||||
@ -439,7 +440,8 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle
|
||||
threadEventEntity = eventEntity,
|
||||
roomMemberContentsByUser = roomMemberContentsByUser,
|
||||
userId = userId,
|
||||
roomEntity = roomEntity)
|
||||
roomEntity = roomEntity
|
||||
)
|
||||
}
|
||||
} ?: run {
|
||||
// This is a normal event or a root thread one
|
||||
@ -477,7 +479,8 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle
|
||||
roomId = roomId,
|
||||
realm = realm,
|
||||
chunkEntity = chunkEntity,
|
||||
currentUserId = userId)
|
||||
currentUserId = userId
|
||||
)
|
||||
}
|
||||
|
||||
// posting new events to timeline if any is registered
|
||||
@ -507,11 +510,11 @@ internal class RoomSyncHandler @Inject constructor(private val readReceiptHandle
|
||||
}
|
||||
}
|
||||
|
||||
// note: runBlocking should be used here while we are in realm single thread executor, to avoid thread switching
|
||||
private fun decryptIfNeeded(event: Event, roomId: String) = runBlocking {
|
||||
private fun decryptIfNeeded(event: Event, roomId: String) {
|
||||
try {
|
||||
// Event from sync does not have roomId, so add it to the event first
|
||||
val result = cryptoService.decryptEvent(event.copy(roomId = roomId), "")
|
||||
// note: runBlocking should be used here while we are in realm single thread executor, to avoid thread switching
|
||||
val result = runBlocking { cryptoService.decryptEvent(event.copy(roomId = roomId), "") }
|
||||
event.mxDecryptionResult = OlmDecryptionResult(
|
||||
payload = result.clearEvent,
|
||||
senderKey = result.senderCurve25519Key,
|
||||
|
Loading…
Reference in New Issue
Block a user