Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add priority field to message and sorting by priority within local store #276

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions messaginginapp/api/messaginginapp.api
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,19 @@ public final class io/customer/messaginginapp/gist/data/model/LogEvent {

public final class io/customer/messaginginapp/gist/data/model/Message {
public fun <init> ()V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/util/Map;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Ljava/lang/String;
public final fun component4 ()Ljava/util/Map;
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;)Lio/customer/messaginginapp/gist/data/model/Message;
public static synthetic fun copy$default (Lio/customer/messaginginapp/gist/data/model/Message;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;ILjava/lang/Object;)Lio/customer/messaginginapp/gist/data/model/Message;
public final fun component3 ()Ljava/lang/Integer;
public final fun component4 ()Ljava/lang/String;
public final fun component5 ()Ljava/util/Map;
public final fun copy (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/util/Map;)Lio/customer/messaginginapp/gist/data/model/Message;
public static synthetic fun copy$default (Lio/customer/messaginginapp/gist/data/model/Message;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/String;Ljava/util/Map;ILjava/lang/Object;)Lio/customer/messaginginapp/gist/data/model/Message;
public fun equals (Ljava/lang/Object;)Z
public final fun getInstanceId ()Ljava/lang/String;
public final fun getMessageId ()Ljava/lang/String;
public final fun getPriority ()Ljava/lang/Integer;
public final fun getProperties ()Ljava/util/Map;
public final fun getQueueId ()Ljava/lang/String;
public fun hashCode ()I
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import okhttp3.Cache
import okhttp3.OkHttpClient
import okhttp3.Response
import okhttp3.ResponseBody.Companion.toResponseBody
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

class Queue : GistListener {

private var localMessageStore: MutableList<Message> = mutableListOf()
private val cacheMap = mutableMapOf<String, Response>()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shahroz16 just to confirm, this is not needed right?

Copy link
Contributor

@Shahroz16 Shahroz16 Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BernardGatt yes!! thank you for removing it.


init {
GistSdk.addListener(this)
Expand Down Expand Up @@ -143,7 +141,9 @@ class Queue : GistListener {
}

private fun handleMessages(messages: List<Message>) {
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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Any?>? = null
)
Expand Down