Skip to content
Merged
Show file tree
Hide file tree
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 Oct 5, 2021
51d3cc5
creating dedicated class for the processing the serialized events
ouchadam Oct 6, 2021
dded400
creating the notifications separate to where they're displayed
ouchadam Oct 6, 2021
5c4ea4a
chaining the event process, notification creation and display logic i…
ouchadam Oct 6, 2021
b3bb42f
lifting settings change to cancel all notifications out of the renderer
ouchadam Oct 7, 2021
55480e0
removing no longer needed hasBeenDisplayed state, the eventList is ou…
ouchadam Oct 7, 2021
066fd49
handling creating the summary when notification events are filtered t…
ouchadam Oct 7, 2021
d925044
removing this usages for project convention
ouchadam Oct 7, 2021
1be096b
formatting
ouchadam Oct 7, 2021
c705496
ensuring that we removing the summary group before removing individua…
ouchadam Oct 8, 2021
bf9a3ef
relying on the notification refreshing to cancel/update the notificat…
ouchadam Oct 11, 2021
41b3deb
splitting the event processing from the rendering
ouchadam Oct 11, 2021
b0306ab
using a process state of keep/removed rather than mapping to an ignor…
ouchadam Oct 11, 2021
edff292
diffing the notification events against the currently rendered events…
ouchadam Oct 11, 2021
28df5a3
ensuring that we remove read messages when they come through by respe…
ouchadam Oct 11, 2021
25c4322
adding documentation around the two notifiable event lists which act …
ouchadam Oct 13, 2021
2f8be02
fixing line lengths
ouchadam Oct 13, 2021
672e7f9
adding missing fixture parameter from rebase
ouchadam Oct 13, 2021
92d05e7
inlining single use extension functions
ouchadam Oct 13, 2021
75e45d1
adding missing parameter from rebase and removing no longer needed si…
ouchadam Oct 14, 2021
5029937
replacing notification utils usage with the displayer and removing un…
ouchadam Oct 14, 2021
60a5bb9
removing unused imports
ouchadam Oct 14, 2021
6393311
updating tests with shortcut placement changes
ouchadam Oct 14, 2021
63bbc71
increase enum class allowance by 1
ouchadam Oct 14, 2021
f5de7f7
using dedicated ProcessedEvent data class instead of type alias for p…
ouchadam Oct 19, 2021
0fe1b69
renaming event lists to give more context and remove the list suffix/…
ouchadam Oct 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/check/forbidden_strings_in_code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Formatter\.formatShortFileSize===1
# android\.text\.TextUtils

### This is not a rule, but a warning: the number of "enum class" has changed. For Json classes, it is mandatory that they have `@JsonClass(generateAdapter = false)`. If the enum is not used as a Json class, change the value in file forbidden_strings_in_code.txt
enum class===106
enum class===107

### Do not import temporary legacy classes
import org.matrix.android.sdk.internal.legacy.riot===3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,4 @@ data class InviteNotifiableEvent(
val timestamp: Long,
val soundName: String?,
override val isRedacted: Boolean = false
) : NotifiableEvent {

override var hasBeenDisplayed = false
Copy link
Contributor Author

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 eventList and renderedEventsList

}
) : NotifiableEvent
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import java.io.Serializable
sealed interface NotifiableEvent : Serializable {
val eventId: String
val editedEventId: String?
var hasBeenDisplayed: Boolean

// Used to know if event should be replaced with the one coming from eventstream
val canBeReplaced: Boolean
Expand Down
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ data class NotifiableMessageEvent(
override val isRedacted: Boolean = false
) : NotifiableEvent {

override var hasBeenDisplayed: Boolean = false

val type: String = EventType.MESSAGE
val description: String = body ?: ""
val title: String = senderName ?: ""
Expand Down
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) {
Copy link
Member

Choose a reason for hiding this comment

The 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")
}
}
}
Loading