Skip to content

Commit

Permalink
Clean up the PushManager (#1462)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-livefront authored and vvolkgang committed Jun 20, 2024
1 parent 2f2d371 commit 3c03592
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.x8bit.bitwarden.data.platform.manager.model.SyncFolderUpsertData
import com.x8bit.bitwarden.data.platform.manager.model.SyncSendDeleteData
import com.x8bit.bitwarden.data.platform.manager.model.SyncSendUpsertData
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.data.platform.util.decodeFromStringOrNull
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
Expand Down Expand Up @@ -107,23 +108,15 @@ class PushManagerImpl @Inject constructor(
}

override fun onMessageReceived(data: String) {
val notification = try {
json.decodeFromString<BitwardenNotification>(data)
} catch (exception: IllegalArgumentException) {
return
}
val notification = json.decodeFromStringOrNull<BitwardenNotification>(data) ?: return
onMessageReceived(notification)
}

@Suppress("ReturnCount")
override fun onMessageReceived(data: Map<String, String>) {
val type = data["type"] ?: return
val notificationType = data["type"]
?.let { json.decodeFromStringOrNull<NotificationType>(string = it) }
?: return
val payload = data["payload"] ?: return
val notificationType = try {
json.decodeFromString<NotificationType>(string = type)
} catch (exception: IllegalArgumentException) {
return
}
val notification = BitwardenNotification(
contextId = data["contextId"],
notificationType = notificationType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ inline fun <reified T> Json.decodeFromStringOrNull(
decodeFromString(string = string)
} catch (e: SerializationException) {
null
} catch (e: IllegalStateException) {
} catch (e: IllegalArgumentException) {
null
}
Loading

0 comments on commit 3c03592

Please sign in to comment.