Avoid duplicated MessagingStyle notification text
This commit is contained in:
@@ -21,14 +21,25 @@ data class NotificationSnapshot(
|
|||||||
|
|
||||||
object NotificationContents {
|
object NotificationContents {
|
||||||
fun extract(notification: Notification): String? {
|
fun extract(notification: Notification): String? {
|
||||||
val parts = linkedSetOf<String>()
|
|
||||||
val extras = notification.extras ?: Bundle.EMPTY
|
val extras = notification.extras ?: Bundle.EMPTY
|
||||||
|
messagingContents(extras)?.let { return it }
|
||||||
|
|
||||||
|
val parts = linkedSetOf<String>()
|
||||||
extras.getCharSequence(Notification.EXTRA_TITLE)?.addTo(parts)
|
extras.getCharSequence(Notification.EXTRA_TITLE)?.addTo(parts)
|
||||||
extras.getCharSequence(Notification.EXTRA_TEXT)?.addTo(parts)
|
extras.getCharSequence(Notification.EXTRA_TEXT)?.addTo(parts)
|
||||||
extras.getCharSequence(Notification.EXTRA_BIG_TEXT)?.addTo(parts)
|
extras.getCharSequence(Notification.EXTRA_BIG_TEXT)?.addTo(parts)
|
||||||
extras.getCharSequence(Notification.EXTRA_SUB_TEXT)?.addTo(parts)
|
extras.getCharSequence(Notification.EXTRA_SUB_TEXT)?.addTo(parts)
|
||||||
extras.getCharSequence(Notification.EXTRA_SUMMARY_TEXT)?.addTo(parts)
|
extras.getCharSequence(Notification.EXTRA_SUMMARY_TEXT)?.addTo(parts)
|
||||||
extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES)?.forEach { it?.addTo(parts) }
|
extras.getCharSequenceArray(Notification.EXTRA_TEXT_LINES)?.forEach { it?.addTo(parts) }
|
||||||
|
return parts.takeIf { it.isNotEmpty() }?.joinToString(" — ")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MessagingStyle also fills generic title and text fields. Those fields commonly duplicate
|
||||||
|
* the newest structured message, so structured messages are the canonical representation.
|
||||||
|
*/
|
||||||
|
private fun messagingContents(extras: Bundle): String? {
|
||||||
|
val parts = linkedSetOf<String>()
|
||||||
Notification.MessagingStyle.Message.getMessagesFromBundleArray(
|
Notification.MessagingStyle.Message.getMessagesFromBundleArray(
|
||||||
extras.getParcelableArray(Notification.EXTRA_MESSAGES, Bundle::class.java),
|
extras.getParcelableArray(Notification.EXTRA_MESSAGES, Bundle::class.java),
|
||||||
).forEach { message ->
|
).forEach { message ->
|
||||||
|
|||||||
Reference in New Issue
Block a user