mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-10-05 19:28:25 +00:00
refactor(sonar): merge nested if statements
Sonar kotlin:S1066 — collapse 'if (A) { if (B) { body } }' into 'if (A && B) { body }'
across 16 files. Kotlin's && short-circuits identically to the nested form, so this
is a behaviour-preserving change.
This commit is contained in:
@@ -3277,10 +3277,12 @@ class Account(
|
||||
scope.launch {
|
||||
cache.antiSpam.flowSpam.collect {
|
||||
it.cache.spamMessages.snapshot().values.forEach { spammer ->
|
||||
if (!hiddenUsers.isHidden(spammer.pubkeyHex) && spammer.shouldHide()) {
|
||||
if (spammer.pubkeyHex != userProfile().pubkeyHex && spammer.pubkeyHex !in followingKeySet()) {
|
||||
hiddenUsers.hideUser(spammer.pubkeyHex)
|
||||
}
|
||||
if (!hiddenUsers.isHidden(spammer.pubkeyHex) &&
|
||||
spammer.shouldHide() &&
|
||||
spammer.pubkeyHex != userProfile().pubkeyHex &&
|
||||
spammer.pubkeyHex !in followingKeySet()
|
||||
) {
|
||||
hiddenUsers.hideUser(spammer.pubkeyHex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -807,16 +807,14 @@ object LocalCache : ILocalCache, ICacheProvider {
|
||||
return false
|
||||
}
|
||||
|
||||
if (isVerified || justVerify(event)) {
|
||||
if (event.createdAt > (note.createdAt() ?: 0L)) {
|
||||
val replyTo = computeReplyTo(event)
|
||||
if ((isVerified || justVerify(event)) && event.createdAt > (note.createdAt() ?: 0L)) {
|
||||
val replyTo = computeReplyTo(event)
|
||||
|
||||
note.loadEvent(event, author, replyTo)
|
||||
note.loadEvent(event, author, replyTo)
|
||||
|
||||
refreshNewNoteObservers(note)
|
||||
refreshNewNoteObservers(note)
|
||||
|
||||
return true
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
@@ -852,16 +850,14 @@ object LocalCache : ILocalCache, ICacheProvider {
|
||||
return false
|
||||
}
|
||||
|
||||
if (isVerified || justVerify(event)) {
|
||||
if (event.createdAt > (note.createdAt() ?: 0L)) {
|
||||
val replyTo = computeReplyTo(event)
|
||||
if ((isVerified || justVerify(event)) && event.createdAt > (note.createdAt() ?: 0L)) {
|
||||
val replyTo = computeReplyTo(event)
|
||||
|
||||
note.loadEvent(event, author, replyTo)
|
||||
note.loadEvent(event, author, replyTo)
|
||||
|
||||
refreshNewNoteObservers(note)
|
||||
refreshNewNoteObservers(note)
|
||||
|
||||
return true
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
@@ -1197,10 +1193,12 @@ object LocalCache : ILocalCache, ICacheProvider {
|
||||
|
||||
notes.forEach { _, note ->
|
||||
val noteEvent = note.event
|
||||
if (noteEvent is AddressableEvent && noteEvent.addressTag() in addressSet) {
|
||||
if (noteEvent.pubKey == event.pubKey && noteEvent.createdAt <= event.createdAt) {
|
||||
deleteNote(note)
|
||||
}
|
||||
if (noteEvent is AddressableEvent &&
|
||||
noteEvent.addressTag() in addressSet &&
|
||||
noteEvent.pubKey == event.pubKey &&
|
||||
noteEvent.createdAt <= event.createdAt
|
||||
) {
|
||||
deleteNote(note)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1466,10 +1464,8 @@ object LocalCache : ILocalCache, ICacheProvider {
|
||||
return false // older data, does nothing
|
||||
}
|
||||
|
||||
if (oldChannel.creator == null || oldChannel.creator == author) {
|
||||
if (isVerified || justVerify(event)) {
|
||||
oldChannel.updateChannelInfo(author, event, note)
|
||||
}
|
||||
if ((oldChannel.creator == null || oldChannel.creator == author) && (isVerified || justVerify(event))) {
|
||||
oldChannel.updateChannelInfo(author, event, note)
|
||||
}
|
||||
|
||||
return isVerified
|
||||
|
||||
+6
-4
@@ -171,10 +171,12 @@ class LightningAddressResolver {
|
||||
val messageNode = tree.get("message")
|
||||
val statusNode = tree.get("status")
|
||||
|
||||
if (tree.get("error") != null && tree.get("error").isBoolean && messageNode != null) {
|
||||
if (errorNode.asBoolean()) {
|
||||
return messageNode.asText()
|
||||
}
|
||||
if (tree.get("error") != null &&
|
||||
tree.get("error").isBoolean &&
|
||||
messageNode != null &&
|
||||
errorNode.asBoolean()
|
||||
) {
|
||||
return messageNode.asText()
|
||||
}
|
||||
|
||||
val status = statusNode?.asText()
|
||||
|
||||
+2
-4
@@ -57,10 +57,8 @@ abstract class SingleSubNoEoseCacheEoseManager<T>(
|
||||
relay: NormalizedRelayUrl,
|
||||
forFilters: List<Filter>?,
|
||||
) {
|
||||
if (isLive) {
|
||||
if (invalidateAfterEose) {
|
||||
invalidateFilters()
|
||||
}
|
||||
if (isLive && invalidateAfterEose) {
|
||||
invalidateFilters()
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
+2
-4
@@ -29,10 +29,8 @@ import com.vitorpamplona.quartz.nip94FileMetadata.tags.DimensionTag
|
||||
|
||||
fun MediaMetadataRetriever.getThumbnail(): Bitmap? {
|
||||
val raw: ByteArray? = embeddedPicture
|
||||
if (raw != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
return ImageDecoder.decodeBitmap(ImageDecoder.createSource(raw))
|
||||
}
|
||||
if (raw != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
return ImageDecoder.decodeBitmap(ImageDecoder.createSource(raw))
|
||||
}
|
||||
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
|
||||
+1
-3
@@ -320,9 +320,7 @@ class UploadOrchestrator {
|
||||
MetadataStripper.strip(compressed.uri, effectiveMimeType, context.applicationContext)
|
||||
}
|
||||
|
||||
if (!strippingResult.stripped) {
|
||||
if (!onStrippingFailed()) return null
|
||||
}
|
||||
if (!strippingResult.stripped && !onStrippingFailed()) return null
|
||||
|
||||
return strippingResult.uri
|
||||
}
|
||||
|
||||
@@ -83,13 +83,11 @@ fun <T> Transition<T>.MyCrossfade(
|
||||
) {
|
||||
val currentlyVisible = remember { mutableStateListOf<T>().apply { add(currentState) } }
|
||||
val contentMap = remember { mutableScatterMapOf<T, @Composable () -> Unit>() }
|
||||
if (currentState == targetState) {
|
||||
// If not animating, just display the current state
|
||||
if (currentlyVisible.size != 1 || currentlyVisible[0] != targetState) {
|
||||
// Remove all the intermediate items from the list once the animation is finished.
|
||||
currentlyVisible.removeAll { it != targetState }
|
||||
contentMap.clear()
|
||||
}
|
||||
// If not animating, just display the current state
|
||||
if (currentState == targetState && (currentlyVisible.size != 1 || currentlyVisible[0] != targetState)) {
|
||||
// Remove all the intermediate items from the list once the animation is finished.
|
||||
currentlyVisible.removeAll { it != targetState }
|
||||
contentMap.clear()
|
||||
}
|
||||
|
||||
if (targetState !in contentMap) {
|
||||
|
||||
+4
-4
@@ -245,10 +245,10 @@ private fun ResetBarsOnResume(state: DisappearingBarState) {
|
||||
DisposableEffect(lifecycleOwner, state) {
|
||||
val observer =
|
||||
LifecycleEventObserver { _, event ->
|
||||
if (event == Lifecycle.Event.ON_RESUME) {
|
||||
if (state.topHeightOffset != 0f || state.bottomHeightOffset != 0f) {
|
||||
scope.launch { state.resetToVisible() }
|
||||
}
|
||||
if (event == Lifecycle.Event.ON_RESUME &&
|
||||
(state.topHeightOffset != 0f || state.bottomHeightOffset != 0f)
|
||||
) {
|
||||
scope.launch { state.resetToVisible() }
|
||||
}
|
||||
}
|
||||
lifecycleOwner.lifecycle.addObserver(observer)
|
||||
|
||||
@@ -86,30 +86,28 @@ fun ReplyInformationChannel(
|
||||
onUserTagClick: (User) -> Unit,
|
||||
) {
|
||||
FlowRow {
|
||||
if (!mentions.isNullOrEmpty()) {
|
||||
if (!replyTo.isNullOrEmpty()) {
|
||||
Text(
|
||||
stringRes(id = R.string.replying_to),
|
||||
fontSize = 13.sp,
|
||||
color = MaterialTheme.colorScheme.placeholderText,
|
||||
)
|
||||
if (!mentions.isNullOrEmpty() && !replyTo.isNullOrEmpty()) {
|
||||
Text(
|
||||
stringRes(id = R.string.replying_to),
|
||||
fontSize = 13.sp,
|
||||
color = MaterialTheme.colorScheme.placeholderText,
|
||||
)
|
||||
|
||||
mentions.forEachIndexed { idx, user ->
|
||||
ReplyInfoMention(user, prefix, accountViewModel, onUserTagClick)
|
||||
mentions.forEachIndexed { idx, user ->
|
||||
ReplyInfoMention(user, prefix, accountViewModel, onUserTagClick)
|
||||
|
||||
if (idx < mentions.size - 2) {
|
||||
Text(
|
||||
", ",
|
||||
fontSize = 13.sp,
|
||||
color = MaterialTheme.colorScheme.placeholderText,
|
||||
)
|
||||
} else if (idx < mentions.size - 1) {
|
||||
Text(
|
||||
" ${stringRes(id = R.string.and)} ",
|
||||
fontSize = 13.sp,
|
||||
color = MaterialTheme.colorScheme.placeholderText,
|
||||
)
|
||||
}
|
||||
if (idx < mentions.size - 2) {
|
||||
Text(
|
||||
", ",
|
||||
fontSize = 13.sp,
|
||||
color = MaterialTheme.colorScheme.placeholderText,
|
||||
)
|
||||
} else if (idx < mentions.size - 1) {
|
||||
Text(
|
||||
" ${stringRes(id = R.string.and)} ",
|
||||
fontSize = 13.sp,
|
||||
color = MaterialTheme.colorScheme.placeholderText,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -145,10 +145,8 @@ fun ChatBubbleLayout(
|
||||
remember {
|
||||
Modifier.combinedClickable(
|
||||
onClick = {
|
||||
if (!onClick()) {
|
||||
if (!isComplete) {
|
||||
showDetails.value = !showDetails.value
|
||||
}
|
||||
if (!onClick() && !isComplete) {
|
||||
showDetails.value = !showDetails.value
|
||||
}
|
||||
},
|
||||
onLongClick = { popupExpanded.value = true },
|
||||
|
||||
+19
-23
@@ -184,16 +184,14 @@ class ChatroomListKnownFeedFilter(
|
||||
newItems
|
||||
.forEach { newNote ->
|
||||
val channelId = (newNote.event as? ChannelMessageEvent)?.channelId()
|
||||
if (channelId != null) {
|
||||
if (channelId in followingChannels && account.isAcceptable(newNote)) {
|
||||
val lastNote = newRelevantPublicMessages.get(channelId)
|
||||
if (lastNote != null) {
|
||||
if ((newNote.createdAt() ?: 0L) > (lastNote.createdAt() ?: 0L)) {
|
||||
newRelevantPublicMessages.put(channelId, newNote)
|
||||
}
|
||||
} else {
|
||||
if (channelId != null && channelId in followingChannels && account.isAcceptable(newNote)) {
|
||||
val lastNote = newRelevantPublicMessages.get(channelId)
|
||||
if (lastNote != null) {
|
||||
if ((newNote.createdAt() ?: 0L) > (lastNote.createdAt() ?: 0L)) {
|
||||
newRelevantPublicMessages.put(channelId, newNote)
|
||||
}
|
||||
} else {
|
||||
newRelevantPublicMessages.put(channelId, newNote)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,23 +237,21 @@ class ChatroomListKnownFeedFilter(
|
||||
val roomKey = (newNote.event as? ChatroomKeyable)?.chatroomKey(me.pubkeyHex)
|
||||
if (roomKey != null) {
|
||||
val room = account.chatroomList.rooms.get(roomKey)
|
||||
if (room != null) {
|
||||
if (
|
||||
(
|
||||
newNote.author?.pubkeyHex == me.pubkeyHex ||
|
||||
room.senderIntersects(followingKeySet) ||
|
||||
account.chatroomList.hasSentMessagesTo(roomKey)
|
||||
) &&
|
||||
!account.isAllHidden(roomKey.users)
|
||||
) {
|
||||
val lastNote = newRelevantPrivateMessages.get(roomKey)
|
||||
if (lastNote != null) {
|
||||
if ((newNote.createdAt() ?: 0L) > (lastNote.createdAt() ?: 0L)) {
|
||||
newRelevantPrivateMessages.put(roomKey, newNote)
|
||||
}
|
||||
} else {
|
||||
if (room != null &&
|
||||
(
|
||||
newNote.author?.pubkeyHex == me.pubkeyHex ||
|
||||
room.senderIntersects(followingKeySet) ||
|
||||
account.chatroomList.hasSentMessagesTo(roomKey)
|
||||
) &&
|
||||
!account.isAllHidden(roomKey.users)
|
||||
) {
|
||||
val lastNote = newRelevantPrivateMessages.get(roomKey)
|
||||
if (lastNote != null) {
|
||||
if ((newNote.createdAt() ?: 0L) > (lastNote.createdAt() ?: 0L)) {
|
||||
newRelevantPrivateMessages.put(roomKey, newNote)
|
||||
}
|
||||
} else {
|
||||
newRelevantPrivateMessages.put(roomKey, newNote)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -287,10 +287,8 @@ class HomeLiveFilter(
|
||||
|
||||
channel.notes.forEach { _, value ->
|
||||
val author = value.author
|
||||
if (author != null) {
|
||||
if (followingSet == null || author.pubkeyHex in followingSet) {
|
||||
count++
|
||||
}
|
||||
if (author != null && (followingSet == null || author.pubkeyHex in followingSet)) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+29
-27
@@ -117,21 +117,22 @@ class NotificationSummaryState(
|
||||
zaps[netDate] = (zaps[netDate] ?: BigDecimal.ZERO) + (noteEvent.amount ?: BigDecimal.ZERO)
|
||||
takenIntoAccount.add(noteEvent.id)
|
||||
}
|
||||
} else if (noteEvent is BaseThreadedEvent) {
|
||||
if (noteEvent.isTaggedUser(currentUser) && noteEvent.pubKey != currentUser) {
|
||||
val isCitation =
|
||||
noteEvent.findCitations().any {
|
||||
LocalCache.getNoteIfExists(it)?.author?.pubkeyHex == currentUser
|
||||
}
|
||||
|
||||
val netDate = formatDate(noteEvent.createdAt)
|
||||
if (isCitation) {
|
||||
boosts[netDate] = (boosts[netDate] ?: 0) + 1
|
||||
} else {
|
||||
replies[netDate] = (replies[netDate] ?: 0) + 1
|
||||
} else if (noteEvent is BaseThreadedEvent &&
|
||||
noteEvent.isTaggedUser(currentUser) &&
|
||||
noteEvent.pubKey != currentUser
|
||||
) {
|
||||
val isCitation =
|
||||
noteEvent.findCitations().any {
|
||||
LocalCache.getNoteIfExists(it)?.author?.pubkeyHex == currentUser
|
||||
}
|
||||
takenIntoAccount.add(noteEvent.id)
|
||||
|
||||
val netDate = formatDate(noteEvent.createdAt)
|
||||
if (isCitation) {
|
||||
boosts[netDate] = (boosts[netDate] ?: 0) + 1
|
||||
} else {
|
||||
replies[netDate] = (replies[netDate] ?: 0) + 1
|
||||
}
|
||||
takenIntoAccount.add(noteEvent.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,22 +184,23 @@ class NotificationSummaryState(
|
||||
takenIntoAccount.add(noteEvent.id)
|
||||
hasNewElements = true
|
||||
}
|
||||
} else if (noteEvent is BaseThreadedEvent) {
|
||||
if (noteEvent.isTaggedUser(currentUser) && noteEvent.pubKey != currentUser) {
|
||||
val isCitation =
|
||||
noteEvent.findCitations().any {
|
||||
LocalCache.getNoteIfExists(it)?.author?.pubkeyHex == currentUser
|
||||
}
|
||||
|
||||
val netDate = formatDate(noteEvent.createdAt)
|
||||
if (isCitation) {
|
||||
boosts[netDate] = (boosts[netDate] ?: 0) + 1
|
||||
} else {
|
||||
replies[netDate] = (replies[netDate] ?: 0) + 1
|
||||
} else if (noteEvent is BaseThreadedEvent &&
|
||||
noteEvent.isTaggedUser(currentUser) &&
|
||||
noteEvent.pubKey != currentUser
|
||||
) {
|
||||
val isCitation =
|
||||
noteEvent.findCitations().any {
|
||||
LocalCache.getNoteIfExists(it)?.author?.pubkeyHex == currentUser
|
||||
}
|
||||
takenIntoAccount.add(noteEvent.id)
|
||||
hasNewElements = true
|
||||
|
||||
val netDate = formatDate(noteEvent.createdAt)
|
||||
if (isCitation) {
|
||||
boosts[netDate] = (boosts[netDate] ?: 0) + 1
|
||||
} else {
|
||||
replies[netDate] = (replies[netDate] ?: 0) + 1
|
||||
}
|
||||
takenIntoAccount.add(noteEvent.id)
|
||||
hasNewElements = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-8
@@ -40,14 +40,12 @@ fun QuickActionGallery(
|
||||
|
||||
content { popupExpanded.value = true }
|
||||
|
||||
if (popupExpanded.value) {
|
||||
if (baseNote.author == accountViewModel.account.userProfile()) {
|
||||
DeleteFromGalleryDialog(
|
||||
note = baseNote,
|
||||
onDismiss = { popupExpanded.value = false },
|
||||
accountViewModel = accountViewModel,
|
||||
)
|
||||
}
|
||||
if (popupExpanded.value && baseNote.author == accountViewModel.account.userProfile()) {
|
||||
DeleteFromGalleryDialog(
|
||||
note = baseNote,
|
||||
onDismiss = { popupExpanded.value = false },
|
||||
accountViewModel = accountViewModel,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -48,10 +48,8 @@ class UserProfileAppRecommendationsFeedFilter(
|
||||
|
||||
fun filterMap(it: Note): List<Note>? {
|
||||
val noteEvent = it.event
|
||||
if (noteEvent is AppRecommendationEvent) {
|
||||
if (noteEvent.pubKey == user.pubkeyHex) {
|
||||
return noteEvent.recommendations().map { LocalCache.getOrCreateAddressableNote(it.address) }
|
||||
}
|
||||
if (noteEvent is AppRecommendationEvent && noteEvent.pubKey == user.pubkeyHex) {
|
||||
return noteEvent.recommendations().map { LocalCache.getOrCreateAddressableNote(it.address) }
|
||||
}
|
||||
|
||||
return null
|
||||
|
||||
+2
-4
@@ -151,10 +151,8 @@ fun Context.getLocaleListFromXml(): LocaleListCompat {
|
||||
try {
|
||||
val xpp: XmlPullParser = resources.getXml(R.xml.locales_config)
|
||||
while (xpp.eventType != XmlPullParser.END_DOCUMENT) {
|
||||
if (xpp.eventType == XmlPullParser.START_TAG) {
|
||||
if (xpp.name == "locale") {
|
||||
tagsList.add(xpp.getAttributeValue(0))
|
||||
}
|
||||
if (xpp.eventType == XmlPullParser.START_TAG && xpp.name == "locale") {
|
||||
tagsList.add(xpp.getAttributeValue(0))
|
||||
}
|
||||
xpp.next()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user