From 318ab35eab72b3caa01a708db8c2c391f5a76c7c Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 15 Sep 2023 09:55:03 +0200 Subject: [PATCH] Another improvement for chat message reaction notification: remove previous notification when user changes it's reaction --- .../notifications/NotificationsManager.kt | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt index 449cb7401..aaf950229 100644 --- a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt +++ b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt @@ -303,9 +303,14 @@ class NotificationsManager(private val context: Context) { } } - val notifiable = createChatReactionNotifiable(chatRoom, reaction.body, address, message) - if (notifiable.messages.isNotEmpty()) { - displayChatNotifiable(chatRoom, notifiable) + val newNotifiable = createChatReactionNotifiable( + chatRoom, + reaction.body, + address, + message + ) + if (newNotifiable.messages.isNotEmpty()) { + displayChatNotifiable(chatRoom, newNotifiable) } else { Log.e( "[Notifications Manager] Notifiable is empty but we should have displayed the reaction!" @@ -949,6 +954,18 @@ class NotificationsManager(private val context: Context) { ): Notifiable { val notifiable = getNotifiableForRoom(room) + // Check for previous reaction notifiable from the same person for the same message + val fromAddr = from.asStringUriOnly() + val found = notifiable.messages.find { + it.isReaction && it.reactionToMessageId == message.messageId && it.reactionFrom == fromAddr + } + if (found != null) { + Log.i( + "[Notifications Manager] Found a previous notifiable for a reaction from the same person to the same message, removing it" + ) + notifiable.messages.remove(found) + } + val friend = coreContext.contactsManager.findContactByAddress(from) val roundPicture = ImageUtils.getRoundBitmapFromUri(context, friend?.getThumbnailUri()) val displayName = friend?.name ?: LinphoneUtils.getDisplayName(from)