Passes the video note uri so that when the user clicks in the video popup the app brings it back to the playing screen without breaking the video.

This commit is contained in:
Vitor Pamplona
2024-06-03 17:26:40 -04:00
parent 2b2ee5bbfc
commit a6519d57c6
27 changed files with 100 additions and 62 deletions
@@ -36,6 +36,7 @@ fun TranslatableRichTextViewer(
tags: ImmutableListOfLists<String>, tags: ImmutableListOfLists<String>,
backgroundColor: MutableState<Color>, backgroundColor: MutableState<Color>,
id: String, id: String,
callbackUri: String? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit, nav: (String) -> Unit,
) = ExpandableRichTextViewer( ) = ExpandableRichTextViewer(
@@ -46,6 +47,7 @@ fun TranslatableRichTextViewer(
tags, tags,
backgroundColor, backgroundColor,
id, id,
callbackUri,
accountViewModel, accountViewModel,
nav, nav,
) )
@@ -31,11 +31,12 @@ object CachedRichTextParser {
fun parseText( fun parseText(
content: String, content: String,
tags: ImmutableListOfLists<String>, tags: ImmutableListOfLists<String>,
callbackUri: String? = null,
): RichTextViewerState { ): RichTextViewerState {
return if (richTextCache[content] != null) { return if (richTextCache[content] != null) {
richTextCache[content] richTextCache[content]
} else { } else {
val newUrls = RichTextParser().parseText(content, tags) val newUrls = RichTextParser().parseText(content, tags, callbackUri)
richTextCache.put(content, newUrls) richTextCache.put(content, newUrls)
newUrls newUrls
} }
@@ -308,7 +308,7 @@ fun EditPostView(
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
) )
} else { } else {
LoadUrlPreview(myUrlPreview, myUrlPreview, accountViewModel) LoadUrlPreview(myUrlPreview, myUrlPreview, null, accountViewModel)
} }
} else if (RichTextParser.startsWithNIP19Scheme(myUrlPreview)) { } else if (RichTextParser.startsWithNIP19Scheme(myUrlPreview)) {
val bgColor = MaterialTheme.colorScheme.background val bgColor = MaterialTheme.colorScheme.background
@@ -323,7 +323,7 @@ fun EditPostView(
nav = nav, nav = nav,
) )
} else if (RichTextParser.isUrlWithoutScheme(myUrlPreview)) { } else if (RichTextParser.isUrlWithoutScheme(myUrlPreview)) {
LoadUrlPreview("https://$myUrlPreview", myUrlPreview, accountViewModel) LoadUrlPreview("https://$myUrlPreview", myUrlPreview, null, accountViewModel)
} }
} }
} }
@@ -429,7 +429,7 @@ fun NewPostView(
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
) )
} else { } else {
LoadUrlPreview(myUrlPreview, myUrlPreview, accountViewModel) LoadUrlPreview(myUrlPreview, myUrlPreview, null, accountViewModel)
} }
} else if (RichTextParser.startsWithNIP19Scheme(myUrlPreview)) { } else if (RichTextParser.startsWithNIP19Scheme(myUrlPreview)) {
val bgColor = MaterialTheme.colorScheme.background val bgColor = MaterialTheme.colorScheme.background
@@ -444,7 +444,7 @@ fun NewPostView(
nav = nav, nav = nav,
) )
} else if (RichTextParser.isUrlWithoutScheme(myUrlPreview)) { } else if (RichTextParser.isUrlWithoutScheme(myUrlPreview)) {
LoadUrlPreview("https://$myUrlPreview", myUrlPreview, accountViewModel) LoadUrlPreview("https://$myUrlPreview", myUrlPreview, null, accountViewModel)
} }
} }
} }
@@ -63,15 +63,16 @@ fun NotifyRequestDialog(
val background = remember { mutableStateOf(defaultBackground) } val background = remember { mutableStateOf(defaultBackground) }
TranslatableRichTextViewer( TranslatableRichTextViewer(
textContent, content = textContent,
canPreview = true, canPreview = true,
quotesLeft = 1, quotesLeft = 1,
Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
EmptyTagList, tags = EmptyTagList,
background, backgroundColor = background,
textContent, id = textContent,
accountViewModel, callbackUri = null,
nav, accountViewModel = accountViewModel,
nav = nav,
) )
}, },
confirmButton = { confirmButton = {
@@ -64,6 +64,7 @@ fun ExpandableRichTextViewer(
tags: ImmutableListOfLists<String>, tags: ImmutableListOfLists<String>,
backgroundColor: MutableState<Color>, backgroundColor: MutableState<Color>,
id: String, id: String,
callbackUri: String? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit, nav: (String) -> Unit,
) { ) {
@@ -99,6 +100,7 @@ fun ExpandableRichTextViewer(
modifier.align(Alignment.TopStart), modifier.align(Alignment.TopStart),
tags, tags,
backgroundColor, backgroundColor,
callbackUri,
accountViewModel, accountViewModel,
nav, nav,
) )
@@ -37,6 +37,7 @@ import com.vitorpamplona.amethyst.ui.theme.HalfVertPadding
fun LoadUrlPreview( fun LoadUrlPreview(
url: String, url: String,
urlText: String, urlText: String,
callbackUri: String? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
) { ) {
val automaticallyShowUrlPreview = remember { accountViewModel.settings.showUrlPreview.value } val automaticallyShowUrlPreview = remember { accountViewModel.settings.showUrlPreview.value }
@@ -61,7 +62,7 @@ fun LoadUrlPreview(
) { state -> ) { state ->
when (state) { when (state) {
is UrlPreviewState.Loaded -> { is UrlPreviewState.Loaded -> {
RenderLoaded(state, url, accountViewModel) RenderLoaded(state, url, callbackUri, accountViewModel)
} }
else -> { else -> {
ClickableUrl(urlText, url) ClickableUrl(urlText, url)
@@ -75,12 +76,13 @@ fun LoadUrlPreview(
fun RenderLoaded( fun RenderLoaded(
state: UrlPreviewState.Loaded, state: UrlPreviewState.Loaded,
url: String, url: String,
callbackUri: String? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
) { ) {
if (state.previewInfo.mimeType.type == "image") { if (state.previewInfo.mimeType.type == "image") {
Box(modifier = HalfVertPadding) { Box(modifier = HalfVertPadding) {
ZoomableContentView( ZoomableContentView(
content = MediaUrlImage(url), content = MediaUrlImage(url, uri = callbackUri),
roundedCorner = true, roundedCorner = true,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
) )
@@ -88,7 +90,7 @@ fun RenderLoaded(
} else if (state.previewInfo.mimeType.type == "video") { } else if (state.previewInfo.mimeType.type == "video") {
Box(modifier = HalfVertPadding) { Box(modifier = HalfVertPadding) {
ZoomableContentView( ZoomableContentView(
content = MediaUrlVideo(url), content = MediaUrlVideo(url, uri = callbackUri),
roundedCorner = true, roundedCorner = true,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
) )
@@ -121,14 +121,15 @@ fun RichTextViewer(
modifier: Modifier, modifier: Modifier,
tags: ImmutableListOfLists<String>, tags: ImmutableListOfLists<String>,
backgroundColor: MutableState<Color>, backgroundColor: MutableState<Color>,
callbackUri: String? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit, nav: (String) -> Unit,
) { ) {
Column(modifier = modifier) { Column(modifier = modifier) {
if (remember(content) { isMarkdown(content) }) { if (remember(content) { isMarkdown(content) }) {
RenderContentAsMarkdown(content, tags, canPreview, quotesLeft, backgroundColor, accountViewModel, nav) RenderContentAsMarkdown(content, tags, canPreview, quotesLeft, backgroundColor, callbackUri, accountViewModel, nav)
} else { } else {
RenderRegular(content, tags, canPreview, quotesLeft, backgroundColor, accountViewModel, nav) RenderRegular(content, tags, canPreview, quotesLeft, backgroundColor, callbackUri, accountViewModel, nav)
} }
} }
} }
@@ -267,7 +268,7 @@ fun RenderRegularPreview3() {
) { word, state -> ) { word, state ->
when (word) { when (word) {
// is ImageSegment -> ZoomableContentView(word.segmentText, state, accountViewModel) // is ImageSegment -> ZoomableContentView(word.segmentText, state, accountViewModel)
is LinkSegment -> LoadUrlPreview(word.segmentText, word.segmentText, accountViewModel) is LinkSegment -> LoadUrlPreview(word.segmentText, word.segmentText, null, accountViewModel)
is EmojiSegment -> RenderCustomEmoji(word.segmentText, state) is EmojiSegment -> RenderCustomEmoji(word.segmentText, state)
is InvoiceSegment -> MayBeInvoicePreview(word.segmentText) is InvoiceSegment -> MayBeInvoicePreview(word.segmentText)
is WithdrawSegment -> MayBeWithdrawal(word.segmentText) is WithdrawSegment -> MayBeWithdrawal(word.segmentText)
@@ -291,16 +292,18 @@ private fun RenderRegular(
canPreview: Boolean, canPreview: Boolean,
quotesLeft: Int, quotesLeft: Int,
backgroundColor: MutableState<Color>, backgroundColor: MutableState<Color>,
callbackUri: String? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit, nav: (String) -> Unit,
) { ) {
RenderRegular(content, tags) { word, state -> RenderRegular(content, tags, callbackUri) { word, state ->
if (canPreview) { if (canPreview) {
RenderWordWithPreview( RenderWordWithPreview(
word, word,
state, state,
backgroundColor, backgroundColor,
quotesLeft, quotesLeft,
callbackUri,
accountViewModel, accountViewModel,
nav, nav,
) )
@@ -321,9 +324,10 @@ private fun RenderRegular(
fun RenderRegular( fun RenderRegular(
content: String, content: String,
tags: ImmutableListOfLists<String>, tags: ImmutableListOfLists<String>,
callbackUri: String? = null,
wordRenderer: @Composable (Segment, RichTextViewerState) -> Unit, wordRenderer: @Composable (Segment, RichTextViewerState) -> Unit,
) { ) {
val state by remember(content, tags) { mutableStateOf(CachedRichTextParser.parseText(content, tags)) } val state by remember(content, tags) { mutableStateOf(CachedRichTextParser.parseText(content, tags, callbackUri)) }
val spaceWidth = measureSpaceWidth(LocalTextStyle.current) val spaceWidth = measureSpaceWidth(LocalTextStyle.current)
@@ -412,12 +416,13 @@ private fun RenderWordWithPreview(
state: RichTextViewerState, state: RichTextViewerState,
backgroundColor: MutableState<Color>, backgroundColor: MutableState<Color>,
quotesLeft: Int, quotesLeft: Int,
callbackUri: String? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit, nav: (String) -> Unit,
) { ) {
when (word) { when (word) {
is ImageSegment -> ZoomableContentView(word.segmentText, state, accountViewModel) is ImageSegment -> ZoomableContentView(word.segmentText, state, accountViewModel)
is LinkSegment -> LoadUrlPreview(word.segmentText, word.segmentText, accountViewModel) is LinkSegment -> LoadUrlPreview(word.segmentText, word.segmentText, callbackUri, accountViewModel)
is EmojiSegment -> RenderCustomEmoji(word.segmentText, state) is EmojiSegment -> RenderCustomEmoji(word.segmentText, state)
is InvoiceSegment -> MayBeInvoicePreview(word.segmentText) is InvoiceSegment -> MayBeInvoicePreview(word.segmentText)
is WithdrawSegment -> MayBeWithdrawal(word.segmentText) is WithdrawSegment -> MayBeWithdrawal(word.segmentText)
@@ -542,15 +542,13 @@ fun GetVideoController(
} }
} }
if (event == Lifecycle.Event.ON_PAUSE) { if (event == Lifecycle.Event.ON_PAUSE) {
GlobalScope.launch(Dispatchers.Main) { if (!keepPlaying.value) {
if (!keepPlaying.value) { // Stops and releases the media.
// Stops and releases the media. controller.value?.let {
controller.value?.let { Log.d("PlaybackService", "Releasing Video from Pause $videoUri ")
Log.d("PlaybackService", "Releasing Video from Pause $videoUri ") it.stop()
it.stop() it.release()
it.release() controller.value = null
controller.value = null
}
} }
} }
} }
@@ -57,6 +57,7 @@ class MarkdownMediaRenderer(
val canPreview: Boolean, val canPreview: Boolean,
val quotesLeft: Int, val quotesLeft: Int,
val backgroundColor: MutableState<Color>, val backgroundColor: MutableState<Color>,
val callbackUri: String? = null,
val accountViewModel: AccountViewModel, val accountViewModel: AccountViewModel,
val nav: (String) -> Unit, val nav: (String) -> Unit,
) : MediaRenderer { ) : MediaRenderer {
@@ -107,7 +108,7 @@ class MarkdownMediaRenderer(
uri: String, uri: String,
richTextStringBuilder: RichTextString.Builder, richTextStringBuilder: RichTextString.Builder,
) { ) {
val content = parser.parseMediaUrl(uri, eventTags = tags ?: EmptyTagList, startOfText) val content = parser.parseMediaUrl(uri, eventTags = tags ?: EmptyTagList, startOfText, callbackUri)
if (canPreview) { if (canPreview) {
if (content != null) { if (content != null) {
@@ -123,7 +124,7 @@ class MarkdownMediaRenderer(
renderAsCompleteLink(title ?: uri, uri, richTextStringBuilder) renderAsCompleteLink(title ?: uri, uri, richTextStringBuilder)
} else { } else {
renderInlineFullWidth(richTextStringBuilder) { renderInlineFullWidth(richTextStringBuilder) {
LoadUrlPreview(uri, title ?: uri, accountViewModel) LoadUrlPreview(uri, title ?: uri, callbackUri, accountViewModel)
} }
} }
} }
@@ -44,6 +44,7 @@ fun RenderContentAsMarkdown(
canPreview: Boolean, canPreview: Boolean,
quotesLeft: Int, quotesLeft: Int,
backgroundColor: MutableState<Color>, backgroundColor: MutableState<Color>,
callbackUri: String? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit, nav: (String) -> Unit,
) { ) {
@@ -70,13 +71,14 @@ fun RenderContentAsMarkdown(
val renderer = val renderer =
remember(content) { remember(content) {
MarkdownMediaRenderer( MarkdownMediaRenderer(
content.take(100), startOfText = content.take(100),
tags, tags = tags,
canPreview, canPreview = canPreview,
quotesLeft, quotesLeft = quotesLeft,
backgroundColor, backgroundColor = backgroundColor,
accountViewModel, callbackUri = callbackUri,
nav, accountViewModel = accountViewModel,
nav = nav,
) )
} }
@@ -396,9 +396,12 @@ fun AppNavigation(
LaunchedEffect(intentNextPage) { LaunchedEffect(intentNextPage) {
if (actionableNextPage != null) { if (actionableNextPage != null) {
actionableNextPage?.let { actionableNextPage?.let {
navController.navigate(it) { val currentRoute = getRouteWithArguments(navController)
popUpTo(Route.Home.route) if (!isSameRoute(currentRoute, it)) {
launchSingleTop = true navController.navigate(it) {
popUpTo(Route.Home.route)
launchSingleTop = true
}
} }
actionableNextPage = null actionableNextPage = null
} }
@@ -642,6 +642,7 @@ private fun RenderRegularTextNote(
tags = tags, tags = tags,
backgroundColor = backgroundBubbleColor, backgroundColor = backgroundBubbleColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(),
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -655,6 +656,7 @@ private fun RenderRegularTextNote(
tags = EmptyTagList, tags = EmptyTagList,
backgroundColor = backgroundBubbleColor, backgroundColor = backgroundBubbleColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(),
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -179,6 +179,7 @@ private fun OptionNote(
pollViewModel = pollViewModel, pollViewModel = pollViewModel,
nonClickablePrepend = { nonClickablePrepend = {
RenderOptionAfterVote( RenderOptionAfterVote(
baseNote,
poolOption, poolOption,
color, color,
canPreview, canPreview,
@@ -217,6 +218,7 @@ private fun OptionNote(
@Composable @Composable
private fun RenderOptionAfterVote( private fun RenderOptionAfterVote(
baseNote: Note,
poolOption: PollOption, poolOption: PollOption,
color: Color, color: Color,
canPreview: Boolean, canPreview: Boolean,
@@ -276,7 +278,8 @@ private fun RenderOptionAfterVote(
Modifier, Modifier,
tags, tags,
backgroundColor, backgroundColor,
poolOption.descriptor, baseNote.idHex + poolOption.descriptor,
baseNote.toNostrUri(),
accountViewModel, accountViewModel,
nav, nav,
) )
@@ -236,6 +236,7 @@ fun RenderAppDefinition(
tags = tags, tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(),
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -220,6 +220,7 @@ fun AudioHeader(
tags = tags, tags = tags,
backgroundColor = background, backgroundColor = background,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(),
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -188,6 +188,7 @@ private fun RenderGitPatchEvent(
tags = tags, tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(),
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -291,6 +292,7 @@ private fun RenderGitIssueEvent(
tags = tags, tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(),
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -100,15 +100,16 @@ fun DisplayHighlight(
} }
TranslatableRichTextViewer( TranslatableRichTextViewer(
quote, content = quote,
canPreview = canPreview && !makeItShort, canPreview = canPreview && !makeItShort,
quotesLeft, quotesLeft = quotesLeft,
Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
EmptyTagList, tags = EmptyTagList,
backgroundColor, backgroundColor = backgroundColor,
id = quote, id = quote,
accountViewModel, callbackUri = null,
nav, accountViewModel = accountViewModel,
nav = nav,
) )
DisplayQuoteAuthor(authorHex ?: "", url, postAddress, accountViewModel, nav) DisplayQuoteAuthor(authorHex ?: "", url, postAddress, accountViewModel, nav)
@@ -138,6 +138,7 @@ fun RenderNIP90ContentDiscoveryResponse(
tags = tags, tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(),
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -41,7 +41,6 @@ import com.vitorpamplona.amethyst.ui.note.elements.DisplayUncitedHashtags
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
import com.vitorpamplona.amethyst.ui.theme.placeholderText import com.vitorpamplona.amethyst.ui.theme.placeholderText
import com.vitorpamplona.quartz.events.BaseTextNoteEvent
import com.vitorpamplona.quartz.events.CommunityDefinitionEvent import com.vitorpamplona.quartz.events.CommunityDefinitionEvent
import com.vitorpamplona.quartz.events.EmptyTagList import com.vitorpamplona.quartz.events.EmptyTagList
import com.vitorpamplona.quartz.events.PollNoteEvent import com.vitorpamplona.quartz.events.PollNoteEvent
@@ -65,22 +64,18 @@ fun RenderPoll(
val showReply by val showReply by
remember(note) { remember(note) {
derivedStateOf { derivedStateOf {
noteEvent is BaseTextNoteEvent && !makeItShort && unPackReply && (note.replyTo != null || noteEvent.hasAnyTaggedUser()) !makeItShort && unPackReply && (note.replyTo != null || noteEvent.hasAnyTaggedUser())
} }
} }
if (showReply) { if (showReply) {
val replyingDirectlyTo = val replyingDirectlyTo =
remember(note) { remember(note) {
if (noteEvent is BaseTextNoteEvent) { val replyingTo = noteEvent.replyingToAddressOrEvent()
val replyingTo = noteEvent.replyingToAddressOrEvent() if (replyingTo != null) {
if (replyingTo != null) { val newNote = accountViewModel.getNoteIfExists(replyingTo)
val newNote = accountViewModel.getNoteIfExists(replyingTo) if (newNote != null && newNote.channelHex() == null && newNote.event?.kind() != CommunityDefinitionEvent.KIND) {
if (newNote != null && newNote.channelHex() == null && newNote.event?.kind() != CommunityDefinitionEvent.KIND) { newNote
newNote
} else {
note.replyTo?.lastOrNull { it.event?.kind() != CommunityDefinitionEvent.KIND }
}
} else { } else {
note.replyTo?.lastOrNull { it.event?.kind() != CommunityDefinitionEvent.KIND } note.replyTo?.lastOrNull { it.event?.kind() != CommunityDefinitionEvent.KIND }
} }
@@ -116,6 +111,7 @@ fun RenderPoll(
tags = tags, tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(),
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -115,6 +115,7 @@ fun RenderPrivateMessage(
tags = tags, tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(),
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -144,6 +145,7 @@ fun RenderPrivateMessage(
tags = EmptyTagList, tags = EmptyTagList,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(),
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -76,6 +76,7 @@ fun RenderReport(
tags = EmptyTagList, tags = EmptyTagList,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(),
quotesLeft = 1, quotesLeft = 1,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
@@ -149,6 +149,7 @@ fun RenderTextEvent(
tags = tags, tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(),
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -119,6 +119,7 @@ fun RenderTextModificationEvent(
tags = EmptyTagList, tags = EmptyTagList,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(),
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -169,6 +169,7 @@ fun VideoDisplay(
tags = tags, tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = note.idHex, id = note.idHex,
callbackUri = note.toNostrUri(),
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -77,6 +77,7 @@ fun TranslatableRichTextViewer(
tags: ImmutableListOfLists<String>, tags: ImmutableListOfLists<String>,
backgroundColor: MutableState<Color>, backgroundColor: MutableState<Color>,
id: String, id: String,
callbackUri: String? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit, nav: (String) -> Unit,
) { ) {
@@ -103,6 +104,7 @@ fun TranslatableRichTextViewer(
tags = tags, tags = tags,
backgroundColor = backgroundColor, backgroundColor = backgroundColor,
id = id, id = id,
callbackUri = callbackUri,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -119,6 +121,7 @@ private fun RenderText(
tags: ImmutableListOfLists<String>, tags: ImmutableListOfLists<String>,
backgroundColor: MutableState<Color>, backgroundColor: MutableState<Color>,
id: String, id: String,
callbackUri: String? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: (String) -> Unit, nav: (String) -> Unit,
) { ) {
@@ -139,6 +142,7 @@ private fun RenderText(
tags, tags,
backgroundColor, backgroundColor,
id, id,
callbackUri,
accountViewModel, accountViewModel,
nav, nav,
) )
@@ -46,6 +46,7 @@ class RichTextParser() {
fullUrl: String, fullUrl: String,
eventTags: ImmutableListOfLists<String>, eventTags: ImmutableListOfLists<String>,
description: String?, description: String?,
callbackUri: String? = null,
): MediaUrlContent? { ): MediaUrlContent? {
val removedParamsFromUrl = removeQueryParamsForExtensionComparison(fullUrl) val removedParamsFromUrl = removeQueryParamsForExtensionComparison(fullUrl)
return if (imageExtensions.any { removedParamsFromUrl.endsWith(it) }) { return if (imageExtensions.any { removedParamsFromUrl.endsWith(it) }) {
@@ -59,6 +60,7 @@ class RichTextParser() {
blurhash = frags[FileHeaderEvent.BLUR_HASH] ?: tags[FileHeaderEvent.BLUR_HASH], blurhash = frags[FileHeaderEvent.BLUR_HASH] ?: tags[FileHeaderEvent.BLUR_HASH],
dim = frags[FileHeaderEvent.DIMENSION] ?: tags[FileHeaderEvent.DIMENSION], dim = frags[FileHeaderEvent.DIMENSION] ?: tags[FileHeaderEvent.DIMENSION],
contentWarning = frags["content-warning"] ?: tags["content-warning"], contentWarning = frags["content-warning"] ?: tags["content-warning"],
uri = callbackUri,
) )
} else if (videoExtensions.any { removedParamsFromUrl.endsWith(it) }) { } else if (videoExtensions.any { removedParamsFromUrl.endsWith(it) }) {
val frags = Nip54InlineMetadata().parse(fullUrl) val frags = Nip54InlineMetadata().parse(fullUrl)
@@ -70,6 +72,7 @@ class RichTextParser() {
blurhash = frags[FileHeaderEvent.BLUR_HASH] ?: tags[FileHeaderEvent.BLUR_HASH], blurhash = frags[FileHeaderEvent.BLUR_HASH] ?: tags[FileHeaderEvent.BLUR_HASH],
dim = frags[FileHeaderEvent.DIMENSION] ?: tags[FileHeaderEvent.DIMENSION], dim = frags[FileHeaderEvent.DIMENSION] ?: tags[FileHeaderEvent.DIMENSION],
contentWarning = frags["content-warning"] ?: tags["content-warning"], contentWarning = frags["content-warning"] ?: tags["content-warning"],
uri = callbackUri,
) )
} else { } else {
null null
@@ -103,11 +106,12 @@ class RichTextParser() {
fun parseText( fun parseText(
content: String, content: String,
tags: ImmutableListOfLists<String>, tags: ImmutableListOfLists<String>,
callbackUri: String?,
): RichTextViewerState { ): RichTextViewerState {
val urlSet = parseValidUrls(content) val urlSet = parseValidUrls(content)
val imagesForPager = val imagesForPager =
urlSet.mapNotNull { fullUrl -> parseMediaUrl(fullUrl, tags, content) }.associateBy { it.url } urlSet.mapNotNull { fullUrl -> parseMediaUrl(fullUrl, tags, content, callbackUri) }.associateBy { it.url }
val imageList = imagesForPager.values.toList() val imageList = imagesForPager.values.toList()
val emojiMap = Nip30CustomEmoji.createEmojiMap(tags) val emojiMap = Nip30CustomEmoji.createEmojiMap(tags)