Skip to content
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

Merged
merged 10 commits into from
Nov 18, 2021
Merged

Feature/aris/thread aware #4396

merged 10 commits into from
Nov 18, 2021

Conversation

ariskotsomitopoulos
Copy link
Contributor

Make Element Android Thread aware

This feature temporarily until the main threads release and will be deleted. The idea is to make smoother the thread transition release for the clients
Closes #4246

What was the main challenge?
Too old root thread messages, are not fetched in the device so is impossible to show the thread as a reply appropriately. So a custom fetch root thread event mechanism was implemented in order to fetch those root thread events prior the transformation to replies

  • To treat m.thread the same way that they treat m.in_reply_to
  • To change the event references from m.in_reply_to to m.thread when replying to an event that has an m.thread relation ( no need for that while it is already supported and displayed correctly in the web clients)

@github-actions
Copy link

github-actions bot commented Nov 3, 2021

Unit Test Results

  66 files  +  4    66 suites  +4   58s ⏱️ +10s
135 tests +17  135 ✔️ +17  0 💤 ±0  0 ±0 
418 runs  +68  418 ✔️ +68  0 💤 ±0  0 ±0 

Results for commit 8015ffe. ± Comparison against base commit 3760401.

♻️ This comment has been updated with latest results.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some remarks. I think it would be valuable if @ganfra review this PR too.
I'm wondering why it's mandatory to retrieve the root event during the sync response processing. Can we do it only if the timeline is rendered?

@@ -56,10 +57,10 @@ internal open class EventEntity(@Index var eventId: String = "",

companion object

fun setDecryptionResult(result: MXEventDecryptionResult) {
fun setDecryptionResult(result: MXEventDecryptionResult, clearEvent: JsonDict? = null) {
Copy link
Member

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

* 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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not use runBlocking

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@bmarty bmarty requested a review from ganfra November 3, 2021 17:20
@ariskotsomitopoulos
Copy link
Contributor Author

I have some remarks. I think it would be valuable if @ganfra review this PR too. I'm wondering why it's mandatory to retrieve the root event during the sync response processing. Can we do it only if the timeline is rendered?

Later in the handler you would need that info, especially for the 10 latest messages.
It's not a big deal while:

  • User will fetch the root event ONLY once and never again
  • User will fetch them only if there is a thread response in the last messages

The majority of the fetching will be done when the timeline is rendered and decrypted.

Furthermore, if we go with a different approach we should add loaders on messages and the complexity of that is not worth it while its just a temporarily solution, and we should not spent that much time

if (eventList.isNullOrEmpty()) return

val threadsToFetch = emptyMap<String, String>().toMutableMap()
monarchy.awaitTransaction { realm ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are u using awaitTransaction here?

private val permalinkFactory: PermalinkFactory,
private val cryptoService: CryptoService,
@SessionDatabase private val monarchy: Monarchy,
private val session: Session
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't use session in the SDK this is only intended to be used by SDK user

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated accordingly

Copy link
Member

@ganfra ganfra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some remarks

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, @ganfra ?

return runCatching {
Timber.i("------> Fetching event[$eventId]....")
getEventTask.execute(GetEventTask.Params(roomId = roomId, eventId = eventId)).apply {
unsignedData?.age?.let { System.currentTimeMillis() - it }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be added to the task?

Copy link
Member

@ganfra ganfra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes, ok for me now

@bmarty bmarty merged commit e98dd2e into develop Nov 18, 2021
@bmarty bmarty deleted the feature/aris/thread_aware branch November 18, 2021 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Element Android Thread aware
3 participants