Broadcast nostr DM

This commit is contained in:
Kgothatso Ngako committed 2026-06-03 01:37:15 +02:00
1 parent 1ab17510cf
commit 22800bdabb
2 files changed
+41 -11

No files matched your search

@@ -24,6 +24,7 @@ import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
import com.vitorpamplona.quartz.nip01Core.tags.events.taggedEvents import com.vitorpamplona.quartz.nip01Core.tags.events.taggedEvents
import com.vitorpamplona.quartz.nip01Core.tags.people.taggedUsers import com.vitorpamplona.quartz.nip01Core.tags.people.taggedUsers
import com.vitorpamplona.quartz.nip02FollowList.ContactListEvent import com.vitorpamplona.quartz.nip02FollowList.ContactListEvent
import com.vitorpamplona.quartz.nip17Dm.settings.ChatMessageRelayListEvent
import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent
import kotlin.time.Clock import kotlin.time.Clock
import kotlin.time.Instant import kotlin.time.Instant
@@ -37,8 +38,8 @@ abstract class NostrDao(
val profileEventKinds = arrayOf( val profileEventKinds = arrayOf(
MetadataEvent.KIND, MetadataEvent.KIND,
ContactListEvent.KIND, ContactListEvent.KIND,
ChatMessageRelayListEvent.KIND,
// AdvertisedRelayListEvent.KIND, // AdvertisedRelayListEvent.KIND,
// ChatMessageRelayListEvent.KIND,
// SearchRelayListEvent.KIND, // SearchRelayListEvent.KIND,
// IndexerRelayListEvent.KIND, // IndexerRelayListEvent.KIND,
// ChannelListEvent.KIND, // ChannelListEvent.KIND,
@@ -1,6 +1,7 @@
package ac.cord.auxiliary.compose.database.dao package ac.cord.auxiliary.compose.database.dao
import ac.cord.auxiliary.compose.database.AuxDatabase import ac.cord.auxiliary.compose.database.AuxDatabase
import ac.cord.auxiliary.compose.database.GENESIS_AT
import ac.cord.auxiliary.compose.database.model.BroadcastNostrEventRequest import ac.cord.auxiliary.compose.database.model.BroadcastNostrEventRequest
import ac.cord.auxiliary.compose.database.model.ChatRoom import ac.cord.auxiliary.compose.database.model.ChatRoom
import ac.cord.auxiliary.compose.database.model.GiftWrapMessage import ac.cord.auxiliary.compose.database.model.GiftWrapMessage
@@ -17,6 +18,7 @@ import com.vitorpamplona.quartz.nip01Core.tags.people.PTag
import com.vitorpamplona.quartz.nip17Dm.settings.ChatMessageRelayListEvent import com.vitorpamplona.quartz.nip17Dm.settings.ChatMessageRelayListEvent
import com.vitorpamplona.quartz.nip59Giftwrap.seals.SealedRumorEvent import com.vitorpamplona.quartz.nip59Giftwrap.seals.SealedRumorEvent
import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent
import kotlin.math.log
import kotlin.time.Instant import kotlin.time.Instant
@@ -94,16 +96,43 @@ abstract class NostrNip17Dao(
database.nostrEventDao().insert(nostrEvent) database.nostrEventDao().insert(nostrEvent)
// TODO: Get ChatMessageRelayListEvent.KIND for receiverPublicKey.pubkey // TODO: Get ChatMessageRelayListEvent.KIND for receiverPublicKey.pubkey
// receiverPublicKey.relayHint?.url?.let { url -> val chatMessageRelayListEvents = database.nostrEventDao().getAuthoredNostrEvents(
// database.broadcastNostrEventRequestDao().insert( kinds = arrayOf(ChatMessageRelayListEvent.KIND),
// listOf( authors = arrayOf(
// BroadcastNostrEventRequest( receiverPublicKey.pubKey
// nostrEventId = nostrEvent.id, ),
// relayURL = url since = GENESIS_AT,
// ) limit = 5
// ) )
// ) logger.d("Found messageRelayLists: $chatMessageRelayListEvents")
// }
chatMessageRelayListEvents.firstOrNull()?.let { chatMessageRelayListNostrEvent ->
val chatMessageRelayListEvent = ChatMessageRelayListEvent(
id = chatMessageRelayListNostrEvent.id,
pubKey = chatMessageRelayListNostrEvent.pubKey,
tags = chatMessageRelayListNostrEvent.tags,
content = chatMessageRelayListNostrEvent.content,
sig = chatMessageRelayListNostrEvent.sig,
createdAt = chatMessageRelayListNostrEvent.createdAt.epochSeconds,
)
logger.d("Broadcast to ${chatMessageRelayListEvent.relays()}")
// TODO: Only broadcasting to the first 3 relays...
chatMessageRelayListEvent.relays().take(3).forEach { relayUrl ->
logger.d("Submit BroadcastNostrEventRequest to $relayUrl")
database.broadcastNostrEventRequestDao().insert(
listOf(
BroadcastNostrEventRequest(
nostrEventId = nostrEvent.id,
relayURL = relayUrl.url
)
)
)
}
}
database.giftWrapMessageDao().upsert( database.giftWrapMessageDao().upsert(