Skip to content

Commit

Permalink
Merge pull request #23 from KoalaSat/broadcast-evetns
Browse files Browse the repository at this point in the history
Broadcast events
  • Loading branch information
KoalaSat authored Nov 2, 2024
2 parents ea583d5 + 89540c4 commit fd14b94
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class NotificationsService : Service() {
private var broadcastIntentName = "com.shared.NOSTR"
private var channelRelaysId = "RelaysConnections"
private var channelNotificationsId = "Notifications"

Expand Down Expand Up @@ -85,7 +86,15 @@ class NotificationsService : Service() {
) {
if (processedEvents.putIfAbsent(event.id, true) == null) {
Log.d("Pokey", "Relay Event: ${relay.url} - $subscriptionId - ${event.toJson()}")

val hexKey = Pokey.getInstance().getHexKey()
if (event.pubKey == hexKey || !event.taggedUsers().contains(hexKey)) return

createNoteNotification(event)

val intent = Intent(broadcastIntentName)
intent.putExtra("EVENT", event.toJson())
sendBroadcast(intent)
}
}

Expand Down Expand Up @@ -326,11 +335,8 @@ class NotificationsService : Service() {
}

private fun createNoteNotification(event: Event) {
val hexKey = Pokey.getInstance().getHexKey()
if (event.pubKey == hexKey || !event.taggedUsers().contains(hexKey)) return

CoroutineScope(Dispatchers.IO).launch {
val dao = AppDatabase.getDatabase(this@NotificationsService, hexKey).applicationDao()
val dao = AppDatabase.getDatabase(this@NotificationsService, Pokey.getInstance().getHexKey()).applicationDao()
val existsEvent = dao.existsNotification(event.id)
if (existsEvent > 0) return@launch

Expand Down

0 comments on commit fd14b94

Please sign in to comment.