From 14dca2f984522f7aca4c642070eee3c1de057dea Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 15 Sep 2023 09:55:27 +0200 Subject: [PATCH] Improved reaction notification --- .../notifications/NotificationsManager.kt | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt index 74f1bc6f3..2bae66e30 100644 --- a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt +++ b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt @@ -402,20 +402,36 @@ class NotificationsManager @MainThread constructor(private val context: Context) private fun showChatMessageReactionNotification( chatRoom: ChatRoom, reaction: String, - from: Address, + address: Address, message: ChatMessage ) { val notifiable = getNotifiableForRoom(chatRoom) + // Check if a previous reaction notifiable exists from the same person & for the same message + val from = address.asStringUriOnly() + val found = notifiable.messages.find { + it.isReaction && it.reactionToMessageId == message.messageId && it.reactionFrom == from + } + if (found != null) { + Log.i( + "$TAG Found a previous notifiable for a reaction from the same person to the same message" + ) + if (notifiable.messages.remove(found)) { + Log.i("$TAG Previous reaction notifiable removed") + } else { + Log.w("$TAG Failed to remove previous reaction notifiable") + } + } + val contact = - coreContext.contactsManager.findContactByAddress(from) + coreContext.contactsManager.findContactByAddress(address) val contactPicture = contact?.photo val roundPicture = if (!contactPicture.isNullOrEmpty()) { ImageUtils.getRoundBitmapFromUri(context, Uri.parse(contactPicture)) } else { null } - val displayName = contact?.name ?: LinphoneUtils.getDisplayName(from) + val displayName = contact?.name ?: LinphoneUtils.getDisplayName(address) val originalMessage = getTextDescribingMessage(message) val text = AppUtils.getString(R.string.chat_message_reaction_received).format( @@ -433,7 +449,7 @@ class NotificationsManager @MainThread constructor(private val context: Context) isOutgoing = false, isReaction = true, reactionToMessageId = message.messageId, - reactionFrom = from.asStringUriOnly() + reactionFrom = address.asStringUriOnly() ) notifiable.messages.add(notifiableMessage)