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 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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 +34,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 39 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#L37-L39

Added lines #L37 - L39 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 43 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#L42-L43

Added lines #L42 - L43 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 50 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#L48-L50

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

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

response
}
.build()

Check warning on line 99 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#L99

Added line #L99 was not covered by tests

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

internal fun fetchUserMessages() {
GlobalScope.launch {

Check warning on line 118 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 118 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 118 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 118 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 118 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 118 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 118 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 118 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 118 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 118 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 +142,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 146 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#L146

Added line #L146 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