-
Notifications
You must be signed in to change notification settings - Fork 753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/aris/thread aware #4396
Changes from 6 commits
8f00749
d1f3e3f
45a63b7
8ee3f2c
4192c1c
ec366f1
88656ce
d463500
9972dbc
8015ffe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Make Element Android Thread aware |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import io.realm.RealmConfiguration | |
import io.realm.RealmQuery | ||
import io.realm.RealmResults | ||
import io.realm.Sort | ||
import kotlinx.coroutines.runBlocking | ||
import org.matrix.android.sdk.api.MatrixCallback | ||
import org.matrix.android.sdk.api.extensions.orFalse | ||
import org.matrix.android.sdk.api.extensions.tryOrNull | ||
|
@@ -33,6 +34,7 @@ import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent | |
import org.matrix.android.sdk.api.session.room.timeline.TimelineSettings | ||
import org.matrix.android.sdk.api.util.CancelableBag | ||
import org.matrix.android.sdk.internal.database.RealmSessionProvider | ||
import org.matrix.android.sdk.internal.database.mapper.EventMapper | ||
import org.matrix.android.sdk.internal.database.mapper.TimelineEventMapper | ||
import org.matrix.android.sdk.internal.database.model.ChunkEntity | ||
import org.matrix.android.sdk.internal.database.model.RoomEntity | ||
|
@@ -43,6 +45,7 @@ import org.matrix.android.sdk.internal.database.query.where | |
import org.matrix.android.sdk.internal.database.query.whereRoomId | ||
import org.matrix.android.sdk.internal.session.room.membership.LoadRoomMembersTask | ||
import org.matrix.android.sdk.internal.session.sync.handler.room.ReadReceiptHandler | ||
import org.matrix.android.sdk.internal.session.sync.handler.room.ThreadsAwarenessHandler | ||
import org.matrix.android.sdk.internal.task.TaskExecutor | ||
import org.matrix.android.sdk.internal.task.configureWith | ||
import org.matrix.android.sdk.internal.util.Debouncer | ||
|
@@ -72,6 +75,7 @@ internal class DefaultTimeline( | |
private val eventDecryptor: TimelineEventDecryptor, | ||
private val realmSessionProvider: RealmSessionProvider, | ||
private val loadRoomMembersTask: LoadRoomMembersTask, | ||
private val threadsAwarenessHandler: ThreadsAwarenessHandler, | ||
private val readReceiptHandler: ReadReceiptHandler | ||
) : Timeline, | ||
TimelineInput.Listener, | ||
|
@@ -577,6 +581,10 @@ internal class DefaultTimeline( | |
} else { | ||
nextDisplayIndex = offsetIndex + 1 | ||
} | ||
|
||
// Prerequisite to in order for the ThreadsAwarenessHandler to work properly | ||
fetchRootThreadEventsIfNeeded(offsetResults) | ||
|
||
offsetResults.forEach { eventEntity -> | ||
|
||
val timelineEvent = buildTimelineEvent(eventEntity) | ||
|
@@ -601,6 +609,20 @@ internal class DefaultTimeline( | |
return offsetResults.size | ||
} | ||
|
||
/** | ||
* This function is responsible to fetch and store the root event of a thread event | ||
* in order to be able to display the event to the user appropriately | ||
*/ | ||
private fun fetchRootThreadEventsIfNeeded(offsetResults: RealmResults<TimelineEventEntity>) = runBlocking { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, but we are already in a thread (and the UI will not freeze) and it's the only way to ensure that the next code block will have the required info, if you can suggest an alternative to that it's welcome. Furthermore keep in mind that this is a temporary fix and will be removed after the thread release There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes thats not really great but it's ok I guess for now. Note that my rework of the timeline authorise direct usage of suspend methods |
||
val eventEntityList = offsetResults | ||
.mapNotNull { | ||
it?.root | ||
}.map { | ||
EventMapper.map(it) | ||
} | ||
threadsAwarenessHandler.fetchRootThreadEventsIfNeeded(eventEntityList) | ||
} | ||
|
||
private fun buildTimelineEvent(eventEntity: TimelineEventEntity): TimelineEvent { | ||
return timelineEventMapper.map( | ||
timelineEventEntity = eventEntity, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ import org.matrix.android.sdk.internal.session.sync.handler.PresenceSyncHandler | |
import org.matrix.android.sdk.internal.session.sync.handler.SyncResponsePostTreatmentAggregatorHandler | ||
import org.matrix.android.sdk.internal.session.sync.handler.UserAccountDataSyncHandler | ||
import org.matrix.android.sdk.internal.session.sync.handler.room.RoomSyncHandler | ||
import org.matrix.android.sdk.internal.session.sync.handler.room.ThreadsAwarenessHandler | ||
import org.matrix.android.sdk.internal.util.awaitTransaction | ||
import org.matrix.android.sdk.internal.worker.WorkerParamsFactory | ||
import timber.log.Timber | ||
|
@@ -62,6 +63,7 @@ internal class SyncResponseHandler @Inject constructor( | |
private val tokenStore: SyncTokenStore, | ||
private val processEventForPushTask: ProcessEventForPushTask, | ||
private val pushRuleService: PushRuleService, | ||
private val threadsAwarenessHandler: ThreadsAwarenessHandler, | ||
private val presenceSyncHandler: PresenceSyncHandler | ||
) { | ||
|
||
|
@@ -94,6 +96,10 @@ internal class SyncResponseHandler @Inject constructor( | |
Timber.v("Finish handling toDevice in $it ms") | ||
} | ||
val aggregator = SyncResponsePostTreatmentAggregator() | ||
|
||
// Prerequisite for thread events handling in RoomSyncHandler | ||
threadsAwarenessHandler.fetchRootThreadEventsIfNeeded(syncResponse) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to do that even for the initial sync? It can take time if there are lots of events to retrieve There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, without this it will not be rendered appropriately. I think there will be never more than max 1/2 fetches per room worst case. Ofc this will be removed upon the first thread release. |
||
|
||
// Start one big transaction | ||
monarchy.awaitTransaction { realm -> | ||
measureTimeMillis { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is strange, let me see the rest of the changes to understand why it is done