diff --git a/hydration/index.ts b/hydration/index.ts index 0180162..6231db6 100644 --- a/hydration/index.ts +++ b/hydration/index.ts @@ -611,6 +611,9 @@ export class Hydrator { // - story // - profile // - list basic + // - sound + // - profile + // - list basic // - embeds (story record) // - mention // - profile @@ -626,12 +629,16 @@ export class Hydrator { const stories = await this.story.getStories(uris, ctx.includeTakedowns); const storyAuthorDids = uris.map(didFromUri); + const soundUris = new Set(); const embedPostUris = new Set(); const mentionDids = new Set(); for (const story of stories.values()) { if (!story) continue; const record = story.record as StoryRecord; + if (record.sound?.uri) { + soundUris.add(record.sound.uri); + } for (const embed of record.embeds ?? []) { if ( embed && @@ -673,14 +680,18 @@ export class Hydrator { ]), ); - const [postState, profileState] = await Promise.all([ + const [postState, profileState, soundState] = await Promise.all([ postUris.length > 0 ? this.hydratePosts(postUris.map((uri) => ({ uri })), ctx) : Promise.resolve({}), this.hydrateProfilesBasic(profileDids, ctx), + this.hydrateSounds(Array.from(soundUris), ctx), ]); - return mergeManyStates(profileState, postState, { stories, ctx }); + return mergeManyStates(profileState, postState, soundState, { + stories, + ctx, + }); } // so.sprk.feed.defs#generatorView diff --git a/lexicons/so/sprk/story/defs.json b/lexicons/so/sprk/story/defs.json index 215727a..293ab81 100644 --- a/lexicons/so/sprk/story/defs.json +++ b/lexicons/so/sprk/story/defs.json @@ -17,6 +17,7 @@ "type": "union", "refs": ["so.sprk.media.image#view", "so.sprk.media.video#view"] }, + "sound": { "type": "ref", "ref": "so.sprk.sound.defs#audioView" }, "embeds": { "type": "ref", "ref": "so.sprk.embed.defs#views" diff --git a/tests/stories_test.ts b/tests/stories_test.ts index 1de7612..4f9e1db 100644 --- a/tests/stories_test.ts +++ b/tests/stories_test.ts @@ -292,6 +292,7 @@ Deno.test({ post: { uri: postUri, cid: VALID_BLOB_CID }, }, ], + sound: { uri: soundUri, cid: VALID_BLOB_CID }, createdAt: nowIso, }; @@ -385,6 +386,15 @@ Deno.test({ assertEquals(embed?.post.repostCount, 2); assertEquals(embed?.post.viewer !== undefined, true); assertEquals(embed?.post.sound?.uri, soundUri); + assertEquals(storyView?.sound?.uri, soundUri); + assertEquals(storyView?.sound?.title, "Hydrated Sound"); + assertEquals(storyView?.sound?.author.did as string, postAuthorDid); + assertEquals( + storyView?.sound?.audio, + `https://media.sprk.so/sound/${encodeURIComponent(postAuthorDid)}/${ + encodeURIComponent(VALID_BLOB_CID) + }`, + ); } finally { await cleanup(); } diff --git a/views/index.ts b/views/index.ts index e0cec5f..107437b 100644 --- a/views/index.ts +++ b/views/index.ts @@ -492,6 +492,9 @@ export class Views { author, record: storyInfo.record, media: mediaRecord ? this.storyMedia(uri, mediaRecord) : undefined, + sound: storyInfo.record.sound + ? this.sound(storyInfo.record.sound.uri, state) + : undefined, embeds: this.storyEmbeds(storyInfo.record.embeds, state), indexedAt: asDatetime( this.indexedAt(storyInfo)?.toISOString() ?? new Date().toISOString(),