Adds a card to setup the DM relay list if the user doesn't have one.

This commit is contained in:
Vitor Pamplona
2024-05-22 17:46:39 -04:00
parent 76103ac057
commit 599fddb369
11 changed files with 900 additions and 82 deletions

View File

@@ -21,6 +21,7 @@
package com.vitorpamplona.quartz.events
import androidx.compose.runtime.Immutable
import com.vitorpamplona.quartz.encoders.ATag
import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.signers.NostrSigner
import com.vitorpamplona.quartz.utils.TimeUtils
@@ -57,6 +58,10 @@ class AdvertisedRelayListEvent(
const val KIND = 10002
const val FIXED_D_TAG = ""
fun createAddressTag(pubKey: HexKey): ATag {
return ATag(KIND, pubKey, FIXED_D_TAG, null)
}
fun create(
list: List<AdvertisedRelayInfo>,
signer: NostrSigner,

View File

@@ -51,6 +51,10 @@ class ChatMessageRelayListEvent(
const val KIND = 10050
const val FIXED_D_TAG = ""
fun createAddressATag(pubKey: HexKey): ATag {
return ATag(KIND, pubKey, FIXED_D_TAG, null)
}
fun createAddressTag(pubKey: HexKey): String {
return ATag.assembleATag(KIND, pubKey, FIXED_D_TAG)
}
@@ -58,7 +62,33 @@ class ChatMessageRelayListEvent(
fun createTagArray(relays: List<String>): Array<Array<String>> {
return relays.map {
arrayOf("relay", it)
}.plusElement(arrayOf("alt", "Relay list for private messages")).toTypedArray()
}.plusElement(arrayOf("alt", "Relay list to receive private messages")).toTypedArray()
}
fun updateRelayList(
earlierVersion: ChatMessageRelayListEvent,
relays: List<String>,
signer: NostrSigner,
createdAt: Long = TimeUtils.now(),
onReady: (ChatMessageRelayListEvent) -> Unit,
) {
val tags =
earlierVersion.tags.filter { it[0] != "relay" }.plus(
relays.map {
arrayOf("relay", it)
},
).toTypedArray()
signer.sign(createdAt, KIND, tags, earlierVersion.content, onReady)
}
fun createFromScratch(
relays: List<String>,
signer: NostrSigner,
createdAt: Long = TimeUtils.now(),
onReady: (ChatMessageRelayListEvent) -> Unit,
) {
create(relays, signer, createdAt, onReady)
}
fun create(