From e66c27e3757fc63dc9dc24ea6d919474e9c16b5c Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 30 May 2026 22:23:47 +0000 Subject: [PATCH] refactor(commons): move CLI-safe util extensions out of amethyst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First low-friction slice of the amethyst→commons migration (commons/plans/2026-05-30-amethyst-to-commons-migration.md): the model nipNN state holders are all blocked by the LocalCache/Note/Account keystone (Phase A), so start with the genuinely Android-free utilities. - Delete amethyst service/IterableExt.kt — exact duplicate of the existing commons util/IterableUtils.kt (Iterable.replace); re-point 4 callers. - Move retryIfException (CoroutinesExt.kt) into commons util/CoroutinesUtils.kt. - Move togglePresenceInSet (SetExt.kt) into commons util/SetUtils.kt. All commonMain-safe (verifyKmpPurity passes). amethyst play + fdroid both compile against the relocated helpers. --- .../notifications/PushNotificationUtils.kt | 2 +- .../amethyst/service/IterableExt.kt | 26 ------------------- .../rooms/dal/ChatroomListKnownFeedFilter.kt | 2 +- .../rooms/dal/ChatroomListNewFeedFilter.kt | 2 +- .../relays/common/BasicRelaySetupInfoModel.kt | 2 +- .../relays/nip65/Nip65RelayListViewModel.kt | 2 +- .../notifications/PushNotificationUtils.kt | 2 +- .../amethyst/commons/util/CoroutinesUtils.kt | 2 +- .../amethyst/commons/util/SetUtils.kt | 2 +- 9 files changed, 8 insertions(+), 34 deletions(-) delete mode 100644 amethyst/src/main/java/com/vitorpamplona/amethyst/service/IterableExt.kt rename amethyst/src/main/java/com/vitorpamplona/amethyst/service/CoroutinesExt.kt => commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/util/CoroutinesUtils.kt (97%) rename amethyst/src/main/java/com/vitorpamplona/amethyst/service/SetExt.kt => commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/util/SetUtils.kt (96%) diff --git a/amethyst/src/fdroid/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationUtils.kt b/amethyst/src/fdroid/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationUtils.kt index 310ced70b8..a3d52c6c8d 100644 --- a/amethyst/src/fdroid/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationUtils.kt +++ b/amethyst/src/fdroid/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationUtils.kt @@ -21,7 +21,7 @@ package com.vitorpamplona.amethyst.service.notifications import com.vitorpamplona.amethyst.AccountInfo -import com.vitorpamplona.amethyst.service.retryIfException +import com.vitorpamplona.amethyst.commons.util.retryIfException import kotlinx.coroutines.Dispatchers import okhttp3.OkHttpClient diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/IterableExt.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/IterableExt.kt deleted file mode 100644 index 7df5fa41e2..0000000000 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/IterableExt.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2025 Vitor Pamplona - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the - * Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -package com.vitorpamplona.amethyst.service - -fun Iterable.replace( - old: T, - new: T, -): List = map { if (it == old) new else it } 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 c11283c657..eeabb81cc3 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 @@ -20,10 +20,10 @@ */ package com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.rooms.dal +import com.vitorpamplona.amethyst.commons.util.replace import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.Note -import com.vitorpamplona.amethyst.service.replace import com.vitorpamplona.amethyst.ui.dal.AdditiveFeedFilter import com.vitorpamplona.amethyst.ui.dal.DefaultFeedOrder import com.vitorpamplona.quartz.experimental.ephemChat.chat.EphemeralChatEvent diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/dal/ChatroomListNewFeedFilter.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/dal/ChatroomListNewFeedFilter.kt index 9f859dd14b..7cf22d65e9 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/dal/ChatroomListNewFeedFilter.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/rooms/dal/ChatroomListNewFeedFilter.kt @@ -20,9 +20,9 @@ */ package com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.rooms.dal +import com.vitorpamplona.amethyst.commons.util.replace import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.model.Note -import com.vitorpamplona.amethyst.service.replace import com.vitorpamplona.amethyst.ui.dal.AdditiveFeedFilter import com.vitorpamplona.amethyst.ui.dal.DefaultFeedOrder import com.vitorpamplona.quartz.nip17Dm.base.ChatroomKey diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoModel.kt index 6b3bd54272..0b51be87c9 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/common/BasicRelaySetupInfoModel.kt @@ -23,8 +23,8 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.vitorpamplona.amethyst.Amethyst +import com.vitorpamplona.amethyst.commons.util.replace import com.vitorpamplona.amethyst.model.Account -import com.vitorpamplona.amethyst.service.replace import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.quartz.nip01Core.relay.client.accessories.count import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/nip65/Nip65RelayListViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/nip65/Nip65RelayListViewModel.kt index 4534896968..05b76dbaf2 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/nip65/Nip65RelayListViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/nip65/Nip65RelayListViewModel.kt @@ -25,8 +25,8 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.vitorpamplona.amethyst.Amethyst import com.vitorpamplona.amethyst.R +import com.vitorpamplona.amethyst.commons.util.replace import com.vitorpamplona.amethyst.model.Account -import com.vitorpamplona.amethyst.service.replace import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.BasicRelaySetupInfo import com.vitorpamplona.amethyst.ui.screen.loggedIn.relays.common.RelayCountResult diff --git a/amethyst/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationUtils.kt b/amethyst/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationUtils.kt index 8216ca889c..fb355c45cf 100644 --- a/amethyst/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationUtils.kt +++ b/amethyst/src/play/java/com/vitorpamplona/amethyst/service/notifications/PushNotificationUtils.kt @@ -22,7 +22,7 @@ package com.vitorpamplona.amethyst.service.notifications import com.google.firebase.messaging.FirebaseMessaging import com.vitorpamplona.amethyst.AccountInfo -import com.vitorpamplona.amethyst.service.retryIfException +import com.vitorpamplona.amethyst.commons.util.retryIfException import com.vitorpamplona.quartz.utils.Log import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.tasks.await diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/CoroutinesExt.kt b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/util/CoroutinesUtils.kt similarity index 97% rename from amethyst/src/main/java/com/vitorpamplona/amethyst/service/CoroutinesExt.kt rename to commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/util/CoroutinesUtils.kt index 2d5bfaf9d9..9462a3b696 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/CoroutinesExt.kt +++ b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/util/CoroutinesUtils.kt @@ -18,7 +18,7 @@ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.vitorpamplona.amethyst.service +package com.vitorpamplona.amethyst.commons.util import com.vitorpamplona.quartz.utils.Log import kotlinx.coroutines.CancellationException diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/SetExt.kt b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/util/SetUtils.kt similarity index 96% rename from amethyst/src/main/java/com/vitorpamplona/amethyst/service/SetExt.kt rename to commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/util/SetUtils.kt index 48f52e791d..7f46393d6e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/SetExt.kt +++ b/commons/src/commonMain/kotlin/com/vitorpamplona/amethyst/commons/util/SetUtils.kt @@ -18,6 +18,6 @@ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package com.vitorpamplona.amethyst.service +package com.vitorpamplona.amethyst.commons.util fun Set.togglePresenceInSet(item: T): Set = if (contains(item)) minus(item) else plus(item)