refactor(amethyst): address Sonar code-smell warnings

- Merge nested if statements in marmot stores' delete() and in
  ZoomableContentDialog's MediaUrl* gating block (S1066).
- Replace `if (cond) false else x` with `!cond && x` in
  ImageVideoDescription's effectiveStripMetadata (S1125).
- Remove unused `nip95description` local in FileServerSelectionRow.

All changes are body-internal with identical behaviour.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
davotoula
2026-05-09 10:05:07 +02:00
parent 2a9b5bc17d
commit 5dec9e665a
5 changed files with 53 additions and 60 deletions
@@ -99,14 +99,12 @@ class AndroidKeyPackageBundleStore(
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
mutex.withLock { mutex.withLock {
val file = stateFile() val file = stateFile()
if (file.exists()) { if (file.exists() && !file.delete()) {
if (!file.delete()) {
Log.w(TAG) { "delete(): failed to remove ${file.absolutePath}" } Log.w(TAG) { "delete(): failed to remove ${file.absolutePath}" }
} }
} }
} }
} }
}
private fun atomicWrite( private fun atomicWrite(
target: File, target: File,
@@ -108,14 +108,12 @@ class AndroidMarmotMessageStore(
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
writeMutex.withLock { writeMutex.withLock {
val file = messagesFile(nostrGroupId) val file = messagesFile(nostrGroupId)
if (file.exists()) { if (file.exists() && !file.delete()) {
if (!file.delete()) {
Log.w(TAG) { "delete($nostrGroupId): failed to remove ${file.absolutePath}" } Log.w(TAG) { "delete($nostrGroupId): failed to remove ${file.absolutePath}" }
} }
} }
} }
} }
}
private fun readAll(nostrGroupId: String): List<String> { private fun readAll(nostrGroupId: String): List<String> {
val file = messagesFile(nostrGroupId) val file = messagesFile(nostrGroupId)
@@ -26,7 +26,6 @@ import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.ui.components.TextSpinner import com.vitorpamplona.amethyst.ui.components.TextSpinner
import com.vitorpamplona.amethyst.ui.components.TitleExplainer import com.vitorpamplona.amethyst.ui.components.TitleExplainer
import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.SettingsRow import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.SettingsRow
import com.vitorpamplona.amethyst.ui.stringRes
import kotlinx.collections.immutable.toImmutableList import kotlinx.collections.immutable.toImmutableList
@Composable @Composable
@@ -35,8 +34,6 @@ fun FileServerSelectionRow(
selectedServer: ServerName?, selectedServer: ServerName?,
onSelect: (ServerName) -> Unit, onSelect: (ServerName) -> Unit,
) { ) {
val nip95description = stringRes(id = R.string.upload_server_relays_nip95)
val fileServerOptions = val fileServerOptions =
remember(fileServers) { remember(fileServers) {
fileServers fileServers
@@ -382,8 +382,9 @@ private fun DialogContent(
} }
} }
if (myContent is MediaUrlImage || myContent is MediaLocalImage || myContent is MediaUrlPdf) { val isPdfOrStaticImage = myContent is MediaUrlImage || myContent is MediaLocalImage || myContent is MediaUrlPdf
if (myContent !is MediaUrlContent || !isLiveStreaming(myContent.url)) { val isNotLiveStream = myContent !is MediaUrlContent || !isLiveStreaming(myContent.url)
if (isPdfOrStaticImage && isNotLiveStream) {
val localContext = LocalContext.current val localContext = LocalContext.current
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
@@ -441,7 +442,6 @@ private fun DialogContent(
} }
} }
} }
}
private fun showToastOnMain( private fun showToastOnMain(
context: Context, context: Context,
@@ -438,7 +438,7 @@ fun ImageVideoDescription(
.padding(vertical = 10.dp), .padding(vertical = 10.dp),
enabled = !isUploading, enabled = !isUploading,
onClick = { onClick = {
val effectiveStripMetadata = if (isVideoWithCompression) false else stripMetadata val effectiveStripMetadata = !isVideoWithCompression && stripMetadata
onAdd(message, selectedServer, sensitiveContent, mediaQualitySlider, useH265Codec, effectiveStripMetadata, convertGifToMp4) onAdd(message, selectedServer, sensitiveContent, mediaQualitySlider, useH265Codec, effectiveStripMetadata, convertGifToMp4)
}, },
shape = QuoteBorder, shape = QuoteBorder,