diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/labeledBookmarkLists/LabeledBookmarkListsState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/labeledBookmarkLists/LabeledBookmarkListsState.kt index e753fc751..b8686c695 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/labeledBookmarkLists/LabeledBookmarkListsState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/nip51Lists/labeledBookmarkLists/LabeledBookmarkListsState.kt @@ -265,6 +265,23 @@ class LabeledBookmarkListsState( account.sendMyPublicAndPrivateOutbox(updatedList) } + suspend fun moveBookmarkInList( + bookmark: BookmarkIdTag, + bookmarkListIdentifier: String, + isBookmarkCurrentlyPrivate: Boolean, + account: Account, + ) { + val bookmarkList = getLabeledBookmarkListEvent(bookmarkListIdentifier) + val updatedList = + LabeledBookmarkListEvent.moveBookmark( + earlierVersion = bookmarkList, + bookmarkIdTag = bookmark, + isCurrentlyPrivate = isBookmarkCurrentlyPrivate, + signer = account.signer, + ) + account.sendMyPublicAndPrivateOutbox(updatedList) + } + suspend fun removeBookmarkFromList( bookmark: BookmarkIdTag, bookmarkListIdentifier: String, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/bookmarkgroups/display/BookmarkGroupViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/bookmarkgroups/display/BookmarkGroupViewModel.kt index 97b12bad6..d51cb49de 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/bookmarkgroups/display/BookmarkGroupViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/bookmarkgroups/display/BookmarkGroupViewModel.kt @@ -29,7 +29,6 @@ import com.vitorpamplona.quartz.nip01Core.core.Address import com.vitorpamplona.quartz.nip51Lists.bookmarkList.tags.AddressBookmark import com.vitorpamplona.quartz.nip51Lists.bookmarkList.tags.BookmarkIdTag import com.vitorpamplona.quartz.nip51Lists.bookmarkList.tags.EventBookmark -import kotlinx.coroutines.delay import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.map @@ -110,9 +109,12 @@ class BookmarkGroupViewModel( bookmark: BookmarkIdTag, isCurrentlyPrivate: Boolean, ) { - removeBookmarkFromGroup(groupIdentifier, bookmark, isCurrentlyPrivate) - delay(1500L) - addBookmarkToGroup(groupIdentifier, bookmark, !isCurrentlyPrivate) + account.labeledBookmarkLists.moveBookmarkInList( + bookmark, + groupIdentifier, + isCurrentlyPrivate, + account, + ) } suspend fun removePostBookmark( diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip51Lists/labeledBookmarkList/LabeledBookmarkListEvent.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip51Lists/labeledBookmarkList/LabeledBookmarkListEvent.kt index 73b5684f6..02edaacab 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip51Lists/labeledBookmarkList/LabeledBookmarkListEvent.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/nip51Lists/labeledBookmarkList/LabeledBookmarkListEvent.kt @@ -144,6 +144,31 @@ class LabeledBookmarkListEvent( ) } + suspend fun moveBookmark( + earlierVersion: LabeledBookmarkListEvent, + bookmarkIdTag: BookmarkIdTag, + isCurrentlyPrivate: Boolean, + signer: NostrSigner, + createdAt: Long = TimeUtils.now(), + ): LabeledBookmarkListEvent = + if (isCurrentlyPrivate) { + val privateTags = earlierVersion.privateTags(signer) ?: throw SignerExceptions.UnauthorizedDecryptionException() + resign( + privateTags = privateTags.remove(bookmarkIdTag.toTagArray()), + tags = earlierVersion.tags.plus(bookmarkIdTag.toTagArray()), + signer = signer, + createdAt = createdAt, + ) + } else { + val privateTags = earlierVersion.privateTags(signer) ?: throw SignerExceptions.UnauthorizedDecryptionException() + resign( + privateTags = privateTags.plus(bookmarkIdTag.toTagArray()), + tags = earlierVersion.tags.remove(bookmarkIdTag.toTagArray()), + signer = signer, + createdAt = createdAt, + ) + } + suspend fun removeBookmark( earlierVersion: LabeledBookmarkListEvent, bookmarkIdTag: BookmarkIdTag,