diff --git a/app/src/main/java/com/koalasat/pokey/models/EncryptedStorage.kt b/app/src/main/java/com/koalasat/pokey/models/EncryptedStorage.kt index e499e05..26552ee 100644 --- a/app/src/main/java/com/koalasat/pokey/models/EncryptedStorage.kt +++ b/app/src/main/java/com/koalasat/pokey/models/EncryptedStorage.kt @@ -32,6 +32,8 @@ object EncryptedStorage { EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM, ) as EncryptedSharedPreferences + + _pubKey.value = sharedPreferences.getString(PrefKeys.NOSTR_PUBKEY, "").toString() } fun updatePubKey(newValue: String) { diff --git a/app/src/main/java/com/koalasat/pokey/service/NotificationsService.kt b/app/src/main/java/com/koalasat/pokey/service/NotificationsService.kt index 3897a90..af05103 100644 --- a/app/src/main/java/com/koalasat/pokey/service/NotificationsService.kt +++ b/app/src/main/java/com/koalasat/pokey/service/NotificationsService.kt @@ -55,7 +55,6 @@ class NotificationsService : Service() { "wss://relay.nsec.app", "wss://relay.0xchat.com", ) - private var useDefaultRelays = false private val timer = Timer() private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob()) @@ -200,13 +199,7 @@ class NotificationsService : Service() { var latestNotification = dao.getLatestNotification() if (latestNotification == null) latestNotification = Instant.now().toEpochMilli() / 1000 - var relays = dao.getRelays() - if (relays.isEmpty()) { - relays = defaultRelayUrls.map { RelayEntity(id = 0, url = it, kind = 0, createdAt = 0) } - useDefaultRelays = true - } - connectRelays(relays) - + connectRelays() Client.sendFilter( subscriptionNotificationId, listOf( @@ -303,14 +296,13 @@ class NotificationsService : Service() { if (lastCreatedRelayAt == null || lastCreatedRelayAt < event.createdAt) { stopSubscription() dao.deleteRelaysByKind(event.kind) - val relays = event.tags + event.tags .filter { it.size > 1 && (it[0] == "relay" || it[0] == "r") } .map { val entity = RelayEntity(id = 0, url = it[1], kind = event.kind, createdAt = event.createdAt) dao.insertRelay(entity) entity } - connectRelays(relays) startSubscription() } } @@ -412,25 +404,24 @@ class NotificationsService : Service() { return hexKey } - private fun connectRelays(relays: List) { - Log.d("Pokey", relays.toString()) - if (useDefaultRelays) { - RelayPool.unloadRelays() - useDefaultRelays = false + private fun connectRelays() { + RelayPool.unloadRelays() + val dao = AppDatabase.getDatabase(this@NotificationsService, getHexKey()).applicationDao() + var relays = dao.getRelays() + if (relays.isEmpty()) { + relays = defaultRelayUrls.map { RelayEntity(id = 0, url = it, kind = 0, createdAt = 0) } } relays.forEach { - if (RelayPool.getRelays(it.url).isEmpty()) { - Client.sendFilterOnlyIfDisconnected() - RelayPool.addRelay( - Relay( - it.url, - read = true, - write = false, - forceProxy = false, - activeTypes = COMMON_FEED_TYPES, - ), - ) - } + Client.sendFilterOnlyIfDisconnected() + RelayPool.addRelay( + Relay( + it.url, + read = true, + write = false, + forceProxy = false, + activeTypes = COMMON_FEED_TYPES, + ), + ) } } } diff --git a/zapstore.yaml b/zapstore.yaml index 65b0b81..af6dc61 100644 --- a/zapstore.yaml +++ b/zapstore.yaml @@ -6,4 +6,4 @@ pokey: repository: https://github.com/koalasat/pokey license: MIT artifacts: - - ./app/build/outputs/apk/release/pokey-universal-v%v.apk + - ./app/build/outputs/apk/release/pokey-universal-v%v-alpha.apk