Extract IIFE into separate function
This commit is contained in:
parent
11f98474ba
commit
b7b6195cfc
1 changed files with 23 additions and 22 deletions
|
@ -91,31 +91,32 @@ const createRandomMessage = ({ conversationId } = {}) => {
|
|||
type,
|
||||
};
|
||||
|
||||
const message = (() => {
|
||||
switch (type) {
|
||||
case 'incoming':
|
||||
return Object.assign({}, commonProperties, {
|
||||
flags: 0,
|
||||
source: conversationId,
|
||||
sourceDevice: 1,
|
||||
});
|
||||
case 'outgoing':
|
||||
return Object.assign({}, commonProperties, {
|
||||
delivered: 1,
|
||||
delivered_to: [conversationId],
|
||||
expireTimer: 0,
|
||||
recipients: [conversationId],
|
||||
sent_to: [conversationId],
|
||||
synced: true,
|
||||
});
|
||||
default:
|
||||
throw new TypeError(`Unknown message type: '${type}'`);
|
||||
}
|
||||
})();
|
||||
|
||||
const message = _createMessage({ commonProperties, conversationId, type });
|
||||
return Message.initializeSchemaVersion(message);
|
||||
};
|
||||
|
||||
const _createMessage = ({ commonProperties, conversationId, type } = {}) => {
|
||||
switch (type) {
|
||||
case 'incoming':
|
||||
return Object.assign({}, commonProperties, {
|
||||
flags: 0,
|
||||
source: conversationId,
|
||||
sourceDevice: 1,
|
||||
});
|
||||
case 'outgoing':
|
||||
return Object.assign({}, commonProperties, {
|
||||
delivered: 1,
|
||||
delivered_to: [conversationId],
|
||||
expireTimer: 0,
|
||||
recipients: [conversationId],
|
||||
sent_to: [conversationId],
|
||||
synced: true,
|
||||
});
|
||||
default:
|
||||
throw new TypeError(`Unknown message type: '${type}'`);
|
||||
}
|
||||
};
|
||||
|
||||
const MEGA_BYTE = 1e6;
|
||||
const createRandomInMemoryAttachment = () => {
|
||||
const numBytes = (1 + Math.ceil((Math.random() * 50))) * MEGA_BYTE;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue