Applies new UrlDetector to the RichTextViewer
This commit is contained in:
@@ -79,7 +79,7 @@ object CachedUrlParser {
|
||||
cached
|
||||
} else {
|
||||
val urlSet = UrlParser().parseValidUrls(content)
|
||||
val newUrls = urlSet.withScheme.filter { it.startsWith("http") } + urlSet.withoutScheme.map { "http://$it" }
|
||||
val newUrls = urlSet.withScheme.filter { it.startsWith("http") } + urlSet.withoutScheme.map { "http://$it" } + urlSet.bech32s.map { "http://$it" }
|
||||
parsedUrlsCache.put(key, newUrls)
|
||||
newUrls
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ import com.vitorpamplona.amethyst.commons.richtext.PhoneSegment
|
||||
import com.vitorpamplona.amethyst.commons.richtext.RegularTextSegment
|
||||
import com.vitorpamplona.amethyst.commons.richtext.RelayUrlSegment
|
||||
import com.vitorpamplona.amethyst.commons.richtext.RichTextViewerState
|
||||
import com.vitorpamplona.amethyst.commons.richtext.SchemelessUrlSegment
|
||||
import com.vitorpamplona.amethyst.commons.richtext.SecretEmoji
|
||||
import com.vitorpamplona.amethyst.commons.richtext.Segment
|
||||
import com.vitorpamplona.amethyst.commons.richtext.VideoSegment
|
||||
@@ -168,6 +169,10 @@ fun RenderStrangeNamePreview() {
|
||||
is RelayUrlSegment -> {
|
||||
ClickableRelayUrl(word.segmentText, EmptyNav())
|
||||
}
|
||||
|
||||
is SchemelessUrlSegment -> {
|
||||
NoProtocolUrlRenderer(word.segmentText)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -225,6 +230,10 @@ fun RenderRegularPreview() {
|
||||
is RegularTextSegment -> {
|
||||
Text(word.segmentText)
|
||||
}
|
||||
|
||||
is SchemelessUrlSegment -> {
|
||||
NoProtocolUrlRenderer(word.segmentText)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -261,6 +270,8 @@ fun RenderRegularPreview2() {
|
||||
is RegularTextSegment -> Text(word.segmentText)
|
||||
|
||||
is RelayUrlSegment -> ClickableRelayUrl(word.segmentText, EmptyNav())
|
||||
|
||||
is SchemelessUrlSegment -> NoProtocolUrlRenderer(word.segmentText)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -310,6 +321,8 @@ fun RenderRegularPreview3() {
|
||||
is RegularTextSegment -> Text(word.segmentText)
|
||||
|
||||
is RelayUrlSegment -> ClickableRelayUrl(word.segmentText, EmptyNav())
|
||||
|
||||
is SchemelessUrlSegment -> NoProtocolUrlRenderer(word.segmentText)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -486,6 +499,8 @@ private fun RenderWordWithoutPreview(
|
||||
is RegularTextSegment -> Text(word.segmentText)
|
||||
|
||||
is RelayUrlSegment -> ClickableRelayUrl(word.segmentText, nav)
|
||||
|
||||
is SchemelessUrlSegment -> NoProtocolUrlRenderer(word.segmentText)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -517,6 +532,7 @@ private fun RenderWordWithPreview(
|
||||
is RegularTextSegment -> Text(word.segmentText)
|
||||
is Base64Segment -> ZoomableContentView(word.segmentText, state, accountViewModel)
|
||||
is RelayUrlSegment -> ClickableRelayUrl(word.segmentText, nav)
|
||||
is SchemelessUrlSegment -> NoProtocolUrlRenderer(word.segmentText)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -533,6 +549,11 @@ private fun ZoomableContentView(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun NoProtocolUrlRenderer(url: String) {
|
||||
ClickableUrl(url, "https://$url")
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun RenderCustomEmoji(
|
||||
word: String,
|
||||
|
||||
+2
-2
@@ -38,7 +38,7 @@ import com.vitorpamplona.amethyst.commons.model.emphChat.EphemeralChatChannel
|
||||
import com.vitorpamplona.amethyst.commons.model.nip28PublicChats.PublicChatChannel
|
||||
import com.vitorpamplona.amethyst.commons.model.nip30CustomEmojis.EmojiPackState
|
||||
import com.vitorpamplona.amethyst.commons.model.nip53LiveActivities.LiveActivitiesChannel
|
||||
import com.vitorpamplona.amethyst.commons.richtext.RichTextParser
|
||||
import com.vitorpamplona.amethyst.commons.richtext.UrlParser
|
||||
import com.vitorpamplona.amethyst.model.Account
|
||||
import com.vitorpamplona.amethyst.model.LocalCache
|
||||
import com.vitorpamplona.amethyst.model.Note
|
||||
@@ -517,7 +517,7 @@ open class ChannelNewMessageViewModel :
|
||||
emojiSuggestions?.reset()
|
||||
}
|
||||
|
||||
open fun findUrlInMessage(): String? = RichTextParser().parseValidUrls(message.text).firstOrNull()
|
||||
open fun findUrlInMessage(): String? = UrlParser().parseValidUrls(message.text).withScheme.firstOrNull()
|
||||
|
||||
open fun addToMessage(it: String) {
|
||||
updateMessage(TextFieldValue(message.text + " " + it))
|
||||
|
||||
Reference in New Issue
Block a user