diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 20f98529b..b1c1b751a 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -18,11 +18,11 @@ jobs:
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
- distribution: 'temurin'
+ distribution: 'zulu'
java-version: 17
- name: Cache gradle
- uses: actions/cache@v3
+ uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml
index a1579b7de..92f24e021 100644
--- a/.github/workflows/create-release.yml
+++ b/.github/workflows/create-release.yml
@@ -15,11 +15,11 @@ jobs:
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
- distribution: 'temurin'
+ distribution: 'zulu'
java-version: 17
- name: Cache gradle
- uses: actions/cache@v3
+ uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
diff --git a/.gitignore b/.gitignore
index 56a64a7a2..23b285a78 100644
--- a/.gitignore
+++ b/.gitignore
@@ -42,6 +42,7 @@ out/
.gradle
.gradle/
build/
+.kotlin/
# Local configuration file (sdk path, etc)
local.properties
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
index 148fdd246..6d0ee1c2a 100644
--- a/.idea/kotlinc.xml
+++ b/.idea/kotlinc.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/amethyst/build.gradle b/amethyst/build.gradle
index d154fda61..83082f576 100644
--- a/amethyst/build.gradle
+++ b/amethyst/build.gradle
@@ -2,16 +2,17 @@ plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsKotlinAndroid)
alias(libs.plugins.googleServices)
+ alias(libs.plugins.jetbrainsComposeCompiler)
}
android {
namespace 'com.vitorpamplona.amethyst'
- compileSdk 34
+ compileSdk libs.versions.android.compileSdk.get().toInteger()
defaultConfig {
applicationId "com.vitorpamplona.amethyst"
- minSdk 26
- targetSdk 34
+ minSdk libs.versions.android.minSdk.get().toInteger()
+ targetSdk libs.versions.android.targetSdk.get().toInteger()
versionCode 385
versionName "0.88.8"
buildConfigField "String", "RELEASE_NOTES_ID", "\"2a34cbadd03212c8162e1ff896ba12641821088a2ec8d5e40d54aa80c0510800\""
@@ -132,19 +133,11 @@ android {
targetCompatibility JavaVersion.VERSION_17
}
- kotlinOptions {
- jvmTarget = '17'
- }
-
buildFeatures {
compose true
buildConfig true
}
- composeOptions {
- // Should match compose version : https://developer.android.com/jetpack/androidx/releases/compose-kotlin
- kotlinCompilerExtensionVersion "1.5.14"
- }
packagingOptions {
resources {
excludes += ['/META-INF/{AL2.0,LGPL2.1}', '**/libscrypt.dylib']
@@ -160,6 +153,16 @@ android {
}
}
+kotlin {
+ compilerOptions {
+ jvmTarget = JvmTarget.JVM_17
+ }
+}
+
+composeCompiler {
+ reportsDestination = layout.buildDirectory.dir("compose_compiler")
+}
+
dependencies {
implementation platform(libs.androidx.compose.bom)
@@ -296,6 +299,7 @@ dependencies {
import com.android.tools.profgen.ArtProfileKt
import com.android.tools.profgen.ArtProfileSerializer
import com.android.tools.profgen.DexFile
+import org.jetbrains.kotlin.gradle.dsl.JvmTarget
project.afterEvaluate {
tasks.each { task ->
diff --git a/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ImageUploadTesting.kt b/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ImageUploadTesting.kt
index bd67a381d..d8fe4b70a 100644
--- a/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ImageUploadTesting.kt
+++ b/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ImageUploadTesting.kt
@@ -75,9 +75,21 @@ class ImageUploadTesting {
)
val url = result.tags!!.first { it[0] == "url" }.get(1)
- val size = result.tags!!.firstOrNull { it[0] == "size" }?.get(1)?.ifBlank { null }
- val dim = result.tags!!.firstOrNull { it[0] == "dim" }?.get(1)?.ifBlank { null }
- val hash = result.tags!!.firstOrNull { it[0] == "x" }?.get(1)?.ifBlank { null }
+ val size =
+ result.tags!!
+ .firstOrNull { it[0] == "size" }
+ ?.get(1)
+ ?.ifBlank { null }
+ val dim =
+ result.tags!!
+ .firstOrNull { it[0] == "dim" }
+ ?.get(1)
+ ?.ifBlank { null }
+ val hash =
+ result.tags!!
+ .firstOrNull { it[0] == "x" }
+ ?.get(1)
+ ?.ifBlank { null }
val contentType = result.tags!!.first { it[0] == "m" }.get(1)
val ox = result.tags!!.first { it[0] == "ox" }.get(1)
diff --git a/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ThreadAssemblerTest.kt b/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ThreadAssemblerTest.kt
index 39cf69711..cf43f6020 100644
--- a/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ThreadAssemblerTest.kt
+++ b/amethyst/src/androidTest/java/com/vitorpamplona/amethyst/ThreadAssemblerTest.kt
@@ -79,8 +79,7 @@ class ThreadAssemblerTest {
{"id":"512962dbada5fd5015fc727a107d5c3f569662de67eab8e5da5a8065012cf11e","pubkey":"7fa56f5d6962ab1e3cd424e758c3002b8665f7b0d8dcee9fe9e288d7751ac194","created_at":1688194800,"kind":1,"tags":[["a","30023:6e468422dfb74a5738702a8823b9b28168abab8655faacb6853cd0ee15deee93:1680612926599","","root"],["e","87a5bd25aa084cefb3357fc9c2a5b327254fab35fdd7b2d4bd0acddc63d0abe8","","reply"]],"content":"another one","sig":"b4bc4d8206a08de0a918043129b27c8863d17f60e4f58b4d2b535326625870d32640b04f247eb9eb5df1d62fe98c8e1b0341bdd119655553488300ec9d5b4036"},
{"id":"ce6e32e3e17b6901d2cc70b60f3743e24f885bb6e9da6d88cff516079eac1883","pubkey":"726a1e261cc6474674e8285e3951b3bb139be9a773d1acf49dc868db861a1c11","created_at":1688234921,"kind":1,"tags":[["a","30023:6e468422dfb74a5738702a8823b9b28168abab8655faacb6853cd0ee15deee93:1680612926599","","root"],["e","512962dbada5fd5015fc727a107d5c3f569662de67eab8e5da5a8065012cf11e","","reply"]],"content":"yet another one, testing 0.0.3","sig":"13bd41c4029c6a7ee41cb03d12e831e9e9b6e14d43a61c78a72657070b45385ba2ce98e8121049fbcbdb7b2dd777c36c7867ba70b5e6a4798a9b866910ae5b62"}
]
- """
- .trimIndent()
+ """.trimIndent()
val header =
"""
@@ -111,8 +110,7 @@ class ThreadAssemblerTest {
["p","b9e76546ba06456ed301d9e52bc49fa48e70a6bf2282be7a1ae72947612023dc"]
]
}
- """
- .trimIndent()
+ """.trimIndent()
@Test
fun threadOrderTest() =
diff --git a/amethyst/src/fdroid/java/com/vitorpamplona/amethyst/service/notifications/PushDistributorHandler.kt b/amethyst/src/fdroid/java/com/vitorpamplona/amethyst/service/notifications/PushDistributorHandler.kt
index 3a33a77f0..c928185c2 100644
--- a/amethyst/src/fdroid/java/com/vitorpamplona/amethyst/service/notifications/PushDistributorHandler.kt
+++ b/amethyst/src/fdroid/java/com/vitorpamplona/amethyst/service/notifications/PushDistributorHandler.kt
@@ -55,15 +55,11 @@ object PushDistributorHandler : PushDistributorActions {
endpointInternal = ""
}
- override fun getSavedDistributor(): String {
- return unifiedPush.getSavedDistributor(appContext) ?: ""
- }
+ override fun getSavedDistributor(): String = unifiedPush.getSavedDistributor(appContext) ?: ""
fun savedDistributorExists(): Boolean = getSavedDistributor().isNotEmpty()
- override fun getInstalledDistributors(): List {
- return unifiedPush.getDistributors(appContext)
- }
+ override fun getInstalledDistributors(): List = unifiedPush.getDistributors(appContext)
fun formattedDistributorNames(): List {
val distributorsArray = getInstalledDistributors().toTypedArray()
@@ -87,8 +83,7 @@ object PushDistributorHandler : PushDistributorActions {
it
}
as String
- }
- .toTypedArray()
+ }.toTypedArray()
return distributorsNameArray.toList()
}
diff --git a/amethyst/src/fdroid/java/com/vitorpamplona/amethyst/service/notifications/PushMessageReceiver.kt b/amethyst/src/fdroid/java/com/vitorpamplona/amethyst/service/notifications/PushMessageReceiver.kt
index b6313df50..6839761dd 100644
--- a/amethyst/src/fdroid/java/com/vitorpamplona/amethyst/service/notifications/PushMessageReceiver.kt
+++ b/amethyst/src/fdroid/java/com/vitorpamplona/amethyst/service/notifications/PushMessageReceiver.kt
@@ -126,8 +126,7 @@ class PushMessageReceiver : MessagingReceiver() {
pushHandler.removeEndpoint()
}
- fun notificationManager(): NotificationManager {
- return ContextCompat.getSystemService(appContext, NotificationManager::class.java)
+ fun notificationManager(): NotificationManager =
+ ContextCompat.getSystemService(appContext, NotificationManager::class.java)
as NotificationManager
- }
}
diff --git a/amethyst/src/main/java/androidx/compose/material3/pullrefresh/PullRefresh.kt b/amethyst/src/main/java/androidx/compose/material3/pullrefresh/PullRefresh.kt
index 3e750ff23..5594a8418 100644
--- a/amethyst/src/main/java/androidx/compose/material3/pullrefresh/PullRefresh.kt
+++ b/amethyst/src/main/java/androidx/compose/material3/pullrefresh/PullRefresh.kt
@@ -118,7 +118,5 @@ private class PullRefreshNestedScrollConnection(
else -> Offset.Zero
}
- override suspend fun onPreFling(available: Velocity): Velocity {
- return Velocity(0f, onRelease(available.y))
- }
+ override suspend fun onPreFling(available: Velocity): Velocity = Velocity(0f, onRelease(available.y))
}
diff --git a/amethyst/src/main/java/androidx/compose/material3/pullrefresh/PullRefreshIndicatorTransform.kt b/amethyst/src/main/java/androidx/compose/material3/pullrefresh/PullRefreshIndicatorTransform.kt
index 68bfcd489..6e8b9853c 100644
--- a/amethyst/src/main/java/androidx/compose/material3/pullrefresh/PullRefreshIndicatorTransform.kt
+++ b/amethyst/src/main/java/androidx/compose/material3/pullrefresh/PullRefreshIndicatorTransform.kt
@@ -63,8 +63,7 @@ fun Modifier.pullRefreshIndicatorTransform(
) {
this@drawWithContent.drawContent()
}
- }
- .graphicsLayer {
+ }.graphicsLayer {
translationY = state.position - size.height
if (scale && !state.refreshing) {
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/Amethyst.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/Amethyst.kt
index 1199f184b..152bfb9a1 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/Amethyst.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/Amethyst.kt
@@ -61,7 +61,8 @@ class Amethyst : Application() {
}
val coilCache: DiskCache by lazy {
- DiskCache.Builder()
+ DiskCache
+ .Builder()
.directory(applicationContext.safeCacheDir.resolve("image_cache"))
.maxSizePercent(0.2)
.maximumMaxSizeBytes(500L * 1024 * 1024) // 250MB
@@ -77,10 +78,18 @@ class Amethyst : Application() {
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(
- ThreadPolicy.Builder().detectAll().penaltyLog().build(),
+ ThreadPolicy
+ .Builder()
+ .detectAll()
+ .penaltyLog()
+ .build(),
)
StrictMode.setVmPolicy(
- VmPolicy.Builder().detectAll().penaltyLog().build(),
+ VmPolicy
+ .Builder()
+ .detectAll()
+ .penaltyLog()
+ .build(),
)
}
@@ -94,13 +103,9 @@ class Amethyst : Application() {
}
}
- fun imageLoaderBuilder(): ImageLoader.Builder {
- return ImageLoader.Builder(applicationContext).diskCache { coilCache }
- }
+ fun imageLoaderBuilder(): ImageLoader.Builder = ImageLoader.Builder(applicationContext).diskCache { coilCache }
- fun encryptedStorage(npub: String? = null): EncryptedSharedPreferences {
- return EncryptedStorage.preferences(instance, npub)
- }
+ fun encryptedStorage(npub: String? = null): EncryptedSharedPreferences = EncryptedStorage.preferences(instance, npub)
companion object {
lateinit var instance: Amethyst
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/EncryptedStorage.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/EncryptedStorage.kt
index 0768bfec1..7a90f89ae 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/EncryptedStorage.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/EncryptedStorage.kt
@@ -29,16 +29,15 @@ class EncryptedStorage {
private const val PREFERENCES_NAME = "secret_keeper"
// returns the preferences for each account or a global file if null.
- fun prefsFileName(npub: String? = null): String {
- return if (npub == null) PREFERENCES_NAME else "${PREFERENCES_NAME}_$npub"
- }
+ fun prefsFileName(npub: String? = null): String = if (npub == null) PREFERENCES_NAME else "${PREFERENCES_NAME}_$npub"
fun preferences(
applicationContext: Context,
npub: String? = null,
): EncryptedSharedPreferences {
val masterKey: MasterKey =
- MasterKey.Builder(applicationContext, MasterKey.DEFAULT_MASTER_KEY_ALIAS)
+ MasterKey
+ .Builder(applicationContext, MasterKey.DEFAULT_MASTER_KEY_ALIAS)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.build()
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/AntiSpamFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/AntiSpamFilter.kt
index 2f0911488..b68584e43 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/AntiSpamFilter.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/AntiSpamFilter.kt
@@ -33,7 +33,10 @@ import com.vitorpamplona.quartz.encoders.Nip19Bech32
import com.vitorpamplona.quartz.events.Event
import kotlinx.coroutines.Dispatchers
-data class Spammer(val pubkeyHex: HexKey, var duplicatedMessages: Set)
+data class Spammer(
+ val pubkeyHex: HexKey,
+ var duplicatedMessages: Set,
+)
class AntiSpamFilter {
val recentMessages = LruCache(1000)
@@ -109,7 +112,9 @@ class AntiSpamFilter {
}
@Stable
-class AntiSpamLiveData(val cache: AntiSpamFilter) : LiveData(AntiSpamState(cache)) {
+class AntiSpamLiveData(
+ val cache: AntiSpamFilter,
+) : LiveData(AntiSpamState(cache)) {
// Refreshes observers in batches.
private val bundler = BundledUpdate(300, Dispatchers.IO)
@@ -126,4 +131,6 @@ class AntiSpamLiveData(val cache: AntiSpamFilter) : LiveData(Anti
}
}
-class AntiSpamState(val cache: AntiSpamFilter)
+class AntiSpamState(
+ val cache: AntiSpamFilter,
+)
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt
index 2c12a5147..b0b8a3fe4 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Channel.kt
@@ -37,7 +37,9 @@ import com.vitorpamplona.quartz.events.LiveActivitiesEvent
import kotlinx.coroutines.Dispatchers
@Stable
-class PublicChatChannel(idHex: String) : Channel(idHex) {
+class PublicChatChannel(
+ idHex: String,
+) : Channel(idHex) {
var info = ChannelCreateEvent.ChannelData(null, null, null)
fun updateChannelInfo(
@@ -49,26 +51,22 @@ class PublicChatChannel(idHex: String) : Channel(idHex) {
super.updateChannelInfo(creator, updatedAt)
}
- override fun toBestDisplayName(): String {
- return info.name ?: super.toBestDisplayName()
- }
+ override fun toBestDisplayName(): String = info.name ?: super.toBestDisplayName()
- override fun summary(): String? {
- return info.about
- }
+ override fun summary(): String? = info.about
override fun profilePicture(): String? {
if (info.picture.isNullOrBlank()) return super.profilePicture()
return info.picture ?: super.profilePicture()
}
- override fun anyNameStartsWith(prefix: String): Boolean {
- return listOfNotNull(info.name, info.about).filter { it.contains(prefix, true) }.isNotEmpty()
- }
+ override fun anyNameStartsWith(prefix: String): Boolean = listOfNotNull(info.name, info.about).filter { it.contains(prefix, true) }.isNotEmpty()
}
@Stable
-class LiveActivitiesChannel(val address: ATag) : Channel(address.toTag()) {
+class LiveActivitiesChannel(
+ val address: ATag,
+) : Channel(address.toTag()) {
var info: LiveActivitiesEvent? = null
override fun idNote() = address.toNAddr()
@@ -86,27 +84,22 @@ class LiveActivitiesChannel(val address: ATag) : Channel(address.toTag()) {
super.updateChannelInfo(creator, updatedAt)
}
- override fun toBestDisplayName(): String {
- return info?.title() ?: super.toBestDisplayName()
- }
+ override fun toBestDisplayName(): String = info?.title() ?: super.toBestDisplayName()
- override fun summary(): String? {
- return info?.summary()
- }
+ override fun summary(): String? = info?.summary()
- override fun profilePicture(): String? {
- return info?.image()?.ifBlank { null }
- }
+ override fun profilePicture(): String? = info?.image()?.ifBlank { null }
- override fun anyNameStartsWith(prefix: String): Boolean {
- return listOfNotNull(info?.title(), info?.summary())
+ override fun anyNameStartsWith(prefix: String): Boolean =
+ listOfNotNull(info?.title(), info?.summary())
.filter { it.contains(prefix, true) }
.isNotEmpty()
- }
}
@Stable
-abstract class Channel(val idHex: String) {
+abstract class Channel(
+ val idHex: String,
+) {
var creator: User? = null
var updatedMetadataAt: Long = 0
val notes = LargeCache()
@@ -118,21 +111,13 @@ abstract class Channel(val idHex: String) {
open fun idDisplayNote() = idNote().toShortenHex()
- open fun toBestDisplayName(): String {
- return idDisplayNote()
- }
+ open fun toBestDisplayName(): String = idDisplayNote()
- open fun summary(): String? {
- return null
- }
+ open fun summary(): String? = null
- open fun creatorName(): String? {
- return creator?.toBestDisplayName()
- }
+ open fun creatorName(): String? = creator?.toBestDisplayName()
- open fun profilePicture(): String? {
- return creator?.info?.banner
- }
+ open fun profilePicture(): String? = creator?.info?.banner
open fun updateChannelInfo(
creator: User,
@@ -167,10 +152,10 @@ abstract class Channel(val idHex: String) {
fun pruneOldAndHiddenMessages(account: Account): Set {
val important =
- notes.filter { key, it ->
- it.author?.let { author -> account.isHidden(author) } == false
- }
- .sortedWith(DefaultFeedOrder)
+ notes
+ .filter { key, it ->
+ it.author?.let { author -> account.isHidden(author) } == false
+ }.sortedWith(DefaultFeedOrder)
.take(500)
.toSet()
@@ -182,7 +167,9 @@ abstract class Channel(val idHex: String) {
}
}
-class ChannelLiveData(val channel: Channel) : LiveData(ChannelState(channel)) {
+class ChannelLiveData(
+ val channel: Channel,
+) : LiveData(ChannelState(channel)) {
// Refreshes observers in batches.
private val bundler = BundledUpdate(300, Dispatchers.IO)
@@ -208,4 +195,6 @@ class ChannelLiveData(val channel: Channel) : LiveData(ChannelStat
}
}
-class ChannelState(val channel: Channel)
+class ChannelState(
+ val channel: Channel,
+)
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Chatroom.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Chatroom.kt
index f986f1fe1..63e3094ba 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Chatroom.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Chatroom.kt
@@ -26,7 +26,7 @@ import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.utils.TimeUtils
@Stable
-class Chatroom() {
+class Chatroom {
var authors: Set = setOf()
var roomMessages: Set = setOf()
var subject: String? = null
@@ -72,9 +72,7 @@ class Chatroom() {
}
}
- fun senderIntersects(keySet: Set): Boolean {
- return authors.any { it.pubkeyHex in keySet }
- }
+ fun senderIntersects(keySet: Set): Boolean = authors.any { it.pubkeyHex in keySet }
fun pruneMessagesToTheLatestOnly(): Set {
val sorted = roomMessages.sortedWith(compareBy({ it.createdAt() }, { it.idHex })).reversed()
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/HashtagIcon.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/HashtagIcon.kt
index 536b96946..a27419081 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/HashtagIcon.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/HashtagIcon.kt
@@ -68,8 +68,8 @@ fun RenderHashTagIcons() {
}
}
-fun checkForHashtagWithIcon(tag: String): HashtagIcon? {
- return when (tag.lowercase()) {
+fun checkForHashtagWithIcon(tag: String): HashtagIcon? =
+ when (tag.lowercase()) {
"₿itcoin", "bitcoin", "btc", "timechain", "bitcoiner", "bitcoiners" -> bitcoin
"nostr", "nostrich", "nostriches", "thenostr" -> nostr
"lightning", "lightningnetwork" -> lightning
@@ -86,7 +86,6 @@ fun checkForHashtagWithIcon(tag: String): HashtagIcon? {
"weed", "weedstr", "420", "cannabis", "marijuana" -> weed
else -> null
}
-}
val bitcoin = HashtagIcon(CustomHashTagIcons.Btc, "Bitcoin", Modifier.padding(start = 1.dp, bottom = 1.dp, top = 1.dp))
val nostr = HashtagIcon(CustomHashTagIcons.Nostr, "Nostr", Modifier.padding(start = 1.dp, bottom = 1.dp, top = 1.dp))
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/MiniFhir.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/MiniFhir.kt
index 6bf60d156..e770d9d6c 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/MiniFhir.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/MiniFhir.kt
@@ -66,9 +66,7 @@ class HumanName(
var family: String? = null,
var given: ArrayList = arrayListOf(),
) {
- fun assembleName(): String {
- return given.joinToString(" ") + " " + family
- }
+ fun assembleName(): String = given.joinToString(" ") + " " + family
}
class Bundle(
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/ThreadAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/ThreadAssembler.kt
index d8bfb83f0..8694a0825 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/ThreadAssembler.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/ThreadAssembler.kt
@@ -62,8 +62,7 @@ class ThreadAssembler {
} else {
null
}
- }
- ?.filterNotNull()
+ }?.filterNotNull()
if (roots != null && roots.isNotEmpty()) {
return roots[0]
@@ -148,9 +147,7 @@ class OnlyLatestVersionSet : MutableSet {
}
}
- override fun addAll(elements: Collection): Boolean {
- return elements.map { add(it) }.any()
- }
+ override fun addAll(elements: Collection): Boolean = elements.map { add(it) }.any()
override val size: Int
get() = set.size
@@ -160,29 +157,17 @@ class OnlyLatestVersionSet : MutableSet {
map.clear()
}
- override fun isEmpty(): Boolean {
- return set.isEmpty()
- }
+ override fun isEmpty(): Boolean = set.isEmpty()
- override fun containsAll(elements: Collection): Boolean {
- return set.containsAll(elements)
- }
+ override fun containsAll(elements: Collection): Boolean = set.containsAll(elements)
- override fun contains(element: Note): Boolean {
- return set.contains(element)
- }
+ override fun contains(element: Note): Boolean = set.contains(element)
- override fun iterator(): MutableIterator {
- return set.iterator()
- }
+ override fun iterator(): MutableIterator = set.iterator()
- override fun retainAll(elements: Collection): Boolean {
- return set.retainAll(elements)
- }
+ override fun retainAll(elements: Collection): Boolean = set.retainAll(elements)
- override fun removeAll(elements: Collection): Boolean {
- return elements.map { remove(it) }.any()
- }
+ override fun removeAll(elements: Collection): Boolean = elements.map { remove(it) }.any()
override fun remove(element: Note): Boolean {
element.address()?.let {
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/ThreadLevelCalculator.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/ThreadLevelCalculator.kt
index 0bc7518b6..3c86c6e97 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/ThreadLevelCalculator.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/ThreadLevelCalculator.kt
@@ -27,16 +27,20 @@ import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
-data class LevelSignature(val signature: String, val createdAt: Long?, val author: User?)
+data class LevelSignature(
+ val signature: String,
+ val createdAt: Long?,
+ val author: User?,
+)
object ThreadLevelCalculator {
val levelFormatter = DateTimeFormatter.ofPattern("uuuu-MM-dd-HH:mm:ss")
- private fun formattedDateTime(timestamp: Long): String {
- return Instant.ofEpochSecond(timestamp)
+ private fun formattedDateTime(timestamp: Long): String =
+ Instant
+ .ofEpochSecond(timestamp)
.atZone(ZoneId.systemDefault())
.format(levelFormatter)
- }
/**
* This method caches signatures during each execution to avoid recalculation in longer threads
@@ -76,8 +80,7 @@ object ThreadLevelCalculator {
accountFollowingSet,
now,
).apply { cachedSignatures.put(it, this) }
- }
- .maxByOrNull { it.signature.length }
+ }.maxByOrNull { it.signature.length }
)
val parentSignature = parent?.signature?.removeSuffix(";") ?: ""
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/UrlCachedPreviewer.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/UrlCachedPreviewer.kt
index 79c51f801..466726a86 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/UrlCachedPreviewer.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/UrlCachedPreviewer.kt
@@ -74,7 +74,6 @@ object UrlCachedPreviewer {
onReady(state)
}
},
- )
- .fetchUrlPreview()
+ ).fetchUrlPreview()
}
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/observables/LatestByKindAndAuthor.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/observables/LatestByKindAndAuthor.kt
index 41fb72896..996e4fb51 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/observables/LatestByKindAndAuthor.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/observables/LatestByKindAndAuthor.kt
@@ -27,7 +27,10 @@ import com.vitorpamplona.quartz.events.Event
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
-class LatestByKindAndAuthor(private val kind: Int, private val pubkey: String) {
+class LatestByKindAndAuthor(
+ private val kind: Int,
+ private val pubkey: String,
+) {
private val _latest = MutableStateFlow(null)
val latest = _latest.asStateFlow()
@@ -41,30 +44,30 @@ class LatestByKindAndAuthor(private val kind: Int, private val pubkey
}
}
- fun canDelete(): Boolean {
- return _latest.subscriptionCount.value == 0
- }
+ fun canDelete(): Boolean = _latest.subscriptionCount.value == 0
suspend fun init() {
val latestNote =
if ((kind in 10000..19999) || (kind in 30000..39999)) {
- LocalCache.addressables.maxOrNullOf(
- filter = { idHex: String, note: AddressableNote ->
- note.event?.let {
- it.kind() == kind && it.pubKey() == pubkey
- } == true
- },
- comparator = CreatedAtComparatorAddresses,
- )?.event as? T
+ LocalCache.addressables
+ .maxOrNullOf(
+ filter = { idHex: String, note: AddressableNote ->
+ note.event?.let {
+ it.kind() == kind && it.pubKey() == pubkey
+ } == true
+ },
+ comparator = CreatedAtComparatorAddresses,
+ )?.event as? T
} else {
- LocalCache.notes.maxOrNullOf(
- filter = { idHex: String, note: Note ->
- note.event?.let {
- it.kind() == kind && it.pubKey() == pubkey
- } == true
- },
- comparator = CreatedAtComparator,
- )?.event as? T
+ LocalCache.notes
+ .maxOrNullOf(
+ filter = { idHex: String, note: Note ->
+ note.event?.let {
+ it.kind() == kind && it.pubKey() == pubkey
+ } == true
+ },
+ comparator = CreatedAtComparator,
+ )?.event as? T
}
_latest.tryEmit(latestNote)
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/observables/LatestByKindWithETag.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/observables/LatestByKindWithETag.kt
index 30796daa0..4b5af6888 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/observables/LatestByKindWithETag.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/observables/LatestByKindWithETag.kt
@@ -26,7 +26,10 @@ import com.vitorpamplona.quartz.events.Event
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
-class LatestByKindWithETag(private val kind: Int, private val eTag: String) {
+class LatestByKindWithETag(
+ private val kind: Int,
+ private val eTag: String,
+) {
private val _latest = MutableStateFlow(null)
val latest = _latest.asStateFlow()
@@ -40,20 +43,19 @@ class LatestByKindWithETag(private val kind: Int, private val eTag: S
}
}
- fun canDelete(): Boolean {
- return _latest.subscriptionCount.value == 0
- }
+ fun canDelete(): Boolean = _latest.subscriptionCount.value == 0
suspend fun init() {
val latestNote =
- LocalCache.notes.maxOrNullOf(
- filter = { idHex: String, note: Note ->
- note.event?.let {
- it.kind() == kind && it.isTaggedEvent(eTag)
- } == true
- },
- comparator = CreatedAtComparator,
- )?.event as? T
+ LocalCache.notes
+ .maxOrNullOf(
+ filter = { idHex: String, note: Note ->
+ note.event?.let {
+ it.kind() == kind && it.isTaggedEvent(eTag)
+ } == true
+ },
+ comparator = CreatedAtComparator,
+ )?.event as? T
_latest.tryEmit(latestNote)
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/AmethystNostrDataSource.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/AmethystNostrDataSource.kt
index 244d60a1f..99e7d12b2 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/AmethystNostrDataSource.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/AmethystNostrDataSource.kt
@@ -26,7 +26,9 @@ import com.vitorpamplona.ammolite.relays.Relay
import com.vitorpamplona.quartz.events.AddressableEvent
import com.vitorpamplona.quartz.events.Event
-abstract class AmethystNostrDataSource(debugName: String) : NostrDataSource(debugName) {
+abstract class AmethystNostrDataSource(
+ debugName: String,
+) : NostrDataSource(debugName) {
override fun consume(
event: Event,
relay: Relay,
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/BlurHashImage.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/BlurHashImage.kt
index 412289fbb..b87e2f570 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/BlurHashImage.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/BlurHashImage.kt
@@ -59,9 +59,7 @@ class BlurHashFetcher(
data: Uri,
options: Options,
imageLoader: ImageLoader,
- ): Fetcher {
- return BlurHashFetcher(options, data)
- }
+ ): Fetcher = BlurHashFetcher(options, data)
}
}
@@ -72,7 +70,8 @@ object BlurHashRequester {
): ImageRequest {
val encodedMessage = URLEncoder.encode(message, "utf-8")
- return ImageRequest.Builder(context)
+ return ImageRequest
+ .Builder(context)
.data("bluehash:$encodedMessage")
.fetcherFactory(BlurHashFetcher.Factory)
.build()
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/EmojiUtils.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/EmojiUtils.kt
index 8f1e1ab60..c47a21b0d 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/EmojiUtils.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/EmojiUtils.kt
@@ -22,9 +22,7 @@ package com.vitorpamplona.amethyst.service
import com.vitorpamplona.quartz.events.ImmutableListOfLists
-fun String.isUTF16Char(pos: Int): Boolean {
- return Character.charCount(this.codePointAt(pos)) == 2
-}
+fun String.isUTF16Char(pos: Int): Boolean = Character.charCount(this.codePointAt(pos)) == 2
fun String.firstFullCharOld(): String {
return when (this.length) {
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/FileHeader.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/FileHeader.kt
index cdb33e6d6..1fc2400a2 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/FileHeader.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/FileHeader.kt
@@ -236,10 +236,10 @@ fun MediaMetadataRetriever.prepareVideoHeight(): Int? {
}
}
-class ByteArrayMediaDataSource(var imageData: ByteArray) : MediaDataSource() {
- override fun getSize(): Long {
- return imageData.size.toLong()
- }
+class ByteArrayMediaDataSource(
+ var imageData: ByteArray,
+) : MediaDataSource() {
+ override fun getSize(): Long = imageData.size.toLong()
@Throws(IOException::class)
override fun readAt(
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/LocationUtil.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/LocationUtil.kt
index cf02079bf..79ffb292c 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/LocationUtil.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/LocationUtil.kt
@@ -33,7 +33,9 @@ import androidx.compose.runtime.mutableStateOf
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.flow.MutableStateFlow
-class LocationUtil(context: Context) {
+class LocationUtil(
+ context: Context,
+) {
companion object {
const val MIN_TIME: Long = 1000L
const val MIN_DISTANCE: Float = 0.0f
@@ -96,9 +98,7 @@ class LocationUtil(context: Context) {
object CachedGeoLocations {
val locationNames = LruCache(20)
- fun cached(geoHashStr: String): String? {
- return locationNames[geoHashStr]
- }
+ fun cached(geoHashStr: String): String? = locationNames[geoHashStr]
suspend fun geoLocate(
geoHashStr: String,
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/MainThreadChecker.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/MainThreadChecker.kt
index 8d027dbdb..a985b04de 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/MainThreadChecker.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/MainThreadChecker.kt
@@ -31,4 +31,6 @@ fun checkNotInMainThread() {
fun isMainThread() = Looper.myLooper() == Looper.getMainLooper()
-class OnMainThreadException(str: String) : RuntimeException(str)
+class OnMainThreadException(
+ str: String,
+) : RuntimeException(str)
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/Nip96MediaServers.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/Nip96MediaServers.kt
index 07f7244eb..3aca30ca6 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/Nip96MediaServers.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/Nip96MediaServers.kt
@@ -38,7 +38,10 @@ object Nip96MediaServers {
ServerName("Void.cat", "https://void.cat"),
)
- data class ServerName(val name: String, val baseUrl: String)
+ data class ServerName(
+ val name: String,
+ val baseUrl: String,
+ )
val cache: MutableMap = mutableMapOf()
@@ -83,7 +86,8 @@ class Nip96Retriever {
checkNotInMainThread()
val request: Request =
- Request.Builder()
+ Request
+ .Builder()
.header("Accept", "application/nostr+json")
.url(baseUrl.removeSuffix("/") + "/.well-known/nostr/nip96.json")
.build()
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/OnlineCheck.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/OnlineCheck.kt
index 72e11ab2e..72c8fd396 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/OnlineCheck.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/OnlineCheck.kt
@@ -32,7 +32,10 @@ import okhttp3.Request
import okio.ByteString.Companion.toByteString
import kotlin.coroutines.cancellation.CancellationException
-@Immutable data class OnlineCheckResult(val timeInMs: Long, val online: Boolean)
+@Immutable data class OnlineCheckResult(
+ val timeInMs: Long,
+ val online: Boolean,
+)
object OnlineChecker {
val checkOnlineCache = LruCache(100)
@@ -58,7 +61,8 @@ object OnlineChecker {
val result =
if (url.startsWith("wss")) {
val request =
- Request.Builder()
+ Request
+ .Builder()
.header("User-Agent", "Amethyst/${BuildConfig.VERSION_NAME}")
.url(url.replace("wss+livekit://", "wss://"))
.header("Upgrade", "websocket")
@@ -69,7 +73,9 @@ object OnlineChecker {
.build()
val client =
- HttpClientManager.getHttpClient().newBuilder()
+ HttpClientManager
+ .getHttpClient()
+ .newBuilder()
.eventListener(EventListener.NONE)
.protocols(listOf(Protocol.HTTP_1_1))
.build()
@@ -80,7 +86,8 @@ object OnlineChecker {
}
} else {
val request =
- Request.Builder()
+ Request
+ .Builder()
.header("User-Agent", "Amethyst/${BuildConfig.VERSION_NAME}")
.url(url)
.get()
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/PackageUtils.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/PackageUtils.kt
index 07a978d2e..736911a54 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/PackageUtils.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/PackageUtils.kt
@@ -28,15 +28,12 @@ object PackageUtils {
private fun isPackageInstalled(
context: Context,
target: String,
- ): Boolean {
- return context.packageManager.getInstalledApplications(0).find { info ->
+ ): Boolean =
+ context.packageManager.getInstalledApplications(0).find { info ->
info.packageName == target
} != null
- }
- fun isOrbotInstalled(context: Context): Boolean {
- return isPackageInstalled(context, "org.torproject.android")
- }
+ fun isOrbotInstalled(context: Context): Boolean = isPackageInstalled(context, "org.torproject.android")
fun isExternalSignerInstalled(context: Context): Boolean {
val intent =
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/lnurl/CachedLnInvoice.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/lnurl/CachedLnInvoice.kt
index 67a7edcc4..cd71080f2 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/lnurl/CachedLnInvoice.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/lnurl/CachedLnInvoice.kt
@@ -27,14 +27,15 @@ import kotlinx.coroutines.CancellationException
import java.text.NumberFormat
@Stable
-data class InvoiceAmount(val invoice: String, val amount: String?)
+data class InvoiceAmount(
+ val invoice: String,
+ val amount: String?,
+)
object CachedLnInvoiceParser {
val lnInvoicesCache = LruCache(20)
- fun cached(lnurl: String): InvoiceAmount? {
- return lnInvoicesCache[lnurl]
- }
+ fun cached(lnurl: String): InvoiceAmount? = lnInvoicesCache[lnurl]
fun parse(lnbcWord: String): InvoiceAmount? {
val myInvoice = LnInvoiceUtil.findInvoice(lnbcWord)
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/ots/OkHttpBlockstreamExplorer.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/ots/OkHttpBlockstreamExplorer.kt
index eeb092395..defcf6cbb 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/ots/OkHttpBlockstreamExplorer.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/ots/OkHttpBlockstreamExplorer.kt
@@ -42,7 +42,8 @@ class OkHttpBlockstreamExplorer : BitcoinExplorer {
val url = "$BLOCKSTREAM_API_URL/block/$hash"
val request =
- Request.Builder()
+ Request
+ .Builder()
.header("User-Agent", "Amethyst/${BuildConfig.VERSION_NAME}")
.header("Accept", "application/json")
.url(url)
@@ -79,7 +80,8 @@ class OkHttpBlockstreamExplorer : BitcoinExplorer {
val url = "$BLOCKSTREAM_API_URL/block-height/$height"
val request =
- Request.Builder()
+ Request
+ .Builder()
.header("User-Agent", "Amethyst/${BuildConfig.VERSION_NAME}")
.url(url)
.get()
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/ots/OkHttpCalendarAsyncSubmit.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/ots/OkHttpCalendarAsyncSubmit.kt
index 515f9150e..855b7c761 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/ots/OkHttpCalendarAsyncSubmit.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/ots/OkHttpCalendarAsyncSubmit.kt
@@ -33,7 +33,10 @@ import java.util.concurrent.BlockingQueue
/**
* For making async calls to a calendar server
*/
-class OkHttpCalendarAsyncSubmit(private val url: String, private val digest: ByteArray) : ICalendarAsyncSubmit {
+class OkHttpCalendarAsyncSubmit(
+ private val url: String,
+ private val digest: ByteArray,
+) : ICalendarAsyncSubmit {
private var queue: BlockingQueue>? = null
fun setQueue(queue: BlockingQueue>?) {
@@ -49,7 +52,8 @@ class OkHttpCalendarAsyncSubmit(private val url: String, private val digest: Byt
val requestBody = digest.toRequestBody(mediaType)
val request =
- okhttp3.Request.Builder()
+ okhttp3.Request
+ .Builder()
.header("User-Agent", "Amethyst/${BuildConfig.VERSION_NAME}")
.header("Accept", "application/vnd.opentimestamps.v1")
.header("Content-Type", "application/x-www-form-urlencoded")
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/ots/OkHttpCalendarBuilder.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/ots/OkHttpCalendarBuilder.kt
index b8f9408a8..a565d5fde 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/ots/OkHttpCalendarBuilder.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/ots/OkHttpCalendarBuilder.kt
@@ -25,14 +25,10 @@ import com.vitorpamplona.quartz.ots.ICalendar
import com.vitorpamplona.quartz.ots.ICalendarAsyncSubmit
class OkHttpCalendarBuilder : CalendarBuilder {
- override fun newSyncCalendar(url: String): ICalendar {
- return OkHttpCalendar(url)
- }
+ override fun newSyncCalendar(url: String): ICalendar = OkHttpCalendar(url)
override fun newAsyncCalendar(
url: String,
digest: ByteArray,
- ): ICalendarAsyncSubmit {
- return OkHttpCalendarAsyncSubmit(url, digest)
- }
+ ): ICalendarAsyncSubmit = OkHttpCalendarAsyncSubmit(url, digest)
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/VideoCache.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/VideoCache.kt
index c13aeb560..cfcd9042d 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/VideoCache.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/VideoCache.kt
@@ -59,12 +59,12 @@ class VideoCache {
// This method should be called when proxy setting changes.
fun renewCacheFactory(client: OkHttpClient) {
cacheDataSourceFactory =
- CacheDataSource.Factory()
+ CacheDataSource
+ .Factory()
.setCache(simpleCache)
.setUpstreamDataSourceFactory(
OkHttpDataSource.Factory(client),
- )
- .setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR)
+ ).setFlags(CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR)
}
fun get(client: OkHttpClient): CacheDataSource.Factory {
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/VideoViewedPositionCache.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/VideoViewedPositionCache.kt
index e0867cd1c..615990480 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/VideoViewedPositionCache.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/VideoViewedPositionCache.kt
@@ -32,7 +32,5 @@ class VideoViewedPositionCache {
cachedPosition.put(uri, position)
}
- fun get(uri: String): Long? {
- return cachedPosition.get(uri)
- }
+ fun get(uri: String): Long? = cachedPosition.get(uri)
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/WssDataStreamCollector.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/WssDataStreamCollector.kt
index 2af443c10..49fae2804 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/WssDataStreamCollector.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/WssDataStreamCollector.kt
@@ -44,11 +44,7 @@ class WssDataStreamCollector : WebSocketListener() {
wssData.removeAll(wssData)
}
- fun canStream(): Boolean {
- return wssData.size > 0
- }
+ fun canStream(): Boolean = wssData.size > 0
- fun getNextStream(): ByteString {
- return wssData.pollFirst()
- }
+ fun getNextStream(): ByteString = wssData.pollFirst()
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/WssStreamDataSource.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/WssStreamDataSource.kt
index 0a95bd7d6..9e9be49a0 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/WssStreamDataSource.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/playback/WssStreamDataSource.kt
@@ -32,7 +32,9 @@ import okhttp3.WebSocket
import kotlin.math.min
@OptIn(UnstableApi::class)
-class WssStreamDataSource(val httpClient: OkHttpClient) : BaseDataSource(true) {
+class WssStreamDataSource(
+ val httpClient: OkHttpClient,
+) : BaseDataSource(true) {
val dataStreamCollector: WssDataStreamCollector = WssDataStreamCollector()
var webSocketClient: WebSocket? = null
@@ -46,11 +48,14 @@ class WssStreamDataSource(val httpClient: OkHttpClient) : BaseDataSource(true) {
// which collects the data for us (Previous class).
webSocketClient =
httpClient.newWebSocket(
- Request.Builder().apply {
- dataSpec.httpRequestHeaders.forEach { entry ->
- addHeader(entry.key, entry.value)
- }
- }.url(dataSpec.uri.toString()).build(),
+ Request
+ .Builder()
+ .apply {
+ dataSpec.httpRequestHeaders.forEach { entry ->
+ addHeader(entry.key, entry.value)
+ }
+ }.url(dataSpec.uri.toString())
+ .build(),
dataStreamCollector,
)
@@ -106,7 +111,9 @@ class WssStreamDataSource(val httpClient: OkHttpClient) : BaseDataSource(true) {
}
// Factory class for DataSource
- class Factory(val okHttpClient: OkHttpClient) : DataSource.Factory {
+ class Factory(
+ val okHttpClient: OkHttpClient,
+ ) : DataSource.Factory {
override fun createDataSource(): DataSource = WssStreamDataSource(okHttpClient)
}
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/BahaUrlPreview.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/BahaUrlPreview.kt
index e5b326c9c..0678a92c5 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/BahaUrlPreview.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/BahaUrlPreview.kt
@@ -22,7 +22,10 @@ package com.vitorpamplona.amethyst.service.previews
import kotlinx.coroutines.CancellationException
-class BahaUrlPreview(val url: String, var callback: IUrlPreviewCallback?) {
+class BahaUrlPreview(
+ val url: String,
+ var callback: IUrlPreviewCallback?,
+) {
suspend fun fetchUrlPreview(timeOut: Int = 30000) =
try {
fetch(timeOut)
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/UrlInfoItem.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/UrlInfoItem.kt
index 5f5fb186d..720abcdab 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/UrlInfoItem.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/UrlInfoItem.kt
@@ -40,11 +40,7 @@ class UrlInfoItem(
image
}
- fun fetchComplete(): Boolean {
- return url.isNotEmpty() && image.isNotEmpty()
- }
+ fun fetchComplete(): Boolean = url.isNotEmpty() && image.isNotEmpty()
- fun allFetchComplete(): Boolean {
- return title.isNotEmpty() && description.isNotEmpty() && image.isNotEmpty()
- }
+ fun allFetchComplete(): Boolean = title.isNotEmpty() && description.isNotEmpty() && image.isNotEmpty()
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/UrlPreviewUtils.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/UrlPreviewUtils.kt
index 79fb36e32..fc99a7cd3 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/UrlPreviewUtils.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/previews/UrlPreviewUtils.kt
@@ -71,7 +71,12 @@ suspend fun getDocument(
timeOut: Int = 30000,
): UrlInfoItem =
withContext(Dispatchers.IO) {
- val request: Request = Request.Builder().url(url).get().build()
+ val request: Request =
+ Request
+ .Builder()
+ .url(url)
+ .get()
+ .build()
HttpClientManager.getHttpClient().newCall(request).execute().use {
checkNotInMainThread()
if (it.isSuccessful) {
@@ -132,8 +137,8 @@ private val UNICODE_BOMS =
"ffff0000".decodeHex(),
)
-private fun BufferedSource.readBomAsCharset(): Charset? {
- return when (select(UNICODE_BOMS)) {
+private fun BufferedSource.readBomAsCharset(): Charset? =
+ when (select(UNICODE_BOMS)) {
0 -> Charsets.UTF_8
1 -> Charsets.UTF_16BE
2 -> Charsets.UTF_16LE
@@ -142,7 +147,6 @@ private fun BufferedSource.readBomAsCharset(): Charset? {
-1 -> null
else -> throw AssertionError()
}
-}
private val RE_CONTENT_TYPE_CHARSET = Regex("""charset=([^;]+)""")
@@ -158,7 +162,8 @@ private fun detectCharset(bodyBytes: ByteArray): Charset {
}
}
if (meta.attr(ATTRIBUTE_VALUE_HTTP_EQUIV).lowercase() == "content-type") {
- RE_CONTENT_TYPE_CHARSET.find(meta.attr(CONTENT))
+ RE_CONTENT_TYPE_CHARSET
+ .find(meta.attr(CONTENT))
?.let {
runCatching { Charset.forName(it.groupValues[1]) }.getOrNull()
}?.let {
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relays/EOSE.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relays/EOSE.kt
index 83f2e9729..bb3693bd9 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relays/EOSE.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relays/EOSE.kt
@@ -23,7 +23,9 @@ package com.vitorpamplona.amethyst.service.relays
import com.vitorpamplona.amethyst.model.User
import com.vitorpamplona.ammolite.relays.EOSETime
-class EOSERelayList(var relayList: Map = emptyMap()) {
+class EOSERelayList(
+ var relayList: Map = emptyMap(),
+) {
fun addOrUpdate(
relayUrl: String,
time: Long,
@@ -37,7 +39,9 @@ class EOSERelayList(var relayList: Map = emptyMap()) {
}
}
-class EOSEFollowList(var followList: Map = emptyMap()) {
+class EOSEFollowList(
+ var followList: Map = emptyMap(),
+) {
fun addOrUpdate(
listCode: String,
relayUrl: String,
@@ -54,7 +58,9 @@ class EOSEFollowList(var followList: Map = emptyMap()) {
}
}
-class EOSEAccount(var users: Map = emptyMap()) {
+class EOSEAccount(
+ var users: Map = emptyMap(),
+) {
fun addOrUpdate(
user: User,
listCode: String,
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/tts/TextToSpeechHelper.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/tts/TextToSpeechHelper.kt
index 26de2fed8..351267a70 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/tts/TextToSpeechHelper.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/tts/TextToSpeechHelper.kt
@@ -28,150 +28,152 @@ import androidx.lifecycle.LifecycleOwner
import java.lang.ref.WeakReference
import java.util.Locale
-class TextToSpeechHelper private constructor(private val context: WeakReference) :
- LifecycleEventObserver {
- private val appContext
- get() = context.get()!!.applicationContext
+class TextToSpeechHelper private constructor(
+ private val context: WeakReference,
+) : LifecycleEventObserver {
+ private val appContext
+ get() = context.get()!!.applicationContext
- private var message: String? = null
+ private var message: String? = null
- private var ttsEngine: TextToSpeechEngine? = null
+ private var ttsEngine: TextToSpeechEngine? = null
- private var onStart: (() -> Unit)? = null
+ private var onStart: (() -> Unit)? = null
- private var onDoneListener: (() -> Unit)? = null
+ private var onDoneListener: (() -> Unit)? = null
- private var onErrorListener: ((String) -> Unit)? = null
+ private var onErrorListener: ((String) -> Unit)? = null
- private var onHighlightListener: ((Pair) -> Unit)? = null
+ private var onHighlightListener: ((Pair) -> Unit)? = null
- private var customActionForDestroy: (() -> Unit)? = null
+ private var customActionForDestroy: (() -> Unit)? = null
- init {
- Log.d("Init", "Init TTS")
+ init {
+ Log.d("Init", "Init TTS")
+ initTTS()
+ }
+
+ fun registerLifecycle(owner: LifecycleOwner): TextToSpeechHelper {
+ owner.lifecycle.addObserver(this)
+ return this
+ }
+
+ private fun initTTS() =
+ context.get()?.run {
+ ttsEngine =
+ TextToSpeechEngine
+ .getInstance()
+ .setOnCompletionListener { onDoneListener?.invoke() }
+ .setOnErrorListener { onErrorListener?.invoke(it) }
+ .setOnStartListener { onStart?.invoke() }
+ }
+
+ fun speak(message: String): TextToSpeechHelper {
+ if (ttsEngine == null) {
initTTS()
}
+ this.message = message
- fun registerLifecycle(owner: LifecycleOwner): TextToSpeechHelper {
- owner.lifecycle.addObserver(this)
- return this
+ ttsEngine?.initTTS(
+ appContext,
+ message,
+ )
+ return this
+ }
+
+ /**
+ * This method will highlight the text in the textView
+ *
+ * @exception Exception("Message can't be null for highlighting !! Call speak() first")
+ */
+ fun highlight(): TextToSpeechHelper {
+ if (message == null) {
+ throw Exception("Message can't be null for highlighting !! Call speak() first")
}
+ ttsEngine?.setHighlightedMessage(message!!)
+ ttsEngine?.setOnHighlightListener { i, i2 -> onHighlightListener?.invoke(Pair(i, i2)) }
+ return this
+ }
- private fun initTTS() =
- context.get()?.run {
- ttsEngine =
- TextToSpeechEngine.getInstance()
- .setOnCompletionListener { onDoneListener?.invoke() }
- .setOnErrorListener { onErrorListener?.invoke(it) }
- .setOnStartListener { onStart?.invoke() }
- }
+ fun removeHighlight(): TextToSpeechHelper {
+ message = null
+ onHighlightListener = null
+ return this
+ }
- fun speak(message: String): TextToSpeechHelper {
- if (ttsEngine == null) {
- initTTS()
- }
- this.message = message
+ fun destroy(action: (() -> Unit) = {}) {
+ ttsEngine?.destroy()
+ ttsEngine = null
+ action.invoke()
+ instance = null
+ }
- ttsEngine?.initTTS(
- appContext,
- message,
- )
- return this
- }
+ fun onStart(onStartListener: () -> Unit): TextToSpeechHelper {
+ this.onStart = onStartListener
+ return this
+ }
- /**
- * This method will highlight the text in the textView
- *
- * @exception Exception("Message can't be null for highlighting !! Call speak() first")
- */
- fun highlight(): TextToSpeechHelper {
- if (message == null) {
- throw Exception("Message can't be null for highlighting !! Call speak() first")
- }
- ttsEngine?.setHighlightedMessage(message!!)
- ttsEngine?.setOnHighlightListener { i, i2 -> onHighlightListener?.invoke(Pair(i, i2)) }
- return this
- }
+ fun onDone(onCompleteListener: () -> Unit): TextToSpeechHelper {
+ this.onDoneListener = onCompleteListener
+ return this
+ }
- fun removeHighlight(): TextToSpeechHelper {
- message = null
- onHighlightListener = null
- return this
- }
+ fun onError(onErrorListener: (String) -> Unit): TextToSpeechHelper {
+ this.onErrorListener = onErrorListener
+ return this
+ }
- fun destroy(action: (() -> Unit) = {}) {
- ttsEngine?.destroy()
- ttsEngine = null
- action.invoke()
- instance = null
- }
+ fun onHighlight(onHighlightListener: (Pair) -> Unit): TextToSpeechHelper {
+ this.onHighlightListener = onHighlightListener
+ return this
+ }
- fun onStart(onStartListener: () -> Unit): TextToSpeechHelper {
- this.onStart = onStartListener
- return this
- }
+ fun setCustomActionForDestroy(action: () -> Unit): TextToSpeechHelper {
+ customActionForDestroy = action
+ return this
+ }
- fun onDone(onCompleteListener: () -> Unit): TextToSpeechHelper {
- this.onDoneListener = onCompleteListener
- return this
- }
+ fun setLanguage(locale: Locale): TextToSpeechHelper {
+ ttsEngine?.setLanguage(locale)
+ return this
+ }
- fun onError(onErrorListener: (String) -> Unit): TextToSpeechHelper {
- this.onErrorListener = onErrorListener
- return this
- }
+ fun setPitchAndSpeed(
+ pitch: Float = DEF_SPEECH_AND_PITCH,
+ speed: Float = DEF_SPEECH_AND_PITCH,
+ ): TextToSpeechHelper {
+ ttsEngine?.setPitchAndSpeed(pitch, speed)
+ return this
+ }
- fun onHighlight(onHighlightListener: (Pair) -> Unit): TextToSpeechHelper {
- this.onHighlightListener = onHighlightListener
- return this
- }
+ fun resetPitchAndSpeed(): TextToSpeechHelper {
+ ttsEngine?.resetPitchAndSpeed()
+ return this
+ }
- fun setCustomActionForDestroy(action: () -> Unit): TextToSpeechHelper {
- customActionForDestroy = action
- return this
- }
+ companion object {
+ private var instance: TextToSpeechHelper? = null
- fun setLanguage(locale: Locale): TextToSpeechHelper {
- ttsEngine?.setLanguage(locale)
- return this
- }
-
- fun setPitchAndSpeed(
- pitch: Float = DEF_SPEECH_AND_PITCH,
- speed: Float = DEF_SPEECH_AND_PITCH,
- ): TextToSpeechHelper {
- ttsEngine?.setPitchAndSpeed(pitch, speed)
- return this
- }
-
- fun resetPitchAndSpeed(): TextToSpeechHelper {
- ttsEngine?.resetPitchAndSpeed()
- return this
- }
-
- companion object {
- private var instance: TextToSpeechHelper? = null
-
- fun getInstance(context: Context): TextToSpeechHelper {
- synchronized(TextToSpeechHelper::class.java) {
- if (instance == null) {
- instance = TextToSpeechHelper(WeakReference(context))
- }
- return instance!!
+ fun getInstance(context: Context): TextToSpeechHelper {
+ synchronized(TextToSpeechHelper::class.java) {
+ if (instance == null) {
+ instance = TextToSpeechHelper(WeakReference(context))
}
- }
- }
-
- override fun onStateChanged(
- source: LifecycleOwner,
- event: Lifecycle.Event,
- ) {
- if (
- event == Lifecycle.Event.ON_DESTROY ||
- event == Lifecycle.Event.ON_STOP ||
- event == Lifecycle.Event.ON_PAUSE
- ) {
- destroy { customActionForDestroy?.invoke() }
+ return instance!!
}
}
}
+
+ override fun onStateChanged(
+ source: LifecycleOwner,
+ event: Lifecycle.Event,
+ ) {
+ if (
+ event == Lifecycle.Event.ON_DESTROY ||
+ event == Lifecycle.Event.ON_STOP ||
+ event == Lifecycle.Event.ON_PAUSE
+ ) {
+ destroy { customActionForDestroy?.invoke() }
+ }
+ }
+}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/ImageSaver.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/ImageSaver.kt
index d044d249e..63dcd3a23 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/ImageSaver.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/ImageSaver.kt
@@ -88,7 +88,8 @@ object ImageSaver {
val client = HttpClientManager.getHttpClient()
val request =
- Request.Builder()
+ Request
+ .Builder()
.header("User-Agent", "Amethyst/${BuildConfig.VERSION_NAME}")
.get()
.url(url)
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/UrlUserTagTransformation.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/UrlUserTagTransformation.kt
index 7c2c34965..265f32891 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/UrlUserTagTransformation.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/UrlUserTagTransformation.kt
@@ -35,12 +35,15 @@ import com.vitorpamplona.quartz.encoders.decodePublicKey
import com.vitorpamplona.quartz.encoders.toHexKey
import kotlin.coroutines.cancellation.CancellationException
-data class RangesChanges(val original: TextRange, val modified: TextRange)
+data class RangesChanges(
+ val original: TextRange,
+ val modified: TextRange,
+)
-class UrlUserTagTransformation(val color: Color) : VisualTransformation {
- override fun filter(text: AnnotatedString): TransformedText {
- return buildAnnotatedStringWithUrlHighlighting(text, color)
- }
+class UrlUserTagTransformation(
+ val color: Color,
+) : VisualTransformation {
+ override fun filter(text: AnnotatedString): TransformedText = buildAnnotatedStringWithUrlHighlighting(text, color)
}
fun buildAnnotatedStringWithUrlHighlighting(
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/BasicRelaySetupInfoModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/BasicRelaySetupInfoModel.kt
index 9eea0faa9..a4f64e1b5 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/BasicRelaySetupInfoModel.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/BasicRelaySetupInfoModel.kt
@@ -78,12 +78,15 @@ abstract class BasicRelaySetupInfoModel : ViewModel() {
_relays.update {
val relayList = getRelayList() ?: emptyList()
- relayList.map { relayUrl ->
- BasicRelaySetupInfo(
- RelayUrlFormatter.normalize(relayUrl),
- RelayStats.get(relayUrl),
- )
- }.distinctBy { it.url }.sortedBy { it.relayStat.receivedBytes }.reversed()
+ relayList
+ .map { relayUrl ->
+ BasicRelaySetupInfo(
+ RelayUrlFormatter.normalize(relayUrl),
+ RelayStats.get(relayUrl),
+ )
+ }.distinctBy { it.url }
+ .sortedBy { it.relayStat.receivedBytes }
+ .reversed()
}
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/DMRelayListViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/DMRelayListViewModel.kt
index 27c0534ec..5dff04edc 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/DMRelayListViewModel.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/DMRelayListViewModel.kt
@@ -21,9 +21,7 @@
package com.vitorpamplona.amethyst.ui.actions.relays
class DMRelayListViewModel : BasicRelaySetupInfoModel() {
- override fun getRelayList(): List? {
- return account.getDMRelayList()?.relays()
- }
+ override fun getRelayList(): List? = account.getDMRelayList()?.relays()
override fun saveRelayList(urlList: List) {
account.saveDMRelayList(urlList)
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/LocalRelayListViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/LocalRelayListViewModel.kt
index 6c5359b36..803eb87b4 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/LocalRelayListViewModel.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/LocalRelayListViewModel.kt
@@ -21,9 +21,7 @@
package com.vitorpamplona.amethyst.ui.actions.relays
class LocalRelayListViewModel : BasicRelaySetupInfoModel() {
- override fun getRelayList(): List? {
- return account.localRelayServers.toList()
- }
+ override fun getRelayList(): List? = account.localRelayServers.toList()
override fun saveRelayList(urlList: List) {
account.updateLocalRelayServers(urlList.toSet())
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Nip65RelayListViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Nip65RelayListViewModel.kt
index c41ce2c1d..2fdfe7237 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Nip65RelayListViewModel.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/Nip65RelayListViewModel.kt
@@ -105,23 +105,29 @@ class Nip65RelayListViewModel : ViewModel() {
_homeRelays.update {
val relayList = account.getNIP65RelayList()?.writeRelays() ?: emptyList()
- relayList.map { relayUrl ->
- BasicRelaySetupInfo(
- RelayUrlFormatter.normalize(relayUrl),
- RelayStats.get(relayUrl),
- )
- }.distinctBy { it.url }.sortedBy { it.relayStat.receivedBytes }.reversed()
+ relayList
+ .map { relayUrl ->
+ BasicRelaySetupInfo(
+ RelayUrlFormatter.normalize(relayUrl),
+ RelayStats.get(relayUrl),
+ )
+ }.distinctBy { it.url }
+ .sortedBy { it.relayStat.receivedBytes }
+ .reversed()
}
_notificationRelays.update {
val relayList = account.getNIP65RelayList()?.readRelays() ?: emptyList()
- relayList.map { relayUrl ->
- BasicRelaySetupInfo(
- RelayUrlFormatter.normalize(relayUrl),
- RelayStats.get(relayUrl),
- )
- }.distinctBy { it.url }.sortedBy { it.relayStat.receivedBytes }.reversed()
+ relayList
+ .map { relayUrl ->
+ BasicRelaySetupInfo(
+ RelayUrlFormatter.normalize(relayUrl),
+ RelayStats.get(relayUrl),
+ )
+ }.distinctBy { it.url }
+ .sortedBy { it.relayStat.receivedBytes }
+ .reversed()
}
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/PrivateOutboxRelayListViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/PrivateOutboxRelayListViewModel.kt
index 8d5ce7837..92f2c9137 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/PrivateOutboxRelayListViewModel.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/PrivateOutboxRelayListViewModel.kt
@@ -21,9 +21,7 @@
package com.vitorpamplona.amethyst.ui.actions.relays
class PrivateOutboxRelayListViewModel : BasicRelaySetupInfoModel() {
- override fun getRelayList(): List? {
- return account.getPrivateOutboxRelayList()?.relays()
- }
+ override fun getRelayList(): List? = account.getPrivateOutboxRelayList()?.relays()
override fun saveRelayList(urlList: List) {
account.savePrivateOutboxRelayList(urlList)
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/RelayInformationDialog.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/RelayInformationDialog.kt
index 368f5b3ee..3fe171c84 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/RelayInformationDialog.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/RelayInformationDialog.kt
@@ -100,7 +100,11 @@ fun RelayInformationDialog(
),
) {
Surface {
- val color = mutableStateOf(Color.Transparent)
+ val color =
+ remember {
+ mutableStateOf(Color.Transparent)
+ }
+
val context = LocalContext.current
LazyColumn(
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/SearchRelayListViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/SearchRelayListViewModel.kt
index da89cd245..cd1786216 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/SearchRelayListViewModel.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/relays/SearchRelayListViewModel.kt
@@ -21,9 +21,7 @@
package com.vitorpamplona.amethyst.ui.actions.relays
class SearchRelayListViewModel : BasicRelaySetupInfoModel() {
- override fun getRelayList(): List? {
- return account.getSearchRelayList()?.relays()
- }
+ override fun getRelayList(): List? = account.getSearchRelayList()?.relays()
override fun saveRelayList(urlList: List) {
account.saveSearchRelayList(urlList)
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/AudioWaveformReadOnly.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/AudioWaveformReadOnly.kt
index 7002a976e..ac1006b0f 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/AudioWaveformReadOnly.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/AudioWaveformReadOnly.kt
@@ -101,11 +101,11 @@ fun AudioWaveformReadOnly(
minHeight = MIN_SPIKE_HEIGHT,
maxHeight = canvasSize.height.coerceAtLeast(MIN_SPIKE_HEIGHT),
)
- }
- .map { animateFloatAsState(it, spikeAnimationSpec).value }
+ }.map { animateFloatAsState(it, spikeAnimationSpec).value }
Canvas(
modifier =
- Modifier.fillMaxWidth()
+ Modifier
+ .fillMaxWidth()
.requiredHeight(48.dp)
.graphicsLayer(alpha = DEFAULT_GRAPHICS_LAYER_ALPHA)
.then(modifier),
@@ -161,8 +161,7 @@ private fun List.toDrawableAmplitudes(
AmplitudeType.Avg -> data.average()
AmplitudeType.Max -> data.max()
AmplitudeType.Min -> data.min()
- }
- .toFloat()
+ }.toFloat()
.coerceIn(minHeight, maxHeight)
}
return when {
@@ -198,9 +197,7 @@ internal fun Iterable.chunkToSize(
internal fun Iterable.normalize(
min: Float,
max: Float,
-): List {
- return map { (max - min) * ((it - min()) / (max() - min())) + min }
-}
+): List = map { (max - min) * ((it - min()) / (max() - min())) + min }
private fun Int.safeDiv(value: Int): Float {
return if (value == 0) return 0F else this / value.toFloat()
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/GenericLoadable.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/GenericLoadable.kt
index 6817b873f..f2eb7d9e1 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/GenericLoadable.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/GenericLoadable.kt
@@ -26,9 +26,13 @@ import androidx.compose.runtime.Immutable
sealed class GenericLoadable {
@Immutable class Loading : GenericLoadable()
- @Immutable class Loaded(val loaded: T) : GenericLoadable()
+ @Immutable class Loaded(
+ val loaded: T,
+ ) : GenericLoadable()
@Immutable class Empty : GenericLoadable()
- @Immutable class Error(val errorMessage: String) : GenericLoadable()
+ @Immutable class Error(
+ val errorMessage: String,
+ ) : GenericLoadable()
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/SplitItem.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/SplitItem.kt
index 887ae463f..8998cd0a4 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/SplitItem.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/SplitItem.kt
@@ -25,12 +25,14 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import kotlin.math.abs
-class SplitItem(val key: T) {
+class SplitItem(
+ val key: T,
+) {
// 0 to 1
var percentage by mutableStateOf(0f)
}
-class Split() {
+class Split {
var items: List> by mutableStateOf(emptyList())
fun addItem(
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/UrlPreviewState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/UrlPreviewState.kt
index beef6d771..533acdef2 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/UrlPreviewState.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/UrlPreviewState.kt
@@ -27,9 +27,13 @@ import com.vitorpamplona.amethyst.service.previews.UrlInfoItem
sealed class UrlPreviewState {
@Immutable object Loading : UrlPreviewState()
- @Immutable class Loaded(val previewInfo: UrlInfoItem) : UrlPreviewState()
+ @Immutable class Loaded(
+ val previewInfo: UrlInfoItem,
+ ) : UrlPreviewState()
@Immutable object Empty : UrlPreviewState()
- @Immutable class Error(val errorMessage: String) : UrlPreviewState()
+ @Immutable class Error(
+ val errorMessage: String,
+ ) : UrlPreviewState()
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/BookmarkPrivateFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/BookmarkPrivateFeedFilter.kt
index 107c6cb95..3cae7c2e0 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/BookmarkPrivateFeedFilter.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/BookmarkPrivateFeedFilter.kt
@@ -24,10 +24,10 @@ import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.Note
-class BookmarkPrivateFeedFilter(val account: Account) : FeedFilter() {
- override fun feedKey(): String {
- return account.userProfile().latestBookmarkList?.id ?: ""
- }
+class BookmarkPrivateFeedFilter(
+ val account: Account,
+) : FeedFilter() {
+ override fun feedKey(): String = account.userProfile().latestBookmarkList?.id ?: ""
override fun feed(): List {
val bookmarks = account.userProfile().latestBookmarkList
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/BookmarkPublicFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/BookmarkPublicFeedFilter.kt
index 37832131a..032c84296 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/BookmarkPublicFeedFilter.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/BookmarkPublicFeedFilter.kt
@@ -24,10 +24,10 @@ import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.Note
-class BookmarkPublicFeedFilter(val account: Account) : FeedFilter() {
- override fun feedKey(): String {
- return account.userProfile().latestBookmarkList?.id ?: ""
- }
+class BookmarkPublicFeedFilter(
+ val account: Account,
+) : FeedFilter() {
+ override fun feedKey(): String = account.userProfile().latestBookmarkList?.id ?: ""
override fun feed(): List {
val bookmarks = account.userProfile().latestBookmarkList
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChannelFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChannelFeedFilter.kt
index 87e113353..09cd20188 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChannelFeedFilter.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChannelFeedFilter.kt
@@ -24,27 +24,24 @@ import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.Channel
import com.vitorpamplona.amethyst.model.Note
-class ChannelFeedFilter(val channel: Channel, val account: Account) : AdditiveFeedFilter() {
- override fun feedKey(): String {
- return channel.idHex
- }
+class ChannelFeedFilter(
+ val channel: Channel,
+ val account: Account,
+) : AdditiveFeedFilter() {
+ override fun feedKey(): String = channel.idHex
// returns the last Note of each user.
- override fun feed(): List {
- return sort(
+ override fun feed(): List =
+ sort(
channel.notes.filterIntoSet { key, it ->
account.isAcceptable(it)
},
)
- }
- override fun applyFilter(collection: Set): Set {
- return collection
+ override fun applyFilter(collection: Set): Set =
+ collection
.filter { channel.notes.containsKey(it.idHex) && account.isAcceptable(it) }
.toSet()
- }
- override fun sort(collection: Set): List {
- return collection.sortedWith(DefaultFeedOrder)
- }
+ override fun sort(collection: Set): List = collection.sortedWith(DefaultFeedOrder)
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChatroomFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChatroomFeedFilter.kt
index 8cbd4b1fd..234da7305 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChatroomFeedFilter.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChatroomFeedFilter.kt
@@ -24,12 +24,12 @@ import com.vitorpamplona.amethyst.model.Account
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.quartz.events.ChatroomKey
-class ChatroomFeedFilter(val withUser: ChatroomKey, val account: Account) :
- AdditiveFeedFilter() {
+class ChatroomFeedFilter(
+ val withUser: ChatroomKey,
+ val account: Account,
+) : AdditiveFeedFilter() {
// returns the last Note of each user.
- override fun feedKey(): String {
- return withUser.hashCode().toString()
- }
+ override fun feedKey(): String = withUser.hashCode().toString()
override fun feed(): List {
val messages = account.userProfile().privateChatrooms[withUser] ?: return emptyList()
@@ -46,7 +46,5 @@ class ChatroomFeedFilter(val withUser: ChatroomKey, val account: Account) :
return collection.filter { it in messages.roomMessages && account.isAcceptable(it) }.toSet()
}
- override fun sort(collection: Set): List {
- return collection.sortedWith(DefaultFeedOrder)
- }
+ override fun sort(collection: Set): List = collection.sortedWith(DefaultFeedOrder)
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChatroomListKnownFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChatroomListKnownFeedFilter.kt
index 7a7846a41..70e0074c7 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChatroomListKnownFeedFilter.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChatroomListKnownFeedFilter.kt
@@ -28,10 +28,10 @@ import com.vitorpamplona.quartz.events.ChannelMessageEvent
import com.vitorpamplona.quartz.events.ChatroomKey
import com.vitorpamplona.quartz.events.ChatroomKeyable
-class ChatroomListKnownFeedFilter(val account: Account) : AdditiveFeedFilter() {
- override fun feedKey(): String {
- return account.userProfile().pubkeyHex
- }
+class ChatroomListKnownFeedFilter(
+ val account: Account,
+) : AdditiveFeedFilter() {
+ override fun feedKey(): String = account.userProfile().pubkeyHex
// returns the last Note of each user.
override fun feed(): List {
@@ -56,7 +56,8 @@ class ChatroomListKnownFeedFilter(val account: Account) : AdditiveFeedFilter
- it.notes.filter { key, it -> account.isAcceptable(it) && it.event != null }
+ it.notes
+ .filter { key, it -> account.isAcceptable(it) && it.event != null }
.sortedWith(DefaultFeedOrder)
.firstOrNull()
}
@@ -136,7 +137,11 @@ class ChatroomListKnownFeedFilter(val account: Account) : AdditiveFeedFilter {
val followingChannels =
- account.userProfile().latestContactList?.taggedEvents()?.toSet() ?: emptySet()
+ account
+ .userProfile()
+ .latestContactList
+ ?.taggedEvents()
+ ?.toSet() ?: emptySet()
val newRelevantPublicMessages = mutableMapOf()
newItems
.filter { it.event is ChannelMessageEvent }
@@ -177,7 +182,8 @@ class ChatroomListKnownFeedFilter(val account: Account) : AdditiveFeedFilter): List {
- return collection.sortedWith(DefaultFeedOrder)
- }
+ override fun sort(collection: Set): List = collection.sortedWith(DefaultFeedOrder)
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChatroomListNewFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChatroomListNewFeedFilter.kt
index 87cc2c66a..1e6589e95 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChatroomListNewFeedFilter.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/ChatroomListNewFeedFilter.kt
@@ -27,10 +27,10 @@ import com.vitorpamplona.quartz.events.ChatroomKey
import com.vitorpamplona.quartz.events.ChatroomKeyable
import com.vitorpamplona.quartz.events.PrivateDmEvent
-class ChatroomListNewFeedFilter(val account: Account) : AdditiveFeedFilter() {
- override fun feedKey(): String {
- return account.userProfile().pubkeyHex
- }
+class ChatroomListNewFeedFilter(
+ val account: Account,
+) : AdditiveFeedFilter() {
+ override fun feedKey(): String = account.userProfile().pubkeyHex
// returns the last Note of each user.
override fun feed(): List {
@@ -137,7 +137,5 @@ class ChatroomListNewFeedFilter(val account: Account) : AdditiveFeedFilter
return newRelevantPrivateMessages
}
- override fun sort(collection: Set): List {
- return collection.sortedWith(DefaultFeedOrder)
- }
+ override fun sort(collection: Set): List = collection.sortedWith(DefaultFeedOrder)
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/CommunityFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/CommunityFeedFilter.kt
index 4a30b7d77..1b3f628bf 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/CommunityFeedFilter.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/CommunityFeedFilter.kt
@@ -27,10 +27,11 @@ import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.quartz.encoders.HexKey
import com.vitorpamplona.quartz.events.CommunityPostApprovalEvent
-class CommunityFeedFilter(val note: AddressableNote, val account: Account) : AdditiveFeedFilter() {
- override fun feedKey(): String {
- return account.userProfile().pubkeyHex + "-" + note.idHex
- }
+class CommunityFeedFilter(
+ val note: AddressableNote,
+ val account: Account,
+) : AdditiveFeedFilter() {
+ override fun feedKey(): String = account.userProfile().pubkeyHex + "-" + note.idHex
override fun feed(): List {
val myPubKey = account.userProfile().pubkeyHex
@@ -42,23 +43,23 @@ class CommunityFeedFilter(val note: AddressableNote, val account: Account) : Add
return sort(result)
}
- override fun applyFilter(collection: Set): Set {
- return innerApplyFilter(collection)
- }
+ override fun applyFilter(collection: Set): Set = innerApplyFilter(collection)
private fun innerApplyFilter(collection: Collection): Set {
val myPubKey = account.userProfile().pubkeyHex
- return collection.mapNotNull {
- filterMap(it, myPubKey)
- }.flatten().toSet()
+ return collection
+ .mapNotNull {
+ filterMap(it, myPubKey)
+ }.flatten()
+ .toSet()
}
private fun filterMap(
note: Note,
myPubKey: HexKey,
- ): List? {
- return if (
+ ): List? =
+ if (
// Only Approvals
note.event is CommunityPostApprovalEvent &&
// Of the given community
@@ -74,9 +75,6 @@ class CommunityFeedFilter(val note: AddressableNote, val account: Account) : Add
} else {
null
}
- }
- override fun sort(collection: Set): List {
- return collection.sortedWith(DefaultFeedOrder)
- }
+ override fun sort(collection: Set): List = collection.sortedWith(DefaultFeedOrder)
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DiscoverChatFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DiscoverChatFeedFilter.kt
index 0eabe3422..92a4900d1 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DiscoverChatFeedFilter.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DiscoverChatFeedFilter.kt
@@ -29,17 +29,16 @@ import com.vitorpamplona.quartz.events.IsInPublicChatChannel
import com.vitorpamplona.quartz.events.MuteListEvent
import com.vitorpamplona.quartz.events.PeopleListEvent
-open class DiscoverChatFeedFilter(val account: Account) : AdditiveFeedFilter() {
- override fun feedKey(): String {
- return account.userProfile().pubkeyHex + "-" + account.defaultDiscoveryFollowList.value
- }
+open class DiscoverChatFeedFilter(
+ val account: Account,
+) : AdditiveFeedFilter() {
+ override fun feedKey(): String = account.userProfile().pubkeyHex + "-" + account.defaultDiscoveryFollowList.value
- override fun showHiddenKey(): Boolean {
- return account.defaultDiscoveryFollowList.value ==
+ override fun showHiddenKey(): Boolean =
+ account.defaultDiscoveryFollowList.value ==
PeopleListEvent.blockListFor(account.userProfile().pubkeyHex) ||
account.defaultDiscoveryFollowList.value ==
MuteListEvent.blockListFor(account.userProfile().pubkeyHex)
- }
override fun feed(): List {
val params = buildFilterParams(account)
@@ -63,18 +62,15 @@ open class DiscoverChatFeedFilter(val account: Account) : AdditiveFeedFilter): Set {
- return innerApplyFilter(collection)
- }
+ override fun applyFilter(collection: Set): Set = innerApplyFilter(collection)
- fun buildFilterParams(account: Account): FilterByListParams {
- return FilterByListParams.create(
+ fun buildFilterParams(account: Account): FilterByListParams =
+ FilterByListParams.create(
userHex = account.userProfile().pubkeyHex,
selectedListName = account.defaultDiscoveryFollowList.value,
followLists = account.liveDiscoveryFollowLists.value,
hiddenUsers = account.flowHiddenUsers.value,
)
- }
protected open fun innerApplyFilter(collection: Collection): Set {
val params = buildFilterParams(account)
@@ -120,7 +116,6 @@ open class DiscoverChatFeedFilter(val account: Account) : AdditiveFeedFilter() {
- override fun feedKey(): String {
- return account.userProfile().pubkeyHex + "-" + account.defaultDiscoveryFollowList.value
- }
+open class DiscoverCommunityFeedFilter(
+ val account: Account,
+) : AdditiveFeedFilter() {
+ override fun feedKey(): String = account.userProfile().pubkeyHex + "-" + account.defaultDiscoveryFollowList.value
- override fun showHiddenKey(): Boolean {
- return account.defaultDiscoveryFollowList.value ==
+ override fun showHiddenKey(): Boolean =
+ account.defaultDiscoveryFollowList.value ==
PeopleListEvent.blockListFor(account.userProfile().pubkeyHex) ||
account.defaultDiscoveryFollowList.value ==
MuteListEvent.blockListFor(account.userProfile().pubkeyHex)
- }
override fun feed(): List {
val filterParams =
@@ -67,9 +66,7 @@ open class DiscoverCommunityFeedFilter(val account: Account) : AdditiveFeedFilte
return sort(notes)
}
- override fun applyFilter(collection: Set): Set {
- return innerApplyFilter(collection)
- }
+ override fun applyFilter(collection: Set): Set = innerApplyFilter(collection)
protected open fun innerApplyFilter(collection: Collection): Set {
// here, we need to look for CommunityDefinition in new collection AND new CommunityDefinition from Post Approvals
@@ -81,28 +78,30 @@ open class DiscoverCommunityFeedFilter(val account: Account) : AdditiveFeedFilte
hiddenUsers = account.flowHiddenUsers.value,
)
- return collection.mapNotNull { note ->
- // note event here will never be null
- val noteEvent = note.event
- if (noteEvent is CommunityDefinitionEvent && filterParams.match(noteEvent)) {
- listOf(note)
- } else if (noteEvent is CommunityPostApprovalEvent) {
- noteEvent.communities().mapNotNull {
- val definitionNote = LocalCache.getOrCreateAddressableNote(it)
- val definitionEvent = definitionNote.event
+ return collection
+ .mapNotNull { note ->
+ // note event here will never be null
+ val noteEvent = note.event
+ if (noteEvent is CommunityDefinitionEvent && filterParams.match(noteEvent)) {
+ listOf(note)
+ } else if (noteEvent is CommunityPostApprovalEvent) {
+ noteEvent.communities().mapNotNull {
+ val definitionNote = LocalCache.getOrCreateAddressableNote(it)
+ val definitionEvent = definitionNote.event
- if (definitionEvent == null && shouldInclude(it, filterParams)) {
- definitionNote
- } else if (definitionEvent is CommunityDefinitionEvent && filterParams.match(definitionEvent)) {
- definitionNote
- } else {
- null
+ if (definitionEvent == null && shouldInclude(it, filterParams)) {
+ definitionNote
+ } else if (definitionEvent is CommunityDefinitionEvent && filterParams.match(definitionEvent)) {
+ definitionNote
+ } else {
+ null
+ }
}
+ } else {
+ null
}
- } else {
- null
- }
- }.flatten().toSet()
+ }.flatten()
+ .toSet()
}
private fun shouldInclude(
@@ -123,7 +122,6 @@ open class DiscoverCommunityFeedFilter(val account: Account) : AdditiveFeedFilte
{ it.createdAt() },
{ it.idHex },
),
- )
- .reversed()
+ ).reversed()
}
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DiscoverLiveFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DiscoverLiveFeedFilter.kt
index ebce2500a..abb993745 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DiscoverLiveFeedFilter.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DiscoverLiveFeedFilter.kt
@@ -34,18 +34,13 @@ import com.vitorpamplona.quartz.events.PeopleListEvent
open class DiscoverLiveFeedFilter(
val account: Account,
) : AdditiveFeedFilter() {
- override fun feedKey(): String {
- return account.userProfile().pubkeyHex + "-" + followList()
- }
+ override fun feedKey(): String = account.userProfile().pubkeyHex + "-" + followList()
- open fun followList(): String {
- return account.defaultDiscoveryFollowList.value
- }
+ open fun followList(): String = account.defaultDiscoveryFollowList.value
- override fun showHiddenKey(): Boolean {
- return followList() == PeopleListEvent.blockListFor(account.userProfile().pubkeyHex) ||
+ override fun showHiddenKey(): Boolean =
+ followList() == PeopleListEvent.blockListFor(account.userProfile().pubkeyHex) ||
followList() == MuteListEvent.blockListFor(account.userProfile().pubkeyHex)
- }
override fun feed(): List {
val allChannelNotes = LocalCache.channels.mapNotNull { _, channel -> LocalCache.getNoteIfExists(channel.idHex) }
@@ -56,9 +51,7 @@ open class DiscoverLiveFeedFilter(
return sort(notes)
}
- override fun applyFilter(collection: Set): Set {
- return innerApplyFilter(collection)
- }
+ override fun applyFilter(collection: Set): Set = innerApplyFilter(collection)
protected open fun innerApplyFilter(collection: Collection): Set {
val filterParams =
@@ -92,16 +85,14 @@ open class DiscoverLiveFeedFilter(
{ (it.event as? LiveActivitiesEvent)?.starts() ?: it.createdAt() },
{ it.idHex },
),
- )
- .reversed()
+ ).reversed()
}
- fun convertStatusToOrder(status: String?): Int {
- return when (status) {
+ fun convertStatusToOrder(status: String?): Int =
+ when (status) {
STATUS_LIVE -> 2
STATUS_PLANNED -> 1
STATUS_ENDED -> 0
else -> 0
}
- }
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DiscoverMarketplaceFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DiscoverMarketplaceFeedFilter.kt
index 0be87e5b8..8d96f4b83 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DiscoverMarketplaceFeedFilter.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DiscoverMarketplaceFeedFilter.kt
@@ -30,18 +30,13 @@ import com.vitorpamplona.quartz.events.PeopleListEvent
open class DiscoverMarketplaceFeedFilter(
val account: Account,
) : AdditiveFeedFilter() {
- override fun feedKey(): String {
- return account.userProfile().pubkeyHex + "-" + followList()
- }
+ override fun feedKey(): String = account.userProfile().pubkeyHex + "-" + followList()
- open fun followList(): String {
- return account.defaultDiscoveryFollowList.value
- }
+ open fun followList(): String = account.defaultDiscoveryFollowList.value
- override fun showHiddenKey(): Boolean {
- return followList() == PeopleListEvent.blockListFor(account.userProfile().pubkeyHex) ||
+ override fun showHiddenKey(): Boolean =
+ followList() == PeopleListEvent.blockListFor(account.userProfile().pubkeyHex) ||
followList() == MuteListEvent.blockListFor(account.userProfile().pubkeyHex)
- }
override fun feed(): List {
val params = buildFilterParams(account)
@@ -55,18 +50,15 @@ open class DiscoverMarketplaceFeedFilter(
return sort(notes)
}
- override fun applyFilter(collection: Set): Set {
- return innerApplyFilter(collection)
- }
+ override fun applyFilter(collection: Set): Set = innerApplyFilter(collection)
- fun buildFilterParams(account: Account): FilterByListParams {
- return FilterByListParams.create(
+ fun buildFilterParams(account: Account): FilterByListParams =
+ FilterByListParams.create(
account.userProfile().pubkeyHex,
account.defaultDiscoveryFollowList.value,
account.liveDiscoveryFollowLists.value,
account.flowHiddenUsers.value,
)
- }
protected open fun innerApplyFilter(collection: Collection): Set {
val params = buildFilterParams(account)
@@ -77,7 +69,5 @@ open class DiscoverMarketplaceFeedFilter(
}
}
- override fun sort(collection: Set): List {
- return collection.sortedWith(compareBy({ it.createdAt() }, { it.idHex })).reversed()
- }
+ override fun sort(collection: Set): List = collection.sortedWith(compareBy({ it.createdAt() }, { it.idHex })).reversed()
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DiscoverNIP89FeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DiscoverNIP89FeedFilter.kt
index d57288470..abb509d0f 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DiscoverNIP89FeedFilter.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DiscoverNIP89FeedFilter.kt
@@ -34,18 +34,13 @@ open class DiscoverNIP89FeedFilter(
val lastAnnounced = 90 * 24 * 60 * 60 // 90 Days ago
// TODO better than announced would be last active, as this requires the DVM provider to regularly update the NIP89 announcement
- override fun feedKey(): String {
- return account.userProfile().pubkeyHex + "-" + followList()
- }
+ override fun feedKey(): String = account.userProfile().pubkeyHex + "-" + followList()
- open fun followList(): String {
- return account.defaultDiscoveryFollowList.value
- }
+ open fun followList(): String = account.defaultDiscoveryFollowList.value
- override fun showHiddenKey(): Boolean {
- return followList() == PeopleListEvent.blockListFor(account.userProfile().pubkeyHex) ||
+ override fun showHiddenKey(): Boolean =
+ followList() == PeopleListEvent.blockListFor(account.userProfile().pubkeyHex) ||
followList() == MuteListEvent.blockListFor(account.userProfile().pubkeyHex)
- }
override fun feed(): List {
val filterParams = buildFilterParams(account)
@@ -58,18 +53,15 @@ open class DiscoverNIP89FeedFilter(
return sort(notes)
}
- override fun applyFilter(collection: Set): Set {
- return innerApplyFilter(collection)
- }
+ override fun applyFilter(collection: Set): Set = innerApplyFilter(collection)
- fun buildFilterParams(account: Account): FilterByListParams {
- return FilterByListParams.create(
+ fun buildFilterParams(account: Account): FilterByListParams =
+ FilterByListParams.create(
account.userProfile().pubkeyHex,
account.defaultDiscoveryFollowList.value,
account.liveDiscoveryFollowLists.value,
account.flowHiddenUsers.value,
)
- }
fun acceptDVM(note: Note): Boolean {
val noteEvent = note.event
@@ -88,13 +80,10 @@ open class DiscoverNIP89FeedFilter(
noteEvent.createdAt > TimeUtils.now() - lastAnnounced // && params.match(noteEvent)
}
- protected open fun innerApplyFilter(collection: Collection): Set {
- return collection.filterTo(HashSet()) {
+ protected open fun innerApplyFilter(collection: Collection): Set =
+ collection.filterTo(HashSet()) {
acceptDVM(it)
}
- }
- override fun sort(collection: Set): List {
- return collection.sortedWith(compareBy({ it.createdAt() }, { it.idHex })).reversed()
- }
+ override fun sort(collection: Set): List = collection.sortedWith(compareBy({ it.createdAt() }, { it.idHex })).reversed()
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DraftEventsFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DraftEventsFeedFilter.kt
index 883bc8df0..25bebe5d6 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DraftEventsFeedFilter.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/DraftEventsFeedFilter.kt
@@ -25,16 +25,15 @@ import com.vitorpamplona.amethyst.model.LocalCache
import com.vitorpamplona.amethyst.model.Note
import com.vitorpamplona.quartz.events.DraftEvent
-class DraftEventsFeedFilter(val account: Account) : AdditiveFeedFilter() {
- override fun feedKey(): String {
- return account.userProfile().pubkeyHex
- }
+class DraftEventsFeedFilter(
+ val account: Account,
+) : AdditiveFeedFilter() {
+ override fun feedKey(): String = account.userProfile().pubkeyHex
- override fun applyFilter(collection: Set): Set {
- return collection.filterTo(HashSet()) {
+ override fun applyFilter(collection: Set): Set =
+ collection.filterTo(HashSet()) {
acceptableEvent(it)
}
- }
override fun feed(): List {
val drafts =
@@ -50,7 +49,5 @@ class DraftEventsFeedFilter(val account: Account) : AdditiveFeedFilter() {
return noteEvent is DraftEvent && noteEvent.pubKey == account.userProfile().pubkeyHex
}
- override fun sort(collection: Set): List {
- return collection.sortedWith(DefaultFeedOrder)
- }
+ override fun sort(collection: Set): List = collection.sortedWith(DefaultFeedOrder)
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FilterByListParams.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FilterByListParams.kt
index dad30487f..80b5bd65b 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FilterByListParams.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/FilterByListParams.kt
@@ -91,13 +91,12 @@ class FilterByListParams(
selectedListName: String,
followLists: Account.LiveFollowLists?,
hiddenUsers: Account.LiveHiddenUsers,
- ): FilterByListParams {
- return FilterByListParams(
+ ): FilterByListParams =
+ FilterByListParams(
isGlobal = selectedListName == GLOBAL_FOLLOWS,
isHiddenList = showHiddenKey(selectedListName, userHex),
followLists = followLists,
hiddenLists = hiddenUsers,
)
- }
}
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/GeoHashFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/GeoHashFeedFilter.kt
index e2fa72fe6..f2cd9b72e 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/GeoHashFeedFilter.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/GeoHashFeedFilter.kt
@@ -31,10 +31,11 @@ import com.vitorpamplona.quartz.events.PrivateDmEvent
import com.vitorpamplona.quartz.events.TextNoteEvent
import com.vitorpamplona.quartz.events.WikiNoteEvent
-class GeoHashFeedFilter(val tag: String, val account: Account) : AdditiveFeedFilter() {
- override fun feedKey(): String {
- return account.userProfile().pubkeyHex + "-" + tag
- }
+class GeoHashFeedFilter(
+ val tag: String,
+ val account: Account,
+) : AdditiveFeedFilter() {
+ override fun feedKey(): String = account.userProfile().pubkeyHex + "-" + tag
override fun feed(): List {
val notes =
@@ -45,19 +46,15 @@ class GeoHashFeedFilter(val tag: String, val account: Account) : AdditiveFeedFil
return sort(notes)
}
- override fun applyFilter(collection: Set): Set {
- return innerApplyFilter(collection)
- }
+ override fun applyFilter(collection: Set): Set = innerApplyFilter(collection)
- private fun innerApplyFilter(collection: Collection): Set {
- return collection.filterTo(HashSet()) { acceptableEvent(it, tag) }
- }
+ private fun innerApplyFilter(collection: Collection): Set = collection.filterTo(HashSet()) { acceptableEvent(it, tag) }
fun acceptableEvent(
it: Note,
geoTag: String,
- ): Boolean {
- return (
+ ): Boolean =
+ (
it.event is TextNoteEvent ||
it.event is LongTextNoteEvent ||
it.event is WikiNoteEvent ||
@@ -66,9 +63,6 @@ class GeoHashFeedFilter(val tag: String, val account: Account) : AdditiveFeedFil
it.event is PollNoteEvent ||
it.event is AudioHeaderEvent
) && it.event?.isTaggedGeoHash(geoTag) == true && account.isAcceptable(it)
- }
- override fun sort(collection: Set): List {
- return collection.sortedWith(DefaultFeedOrder)
- }
+ override fun sort(collection: Set): List = collection.sortedWith(DefaultFeedOrder)
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/HashtagFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/HashtagFeedFilter.kt
index 7aeebbc81..0f5c7950e 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/HashtagFeedFilter.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/HashtagFeedFilter.kt
@@ -33,10 +33,11 @@ import com.vitorpamplona.quartz.events.RepostEvent
import com.vitorpamplona.quartz.events.TextNoteEvent
import com.vitorpamplona.quartz.events.WikiNoteEvent
-class HashtagFeedFilter(val tag: String, val account: Account) : AdditiveFeedFilter() {
- override fun feedKey(): String {
- return account.userProfile().pubkeyHex + "-" + tag
- }
+class HashtagFeedFilter(
+ val tag: String,
+ val account: Account,
+) : AdditiveFeedFilter() {
+ override fun feedKey(): String = account.userProfile().pubkeyHex + "-" + tag
override fun feed(): List {
val notes =
@@ -47,19 +48,15 @@ class HashtagFeedFilter(val tag: String, val account: Account) : AdditiveFeedFil
return sort(notes)
}
- override fun applyFilter(collection: Set): Set {
- return innerApplyFilter(collection)
- }
+ override fun applyFilter(collection: Set): Set = innerApplyFilter(collection)
- private fun innerApplyFilter(collection: Collection): Set {
- return collection.filterTo(HashSet()) { acceptableEvent(it, tag) }
- }
+ private fun innerApplyFilter(collection: Collection): Set = collection.filterTo(HashSet()) { acceptableEvent(it, tag) }
fun acceptableEvent(
it: Note,
hashTag: String,
- ): Boolean {
- return (
+ ): Boolean =
+ (
it.event is TextNoteEvent ||
it.event is RepostEvent ||
it.event is GenericRepostEvent ||
@@ -69,10 +66,9 @@ class HashtagFeedFilter(val tag: String, val account: Account) : AdditiveFeedFil
it.event is PrivateDmEvent ||
it.event is PollNoteEvent ||
it.event is AudioHeaderEvent
- ) && it.event?.isTaggedHash(hashTag) == true && account.isAcceptable(it)
- }
+ ) &&
+ it.event?.isTaggedHash(hashTag) == true &&
+ account.isAcceptable(it)
- override fun sort(collection: Set): List {
- return collection.sortedWith(DefaultFeedOrder)
- }
+ override fun sort(collection: Set): List = collection.sortedWith(DefaultFeedOrder)
}
diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/HomeConversationsFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/HomeConversationsFeedFilter.kt
index c5c2981fb..c4a46c40e 100644
--- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/HomeConversationsFeedFilter.kt
+++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/dal/HomeConversationsFeedFilter.kt
@@ -30,15 +30,14 @@ import com.vitorpamplona.quartz.events.PeopleListEvent
import com.vitorpamplona.quartz.events.PollNoteEvent
import com.vitorpamplona.quartz.events.TextNoteEvent
-class HomeConversationsFeedFilter(val account: Account) : AdditiveFeedFilter() {
- override fun feedKey(): String {
- return account.userProfile().pubkeyHex + "-" + account.defaultHomeFollowList.value
- }
+class HomeConversationsFeedFilter(
+ val account: Account,
+) : AdditiveFeedFilter() {
+ override fun feedKey(): String = account.userProfile().pubkeyHex + "-" + account.defaultHomeFollowList.value
- override fun showHiddenKey(): Boolean {
- return account.defaultHomeFollowList.value == PeopleListEvent.blockListFor(account.userProfile().pubkeyHex) ||
+ override fun showHiddenKey(): Boolean =
+ account.defaultHomeFollowList.value == PeopleListEvent.blockListFor(account.userProfile().pubkeyHex) ||
account.defaultHomeFollowList.value == MuteListEvent.blockListFor(account.userProfile().pubkeyHex)
- }
override fun feed(): List {
val filterParams = buildFilterParams(account)
@@ -50,18 +49,15 @@ class HomeConversationsFeedFilter(val account: Account) : AdditiveFeedFilter