Sync profiles messages are received from.
This commit is contained in:
@@ -354,7 +354,8 @@ abstract class NostrDao(
|
||||
|
||||
val musig2AggregatedPublicKey = giftWrapPayload.aggregateParticipantsPublicKeys()
|
||||
if (musig2AggregatedPublicKey != null) {
|
||||
val chatRoomId = musig2AggregatedPublicKey.value.toHex()
|
||||
val chatRoomId = musig2AggregatedPublicKey.publicKey.toHex()
|
||||
|
||||
logger.d("ChatRoomId: $chatRoomId")
|
||||
// Find or create chatRoom
|
||||
val localChatRoom = database.chatRoomDao().findChatRoomById(
|
||||
@@ -373,13 +374,48 @@ abstract class NostrDao(
|
||||
)
|
||||
|
||||
// Add participants...
|
||||
database.participantDao().upsert(
|
||||
giftWrapPayload.receiverPubKeys().map {
|
||||
Participant(
|
||||
participantPublicKey = it,
|
||||
chatRoomId = chatRoomId
|
||||
val participants = giftWrapPayload.participantPubKeys().map {
|
||||
Participant(
|
||||
participantPublicKey = it,
|
||||
chatRoomId = chatRoomId
|
||||
)
|
||||
}
|
||||
|
||||
// Sync missing participant profiles...
|
||||
participants.forEach { participant ->
|
||||
val giftWrapParticipantProfile = database.profileDao().getProfileByPublicKey(participant.participantPublicKey)
|
||||
|
||||
if (giftWrapParticipantProfile == null) {
|
||||
// Save a placeholder
|
||||
database.profileDao().insertPlaceholderProfile(
|
||||
Profile(
|
||||
displayName = "LOADING...",
|
||||
publicKey = participant.participantPublicKey,
|
||||
createdAt = GENESIS_AT,
|
||||
nostrEventId = nostrEvent.id, // Will get overwriting by sync,
|
||||
)
|
||||
)
|
||||
|
||||
val recommendRelayUrl = giftWrapMessage.receiverRelayHit
|
||||
|
||||
if (recommendRelayUrl != null) {
|
||||
if (profilePublicKeysToSync[recommendRelayUrl] == null) {
|
||||
profilePublicKeysToSync[recommendRelayUrl] = mutableSetOf()
|
||||
}
|
||||
profilePublicKeysToSync[recommendRelayUrl]?.add(participant.participantPublicKey)
|
||||
} else {
|
||||
if (profilePublicKeysToSync[relayURL] == null) {
|
||||
profilePublicKeysToSync[relayURL] = mutableSetOf()
|
||||
}
|
||||
profilePublicKeysToSync[relayURL]?.add(
|
||||
participant.participantPublicKey
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
database.participantDao().upsert(
|
||||
participants
|
||||
)
|
||||
} else {
|
||||
giftWrapPayload.parseSubject()?.let { subject ->
|
||||
|
||||
@@ -34,9 +34,14 @@ abstract class NostrNip17Dao(
|
||||
logger.d("hexKeys: $hexKeys")
|
||||
|
||||
val publicKeys = hexKeys.map {
|
||||
PublicKey(
|
||||
val publicKey = PublicKey(
|
||||
PublicKey.compress(it.hexToByteArray())
|
||||
)
|
||||
if (publicKey.isValid().not()) {
|
||||
logger.w("$it is an invalid pubkey: $publicKey")
|
||||
}
|
||||
|
||||
publicKey
|
||||
}
|
||||
logger.d("PublicKeys: $publicKeys")
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import ac.cord.auxiliary.compose.database.model.traits.TimestampedEntity
|
||||
import ac.cord.auxiliary.compose.database.model.traits.UserViewableEntity
|
||||
import androidx.room3.Entity
|
||||
import androidx.room3.ForeignKey
|
||||
import androidx.room3.Ignore
|
||||
import androidx.room3.PrimaryKey
|
||||
import co.touchlab.kermit.Logger
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
@@ -78,20 +79,24 @@ data class GiftWrapPayload( // TODO: Rename this to GiftWrapPayload...
|
||||
override val viewedAt: Instant? = null,
|
||||
override val deletedAt: Instant? = null, // Who this message should be seen by (used to derive conversationId)
|
||||
): TimestampedEntity, LocalStoreEntity, UserViewableEntity, SoftDeletableEntity {
|
||||
val logger = Logger.withTag(TAG)
|
||||
@Ignore
|
||||
private val logger = Logger.withTag(TAG)
|
||||
|
||||
fun aggregateParticipantsPublicKeys(): XonlyPublicKey? = try {
|
||||
logger.d("aggregateParticipantsPublicKeys")
|
||||
val hexKeys = tags.taggedUsers().map {
|
||||
it.pubKey
|
||||
}
|
||||
|
||||
val hexKeys = participantPubKeys()
|
||||
|
||||
logger.d("HexKeys: $hexKeys")
|
||||
val publicKeys = hexKeys.map {
|
||||
PublicKey(
|
||||
val publicKey = PublicKey(
|
||||
PublicKey.compress(it.hexToByteArray())
|
||||
)
|
||||
|
||||
logger.d("$publicKey: ${publicKey.isValid()}")
|
||||
publicKey
|
||||
}
|
||||
|
||||
logger.d("PublicKeys: $publicKeys")
|
||||
|
||||
val chatRoomXOnlyPublicKey = Musig2.aggregateKeys(
|
||||
@@ -105,12 +110,19 @@ data class GiftWrapPayload( // TODO: Rename this to GiftWrapPayload...
|
||||
return null
|
||||
}
|
||||
|
||||
fun receiverPubKeys(): List<HexKey> = try {
|
||||
tags.taggedUsers().map {
|
||||
it.pubKey
|
||||
}
|
||||
fun participantPubKeys(): Set<HexKey> = try {
|
||||
val hexKeys = mutableSetOf(
|
||||
publicKey
|
||||
)
|
||||
hexKeys.addAll(
|
||||
tags.taggedUsers().map {
|
||||
it.pubKey
|
||||
}
|
||||
)
|
||||
|
||||
return hexKeys
|
||||
} catch (e: Throwable) {
|
||||
return emptyList()
|
||||
return emptySet()
|
||||
}
|
||||
|
||||
fun parseSubject(): String? {
|
||||
|
||||
Reference in New Issue
Block a user