Fixed chat message replies in notification

This commit is contained in:
Sylvain Berfini 2023-01-19 09:21:19 +01:00
parent 327f296ac0
commit 31f3cb3391

View file

@ -675,7 +675,7 @@ class NotificationsManager(private val context: Context) {
for (message in messages) { for (message in messages) {
if (message.isRead || message.isOutgoing) continue if (message.isRead || message.isOutgoing) continue
val friend = coreContext.contactsManager.findContactByAddress(message.fromAddress) val friend = coreContext.contactsManager.findContactByAddress(message.fromAddress)
val notifiableMessage = getNotifiableMessage(message, friend, notifiable) val notifiableMessage = getNotifiableMessage(message, friend)
notifiable.messages.add(notifiableMessage) notifiable.messages.add(notifiableMessage)
} }
@ -703,7 +703,7 @@ class NotificationsManager(private val context: Context) {
return notifiable return notifiable
} }
private fun getNotifiableMessage(message: ChatMessage, friend: Friend?, notifiable: Notifiable): NotifiableMessage { private fun getNotifiableMessage(message: ChatMessage, friend: Friend?): NotifiableMessage {
val roundPicture = ImageUtils.getRoundBitmapFromUri(context, friend?.getThumbnailUri()) val roundPicture = ImageUtils.getRoundBitmapFromUri(context, friend?.getThumbnailUri())
val displayName = friend?.name ?: LinphoneUtils.getDisplayName(message.fromAddress) val displayName = friend?.name ?: LinphoneUtils.getDisplayName(message.fromAddress)
var text = "" var text = ""
@ -825,10 +825,7 @@ class NotificationsManager(private val context: Context) {
var lastPerson: Person? = null var lastPerson: Person? = null
for (message in notifiable.messages) { for (message in notifiable.messages) {
val friend = message.friend val friend = message.friend
val person = if (message.isOutgoing) val person = getPerson(friend, message.sender, message.senderAvatar)
me
else
getPerson(friend, message.sender, message.senderAvatar)
if (!message.isOutgoing) { if (!message.isOutgoing) {
// We don't want to see our own avatar // We don't want to see our own avatar
@ -840,15 +837,19 @@ class NotificationsManager(private val context: Context) {
} }
} }
val senderPerson = if (message.isOutgoing) null else person // Use null for ourselves
val msg = if (corePreferences.hideChatMessageContentInNotification) { val msg = if (corePreferences.hideChatMessageContentInNotification) {
NotificationCompat.MessagingStyle.Message(AppUtils.getString(R.string.chat_message_notification_hidden_content), message.time, person) NotificationCompat.MessagingStyle.Message(AppUtils.getString(R.string.chat_message_notification_hidden_content), message.time, senderPerson)
} else { } else {
val tmp = NotificationCompat.MessagingStyle.Message(message.message, message.time, person) val tmp = NotificationCompat.MessagingStyle.Message(message.message, message.time, senderPerson)
if (message.filePath != null) tmp.setData(message.fileMime, message.filePath) if (message.filePath != null) tmp.setData(message.fileMime, message.filePath)
tmp tmp
} }
style.addMessage(msg) style.addMessage(msg)
if (message.isOutgoing) {
style.addHistoricMessage(msg)
}
} }
style.conversationTitle = if (notifiable.isGroup) notifiable.groupTitle else lastPerson?.name style.conversationTitle = if (notifiable.isGroup) notifiable.groupTitle else lastPerson?.name