mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-10 18:54:53 +02:00
Parse base64 inside the wordIdentifier function
This commit is contained in:
@@ -127,15 +127,13 @@ class RichTextParser {
|
|||||||
): RichTextViewerState {
|
): RichTextViewerState {
|
||||||
val urlSet = parseValidUrls(content)
|
val urlSet = parseValidUrls(content)
|
||||||
|
|
||||||
val base64Images = parseBase64Images(content)
|
|
||||||
|
|
||||||
val imagesForPager =
|
val imagesForPager =
|
||||||
urlSet.mapNotNull { fullUrl -> parseMediaUrl(fullUrl, tags, content, callbackUri) }.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)
|
||||||
|
|
||||||
val segments = findTextSegments(content, imagesForPager.keys, urlSet, emojiMap, tags, base64Images)
|
val segments = findTextSegments(content, imagesForPager.keys, urlSet, emojiMap, tags)
|
||||||
|
|
||||||
return RichTextViewerState(
|
return RichTextViewerState(
|
||||||
urlSet.toImmutableSet(),
|
urlSet.toImmutableSet(),
|
||||||
@@ -143,7 +141,6 @@ class RichTextParser {
|
|||||||
imageList.toImmutableList(),
|
imageList.toImmutableList(),
|
||||||
emojiMap.toImmutableMap(),
|
emojiMap.toImmutableMap(),
|
||||||
segments,
|
segments,
|
||||||
base64Images.toImmutableSet(),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +150,6 @@ class RichTextParser {
|
|||||||
urls: Set<String>,
|
urls: Set<String>,
|
||||||
emojis: Map<String, String>,
|
emojis: Map<String, String>,
|
||||||
tags: ImmutableListOfLists<String>,
|
tags: ImmutableListOfLists<String>,
|
||||||
base64Images: Set<String>,
|
|
||||||
): ImmutableList<ParagraphState> {
|
): ImmutableList<ParagraphState> {
|
||||||
val lines = content.split('\n')
|
val lines = content.split('\n')
|
||||||
val paragraphSegments = ArrayList<ParagraphState>(lines.size)
|
val paragraphSegments = ArrayList<ParagraphState>(lines.size)
|
||||||
@@ -165,7 +161,7 @@ class RichTextParser {
|
|||||||
val wordList = paragraph.trimEnd().split(' ')
|
val wordList = paragraph.trimEnd().split(' ')
|
||||||
val segments = ArrayList<Segment>(wordList.size)
|
val segments = ArrayList<Segment>(wordList.size)
|
||||||
wordList.forEach { word ->
|
wordList.forEach { word ->
|
||||||
val wordSegment = wordIdentifier(word, images, urls, emojis, tags, base64Images)
|
val wordSegment = wordIdentifier(word, images, urls, emojis, tags)
|
||||||
if (wordSegment !is RegularTextSegment) {
|
if (wordSegment !is RegularTextSegment) {
|
||||||
isDirty = true
|
isDirty = true
|
||||||
}
|
}
|
||||||
@@ -219,11 +215,15 @@ class RichTextParser {
|
|||||||
urls: Set<String>,
|
urls: Set<String>,
|
||||||
emojis: Map<String, String>,
|
emojis: Map<String, String>,
|
||||||
tags: ImmutableListOfLists<String>,
|
tags: ImmutableListOfLists<String>,
|
||||||
base64Images: Set<String>,
|
|
||||||
): Segment {
|
): Segment {
|
||||||
if (word.isEmpty()) return RegularTextSegment(word)
|
if (word.isEmpty()) return RegularTextSegment(word)
|
||||||
|
|
||||||
if (base64Images.contains(word)) return Base64Segment(word)
|
if (word.startsWith("data:image")) {
|
||||||
|
val base64Images = parseBase64Images(word)
|
||||||
|
if (base64Images.isNotEmpty()) {
|
||||||
|
return Base64Segment(word)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (images.contains(word)) return ImageSegment(word)
|
if (images.contains(word)) return ImageSegment(word)
|
||||||
|
|
||||||
|
@@ -32,7 +32,6 @@ data class RichTextViewerState(
|
|||||||
val imageList: ImmutableList<MediaUrlContent>,
|
val imageList: ImmutableList<MediaUrlContent>,
|
||||||
val customEmoji: ImmutableMap<String, String>,
|
val customEmoji: ImmutableMap<String, String>,
|
||||||
val paragraphs: ImmutableList<ParagraphState>,
|
val paragraphs: ImmutableList<ParagraphState>,
|
||||||
val base64Images: ImmutableSet<String>,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
|
Reference in New Issue
Block a user