mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-28 22:18:46 +03:00
Check encrypted event status using the Event model
This commit is contained in:
parent
ee3cbd9884
commit
60e838a82c
1 changed files with 34 additions and 17 deletions
|
@ -55,12 +55,11 @@ internal class EventInsertLiveObserver @Inject constructor(
|
||||||
if (!results.isLoaded || results.isEmpty()) {
|
if (!results.isLoaded || results.isEmpty()) {
|
||||||
return@withLock
|
return@withLock
|
||||||
}
|
}
|
||||||
val idsToDeleteAfterProcess = ArrayList<String>()
|
val eventsToProcess = ArrayList<EventInsertEntity>(results.size)
|
||||||
val idsOfEncryptedEvents = ArrayList<String>()
|
val eventsToIgnore = ArrayList<EventInsertEntity>(results.size)
|
||||||
val filteredEvents = ArrayList<EventInsertEntity>(results.size)
|
|
||||||
Timber.v("EventInsertEntity updated with ${results.size} results in db")
|
Timber.v("EventInsertEntity updated with ${results.size} results in db")
|
||||||
results.forEach {
|
results.forEach {
|
||||||
if (shouldProcess(it)) {
|
|
||||||
// don't use copy from realm over there
|
// don't use copy from realm over there
|
||||||
val copiedEvent = EventInsertEntity(
|
val copiedEvent = EventInsertEntity(
|
||||||
eventId = it.eventId,
|
eventId = it.eventId,
|
||||||
|
@ -68,19 +67,34 @@ internal class EventInsertLiveObserver @Inject constructor(
|
||||||
).apply {
|
).apply {
|
||||||
insertType = it.insertType
|
insertType = it.insertType
|
||||||
}
|
}
|
||||||
filteredEvents.add(copiedEvent)
|
|
||||||
}
|
if (shouldProcess(it)) {
|
||||||
if (it.eventType == EventType.ENCRYPTED) {
|
eventsToProcess.add(copiedEvent)
|
||||||
idsOfEncryptedEvents.add(it.eventId)
|
|
||||||
} else {
|
} else {
|
||||||
idsToDeleteAfterProcess.add(it.eventId)
|
eventsToIgnore.add(copiedEvent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
awaitTransaction(realmConfiguration) { realm ->
|
awaitTransaction(realmConfiguration) { realm ->
|
||||||
Timber.v("##Transaction: There are ${filteredEvents.size} events to process ")
|
Timber.v("##Transaction: There are ${eventsToProcess.size} events to process")
|
||||||
filteredEvents.forEach { eventInsert ->
|
|
||||||
|
val idsToDeleteAfterProcess = ArrayList<String>()
|
||||||
|
val idsOfEncryptedEvents = ArrayList<String>()
|
||||||
|
val getAndTriageEvent: (EventInsertEntity) -> Event? = { eventInsert ->
|
||||||
val eventId = eventInsert.eventId
|
val eventId = eventInsert.eventId
|
||||||
val event = getEvent(realm, eventId)
|
val event = getEvent(realm, eventId)
|
||||||
|
if (event?.getClearType() == EventType.ENCRYPTED) {
|
||||||
|
idsOfEncryptedEvents.add(eventId)
|
||||||
|
} else {
|
||||||
|
idsToDeleteAfterProcess.add(eventId)
|
||||||
|
}
|
||||||
|
event
|
||||||
|
}
|
||||||
|
|
||||||
|
eventsToProcess.forEach { eventInsert ->
|
||||||
|
val eventId = eventInsert.eventId
|
||||||
|
val event = getAndTriageEvent(eventInsert)
|
||||||
|
|
||||||
if (event != null && canProcessEvent(event)) {
|
if (event != null && canProcessEvent(event)) {
|
||||||
processors.filter {
|
processors.filter {
|
||||||
it.shouldProcess(eventId, event.getClearType(), eventInsert.insertType)
|
it.shouldProcess(eventId, event.getClearType(), eventInsert.insertType)
|
||||||
|
@ -92,6 +106,9 @@ internal class EventInsertLiveObserver @Inject constructor(
|
||||||
return@forEach
|
return@forEach
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
eventsToIgnore.forEach { getAndTriageEvent(it) }
|
||||||
|
|
||||||
realm.where(EventInsertEntity::class.java)
|
realm.where(EventInsertEntity::class.java)
|
||||||
.`in`(EventInsertEntityFields.EVENT_ID, idsToDeleteAfterProcess.toTypedArray())
|
.`in`(EventInsertEntityFields.EVENT_ID, idsToDeleteAfterProcess.toTypedArray())
|
||||||
.findAll()
|
.findAll()
|
||||||
|
|
Loading…
Reference in a new issue