Remove delay, and implement custom moving function that updates the list in one event, rather than two with the previous approach.

This commit is contained in:
KotlinGeekDev
2025-11-28 16:14:47 +01:00
parent bf6109d18b
commit 80947207ab
3 changed files with 48 additions and 4 deletions
@@ -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,
@@ -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(
@@ -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,