[Drafts] Always write embedGallery for image embeds

Stop writing the legacy `embedImages` shape when saving drafts. Both the
`images` (<=4) and `gallery` (>4) composer variants now serialize to
`embedGallery`, which stays well under the lexicon `maxLength` of 20.

The restore path still reads `embedImages` from older drafts for
backwards compat, merging both shapes and re-deriving the variant from
image count.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Eric Bailey
2026-06-05 15:50:29 -05:00
parent b236f274c3
commit f829142ccd
+10 -14
View File
@@ -111,20 +111,16 @@ async function postDraftToServerPost(
// Add embeds // Add embeds
if (post.embed.media) { if (post.embed.media) {
if (post.embed.media.type === 'images') { // We always write the `embedGallery` shape for images now, including the
draftPost.embedImages = serializeImages( // legacy `images` variant (<=4 photos). We still read `embedImages` from
post.embed.media.images, // older drafts for backwards compat - see `draftToPostDrafts`.
localRefPaths, if (
) post.embed.media.type === 'images' ||
} else if (post.embed.media.type === 'gallery') { post.embed.media.type === 'gallery'
) {
draftPost.embedGallery = { draftPost.embedGallery = {
$type: 'app.bsky.draft.defs#draftEmbedGallery', $type: 'app.bsky.draft.defs#draftEmbedGallery',
items: serializeImages(post.embed.media.images, localRefPaths).map( items: serializeImages(post.embed.media.images, localRefPaths),
img => ({
$type: 'app.bsky.draft.defs#draftEmbedImage' as const,
...img,
}),
),
} }
} else if (post.embed.media.type === 'video') { } else if (post.embed.media.type === 'video') {
const video = await serializeVideo(post.embed.media.video, localRefPaths) const video = await serializeVideo(post.embed.media.video, localRefPaths)
@@ -179,7 +175,7 @@ async function postDraftToServerPost(
function serializeImages( function serializeImages(
images: ComposerImage[], images: ComposerImage[],
localRefPaths: Map<string, string>, localRefPaths: Map<string, string>,
): AppBskyDraftDefs.DraftEmbedImage[] { ): AppBskyDraftDefs.DraftEmbedGalleryItems {
return images.map(image => { return images.map(image => {
const sourcePath = image.transformed?.path || image.source.path const sourcePath = image.transformed?.path || image.source.path
// Reuse existing localRefPath if present (editing draft), otherwise generate new // Reuse existing localRefPath if present (editing draft), otherwise generate new
@@ -194,7 +190,7 @@ function serializeImages(
}) })
return { return {
$type: 'app.bsky.draft.defs#draftEmbedImage', $type: 'app.bsky.draft.defs#draftEmbedImage' as const,
localRef: { localRef: {
$type: 'app.bsky.draft.defs#draftEmbedLocalRef', $type: 'app.bsky.draft.defs#draftEmbedLocalRef',
path: localRefPath, path: localRefPath,