mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-05 21:52:52 +02:00
gallery is visualised
This commit is contained in:
@@ -2226,7 +2226,6 @@ class Account(
|
||||
GalleryListEvent.removeReplaceable(
|
||||
galleryentries,
|
||||
note.address,
|
||||
false,
|
||||
signer,
|
||||
) {
|
||||
Client.send(it)
|
||||
@@ -2236,7 +2235,6 @@ class Account(
|
||||
GalleryListEvent.removeEvent(
|
||||
galleryentries,
|
||||
note.idHex,
|
||||
false,
|
||||
signer,
|
||||
) {
|
||||
Client.send(it)
|
||||
|
@@ -27,26 +27,26 @@ import com.vitorpamplona.amethyst.model.User
|
||||
|
||||
class UserProfileGalleryFeedFilter(val user: User, val account: Account) : FeedFilter<Note>() {
|
||||
override fun feedKey(): String {
|
||||
return account.userProfile().pubkeyHex + "-" + user.pubkeyHex
|
||||
return account.userProfile().pubkeyHex + "-Gallery-" + user.pubkeyHex
|
||||
}
|
||||
|
||||
override fun feed(): List<Note> {
|
||||
val notes =
|
||||
user.latestGalleryList
|
||||
?.taggedEvents()
|
||||
?.mapNotNull { LocalCache.checkGetOrCreateNote(it) }
|
||||
?.taggedGalleryEntries()
|
||||
?.mapNotNull { LocalCache.checkGetOrCreateNote(it.id) }
|
||||
?.toSet()
|
||||
?: emptySet()
|
||||
|
||||
val addresses =
|
||||
/*val addresses =
|
||||
user.latestGalleryList
|
||||
?.taggedAddresses()
|
||||
?.map { LocalCache.getOrCreateAddressableNote(it) }
|
||||
?.toSet()
|
||||
?: emptySet()
|
||||
?: emptySet() */
|
||||
|
||||
return (notes + addresses)
|
||||
// .sortedWith(DefaultFeedOrder)
|
||||
return (notes)
|
||||
.filter { account.isAcceptable(it) }
|
||||
.sortedWith(DefaultFeedOrder)
|
||||
}
|
||||
}
|
||||
|
@@ -32,8 +32,10 @@ import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyGridState
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.itemsIndexed
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Surface
|
||||
@@ -63,7 +65,6 @@ import com.vitorpamplona.amethyst.ui.components.SensitivityWarning
|
||||
import com.vitorpamplona.amethyst.ui.note.CheckHiddenFeedWatchBlockAndReport
|
||||
import com.vitorpamplona.amethyst.ui.note.ClickableNote
|
||||
import com.vitorpamplona.amethyst.ui.note.LongPressToQuickAction
|
||||
import com.vitorpamplona.amethyst.ui.note.NormalChannelCard
|
||||
import com.vitorpamplona.amethyst.ui.note.WatchAuthor
|
||||
import com.vitorpamplona.amethyst.ui.note.WatchNoteEvent
|
||||
import com.vitorpamplona.amethyst.ui.note.calculateBackgroundColor
|
||||
@@ -78,19 +79,18 @@ import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.HalfPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.QuoteBorder
|
||||
import com.vitorpamplona.amethyst.ui.theme.Size5dp
|
||||
import com.vitorpamplona.quartz.events.GalleryListEvent
|
||||
import com.vitorpamplona.quartz.events.TextNoteEvent
|
||||
|
||||
@Composable
|
||||
private fun RenderGalleryFeed(
|
||||
fun RenderGalleryFeed(
|
||||
viewModel: FeedViewModel,
|
||||
routeForLastRead: String?,
|
||||
forceEventKind: Int?,
|
||||
listState: LazyListState,
|
||||
listState: LazyGridState,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: (String) -> Unit,
|
||||
) {
|
||||
val feedState by viewModel.feedContent.collectAsStateWithLifecycle()
|
||||
|
||||
CrossfadeIfEnabled(
|
||||
targetState = feedState,
|
||||
animationSpec = tween(durationMillis = 100),
|
||||
@@ -126,12 +126,13 @@ private fun RenderGalleryFeed(
|
||||
private fun GalleryFeedLoaded(
|
||||
state: FeedState.Loaded,
|
||||
routeForLastRead: String?,
|
||||
listState: LazyListState,
|
||||
listState: LazyGridState,
|
||||
forceEventKind: Int?,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: (String) -> Unit,
|
||||
) {
|
||||
LazyColumn(
|
||||
LazyVerticalGrid(
|
||||
columns = GridCells.Fixed(3),
|
||||
contentPadding = FeedPadding,
|
||||
state = listState,
|
||||
) {
|
||||
@@ -142,7 +143,7 @@ private fun GalleryFeedLoaded(
|
||||
GalleryCardCompose(
|
||||
baseNote = item,
|
||||
routeForLastRead = routeForLastRead,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
modifier = Modifier,
|
||||
forceEventKind = forceEventKind,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
@@ -167,25 +168,30 @@ fun GalleryCardCompose(
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: (String) -> Unit,
|
||||
) {
|
||||
/* baseNote.event?.let {
|
||||
Text(text = it.id() + " " + it.firstTaggedUrl() + " ") // TODO why does it.taggedGalleryEntries() not return something? whats different?
|
||||
} baseNote.event?.let {
|
||||
for (entry in it.taggedGalleryEntries()) {
|
||||
Text(text = entry.url + " " + entry.id)
|
||||
}
|
||||
}*/
|
||||
|
||||
WatchNoteEvent(baseNote = baseNote, accountViewModel = accountViewModel) {
|
||||
if (forceEventKind == null || baseNote.event?.kind() == forceEventKind) {
|
||||
CheckHiddenFeedWatchBlockAndReport(
|
||||
note = baseNote,
|
||||
CheckHiddenFeedWatchBlockAndReport(
|
||||
note = baseNote,
|
||||
modifier = modifier,
|
||||
ignoreAllBlocksAndReports = isHiddenFeed,
|
||||
showHiddenWarning = false,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
) { canPreview ->
|
||||
GalleryCard(
|
||||
baseNote = baseNote,
|
||||
modifier = modifier,
|
||||
ignoreAllBlocksAndReports = isHiddenFeed,
|
||||
showHiddenWarning = false,
|
||||
parentBackgroundColor = parentBackgroundColor,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
) { canPreview ->
|
||||
NormalChannelCard(
|
||||
baseNote = baseNote,
|
||||
routeForLastRead = routeForLastRead,
|
||||
modifier = modifier,
|
||||
parentBackgroundColor = parentBackgroundColor,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,7 +241,6 @@ fun ProfileGallery(
|
||||
@Composable
|
||||
fun GalleryCard(
|
||||
baseNote: Note,
|
||||
url: String,
|
||||
modifier: Modifier = Modifier,
|
||||
parentBackgroundColor: MutableState<Color>? = null,
|
||||
accountViewModel: AccountViewModel,
|
||||
@@ -246,7 +251,6 @@ fun GalleryCard(
|
||||
|
||||
CheckNewAndRenderChannelCard(
|
||||
baseNote,
|
||||
url,
|
||||
modifier,
|
||||
parentBackgroundColor,
|
||||
accountViewModel,
|
||||
@@ -259,7 +263,6 @@ fun GalleryCard(
|
||||
@Composable
|
||||
private fun CheckNewAndRenderChannelCard(
|
||||
baseNote: Note,
|
||||
url: String,
|
||||
modifier: Modifier = Modifier,
|
||||
parentBackgroundColor: MutableState<Color>? = null,
|
||||
accountViewModel: AccountViewModel,
|
||||
@@ -284,7 +287,6 @@ private fun CheckNewAndRenderChannelCard(
|
||||
// baseNote.event?.let { Text(text = it.pubKey()) }
|
||||
InnerGalleryCardWithReactions(
|
||||
baseNote = baseNote,
|
||||
url = url,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
@@ -294,17 +296,15 @@ private fun CheckNewAndRenderChannelCard(
|
||||
@Composable
|
||||
fun InnerGalleryCardWithReactions(
|
||||
baseNote: Note,
|
||||
url: String,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: (String) -> Unit,
|
||||
) {
|
||||
InnerGalleryCardBox(baseNote, url, accountViewModel, nav)
|
||||
InnerGalleryCardBox(baseNote, accountViewModel, nav)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun InnerGalleryCardBox(
|
||||
baseNote: Note,
|
||||
url: String,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: (String) -> Unit,
|
||||
) {
|
||||
@@ -313,14 +313,13 @@ fun InnerGalleryCardBox(
|
||||
note = baseNote,
|
||||
accountViewModel = accountViewModel,
|
||||
) {
|
||||
RenderGalleryThumb(baseNote, url, accountViewModel, nav)
|
||||
RenderGalleryThumb(baseNote, accountViewModel, nav)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Immutable
|
||||
data class GalleryThumb(
|
||||
val baseNote: Note?,
|
||||
val id: String?,
|
||||
val image: String?,
|
||||
val title: String?,
|
||||
@@ -330,34 +329,31 @@ data class GalleryThumb(
|
||||
@Composable
|
||||
fun RenderGalleryThumb(
|
||||
baseNote: Note,
|
||||
url: String,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: (String) -> Unit,
|
||||
) {
|
||||
val noteEvent = baseNote.event as? GalleryListEvent ?: return
|
||||
val noteEvent = baseNote.event as? TextNoteEvent ?: return
|
||||
|
||||
val card by
|
||||
baseNote
|
||||
.live()
|
||||
.metadata
|
||||
.map {
|
||||
val noteEvent = baseNote.event as GalleryListEvent
|
||||
val noteEvent = baseNote.event as TextNoteEvent
|
||||
|
||||
GalleryThumb(
|
||||
baseNote = baseNote,
|
||||
id = "",
|
||||
image = url,
|
||||
title = "Hello",
|
||||
image = noteEvent.firstTaggedUrl(),
|
||||
title = noteEvent.content(),
|
||||
// noteEvent?.title(),
|
||||
// price = noteEvent?.price(),
|
||||
)
|
||||
}.distinctUntilChanged()
|
||||
.observeAsState(
|
||||
GalleryThumb(
|
||||
baseNote = baseNote,
|
||||
id = "",
|
||||
image = "https://gokaygokay-aurasr.hf.space/file=/tmp/gradio/68292f324a38d7071453cf6912dfb1da9d1305c8/image3.png",
|
||||
title = "Hello",
|
||||
image = noteEvent.firstTaggedUrl(),
|
||||
title = noteEvent.content(),
|
||||
// image = noteEvent.image(),
|
||||
// title = noteEvent.title(),
|
||||
// price = noteEvent.price(),
|
||||
@@ -374,7 +370,6 @@ fun RenderGalleryThumbPreview() {
|
||||
InnerRenderGalleryThumb(
|
||||
card =
|
||||
GalleryThumb(
|
||||
baseNote = null,
|
||||
id = "",
|
||||
image = null,
|
||||
title = "Like New",
|
||||
|
@@ -42,6 +42,7 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.grid.LazyGridState
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.pager.HorizontalPager
|
||||
import androidx.compose.foundation.pager.PagerState
|
||||
@@ -1569,10 +1570,12 @@ fun TabGallery(
|
||||
Column(
|
||||
modifier = Modifier.padding(vertical = 0.dp),
|
||||
) {
|
||||
RefresheableFeedView(
|
||||
var state = LazyGridState()
|
||||
RenderGalleryFeed(
|
||||
feedViewModel,
|
||||
null,
|
||||
enablePullRefresh = false,
|
||||
0,
|
||||
state,
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
)
|
||||
|
@@ -72,3 +72,21 @@ data class EmojiUrl(val code: String, val url: String) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Immutable
|
||||
data class GalleryUrl(val id: String, val url: String) {
|
||||
fun encode(): String {
|
||||
return ":$id:$url"
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun decode(encodedGallerySetup: String): EmojiUrl? {
|
||||
val emojiParts = encodedGallerySetup.split(":", limit = 3)
|
||||
return if (emojiParts.size > 2) {
|
||||
EmojiUrl(emojiParts[1], emojiParts[2])
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -119,6 +119,8 @@ 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] == "g" }.map { GalleryUrl(it[1], it[2]) }
|
||||
|
||||
override fun taggedUrls() = tags.filter { it.size > 1 && it[0] == "r" }.map { it[1] }
|
||||
|
||||
override fun firstTagFor(vararg key: String) = tags.firstOrNull { it.size > 1 && it[0] in key }?.let { it[1] }
|
||||
|
@@ -145,6 +145,8 @@ interface EventInterface {
|
||||
|
||||
fun firstTaggedK(): Int?
|
||||
|
||||
fun taggedGalleryEntries(): List<GalleryUrl>
|
||||
|
||||
fun taggedEmojis(): List<EmojiUrl>
|
||||
|
||||
fun matchTag1With(text: String): Boolean
|
||||
|
Reference in New Issue
Block a user