diff --git a/messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt b/messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt index 6dcc9ad8f..2e821cc41 100644 --- a/messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt +++ b/messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt @@ -143,7 +143,9 @@ class Queue : GistListener { } private fun handleMessages(messages: List) { - for (message in messages) { + // Sorting messages by priority and placing nulls last. + val sortedMessages = messages.sortedWith(compareBy(nullsLast()) { it.priority }) + for (message in sortedMessages) { processMessage(message) } } diff --git a/messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/model/Message.kt b/messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/model/Message.kt index 9f3c1dda2..084074283 100644 --- a/messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/model/Message.kt +++ b/messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/model/Message.kt @@ -18,6 +18,7 @@ data class GistProperties( data class Message( val messageId: String = "", val instanceId: String = UUID.randomUUID().toString(), + val priority: Int? = null, val queueId: String? = null, val properties: Map? = null )