-
Notifications
You must be signed in to change notification settings - Fork 782
Single PushTriggerListener
dispatch
#4401
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
Changes from all commits
5096318
57f7d83
6e0bd03
4014638
b76f881
7b38a06
cd9175b
576d945
5f13ba0
805f09f
88fbb8f
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 @@ | ||
Breaking SDK API change to PushRuleListener, the separated callbacks have been merged into one with a data class which includes all the previously separated push information |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2021 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.matrix.android.sdk.api.pushrules | ||
|
||
import org.matrix.android.sdk.api.pushrules.rest.PushRule | ||
import org.matrix.android.sdk.api.session.events.model.Event | ||
|
||
data class PushEvents( | ||
val matchedEvents: List<Pair<Event, PushRule>>, | ||
val roomsJoined: Collection<String>, | ||
val roomsLeft: Collection<String>, | ||
val redactedEventIds: List<String> | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import androidx.lifecycle.LiveData | |
import androidx.lifecycle.Transformations | ||
import com.zhuinden.monarchy.Monarchy | ||
import org.matrix.android.sdk.api.pushrules.Action | ||
import org.matrix.android.sdk.api.pushrules.PushEvents | ||
import org.matrix.android.sdk.api.pushrules.PushRuleService | ||
import org.matrix.android.sdk.api.pushrules.RuleKind | ||
import org.matrix.android.sdk.api.pushrules.RuleScope | ||
|
@@ -142,79 +143,6 @@ internal class DefaultPushRuleService @Inject constructor( | |
return pushRuleFinder.fulfilledBingRule(event, rules)?.getActions().orEmpty() | ||
} | ||
|
||
// fun processEvents(events: List<Event>) { | ||
// var hasDoneSomething = false | ||
// events.forEach { event -> | ||
// fulfilledBingRule(event)?.let { | ||
// hasDoneSomething = true | ||
// dispatchBing(event, it) | ||
// } | ||
// } | ||
// if (hasDoneSomething) | ||
// dispatchFinish() | ||
// } | ||
|
||
fun dispatchBing(event: Event, rule: PushRule) { | ||
synchronized(listeners) { | ||
val actionsList = rule.getActions() | ||
listeners.forEach { | ||
try { | ||
it.onMatchRule(event, actionsList) | ||
} catch (e: Throwable) { | ||
Timber.e(e, "Error while dispatching bing") | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun dispatchRoomJoined(roomId: String) { | ||
synchronized(listeners) { | ||
listeners.forEach { | ||
try { | ||
it.onRoomJoined(roomId) | ||
} catch (e: Throwable) { | ||
Timber.e(e, "Error while dispatching room joined") | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun dispatchRoomLeft(roomId: String) { | ||
synchronized(listeners) { | ||
listeners.forEach { | ||
try { | ||
it.onRoomLeft(roomId) | ||
} catch (e: Throwable) { | ||
Timber.e(e, "Error while dispatching room left") | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun dispatchRedactedEventId(redactedEventId: String) { | ||
synchronized(listeners) { | ||
listeners.forEach { | ||
try { | ||
it.onEventRedacted(redactedEventId) | ||
} catch (e: Throwable) { | ||
Timber.e(e, "Error while dispatching redacted event") | ||
} | ||
} | ||
} | ||
} | ||
|
||
fun dispatchFinish() { | ||
synchronized(listeners) { | ||
listeners.forEach { | ||
try { | ||
it.batchFinish() | ||
} catch (e: Throwable) { | ||
Timber.e(e, "Error while dispatching finish") | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun getKeywords(): LiveData<Set<String>> { | ||
// Keywords are all content rules that don't start with '.' | ||
val liveData = monarchy.findAllMappedWithChanges( | ||
|
@@ -229,4 +157,16 @@ internal class DefaultPushRuleService @Inject constructor( | |
results.firstOrNull().orEmpty().toSet() | ||
} | ||
} | ||
|
||
fun dispatchEvents(pushEvents: PushEvents) { | ||
synchronized(listeners) { | ||
listeners.forEach { | ||
try { | ||
it.onEvents(pushEvents) | ||
} catch (e: Throwable) { | ||
Timber.e(e, "Error while dispatching push events") | ||
} | ||
} | ||
} | ||
} | ||
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. This code looks way better for this class at least :) |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
package org.matrix.android.sdk.internal.session.notification | ||
|
||
import org.matrix.android.sdk.api.pushrules.PushEvents | ||
import org.matrix.android.sdk.api.pushrules.rest.PushRule | ||
import org.matrix.android.sdk.api.session.events.model.EventType | ||
import org.matrix.android.sdk.api.session.events.model.isInvitation | ||
|
@@ -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 { | ||
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. these have moved to
|
||
defaultPushRuleService.dispatchRoomLeft(it) | ||
} | ||
// Handle joined rooms | ||
params.syncResponse.join.keys.forEach { | ||
defaultPushRuleService.dispatchRoomJoined(it) | ||
} | ||
val newJoinEvents = params.syncResponse.join | ||
.mapNotNull { (key, value) -> | ||
value.timeline?.events?.mapNotNull { | ||
|
@@ -74,10 +67,10 @@ internal class DefaultProcessEventForPushTask @Inject constructor( | |
} | ||
Timber.v("[PushRules] Found ${allEvents.size} out of ${(newJoinEvents + inviteEvents).size}" + | ||
" to check for push rules with ${params.rules.size} rules") | ||
allEvents.forEach { event -> | ||
val matchedEvents = allEvents.mapNotNull { event -> | ||
pushRuleFinder.fulfilledBingRule(event, params.rules)?.let { | ||
Timber.v("[PushRules] Rule $it match for event ${event.eventId}") | ||
defaultPushRuleService.dispatchBing(event, it) | ||
event to it | ||
} | ||
} | ||
|
||
|
@@ -91,10 +84,13 @@ internal class DefaultProcessEventForPushTask @Inject constructor( | |
|
||
Timber.v("[PushRules] Found ${allRedactedEvents.size} redacted events") | ||
|
||
allRedactedEvents.forEach { redactedEventId -> | ||
defaultPushRuleService.dispatchRedactedEventId(redactedEventId) | ||
} | ||
|
||
defaultPushRuleService.dispatchFinish() | ||
defaultPushRuleService.dispatchEvents( | ||
PushEvents( | ||
matchedEvents = matchedEvents, | ||
roomsJoined = params.syncResponse.join.keys, | ||
roomsLeft = params.syncResponse.leave.keys, | ||
redactedEventIds = allRedactedEvents | ||
) | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) } | ||
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.
|
||
} | ||
} | ||
} | ||
|
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.
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!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.
OK, You should add a file for the changelog with
.removal
extension to notify SDK users about this API break.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.
added 88fbb8f