Adds support for the FileServers kind

This commit is contained in:
Vitor Pamplona
2023-12-10 21:27:47 -05:00
parent c5cf2c5442
commit 04addc4cba
4 changed files with 62 additions and 0 deletions
@@ -51,6 +51,7 @@ class EventFactory {
SealedGossipEvent.kind -> SealedGossipEvent(id, pubKey, createdAt, tags, content, sig)
FileHeaderEvent.kind -> FileHeaderEvent(id, pubKey, createdAt, tags, content, sig)
FileServersEvent.kind -> FileServersEvent(id, pubKey, createdAt, tags, content, sig)
FileStorageEvent.kind -> FileStorageEvent(id, pubKey, createdAt, tags, content, sig)
FileStorageHeaderEvent.kind -> FileStorageHeaderEvent(id, pubKey, createdAt, tags, content, sig)
GenericRepostEvent.kind -> GenericRepostEvent(id, pubKey, createdAt, tags, content, sig)
@@ -0,0 +1,43 @@
package com.vitorpamplona.quartz.events
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.utils.TimeUtils
import com.vitorpamplona.quartz.encoders.toHexKey
import com.vitorpamplona.quartz.crypto.CryptoUtils
import com.vitorpamplona.quartz.crypto.KeyPair
import com.vitorpamplona.quartz.encoders.ATag
import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.signers.NostrSigner
@Immutable
class FileServersEvent(
id: HexKey,
pubKey: HexKey,
createdAt: Long,
tags: Array<Array<String>>,
content: String,
sig: HexKey
) : BaseAddressableEvent(id, pubKey, createdAt, kind, tags, content, sig) {
override fun dTag() = fixedDTag
companion object {
const val kind = 10096
const val fixedDTag = ""
fun create(
listOfServers: List<String>,
signer: NostrSigner,
createdAt: Long = TimeUtils.now(),
onReady: (FileServersEvent) -> Unit
) {
val msg = ""
val tags = mutableListOf<Array<String>>()
listOfServers.forEach {
tags.add(arrayOf("server", it))
}
signer.sign(createdAt, kind, tags.toTypedArray(), msg, onReady)
}
}
}