kopia lustrzana https://github.com/vitorpamplona/amethyst
use url tag, add relay hint
rodzic
c81324843c
commit
ad6dcfc030
|
@ -2201,6 +2201,7 @@ class Account(
|
|||
fun addToGallery(
|
||||
idHex: String,
|
||||
url: String,
|
||||
relay: String?,
|
||||
) {
|
||||
if (!isWriteable()) return
|
||||
|
||||
|
@ -2208,6 +2209,7 @@ class Account(
|
|||
userProfile().latestGalleryList,
|
||||
idHex,
|
||||
url,
|
||||
relay,
|
||||
signer,
|
||||
) {
|
||||
Client.send(it)
|
||||
|
|
|
@ -663,7 +663,7 @@ fun ShareImageAction(
|
|||
if (videoUri != null) {
|
||||
var n19 = Nip19Bech32.uriToRoute(postNostrUri)?.entity as? Nip19Bech32.NEvent
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -672,8 +672,9 @@ class AccountViewModel(
|
|||
fun addMediaToGallery(
|
||||
hex: String,
|
||||
url: String,
|
||||
relay: String?,
|
||||
) {
|
||||
viewModelScope.launch(Dispatchers.IO) { account.addToGallery(hex, url) }
|
||||
viewModelScope.launch(Dispatchers.IO) { account.addToGallery(hex, url, relay) }
|
||||
}
|
||||
|
||||
fun removefromMediaGallery(
|
||||
|
|
|
@ -119,7 +119,10 @@ open class Event(
|
|||
|
||||
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] }
|
||||
|
||||
|
|
|
@ -38,29 +38,36 @@ class GalleryListEvent(
|
|||
companion object {
|
||||
const val KIND = 10011
|
||||
const val ALT = "Profile Gallery"
|
||||
const val GALLERYTAGNAME = "G"
|
||||
const val GALLERYTAGNAME = "url"
|
||||
|
||||
fun addEvent(
|
||||
earlierVersion: GalleryListEvent?,
|
||||
eventId: HexKey,
|
||||
url: String,
|
||||
relay: String?,
|
||||
signer: NostrSigner,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
onReady: (GalleryListEvent) -> Unit,
|
||||
) = addTag(earlierVersion, GALLERYTAGNAME, eventId, url, signer, createdAt, onReady)
|
||||
) = addTag(earlierVersion, GALLERYTAGNAME, eventId, url, relay, signer, createdAt, onReady)
|
||||
|
||||
fun addTag(
|
||||
earlierVersion: GalleryListEvent?,
|
||||
tagName: String,
|
||||
tagValue: HexKey,
|
||||
eventid: HexKey,
|
||||
url: String,
|
||||
relay: String?,
|
||||
signer: NostrSigner,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
onReady: (GalleryListEvent) -> Unit,
|
||||
) {
|
||||
var tags = arrayOf(tagName, url, eventid)
|
||||
if (relay != null) {
|
||||
tags + relay
|
||||
}
|
||||
|
||||
add(
|
||||
earlierVersion,
|
||||
arrayOf(arrayOf(tagName, tagValue, url)),
|
||||
arrayOf(tags),
|
||||
signer,
|
||||
createdAt,
|
||||
onReady,
|
||||
|
@ -104,7 +111,7 @@ class GalleryListEvent(
|
|||
private fun removeTag(
|
||||
earlierVersion: GalleryListEvent,
|
||||
tagName: String,
|
||||
tagValue: HexKey,
|
||||
eventid: HexKey,
|
||||
url: String,
|
||||
signer: NostrSigner,
|
||||
createdAt: Long = TimeUtils.now(),
|
||||
|
@ -114,7 +121,7 @@ class GalleryListEvent(
|
|||
content = earlierVersion.content,
|
||||
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(),
|
||||
signer = signer,
|
||||
createdAt = createdAt,
|
||||
|
@ -142,16 +149,17 @@ class GalleryListEvent(
|
|||
|
||||
@Immutable
|
||||
data class GalleryUrl(
|
||||
val id: String,
|
||||
val url: String,
|
||||
val id: String,
|
||||
val relay: String?,
|
||||
) {
|
||||
fun encode(): String = ":$id:$url"
|
||||
fun encode(): String = ":$url:$id:$relay"
|
||||
|
||||
companion object {
|
||||
fun decode(encodedGallerySetup: String): EmojiUrl? {
|
||||
val emojiParts = encodedGallerySetup.split(":", limit = 3)
|
||||
return if (emojiParts.size > 2) {
|
||||
EmojiUrl(emojiParts[1], emojiParts[2])
|
||||
fun decode(encodedGallerySetup: String): GalleryUrl? {
|
||||
val galleryParts = encodedGallerySetup.split(":", limit = 3)
|
||||
return if (galleryParts.size > 3) {
|
||||
GalleryUrl(galleryParts[1], galleryParts[2], galleryParts[3])
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue