Also send a giftWrapMessage to self for message history
This commit is contained in:
@@ -15,6 +15,8 @@ interface ParticipantDao {
|
||||
@Query("SELECT * FROM Participant WHERE participantPublicKey = :participantPublicKey")
|
||||
fun findParticipantByPublicKey(participantPublicKey: String): Participant?
|
||||
|
||||
@Query("SELECT * FROM Participant WHERE chatRoomId = :chatRoomId")
|
||||
fun findParticipantsByChatRoomId(chatRoomId: String): List<Participant>
|
||||
|
||||
@Upsert
|
||||
suspend fun upsert(participants: List<Participant>)
|
||||
|
||||
@@ -37,6 +37,8 @@ data class GiftWrapPayload( // TODO: Rename this to GiftWrapPayload...
|
||||
*/
|
||||
val publicKey: String,
|
||||
|
||||
val chatRoomId: String,
|
||||
|
||||
/**
|
||||
* Payload Event Kind
|
||||
*/
|
||||
|
||||
@@ -95,14 +95,20 @@ data class GiftWrapSeal(
|
||||
)?.let { giftWrapPayload ->
|
||||
logger.d("giftWrapPayload: ${giftWrapPayload.toJson()}")
|
||||
|
||||
return GiftWrapPayload(
|
||||
val giftWrapPayload = GiftWrapPayload(
|
||||
giftWrapSealId = id,
|
||||
publicKey = giftWrapPayload.pubKey,
|
||||
kind = giftWrapPayload.kind,
|
||||
tags = giftWrapPayload.tags,
|
||||
content = giftWrapPayload.content,
|
||||
createdAt = Instant.fromEpochSeconds(giftWrapPayload.createdAt),
|
||||
chatRoomId = ""
|
||||
)
|
||||
return giftWrapPayload.aggregatedParticipantsPublicKey()?.let {
|
||||
giftWrapPayload.copy(
|
||||
chatRoomId = it
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -113,6 +113,7 @@ class DatabaseChatRepository(
|
||||
kind = messageType,
|
||||
tags = receiverTags.toTypedArray(),
|
||||
content = text,
|
||||
chatRoomId = localChatRoom.chatRoom.id,
|
||||
publicKey = localChatRoom.chatRoom.userPublicKey
|
||||
)
|
||||
)
|
||||
@@ -143,21 +144,22 @@ class DatabaseChatRepository(
|
||||
giftWrapPayload: GiftWrapPayload,
|
||||
nostrSignerSync: NostrSignerSync
|
||||
) {
|
||||
val wrapperKeyPair = KeyPair()
|
||||
val wrapperSigner = NostrSignerSync(
|
||||
keyPair = wrapperKeyPair
|
||||
)
|
||||
database.participantDao().findParticipantsByChatRoomId(giftWrapPayload.chatRoomId).forEachIndexed { index, participant ->
|
||||
val wrapperKeyPair = KeyPair()
|
||||
val wrapperSigner = NostrSignerSync(
|
||||
keyPair = wrapperKeyPair
|
||||
)
|
||||
|
||||
val giftWrapPayloadEvent = nostrSignerSync.signNormal<Event>(
|
||||
createdAt = giftWrapPayload.createdAt.epochSeconds,
|
||||
kind = giftWrapPayload.kind,
|
||||
tags = giftWrapPayload.tags,
|
||||
content = giftWrapPayload.content
|
||||
)
|
||||
logger.d("GiftWrap Payload Event: ${giftWrapPayloadEvent.toJson()}")
|
||||
val giftWrapPayloadEvent = nostrSignerSync.signNormal<Event>(
|
||||
createdAt = giftWrapPayload.createdAt.epochSeconds,
|
||||
kind = giftWrapPayload.kind,
|
||||
tags = giftWrapPayload.tags,
|
||||
content = giftWrapPayload.content
|
||||
)
|
||||
logger.d("GiftWrap Payload Event: ${giftWrapPayloadEvent.toJson()}")
|
||||
|
||||
giftWrapPayload.tags.taggedUsers().forEachIndexed { index, receiverPublicKey ->
|
||||
logger.d("Seal to $receiverPublicKey")
|
||||
|
||||
logger.d("Seal to $participant")
|
||||
val payload = giftWrapPayloadEvent.toJson()
|
||||
|
||||
val sealedRumorEvent = nostrSignerSync.signNormal<SealedRumorEvent>(
|
||||
@@ -166,7 +168,7 @@ class DatabaseChatRepository(
|
||||
tags = emptyArray(),
|
||||
content = nostrSignerSync.nip44Encrypt(
|
||||
plaintext = payload,
|
||||
toPublicKey = receiverPublicKey.pubKey
|
||||
toPublicKey = participant.participantPublicKey
|
||||
)
|
||||
)
|
||||
logger.d("SealedRumorEvent: ${sealedRumorEvent.toJson()}")
|
||||
@@ -175,11 +177,11 @@ class DatabaseChatRepository(
|
||||
createdAt = TimeUtils.randomWithTwoDays(),
|
||||
kind = GiftWrapEvent.KIND,
|
||||
tags = arrayOf(
|
||||
PTag.assemble(receiverPublicKey.pubKey, receiverPublicKey.relayHint)
|
||||
PTag.assemble(participant.participantPublicKey, participant.relayHint?.let { NormalizedRelayUrl(it) })
|
||||
),
|
||||
content = wrapperSigner.nip44Encrypt(
|
||||
plaintext = sealedRumorEvent.toJson(),
|
||||
toPublicKey = receiverPublicKey.pubKey
|
||||
toPublicKey = participant.participantPublicKey
|
||||
)
|
||||
)
|
||||
logger.d("giftWrapEvent: ${giftWrapEvent.toJson()}")
|
||||
@@ -191,9 +193,13 @@ class DatabaseChatRepository(
|
||||
),
|
||||
sealedRumorEvent = sealedRumorEvent,
|
||||
giftWrapEvent = giftWrapEvent,
|
||||
receiverPublicKey = receiverPublicKey
|
||||
receiverPublicKey = PTag(
|
||||
pubKey = participant.participantPublicKey,
|
||||
relayHint = participant.relayHint?.let { NormalizedRelayUrl(it) }
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
Reference in New Issue
Block a user