-
Notifications
You must be signed in to change notification settings - Fork 857
Splitting notifications into separate creation and displaying passes #4235
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
Merged
ouchadam
merged 26 commits into
feature/adm/notification-redesign
from
feature/adm/notification-logic-split
Oct 20, 2021
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
098d4ab
making the event body non null and immutable to allow less cases to b…
ouchadam 51d3cc5
creating dedicated class for the processing the serialized events
ouchadam dded400
creating the notifications separate to where they're displayed
ouchadam 5c4ea4a
chaining the event process, notification creation and display logic i…
ouchadam b3bb42f
lifting settings change to cancel all notifications out of the renderer
ouchadam 55480e0
removing no longer needed hasBeenDisplayed state, the eventList is ou…
ouchadam 066fd49
handling creating the summary when notification events are filtered t…
ouchadam d925044
removing this usages for project convention
ouchadam 1be096b
formatting
ouchadam c705496
ensuring that we removing the summary group before removing individua…
ouchadam bf9a3ef
relying on the notification refreshing to cancel/update the notificat…
ouchadam 41b3deb
splitting the event processing from the rendering
ouchadam b0306ab
using a process state of keep/removed rather than mapping to an ignor…
ouchadam edff292
diffing the notification events against the currently rendered events…
ouchadam 28df5a3
ensuring that we remove read messages when they come through by respe…
ouchadam 25c4322
adding documentation around the two notifiable event lists which act …
ouchadam 2f8be02
fixing line lengths
ouchadam 672e7f9
adding missing fixture parameter from rebase
ouchadam 92d05e7
inlining single use extension functions
ouchadam 75e45d1
adding missing parameter from rebase and removing no longer needed si…
ouchadam 5029937
replacing notification utils usage with the displayer and removing un…
ouchadam 60a5bb9
removing unused imports
ouchadam 6393311
updating tests with shortcut placement changes
ouchadam 63bbc71
increase enum class allowance by 1
ouchadam f5de7f7
using dedicated ProcessedEvent data class instead of type alias for p…
ouchadam 0fe1b69
renaming event lists to give more context and remove the list suffix/…
ouchadam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
vector/src/main/java/im/vector/app/features/notifications/NotifiableEventProcessor.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * Copyright (c) 2021 New Vector Ltd | ||
| * | ||
| * 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 im.vector.app.features.notifications | ||
|
|
||
| import im.vector.app.features.invite.AutoAcceptInvites | ||
| import im.vector.app.features.notifications.ProcessedEvent.Type.KEEP | ||
| import im.vector.app.features.notifications.ProcessedEvent.Type.REMOVE | ||
| import javax.inject.Inject | ||
|
|
||
| private typealias ProcessedEvents = List<ProcessedEvent<NotifiableEvent>> | ||
|
|
||
| class NotifiableEventProcessor @Inject constructor( | ||
| private val outdatedDetector: OutdatedEventDetector, | ||
| private val autoAcceptInvites: AutoAcceptInvites | ||
| ) { | ||
|
|
||
| fun process(queuedEvents: List<NotifiableEvent>, currentRoomId: String?, renderedEvents: ProcessedEvents): ProcessedEvents { | ||
| val processedEvents = queuedEvents.map { | ||
| val type = when (it) { | ||
| is InviteNotifiableEvent -> if (autoAcceptInvites.hideInvites) REMOVE else KEEP | ||
| is NotifiableMessageEvent -> if (shouldIgnoreMessageEventInRoom(currentRoomId, it.roomId) || outdatedDetector.isMessageOutdated(it)) { | ||
| REMOVE | ||
| } else KEEP | ||
| is SimpleNotifiableEvent -> KEEP | ||
| } | ||
| ProcessedEvent(type, it) | ||
| } | ||
|
|
||
| val removedEventsDiff = renderedEvents.filter { renderedEvent -> | ||
| queuedEvents.none { it.eventId == renderedEvent.event.eventId } | ||
| }.map { ProcessedEvent(REMOVE, it.event) } | ||
|
|
||
| return removedEventsDiff + processedEvents | ||
| } | ||
|
|
||
| private fun shouldIgnoreMessageEventInRoom(currentRoomId: String?, roomId: String?): Boolean { | ||
| return currentRoomId != null && roomId == currentRoomId | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
vector/src/main/java/im/vector/app/features/notifications/NotificationDisplayer.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright (c) 2021 New Vector Ltd | ||
| * | ||
| * 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 im.vector.app.features.notifications | ||
|
|
||
| import android.app.Notification | ||
| import android.content.Context | ||
| import androidx.core.app.NotificationManagerCompat | ||
| import timber.log.Timber | ||
| import javax.inject.Inject | ||
|
|
||
| class NotificationDisplayer @Inject constructor(context: Context) { | ||
|
Member
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. I like this simple class 👍 |
||
|
|
||
| private val notificationManager = NotificationManagerCompat.from(context) | ||
|
|
||
| fun showNotificationMessage(tag: String?, id: Int, notification: Notification) { | ||
| notificationManager.notify(tag, id, notification) | ||
| } | ||
|
|
||
| fun cancelNotificationMessage(tag: String?, id: Int) { | ||
| notificationManager.cancel(tag, id) | ||
| } | ||
|
|
||
| fun cancelAllNotifications() { | ||
| // Keep this try catch (reported by GA) | ||
| try { | ||
| notificationManager.cancelAll() | ||
| } catch (e: Exception) { | ||
| Timber.e(e, "## cancelAllNotifications() failed") | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
no longer needed as we diff the
eventListandrenderedEventsList