Prevent chat message notification to be updated for nothing
This commit is contained in:
parent
04bfce0406
commit
7335360c26
1 changed files with 25 additions and 6 deletions
|
@ -179,7 +179,23 @@ class NotificationsManager(private val context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val notifiable = createChatNotifiable(room, messages)
|
var allOutgoing = true
|
||||||
|
for (message in messages) {
|
||||||
|
if (!message.isOutgoing) {
|
||||||
|
allOutgoing = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val notifiable = getNotifiableForRoom(room)
|
||||||
|
val updated = updateChatNotifiableWithMessages(notifiable, room, messages)
|
||||||
|
if (!updated) {
|
||||||
|
Log.w(
|
||||||
|
"[Notifications Manager] No changes made to notifiable, do not display it again"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (notifiable.messages.isNotEmpty()) {
|
if (notifiable.messages.isNotEmpty()) {
|
||||||
displayChatNotifiable(room, notifiable)
|
displayChatNotifiable(room, notifiable)
|
||||||
} else {
|
} else {
|
||||||
|
@ -794,14 +810,18 @@ class NotificationsManager(private val context: Context) {
|
||||||
notify(notifiable.notificationId, notification, CHAT_TAG)
|
notify(notifiable.notificationId, notification, CHAT_TAG)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createChatNotifiable(room: ChatRoom, messages: Array<out ChatMessage>): Notifiable {
|
private fun updateChatNotifiableWithMessages(
|
||||||
val notifiable = getNotifiableForRoom(room)
|
notifiable: Notifiable,
|
||||||
|
room: ChatRoom,
|
||||||
|
messages: Array<out ChatMessage>
|
||||||
|
): Boolean {
|
||||||
|
var updated = false
|
||||||
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)
|
val notifiableMessage = getNotifiableMessage(message, friend)
|
||||||
notifiable.messages.add(notifiableMessage)
|
notifiable.messages.add(notifiableMessage)
|
||||||
|
updated = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (room.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
|
if (room.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
|
||||||
|
@ -810,8 +830,7 @@ class NotificationsManager(private val context: Context) {
|
||||||
notifiable.isGroup = true
|
notifiable.isGroup = true
|
||||||
notifiable.groupTitle = room.subject
|
notifiable.groupTitle = room.subject
|
||||||
}
|
}
|
||||||
|
return updated
|
||||||
return notifiable
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getNotifiableForRoom(room: ChatRoom): Notifiable {
|
private fun getNotifiableForRoom(room: ChatRoom): Notifiable {
|
||||||
|
|
Loading…
Reference in a new issue