Skip to content

Commit

Permalink
fix: add sentAt field to each event (#438)
Browse files Browse the repository at this point in the history
fix: add sentAt field to each event (#438)
  • Loading branch information
itsdebs authored Jun 10, 2024
1 parent 0a3fc95 commit 6781895
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,7 @@ internal class DataUploadServiceImpl @JvmOverloads constructor(

currentConfiguration?.apply {
if (networkExecutor.isShutdown || networkExecutor.isTerminated) return
val batchBody = mapOf<String, Any>(
"sentAt" to RudderUtils.timeStamp, "batch" to data
).let {
if (extraInfo.isNullOrEmpty()) it else it + extraInfo //adding extra info data
}.let {
jsonAdapter.writeToJson(it, object : RudderTypeAdapter<Map<String, Any>>() {})
}
val batchBody = createBatchBody(data, extraInfo)
webService.get()?.post(
mapOf(
"Content-Type" to "application/json",
Expand All @@ -99,20 +93,14 @@ internal class DataUploadServiceImpl @JvmOverloads constructor(
}
}



override fun uploadSync(
data: List<Message>, extraInfo: Map<String, String>?
): HttpResponse<out Any>? {
if (_isPaused.get()) return null
return currentConfiguration?.let { config ->
val batchBody = mapOf<String, Any>(
"sentAt" to RudderUtils.timeStamp, "batch" to data
).let {
if (extraInfo.isNullOrEmpty()) it else it + extraInfo //adding extra info data
}.let {
config.jsonAdapter.writeToJson(
it,
object : RudderTypeAdapter<Map<String, Any>>() {})
}
val batchBody = config.createBatchBody(data, extraInfo)
webService.get()?.post(
mapOf(
"Content-Type" to "application/json",
Expand All @@ -122,7 +110,22 @@ internal class DataUploadServiceImpl @JvmOverloads constructor(
)?.get()
}
}

private fun Configuration.createBatchBody(
data: List<Message>,
extraInfo: Map<String, String>?
) : String?{
val sentAt = RudderUtils.timeStamp
return mapOf<String, Any>(
"sentAt" to sentAt, "batch" to data.map {
it.sentAt = sentAt
it
}
).let {
if (extraInfo.isNullOrEmpty()) it else it + extraInfo //adding extra info data
}.let {
jsonAdapter.writeToJson(it, object : RudderTypeAdapter<Map<String, Any>>() {})
}
}
override fun setup(analytics: Analytics) {
// No-op
}
Expand Down
9 changes: 9 additions & 0 deletions models/src/main/java/com/rudderstack/models/Message.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ sealed class Message(
@Json(name = "integrations")
var integrations: MessageIntegrations? = null

/**
* For internal usage. This variable will return null when called.
* Setting this variable will make no difference as this value will be overridden while
* syncing the data with server.
*/
@SerializedName("sentAt")
@JsonProperty("sentAt")
@Json(name = "sentAt")
var sentAt: String?= null
open fun copy(
context: MessageContext? = this.context,
anonymousId: String? = this.anonymousId,
Expand Down

0 comments on commit 6781895

Please sign in to comment.