Changeset View
Changeset View
Standalone View
Standalone View
lib/media/media-utils.js
// @flow | // @flow | ||||
import invariant from 'invariant'; | import invariant from 'invariant'; | ||||
import type { Media } from '../types/media-types.js'; | import type { Media } from '../types/media-types.js'; | ||||
import type { | import type { | ||||
MultimediaMessageInfo, | MultimediaMessageInfo, | ||||
RawMultimediaMessageInfo, | RawMultimediaMessageInfo, | ||||
} from '../types/message-types.js'; | } from '../types/message-types.js'; | ||||
const maxDimensions = Object.freeze({ width: 1920, height: 1920 }); | const maxDimensions = Object.freeze({ width: 1920, height: 1920 }); | ||||
function contentStringForMediaArray(media: $ReadOnlyArray<Media>): string { | function contentStringForMediaArray(media: $ReadOnlyArray<Media>): string { | ||||
if (media.length === 0) { | if (media.length === 0) { | ||||
return 'corrupted media'; | return 'corrupted media'; | ||||
} else if (media.length === 1) { | } else if (media.length === 1) { | ||||
return `a ${media[0].type}`; | const type = media[0].type.replace('encrypted_', ''); | ||||
return `a ${type}`; | |||||
} | } | ||||
let firstType; | let firstType; | ||||
for (const single of media) { | for (const single of media) { | ||||
if (!firstType) { | if (!firstType) { | ||||
firstType = single.type; | firstType = single.type; | ||||
} | } | ||||
if (firstType === single.type) { | if (firstType === single.type) { | ||||
continue; | continue; | ||||
} else { | } else { | ||||
return 'some media'; | return 'some media'; | ||||
} | } | ||||
} | } | ||||
invariant(firstType, 'there should be some media'); | invariant(firstType, 'there should be some media'); | ||||
firstType = firstType.replace('encrypted_', ''); | |||||
if (firstType === 'photo') { | if (firstType === 'photo') { | ||||
firstType = 'image'; | firstType = 'image'; | ||||
} | } | ||||
return `some ${firstType}s`; | return `some ${firstType}s`; | ||||
} | } | ||||
function multimediaMessagePreview( | function multimediaMessagePreview( | ||||
messageInfo: MultimediaMessageInfo | RawMultimediaMessageInfo, | messageInfo: MultimediaMessageInfo | RawMultimediaMessageInfo, | ||||
Show All 23 Lines |