Merge pull request #1210 from believethehype/olas-profile-with-legacy

Extend NIP93 Profile Gallery with Nip68 Events
This commit is contained in:
Vitor Pamplona 2024-12-06 08:22:22 -05:00 committed by GitHub
commit f759acf66e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 54 additions and 13 deletions

View File

@ -1962,6 +1962,7 @@ class Account(
if (isImage) { if (isImage) {
PictureEvent.create( PictureEvent.create(
url = url, url = url,
msg = alt,
mimeType = headerInfo.mimeType, mimeType = headerInfo.mimeType,
hash = headerInfo.hash, hash = headerInfo.hash,
size = headerInfo.size.toLong(), size = headerInfo.size.toLong(),

View File

@ -250,6 +250,7 @@ fun VideoView(
onControllerVisibilityChanged: ((Boolean) -> Unit)? = null, onControllerVisibilityChanged: ((Boolean) -> Unit)? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
alwaysShowVideo: Boolean = false, alwaysShowVideo: Boolean = false,
showControls: Boolean = true,
) { ) {
val defaultToStart by remember(videoUri) { mutableStateOf(DEFAULT_MUTED_SETTING.value) } val defaultToStart by remember(videoUri) { mutableStateOf(DEFAULT_MUTED_SETTING.value) }
@ -337,6 +338,7 @@ fun VideoView(
onControllerVisibilityChanged = onControllerVisibilityChanged, onControllerVisibilityChanged = onControllerVisibilityChanged,
onDialog = onDialog, onDialog = onDialog,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
showControls = showControls,
) )
} }
} }

View File

@ -27,6 +27,7 @@ import androidx.compose.animation.fadeOut
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.text.InlineTextContent import androidx.compose.foundation.text.InlineTextContent
@ -222,7 +223,7 @@ fun GalleryContentView(
} }
is MediaUrlVideo -> is MediaUrlVideo ->
SensitivityWarning(content.contentWarning != null, accountViewModel) { SensitivityWarning(content.contentWarning != null, accountViewModel) {
Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) { Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
VideoView( VideoView(
videoUri = content.url, videoUri = content.url,
mimeType = content.mimeType, mimeType = content.mimeType,
@ -230,11 +231,13 @@ fun GalleryContentView(
artworkUri = content.artworkUri, artworkUri = content.artworkUri,
borderModifier = MaterialTheme.colorScheme.videoGalleryModifier, borderModifier = MaterialTheme.colorScheme.videoGalleryModifier,
authorName = content.authorName, authorName = content.authorName,
dimensions = content.dim, dimensions = Dimension(1, 1), // fit video in 1:1 ratio
blurhash = content.blurhash, blurhash = content.blurhash,
isFiniteHeight = isFiniteHeight, isFiniteHeight = isFiniteHeight,
nostrUriCallback = content.uri, nostrUriCallback = content.uri,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
alwaysShowVideo = true,
showControls = false,
) )
} }
} }

View File

