Preparing to move Kind1 content parsers to commons.
This commit is contained in:
@@ -21,8 +21,8 @@
|
|||||||
package com.vitorpamplona.amethyst
|
package com.vitorpamplona.amethyst
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
import com.vitorpamplona.amethyst.service.RichTextParser
|
import com.vitorpamplona.amethyst.commons.RichTextParser
|
||||||
import com.vitorpamplona.amethyst.service.RichTextViewerState
|
import com.vitorpamplona.amethyst.commons.RichTextViewerState
|
||||||
import com.vitorpamplona.quartz.events.EmptyTagList
|
import com.vitorpamplona.quartz.events.EmptyTagList
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|||||||
@@ -20,45 +20,10 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.amethyst.service
|
package com.vitorpamplona.amethyst.service
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import android.util.LruCache
|
import android.util.LruCache
|
||||||
import android.util.Patterns
|
import com.vitorpamplona.amethyst.commons.RichTextParser
|
||||||
import androidx.compose.runtime.Immutable
|
import com.vitorpamplona.amethyst.commons.RichTextViewerState
|
||||||
import com.linkedin.urls.detection.UrlDetector
|
|
||||||
import com.linkedin.urls.detection.UrlDetectorOptions
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.ZoomableUrlContent
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.ZoomableUrlImage
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.ZoomableUrlVideo
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.hashTagsPattern
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.imageExtensions
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.removeQueryParamsForExtensionComparison
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.tagIndex
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.videoExtensions
|
|
||||||
import com.vitorpamplona.quartz.encoders.Nip54
|
|
||||||
import com.vitorpamplona.quartz.encoders.Nip92
|
|
||||||
import com.vitorpamplona.quartz.events.FileHeaderEvent
|
|
||||||
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
||||||
import kotlinx.collections.immutable.ImmutableList
|
|
||||||
import kotlinx.collections.immutable.ImmutableMap
|
|
||||||
import kotlinx.collections.immutable.ImmutableSet
|
|
||||||
import kotlinx.collections.immutable.persistentListOf
|
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
|
||||||
import kotlinx.collections.immutable.toImmutableMap
|
|
||||||
import kotlinx.collections.immutable.toImmutableSet
|
|
||||||
import kotlinx.collections.immutable.toPersistentList
|
|
||||||
import kotlinx.coroutines.CancellationException
|
|
||||||
import java.util.regex.Pattern
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
data class RichTextViewerState(
|
|
||||||
val urlSet: ImmutableSet<String>,
|
|
||||||
val imagesForPager: ImmutableMap<String, ZoomableUrlContent>,
|
|
||||||
val imageList: ImmutableList<ZoomableUrlContent>,
|
|
||||||
val customEmoji: ImmutableMap<String, String>,
|
|
||||||
val paragraphs: ImmutableList<ParagraphState>,
|
|
||||||
)
|
|
||||||
|
|
||||||
data class ParagraphState(val words: ImmutableList<Segment>, val isRTL: Boolean)
|
|
||||||
|
|
||||||
object CachedRichTextParser {
|
object CachedRichTextParser {
|
||||||
val richTextCache = LruCache<String, RichTextViewerState>(200)
|
val richTextCache = LruCache<String, RichTextViewerState>(200)
|
||||||
@@ -76,298 +41,3 @@ object CachedRichTextParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Group 1 = url, group 4 additional chars
|
|
||||||
// val noProtocolUrlValidator =
|
|
||||||
// Pattern.compile("(([\\w\\d-]+\\.)*[a-zA-Z][\\w-]+[\\.\\:]\\w+([\\/\\?\\=\\&\\#\\.]?[\\w-]+)*\\/?)(.*)")
|
|
||||||
|
|
||||||
// Android9 seems to have an issue starting this regex.
|
|
||||||
val noProtocolUrlValidator =
|
|
||||||
try {
|
|
||||||
Pattern.compile(
|
|
||||||
"(([\\w\\d-]+\\.)*[a-zA-Z][\\w-]+[\\.\\:]\\w+([\\/\\?\\=\\&\\#\\.]?[\\w-]+[^\\p{IsHan}\\p{IsHiragana}\\p{IsKatakana}])*\\/?)(.*)",
|
|
||||||
)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Pattern.compile(
|
|
||||||
"(([\\w\\d-]+\\.)*[a-zA-Z][\\w-]+[\\.\\:]\\w+([\\/\\?\\=\\&\\#\\.]?[\\w-]+)*\\/?)(.*)",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
val HTTPRegex =
|
|
||||||
"^((http|https)://)?([A-Za-z0-9-_]+(\\.[A-Za-z0-9-_]+)+)(:[0-9]+)?(/[^?#]*)?(\\?[^#]*)?(#.*)?"
|
|
||||||
.toRegex(RegexOption.IGNORE_CASE)
|
|
||||||
|
|
||||||
class RichTextParser() {
|
|
||||||
fun parseMediaUrl(
|
|
||||||
fullUrl: String,
|
|
||||||
eventTags: ImmutableListOfLists<String>,
|
|
||||||
): ZoomableUrlContent? {
|
|
||||||
val removedParamsFromUrl = removeQueryParamsForExtensionComparison(fullUrl)
|
|
||||||
return if (imageExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
|
||||||
val frags = Nip54().parse(fullUrl)
|
|
||||||
val tags = Nip92().parse(fullUrl, eventTags.lists)
|
|
||||||
|
|
||||||
ZoomableUrlImage(
|
|
||||||
url = fullUrl,
|
|
||||||
description = frags[FileHeaderEvent.ALT] ?: tags[FileHeaderEvent.ALT],
|
|
||||||
hash = frags[FileHeaderEvent.HASH] ?: tags[FileHeaderEvent.HASH],
|
|
||||||
blurhash = frags[FileHeaderEvent.BLUR_HASH] ?: tags[FileHeaderEvent.BLUR_HASH],
|
|
||||||
dim = frags[FileHeaderEvent.DIMENSION] ?: tags[FileHeaderEvent.DIMENSION],
|
|
||||||
contentWarning = frags["content-warning"] ?: tags["content-warning"],
|
|
||||||
)
|
|
||||||
} else if (videoExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
|
||||||
val frags = Nip54().parse(fullUrl)
|
|
||||||
val tags = Nip92().parse(fullUrl, eventTags.lists)
|
|
||||||
ZoomableUrlVideo(
|
|
||||||
url = fullUrl,
|
|
||||||
description = frags[FileHeaderEvent.ALT] ?: tags[FileHeaderEvent.ALT],
|
|
||||||
hash = frags[FileHeaderEvent.HASH] ?: tags[FileHeaderEvent.HASH],
|
|
||||||
blurhash = frags[FileHeaderEvent.BLUR_HASH] ?: tags[FileHeaderEvent.BLUR_HASH],
|
|
||||||
dim = frags[FileHeaderEvent.DIMENSION] ?: tags[FileHeaderEvent.DIMENSION],
|
|
||||||
contentWarning = frags["content-warning"] ?: tags["content-warning"],
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun parseText(
|
|
||||||
content: String,
|
|
||||||
tags: ImmutableListOfLists<String>,
|
|
||||||
): RichTextViewerState {
|
|
||||||
val urls = UrlDetector(content, UrlDetectorOptions.Default).detect()
|
|
||||||
|
|
||||||
val urlSet =
|
|
||||||
urls.mapNotNullTo(LinkedHashSet(urls.size)) {
|
|
||||||
// removes e-mails
|
|
||||||
if (Patterns.EMAIL_ADDRESS.matcher(it.originalUrl).matches()) {
|
|
||||||
null
|
|
||||||
} else if (isNumber(it.originalUrl)) {
|
|
||||||
null
|
|
||||||
} else if (it.originalUrl.contains("。")) {
|
|
||||||
null
|
|
||||||
} else {
|
|
||||||
if (HTTPRegex.matches(it.originalUrl)) {
|
|
||||||
it.originalUrl
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val imagesForPager =
|
|
||||||
urlSet.mapNotNull { fullUrl -> parseMediaUrl(fullUrl, tags) }.associateBy { it.url }
|
|
||||||
val imageList = imagesForPager.values.toList()
|
|
||||||
|
|
||||||
val emojiMap =
|
|
||||||
tags.lists.filter { it.size > 2 && it[0] == "emoji" }.associate { ":${it[1]}:" to it[2] }
|
|
||||||
|
|
||||||
val segments = findTextSegments(content, imagesForPager.keys, urlSet, emojiMap, tags)
|
|
||||||
|
|
||||||
return RichTextViewerState(
|
|
||||||
urlSet.toImmutableSet(),
|
|
||||||
imagesForPager.toImmutableMap(),
|
|
||||||
imageList.toImmutableList(),
|
|
||||||
emojiMap.toImmutableMap(),
|
|
||||||
segments,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun findTextSegments(
|
|
||||||
content: String,
|
|
||||||
images: Set<String>,
|
|
||||||
urls: Set<String>,
|
|
||||||
emojis: Map<String, String>,
|
|
||||||
tags: ImmutableListOfLists<String>,
|
|
||||||
): ImmutableList<ParagraphState> {
|
|
||||||
val lines = content.split('\n')
|
|
||||||
val paragraphSegments = ArrayList<ParagraphState>(lines.size)
|
|
||||||
|
|
||||||
lines.forEach { paragraph ->
|
|
||||||
var isDirty = false
|
|
||||||
val isRTL = isArabic(paragraph)
|
|
||||||
|
|
||||||
val wordList = paragraph.trimEnd().split(' ')
|
|
||||||
val segments = ArrayList<Segment>(wordList.size)
|
|
||||||
wordList.forEach { word ->
|
|
||||||
val wordSegment = wordIdentifier(word, images, urls, emojis, tags)
|
|
||||||
if (wordSegment !is RegularTextSegment) {
|
|
||||||
isDirty = true
|
|
||||||
}
|
|
||||||
segments.add(wordSegment)
|
|
||||||
}
|
|
||||||
|
|
||||||
val newSegments =
|
|
||||||
if (isDirty) {
|
|
||||||
ParagraphState(segments.toPersistentList(), isRTL)
|
|
||||||
} else {
|
|
||||||
ParagraphState(persistentListOf<Segment>(RegularTextSegment(paragraph)), isRTL)
|
|
||||||
}
|
|
||||||
|
|
||||||
paragraphSegments.add(newSegments)
|
|
||||||
}
|
|
||||||
|
|
||||||
return paragraphSegments.toImmutableList()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun isNumber(word: String): Boolean {
|
|
||||||
return numberPattern.matcher(word).matches()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun isDate(word: String): Boolean {
|
|
||||||
return shortDatePattern.matcher(word).matches() || longDatePattern.matcher(word).matches()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun isArabic(text: String): Boolean {
|
|
||||||
return text.any { it in '\u0600'..'\u06FF' || it in '\u0750'..'\u077F' }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun wordIdentifier(
|
|
||||||
word: String,
|
|
||||||
images: Set<String>,
|
|
||||||
urls: Set<String>,
|
|
||||||
emojis: Map<String, String>,
|
|
||||||
tags: ImmutableListOfLists<String>,
|
|
||||||
): Segment {
|
|
||||||
val emailMatcher = Patterns.EMAIL_ADDRESS.matcher(word)
|
|
||||||
val phoneMatcher = Patterns.PHONE.matcher(word)
|
|
||||||
val schemelessMatcher = noProtocolUrlValidator.matcher(word)
|
|
||||||
|
|
||||||
return if (word.isEmpty()) {
|
|
||||||
RegularTextSegment(word)
|
|
||||||
} else if (images.contains(word)) {
|
|
||||||
ImageSegment(word)
|
|
||||||
} else if (urls.contains(word)) {
|
|
||||||
LinkSegment(word)
|
|
||||||
} else if (emojis.any { word.contains(it.key) }) {
|
|
||||||
EmojiSegment(word)
|
|
||||||
} else if (word.startsWith("lnbc", true)) {
|
|
||||||
InvoiceSegment(word)
|
|
||||||
} else if (word.startsWith("lnurl", true)) {
|
|
||||||
WithdrawSegment(word)
|
|
||||||
} else if (word.startsWith("cashuA", true)) {
|
|
||||||
CashuSegment(word)
|
|
||||||
} else if (emailMatcher.matches()) {
|
|
||||||
EmailSegment(word)
|
|
||||||
} else if (word.length in 7..14 && !isDate(word) && phoneMatcher.matches()) {
|
|
||||||
PhoneSegment(word)
|
|
||||||
} else if (startsWithNIP19Scheme(word)) {
|
|
||||||
BechSegment(word)
|
|
||||||
} else if (word.startsWith("#")) {
|
|
||||||
parseHash(word, tags)
|
|
||||||
} else if (word.contains(".") && schemelessMatcher.find()) {
|
|
||||||
val url = schemelessMatcher.group(1) // url
|
|
||||||
val additionalChars = schemelessMatcher.group(4).ifEmpty { null } // additional chars
|
|
||||||
val pattern =
|
|
||||||
"""^([A-Za-z0-9-_]+(\.[A-Za-z0-9-_]+)+)(:[0-9]+)?(/[^?#]*)?(\?[^#]*)?(#.*)?"""
|
|
||||||
.toRegex(RegexOption.IGNORE_CASE)
|
|
||||||
if (pattern.find(word) != null) {
|
|
||||||
SchemelessUrlSegment(word, url, additionalChars)
|
|
||||||
} else {
|
|
||||||
RegularTextSegment(word)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
RegularTextSegment(word)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun parseHash(
|
|
||||||
word: String,
|
|
||||||
tags: ImmutableListOfLists<String>,
|
|
||||||
): Segment {
|
|
||||||
// First #[n]
|
|
||||||
|
|
||||||
val matcher = tagIndex.matcher(word)
|
|
||||||
try {
|
|
||||||
if (matcher.find()) {
|
|
||||||
val index = matcher.group(1)?.toInt()
|
|
||||||
val suffix = matcher.group(2)
|
|
||||||
|
|
||||||
if (index != null && index >= 0 && index < tags.lists.size) {
|
|
||||||
val tag = tags.lists[index]
|
|
||||||
|
|
||||||
if (tag.size > 1) {
|
|
||||||
if (tag[0] == "p") {
|
|
||||||
return HashIndexUserSegment(word, tag[1], suffix)
|
|
||||||
} else if (tag[0] == "e" || tag[0] == "a") {
|
|
||||||
return HashIndexEventSegment(word, tag[1], suffix)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
if (e is CancellationException) throw e
|
|
||||||
Log.w("Tag Parser", "Couldn't link tag $word", e)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Second #Amethyst
|
|
||||||
val hashtagMatcher = hashTagsPattern.matcher(word)
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (hashtagMatcher.find()) {
|
|
||||||
val hashtag = hashtagMatcher.group(1)
|
|
||||||
if (hashtag != null) {
|
|
||||||
return HashTagSegment(word, hashtag, hashtagMatcher.group(2).ifEmpty { null })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
if (e is CancellationException) throw e
|
|
||||||
Log.e("Hashtag Parser", "Couldn't link hashtag $word", e)
|
|
||||||
}
|
|
||||||
|
|
||||||
return RegularTextSegment(word)
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
val longDatePattern: Pattern = Pattern.compile("^\\d{4}-\\d{2}-\\d{2}$")
|
|
||||||
val shortDatePattern: Pattern = Pattern.compile("^\\d{2}-\\d{2}-\\d{2}$")
|
|
||||||
val numberPattern: Pattern = Pattern.compile("^(-?[\\d.]+)([a-zA-Z%]*)$")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Immutable open class Segment(val segmentText: String)
|
|
||||||
|
|
||||||
@Immutable class ImageSegment(segment: String) : Segment(segment)
|
|
||||||
|
|
||||||
@Immutable class LinkSegment(segment: String) : Segment(segment)
|
|
||||||
|
|
||||||
@Immutable class EmojiSegment(segment: String) : Segment(segment)
|
|
||||||
|
|
||||||
@Immutable class InvoiceSegment(segment: String) : Segment(segment)
|
|
||||||
|
|
||||||
@Immutable class WithdrawSegment(segment: String) : Segment(segment)
|
|
||||||
|
|
||||||
@Immutable class CashuSegment(segment: String) : Segment(segment)
|
|
||||||
|
|
||||||
@Immutable class EmailSegment(segment: String) : Segment(segment)
|
|
||||||
|
|
||||||
@Immutable class PhoneSegment(segment: String) : Segment(segment)
|
|
||||||
|
|
||||||
@Immutable class BechSegment(segment: String) : Segment(segment)
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
open class HashIndexSegment(segment: String, val hex: String, val extras: String?) :
|
|
||||||
Segment(segment)
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
class HashIndexUserSegment(segment: String, hex: String, extras: String?) :
|
|
||||||
HashIndexSegment(segment, hex, extras)
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
class HashIndexEventSegment(segment: String, hex: String, extras: String?) :
|
|
||||||
HashIndexSegment(segment, hex, extras)
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
class HashTagSegment(segment: String, val hashtag: String, val extras: String?) : Segment(segment)
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
class SchemelessUrlSegment(segment: String, val url: String, val extras: String?) :
|
|
||||||
Segment(segment)
|
|
||||||
|
|
||||||
@Immutable class RegularTextSegment(segment: String) : Segment(segment)
|
|
||||||
|
|
||||||
fun startsWithNIP19Scheme(word: String): Boolean {
|
|
||||||
val cleaned = word.lowercase().removePrefix("@").removePrefix("nostr:").removePrefix("@")
|
|
||||||
|
|
||||||
return listOf("npub1", "naddr1", "note1", "nprofile1", "nevent1").any { cleaned.startsWith(it) }
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -129,23 +129,18 @@ import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
|||||||
import com.google.accompanist.permissions.isGranted
|
import com.google.accompanist.permissions.isGranted
|
||||||
import com.google.accompanist.permissions.rememberPermissionState
|
import com.google.accompanist.permissions.rememberPermissionState
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
|
import com.vitorpamplona.amethyst.commons.RichTextParser
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import com.vitorpamplona.amethyst.service.Nip96MediaServers
|
import com.vitorpamplona.amethyst.service.Nip96MediaServers
|
||||||
import com.vitorpamplona.amethyst.service.NostrSearchEventOrUserDataSource
|
import com.vitorpamplona.amethyst.service.NostrSearchEventOrUserDataSource
|
||||||
import com.vitorpamplona.amethyst.service.ReverseGeoLocationUtil
|
import com.vitorpamplona.amethyst.service.ReverseGeoLocationUtil
|
||||||
import com.vitorpamplona.amethyst.service.noProtocolUrlValidator
|
|
||||||
import com.vitorpamplona.amethyst.service.startsWithNIP19Scheme
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.BechLink
|
import com.vitorpamplona.amethyst.ui.components.BechLink
|
||||||
import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
|
import com.vitorpamplona.amethyst.ui.components.CreateTextWithEmoji
|
||||||
import com.vitorpamplona.amethyst.ui.components.InvoiceRequest
|
import com.vitorpamplona.amethyst.ui.components.InvoiceRequest
|
||||||
import com.vitorpamplona.amethyst.ui.components.LoadUrlPreview
|
import com.vitorpamplona.amethyst.ui.components.LoadUrlPreview
|
||||||
import com.vitorpamplona.amethyst.ui.components.VideoView
|
import com.vitorpamplona.amethyst.ui.components.VideoView
|
||||||
import com.vitorpamplona.amethyst.ui.components.ZapRaiserRequest
|
import com.vitorpamplona.amethyst.ui.components.ZapRaiserRequest
|
||||||
import com.vitorpamplona.amethyst.ui.components.imageExtensions
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.isValidURL
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.removeQueryParamsForExtensionComparison
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.videoExtensions
|
|
||||||
import com.vitorpamplona.amethyst.ui.note.BaseUserPicture
|
import com.vitorpamplona.amethyst.ui.note.BaseUserPicture
|
||||||
import com.vitorpamplona.amethyst.ui.note.CancelIcon
|
import com.vitorpamplona.amethyst.ui.note.CancelIcon
|
||||||
import com.vitorpamplona.amethyst.ui.note.CloseIcon
|
import com.vitorpamplona.amethyst.ui.note.CloseIcon
|
||||||
@@ -476,10 +471,8 @@ fun NewPostView(
|
|||||||
val myUrlPreview = postViewModel.urlPreview
|
val myUrlPreview = postViewModel.urlPreview
|
||||||
if (myUrlPreview != null) {
|
if (myUrlPreview != null) {
|
||||||
Row(modifier = Modifier.padding(vertical = Size5dp, horizontal = Size10dp)) {
|
Row(modifier = Modifier.padding(vertical = Size5dp, horizontal = Size10dp)) {
|
||||||
if (isValidURL(myUrlPreview)) {
|
if (RichTextParser.isValidURL(myUrlPreview)) {
|
||||||
val removedParamsFromUrl =
|
if (RichTextParser.isImageUrl(myUrlPreview)) {
|
||||||
removeQueryParamsForExtensionComparison(myUrlPreview)
|
|
||||||
if (imageExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
|
||||||
AsyncImage(
|
AsyncImage(
|
||||||
model = myUrlPreview,
|
model = myUrlPreview,
|
||||||
contentDescription = myUrlPreview,
|
contentDescription = myUrlPreview,
|
||||||
@@ -495,7 +488,7 @@ fun NewPostView(
|
|||||||
QuoteBorder,
|
QuoteBorder,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
} else if (videoExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
} else if (RichTextParser.isVideoUrl(myUrlPreview)) {
|
||||||
VideoView(
|
VideoView(
|
||||||
myUrlPreview,
|
myUrlPreview,
|
||||||
roundedCorner = true,
|
roundedCorner = true,
|
||||||
@@ -504,7 +497,7 @@ fun NewPostView(
|
|||||||
} else {
|
} else {
|
||||||
LoadUrlPreview(myUrlPreview, myUrlPreview, accountViewModel)
|
LoadUrlPreview(myUrlPreview, myUrlPreview, accountViewModel)
|
||||||
}
|
}
|
||||||
} else if (startsWithNIP19Scheme(myUrlPreview)) {
|
} else if (RichTextParser.startsWithNIP19Scheme(myUrlPreview)) {
|
||||||
val bgColor = MaterialTheme.colorScheme.background
|
val bgColor = MaterialTheme.colorScheme.background
|
||||||
val backgroundColor = remember { mutableStateOf(bgColor) }
|
val backgroundColor = remember { mutableStateOf(bgColor) }
|
||||||
|
|
||||||
@@ -515,7 +508,7 @@ fun NewPostView(
|
|||||||
accountViewModel,
|
accountViewModel,
|
||||||
nav,
|
nav,
|
||||||
)
|
)
|
||||||
} else if (noProtocolUrlValidator.matcher(myUrlPreview).matches()) {
|
} else if (RichTextParser.isUrlWithoutScheme(myUrlPreview)) {
|
||||||
LoadUrlPreview("https://$myUrlPreview", myUrlPreview, accountViewModel)
|
LoadUrlPreview("https://$myUrlPreview", myUrlPreview, accountViewModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import androidx.compose.ui.text.input.TextFieldValue
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.fonfon.kgeohash.toGeoHash
|
import com.fonfon.kgeohash.toGeoHash
|
||||||
|
import com.vitorpamplona.amethyst.commons.RichTextParser
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
@@ -43,11 +44,9 @@ import com.vitorpamplona.amethyst.service.FileHeader
|
|||||||
import com.vitorpamplona.amethyst.service.LocationUtil
|
import com.vitorpamplona.amethyst.service.LocationUtil
|
||||||
import com.vitorpamplona.amethyst.service.Nip96Uploader
|
import com.vitorpamplona.amethyst.service.Nip96Uploader
|
||||||
import com.vitorpamplona.amethyst.service.NostrSearchEventOrUserDataSource
|
import com.vitorpamplona.amethyst.service.NostrSearchEventOrUserDataSource
|
||||||
import com.vitorpamplona.amethyst.service.noProtocolUrlValidator
|
|
||||||
import com.vitorpamplona.amethyst.service.relays.Relay
|
import com.vitorpamplona.amethyst.service.relays.Relay
|
||||||
import com.vitorpamplona.amethyst.ui.components.MediaCompressor
|
import com.vitorpamplona.amethyst.ui.components.MediaCompressor
|
||||||
import com.vitorpamplona.amethyst.ui.components.Split
|
import com.vitorpamplona.amethyst.ui.components.Split
|
||||||
import com.vitorpamplona.amethyst.ui.components.isValidURL
|
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.quartz.encoders.HexKey
|
import com.vitorpamplona.quartz.encoders.HexKey
|
||||||
import com.vitorpamplona.quartz.events.AddressableEvent
|
import com.vitorpamplona.quartz.events.AddressableEvent
|
||||||
@@ -540,7 +539,7 @@ open class NewPostViewModel() : ViewModel() {
|
|||||||
open fun findUrlInMessage(): String? {
|
open fun findUrlInMessage(): String? {
|
||||||
return message.text.split('\n').firstNotNullOfOrNull { paragraph ->
|
return message.text.split('\n').firstNotNullOfOrNull { paragraph ->
|
||||||
paragraph.split(' ').firstOrNull { word: String ->
|
paragraph.split(' ').firstOrNull { word: String ->
|
||||||
isValidURL(word) || noProtocolUrlValidator.matcher(word).matches()
|
RichTextParser.isValidURL(word) || RichTextParser.isUrlWithoutScheme(word)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
import com.vitorpamplona.amethyst.commons.ZoomableUrlImage
|
||||||
|
import com.vitorpamplona.amethyst.commons.ZoomableUrlVideo
|
||||||
import com.vitorpamplona.amethyst.model.UrlCachedPreviewer
|
import com.vitorpamplona.amethyst.model.UrlCachedPreviewer
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.theme.HalfVertPadding
|
import com.vitorpamplona.amethyst.ui.theme.HalfVertPadding
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ package com.vitorpamplona.amethyst.ui.components
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.util.Patterns
|
import android.util.Patterns
|
||||||
|
import com.vitorpamplona.amethyst.commons.RichTextParser
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
import com.vitorpamplona.amethyst.service.startsWithNIP19Scheme
|
|
||||||
import com.vitorpamplona.quartz.encoders.Nip19
|
import com.vitorpamplona.quartz.encoders.Nip19
|
||||||
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
@@ -34,7 +34,7 @@ class MarkdownParser {
|
|||||||
tag: String,
|
tag: String,
|
||||||
tags: ImmutableListOfLists<String>,
|
tags: ImmutableListOfLists<String>,
|
||||||
): Pair<String, String>? {
|
): Pair<String, String>? {
|
||||||
val matcher = tagIndex.matcher(tag)
|
val matcher = RichTextParser.tagIndex.matcher(tag)
|
||||||
val (index, suffix) =
|
val (index, suffix) =
|
||||||
try {
|
try {
|
||||||
matcher.find()
|
matcher.find()
|
||||||
@@ -95,7 +95,7 @@ class MarkdownParser {
|
|||||||
val listOfReferences = mutableListOf<Nip19.Return>()
|
val listOfReferences = mutableListOf<Nip19.Return>()
|
||||||
content.split('\n').forEach { paragraph ->
|
content.split('\n').forEach { paragraph ->
|
||||||
paragraph.split(' ').forEach { word: String ->
|
paragraph.split(' ').forEach { word: String ->
|
||||||
if (startsWithNIP19Scheme(word)) {
|
if (RichTextParser.startsWithNIP19Scheme(word)) {
|
||||||
val parsedNip19 = Nip19.uriToRoute(word)
|
val parsedNip19 = Nip19.uriToRoute(word)
|
||||||
parsedNip19?.let { listOfReferences.add(it) }
|
parsedNip19?.let { listOfReferences.add(it) }
|
||||||
}
|
}
|
||||||
@@ -122,9 +122,8 @@ class MarkdownParser {
|
|||||||
var returnContent = ""
|
var returnContent = ""
|
||||||
content.split('\n').forEach { paragraph ->
|
content.split('\n').forEach { paragraph ->
|
||||||
paragraph.split(' ').forEach { word: String ->
|
paragraph.split(' ').forEach { word: String ->
|
||||||
if (isValidURL(word)) {
|
if (RichTextParser.isValidURL(word)) {
|
||||||
val removedParamsFromUrl = removeQueryParamsForExtensionComparison(word)
|
if (RichTextParser.isImageUrl(word)) {
|
||||||
if (imageExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
|
||||||
returnContent += " "
|
returnContent += " "
|
||||||
} else {
|
} else {
|
||||||
returnContent += "[$word]($word) "
|
returnContent += "[$word]($word) "
|
||||||
@@ -133,7 +132,7 @@ class MarkdownParser {
|
|||||||
returnContent += "[$word](mailto:$word) "
|
returnContent += "[$word](mailto:$word) "
|
||||||
} else if (Patterns.PHONE.matcher(word).matches() && word.length > 6) {
|
} else if (Patterns.PHONE.matcher(word).matches() && word.length > 6) {
|
||||||
returnContent += "[$word](tel:$word) "
|
returnContent += "[$word](tel:$word) "
|
||||||
} else if (startsWithNIP19Scheme(word)) {
|
} else if (RichTextParser.startsWithNIP19Scheme(word)) {
|
||||||
val parsedNip19 = Nip19.uriToRoute(word)
|
val parsedNip19 = Nip19.uriToRoute(word)
|
||||||
returnContent +=
|
returnContent +=
|
||||||
if (parsedNip19 !== null) {
|
if (parsedNip19 !== null) {
|
||||||
@@ -148,15 +147,15 @@ class MarkdownParser {
|
|||||||
"$word "
|
"$word "
|
||||||
}
|
}
|
||||||
} else if (word.startsWith("#")) {
|
} else if (word.startsWith("#")) {
|
||||||
if (tagIndex.matcher(word).matches() && tags != null) {
|
if (RichTextParser.tagIndex.matcher(word).matches() && tags != null) {
|
||||||
val pair = getDisplayNameAndNIP19FromTag(word, tags)
|
val pair = getDisplayNameAndNIP19FromTag(word, tags)
|
||||||
if (pair != null) {
|
if (pair != null) {
|
||||||
returnContent += "[${pair.first}](nostr:${pair.second}) "
|
returnContent += "[${pair.first}](nostr:${pair.second}) "
|
||||||
} else {
|
} else {
|
||||||
returnContent += "$word "
|
returnContent += "$word "
|
||||||
}
|
}
|
||||||
} else if (hashTagsPattern.matcher(word).matches()) {
|
} else if (RichTextParser.hashTagsPattern.matcher(word).matches()) {
|
||||||
val hashtagMatcher = hashTagsPattern.matcher(word)
|
val hashtagMatcher = RichTextParser.hashTagsPattern.matcher(word)
|
||||||
|
|
||||||
val (myTag, mySuffix) =
|
val (myTag, mySuffix) =
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -68,28 +68,29 @@ import androidx.compose.ui.unit.em
|
|||||||
import com.halilibo.richtext.markdown.Markdown
|
import com.halilibo.richtext.markdown.Markdown
|
||||||
import com.halilibo.richtext.markdown.MarkdownParseOptions
|
import com.halilibo.richtext.markdown.MarkdownParseOptions
|
||||||
import com.halilibo.richtext.ui.material3.Material3RichText
|
import com.halilibo.richtext.ui.material3.Material3RichText
|
||||||
|
import com.vitorpamplona.amethyst.commons.BechSegment
|
||||||
|
import com.vitorpamplona.amethyst.commons.CashuSegment
|
||||||
|
import com.vitorpamplona.amethyst.commons.EmailSegment
|
||||||
|
import com.vitorpamplona.amethyst.commons.EmojiSegment
|
||||||
|
import com.vitorpamplona.amethyst.commons.HashIndexEventSegment
|
||||||
|
import com.vitorpamplona.amethyst.commons.HashIndexUserSegment
|
||||||
|
import com.vitorpamplona.amethyst.commons.HashTagSegment
|
||||||
|
import com.vitorpamplona.amethyst.commons.ImageSegment
|
||||||
|
import com.vitorpamplona.amethyst.commons.InvoiceSegment
|
||||||
|
import com.vitorpamplona.amethyst.commons.LinkSegment
|
||||||
|
import com.vitorpamplona.amethyst.commons.PhoneSegment
|
||||||
|
import com.vitorpamplona.amethyst.commons.RegularTextSegment
|
||||||
|
import com.vitorpamplona.amethyst.commons.RichTextParser
|
||||||
|
import com.vitorpamplona.amethyst.commons.RichTextViewerState
|
||||||
|
import com.vitorpamplona.amethyst.commons.SchemelessUrlSegment
|
||||||
|
import com.vitorpamplona.amethyst.commons.Segment
|
||||||
|
import com.vitorpamplona.amethyst.commons.WithdrawSegment
|
||||||
|
import com.vitorpamplona.amethyst.commons.ZoomableUrlImage
|
||||||
import com.vitorpamplona.amethyst.model.HashtagIcon
|
import com.vitorpamplona.amethyst.model.HashtagIcon
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import com.vitorpamplona.amethyst.model.checkForHashtagWithIcon
|
import com.vitorpamplona.amethyst.model.checkForHashtagWithIcon
|
||||||
import com.vitorpamplona.amethyst.service.BechSegment
|
|
||||||
import com.vitorpamplona.amethyst.service.CachedRichTextParser
|
import com.vitorpamplona.amethyst.service.CachedRichTextParser
|
||||||
import com.vitorpamplona.amethyst.service.CashuSegment
|
|
||||||
import com.vitorpamplona.amethyst.service.EmailSegment
|
|
||||||
import com.vitorpamplona.amethyst.service.EmojiSegment
|
|
||||||
import com.vitorpamplona.amethyst.service.HashIndexEventSegment
|
|
||||||
import com.vitorpamplona.amethyst.service.HashIndexUserSegment
|
|
||||||
import com.vitorpamplona.amethyst.service.HashTagSegment
|
|
||||||
import com.vitorpamplona.amethyst.service.ImageSegment
|
|
||||||
import com.vitorpamplona.amethyst.service.InvoiceSegment
|
|
||||||
import com.vitorpamplona.amethyst.service.LinkSegment
|
|
||||||
import com.vitorpamplona.amethyst.service.PhoneSegment
|
|
||||||
import com.vitorpamplona.amethyst.service.RegularTextSegment
|
|
||||||
import com.vitorpamplona.amethyst.service.RichTextParser
|
|
||||||
import com.vitorpamplona.amethyst.service.RichTextViewerState
|
|
||||||
import com.vitorpamplona.amethyst.service.SchemelessUrlSegment
|
|
||||||
import com.vitorpamplona.amethyst.service.Segment
|
|
||||||
import com.vitorpamplona.amethyst.service.WithdrawSegment
|
|
||||||
import com.vitorpamplona.amethyst.ui.note.LoadUser
|
import com.vitorpamplona.amethyst.ui.note.LoadUser
|
||||||
import com.vitorpamplona.amethyst.ui.note.NoteCompose
|
import com.vitorpamplona.amethyst.ui.note.NoteCompose
|
||||||
import com.vitorpamplona.amethyst.ui.note.toShortenHex
|
import com.vitorpamplona.amethyst.ui.note.toShortenHex
|
||||||
@@ -106,45 +107,6 @@ import com.vitorpamplona.quartz.events.EmptyTagList
|
|||||||
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.net.MalformedURLException
|
|
||||||
import java.net.URISyntaxException
|
|
||||||
import java.net.URL
|
|
||||||
import java.util.regex.Pattern
|
|
||||||
|
|
||||||
val imageExtensions = listOf("png", "jpg", "gif", "bmp", "jpeg", "webp", "svg")
|
|
||||||
val videoExtensions = listOf("mp4", "avi", "wmv", "mpg", "amv", "webm", "mov", "mp3", "m3u8")
|
|
||||||
|
|
||||||
val tagIndex = Pattern.compile("\\#\\[([0-9]+)\\](.*)")
|
|
||||||
val hashTagsPattern: Pattern =
|
|
||||||
Pattern.compile("#([^\\s!@#\$%^&*()=+./,\\[{\\]};:'\"?><]+)(.*)", Pattern.CASE_INSENSITIVE)
|
|
||||||
|
|
||||||
fun removeQueryParamsForExtensionComparison(fullUrl: String): String {
|
|
||||||
return if (fullUrl.contains("?")) {
|
|
||||||
fullUrl.split("?")[0].lowercase()
|
|
||||||
} else if (fullUrl.contains("#")) {
|
|
||||||
fullUrl.split("#")[0].lowercase()
|
|
||||||
} else {
|
|
||||||
fullUrl.lowercase()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun isImageOrVideoUrl(url: String): Boolean {
|
|
||||||
val removedParamsFromUrl = removeQueryParamsForExtensionComparison(url)
|
|
||||||
|
|
||||||
return imageExtensions.any { removedParamsFromUrl.endsWith(it) } ||
|
|
||||||
videoExtensions.any { removedParamsFromUrl.endsWith(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun isValidURL(url: String?): Boolean {
|
|
||||||
return try {
|
|
||||||
URL(url).toURI()
|
|
||||||
true
|
|
||||||
} catch (e: MalformedURLException) {
|
|
||||||
false
|
|
||||||
} catch (e: URISyntaxException) {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun isMarkdown(content: String): Boolean {
|
fun isMarkdown(content: String): Boolean {
|
||||||
return content.startsWith("> ") ||
|
return content.startsWith("> ") ||
|
||||||
@@ -420,7 +382,7 @@ fun RenderCustomEmoji(
|
|||||||
val markdownParseOptions =
|
val markdownParseOptions =
|
||||||
MarkdownParseOptions(
|
MarkdownParseOptions(
|
||||||
autolink = true,
|
autolink = true,
|
||||||
isImage = { url -> isImageOrVideoUrl(url) },
|
isImage = { url -> RichTextParser.isImageOrVideoUrl(url) },
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ import androidx.compose.material3.Surface
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.DisposableEffect
|
import androidx.compose.runtime.DisposableEffect
|
||||||
import androidx.compose.runtime.Immutable
|
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.MutableState
|
import androidx.compose.runtime.MutableState
|
||||||
import androidx.compose.runtime.SideEffect
|
import androidx.compose.runtime.SideEffect
|
||||||
@@ -107,6 +106,13 @@ import coil.compose.AsyncImage
|
|||||||
import coil.compose.AsyncImagePainter
|
import coil.compose.AsyncImagePainter
|
||||||
import coil.imageLoader
|
import coil.imageLoader
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
|
import com.vitorpamplona.amethyst.commons.ZoomableContent
|
||||||
|
import com.vitorpamplona.amethyst.commons.ZoomableLocalImage
|
||||||
|
import com.vitorpamplona.amethyst.commons.ZoomableLocalVideo
|
||||||
|
import com.vitorpamplona.amethyst.commons.ZoomablePreloadedContent
|
||||||
|
import com.vitorpamplona.amethyst.commons.ZoomableUrlContent
|
||||||
|
import com.vitorpamplona.amethyst.commons.ZoomableUrlImage
|
||||||
|
import com.vitorpamplona.amethyst.commons.ZoomableUrlVideo
|
||||||
import com.vitorpamplona.amethyst.service.BlurHashRequester
|
import com.vitorpamplona.amethyst.service.BlurHashRequester
|
||||||
import com.vitorpamplona.amethyst.ui.actions.CloseButton
|
import com.vitorpamplona.amethyst.ui.actions.CloseButton
|
||||||
import com.vitorpamplona.amethyst.ui.actions.InformationDialog
|
import com.vitorpamplona.amethyst.ui.actions.InformationDialog
|
||||||
@@ -137,93 +143,6 @@ import kotlinx.coroutines.delay
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import net.engawapg.lib.zoomable.rememberZoomState
|
import net.engawapg.lib.zoomable.rememberZoomState
|
||||||
import net.engawapg.lib.zoomable.zoomable
|
import net.engawapg.lib.zoomable.zoomable
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
abstract class ZoomableContent(
|
|
||||||
val description: String? = null,
|
|
||||||
val dim: String? = null,
|
|
||||||
)
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
abstract class ZoomableUrlContent(
|
|
||||||
val url: String,
|
|
||||||
description: String? = null,
|
|
||||||
val hash: String? = null,
|
|
||||||
dim: String? = null,
|
|
||||||
val uri: String? = null,
|
|
||||||
) : ZoomableContent(description, dim)
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
class ZoomableUrlImage(
|
|
||||||
url: String,
|
|
||||||
description: String? = null,
|
|
||||||
hash: String? = null,
|
|
||||||
val blurhash: String? = null,
|
|
||||||
dim: String? = null,
|
|
||||||
uri: String? = null,
|
|
||||||
val contentWarning: String? = null,
|
|
||||||
) : ZoomableUrlContent(url, description, hash, dim, uri)
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
class ZoomableUrlVideo(
|
|
||||||
url: String,
|
|
||||||
description: String? = null,
|
|
||||||
hash: String? = null,
|
|
||||||
dim: String? = null,
|
|
||||||
uri: String? = null,
|
|
||||||
val artworkUri: String? = null,
|
|
||||||
val authorName: String? = null,
|
|
||||||
val blurhash: String? = null,
|
|
||||||
val contentWarning: String? = null,
|
|
||||||
) : ZoomableUrlContent(url, description, hash, dim, uri)
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
abstract class ZoomablePreloadedContent(
|
|
||||||
val localFile: File?,
|
|
||||||
description: String? = null,
|
|
||||||
val mimeType: String? = null,
|
|
||||||
val isVerified: Boolean? = null,
|
|
||||||
dim: String? = null,
|
|
||||||
val uri: String,
|
|
||||||
) : ZoomableContent(description, dim)
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
class ZoomableLocalImage(
|
|
||||||
localFile: File?,
|
|
||||||
mimeType: String? = null,
|
|
||||||
description: String? = null,
|
|
||||||
val blurhash: String? = null,
|
|
||||||
dim: String? = null,
|
|
||||||
isVerified: Boolean? = null,
|
|
||||||
uri: String,
|
|
||||||
) : ZoomablePreloadedContent(localFile, description, mimeType, isVerified, dim, uri)
|
|
||||||
|
|
||||||
@Immutable
|
|
||||||
class ZoomableLocalVideo(
|
|
||||||
localFile: File?,
|
|
||||||
mimeType: String? = null,
|
|
||||||
description: String? = null,
|
|
||||||
dim: String? = null,
|
|
||||||
isVerified: Boolean? = null,
|
|
||||||
uri: String,
|
|
||||||
val artworkUri: String? = null,
|
|
||||||
val authorName: String? = null,
|
|
||||||
) : ZoomablePreloadedContent(localFile, description, mimeType, isVerified, dim, uri)
|
|
||||||
|
|
||||||
fun figureOutMimeType(fullUrl: String): ZoomableContent {
|
|
||||||
val removedParamsFromUrl = removeQueryParamsForExtensionComparison(fullUrl)
|
|
||||||
val isImage = imageExtensions.any { removedParamsFromUrl.endsWith(it) }
|
|
||||||
val isVideo = videoExtensions.any { removedParamsFromUrl.endsWith(it) }
|
|
||||||
|
|
||||||
return if (isImage) {
|
|
||||||
ZoomableUrlImage(fullUrl)
|
|
||||||
} else if (isVideo) {
|
|
||||||
ZoomableUrlVideo(fullUrl)
|
|
||||||
} else {
|
|
||||||
ZoomableUrlImage(fullUrl)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@@ -316,7 +235,7 @@ private fun LocalImageView(
|
|||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
alwayShowImage: Boolean = false,
|
alwayShowImage: Boolean = false,
|
||||||
) {
|
) {
|
||||||
if (content.localFile != null && content.localFile.exists()) {
|
if (content.localFileExists()) {
|
||||||
BoxWithConstraints(contentAlignment = Alignment.Center) {
|
BoxWithConstraints(contentAlignment = Alignment.Center) {
|
||||||
val showImage =
|
val showImage =
|
||||||
remember {
|
remember {
|
||||||
@@ -549,8 +468,8 @@ private fun AddedImageFeatures(
|
|||||||
BlankNote()
|
BlankNote()
|
||||||
}
|
}
|
||||||
is AsyncImagePainter.State.Success -> {
|
is AsyncImagePainter.State.Success -> {
|
||||||
if (content.isVerified != null) {
|
content.isVerified?.let {
|
||||||
HashVerificationSymbol(content.isVerified, verifiedModifier)
|
HashVerificationSymbol(it, verifiedModifier)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {}
|
else -> {}
|
||||||
@@ -888,9 +807,9 @@ private fun DialogContent(
|
|||||||
Spacer(modifier = StdHorzSpacer)
|
Spacer(modifier = StdHorzSpacer)
|
||||||
SaveToGallery(url = myContent.url)
|
SaveToGallery(url = myContent.url)
|
||||||
}
|
}
|
||||||
} else if (myContent is ZoomableLocalImage && myContent.localFile != null) {
|
} else if (myContent is ZoomableLocalImage && myContent.localFileExists()) {
|
||||||
SaveToGallery(
|
SaveToGallery(
|
||||||
localFile = myContent.localFile,
|
localFile = myContent.localFile!!,
|
||||||
mimeType = myContent.mimeType,
|
mimeType = myContent.mimeType,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -975,11 +894,11 @@ private fun ShareImageAction(
|
|||||||
onDismiss()
|
onDismiss()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if (content.uri != null) {
|
content.uri?.let {
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
text = { Text(stringResource(R.string.copy_the_note_id_to_the_clipboard)) },
|
text = { Text(stringResource(R.string.copy_the_note_id_to_the_clipboard)) },
|
||||||
onClick = {
|
onClick = {
|
||||||
clipboardManager.setText(AnnotatedString(content.uri))
|
clipboardManager.setText(AnnotatedString(it))
|
||||||
onDismiss()
|
onDismiss()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -95,6 +95,12 @@ import coil.request.SuccessResult
|
|||||||
import com.fonfon.kgeohash.GeoHash
|
import com.fonfon.kgeohash.GeoHash
|
||||||
import com.fonfon.kgeohash.toGeoHash
|
import com.fonfon.kgeohash.toGeoHash
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
|
import com.vitorpamplona.amethyst.commons.RichTextParser
|
||||||
|
import com.vitorpamplona.amethyst.commons.ZoomableContent
|
||||||
|
import com.vitorpamplona.amethyst.commons.ZoomableLocalImage
|
||||||
|
import com.vitorpamplona.amethyst.commons.ZoomableLocalVideo
|
||||||
|
import com.vitorpamplona.amethyst.commons.ZoomableUrlImage
|
||||||
|
import com.vitorpamplona.amethyst.commons.ZoomableUrlVideo
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
import com.vitorpamplona.amethyst.model.AddressableNote
|
||||||
import com.vitorpamplona.amethyst.model.Channel
|
import com.vitorpamplona.amethyst.model.Channel
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
@@ -113,17 +119,9 @@ import com.vitorpamplona.amethyst.ui.components.SensitivityWarning
|
|||||||
import com.vitorpamplona.amethyst.ui.components.ShowMoreButton
|
import com.vitorpamplona.amethyst.ui.components.ShowMoreButton
|
||||||
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
|
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
|
||||||
import com.vitorpamplona.amethyst.ui.components.VideoView
|
import com.vitorpamplona.amethyst.ui.components.VideoView
|
||||||
import com.vitorpamplona.amethyst.ui.components.ZoomableContent
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.ZoomableContentView
|
import com.vitorpamplona.amethyst.ui.components.ZoomableContentView
|
||||||
import com.vitorpamplona.amethyst.ui.components.ZoomableImageDialog
|
import com.vitorpamplona.amethyst.ui.components.ZoomableImageDialog
|
||||||
import com.vitorpamplona.amethyst.ui.components.ZoomableLocalImage
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.ZoomableLocalVideo
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.ZoomableUrlImage
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.ZoomableUrlVideo
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.figureOutMimeType
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.imageExtensions
|
|
||||||
import com.vitorpamplona.amethyst.ui.components.measureSpaceWidth
|
import com.vitorpamplona.amethyst.ui.components.measureSpaceWidth
|
||||||
import com.vitorpamplona.amethyst.ui.components.removeQueryParamsForExtensionComparison
|
|
||||||
import com.vitorpamplona.amethyst.ui.elements.AddButton
|
import com.vitorpamplona.amethyst.ui.elements.AddButton
|
||||||
import com.vitorpamplona.amethyst.ui.elements.DisplayFollowingCommunityInPost
|
import com.vitorpamplona.amethyst.ui.elements.DisplayFollowingCommunityInPost
|
||||||
import com.vitorpamplona.amethyst.ui.elements.DisplayFollowingHashtagsInPost
|
import com.vitorpamplona.amethyst.ui.elements.DisplayFollowingHashtagsInPost
|
||||||
@@ -1447,7 +1445,7 @@ fun RenderAppDefinition(
|
|||||||
|
|
||||||
if (zoomImageDialogOpen) {
|
if (zoomImageDialogOpen) {
|
||||||
ZoomableImageDialog(
|
ZoomableImageDialog(
|
||||||
imageUrl = figureOutMimeType(it.banner!!),
|
imageUrl = RichTextParser.parseImageOrVideo(it.banner!!),
|
||||||
onDismiss = { zoomImageDialogOpen = false },
|
onDismiss = { zoomImageDialogOpen = false },
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
)
|
)
|
||||||
@@ -1503,7 +1501,7 @@ fun RenderAppDefinition(
|
|||||||
|
|
||||||
if (zoomImageDialogOpen) {
|
if (zoomImageDialogOpen) {
|
||||||
ZoomableImageDialog(
|
ZoomableImageDialog(
|
||||||
imageUrl = figureOutMimeType(it.banner!!),
|
imageUrl = RichTextParser.parseImageOrVideo(it.banner!!),
|
||||||
onDismiss = { zoomImageDialogOpen = false },
|
onDismiss = { zoomImageDialogOpen = false },
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
)
|
)
|
||||||
@@ -3064,10 +3062,7 @@ fun FileHeaderDisplay(
|
|||||||
val hash = event.hash()
|
val hash = event.hash()
|
||||||
val dimensions = event.dimensions()
|
val dimensions = event.dimensions()
|
||||||
val description = event.alt() ?: event.content
|
val description = event.alt() ?: event.content
|
||||||
val isImage =
|
val isImage = RichTextParser.isImageUrl(fullUrl)
|
||||||
imageExtensions.any {
|
|
||||||
removeQueryParamsForExtensionComparison(fullUrl).lowercase().endsWith(it)
|
|
||||||
}
|
|
||||||
val uri = note.toNostrUri()
|
val uri = note.toNostrUri()
|
||||||
|
|
||||||
mutableStateOf<ZoomableContent>(
|
mutableStateOf<ZoomableContent>(
|
||||||
@@ -3126,10 +3121,7 @@ fun VideoDisplay(
|
|||||||
val hash = event.hash()
|
val hash = event.hash()
|
||||||
val dimensions = event.dimensions()
|
val dimensions = event.dimensions()
|
||||||
val description = event.alt() ?: event.content
|
val description = event.alt() ?: event.content
|
||||||
val isImage =
|
val isImage = RichTextParser.isImageUrl(fullUrl)
|
||||||
imageExtensions.any {
|
|
||||||
removeQueryParamsForExtensionComparison(fullUrl).lowercase().endsWith(it)
|
|
||||||
}
|
|
||||||
val uri = note.toNostrUri()
|
val uri = note.toNostrUri()
|
||||||
|
|
||||||
mutableStateOf<ZoomableContent>(
|
mutableStateOf<ZoomableContent>(
|
||||||
|
|||||||
@@ -101,6 +101,7 @@ import androidx.lifecycle.distinctUntilChanged
|
|||||||
import androidx.lifecycle.map
|
import androidx.lifecycle.map
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
|
import com.vitorpamplona.amethyst.commons.ZoomableUrlVideo
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
import com.vitorpamplona.amethyst.model.AddressableNote
|
||||||
import com.vitorpamplona.amethyst.model.Channel
|
import com.vitorpamplona.amethyst.model.Channel
|
||||||
import com.vitorpamplona.amethyst.model.LiveActivitiesChannel
|
import com.vitorpamplona.amethyst.model.LiveActivitiesChannel
|
||||||
@@ -120,7 +121,6 @@ import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
|
|||||||
import com.vitorpamplona.amethyst.ui.components.SensitivityWarning
|
import com.vitorpamplona.amethyst.ui.components.SensitivityWarning
|
||||||
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
|
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
|
||||||
import com.vitorpamplona.amethyst.ui.components.ZoomableContentView
|
import com.vitorpamplona.amethyst.ui.components.ZoomableContentView
|
||||||
import com.vitorpamplona.amethyst.ui.components.ZoomableUrlVideo
|
|
||||||
import com.vitorpamplona.amethyst.ui.elements.DisplayUncitedHashtags
|
import com.vitorpamplona.amethyst.ui.elements.DisplayUncitedHashtags
|
||||||
import com.vitorpamplona.amethyst.ui.navigation.routeFor
|
import com.vitorpamplona.amethyst.ui.navigation.routeFor
|
||||||
import com.vitorpamplona.amethyst.ui.note.ChatroomMessageCompose
|
import com.vitorpamplona.amethyst.ui.note.ChatroomMessageCompose
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ import androidx.lifecycle.map
|
|||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import coil.compose.AsyncImage
|
import coil.compose.AsyncImage
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
|
import com.vitorpamplona.amethyst.commons.RichTextParser
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
import com.vitorpamplona.amethyst.model.AddressableNote
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
@@ -127,7 +128,6 @@ import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImage
|
|||||||
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
|
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
|
||||||
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
|
import com.vitorpamplona.amethyst.ui.components.TranslatableRichTextViewer
|
||||||
import com.vitorpamplona.amethyst.ui.components.ZoomableImageDialog
|
import com.vitorpamplona.amethyst.ui.components.ZoomableImageDialog
|
||||||
import com.vitorpamplona.amethyst.ui.components.figureOutMimeType
|
|
||||||
import com.vitorpamplona.amethyst.ui.dal.UserProfileReportsFeedFilter
|
import com.vitorpamplona.amethyst.ui.dal.UserProfileReportsFeedFilter
|
||||||
import com.vitorpamplona.amethyst.ui.navigation.routeToMessage
|
import com.vitorpamplona.amethyst.ui.navigation.routeToMessage
|
||||||
import com.vitorpamplona.amethyst.ui.note.ClickableUserPicture
|
import com.vitorpamplona.amethyst.ui.note.ClickableUserPicture
|
||||||
@@ -826,7 +826,7 @@ private fun ProfileHeader(
|
|||||||
val profilePic = baseUser.profilePicture()
|
val profilePic = baseUser.profilePicture()
|
||||||
if (zoomImageDialogOpen && profilePic != null) {
|
if (zoomImageDialogOpen && profilePic != null) {
|
||||||
ZoomableImageDialog(
|
ZoomableImageDialog(
|
||||||
figureOutMimeType(profilePic),
|
RichTextParser.parseImageOrVideo(profilePic),
|
||||||
onDismiss = { zoomImageDialogOpen = false },
|
onDismiss = { zoomImageDialogOpen = false },
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
)
|
)
|
||||||
@@ -1477,7 +1477,7 @@ fun DrawBanner(
|
|||||||
|
|
||||||
if (zoomImageDialogOpen) {
|
if (zoomImageDialogOpen) {
|
||||||
ZoomableImageDialog(
|
ZoomableImageDialog(
|
||||||
imageUrl = figureOutMimeType(banner),
|
imageUrl = RichTextParser.parseImageOrVideo(banner),
|
||||||
onDismiss = { zoomImageDialogOpen = false },
|
onDismiss = { zoomImageDialogOpen = false },
|
||||||
accountViewModel = accountViewModel,
|
accountViewModel = accountViewModel,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -37,6 +37,12 @@ android {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation project(path: ':quartz')
|
implementation project(path: ':quartz')
|
||||||
|
|
||||||
|
// Import @Immutable and @Stable
|
||||||
|
implementation "androidx.compose.ui:ui:$compose_ui_version"
|
||||||
|
|
||||||
|
// immutable collections to avoid recomposition
|
||||||
|
api('org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.7')
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||||
|
|||||||
@@ -0,0 +1,352 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Vitor Pamplona
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to use,
|
||||||
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||||
|
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.vitorpamplona.amethyst.commons
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
|
import android.util.Patterns
|
||||||
|
import com.linkedin.urls.detection.UrlDetector
|
||||||
|
import com.linkedin.urls.detection.UrlDetectorOptions
|
||||||
|
import com.vitorpamplona.quartz.encoders.Nip54
|
||||||
|
import com.vitorpamplona.quartz.encoders.Nip92
|
||||||
|
import com.vitorpamplona.quartz.events.FileHeaderEvent
|
||||||
|
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
||||||
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
|
import kotlinx.collections.immutable.persistentListOf
|
||||||
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
|
import kotlinx.collections.immutable.toImmutableMap
|
||||||
|
import kotlinx.collections.immutable.toImmutableSet
|
||||||
|
import kotlinx.collections.immutable.toPersistentList
|
||||||
|
import java.net.MalformedURLException
|
||||||
|
import java.net.URISyntaxException
|
||||||
|
import java.net.URL
|
||||||
|
import java.util.regex.Pattern
|
||||||
|
import kotlin.coroutines.cancellation.CancellationException
|
||||||
|
|
||||||
|
class RichTextParser() {
|
||||||
|
fun parseMediaUrl(
|
||||||
|
fullUrl: String,
|
||||||
|
eventTags: ImmutableListOfLists<String>,
|
||||||
|
): ZoomableUrlContent? {
|
||||||
|
val removedParamsFromUrl = removeQueryParamsForExtensionComparison(fullUrl)
|
||||||
|
return if (imageExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
||||||
|
val frags = Nip54().parse(fullUrl)
|
||||||
|
val tags = Nip92().parse(fullUrl, eventTags.lists)
|
||||||
|
|
||||||
|
ZoomableUrlImage(
|
||||||
|
url = fullUrl,
|
||||||
|
description = frags[FileHeaderEvent.ALT] ?: tags[FileHeaderEvent.ALT],
|
||||||
|
hash = frags[FileHeaderEvent.HASH] ?: tags[FileHeaderEvent.HASH],
|
||||||
|
blurhash = frags[FileHeaderEvent.BLUR_HASH] ?: tags[FileHeaderEvent.BLUR_HASH],
|
||||||
|
dim = frags[FileHeaderEvent.DIMENSION] ?: tags[FileHeaderEvent.DIMENSION],
|
||||||
|
contentWarning = frags["content-warning"] ?: tags["content-warning"],
|
||||||
|
)
|
||||||
|
} else if (videoExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
||||||
|
val frags = Nip54().parse(fullUrl)
|
||||||
|
val tags = Nip92().parse(fullUrl, eventTags.lists)
|
||||||
|
ZoomableUrlVideo(
|
||||||
|
url = fullUrl,
|
||||||
|
description = frags[FileHeaderEvent.ALT] ?: tags[FileHeaderEvent.ALT],
|
||||||
|
hash = frags[FileHeaderEvent.HASH] ?: tags[FileHeaderEvent.HASH],
|
||||||
|
blurhash = frags[FileHeaderEvent.BLUR_HASH] ?: tags[FileHeaderEvent.BLUR_HASH],
|
||||||
|
dim = frags[FileHeaderEvent.DIMENSION] ?: tags[FileHeaderEvent.DIMENSION],
|
||||||
|
contentWarning = frags["content-warning"] ?: tags["content-warning"],
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun parseText(
|
||||||
|
content: String,
|
||||||
|
tags: ImmutableListOfLists<String>,
|
||||||
|
): RichTextViewerState {
|
||||||
|
val urls = UrlDetector(content, UrlDetectorOptions.Default).detect()
|
||||||
|
|
||||||
|
val urlSet =
|
||||||
|
urls.mapNotNullTo(LinkedHashSet(urls.size)) {
|
||||||
|
// removes e-mails
|
||||||
|
if (Patterns.EMAIL_ADDRESS.matcher(it.originalUrl).matches()) {
|
||||||
|
null
|
||||||
|
} else if (isNumber(it.originalUrl)) {
|
||||||
|
null
|
||||||
|
} else if (it.originalUrl.contains("。")) {
|
||||||
|
null
|
||||||
|
} else {
|
||||||
|
if (HTTPRegex.matches(it.originalUrl)) {
|
||||||
|
it.originalUrl
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val imagesForPager =
|
||||||
|
urlSet.mapNotNull { fullUrl -> parseMediaUrl(fullUrl, tags) }.associateBy { it.url }
|
||||||
|
val imageList = imagesForPager.values.toList()
|
||||||
|
|
||||||
|
val emojiMap =
|
||||||
|
tags.lists.filter { it.size > 2 && it[0] == "emoji" }.associate { ":${it[1]}:" to it[2] }
|
||||||
|
|
||||||
|
val segments = findTextSegments(content, imagesForPager.keys, urlSet, emojiMap, tags)
|
||||||
|
|
||||||
|
return RichTextViewerState(
|
||||||
|
urlSet.toImmutableSet(),
|
||||||
|
imagesForPager.toImmutableMap(),
|
||||||
|
imageList.toImmutableList(),
|
||||||
|
emojiMap.toImmutableMap(),
|
||||||
|
segments,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun findTextSegments(
|
||||||
|
content: String,
|
||||||
|
images: Set<String>,
|
||||||
|
urls: Set<String>,
|
||||||
|
emojis: Map<String, String>,
|
||||||
|
tags: ImmutableListOfLists<String>,
|
||||||
|
): ImmutableList<ParagraphState> {
|
||||||
|
val lines = content.split('\n')
|
||||||
|
val paragraphSegments = ArrayList<ParagraphState>(lines.size)
|
||||||
|
|
||||||
|
lines.forEach { paragraph ->
|
||||||
|
var isDirty = false
|
||||||
|
val isRTL = isArabic(paragraph)
|
||||||
|
|
||||||
|
val wordList = paragraph.trimEnd().split(' ')
|
||||||
|
val segments = ArrayList<Segment>(wordList.size)
|
||||||
|
wordList.forEach { word ->
|
||||||
|
val wordSegment = wordIdentifier(word, images, urls, emojis, tags)
|
||||||
|
if (wordSegment !is RegularTextSegment) {
|
||||||
|
isDirty = true
|
||||||
|
}
|
||||||
|
segments.add(wordSegment)
|
||||||
|
}
|
||||||
|
|
||||||
|
val newSegments =
|
||||||
|
if (isDirty) {
|
||||||
|
ParagraphState(segments.toPersistentList(), isRTL)
|
||||||
|
} else {
|
||||||
|
ParagraphState(persistentListOf<Segment>(RegularTextSegment(paragraph)), isRTL)
|
||||||
|
}
|
||||||
|
|
||||||
|
paragraphSegments.add(newSegments)
|
||||||
|
}
|
||||||
|
|
||||||
|
return paragraphSegments.toImmutableList()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isNumber(word: String): Boolean {
|
||||||
|
return numberPattern.matcher(word).matches()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isDate(word: String): Boolean {
|
||||||
|
return shortDatePattern.matcher(word).matches() || longDatePattern.matcher(word).matches()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun isArabic(text: String): Boolean {
|
||||||
|
return text.any { it in '\u0600'..'\u06FF' || it in '\u0750'..'\u077F' }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun wordIdentifier(
|
||||||
|
word: String,
|
||||||
|
images: Set<String>,
|
||||||
|
urls: Set<String>,
|
||||||
|
emojis: Map<String, String>,
|
||||||
|
tags: ImmutableListOfLists<String>,
|
||||||
|
): Segment {
|
||||||
|
val emailMatcher = Patterns.EMAIL_ADDRESS.matcher(word)
|
||||||
|
val phoneMatcher = Patterns.PHONE.matcher(word)
|
||||||
|
val schemelessMatcher = noProtocolUrlValidator.matcher(word)
|
||||||
|
|
||||||
|
return if (word.isEmpty()) {
|
||||||
|
RegularTextSegment(word)
|
||||||
|
} else if (images.contains(word)) {
|
||||||
|
ImageSegment(word)
|
||||||
|
} else if (urls.contains(word)) {
|
||||||
|
LinkSegment(word)
|
||||||
|
} else if (emojis.any { word.contains(it.key) }) {
|
||||||
|
EmojiSegment(word)
|
||||||
|
} else if (word.startsWith("lnbc", true)) {
|
||||||
|
InvoiceSegment(word)
|
||||||
|
} else if (word.startsWith("lnurl", true)) {
|
||||||
|
WithdrawSegment(word)
|
||||||
|
} else if (word.startsWith("cashuA", true)) {
|
||||||
|
CashuSegment(word)
|
||||||
|
} else if (emailMatcher.matches()) {
|
||||||
|
EmailSegment(word)
|
||||||
|
} else if (word.length in 7..14 && !isDate(word) && phoneMatcher.matches()) {
|
||||||
|
PhoneSegment(word)
|
||||||
|
} else if (startsWithNIP19Scheme(word)) {
|
||||||
|
BechSegment(word)
|
||||||
|
} else if (word.startsWith("#")) {
|
||||||
|
parseHash(word, tags)
|
||||||
|
} else if (word.contains(".") && schemelessMatcher.find()) {
|
||||||
|
val url = schemelessMatcher.group(1) // url
|
||||||
|
val additionalChars = schemelessMatcher.group(4).ifEmpty { null } // additional chars
|
||||||
|
val pattern =
|
||||||
|
"""^([A-Za-z0-9-_]+(\.[A-Za-z0-9-_]+)+)(:[0-9]+)?(/[^?#]*)?(\?[^#]*)?(#.*)?"""
|
||||||
|
.toRegex(RegexOption.IGNORE_CASE)
|
||||||
|
if (pattern.find(word) != null) {
|
||||||
|
SchemelessUrlSegment(word, url, additionalChars)
|
||||||
|
} else {
|
||||||
|
RegularTextSegment(word)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
RegularTextSegment(word)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseHash(
|
||||||
|
word: String,
|
||||||
|
tags: ImmutableListOfLists<String>,
|
||||||
|
): Segment {
|
||||||
|
// First #[n]
|
||||||
|
|
||||||
|
val matcher = tagIndex.matcher(word)
|
||||||
|
try {
|
||||||
|
if (matcher.find()) {
|
||||||
|
val index = matcher.group(1)?.toInt()
|
||||||
|
val suffix = matcher.group(2)
|
||||||
|
|
||||||
|
if (index != null && index >= 0 && index < tags.lists.size) {
|
||||||
|
val tag = tags.lists[index]
|
||||||
|
|
||||||
|
if (tag.size > 1) {
|
||||||
|
if (tag[0] == "p") {
|
||||||
|
return HashIndexUserSegment(word, tag[1], suffix)
|
||||||
|
} else if (tag[0] == "e" || tag[0] == "a") {
|
||||||
|
return HashIndexEventSegment(word, tag[1], suffix)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
if (e is CancellationException) throw e
|
||||||
|
Log.w("Tag Parser", "Couldn't link tag $word", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second #Amethyst
|
||||||
|
val hashtagMatcher = hashTagsPattern.matcher(word)
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (hashtagMatcher.find()) {
|
||||||
|
val hashtag = hashtagMatcher.group(1)
|
||||||
|
if (hashtag != null) {
|
||||||
|
return HashTagSegment(word, hashtag, hashtagMatcher.group(2).ifEmpty { null })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
if (e is CancellationException) throw e
|
||||||
|
Log.e("Hashtag Parser", "Couldn't link hashtag $word", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
return RegularTextSegment(word)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val longDatePattern: Pattern = Pattern.compile("^\\d{4}-\\d{2}-\\d{2}$")
|
||||||
|
val shortDatePattern: Pattern = Pattern.compile("^\\d{2}-\\d{2}-\\d{2}$")
|
||||||
|
val numberPattern: Pattern = Pattern.compile("^(-?[\\d.]+)([a-zA-Z%]*)$")
|
||||||
|
|
||||||
|
// Android9 seems to have an issue starting this regex.
|
||||||
|
val noProtocolUrlValidator =
|
||||||
|
try {
|
||||||
|
Pattern.compile(
|
||||||
|
"(([\\w\\d-]+\\.)*[a-zA-Z][\\w-]+[\\.\\:]\\w+([\\/\\?\\=\\&\\#\\.]?[\\w-]+[^\\p{IsHan}\\p{IsHiragana}\\p{IsKatakana}])*\\/?)(.*)",
|
||||||
|
)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Pattern.compile(
|
||||||
|
"(([\\w\\d-]+\\.)*[a-zA-Z][\\w-]+[\\.\\:]\\w+([\\/\\?\\=\\&\\#\\.]?[\\w-]+)*\\/?)(.*)",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val HTTPRegex =
|
||||||
|
"^((http|https)://)?([A-Za-z0-9-_]+(\\.[A-Za-z0-9-_]+)+)(:[0-9]+)?(/[^?#]*)?(\\?[^#]*)?(#.*)?"
|
||||||
|
.toRegex(RegexOption.IGNORE_CASE)
|
||||||
|
|
||||||
|
val imageExtensions = listOf("png", "jpg", "gif", "bmp", "jpeg", "webp", "svg")
|
||||||
|
val videoExtensions = listOf("mp4", "avi", "wmv", "mpg", "amv", "webm", "mov", "mp3", "m3u8")
|
||||||
|
|
||||||
|
val tagIndex = Pattern.compile("\\#\\[([0-9]+)\\](.*)")
|
||||||
|
val hashTagsPattern: Pattern =
|
||||||
|
Pattern.compile("#([^\\s!@#\$%^&*()=+./,\\[{\\]};:'\"?><]+)(.*)", Pattern.CASE_INSENSITIVE)
|
||||||
|
|
||||||
|
fun removeQueryParamsForExtensionComparison(fullUrl: String): String {
|
||||||
|
return if (fullUrl.contains("?")) {
|
||||||
|
fullUrl.split("?")[0].lowercase()
|
||||||
|
} else if (fullUrl.contains("#")) {
|
||||||
|
fullUrl.split("#")[0].lowercase()
|
||||||
|
} else {
|
||||||
|
fullUrl.lowercase()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isImageOrVideoUrl(url: String): Boolean {
|
||||||
|
val removedParamsFromUrl = removeQueryParamsForExtensionComparison(url)
|
||||||
|
|
||||||
|
return imageExtensions.any { removedParamsFromUrl.endsWith(it) } ||
|
||||||
|
videoExtensions.any { removedParamsFromUrl.endsWith(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isImageUrl(url: String): Boolean {
|
||||||
|
val removedParamsFromUrl = removeQueryParamsForExtensionComparison(url)
|
||||||
|
return imageExtensions.any { removedParamsFromUrl.endsWith(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isVideoUrl(url: String): Boolean {
|
||||||
|
val removedParamsFromUrl = removeQueryParamsForExtensionComparison(url)
|
||||||
|
return videoExtensions.any { removedParamsFromUrl.endsWith(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isValidURL(url: String?): Boolean {
|
||||||
|
return try {
|
||||||
|
URL(url).toURI()
|
||||||
|
true
|
||||||
|
} catch (e: MalformedURLException) {
|
||||||
|
false
|
||||||
|
} catch (e: URISyntaxException) {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun parseImageOrVideo(fullUrl: String): ZoomableContent {
|
||||||
|
val removedParamsFromUrl = removeQueryParamsForExtensionComparison(fullUrl)
|
||||||
|
val isImage = imageExtensions.any { removedParamsFromUrl.endsWith(it) }
|
||||||
|
val isVideo = videoExtensions.any { removedParamsFromUrl.endsWith(it) }
|
||||||
|
|
||||||
|
return if (isImage) {
|
||||||
|
ZoomableUrlImage(fullUrl)
|
||||||
|
} else if (isVideo) {
|
||||||
|
ZoomableUrlVideo(fullUrl)
|
||||||
|
} else {
|
||||||
|
ZoomableUrlImage(fullUrl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun startsWithNIP19Scheme(word: String): Boolean {
|
||||||
|
val cleaned = word.lowercase().removePrefix("@").removePrefix("nostr:").removePrefix("@")
|
||||||
|
|
||||||
|
return listOf("npub1", "naddr1", "note1", "nprofile1", "nevent1").any { cleaned.startsWith(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isUrlWithoutScheme(url: String) = noProtocolUrlValidator.matcher(url).matches()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Vitor Pamplona
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to use,
|
||||||
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||||
|
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.vitorpamplona.amethyst.commons
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Immutable
|
||||||
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
|
import kotlinx.collections.immutable.ImmutableMap
|
||||||
|
import kotlinx.collections.immutable.ImmutableSet
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
data class RichTextViewerState(
|
||||||
|
val urlSet: ImmutableSet<String>,
|
||||||
|
val imagesForPager: ImmutableMap<String, ZoomableUrlContent>,
|
||||||
|
val imageList: ImmutableList<ZoomableUrlContent>,
|
||||||
|
val customEmoji: ImmutableMap<String, String>,
|
||||||
|
val paragraphs: ImmutableList<ParagraphState>,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
data class ParagraphState(val words: ImmutableList<Segment>, val isRTL: Boolean)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
open class Segment(val segmentText: String)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class ImageSegment(segment: String) : Segment(segment)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class LinkSegment(segment: String) : Segment(segment)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class EmojiSegment(segment: String) : Segment(segment)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class InvoiceSegment(segment: String) : Segment(segment)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class WithdrawSegment(segment: String) : Segment(segment)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class CashuSegment(segment: String) : Segment(segment)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class EmailSegment(segment: String) : Segment(segment)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class PhoneSegment(segment: String) : Segment(segment)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class BechSegment(segment: String) : Segment(segment)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
open class HashIndexSegment(segment: String, val hex: String, val extras: String?) :
|
||||||
|
Segment(segment)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class HashIndexUserSegment(segment: String, hex: String, extras: String?) :
|
||||||
|
HashIndexSegment(segment, hex, extras)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class HashIndexEventSegment(segment: String, hex: String, extras: String?) :
|
||||||
|
HashIndexSegment(segment, hex, extras)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class HashTagSegment(segment: String, val hashtag: String, val extras: String?) : Segment(segment)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class SchemelessUrlSegment(segment: String, val url: String, val extras: String?) :
|
||||||
|
Segment(segment)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class RegularTextSegment(segment: String) : Segment(segment)
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2024 Vitor Pamplona
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to use,
|
||||||
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||||
|
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.vitorpamplona.amethyst.commons
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Immutable
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
abstract class ZoomableContent(
|
||||||
|
val description: String? = null,
|
||||||
|
val dim: String? = null,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
abstract class ZoomableUrlContent(
|
||||||
|
val url: String,
|
||||||
|
description: String? = null,
|
||||||
|
val hash: String? = null,
|
||||||
|
dim: String? = null,
|
||||||
|
val uri: String? = null,
|
||||||
|
) : ZoomableContent(description, dim)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class ZoomableUrlImage(
|
||||||
|
url: String,
|
||||||
|
description: String? = null,
|
||||||
|
hash: String? = null,
|
||||||
|
val blurhash: String? = null,
|
||||||
|
dim: String? = null,
|
||||||
|
uri: String? = null,
|
||||||
|
val contentWarning: String? = null,
|
||||||
|
) : ZoomableUrlContent(url, description, hash, dim, uri)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class ZoomableUrlVideo(
|
||||||
|
url: String,
|
||||||
|
description: String? = null,
|
||||||
|
hash: String? = null,
|
||||||
|
dim: String? = null,
|
||||||
|
uri: String? = null,
|
||||||
|
val artworkUri: String? = null,
|
||||||
|
val authorName: String? = null,
|
||||||
|
val blurhash: String? = null,
|
||||||
|
val contentWarning: String? = null,
|
||||||
|
) : ZoomableUrlContent(url, description, hash, dim, uri)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
abstract class ZoomablePreloadedContent(
|
||||||
|
val localFile: File?,
|
||||||
|
description: String? = null,
|
||||||
|
val mimeType: String? = null,
|
||||||
|
val isVerified: Boolean? = null,
|
||||||
|
dim: String? = null,
|
||||||
|
val uri: String,
|
||||||
|
) : ZoomableContent(description, dim) {
|
||||||
|
fun localFileExists() = localFile != null && localFile.exists()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class ZoomableLocalImage(
|
||||||
|
localFile: File?,
|
||||||
|
mimeType: String? = null,
|
||||||
|
description: String? = null,
|
||||||
|
val blurhash: String? = null,
|
||||||
|
dim: String? = null,
|
||||||
|
isVerified: Boolean? = null,
|
||||||
|
uri: String,
|
||||||
|
) : ZoomablePreloadedContent(localFile, description, mimeType, isVerified, dim, uri)
|
||||||
|
|
||||||
|
@Immutable
|
||||||
|
class ZoomableLocalVideo(
|
||||||
|
localFile: File?,
|
||||||
|
mimeType: String? = null,
|
||||||
|
description: String? = null,
|
||||||
|
dim: String? = null,
|
||||||
|
isVerified: Boolean? = null,
|
||||||
|
uri: String,
|
||||||
|
val artworkUri: String? = null,
|
||||||
|
val authorName: String? = null,
|
||||||
|
) : ZoomablePreloadedContent(localFile, description, mimeType, isVerified, dim, uri)
|
||||||
Reference in New Issue
Block a user