Use `Message` type to determine send function

Throws on invalid message type.
This commit is contained in:
Daniel Gasienica 2018-02-13 12:57:05 -05:00
parent 5203d945c9
commit 879b6f58f4
2 changed files with 13 additions and 7 deletions

View File

@ -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')) {

View File

@ -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.