Merge branch 'develop' into feature/bca/rust_flavor

This commit is contained in:
valere 2023-01-19 11:23:58 +01:00
commit f1d3eeb0a4
8 changed files with 18 additions and 37 deletions

1
changelog.d/7962.bugfix Normal file
View File

@ -0,0 +1 @@
Fix OOM crashes.

View File

@ -102,7 +102,6 @@ internal class DefaultTimeline(
realm = backgroundRealm, realm = backgroundRealm,
eventDecryptor = eventDecryptor, eventDecryptor = eventDecryptor,
paginationTask = paginationTask, paginationTask = paginationTask,
realmConfiguration = realmConfiguration,
fetchTokenAndPaginateTask = fetchTokenAndPaginateTask, fetchTokenAndPaginateTask = fetchTokenAndPaginateTask,
fetchThreadTimelineTask = fetchThreadTimelineTask, fetchThreadTimelineTask = fetchThreadTimelineTask,
getContextOfEventTask = getEventTask, getContextOfEventTask = getEventTask,

View File

@ -19,7 +19,6 @@ package org.matrix.android.sdk.internal.session.room.timeline
import io.realm.OrderedCollectionChangeSet import io.realm.OrderedCollectionChangeSet
import io.realm.OrderedRealmCollectionChangeListener import io.realm.OrderedRealmCollectionChangeListener
import io.realm.Realm import io.realm.Realm
import io.realm.RealmConfiguration
import io.realm.RealmResults import io.realm.RealmResults
import io.realm.kotlin.createObject import io.realm.kotlin.createObject
import io.realm.kotlin.executeTransactionAwait import io.realm.kotlin.executeTransactionAwait
@ -97,7 +96,6 @@ internal class LoadTimelineStrategy constructor(
val realm: AtomicReference<Realm>, val realm: AtomicReference<Realm>,
val eventDecryptor: TimelineEventDecryptor, val eventDecryptor: TimelineEventDecryptor,
val paginationTask: PaginationTask, val paginationTask: PaginationTask,
val realmConfiguration: RealmConfiguration,
val fetchThreadTimelineTask: FetchThreadTimelineTask, val fetchThreadTimelineTask: FetchThreadTimelineTask,
val fetchTokenAndPaginateTask: FetchTokenAndPaginateTask, val fetchTokenAndPaginateTask: FetchTokenAndPaginateTask,
val getContextOfEventTask: GetContextOfEventTask, val getContextOfEventTask: GetContextOfEventTask,
@ -351,7 +349,6 @@ internal class LoadTimelineStrategy constructor(
fetchThreadTimelineTask = dependencies.fetchThreadTimelineTask, fetchThreadTimelineTask = dependencies.fetchThreadTimelineTask,
eventDecryptor = dependencies.eventDecryptor, eventDecryptor = dependencies.eventDecryptor,
paginationTask = dependencies.paginationTask, paginationTask = dependencies.paginationTask,
realmConfiguration = dependencies.realmConfiguration,
fetchTokenAndPaginateTask = dependencies.fetchTokenAndPaginateTask, fetchTokenAndPaginateTask = dependencies.fetchTokenAndPaginateTask,
timelineEventMapper = dependencies.timelineEventMapper, timelineEventMapper = dependencies.timelineEventMapper,
uiEchoManager = uiEchoManager, uiEchoManager = uiEchoManager,
@ -360,7 +357,6 @@ internal class LoadTimelineStrategy constructor(
initialEventId = mode.originEventId(), initialEventId = mode.originEventId(),
onBuiltEvents = dependencies.onEventsUpdated, onBuiltEvents = dependencies.onEventsUpdated,
onEventsDeleted = dependencies.onEventsDeleted, onEventsDeleted = dependencies.onEventsDeleted,
realm = dependencies.realm,
localEchoEventFactory = dependencies.localEchoEventFactory, localEchoEventFactory = dependencies.localEchoEventFactory,
decorator = createTimelineEventDecorator() decorator = createTimelineEventDecorator()
) )

View File

@ -42,13 +42,12 @@ internal class RealmSendingEventsDataSource(
private var roomEntity: RoomEntity? = null private var roomEntity: RoomEntity? = null
private var sendingTimelineEvents: RealmList<TimelineEventEntity>? = null private var sendingTimelineEvents: RealmList<TimelineEventEntity>? = null
private var frozenSendingTimelineEvents: RealmList<TimelineEventEntity>? = null private var mappedSendingTimelineEvents: List<TimelineEvent> = emptyList()
private val builtEvents = ArrayList<TimelineEvent>()
private val sendingTimelineEventsListener = RealmChangeListener<RealmList<TimelineEventEntity>> { events -> private val sendingTimelineEventsListener = RealmChangeListener<RealmList<TimelineEventEntity>> { events ->
if (events.isValid) { if (events.isValid) {
uiEchoManager.onSentEventsInDatabase(events.map { it.eventId }) uiEchoManager.onSentEventsInDatabase(events.map { it.eventId })
updateFrozenResults(events) mapSendingEvents(events)
onEventsUpdated(false) onEventsUpdated(false)
} }
} }
@ -58,37 +57,29 @@ internal class RealmSendingEventsDataSource(
roomEntity = RoomEntity.where(safeRealm, roomId = roomId).findFirst() roomEntity = RoomEntity.where(safeRealm, roomId = roomId).findFirst()
sendingTimelineEvents = roomEntity?.sendingTimelineEvents sendingTimelineEvents = roomEntity?.sendingTimelineEvents
sendingTimelineEvents?.addChangeListener(sendingTimelineEventsListener) sendingTimelineEvents?.addChangeListener(sendingTimelineEventsListener)
updateFrozenResults(sendingTimelineEvents) mapSendingEvents(sendingTimelineEvents)
} }
override fun stop() { override fun stop() {
sendingTimelineEvents?.removeChangeListener(sendingTimelineEventsListener) sendingTimelineEvents?.removeChangeListener(sendingTimelineEventsListener)
updateFrozenResults(null) mapSendingEvents(null)
sendingTimelineEvents = null sendingTimelineEvents = null
roomEntity = null roomEntity = null
} }
private fun updateFrozenResults(sendingEvents: RealmList<TimelineEventEntity>?) { private fun mapSendingEvents(sendingEvents: RealmList<TimelineEventEntity>?) {
// Makes sure to close the previous frozen realm mappedSendingTimelineEvents = sendingEvents?.map { timelineEventMapper.map(it) }.orEmpty()
if (frozenSendingTimelineEvents?.isValid == true) {
frozenSendingTimelineEvents?.realm?.close()
}
frozenSendingTimelineEvents = sendingEvents?.freeze()
} }
override fun buildSendingEvents(): List<TimelineEvent> { override fun buildSendingEvents(): List<TimelineEvent> {
val builtSendingEvents = mutableListOf<TimelineEvent>() val builtSendingEvents = mutableListOf<TimelineEvent>()
uiEchoManager.getInMemorySendingEvents() uiEchoManager.getInMemorySendingEvents()
.addWithUiEcho(builtSendingEvents) .addWithUiEcho(builtSendingEvents)
if (frozenSendingTimelineEvents?.isValid == true) { mappedSendingTimelineEvents
frozenSendingTimelineEvents .filter { timelineEvent ->
?.filter { timelineEvent -> builtSendingEvents.none { it.eventId == timelineEvent.eventId }
builtSendingEvents.none { it.eventId == timelineEvent.eventId } }
} .addWithUiEcho(builtSendingEvents)
?.map {
timelineEventMapper.map(it)
}?.addWithUiEcho(builtSendingEvents)
}
return builtSendingEvents return builtSendingEvents
} }

View File

@ -18,8 +18,6 @@ package org.matrix.android.sdk.internal.session.room.timeline
import io.realm.OrderedCollectionChangeSet import io.realm.OrderedCollectionChangeSet
import io.realm.OrderedRealmCollectionChangeListener import io.realm.OrderedRealmCollectionChangeListener
import io.realm.Realm
import io.realm.RealmConfiguration
import io.realm.RealmObjectChangeListener import io.realm.RealmObjectChangeListener
import io.realm.RealmQuery import io.realm.RealmQuery
import io.realm.RealmResults import io.realm.RealmResults
@ -48,7 +46,6 @@ import org.matrix.android.sdk.internal.session.sync.handler.room.ThreadsAwarenes
import timber.log.Timber import timber.log.Timber
import java.util.Collections import java.util.Collections
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference
/** /**
* This is a wrapper around a ChunkEntity in the database. * This is a wrapper around a ChunkEntity in the database.
@ -63,7 +60,6 @@ internal class TimelineChunk(
private val fetchThreadTimelineTask: FetchThreadTimelineTask, private val fetchThreadTimelineTask: FetchThreadTimelineTask,
private val eventDecryptor: TimelineEventDecryptor, private val eventDecryptor: TimelineEventDecryptor,
private val paginationTask: PaginationTask, private val paginationTask: PaginationTask,
private val realmConfiguration: RealmConfiguration,
private val fetchTokenAndPaginateTask: FetchTokenAndPaginateTask, private val fetchTokenAndPaginateTask: FetchTokenAndPaginateTask,
private val timelineEventMapper: TimelineEventMapper, private val timelineEventMapper: TimelineEventMapper,
private val uiEchoManager: UIEchoManager?, private val uiEchoManager: UIEchoManager?,
@ -72,7 +68,6 @@ internal class TimelineChunk(
private val initialEventId: String?, private val initialEventId: String?,
private val onBuiltEvents: (Boolean) -> Unit, private val onBuiltEvents: (Boolean) -> Unit,
private val onEventsDeleted: () -> Unit, private val onEventsDeleted: () -> Unit,
private val realm: AtomicReference<Realm>,
private val decorator: TimelineEventDecorator, private val decorator: TimelineEventDecorator,
val localEchoEventFactory: LocalEchoEventFactory, val localEchoEventFactory: LocalEchoEventFactory,
) { ) {
@ -605,7 +600,6 @@ internal class TimelineChunk(
timelineId = timelineId, timelineId = timelineId,
eventDecryptor = eventDecryptor, eventDecryptor = eventDecryptor,
paginationTask = paginationTask, paginationTask = paginationTask,
realmConfiguration = realmConfiguration,
fetchThreadTimelineTask = fetchThreadTimelineTask, fetchThreadTimelineTask = fetchThreadTimelineTask,
fetchTokenAndPaginateTask = fetchTokenAndPaginateTask, fetchTokenAndPaginateTask = fetchTokenAndPaginateTask,
timelineEventMapper = timelineEventMapper, timelineEventMapper = timelineEventMapper,
@ -616,7 +610,6 @@ internal class TimelineChunk(
onBuiltEvents = this.onBuiltEvents, onBuiltEvents = this.onBuiltEvents,
onEventsDeleted = this.onEventsDeleted, onEventsDeleted = this.onEventsDeleted,
decorator = this.decorator, decorator = this.decorator,
realm = realm,
localEchoEventFactory = localEchoEventFactory localEchoEventFactory = localEchoEventFactory
) )
} }

View File

@ -19,9 +19,9 @@ package org.matrix.android.sdk.internal.session.room.timeline.decorator
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
import org.matrix.android.sdk.internal.session.room.timeline.UIEchoManager import org.matrix.android.sdk.internal.session.room.timeline.UIEchoManager
internal class UiEchoDecorator(private val uiEchoManager: UIEchoManager?) : TimelineEventDecorator { internal class UiEchoDecorator(private val uiEchoManager: UIEchoManager) : TimelineEventDecorator {
override fun decorate(timelineEvent: TimelineEvent): TimelineEvent { override fun decorate(timelineEvent: TimelineEvent): TimelineEvent {
return uiEchoManager?.decorateEventWithReactionUiEcho(timelineEvent) ?: timelineEvent return uiEchoManager.decorateEventWithReactionUiEcho(timelineEvent)
} }
} }

View File

@ -105,7 +105,8 @@ internal class SyncResponsePostTreatmentAggregatorHandler @Inject constructor(
.enqueue() .enqueue()
} }
private suspend fun handleUserIdsForCheckingTrustAndAffectedRoomShields(userIdsWithDeviceUpdate: Set<String>) { private fun handleUserIdsForCheckingTrustAndAffectedRoomShields(userIdsWithDeviceUpdate: Collection<String>) {
if (userIdsWithDeviceUpdate.isEmpty()) return
crossSigningService.checkTrustAndAffectedRoomShields(userIdsWithDeviceUpdate.toList()) crossSigningService.checkTrustAndAffectedRoomShields(userIdsWithDeviceUpdate.toList())
} }
} }

View File

@ -797,7 +797,7 @@ class TimelineFragment :
} }
// We use a custom layout for this menu item, so we need to set a ClickListener // We use a custom layout for this menu item, so we need to set a ClickListener
menu.findItem(R.id.open_matrix_apps)?.let { menuItem -> menu.findItem(R.id.open_matrix_apps)?.let { menuItem ->
menuItem.actionView?.debouncedClicks { menuItem.actionView?.setOnClickListener {
handleMenuItemSelected(menuItem) handleMenuItemSelected(menuItem)
} }
} }
@ -808,7 +808,7 @@ class TimelineFragment :
// Custom thread notification menu item // Custom thread notification menu item
menu.findItem(R.id.menu_timeline_thread_list)?.let { menuItem -> menu.findItem(R.id.menu_timeline_thread_list)?.let { menuItem ->
menuItem.actionView?.debouncedClicks { menuItem.actionView?.setOnClickListener {
handleMenuItemSelected(menuItem) handleMenuItemSelected(menuItem)
} }
} }