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) {
mutex.withLock {
val file = stateFile()
if (file.exists()) {
if (!file.delete()) {
if (file.exists() && !file.delete()) {
Log.w(TAG) { "delete(): failed to remove ${file.absolutePath}" }
}
}
}
}
}
private fun atomicWrite(
target: File,
@@ -108,14 +108,12 @@ class AndroidMarmotMessageStore(
withContext(Dispatchers.IO) {
writeMutex.withLock {
val file = messagesFile(nostrGroupId)
if (file.exists()) {
if (!file.delete()) {
if (file.exists() && !file.delete()) {
Log.w(TAG) { "delete($nostrGroupId): failed to remove ${file.absolutePath}" }
}
}
}
}
}
private fun readAll(nostrGroupId: String): List<String> {
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.TitleExplainer
import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.SettingsRow
import com.vitorpamplona.amethyst.ui.stringRes
import kotlinx.collections.immutable.toImmutableList
@Composable
@@ -35,8 +34,6 @@ fun FileServerSelectionRow(
selectedServer: ServerName?,
onSelect: (ServerName) -> Unit,
) {
val nip95description = stringRes(id = R.string.upload_server_relays_nip95)
val fileServerOptions =
remember(fileServers) {
fileServers
@@ -382,8 +382,9 @@ private fun DialogContent(
}
}
if (myContent is MediaUrlImage || myContent is MediaLocalImage || myContent is MediaUrlPdf) {
if (myContent !is MediaUrlContent || !isLiveStreaming(myContent.url)) {
val isPdfOrStaticImage = myContent is MediaUrlImage || myContent is MediaLocalImage || myContent is MediaUrlPdf
val isNotLiveStream = myContent !is MediaUrlContent || !isLiveStreaming(myContent.url)
if (isPdfOrStaticImage && isNotLiveStream) {
val localContext = LocalContext.current
val scope = rememberCoroutineScope()
@@ -440,7 +441,6 @@ private fun DialogContent(
}
}
}
}
}
private fun showToastOnMain(
@@ -438,7 +438,7 @@ fun ImageVideoDescription(
.padding(vertical = 10.dp),
enabled = !isUploading,
onClick = {
val effectiveStripMetadata = if (isVideoWithCompression) false else stripMetadata
val effectiveStripMetadata = !isVideoWithCompression && stripMetadata
onAdd(message, selectedServer, sensitiveContent, mediaQualitySlider, useH265Codec, effectiveStripMetadata, convertGifToMp4)
},
shape = QuoteBorder,