- Updates several libraries

- Reformats code to the newest Klint
- Fixes isEmpty bug on Filters
This commit is contained in:
Vitor Pamplona
2026-02-09 14:06:07 -05:00
parent 710f15f790
commit eb66182211
133 changed files with 1373 additions and 580 deletions
@@ -189,6 +189,7 @@ object BlurHashDecoderOld {
calculate -> {
DoubleArray(height * numCompY).also { cacheCosinesY[height * numCompY] = it }
}
else -> {
cacheCosinesY[height * numCompY]!!
}
@@ -202,7 +203,10 @@ object BlurHashDecoderOld {
calculate -> {
DoubleArray(width * numCompX).also { cacheCosinesX[width * numCompX] = it }
}
else -> cacheCosinesX[width * numCompX]!!
else -> {
cacheCosinesX[width * numCompX]!!
}
}
private fun DoubleArray.getCos(
@@ -60,6 +60,7 @@ object CosineCache {
cacheCosinesY.put(height * numCompY, it)
}
}
else -> {
cacheCosinesY[height * numCompY]!!
}
@@ -77,6 +78,9 @@ object CosineCache {
cos(PI * x * i / width)
}.also { cacheCosinesX.put(width * numCompX, it) }
}
else -> cacheCosinesX[width * numCompX]!!
else -> {
cacheCosinesX[width * numCompX]!!
}
}
}
@@ -191,7 +191,10 @@ open class Note(
fun relayHintUrl(): NormalizedRelayUrl? {
// checks Community Events first
when (val noteEvent = event) {
is CommunityDefinitionEvent -> noteEvent.relayUrls().firstOrNull()?.let { return it }
is CommunityDefinitionEvent -> {
noteEvent.relayUrls().firstOrNull()?.let { return it }
}
is IsInPublicChatChannel -> {
inGatherers?.forEach {
if (it is com.vitorpamplona.amethyst.commons.model.Channel) {
@@ -199,9 +202,11 @@ open class Note(
}
}
}
is LiveActivitiesEvent -> {
noteEvent.relays().ifEmpty { null }?.toSet()
}
is LiveActivitiesChatMessageEvent -> {
inGatherers?.forEach {
if (it is com.vitorpamplona.amethyst.commons.model.Channel) {
@@ -209,7 +214,10 @@ open class Note(
}
}
}
is EphemeralChatEvent -> noteEvent.roomId()?.let { return it.relayUrl }
is EphemeralChatEvent -> {
noteEvent.roomId()?.let { return it.relayUrl }
}
}
val currentOutbox = author?.outboxRelays()?.toSet()
@@ -108,14 +108,17 @@ object MetaTagsParser {
consume()
break
}
// `>` out of quote -> end of tag
quote == null && c == '>' -> {
break
}
// entering quote
quote == null && (c == '\'' || c == '"') -> {
quote = c
}
// leaving quote
quote != null && c == quote -> {
quote = null
@@ -263,6 +266,7 @@ object MetaTagsParser {
State.AFTER_EQ -> {
when {
c.isWhitespace() -> {}
c == '\'' || c == '"' -> {
valueBegin = i + 1
valueQuote = c
@@ -66,54 +66,63 @@ class OpenGraphParser {
metaTags.forEach {
when (it.attr(ATTRIBUTE_VALUE_PROPERTY)) {
in META_X_TITLE ->
in META_X_TITLE -> {
if (title.isEmpty()) {
title = it.attr(CONTENT)
}
}
in META_X_DESCRIPTION ->
in META_X_DESCRIPTION -> {
if (description.isEmpty()) {
description = it.attr(CONTENT)
}
}
in META_X_IMAGE ->
in META_X_IMAGE -> {
if (image.isEmpty()) {
image = it.attr(CONTENT)
}
}
}
when (it.attr(ATTRIBUTE_VALUE_NAME)) {
in META_X_TITLE ->
in META_X_TITLE -> {
if (title.isEmpty()) {
title = it.attr(CONTENT)
}
}
in META_X_DESCRIPTION ->
in META_X_DESCRIPTION -> {
if (description.isEmpty()) {
description = it.attr(CONTENT)
}
}
in META_X_IMAGE ->
in META_X_IMAGE -> {
if (image.isEmpty()) {
image = it.attr(CONTENT)
}
}
}
when (it.attr(ATTRIBUTE_VALUE_ITEMPROP)) {
in META_X_TITLE ->
in META_X_TITLE -> {
if (title.isEmpty()) {
title = it.attr(CONTENT)
}
}
in META_X_DESCRIPTION ->
in META_X_DESCRIPTION -> {
if (description.isEmpty()) {
description = it.attr(CONTENT)
}
}
in META_X_IMAGE ->
in META_X_IMAGE -> {
if (image.isEmpty()) {
image = it.attr(CONTENT)
}
}
}
if (title.isNotEmpty() && description.isNotEmpty() && image.isNotEmpty()) {
@@ -36,14 +36,24 @@ class GalleryParser {
paragraph.words.forEach { word ->
when (word) {
is ImageSegment, is Base64Segment -> imageCount++
is VideoSegment -> hasNonWhitespaceNonImageContent = true // Videos are not images
is ImageSegment, is Base64Segment -> {
imageCount++
}
is VideoSegment -> {
hasNonWhitespaceNonImageContent = true
}
// Videos are not images
is RegularTextSegment -> {
if (word.segmentText.isNotBlank()) {
hasNonWhitespaceNonImageContent = true
}
}
else -> hasNonWhitespaceNonImageContent = true // Links, emojis, etc.
else -> {
hasNonWhitespaceNonImageContent = true
} // Links, emojis, etc.
}
}
@@ -159,9 +169,16 @@ class GalleryParser {
hasVideo = true
break
}
seg is ImageSegment || seg is Base64Segment -> imageSegments.add(seg)
seg is ImageSegment || seg is Base64Segment -> {
imageSegments.add(seg)
}
seg is RegularTextSegment && seg.segmentText.isBlank() -> { /* skip whitespace */ }
else -> break
else -> {
break
}
}
j++
}
@@ -59,6 +59,7 @@ fun parseSearchInput(input: String): List<SearchResult> {
),
)
}
is NProfile -> {
results.add(
SearchResult.UserResult(
@@ -67,6 +68,7 @@ fun parseSearchInput(input: String): List<SearchResult> {
),
)
}
is NSec -> {
results.add(
SearchResult.UserResult(
@@ -75,6 +77,7 @@ fun parseSearchInput(input: String): List<SearchResult> {
),
)
}
is NNote -> {
results.add(
SearchResult.NoteResult(
@@ -83,6 +86,7 @@ fun parseSearchInput(input: String): List<SearchResult> {
),
)
}
is NEvent -> {
results.add(
SearchResult.NoteResult(
@@ -91,6 +95,7 @@ fun parseSearchInput(input: String): List<SearchResult> {
),
)
}
is NAddress -> {
results.add(
SearchResult.AddressResult(
@@ -101,6 +106,7 @@ fun parseSearchInput(input: String): List<SearchResult> {
),
)
}
else -> { }
}
return results
@@ -29,10 +29,16 @@ fun String.firstFullCharOld(): String {
return when (this.length) {
0,
1,
-> return this
-> {
return this
}
2,
3,
-> return if (isUTF16Char(0)) this.take(2) else this.take(1)
-> {
return if (isUTF16Char(0)) this.take(2) else this.take(1)
}
else -> {
val first = isUTF16Char(0)
val second = isUTF16Char(2)
@@ -62,19 +62,24 @@ fun timeAgo(
updateFormattersIfNeeded()
prefix + yearFormatter.format(time * 1000)
}
timeDifference > TimeUtils.ONE_MONTH -> {
updateFormattersIfNeeded()
prefix + monthFormatter.format(time * 1000)
}
timeDifference > TimeUtils.ONE_DAY -> {
prefix + (timeDifference / TimeUtils.ONE_DAY).toString() + "d"
}
timeDifference > TimeUtils.ONE_HOUR -> {
prefix + (timeDifference / TimeUtils.ONE_HOUR).toString() + "h"
}
timeDifference > TimeUtils.ONE_MINUTE -> {
prefix + (timeDifference / TimeUtils.ONE_MINUTE).toString() + "m"
}
else -> {
prefix + "now"
}
@@ -83,46 +88,22 @@ fun timeAgo(
fun timeDiffAgoLong(timeDifference: Int): String =
when {
timeDifference > TimeUtils.ONE_YEAR -> {
(timeDifference / TimeUtils.ONE_YEAR).toString() + " years"
}
timeDifference > TimeUtils.ONE_MONTH -> {
(timeDifference / TimeUtils.ONE_MONTH).toString() + " months"
}
timeDifference > TimeUtils.ONE_DAY -> {
(timeDifference / TimeUtils.ONE_DAY).toString() + " days"
}
timeDifference > TimeUtils.ONE_HOUR -> {
(timeDifference / TimeUtils.ONE_HOUR).toString() + " hours"
}
timeDifference > TimeUtils.ONE_MINUTE -> {
(timeDifference / TimeUtils.ONE_MINUTE).toString() + " minutes"
}
else -> {
"now"
}
timeDifference > TimeUtils.ONE_YEAR -> (timeDifference / TimeUtils.ONE_YEAR).toString() + " years"
timeDifference > TimeUtils.ONE_MONTH -> (timeDifference / TimeUtils.ONE_MONTH).toString() + " months"
timeDifference > TimeUtils.ONE_DAY -> (timeDifference / TimeUtils.ONE_DAY).toString() + " days"
timeDifference > TimeUtils.ONE_HOUR -> (timeDifference / TimeUtils.ONE_HOUR).toString() + " hours"
timeDifference > TimeUtils.ONE_MINUTE -> (timeDifference / TimeUtils.ONE_MINUTE).toString() + " minutes"
else -> "now"
}
fun timeDiffAgoShortish(timeDifference: Int): String =
when {
timeDifference > TimeUtils.ONE_YEAR -> {
(timeDifference / TimeUtils.ONE_YEAR).toString() + " yrs"
}
timeDifference > TimeUtils.ONE_MONTH -> {
(timeDifference / TimeUtils.ONE_MONTH).toString() + " mos"
}
timeDifference > TimeUtils.ONE_DAY -> {
(timeDifference / TimeUtils.ONE_DAY).toString() + " days"
}
timeDifference > TimeUtils.ONE_HOUR -> {
(timeDifference / TimeUtils.ONE_HOUR).toString() + " hrs"
}
timeDifference > TimeUtils.ONE_MINUTE -> {
(timeDifference / TimeUtils.ONE_MINUTE).toString() + " mins"
}
else -> {
"now"
}
timeDifference > TimeUtils.ONE_YEAR -> (timeDifference / TimeUtils.ONE_YEAR).toString() + " yrs"
timeDifference > TimeUtils.ONE_MONTH -> (timeDifference / TimeUtils.ONE_MONTH).toString() + " mos"
timeDifference > TimeUtils.ONE_DAY -> (timeDifference / TimeUtils.ONE_DAY).toString() + " days"
timeDifference > TimeUtils.ONE_HOUR -> (timeDifference / TimeUtils.ONE_HOUR).toString() + " hrs"
timeDifference > TimeUtils.ONE_MINUTE -> (timeDifference / TimeUtils.ONE_MINUTE).toString() + " mins"
else -> "now"
}
/**
@@ -148,11 +129,15 @@ fun dateFormatter(
updateFormattersIfNeeded()
yearFormatter.format(time * 1000)
}
timeDifference > TimeUtils.ONE_DAY -> {
updateFormattersIfNeeded()
monthFormatter.format(time * 1000)
}
else -> today
else -> {
today
}
}
}