Revert "Ignore unknown fields in push V2 json"

This commit is contained in:
Andrew 2023-09-22 10:03:55 +09:30 committed by GitHub
parent e124d442ef
commit 6824b18adc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,7 +10,6 @@ import com.goterl.lazysodium.utils.Key
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.serialization.decodeFromString import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonBuilder
import org.session.libsession.messaging.jobs.BatchMessageReceiveJob import org.session.libsession.messaging.jobs.BatchMessageReceiveJob
import org.session.libsession.messaging.jobs.JobQueue import org.session.libsession.messaging.jobs.JobQueue
import org.session.libsession.messaging.jobs.MessageReceiveParameters import org.session.libsession.messaging.jobs.MessageReceiveParameters
@ -29,7 +28,6 @@ private const val TAG = "PushHandler"
class PushReceiver @Inject constructor(@ApplicationContext val context: Context) { class PushReceiver @Inject constructor(@ApplicationContext val context: Context) {
private val sodium = LazySodiumAndroid(SodiumAndroid()) private val sodium = LazySodiumAndroid(SodiumAndroid())
private val json = Json { ignoreUnknownKeys = true }
fun onPush(dataMap: Map<String, String>?) { fun onPush(dataMap: Map<String, String>?) {
onPush(dataMap?.asByteArray()) onPush(dataMap?.asByteArray())
@ -91,7 +89,7 @@ class PushReceiver @Inject constructor(@ApplicationContext val context: Context)
?: error("Failed to decode bencoded list from payload") ?: error("Failed to decode bencoded list from payload")
val metadataJson = (expectedList[0] as? BencodeString)?.value ?: error("no metadata") 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 { return (expectedList.getOrNull(1) as? BencodeString)?.value.also {
// null content is valid only if we got a "data_too_long" flag // null content is valid only if we got a "data_too_long" flag