Skip to content

Commit

Permalink
fix again
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaSat committed Nov 14, 2024
1 parent 90b6d93 commit 80bf03b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/koalasat/pokey/models/NostrClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ object NostrClient {

fun checkRelaysHealth(context: Context) {
if (RelayPool.getAll().isEmpty()) {
stop()
start(context)
}
RelayPool.getAll().forEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.vitorpamplona.quartz.encoders.toNote
import com.vitorpamplona.quartz.encoders.toNpub
import com.vitorpamplona.quartz.events.Event
import com.vitorpamplona.quartz.events.EventInterface
import com.vitorpamplona.quartz.utils.TimeUtils
import java.util.Timer
import java.util.TimerTask
import java.util.concurrent.ConcurrentHashMap
Expand All @@ -47,14 +48,21 @@ class NotificationsService : Service() {
private val timer = Timer()
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
private val processedEvents = ConcurrentHashMap<String, Boolean>()
private val authRelays = ConcurrentHashMap<String, Long>()

private val clientNotificationListener =
object : Client.Listener {
override fun onAuth(relay: Relay, challenge: String) {
Log.d("Pokey", "Relay on Auth: ${relay.url} : $challenge")
ExternalSigner.auth(relay.url, challenge) { result ->
Log.d("Pokey", "Relay on Auth response: ${relay.url} : ${result.toJson()}")
relay.send(result)
val currentTime = TimeUtils.now()
val fiveMinutesInMillis = 5 * 60 * 1000
val existingTimestamp = authRelays[relay.url]
if (existingTimestamp == null || (currentTime - existingTimestamp > fiveMinutesInMillis)) {
ExternalSigner.auth(relay.url, challenge) { result ->
Log.d("Pokey", "Relay on Auth response: ${relay.url} : ${result.toJson()}")
relay.send(result)
authRelays.putIfAbsent(relay.url, TimeUtils.now())
}
}
}

Expand Down

0 comments on commit 80bf03b

Please sign in to comment.