use url tag, add relay hint

This commit is contained in:
Believethehype
2024-07-05 08:29:49 +02:00
parent c81324843c
commit ad6dcfc030
5 changed files with 29 additions and 15 deletions

View File

@@ -2201,6 +2201,7 @@ class Account(
fun addToGallery( fun addToGallery(
idHex: String, idHex: String,
url: String, url: String,
relay: String?,
) { ) {
if (!isWriteable()) return if (!isWriteable()) return
@@ -2208,6 +2209,7 @@ class Account(
userProfile().latestGalleryList, userProfile().latestGalleryList,
idHex, idHex,
url, url,
relay,
signer, signer,
) { ) {
Client.send(it) Client.send(it)

View File

@@ -663,7 +663,7 @@ fun ShareImageAction(
if (videoUri != null) { if (videoUri != null) {
var n19 = Nip19Bech32.uriToRoute(postNostrUri)?.entity as? Nip19Bech32.NEvent var n19 = Nip19Bech32.uriToRoute(postNostrUri)?.entity as? Nip19Bech32.NEvent
if (n19 != null) { if (n19 != null) {
accountViewModel.addMediaToGallery(n19.hex, videoUri) accountViewModel.addMediaToGallery(n19.hex, videoUri, n19.relay[0]) // TODO Whole list or first?
accountViewModel.toast(R.string.image_saved_to_the_gallery, R.string.image_saved_to_the_gallery) accountViewModel.toast(R.string.image_saved_to_the_gallery, R.string.image_saved_to_the_gallery)
} }
} }

View File

@@ -672,8 +672,9 @@ class AccountViewModel(
fun addMediaToGallery( fun addMediaToGallery(
hex: String, hex: String,
url: String, url: String,
relay: String?,
) { ) {
viewModelScope.launch(Dispatchers.IO) { account.addToGallery(hex, url) } viewModelScope.launch(Dispatchers.IO) { account.addToGallery(hex, url, relay) }
} }
fun removefromMediaGallery( fun removefromMediaGallery(

View File

@@ -119,7 +119,10 @@ open class Event(
override fun taggedEvents() = tags.filter { it.size > 1 && it[0] == "e" }.map { it[1] } override fun taggedEvents() = tags.filter { it.size > 1 && it[0] == "e" }.map { it[1] }
override fun taggedGalleryEntries() = tags.filter { it.size > 2 && it[0] == GalleryListEvent.GALLERYTAGNAME }.map { GalleryListEvent.GalleryUrl(it[1], it[2]) } override fun taggedGalleryEntries() =
tags.filter { it.size > 2 && it[0] == GalleryListEvent.GALLERYTAGNAME }.map {
GalleryListEvent.GalleryUrl(it[1], it[2], it.getOrNull(3))
}
override fun taggedUrls() = tags.filter { it.size > 1 && it[0] == "r" }.map { it[1] } override fun taggedUrls() = tags.filter { it.size > 1 && it[0] == "r" }.map { it[1] }

View File

@@ -38,29 +38,36 @@ class GalleryListEvent(
companion object { companion object {
const val KIND = 10011 const val KIND = 10011
const val ALT = "Profile Gallery" const val ALT = "Profile Gallery"
const val GALLERYTAGNAME = "G" const val GALLERYTAGNAME = "url"
fun addEvent( fun addEvent(
earlierVersion: GalleryListEvent?, earlierVersion: GalleryListEvent?,
eventId: HexKey, eventId: HexKey,
url: String, url: String,
relay: String?,
signer: NostrSigner, signer: NostrSigner,
createdAt: Long = TimeUtils.now(), createdAt: Long = TimeUtils.now(),
onReady: (GalleryListEvent) -> Unit, onReady: (GalleryListEvent) -> Unit,
) = addTag(earlierVersion, GALLERYTAGNAME, eventId, url, signer, createdAt, onReady) ) = addTag(earlierVersion, GALLERYTAGNAME, eventId, url, relay, signer, createdAt, onReady)
fun addTag( fun addTag(
earlierVersion: GalleryListEvent?, earlierVersion: GalleryListEvent?,
tagName: String, tagName: String,
tagValue: HexKey, eventid: HexKey,
url: String, url: String,
relay: String?,
signer: NostrSigner, signer: NostrSigner,
createdAt: Long = TimeUtils.now(), createdAt: Long = TimeUtils.now(),
onReady: (GalleryListEvent) -> Unit, onReady: (GalleryListEvent) -> Unit,
) { ) {
var tags = arrayOf(tagName, url, eventid)
if (relay != null) {
tags + relay
}
add( add(
earlierVersion, earlierVersion,
arrayOf(arrayOf(tagName, tagValue, url)), arrayOf(tags),
signer, signer,
createdAt, createdAt,
onReady, onReady,
@@ -104,7 +111,7 @@ class GalleryListEvent(
private fun removeTag( private fun removeTag(
earlierVersion: GalleryListEvent, earlierVersion: GalleryListEvent,
tagName: String, tagName: String,
tagValue: HexKey, eventid: HexKey,
url: String, url: String,
signer: NostrSigner, signer: NostrSigner,
createdAt: Long = TimeUtils.now(), createdAt: Long = TimeUtils.now(),
@@ -114,7 +121,7 @@ class GalleryListEvent(
content = earlierVersion.content, content = earlierVersion.content,
tags = tags =
earlierVersion.tags earlierVersion.tags
.filter { it.size <= 1 || !(it[0] == tagName && it[1] == tagValue && it[2] == url) } .filter { it.size <= 1 || !(it[0] == tagName && it[1] == url && it[2] == eventid) }
.toTypedArray(), .toTypedArray(),
signer = signer, signer = signer,
createdAt = createdAt, createdAt = createdAt,
@@ -142,16 +149,17 @@ class GalleryListEvent(
@Immutable @Immutable
data class GalleryUrl( data class GalleryUrl(
val id: String,
val url: String, val url: String,
val id: String,
val relay: String?,
) { ) {
fun encode(): String = ":$id:$url" fun encode(): String = ":$url:$id:$relay"
companion object { companion object {
fun decode(encodedGallerySetup: String): EmojiUrl? { fun decode(encodedGallerySetup: String): GalleryUrl? {
val emojiParts = encodedGallerySetup.split(":", limit = 3) val galleryParts = encodedGallerySetup.split(":", limit = 3)
return if (emojiParts.size > 2) { return if (galleryParts.size > 3) {
EmojiUrl(emojiParts[1], emojiParts[2]) GalleryUrl(galleryParts[1], galleryParts[2], galleryParts[3])
} else { } else {
null null
} }