formatting
This commit is contained in:
parent
8fb6bef503
commit
a94a1a0523
@ -84,12 +84,13 @@ class NotificationFactory @Inject constructor(
|
|||||||
val simpleMeta = simpleNotifications.mapToMeta()
|
val simpleMeta = simpleNotifications.mapToMeta()
|
||||||
return when {
|
return when {
|
||||||
roomMeta.isEmpty() && invitationMeta.isEmpty() && simpleMeta.isEmpty() -> SummaryNotification.Removed
|
roomMeta.isEmpty() && invitationMeta.isEmpty() && simpleMeta.isEmpty() -> SummaryNotification.Removed
|
||||||
else -> SummaryNotification.Update(summaryGroupMessageCreator.createSummaryNotification(
|
else -> SummaryNotification.Update(
|
||||||
roomNotifications = roomMeta,
|
summaryGroupMessageCreator.createSummaryNotification(
|
||||||
invitationNotifications = invitationMeta,
|
roomNotifications = roomMeta,
|
||||||
simpleNotifications = simpleMeta,
|
invitationNotifications = invitationMeta,
|
||||||
useCompleteNotificationFormat = useCompleteNotificationFormat
|
simpleNotifications = simpleMeta,
|
||||||
))
|
useCompleteNotificationFormat = useCompleteNotificationFormat
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,10 @@ package im.vector.app.features.notifications
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.annotation.WorkerThread
|
import androidx.annotation.WorkerThread
|
||||||
|
import im.vector.app.features.notifications.NotificationDrawerManager.Companion.ROOM_EVENT_NOTIFICATION_ID
|
||||||
|
import im.vector.app.features.notifications.NotificationDrawerManager.Companion.ROOM_INVITATION_NOTIFICATION_ID
|
||||||
|
import im.vector.app.features.notifications.NotificationDrawerManager.Companion.ROOM_MESSAGES_NOTIFICATION_ID
|
||||||
|
import im.vector.app.features.notifications.NotificationDrawerManager.Companion.SUMMARY_NOTIFICATION_ID
|
||||||
import androidx.core.content.pm.ShortcutManagerCompat
|
import androidx.core.content.pm.ShortcutManagerCompat
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -47,7 +51,11 @@ class NotificationRenderer @Inject constructor(private val notifiableEventProces
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processEvents(notificationEvents: ProcessedNotificationEvents, myUserId: String, myUserDisplayName: String, myUserAvatarUrl: String?, useCompleteNotificationFormat: Boolean) {
|
private fun processEvents(notificationEvents: ProcessedNotificationEvents,
|
||||||
|
myUserId: String,
|
||||||
|
myUserDisplayName: String,
|
||||||
|
myUserAvatarUrl: String?,
|
||||||
|
useCompleteNotificationFormat: Boolean) {
|
||||||
val (roomEvents, simpleEvents, invitationEvents) = notificationEvents
|
val (roomEvents, simpleEvents, invitationEvents) = notificationEvents
|
||||||
with(notificationFactory) {
|
with(notificationFactory) {
|
||||||
val roomNotifications = roomEvents.toNotifications(myUserDisplayName, myUserAvatarUrl)
|
val roomNotifications = roomEvents.toNotifications(myUserDisplayName, myUserAvatarUrl)
|
||||||
@ -62,33 +70,33 @@ class NotificationRenderer @Inject constructor(private val notifiableEventProces
|
|||||||
|
|
||||||
roomNotifications.forEach { wrapper ->
|
roomNotifications.forEach { wrapper ->
|
||||||
when (wrapper) {
|
when (wrapper) {
|
||||||
is RoomNotification.Removed -> notificationDisplayer.cancelNotificationMessage(wrapper.roomId, NotificationDrawerManager.ROOM_MESSAGES_NOTIFICATION_ID)
|
is RoomNotification.Removed -> notificationDisplayer.cancelNotificationMessage(wrapper.roomId, ROOM_MESSAGES_NOTIFICATION_ID)
|
||||||
is RoomNotification.Message -> if (useCompleteNotificationFormat) {
|
is RoomNotification.Message -> if (useCompleteNotificationFormat) {
|
||||||
Timber.d("Updating room messages notification ${wrapper.meta.roomId}")
|
Timber.d("Updating room messages notification ${wrapper.meta.roomId}")
|
||||||
wrapper.shortcutInfo?.let {
|
wrapper.shortcutInfo?.let {
|
||||||
ShortcutManagerCompat.pushDynamicShortcut(appContext, it)
|
ShortcutManagerCompat.pushDynamicShortcut(appContext, it)
|
||||||
}
|
}
|
||||||
notificationDisplayer.showNotificationMessage(wrapper.meta.roomId, NotificationDrawerManager.ROOM_MESSAGES_NOTIFICATION_ID, wrapper.notification)
|
notificationDisplayer.showNotificationMessage(wrapper.meta.roomId, ROOM_MESSAGES_NOTIFICATION_ID, wrapper.notification)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
invitationNotifications.forEach { wrapper ->
|
invitationNotifications.forEach { wrapper ->
|
||||||
when (wrapper) {
|
when (wrapper) {
|
||||||
is OneShotNotification.Removed -> notificationDisplayer.cancelNotificationMessage(wrapper.key, NotificationDrawerManager.ROOM_INVITATION_NOTIFICATION_ID)
|
is OneShotNotification.Removed -> notificationDisplayer.cancelNotificationMessage(wrapper.key, ROOM_INVITATION_NOTIFICATION_ID)
|
||||||
is OneShotNotification.Append -> if (useCompleteNotificationFormat) {
|
is OneShotNotification.Append -> if (useCompleteNotificationFormat) {
|
||||||
Timber.d("Updating invitation notification ${wrapper.meta.key}")
|
Timber.d("Updating invitation notification ${wrapper.meta.key}")
|
||||||
notificationDisplayer.showNotificationMessage(wrapper.meta.key, NotificationDrawerManager.ROOM_INVITATION_NOTIFICATION_ID, wrapper.notification)
|
notificationDisplayer.showNotificationMessage(wrapper.meta.key, ROOM_INVITATION_NOTIFICATION_ID, wrapper.notification)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
simpleNotifications.forEach { wrapper ->
|
simpleNotifications.forEach { wrapper ->
|
||||||
when (wrapper) {
|
when (wrapper) {
|
||||||
is OneShotNotification.Removed -> notificationDisplayer.cancelNotificationMessage(wrapper.key, NotificationDrawerManager.ROOM_EVENT_NOTIFICATION_ID)
|
is OneShotNotification.Removed -> notificationDisplayer.cancelNotificationMessage(wrapper.key, ROOM_EVENT_NOTIFICATION_ID)
|
||||||
is OneShotNotification.Append -> if (useCompleteNotificationFormat) {
|
is OneShotNotification.Append -> if (useCompleteNotificationFormat) {
|
||||||
Timber.d("Updating simple notification ${wrapper.meta.key}")
|
Timber.d("Updating simple notification ${wrapper.meta.key}")
|
||||||
notificationDisplayer.showNotificationMessage(wrapper.meta.key, NotificationDrawerManager.ROOM_EVENT_NOTIFICATION_ID, wrapper.notification)
|
notificationDisplayer.showNotificationMessage(wrapper.meta.key, ROOM_EVENT_NOTIFICATION_ID, wrapper.notification)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,11 +104,11 @@ class NotificationRenderer @Inject constructor(private val notifiableEventProces
|
|||||||
when (summaryNotification) {
|
when (summaryNotification) {
|
||||||
SummaryNotification.Removed -> {
|
SummaryNotification.Removed -> {
|
||||||
Timber.d("Removing summary notification")
|
Timber.d("Removing summary notification")
|
||||||
notificationDisplayer.cancelNotificationMessage(null, NotificationDrawerManager.SUMMARY_NOTIFICATION_ID)
|
notificationDisplayer.cancelNotificationMessage(null, SUMMARY_NOTIFICATION_ID)
|
||||||
}
|
}
|
||||||
is SummaryNotification.Update -> {
|
is SummaryNotification.Update -> {
|
||||||
Timber.d("Updating summary notification")
|
Timber.d("Updating summary notification")
|
||||||
notificationDisplayer.showNotificationMessage(null, NotificationDrawerManager.SUMMARY_NOTIFICATION_ID, summaryNotification.notification)
|
notificationDisplayer.showNotificationMessage(null, SUMMARY_NOTIFICATION_ID, summaryNotification.notification)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,9 +51,9 @@ class SummaryGroupMessageCreator @Inject constructor(
|
|||||||
simpleNotifications.forEach { style.addLine(it.summaryLine) }
|
simpleNotifications.forEach { style.addLine(it.summaryLine) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val summaryIsNoisy = roomNotifications.any { it.shouldBing }
|
val summaryIsNoisy = roomNotifications.any { it.shouldBing } ||
|
||||||
|| invitationNotifications.any { it.isNoisy }
|
invitationNotifications.any { it.isNoisy } ||
|
||||||
|| simpleNotifications.any { it.isNoisy }
|
simpleNotifications.any { it.isNoisy }
|
||||||
|
|
||||||
val messageCount = roomNotifications.fold(initial = 0) { acc, current -> acc + current.messageCount }
|
val messageCount = roomNotifications.fold(initial = 0) { acc, current -> acc + current.messageCount }
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ import android.app.Notification
|
|||||||
import im.vector.app.test.fakes.FakeNotifiableEventProcessor
|
import im.vector.app.test.fakes.FakeNotifiableEventProcessor
|
||||||
import im.vector.app.test.fakes.FakeNotificationDisplayer
|
import im.vector.app.test.fakes.FakeNotificationDisplayer
|
||||||
import im.vector.app.test.fakes.FakeNotificationFactory
|
import im.vector.app.test.fakes.FakeNotificationFactory
|
||||||
import im.vector.app.test.fakes.FakeVectorPreferences
|
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user