From 0cd0ac9c754666b670a0e9261c33ef48a9797183 Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 21 Sep 2023 19:44:54 +0930 Subject: [PATCH] Ignore unknown fields in push V2 json --- .../org/thoughtcrime/securesms/notifications/PushReceiver.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/PushReceiver.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/PushReceiver.kt index 3982113985..7fb9c12ab4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/PushReceiver.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/PushReceiver.kt @@ -10,6 +10,7 @@ import com.goterl.lazysodium.utils.Key import dagger.hilt.android.qualifiers.ApplicationContext import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonBuilder import org.session.libsession.messaging.jobs.BatchMessageReceiveJob import org.session.libsession.messaging.jobs.JobQueue import org.session.libsession.messaging.jobs.MessageReceiveParameters @@ -28,6 +29,7 @@ private const val TAG = "PushHandler" class PushReceiver @Inject constructor(@ApplicationContext val context: Context) { private val sodium = LazySodiumAndroid(SodiumAndroid()) + private val json = Json { ignoreUnknownKeys = true } fun onPush(dataMap: Map?) { onPush(dataMap?.asByteArray()) @@ -89,7 +91,7 @@ class PushReceiver @Inject constructor(@ApplicationContext val context: Context) ?: error("Failed to decode bencoded list from payload") val metadataJson = (expectedList[0] as? BencodeString)?.value ?: error("no metadata") - val metadata: PushNotificationMetadata = Json.decodeFromString(String(metadataJson)) + val metadata: PushNotificationMetadata = json.decodeFromString(String(metadataJson)) return (expectedList.getOrNull(1) as? BencodeString)?.value.also { // null content is valid only if we got a "data_too_long" flag