diff --git a/js/modules/types/attachment.js b/js/modules/types/attachment.js index 25e58bb95..cb67b7f1d 100644 --- a/js/modules/types/attachment.js +++ b/js/modules/types/attachment.js @@ -1,6 +1,6 @@ const is = require('@sindresorhus/is'); -const MIME = require('./mime'); +const MIME = require('../../../ts/types/MIME'); const { arrayBufferToBlob, blobToArrayBuffer, dataURLToBlob } = require('blob-util'); const { autoOrientImage } = require('../auto_orient_image'); const { migrateDataToFileSystem } = require('./attachment/migrate_data_to_file_system'); diff --git a/js/modules/types/mime.js b/js/modules/types/mime.js deleted file mode 100644 index b149aead4..000000000 --- a/js/modules/types/mime.js +++ /dev/null @@ -1,10 +0,0 @@ -exports.isJPEG = mimeType => - mimeType === 'image/jpeg'; - -exports.isVideo = mimeType => - mimeType.startsWith('video/') && mimeType !== 'video/wmv'; - -exports.isImage = mimeType => - mimeType.startsWith('image/') && mimeType !== 'image/tiff'; - -exports.isAudio = mimeType => mimeType.startsWith('audio/'); diff --git a/preload.js b/preload.js index 24eada452..d35da5a88 100644 --- a/preload.js +++ b/preload.js @@ -191,7 +191,7 @@ window.Signal.Types.Conversation = require('./ts/types/Conversation'); window.Signal.Types.Errors = require('./js/modules/types/errors'); window.Signal.Types.Message = Message; -window.Signal.Types.MIME = require('./js/modules/types/mime'); +window.Signal.Types.MIME = require('./ts/types/MIME'); window.Signal.Types.Settings = require('./js/modules/types/settings'); window.Signal.Views = {}; diff --git a/test/modules/types/mime_test.js b/test/modules/types/mime_test.js index b56f831c4..ab62bc343 100644 --- a/test/modules/types/mime_test.js +++ b/test/modules/types/mime_test.js @@ -1,6 +1,6 @@ const { assert } = require('chai'); -const MIME = require('../../../js/modules/types/mime'); +const MIME = require('../../../ts/types/MIME'); describe('MIME', () => { diff --git a/ts/components/conversation/Quote.tsx b/ts/components/conversation/Quote.tsx index 3e541f7ce..417448dd4 100644 --- a/ts/components/conversation/Quote.tsx +++ b/ts/components/conversation/Quote.tsx @@ -1,8 +1,7 @@ import React from 'react'; import classnames from 'classnames'; -// @ts-ignore -import Mime from '../../../js/modules/types/mime'; +import * as MIME from '../../../ts/types/MIME'; interface Props { @@ -92,17 +91,17 @@ export class Quote extends React.Component { const { contentType, thumbnail } = first; const objectUrl = getObjectUrl(thumbnail); - if (Mime.isVideo(contentType)) { + if (MIME.isVideo(contentType)) { return objectUrl ? this.renderImage(objectUrl, 'play') : this.renderIcon('movie'); } - if (Mime.isImage(contentType)) { + if (MIME.isImage(contentType)) { return objectUrl ? this.renderImage(objectUrl) : this.renderIcon('image'); } - if (Mime.isAudio(contentType)) { + if (MIME.isAudio(contentType)) { return this.renderIcon('microphone'); } @@ -123,16 +122,16 @@ export class Quote extends React.Component { const first = attachments[0]; const { contentType, fileName, isVoiceMessage } = first; - if (Mime.isVideo(contentType)) { + if (MIME.isVideo(contentType)) { return
{i18n('video')}
; } - if (Mime.isImage(contentType)) { + if (MIME.isImage(contentType)) { return
{i18n('photo')}
; } - if (Mime.isAudio(contentType) && isVoiceMessage) { + if (MIME.isAudio(contentType) && isVoiceMessage) { return
{i18n('voiceMessage')}
; } - if (Mime.isAudio(contentType)) { + if (MIME.isAudio(contentType)) { return
{i18n('audio')}
; } diff --git a/ts/styleguide/StyleGuideUtil.ts b/ts/styleguide/StyleGuideUtil.ts index 35149e196..0d61d39fe 100644 --- a/ts/styleguide/StyleGuideUtil.ts +++ b/ts/styleguide/StyleGuideUtil.ts @@ -20,8 +20,7 @@ export { BackboneWrapper } from '../components/utility/BackboneWrapper'; import { Quote } from '../components/conversation/Quote'; import * as HTML from '../html'; -// @ts-ignore -import MIME from '../../js/modules/types/mime'; +import * as MIME from '../../ts/types/MIME'; // TypeScript wants two things when you import: // 1) a normal typescript file diff --git a/ts/types/MIME.ts b/ts/types/MIME.ts index ade12d7d5..ed1e3b5fd 100644 --- a/ts/types/MIME.ts +++ b/ts/types/MIME.ts @@ -1 +1,14 @@ export type MIMEType = string & { _mimeTypeBrand: any }; + + +export const isVideo = (value: MIMEType): boolean => + value.startsWith('video/') && value !== 'video/wmv'; + +export const isImage = (value: MIMEType): boolean => + value.startsWith('image/') && value !== 'image/tiff'; + +export const isAudio = (value: MIMEType): boolean => + value.startsWith('audio/'); + +export const isJPEG = (value: MIMEType): boolean => + value === 'image/jpeg';