diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt index 30ca6da762..4019e6f66b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt @@ -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) } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt index 9bd2c6198e..5a50365a20 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt @@ -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 diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/lnurl/LightningAddressResolver.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/lnurl/LightningAddressResolver.kt index c37e4b4de7..9e317e83d4 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/lnurl/LightningAddressResolver.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/lnurl/LightningAddressResolver.kt @@ -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() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/eoseManagers/SingleSubNoEoseCacheEoseManager.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/eoseManagers/SingleSubNoEoseCacheEoseManager.kt index 28c3648bbb..57fb10f46a 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/eoseManagers/SingleSubNoEoseCacheEoseManager.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/eoseManagers/SingleSubNoEoseCacheEoseManager.kt @@ -57,10 +57,8 @@ abstract class SingleSubNoEoseCacheEoseManager( relay: NormalizedRelayUrl, forFilters: List?, ) { - if (isLive) { - if (invalidateAfterEose) { - invalidateFilters() - } + if (isLive && invalidateAfterEose) { + invalidateFilters() } } }, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/MediaMetadataRetrieverExt.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/MediaMetadataRetrieverExt.kt index 3b344ef074..be0c06985a 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/MediaMetadataRetrieverExt.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/MediaMetadataRetrieverExt.kt @@ -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) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/UploadOrchestrator.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/UploadOrchestrator.kt index 192a7fe8fd..3df83dd0b7 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/UploadOrchestrator.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/uploads/UploadOrchestrator.kt @@ -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 } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/CrossfadeIfEnabled.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/CrossfadeIfEnabled.kt index 2b631a9918..fc6be9550a 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/CrossfadeIfEnabled.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/CrossfadeIfEnabled.kt @@ -83,13 +83,11 @@ fun Transition.MyCrossfade( ) { val currentlyVisible = remember { mutableStateListOf().apply { add(currentState) } } val contentMap = remember { mutableScatterMapOf 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) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/layouts/DisappearingScaffold.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/layouts/DisappearingScaffold.kt index 44f49fefb8..5b96c44c16 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/layouts/DisappearingScaffold.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/layouts/DisappearingScaffold.kt @@ -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) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/ReplyInformation.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/ReplyInformation.kt index bf760560e7..18fd469014 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/ReplyInformation.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/ReplyInformation.kt @@ -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, + ) } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/feed/layouts/ChatBubbleLayout.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/feed/layouts/ChatBubbleLayout.kt index 16bb93d8f5..ee2b8de8d2 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/feed/layouts/ChatBubbleLayout.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/feed/layouts/ChatBubbleLayout.kt @@ -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 }, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/dal/ChatroomListKnownFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/dal/ChatroomListKnownFeedFilter.kt index da1627a13e..20699882cb 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/dal/ChatroomListKnownFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/dal/ChatroomListKnownFeedFilter.kt @@ -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) } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/dal/HomeLiveFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/dal/HomeLiveFilter.kt index 29d067e40c..6d1f9f8f89 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/dal/HomeLiveFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/dal/HomeLiveFilter.kt @@ -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++ } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/NotificationSummaryState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/NotificationSummaryState.kt index 09cdd19ca9..136a8bc461 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/NotificationSummaryState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/notifications/NotificationSummaryState.kt @@ -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 } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/QuickActionGallery.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/QuickActionGallery.kt index 2db8332d37..17fa4c647d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/QuickActionGallery.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/gallery/QuickActionGallery.kt @@ -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, + ) } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/apps/UserProfileAppRecommendationsFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/apps/UserProfileAppRecommendationsFeedFilter.kt index 71829a88ce..ab00465d51 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/apps/UserProfileAppRecommendationsFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/header/apps/UserProfileAppRecommendationsFeedFilter.kt @@ -48,10 +48,8 @@ class UserProfileAppRecommendationsFeedFilter( fun filterMap(it: Note): List? { 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 diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/AppSettingsScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/AppSettingsScreen.kt index cedb5c1c85..f31857f149 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/AppSettingsScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/AppSettingsScreen.kt @@ -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() }