check if is using secret and if application is not connected already

This commit is contained in:
greenart7c3
2024-07-22 08:56:59 -03:00
parent a3e4ad4cd0
commit 87dfbcb213
@@ -206,12 +206,21 @@ class EventNotificationConsumer(private val applicationContext: Context) {
if (secret.isNotBlank()) { if (secret.isNotBlank()) {
bunkerRequest.secret = secret bunkerRequest.secret = secret
applicationWithSecret = database.applicationDao().getBySecret(secret) applicationWithSecret = database.applicationDao().getBySecret(secret)
if (applicationWithSecret == null || secret.isBlank()) { if (applicationWithSecret == null || secret.isBlank() || applicationWithSecret.application.isConnected || !applicationWithSecret.application.useSecret) {
val message = if (applicationWithSecret == null) {
"invalid secret"
} else if (secret.isBlank()) {
"no secret"
} else if (applicationWithSecret.application.isConnected) {
"already connected"
} else {
"secret not in use"
}
IntentUtils.sendBunkerResponse( IntentUtils.sendBunkerResponse(
applicationContext, applicationContext,
acc, acc,
bunkerRequest, bunkerRequest,
BunkerResponse(bunkerRequest.id, "", "invalid secret"), BunkerResponse(bunkerRequest.id, "", message),
applicationWithSecret?.application?.relays ?: listOf(), applicationWithSecret?.application?.relays ?: listOf(),
onLoading = { }, onLoading = { },
onDone = { }, onDone = { },