Use better names for API.

This commit is contained in:
Benoit Marty 2025-10-26 09:07:57 +01:00 committed by Benoit Marty
parent 529c708d7e
commit f0e42a70fb
5 changed files with 23 additions and 23 deletions

View file

@ -19,8 +19,8 @@ import io.element.android.libraries.di.annotations.ApplicationContext
import timber.log.Timber import timber.log.Timber
interface NotificationDisplayer { interface NotificationDisplayer {
fun showNotificationMessage(tag: String?, id: Int, notification: Notification): Boolean fun showNotification(tag: String?, id: Int, notification: Notification): Boolean
fun cancelNotificationMessage(tag: String?, id: Int) fun cancelNotification(tag: String?, id: Int)
fun displayDiagnosticNotification(notification: Notification): Boolean fun displayDiagnosticNotification(notification: Notification): Boolean
fun dismissDiagnosticNotification() fun dismissDiagnosticNotification()
} }
@ -30,7 +30,7 @@ class DefaultNotificationDisplayer(
@ApplicationContext private val context: Context, @ApplicationContext private val context: Context,
private val notificationManager: NotificationManagerCompat private val notificationManager: NotificationManagerCompat
) : NotificationDisplayer { ) : NotificationDisplayer {
override fun showNotificationMessage(tag: String?, id: Int, notification: Notification): Boolean { override fun showNotification(tag: String?, id: Int, notification: Notification): Boolean {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
Timber.w("Not allowed to notify.") Timber.w("Not allowed to notify.")
return false return false
@ -40,12 +40,12 @@ class DefaultNotificationDisplayer(
return true return true
} }
override fun cancelNotificationMessage(tag: String?, id: Int) { override fun cancelNotification(tag: String?, id: Int) {
notificationManager.cancel(tag, id) notificationManager.cancel(tag, id)
} }
override fun displayDiagnosticNotification(notification: Notification): Boolean { override fun displayDiagnosticNotification(notification: Notification): Boolean {
return showNotificationMessage( return showNotification(
tag = "DIAGNOSTIC", tag = "DIAGNOSTIC",
id = NOTIFICATION_ID_DIAGNOSTIC, id = NOTIFICATION_ID_DIAGNOSTIC,
notification = notification notification = notification
@ -53,7 +53,7 @@ class DefaultNotificationDisplayer(
} }
override fun dismissDiagnosticNotification() { override fun dismissDiagnosticNotification() {
cancelNotificationMessage( cancelNotification(
tag = "DIAGNOSTIC", tag = "DIAGNOSTIC",
id = NOTIFICATION_ID_DIAGNOSTIC id = NOTIFICATION_ID_DIAGNOSTIC
) )

View file

@ -74,7 +74,7 @@ class NotificationRenderer(
// Remove summary first to avoid briefly displaying it after dismissing the last notification // Remove summary first to avoid briefly displaying it after dismissing the last notification
if (summaryNotification == SummaryNotification.Removed) { if (summaryNotification == SummaryNotification.Removed) {
Timber.tag(loggerTag.value).d("Removing summary notification") Timber.tag(loggerTag.value).d("Removing summary notification")
notificationDisplayer.cancelNotificationMessage( notificationDisplayer.cancelNotification(
tag = null, tag = null,
id = NotificationIdProvider.getSummaryNotificationId(currentUser.userId) id = NotificationIdProvider.getSummaryNotificationId(currentUser.userId)
) )
@ -85,7 +85,7 @@ class NotificationRenderer(
roomId = notificationData.roomId, roomId = notificationData.roomId,
threadId = notificationData.threadId threadId = notificationData.threadId
) )
notificationDisplayer.showNotificationMessage( notificationDisplayer.showNotification(
tag = tag, tag = tag,
id = NotificationIdProvider.getRoomMessagesNotificationId(currentUser.userId), id = NotificationIdProvider.getRoomMessagesNotificationId(currentUser.userId),
notification = notificationData.notification notification = notificationData.notification
@ -95,7 +95,7 @@ class NotificationRenderer(
invitationNotifications.forEach { notificationData -> invitationNotifications.forEach { notificationData ->
if (useCompleteNotificationFormat) { if (useCompleteNotificationFormat) {
Timber.tag(loggerTag.value).d("Updating invitation notification ${notificationData.tag}") Timber.tag(loggerTag.value).d("Updating invitation notification ${notificationData.tag}")
notificationDisplayer.showNotificationMessage( notificationDisplayer.showNotification(
tag = notificationData.tag, tag = notificationData.tag,
id = NotificationIdProvider.getRoomInvitationNotificationId(currentUser.userId), id = NotificationIdProvider.getRoomInvitationNotificationId(currentUser.userId),
notification = notificationData.notification notification = notificationData.notification
@ -106,7 +106,7 @@ class NotificationRenderer(
simpleNotifications.forEach { notificationData -> simpleNotifications.forEach { notificationData ->
if (useCompleteNotificationFormat) { if (useCompleteNotificationFormat) {
Timber.tag(loggerTag.value).d("Updating simple notification ${notificationData.tag}") Timber.tag(loggerTag.value).d("Updating simple notification ${notificationData.tag}")
notificationDisplayer.showNotificationMessage( notificationDisplayer.showNotification(
tag = notificationData.tag, tag = notificationData.tag,
id = NotificationIdProvider.getRoomEventNotificationId(currentUser.userId), id = NotificationIdProvider.getRoomEventNotificationId(currentUser.userId),
notification = notificationData.notification notification = notificationData.notification
@ -117,7 +117,7 @@ class NotificationRenderer(
// Show only the first fallback notification // Show only the first fallback notification
if (fallbackNotifications.isNotEmpty()) { if (fallbackNotifications.isNotEmpty()) {
Timber.tag(loggerTag.value).d("Showing fallback notification") Timber.tag(loggerTag.value).d("Showing fallback notification")
notificationDisplayer.showNotificationMessage( notificationDisplayer.showNotification(
tag = "FALLBACK", tag = "FALLBACK",
id = NotificationIdProvider.getFallbackNotificationId(currentUser.userId), id = NotificationIdProvider.getFallbackNotificationId(currentUser.userId),
notification = fallbackNotifications.first().notification notification = fallbackNotifications.first().notification
@ -127,7 +127,7 @@ class NotificationRenderer(
// Update summary last to avoid briefly displaying it before other notifications // Update summary last to avoid briefly displaying it before other notifications
if (summaryNotification is SummaryNotification.Update) { if (summaryNotification is SummaryNotification.Update) {
Timber.tag(loggerTag.value).d("Updating summary notification") Timber.tag(loggerTag.value).d("Updating summary notification")
notificationDisplayer.showNotificationMessage( notificationDisplayer.showNotification(
tag = null, tag = null,
id = NotificationIdProvider.getSummaryNotificationId(currentUser.userId), id = NotificationIdProvider.getSummaryNotificationId(currentUser.userId),
notification = summaryNotification.notification notification = summaryNotification.notification

View file

@ -73,7 +73,7 @@ class DefaultOnRedactedEventReceived(
oldMessage.person oldMessage.person
) )
messagingStyle.messages[messageToRedactIndex] = newMessage messagingStyle.messages[messageToRedactIndex] = newMessage
notificationDisplayer.showNotificationMessage( notificationDisplayer.showNotification(
statusBarNotification.tag, statusBarNotification.tag,
statusBarNotification.id, statusBarNotification.id,
NotificationCompat.Builder(context, notification) NotificationCompat.Builder(context, notification)

View file

@ -78,7 +78,7 @@ class NotificationRendererTest {
renderEventsAsNotifications(listOf(aNotifiableMessageEvent())) renderEventsAsNotifications(listOf(aNotifiableMessageEvent()))
notificationDisplayer.showNotificationMessageResult.assertions().isCalledExactly(2).withSequence( notificationDisplayer.showNotificationResult.assertions().isCalledExactly(2).withSequence(
listOf(value(A_ROOM_ID.value), value(notificationIdProvider.getRoomMessagesNotificationId(A_SESSION_ID)), value(A_NOTIFICATION)), listOf(value(A_ROOM_ID.value), value(notificationIdProvider.getRoomMessagesNotificationId(A_SESSION_ID)), value(A_NOTIFICATION)),
listOf(value(null), value(notificationIdProvider.getSummaryNotificationId(A_SESSION_ID)), value(A_SUMMARY_NOTIFICATION.notification)) listOf(value(null), value(notificationIdProvider.getSummaryNotificationId(A_SESSION_ID)), value(A_SUMMARY_NOTIFICATION.notification))
) )
@ -90,7 +90,7 @@ class NotificationRendererTest {
renderEventsAsNotifications(listOf(aSimpleNotifiableEvent(eventId = AN_EVENT_ID))) renderEventsAsNotifications(listOf(aSimpleNotifiableEvent(eventId = AN_EVENT_ID)))
notificationDisplayer.showNotificationMessageResult.assertions().isCalledExactly(2).withSequence( notificationDisplayer.showNotificationResult.assertions().isCalledExactly(2).withSequence(
listOf(value(AN_EVENT_ID.value), value(notificationIdProvider.getRoomEventNotificationId(A_SESSION_ID)), value(A_NOTIFICATION)), listOf(value(AN_EVENT_ID.value), value(notificationIdProvider.getRoomEventNotificationId(A_SESSION_ID)), value(A_NOTIFICATION)),
listOf(value(null), value(notificationIdProvider.getSummaryNotificationId(A_SESSION_ID)), value(A_SUMMARY_NOTIFICATION.notification)) listOf(value(null), value(notificationIdProvider.getSummaryNotificationId(A_SESSION_ID)), value(A_SUMMARY_NOTIFICATION.notification))
) )
@ -102,7 +102,7 @@ class NotificationRendererTest {
renderEventsAsNotifications(listOf(anInviteNotifiableEvent())) renderEventsAsNotifications(listOf(anInviteNotifiableEvent()))
notificationDisplayer.showNotificationMessageResult.assertions().isCalledExactly(2).withSequence( notificationDisplayer.showNotificationResult.assertions().isCalledExactly(2).withSequence(
listOf(value(A_ROOM_ID.value), value(notificationIdProvider.getRoomInvitationNotificationId(A_SESSION_ID)), value(A_NOTIFICATION)), listOf(value(A_ROOM_ID.value), value(notificationIdProvider.getRoomInvitationNotificationId(A_SESSION_ID)), value(A_NOTIFICATION)),
listOf(value(null), value(notificationIdProvider.getSummaryNotificationId(A_SESSION_ID)), value(A_SUMMARY_NOTIFICATION.notification)) listOf(value(null), value(notificationIdProvider.getSummaryNotificationId(A_SESSION_ID)), value(A_SUMMARY_NOTIFICATION.notification))
) )

View file

@ -19,17 +19,17 @@ import io.element.android.tests.testutils.lambda.lambdaRecorder
import io.element.android.tests.testutils.lambda.value import io.element.android.tests.testutils.lambda.value
class FakeNotificationDisplayer( class FakeNotificationDisplayer(
var showNotificationMessageResult: LambdaThreeParamsRecorder<String?, Int, Notification, Boolean> = lambdaRecorder { _, _, _ -> true }, var showNotificationResult: LambdaThreeParamsRecorder<String?, Int, Notification, Boolean> = lambdaRecorder { _, _, _ -> true },
var cancelNotificationMessageResult: LambdaTwoParamsRecorder<String?, Int, Unit> = lambdaRecorder { _, _ -> }, var cancelNotificationResult: LambdaTwoParamsRecorder<String?, Int, Unit> = lambdaRecorder { _, _ -> },
var displayDiagnosticNotificationResult: LambdaOneParamRecorder<Notification, Boolean> = lambdaRecorder { _ -> true }, var displayDiagnosticNotificationResult: LambdaOneParamRecorder<Notification, Boolean> = lambdaRecorder { _ -> true },
var dismissDiagnosticNotificationResult: LambdaNoParamRecorder<Unit> = lambdaRecorder { -> }, var dismissDiagnosticNotificationResult: LambdaNoParamRecorder<Unit> = lambdaRecorder { -> },
) : NotificationDisplayer { ) : NotificationDisplayer {
override fun showNotificationMessage(tag: String?, id: Int, notification: Notification): Boolean { override fun showNotification(tag: String?, id: Int, notification: Notification): Boolean {
return showNotificationMessageResult(tag, id, notification) return showNotificationResult(tag, id, notification)
} }
override fun cancelNotificationMessage(tag: String?, id: Int) { override fun cancelNotification(tag: String?, id: Int) {
return cancelNotificationMessageResult(tag, id) return cancelNotificationResult(tag, id)
} }
override fun displayDiagnosticNotification(notification: Notification): Boolean { override fun displayDiagnosticNotification(notification: Notification): Boolean {
@ -41,7 +41,7 @@ class FakeNotificationDisplayer(
} }
fun verifySummaryCancelled(times: Int = 1) { fun verifySummaryCancelled(times: Int = 1) {
cancelNotificationMessageResult.assertions().isCalledExactly(times).withSequence( cancelNotificationResult.assertions().isCalledExactly(times).withSequence(
listOf(value(null), value(NotificationIdProvider.getSummaryNotificationId(A_SESSION_ID))) listOf(value(null), value(NotificationIdProvider.getSummaryNotificationId(A_SESSION_ID)))
) )
} }