Skip to content

Commit

Permalink
Merge pull request #1210 from believethehype/olas-profile-with-legacy
Browse files Browse the repository at this point in the history
Extend NIP93 Profile Gallery with Nip68 Events
  • Loading branch information
vitorpamplona authored Dec 6, 2024
2 parents 8979706 + d218799 commit f759acf
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1962,6 +1962,7 @@ class Account(
if (isImage) {
PictureEvent.create(
url = url,
msg = alt,
mimeType = headerInfo.mimeType,
hash = headerInfo.hash,
size = headerInfo.size.toLong(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ fun VideoView(
onControllerVisibilityChanged: ((Boolean) -> Unit)? = null,
accountViewModel: AccountViewModel,
alwaysShowVideo: Boolean = false,
showControls: Boolean = true,
) {
val defaultToStart by remember(videoUri) { mutableStateOf(DEFAULT_MUTED_SETTING.value) }

Expand Down Expand Up @@ -337,6 +338,7 @@ fun VideoView(
onControllerVisibilityChanged = onControllerVisibilityChanged,
onDialog = onDialog,
accountViewModel = accountViewModel,
showControls = showControls,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.animation.fadeOut
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.text.InlineTextContent
Expand Down Expand Up @@ -222,19 +223,21 @@ fun GalleryContentView(
}
is MediaUrlVideo ->
SensitivityWarning(content.contentWarning != null, accountViewModel) {
Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
VideoView(
videoUri = content.url,
mimeType = content.mimeType,
title = content.description,
artworkUri = content.artworkUri,
borderModifier = MaterialTheme.colorScheme.videoGalleryModifier,
authorName = content.authorName,
dimensions = content.dim,
dimensions = Dimension(1, 1), // fit video in 1:1 ratio
blurhash = content.blurhash,
isFiniteHeight = isFiniteHeight,
nostrUriCallback = content.uri,
accountViewModel = accountViewModel,
alwaysShowVideo = true,
showControls = false,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.quartz.events.MuteListEvent
import com.vitorpamplona.quartz.events.PeopleListEvent
import com.vitorpamplona.quartz.events.PictureEvent
import com.vitorpamplona.quartz.events.ProfileGalleryEntryEvent
import com.vitorpamplona.quartz.events.VideoEvent

class UserProfileGalleryFeedFilter(
val user: User,
Expand Down Expand Up @@ -65,7 +67,7 @@ class UserProfileGalleryFeedFilter(
): Boolean {
val noteEvent = it.event
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) &&
account.isAcceptable(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ import com.vitorpamplona.amethyst.ui.theme.DividerThickness
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
import com.vitorpamplona.amethyst.ui.theme.HalfPadding
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.VideoEvent

@Composable
fun RenderGalleryFeed(
Expand Down Expand Up @@ -171,11 +174,22 @@ fun GalleryCardCompose(
nav = nav,
) { canPreview ->

val galleryEvent = (baseNote.event as? ProfileGalleryEntryEvent) ?: return@CheckHiddenFeedWatchBlockAndReport
var galleryEvent = baseNote.event
var url = ""
var sourceEvent = galleryEvent?.id()

galleryEvent.url()?.let { image ->
val sourceEvent = galleryEvent.fromEvent()
if (baseNote.event is ProfileGalleryEntryEvent) {
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) {
LoadNote(baseNoteHex = sourceEvent, accountViewModel = accountViewModel) { sourceNote ->
if (sourceNote != null) {
Expand Down Expand Up @@ -338,7 +352,31 @@ fun InnerRenderGalleryThumb(
note: Note,
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(
Modifier
Expand All @@ -347,11 +385,6 @@ fun InnerRenderGalleryThumb(
contentAlignment = BottomStart,
) {
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

if (isVideoUrl(it)) {
Expand Down
2 changes: 1 addition & 1 deletion amethyst/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@
<string name="quick_action_unfollow">Unfollow</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_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_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>
Expand Down

0 comments on commit f759acf

Please sign in to comment.