Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ val step3 = MigrationStep(

val pushNotification = PushNotification(
id = notificationId,
credentialId = notificationData["credentialId"]?.jsonPrimitive?.content ?: "",
credentialId = notificationData["credentialId"]?.jsonPrimitive?.content
?: notificationData["mechanismUID"]?.jsonPrimitive?.content
?: "",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like we try to get credentialId first, if not exist we get the mechanismUID, any reason for this scenario? Do you see the legacy set the id either in this 2 attributes?

Similar for other attributes mapping, we try to find if data exist on one attribute, if not found try another, not sure if this is correct.

ttl = notificationData["ttl"]?.jsonPrimitive?.content?.toIntOrNull() ?: 120,
messageId = notificationData["messageId"]?.jsonPrimitive?.content ?: notificationId,
messageText = notificationData["messageText"]?.jsonPrimitive?.content
Expand Down Expand Up @@ -368,14 +370,30 @@ val step4 = MigrationStep(
try {
val tokenData = json.parseToJsonElement(tokenJson).jsonObject

val pushDeviceToken = PushDeviceToken(
id = tokenData["id"]?.jsonPrimitive?.content ?: "",
tokenId = tokenData["deviceToken"]?.jsonPrimitive?.content
?: tokenData["token"]?.jsonPrimitive?.content
?: tokenData["tokenId"]?.jsonPrimitive?.content
?: "",
createdAt = Date(tokenData["timeAdded"]?.jsonPrimitive?.content?.toLongOrNull() ?: System.currentTimeMillis()),
)
// Extract id if present, otherwise let PushDeviceToken generate a UUID
val tokenId = tokenData["id"]?.jsonPrimitive?.content

val pushDeviceToken = if (tokenId != null && tokenId.isNotBlank()) {
PushDeviceToken(
id = tokenId,
tokenId = tokenData["deviceToken"]?.jsonPrimitive?.content
?: tokenData["token"]?.jsonPrimitive?.content
?: tokenData["tokenId"]?.jsonPrimitive?.content
?: "",
createdAt = Date(tokenData["timeAdded"]?.jsonPrimitive?.content?.toLongOrNull()
?: System.currentTimeMillis()),
)
} else {
// Let PushDeviceToken generate a UUID for id (default parameter)
PushDeviceToken(
tokenId = tokenData["deviceToken"]?.jsonPrimitive?.content
?: tokenData["token"]?.jsonPrimitive?.content
?: tokenData["tokenId"]?.jsonPrimitive?.content
?: "",
createdAt = Date(tokenData["timeAdded"]?.jsonPrimitive?.content?.toLongOrNull()
?: System.currentTimeMillis()),
)
}

pushStorage.storePushDeviceToken(pushDeviceToken)
logger.i("Migrated device token successfully")
Expand Down
Loading