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.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 All @@ -35,20 +33,20 @@
private val cache by lazy { Cache(cacheDirectory, cacheSize.toLong()) }

private fun saveToPrefs(context: Context, key: String, value: String) {
val prefs = context.getSharedPreferences("network_cache", Context.MODE_PRIVATE)
prefs.edit().putString(key, value).apply()
}

Check warning on line 38 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt#L36-L38

Added lines #L36 - L38 were not covered by tests

private fun getFromPrefs(context: Context, key: String): String? {
val prefs = context.getSharedPreferences("network_cache", Context.MODE_PRIVATE)
return prefs.getString(key, null)

Check warning on line 42 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt#L41-L42

Added lines #L41 - L42 were not covered by tests
}

private val gistQueueService by lazy {
// Interceptor to set up request headers like site ID, data center, and user token.
val httpClient: OkHttpClient =
OkHttpClient.Builder().cache(cache)
.addInterceptor { chain ->

Check warning on line 49 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt#L47-L49

Added lines #L47 - L49 were not covered by tests
val originalRequest = chain.request()

val networkRequest = originalRequest.newBuilder()
Expand Down Expand Up @@ -97,7 +95,7 @@

response
}
.build()

Check warning on line 98 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt#L98

Added line #L98 was not covered by tests

Retrofit.Builder()
.baseUrl(GistSdk.gistEnvironment.getGistQueueApiUrl())
Expand All @@ -116,7 +114,7 @@
}

internal fun fetchUserMessages() {
GlobalScope.launch {

Check warning on line 117 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt

View workflow job for this annotation

GitHub Actions / Android Lint (messaginginapp)

This is a delicate API and its use requires care. Make sure you fully read and understand documentation of the declaration that is marked as a delicate API.

Check warning on line 117 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt

View workflow job for this annotation

GitHub Actions / API check

This is a delicate API and its use requires care. Make sure you fully read and understand documentation of the declaration that is marked as a delicate API.

Check warning on line 117 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt

View workflow job for this annotation

GitHub Actions / Unit tests (messaginginapp)

This is a delicate API and its use requires care. Make sure you fully read and understand documentation of the declaration that is marked as a delicate API.

Check warning on line 117 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt

View workflow job for this annotation

GitHub Actions / API check

This is a delicate API and its use requires care. Make sure you fully read and understand documentation of the declaration that is marked as a delicate API.

Check warning on line 117 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt

View workflow job for this annotation

GitHub Actions / Android Lint (messaginginapp)

This is a delicate API and its use requires care. Make sure you fully read and understand documentation of the declaration that is marked as a delicate API.

Check warning on line 117 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt

View workflow job for this annotation

GitHub Actions / Unit tests (messaginginapp)

This is a delicate API and its use requires care. Make sure you fully read and understand documentation of the declaration that is marked as a delicate API.

Check warning on line 117 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt

View workflow job for this annotation

GitHub Actions / instrumentation-test (java_layout)

This is a delicate API and its use requires care. Make sure you fully read and understand documentation of the declaration that is marked as a delicate API.

Check warning on line 117 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt

View workflow job for this annotation

GitHub Actions / instrumentation-test (java_layout)

This is a delicate API and its use requires care. Make sure you fully read and understand documentation of the declaration that is marked as a delicate API.

Check warning on line 117 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt

View workflow job for this annotation

GitHub Actions / instrumentation-test (kotlin_compose)

This is a delicate API and its use requires care. Make sure you fully read and understand documentation of the declaration that is marked as a delicate API.

Check warning on line 117 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt

View workflow job for this annotation

GitHub Actions / instrumentation-test (kotlin_compose)

This is a delicate API and its use requires care. Make sure you fully read and understand documentation of the declaration that is marked as a delicate API.
try {
Log.i(GIST_TAG, "Fetching user messages")
val latestMessagesResponse = gistQueueService.fetchMessagesForUser()
Expand All @@ -143,7 +141,9 @@
}

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 })

Check warning on line 145 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/data/listeners/Queue.kt#L145

Added line #L145 was not covered by tests
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
Loading