Log the giftwraps
This commit is contained in:
@@ -181,7 +181,7 @@ abstract class NostrDao(
|
||||
profilePublicKeysToSync[relayURL]?.add(nostrEvent.pubKey)
|
||||
}
|
||||
} else {
|
||||
logger.w("We somehow have an unsignedNostrEvent: $nostrEvent")
|
||||
logger.w("We somehow have an unsignedNostrEvent/giftwrap event: $nostrEvent")
|
||||
}
|
||||
|
||||
// Index reposts first because they have the contained posts...
|
||||
@@ -322,6 +322,7 @@ abstract class NostrDao(
|
||||
}
|
||||
|
||||
nostrEvent.toGiftWrapMessageWithReceiverPTag()?.let { giftWrapMessage ->
|
||||
logger.d("giftWrapMessage: $giftWrapMessage")
|
||||
val giftWrapReceiverProfile = database.profileDao().getProfileByPublicKey(giftWrapMessage.receiverPublicKey)
|
||||
|
||||
if (giftWrapReceiverProfile == null) {
|
||||
@@ -369,46 +370,50 @@ abstract class NostrDao(
|
||||
giftWrapSeal.decryptGiftWrapPayload(
|
||||
activeUserPrivateKey
|
||||
)?.let { giftWrapPayload ->
|
||||
|
||||
database.giftWrapUnsignedDao().upsert(
|
||||
giftWrapPayload
|
||||
)
|
||||
|
||||
val chatRoomId = Musig2.aggregateKeys(
|
||||
giftWrapPayload.receiverPublicKeys()
|
||||
).value.toHex()
|
||||
// Process chatMessage and chatRoom stuff...
|
||||
// Find or create chatRoom
|
||||
val chatRoom = database.chatRoomDao().findChatRoomById(
|
||||
chatRoomId
|
||||
)
|
||||
val receiverPublicKeys = giftWrapPayload.receiverPublicKeys()
|
||||
logger.d("receiverPublicKeys: $receiverPublicKeys")
|
||||
|
||||
if (chatRoom == null) {
|
||||
database.chatRoomDao().upsert(
|
||||
ChatRoom(
|
||||
id = chatRoomId,
|
||||
userPublicKey = SeedManager.activeKeyPair().pubKey.toHex(),
|
||||
subject = null, // TODO: Get subject from tags...
|
||||
if (receiverPublicKeys.isNotEmpty()) {
|
||||
val chatRoomId = Musig2.aggregateKeys(
|
||||
giftWrapPayload.receiverPublicKeys()
|
||||
).value.toHex()
|
||||
// Process chatMessage and chatRoom stuff...
|
||||
// Find or create chatRoom
|
||||
val chatRoom = database.chatRoomDao().findChatRoomById(
|
||||
chatRoomId
|
||||
)
|
||||
|
||||
if (chatRoom == null) {
|
||||
database.chatRoomDao().upsert(
|
||||
ChatRoom(
|
||||
id = chatRoomId,
|
||||
userPublicKey = SeedManager.activeKeyPair().pubKey.toHex(),
|
||||
subject = null, // TODO: Get subject from tags...
|
||||
createdAt = giftWrapPayload.createdAt,
|
||||
initialGiftWrapUnsignedId = giftWrapPayload.id
|
||||
)
|
||||
)
|
||||
} else {
|
||||
// TODO: Update subject from tags...
|
||||
}
|
||||
|
||||
// Save chatMessage
|
||||
database.chatMessageDao().upsert(
|
||||
ChatMessage(
|
||||
id = giftWrapPayload.id,
|
||||
senderPublicKey = giftWrapPayload.publicKey,
|
||||
isUserMessage = SeedManager.activePublicKey().toHex() == giftWrapPayload.publicKey,
|
||||
chatRoomId = chatRoomId,
|
||||
createdAt = giftWrapPayload.createdAt,
|
||||
initialGiftWrapUnsignedId = giftWrapPayload.id
|
||||
content = giftWrapPayload.content,
|
||||
)
|
||||
)
|
||||
} else {
|
||||
// TODO: Update subject from tags...
|
||||
}
|
||||
|
||||
// Save chatMessage
|
||||
database.chatMessageDao().upsert(
|
||||
ChatMessage(
|
||||
id = giftWrapPayload.id,
|
||||
senderPublicKey = giftWrapPayload.publicKey,
|
||||
isUserMessage = SeedManager.activePublicKey().toHex() == giftWrapPayload.publicKey,
|
||||
chatRoomId = chatRoomId,
|
||||
createdAt = giftWrapPayload.createdAt,
|
||||
content = giftWrapPayload.content,
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,12 @@ import ac.cord.auxiliary.compose.database.model.traits.NostrEventEntity
|
||||
import ac.cord.auxiliary.compose.database.model.traits.SoftDeletableEntity
|
||||
import ac.cord.auxiliary.compose.database.model.traits.TimestampedEntity
|
||||
import ac.cord.auxiliary.compose.database.model.traits.UserViewableEntity
|
||||
import ac.cord.auxiliary.compose.network.serialization.encodeToJsonString
|
||||
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
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Kind
|
||||
import com.vitorpamplona.quartz.nip01Core.core.TagArray
|
||||
@@ -80,6 +83,9 @@ data class GiftWrapMessage(
|
||||
override val deletedAt: Instant? = null, // Who this message should be seen by (used to derive conversationId)
|
||||
): NostrEventEntity, TimestampedEntity, LocalStoreEntity, UserViewableEntity, SoftDeletableEntity {
|
||||
|
||||
@Ignore
|
||||
private val logger = Logger.withTag("GiftWrapMessage")
|
||||
|
||||
suspend fun decryptGiftWrapSeal(
|
||||
privateKey: ByteArray
|
||||
): GiftWrapSeal? {
|
||||
@@ -97,6 +103,7 @@ data class GiftWrapMessage(
|
||||
content = content,
|
||||
sig = signature
|
||||
)
|
||||
logger.d("giftWrapEvent: ${giftWrapEvent.toJson()}")
|
||||
|
||||
val nostrSigner = NostrSignerInternal(
|
||||
keyPair = KeyPair(privKey = privateKey)
|
||||
@@ -105,6 +112,8 @@ data class GiftWrapMessage(
|
||||
giftWrapEvent.unwrapOrNull(
|
||||
nostrSigner
|
||||
)?.let { giftWrapSeal ->
|
||||
|
||||
logger.d("giftWrapSeal: ${giftWrapSeal.toJson()}")
|
||||
return GiftWrapSeal(
|
||||
id = giftWrapSeal.id,
|
||||
publicKey = giftWrapSeal.pubKey,
|
||||
|
||||
@@ -4,9 +4,12 @@ import ac.cord.auxiliary.compose.database.model.traits.LocalStoreEntity
|
||||
import ac.cord.auxiliary.compose.database.model.traits.SoftDeletableEntity
|
||||
import ac.cord.auxiliary.compose.database.model.traits.TimestampedEntity
|
||||
import ac.cord.auxiliary.compose.database.model.traits.UserViewableEntity
|
||||
import ac.cord.auxiliary.compose.network.serialization.encodeToJsonString
|
||||
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
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Kind
|
||||
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
|
||||
@@ -66,6 +69,9 @@ data class GiftWrapSeal(
|
||||
override val deletedAt: Instant? = null, // Who this message should be seen by (used to derive conversationId)
|
||||
): TimestampedEntity, LocalStoreEntity, UserViewableEntity, SoftDeletableEntity {
|
||||
|
||||
@Ignore
|
||||
private val logger = Logger.withTag("GiftWrapMessage")
|
||||
|
||||
suspend fun decryptGiftWrapPayload(
|
||||
privateKey: ByteArray
|
||||
): GiftWrapPayload? {
|
||||
@@ -78,6 +84,7 @@ data class GiftWrapSeal(
|
||||
content = content,
|
||||
sig = signature
|
||||
)
|
||||
logger.d("sealedRumorEvent: ${sealedRumorEvent.toJson()}")
|
||||
|
||||
val nostrSigner = NostrSignerInternal(
|
||||
keyPair = KeyPair(privKey = privateKey)
|
||||
@@ -86,6 +93,8 @@ data class GiftWrapSeal(
|
||||
sealedRumorEvent.unsealOrNull(
|
||||
nostrSigner
|
||||
)?.let { giftWrapPayload ->
|
||||
logger.d("giftWrapPayload: ${giftWrapPayload.toJson()}")
|
||||
|
||||
return GiftWrapPayload(
|
||||
id = giftWrapPayload.id,
|
||||
publicKey = giftWrapPayload.pubKey,
|
||||
|
||||
Reference in New Issue
Block a user