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

Single PushTriggerListener dispatch #4401

Conversation

ouchadam
Copy link
Contributor

@ouchadam ouchadam commented Nov 3, 2021

Some preparation/refactors around the Push triggers in order to support suspending NotifiableEventResolver.resolveEvent which is required for including images in the notifications

*points to a feature branch

  • PushRuleListener functions are replaced with a single onEvents(PushEvents) in order to allow any logic within the implementation to be asynchronous
  • All notification event changes are handled via the notificationDrawerManager.updateEvents, this ensures a single point of synchronisation and notification render pass (reduces the amount of render passes and synchronisation locks)
  • Notification queue mutations are extracted to a dedicated class along with unit tests
  • Lifts the NotifiableEvent fixtures to a dedicated fixtures test package

…llback

- simplifies the handling of notifications, will allow us to reduce redundant synchronisations and suspend the entire notification update (will be needed for supporting images)
…a single update point of entry for mutating the events

- this avoids multiple synchronisation locks by batching updates and ensures a single notification render pass
…tifiableEventReceived not synchronised for use within the synchronized batching

- makes the refresh function private as all interactions now come through via update
fun onRoomLeft(roomId: String)
fun onEventRedacted(redactedEventId: String)
fun batchFinish()
fun onEvents(pushEvents: PushEvents)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

using a single function here also allows up to simplfy the notification updates as we can batch all the events into one update pass, reducing the amount of synchronisation locks and redundant render passes

we might not need the private var firstThrottler = FirstThrottler(200) anymore because of how few individual updates we make!

Copy link
Member

Choose a reason for hiding this comment

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

OK, You should add a file for the changelog with .removal extension to notify SDK users about this API break.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added 88fbb8f

@@ -39,14 +40,6 @@ internal class DefaultProcessEventForPushTask @Inject constructor(
) : ProcessEventForPushTask {

override suspend fun execute(params: ProcessEventForPushTask.Params) {
// Handle left rooms
params.syncResponse.leave.keys.forEach {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these have moved to

roomsJoined = params.syncResponse.join.keys,
roomsLeft = params.syncResponse.leave.keys,

https://github.com/vector-im/element-android/pull/4401/files#diff-930446ed1e91a2c4f8a100edef89d21db2bec6b6d4a80765ff58f73e4e042182R88

@@ -201,8 +201,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
resolvedEvent
?.also { Timber.tag(loggerTag.value).d("Fast lane: notify drawer") }
?.let {
notificationDrawerManager.onNotifiableEventReceived(it)
notificationDrawerManager.refreshNotificationDrawer()
notificationDrawerManager.updateEvents { it.onNotifiableEventReceived(resolvedEvent) }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

updateEvents synchronises all queue mutations within the block and refreshes the drawer at the end

override fun onEvents(pushEvents: PushEvents) {
session?.let { session ->
val notifiableEvents = createNotifiableEvents(pushEvents, session)
notificationDrawerManager.updateEvents { queuedEvents ->
Copy link
Contributor Author

@ouchadam ouchadam Nov 3, 2021

Choose a reason for hiding this comment

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

all notification updates from the sync response are now batched together into a single update, this enables the logic within onEvents to be moved to a coroutine without race conditions

@@ -145,48 +148,3 @@ class NotifiableEventProcessorTest {
ProcessedEvent(it.first, it.second)
}
}

fun aSimpleNotifiableEvent(eventId: String, type: String? = null) = SimpleNotifiableEvent(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

extracted out to their own file

@github-actions
Copy link

github-actions bot commented Nov 3, 2021

Unit Test Results

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

Results for commit 88fbb8f. ± 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.

LGTM, just one remark about the changelog

fun onRoomLeft(roomId: String)
fun onEventRedacted(redactedEventId: String)
fun batchFinish()
fun onEvents(pushEvents: PushEvents)
Copy link
Member

Choose a reason for hiding this comment

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

OK, You should add a file for the changelog with .removal extension to notify SDK users about this API break.

}
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

This code looks way better for this class at least :)

@bmarty
Copy link
Member

bmarty commented Nov 5, 2021

@ouchadam please feel free to merge your approved PRs, if not targeting develop :)

@ouchadam
Copy link
Contributor Author

ouchadam commented Nov 5, 2021

@bmarty thanks, will do!

@ouchadam ouchadam merged commit 183ca18 into feature/adm/feature-notification-images Nov 5, 2021
@ouchadam ouchadam deleted the feature/adm/single-transaction-push branch November 5, 2021 15:03
@ouchadam ouchadam mentioned this pull request Nov 8, 2021
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.

2 participants