Format code & add comments

This commit is contained in:
ariskotsomitopoulos 2022-03-21 13:39:15 +02:00
parent a959a15636
commit 277619d833
3 changed files with 14 additions and 12 deletions

View File

@ -213,6 +213,7 @@ 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 { private fun decryptIfNeeded(cryptoService: CryptoService?, eventEntity: EventEntity, roomId: String) = runBlocking {
cryptoService ?: return@runBlocking cryptoService ?: return@runBlocking
val event = eventEntity.asDomain() val event = eventEntity.asDomain()

View File

@ -101,9 +101,7 @@ internal class TimelineEventDecryptor @Inject constructor(
executor?.execute { executor?.execute {
Realm.getInstance(realmConfiguration).use { realm -> Realm.getInstance(realmConfiguration).use { realm ->
try { try {
runBlocking {
processDecryptRequest(request, realm) processDecryptRequest(request, realm)
}
} catch (e: InterruptedException) { } catch (e: InterruptedException) {
Timber.i("Decryption got interrupted") Timber.i("Decryption got interrupted")
} }
@ -122,7 +120,9 @@ internal class TimelineEventDecryptor @Inject constructor(
threadsAwarenessHandler.makeEventThreadAware(realm, event.roomId, decryptedEvent, eventEntity) threadsAwarenessHandler.makeEventThreadAware(realm, event.roomId, decryptedEvent, eventEntity)
} }
} }
private suspend fun processDecryptRequest(request: DecryptionRequest, realm: Realm) {
// 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 {
val event = request.event val event = request.event
val timelineId = request.timelineId val timelineId = request.timelineId
@ -130,7 +130,7 @@ internal class TimelineEventDecryptor @Inject constructor(
// Here we have requested a decryption to an event that is not encrypted // Here we have requested a decryption to an event that is not encrypted
// We will simply make this event thread aware // We will simply make this event thread aware
threadAwareNonEncryptedEvents(request, realm) threadAwareNonEncryptedEvents(request, realm)
return return@runBlocking
} }
try { try {
val result = cryptoService.decryptEvent(request.event, timelineId) val result = cryptoService.decryptEvent(request.event, timelineId)

View File

@ -506,6 +506,7 @@ 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) = runBlocking {
try { try {
// Event from sync does not have roomId, so add it to the event first // Event from sync does not have roomId, so add it to the event first