Keeps track of a message's GiftWrap host in order to broadcast later.

This commit is contained in:
Vitor Pamplona
2023-08-20 10:24:11 -04:00
parent 784f867a8e
commit eb59a9d505
5 changed files with 33 additions and 3 deletions
@@ -17,7 +17,7 @@ class ChatMessageEvent(
tags: List<List<String>>,
content: String,
sig: HexKey
) : Event(id, pubKey, createdAt, kind, tags, content, sig), ChatroomKeyable {
) : WrappedEvent(id, pubKey, createdAt, kind, tags, content, sig), ChatroomKeyable {
/**
* Recepients intended to receive this conversation
*/
@@ -362,6 +362,22 @@ open class Event(
}
}
@Immutable
open class WrappedEvent(
id: HexKey,
@JsonProperty("pubkey")
pubKey: HexKey,
@JsonProperty("created_at")
createdAt: Long,
kind: Int,
tags: List<List<String>>,
content: String,
sig: HexKey
) : Event(id, pubKey, createdAt, kind, tags, content, sig) {
@Transient
var host: Event? = null // host event to broadcast when needed
}
@Immutable
interface AddressableEvent {
fun dTag(): String
@@ -28,6 +28,10 @@ class GiftWrapEvent(
if (cachedInnerEvent.contains(hex)) return cachedInnerEvent[hex]
val myInnerEvent = unwrap(privKey = privKey)
if (myInnerEvent is WrappedEvent) {
myInnerEvent.host = this
}
cachedInnerEvent = cachedInnerEvent + Pair(hex, myInnerEvent)
return myInnerEvent
}
@@ -20,7 +20,7 @@ class SealedGossipEvent(
tags: List<List<String>>,
content: String,
sig: HexKey
) : Event(id, pubKey, createdAt, kind, tags, content, sig) {
): WrappedEvent(id, pubKey, createdAt, kind, tags, content, sig) {
@Transient
private var cachedInnerEvent: Map<HexKey, Event?> = mapOf()
@@ -30,6 +30,10 @@ class SealedGossipEvent(
val gossip = unseal(privKey = privKey)
val event = gossip?.mergeWith(this)
if (event is WrappedEvent) {
event.host = host ?: this
}
cachedInnerEvent = cachedInnerEvent + Pair(hex, event)
return event
}