@ -26,7 +26,9 @@ import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.quartz.events.MuteListEvent import com.vitorpamplona.quartz.events.MuteListEvent
import com.vitorpamplona.quartz.events.PeopleListEvent import com.vitorpamplona.quartz.events.PeopleListEvent
import com.vitorpamplona.quartz.events.PictureEvent
import com.vitorpamplona.quartz.events.ProfileGalleryEntryEvent import com.vitorpamplona.quartz.events.ProfileGalleryEntryEvent
import com.vitorpamplona.quartz.events.VideoEvent
class UserProfileGalleryFeedFilter( class UserProfileGalleryFeedFilter(
val user: User, val user: User,
@ -65,7 +67,7 @@ class UserProfileGalleryFeedFilter(
): Boolean { ): Boolean {
val noteEvent = it.event val noteEvent = it.event
return ( return (
(it.event?.pubKey() == user.pubkeyHex && noteEvent is ProfileGalleryEntryEvent) && noteEvent.hasUrl() && noteEvent.hasFromEvent() // && noteEvent.isOneOf(SUPPORTED_VIDEO_FEED_MIME_TYPES_SET)) (it.event?.pubKey() == user.pubkeyHex && (noteEvent is PictureEvent || noteEvent is VideoEvent || (noteEvent is ProfileGalleryEntryEvent) && noteEvent.hasUrl() && noteEvent.hasFromEvent())) // && noteEvent.isOneOf(SUPPORTED_VIDEO_FEED_MIME_TYPES_SET))
) && ) &&
params.match(noteEvent) && params.match(noteEvent) &&
account.isAcceptable(it) account.isAcceptable(it)

View File

@ -77,7 +77,10 @@ import com.vitorpamplona.amethyst.ui.theme.DividerThickness
import com.vitorpamplona.amethyst.ui.theme.FeedPadding import com.vitorpamplona.amethyst.ui.theme.FeedPadding
import com.vitorpamplona.amethyst.ui.theme.HalfPadding import com.vitorpamplona.amethyst.ui.theme.HalfPadding
import com.vitorpamplona.amethyst.ui.theme.QuoteBorder import com.vitorpamplona.amethyst.ui.theme.QuoteBorder
import com.vitorpamplona.quartz.events.Dimension
import com.vitorpamplona.quartz.events.PictureEvent
import com.vitorpamplona.quartz.events.ProfileGalleryEntryEvent import com.vitorpamplona.quartz.events.ProfileGalleryEntryEvent
import com.vitorpamplona.quartz.events.VideoEvent
@Composable @Composable
fun RenderGalleryFeed( fun RenderGalleryFeed(
@ -171,11 +174,22 @@ fun GalleryCardCompose(
nav = nav, nav = nav,
) { canPreview -> ) { canPreview ->
val galleryEvent = (baseNote.event as? ProfileGalleryEntryEvent) ?: return@CheckHiddenFeedWatchBlockAndReport var galleryEvent = baseNote.event
var url = ""
var sourceEvent = galleryEvent?.id()
galleryEvent.url()?.let { image -> if (baseNote.event is ProfileGalleryEntryEvent) {
val sourceEvent = galleryEvent.fromEvent() url = (baseNote.event as ProfileGalleryEntryEvent).url().toString()
sourceEvent = (baseNote.event as? ProfileGalleryEntryEvent)?.fromEvent()
} else if (baseNote.event is PictureEvent) {
url = (baseNote.event as PictureEvent).imetaTags()[0].url
sourceEvent = (baseNote.event as PictureEvent).id()
} else if (baseNote.event is VideoEvent) {
url = (baseNote.event as VideoEvent).url().toString()
sourceEvent = (baseNote.event as VideoEvent).id()
}
url.let { image ->
if (sourceEvent != null) { if (sourceEvent != null) {
LoadNote(baseNoteHex = sourceEvent, accountViewModel = accountViewModel) { sourceNote -> LoadNote(baseNoteHex = sourceEvent, accountViewModel = accountViewModel) { sourceNote ->
if (sourceNote != null) { if (sourceNote != null) {
@ -338,7 +352,31 @@ fun InnerRenderGalleryThumb(
note: Note, note: Note,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
) { ) {
val noteEvent = note.event as? ProfileGalleryEntryEvent ?: return var noteEvent = note.event
var blurHash = ""
var description = ""
var dimensions: Dimension? = null
var mimeType = ""
if (note.event is ProfileGalleryEntryEvent) {
noteEvent = (note.event as ProfileGalleryEntryEvent)
blurHash = noteEvent.blurhash().toString()
description = noteEvent.content
// var hash = (note.event as ProfileGalleryEntryEvent).hash()
dimensions = noteEvent.dimensions()
mimeType = noteEvent.mimeType().toString()
} else if (note.event is PictureEvent) {
noteEvent = (note.event as PictureEvent)
blurHash = noteEvent.blurhash().toString()
description = noteEvent.content
dimensions = noteEvent.dimensions()
mimeType = noteEvent.mimeType().toString()
} else if (note.event is VideoEvent) {
noteEvent = (note.event as VideoEvent)
blurHash = noteEvent.blurhash().toString()
description = noteEvent.content
dimensions = noteEvent.dimensions()
mimeType = noteEvent.mimeType().toString()
}
Box( Box(
Modifier Modifier
@ -347,11 +385,6 @@ fun InnerRenderGalleryThumb(
contentAlignment = BottomStart, contentAlignment = BottomStart,
) { ) {
card.image?.let { card.image?.let {
val blurHash = noteEvent.blurhash()
val description = noteEvent.content
// var hash = (note.event as ProfileGalleryEntryEvent).hash()
val dimensions = noteEvent.dimensions()
val mimeType = noteEvent.mimeType()
var content: BaseMediaContent? = null var content: BaseMediaContent? = null
if (isVideoUrl(it)) { if (isVideoUrl(it)) {

View File

@ -285,7 +285,7 @@
<string name="quick_action_unfollow">Unfollow</string> <string name="quick_action_unfollow">Unfollow</string>
<string name="quick_action_follow">Follow</string> <string name="quick_action_follow">Follow</string>
<string name="quick_action_request_deletion_gallery_title">Delete from Gallery</string> <string name="quick_action_request_deletion_gallery_title">Delete from Gallery</string>
<string name="quick_action_request_deletion_gallery_alert_body">Remove this media from your Gallery, you can readd it later</string> <string name="quick_action_request_deletion_gallery_alert_body">Remove this media from your Gallery.</string>
<string name="quick_action_request_deletion_alert_title">Request Deletion</string> <string name="quick_action_request_deletion_alert_title">Request Deletion</string>
<string name="quick_action_request_deletion_alert_body">Amethyst will request that your note be deleted from the relays you are currently connected to. There is no guarantee that your note will be permanently deleted from those relays, or from other relays where it may be stored.</string> <string name="quick_action_request_deletion_alert_body">Amethyst will request that your note be deleted from the relays you are currently connected to. There is no guarantee that your note will be permanently deleted from those relays, or from other relays where it may be stored.</string>
<string name="quick_action_block_dialog_btn">Block</string> <string name="quick_action_block_dialog_btn">Block</string>