Update NotificationPayload to handle null values (#3391)

This commit is contained in:
David Perez 2024-07-01 17:01:07 -05:00 committed by GitHub
parent 44e2596a30
commit f5039d72b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 6 deletions

View file

@ -153,7 +153,14 @@ class PushManagerImpl @Inject constructor(
-> {
val payload: NotificationPayload.SyncCipherNotification =
json.decodeFromString(notification.payload)
if (!isLoggedIn(userId) || !payload.userMatchesNotification(userId)) return
@Suppress("ComplexCondition")
if (payload.id == null ||
payload.revisionDate == null ||
!isLoggedIn(userId) ||
!payload.userMatchesNotification(userId)
) {
return
}
mutableSyncCipherUpsertSharedFlow.tryEmit(
SyncCipherUpsertData(
cipherId = payload.id,
@ -170,7 +177,12 @@ class PushManagerImpl @Inject constructor(
-> {
val payload: NotificationPayload.SyncCipherNotification =
json.decodeFromString(notification.payload)
if (!isLoggedIn(userId) || !payload.userMatchesNotification(userId)) return
if (payload.id == null ||
!isLoggedIn(userId) ||
!payload.userMatchesNotification(userId)
) {
return
}
mutableSyncCipherDeleteSharedFlow.tryEmit(
SyncCipherDeleteData(payload.id),
)
@ -291,8 +303,8 @@ class PushManagerImpl @Inject constructor(
.fold(
onSuccess = {
pushDiskSource.storeLastPushTokenRegistrationDate(
userId,
ZonedDateTime.ofInstant(clock.instant(), ZoneOffset.UTC),
userId = userId,
registrationDate = ZonedDateTime.ofInstant(clock.instant(), ZoneOffset.UTC),
)
pushDiskSource.storeCurrentPushToken(
userId = userId,

View file

@ -20,12 +20,12 @@ sealed class NotificationPayload {
*/
@Serializable
data class SyncCipherNotification(
@SerialName("Id") val id: String,
@SerialName("Id") val id: String?,
@SerialName("UserId") override val userId: String?,
@SerialName("OrganizationId") val organizationId: String?,
@SerialName("CollectionIds") val collectionIds: List<String>?,
@Contextual
@SerialName("RevisionDate") val revisionDate: ZonedDateTime,
@SerialName("RevisionDate") val revisionDate: ZonedDateTime?,
) : NotificationPayload()
/**