Also send a giftWrapMessage to self for message history
This commit is contained in:
1 parent
f67ebd60b2
commit
f3c7e21fa3
5 files changed
+43
-21
No files matched your search
@@ -2,7 +2,7 @@
|
|||||||
"formatVersion": 1,
|
"formatVersion": 1,
|
||||||
"database": {
|
"database": {
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"identityHash": "7aff70ac118cd5856e8a4939d62a2ed8",
|
"identityHash": "630d9cf4853f9f393e7e043f4cd03a6d",
|
||||||
"entities": [
|
"entities": [
|
||||||
{
|
{
|
||||||
"tableName": "BroadcastNostrEventReceipt",
|
"tableName": "BroadcastNostrEventReceipt",
|
||||||
@@ -1007,7 +1007,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tableName": "GiftWrapPayload",
|
"tableName": "GiftWrapPayload",
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `publicKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `quotedEventId` TEXT, `giftWrapSealId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, FOREIGN KEY(`giftWrapSealId`) REFERENCES `GiftWrapSeal`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `publicKey` TEXT NOT NULL, `chatRoomId` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `quotedEventId` TEXT, `giftWrapSealId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `viewedAt` INTEGER, `deletedAt` INTEGER, FOREIGN KEY(`giftWrapSealId`) REFERENCES `GiftWrapSeal`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"fieldPath": "id",
|
"fieldPath": "id",
|
||||||
@@ -1021,6 +1021,12 @@
|
|||||||
"affinity": "TEXT",
|
"affinity": "TEXT",
|
||||||
"notNull": true
|
"notNull": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "chatRoomId",
|
||||||
|
"columnName": "chatRoomId",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"fieldPath": "kind",
|
"fieldPath": "kind",
|
||||||
"columnName": "kind",
|
"columnName": "kind",
|
||||||
@@ -2857,7 +2863,7 @@
|
|||||||
],
|
],
|
||||||
"setupQueries": [
|
"setupQueries": [
|
||||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7aff70ac118cd5856e8a4939d62a2ed8')"
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '630d9cf4853f9f393e7e043f4cd03a6d')"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
@@ -15,6 +15,8 @@ interface ParticipantDao {
|
|||||||
@Query("SELECT * FROM Participant WHERE participantPublicKey = :participantPublicKey")
|
@Query("SELECT * FROM Participant WHERE participantPublicKey = :participantPublicKey")
|
||||||
fun findParticipantByPublicKey(participantPublicKey: String): Participant?
|
fun findParticipantByPublicKey(participantPublicKey: String): Participant?
|
||||||
|
|
||||||
|
@Query("SELECT * FROM Participant WHERE chatRoomId = :chatRoomId")
|
||||||
|
fun findParticipantsByChatRoomId(chatRoomId: String): List<Participant>
|
||||||
|
|
||||||
@Upsert
|
@Upsert
|
||||||
suspend fun upsert(participants: List<Participant>)
|
suspend fun upsert(participants: List<Participant>)
|
||||||
|
|||||||
+2
@@ -37,6 +37,8 @@ data class GiftWrapPayload( // TODO: Rename this to GiftWrapPayload...
|
|||||||
*/
|
*/
|
||||||
val publicKey: String,
|
val publicKey: String,
|
||||||
|
|
||||||
|
val chatRoomId: String,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payload Event Kind
|
* Payload Event Kind
|
||||||
*/
|
*/
|
||||||
|
|||||||
+7
-1
@@ -95,14 +95,20 @@ data class GiftWrapSeal(
|
|||||||
)?.let { giftWrapPayload ->
|
)?.let { giftWrapPayload ->
|
||||||
logger.d("giftWrapPayload: ${giftWrapPayload.toJson()}")
|
logger.d("giftWrapPayload: ${giftWrapPayload.toJson()}")
|
||||||
|
|
||||||
return GiftWrapPayload(
|
val giftWrapPayload = GiftWrapPayload(
|
||||||
giftWrapSealId = id,
|
giftWrapSealId = id,
|
||||||
publicKey = giftWrapPayload.pubKey,
|
publicKey = giftWrapPayload.pubKey,
|
||||||
kind = giftWrapPayload.kind,
|
kind = giftWrapPayload.kind,
|
||||||
tags = giftWrapPayload.tags,
|
tags = giftWrapPayload.tags,
|
||||||
content = giftWrapPayload.content,
|
content = giftWrapPayload.content,
|
||||||
createdAt = Instant.fromEpochSeconds(giftWrapPayload.createdAt),
|
createdAt = Instant.fromEpochSeconds(giftWrapPayload.createdAt),
|
||||||
|
chatRoomId = ""
|
||||||
)
|
)
|
||||||
|
return giftWrapPayload.aggregatedParticipantsPublicKey()?.let {
|
||||||
|
giftWrapPayload.copy(
|
||||||
|
chatRoomId = it
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-17
@@ -113,6 +113,7 @@ class DatabaseChatRepository(
|
|||||||
kind = messageType,
|
kind = messageType,
|
||||||
tags = receiverTags.toTypedArray(),
|
tags = receiverTags.toTypedArray(),
|
||||||
content = text,
|
content = text,
|
||||||
|
chatRoomId = localChatRoom.chatRoom.id,
|
||||||
publicKey = localChatRoom.chatRoom.userPublicKey
|
publicKey = localChatRoom.chatRoom.userPublicKey
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -143,21 +144,22 @@ class DatabaseChatRepository(
|
|||||||
giftWrapPayload: GiftWrapPayload,
|
giftWrapPayload: GiftWrapPayload,
|
||||||
nostrSignerSync: NostrSignerSync
|
nostrSignerSync: NostrSignerSync
|
||||||
) {
|
) {
|
||||||
val wrapperKeyPair = KeyPair()
|
database.participantDao().findParticipantsByChatRoomId(giftWrapPayload.chatRoomId).forEachIndexed { index, participant ->
|
||||||
val wrapperSigner = NostrSignerSync(
|
val wrapperKeyPair = KeyPair()
|
||||||
keyPair = wrapperKeyPair
|
val wrapperSigner = NostrSignerSync(
|
||||||
)
|
keyPair = wrapperKeyPair
|
||||||
|
)
|
||||||
|
|
||||||
val giftWrapPayloadEvent = nostrSignerSync.signNormal<Event>(
|
val giftWrapPayloadEvent = nostrSignerSync.signNormal<Event>(
|
||||||
createdAt = giftWrapPayload.createdAt.epochSeconds,
|
createdAt = giftWrapPayload.createdAt.epochSeconds,
|
||||||
kind = giftWrapPayload.kind,
|
kind = giftWrapPayload.kind,
|
||||||
tags = giftWrapPayload.tags,
|
tags = giftWrapPayload.tags,
|
||||||
content = giftWrapPayload.content
|
content = giftWrapPayload.content
|
||||||
)
|
)
|
||||||
logger.d("GiftWrap Payload Event: ${giftWrapPayloadEvent.toJson()}")
|
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 payload = giftWrapPayloadEvent.toJson()
|
||||||
|
|
||||||
val sealedRumorEvent = nostrSignerSync.signNormal<SealedRumorEvent>(
|
val sealedRumorEvent = nostrSignerSync.signNormal<SealedRumorEvent>(
|
||||||
@@ -166,7 +168,7 @@ class DatabaseChatRepository(
|
|||||||
tags = emptyArray(),
|
tags = emptyArray(),
|
||||||
content = nostrSignerSync.nip44Encrypt(
|
content = nostrSignerSync.nip44Encrypt(
|
||||||
plaintext = payload,
|
plaintext = payload,
|
||||||
toPublicKey = receiverPublicKey.pubKey
|
toPublicKey = participant.participantPublicKey
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
logger.d("SealedRumorEvent: ${sealedRumorEvent.toJson()}")
|
logger.d("SealedRumorEvent: ${sealedRumorEvent.toJson()}")
|
||||||
@@ -175,11 +177,11 @@ class DatabaseChatRepository(
|
|||||||
createdAt = TimeUtils.randomWithTwoDays(),
|
createdAt = TimeUtils.randomWithTwoDays(),
|
||||||
kind = GiftWrapEvent.KIND,
|
kind = GiftWrapEvent.KIND,
|
||||||
tags = arrayOf(
|
tags = arrayOf(
|
||||||
PTag.assemble(receiverPublicKey.pubKey, receiverPublicKey.relayHint)
|
PTag.assemble(participant.participantPublicKey, participant.relayHint?.let { NormalizedRelayUrl(it) })
|
||||||
),
|
),
|
||||||
content = wrapperSigner.nip44Encrypt(
|
content = wrapperSigner.nip44Encrypt(
|
||||||
plaintext = sealedRumorEvent.toJson(),
|
plaintext = sealedRumorEvent.toJson(),
|
||||||
toPublicKey = receiverPublicKey.pubKey
|
toPublicKey = participant.participantPublicKey
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
logger.d("giftWrapEvent: ${giftWrapEvent.toJson()}")
|
logger.d("giftWrapEvent: ${giftWrapEvent.toJson()}")
|
||||||
@@ -191,9 +193,13 @@ class DatabaseChatRepository(
|
|||||||
),
|
),
|
||||||
sealedRumorEvent = sealedRumorEvent,
|
sealedRumorEvent = sealedRumorEvent,
|
||||||
giftWrapEvent = giftWrapEvent,
|
giftWrapEvent = giftWrapEvent,
|
||||||
receiverPublicKey = receiverPublicKey
|
receiverPublicKey = PTag(
|
||||||
|
pubKey = participant.participantPublicKey,
|
||||||
|
relayHint = participant.relayHint?.let { NormalizedRelayUrl(it) }
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
Reference in new issue
Block a user