diff --git a/js/models/conversations.js b/js/models/conversations.js index 43b9685ba7..7baad9add3 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -11,7 +11,7 @@ 'use strict'; window.Whisper = window.Whisper || {}; - const { Attachment } = window.Whisper.Types; + const { Attachment, Message } = window.Whisper.Types; // TODO: Factor out private and group subclasses of Conversation @@ -643,12 +643,17 @@ lastMessage: message.getNotificationText(), }); - let sendFunc; - if (this.get('type') === 'private') { - sendFunc = textsecure.messaging.sendMessageToNumber; - } else { - sendFunc = textsecure.messaging.sendMessageToGroup; - } + const conversationType = this.get('type'); + const sendFunc = (() => { + switch (conversationType) { + case Message.PRIVATE: + return textsecure.messaging.sendMessageToNumber; + case Message.GROUP: + return textsecure.messaging.sendMessageToGroup; + default: + throw new TypeError(`Invalid conversation type: '${conversationType}'`); + } + })(); let profileKey; if (this.get('profileSharing')) { diff --git a/preload.js b/preload.js index c74e7f62c7..399978feb0 100644 --- a/preload.js +++ b/preload.js @@ -79,6 +79,7 @@ window.Whisper = window.Whisper || {}; window.Whisper.Types = window.Whisper.Types || {}; window.Whisper.Types.Attachment = require('./js/modules/types/attachment'); + window.Whisper.Types.Message = require('./js/modules/types/message'); // We pull this in last, because the native module involved appears to be sensitive to // /tmp mounted as noexec on Linux.