diff --git a/lib/shared/farcaster/farcaster-messages-types.js b/lib/shared/farcaster/farcaster-messages-types.js --- a/lib/shared/farcaster/farcaster-messages-types.js +++ b/lib/shared/farcaster/farcaster-messages-types.js @@ -68,13 +68,36 @@ mimeType: t.maybe(t.String), }); +type FarcasterMessageVideo = { + +type: 'video', + +url: string, + +sourceUrl: string, + +thumbnailUrl: string, + +width: number, + +height: number, + +duration: number, + ... +}; +const farcasterMessageVideoValidator: TInterface = + tShapeInexact({ + type: t.enums.of(['video']), + url: t.String, + sourceUrl: t.String, + thumbnailUrl: t.String, + width: t.Number, + height: t.Number, + duration: t.Number, + }); + type FarcasterMessageMetadata = { +medias?: $ReadOnlyArray, + +videos?: $ReadOnlyArray, ... }; const farcasterMessageMetadataValidator: TInterface = tShapeInexact({ medias: t.maybe(t.list(farcasterMessageMediaValidator)), + videos: t.maybe(t.list(farcasterMessageVideoValidator)), }); type FarcasterMentionMetadata = { diff --git a/lib/utils/convert-farcaster-message-to-comm-messages.js b/lib/utils/convert-farcaster-message-to-comm-messages.js --- a/lib/utils/convert-farcaster-message-to-comm-messages.js +++ b/lib/utils/convert-farcaster-message-to-comm-messages.js @@ -8,7 +8,7 @@ farcasterThreadIDFromConversationID, userIDFromFID, } from '../shared/id-utils.js'; -import type { Image } from '../types/media-types.js'; +import type { Image, Video } from '../types/media-types.js'; import { messageTypes } from '../types/message-types-enum.js'; import type { RawMessageInfo } from '../types/message-types.js'; @@ -45,21 +45,41 @@ if ( farcasterMessage.type === 'text' && - !!farcasterMessage?.metadata?.medias + (!!farcasterMessage?.metadata?.medias || + !!farcasterMessage?.metadata?.videos) ) { - const media = farcasterMessage.metadata.medias.map( - med => + const media: Array = + farcasterMessage.metadata.medias?.map( + med => + ({ + id: uuid.v4(), + uri: med.staticRaster, + type: 'photo', + thumbHash: findThumbHash(med.staticRaster), + dimensions: { + height: med.height, + width: med.width, + }, + }: Image), + ) || []; + + for (const video of farcasterMessage.metadata?.videos ?? []) { + media.push( ({ + type: 'video', id: uuid.v4(), - uri: med.staticRaster, - type: 'photo', - thumbHash: findThumbHash(med.staticRaster), + uri: video.url, + thumbnailID: uuid.v4(), + thumbnailURI: video.thumbnailUrl, + thumbnailThumbHash: null, + loop: false, dimensions: { - height: med.height, - width: med.width, + width: video.width, + height: video.height, }, - }: Image), - ); + }: Video), + ); + } const time = parseInt(farcasterMessage.serverTimestamp, 10); const messages: Array = [ @@ -86,7 +106,7 @@ type: messageTypes.TEXT, threadID, creatorID, - time, + time: time + 1, text: captionText, }); }