fix: merge old bookmarks into existing new bookmarks during migration
Instead of replacing the new bookmark list, the migration now checks for an existing kind 10003 event and merges old bookmarks into it, skipping duplicates that already exist. https://claude.ai/code/session_01U9sjQHQMVVHxYiesoXjqop
This commit is contained in:
@@ -1822,17 +1822,41 @@ class Account(
|
|||||||
if (!isWriteable()) return
|
if (!isWriteable()) return
|
||||||
|
|
||||||
val oldList = oldBookmarkState.getBookmarkList() ?: return
|
val oldList = oldBookmarkState.getBookmarkList() ?: return
|
||||||
val publicBookmarks = oldList.publicBookmarks()
|
val oldPublic = oldList.publicBookmarks()
|
||||||
val privateBookmarks = oldList.privateBookmarks(signer) ?: emptyList()
|
val oldPrivate = oldList.privateBookmarks(signer) ?: emptyList()
|
||||||
|
|
||||||
if (publicBookmarks.isEmpty() && privateBookmarks.isEmpty()) return
|
if (oldPublic.isEmpty() && oldPrivate.isEmpty()) return
|
||||||
|
|
||||||
|
val existingNewList = bookmarkState.getBookmarkList()
|
||||||
|
|
||||||
val newEvent =
|
val newEvent =
|
||||||
|
if (existingNewList != null) {
|
||||||
|
val existingPublic = existingNewList.publicBookmarks()
|
||||||
|
val existingPrivate = existingNewList.privateBookmarks(signer) ?: emptyList()
|
||||||
|
|
||||||
|
val existingPublicIds = existingPublic.map { it.toTagIdOnly().toList() }.toSet()
|
||||||
|
val existingPrivateIds = existingPrivate.map { it.toTagIdOnly().toList() }.toSet()
|
||||||
|
|
||||||
|
val newPublic = oldPublic.filter { it.toTagIdOnly().toList() !in existingPublicIds }
|
||||||
|
val newPrivate = oldPrivate.filter { it.toTagIdOnly().toList() !in existingPrivateIds }
|
||||||
|
|
||||||
|
if (newPublic.isEmpty() && newPrivate.isEmpty()) return
|
||||||
|
|
||||||
|
val mergedPublic = existingPublic + newPublic
|
||||||
|
val mergedPrivate = existingPrivate + newPrivate
|
||||||
|
|
||||||
BookmarkListEvent.create(
|
BookmarkListEvent.create(
|
||||||
publicBookmarks = publicBookmarks,
|
publicBookmarks = mergedPublic,
|
||||||
privateBookmarks = privateBookmarks,
|
privateBookmarks = mergedPrivate,
|
||||||
signer = signer,
|
signer = signer,
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
BookmarkListEvent.create(
|
||||||
|
publicBookmarks = oldPublic,
|
||||||
|
privateBookmarks = oldPrivate,
|
||||||
|
signer = signer,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
sendMyPublicAndPrivateOutbox(newEvent)
|
sendMyPublicAndPrivateOutbox(newEvent)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -581,7 +581,6 @@ object LocalCache : ILocalCache, ICacheProvider {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun consumeRegularEvent(
|
fun consumeRegularEvent(
|
||||||
event: Event,
|
event: Event,
|
||||||
relay: NormalizedRelayUrl?,
|
relay: NormalizedRelayUrl?,
|
||||||
|
|||||||
Reference in New Issue
Block a user