-
Notifications
You must be signed in to change notification settings - Fork 861
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
Changes from 24 commits
098d4ab
51d3cc5
dded400
5c4ea4a
b3bb42f
55480e0
066fd49
d925044
1be096b
c705496
bf9a3ef
41b3deb
b0306ab
edff292
28df5a3
25c4322
2f8be02
672e7f9
92d05e7
75e45d1
5029937
60a5bb9
6393311
63bbc71
f5de7f7
0fe1b69
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,50 @@ | ||
| /* | ||
| * 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.ProcessedType.KEEP | ||
| import im.vector.app.features.notifications.ProcessedType.REMOVE | ||
| import javax.inject.Inject | ||
|
|
||
| class NotifiableEventProcessor @Inject constructor( | ||
| private val outdatedDetector: OutdatedEventDetector, | ||
| private val autoAcceptInvites: AutoAcceptInvites | ||
| ) { | ||
|
|
||
| fun process(eventList: List<NotifiableEvent>, currentRoomId: String?, renderedEventsList: List<ProcessedEvent>): List<ProcessedEvent> { | ||
|
||
| val processedEventList = eventList.map { | ||
| 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 | ||
| } to it | ||
| } | ||
|
|
||
| val removedEventsDiff = renderedEventsList.filter { renderedEvent -> | ||
| eventList.none { it.eventId == renderedEvent.second.eventId } | ||
| }.map { REMOVE to it.second } | ||
|
|
||
| return removedEventsDiff + processedEventList | ||
| } | ||
|
|
||
| private fun shouldIgnoreMessageEventInRoom(currentRoomId: String?, roomId: String?): Boolean { | ||
| return currentRoomId != null && roomId == currentRoomId | ||
| } | ||
| } | ||
| 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") | ||
| } | ||
| } | ||
| } | ||
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