Format code & add comments
This commit is contained in:
parent
a959a15636
commit
277619d833
|
@ -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()
|
||||||
|
|
|
@ -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")
|
||||||
}
|
}
|
||||||
|
@ -113,16 +111,18 @@ internal class TimelineEventDecryptor @Inject constructor(
|
||||||
|
|
||||||
private fun threadAwareNonEncryptedEvents(request: DecryptionRequest, realm: Realm) {
|
private fun threadAwareNonEncryptedEvents(request: DecryptionRequest, realm: Realm) {
|
||||||
val event = request.event
|
val event = request.event
|
||||||
realm.executeTransaction {
|
realm.executeTransaction {
|
||||||
val eventId = event.eventId ?: return@executeTransaction
|
val eventId = event.eventId ?: return@executeTransaction
|
||||||
val eventEntity = EventEntity
|
val eventEntity = EventEntity
|
||||||
.where(it, eventId = eventId)
|
.where(it, eventId = eventId)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
val decryptedEvent = eventEntity?.asDomain()
|
val decryptedEvent = eventEntity?.asDomain()
|
||||||
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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue