From 5f862e4c084775fcdad83ede0e1500f76979f7f4 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 5 Mar 2021 13:47:46 +1100 Subject: [PATCH] remove uneeded passing of models to Data calls --- js/background.js | 12 +++--------- js/delivery_receipts.js | 5 +---- js/expiring_messages.js | 12 +++--------- js/modules/attachment_downloads.js | 8 ++------ js/modules/backup.js | 5 +---- js/modules/loki_app_dot_net_api.js | 4 +--- js/read_receipts.js | 5 +---- js/read_syncs.js | 5 +---- test/backup_test.js | 12 +++--------- test/fixtures.js | 4 +--- ts/state/ducks/conversations.ts | 5 ----- 11 files changed, 17 insertions(+), 60 deletions(-) diff --git a/js/background.js b/js/background.js index 4f95237f0..7648e5553 100644 --- a/js/background.js +++ b/js/background.js @@ -285,9 +285,7 @@ if (conversation) { conversation.removeMessage(id); } - window.Signal.Data.removeMessage(id, { - Message: window.models.Message.MessageModel, - }); + window.Signal.Data.removeMessage(id); }); } ); @@ -305,9 +303,7 @@ window.log.info('Cleanup: starting...'); const results = await Promise.all([ - window.Signal.Data.getOutgoingWithoutExpiresAt({ - MessageCollection: window.models.Message.MessageCollection, - }), + window.Signal.Data.getOutgoingWithoutExpiresAt(), ]); // Combine the models @@ -344,9 +340,7 @@ } window.log.info(`Cleanup: Deleting unsent message ${sentAt}`); - await window.Signal.Data.removeMessage(message.id, { - Message: window.models.Message.MessageModel, - }); + await window.Signal.Data.removeMessage(message.id); }) ); window.log.info('Cleanup: complete'); diff --git a/js/delivery_receipts.js b/js/delivery_receipts.js index fe0455bd3..e69f6eef3 100644 --- a/js/delivery_receipts.js +++ b/js/delivery_receipts.js @@ -62,10 +62,7 @@ async onReceipt(receipt) { try { const messages = await window.Signal.Data.getMessagesBySentAt( - receipt.get('timestamp'), - { - MessageCollection: window.models.Message.MessageCollection, - } + receipt.get('timestamp') ); const message = await this.getTargetMessage( diff --git a/js/expiring_messages.js b/js/expiring_messages.js index 41eba8721..fe676b4a1 100644 --- a/js/expiring_messages.js +++ b/js/expiring_messages.js @@ -16,9 +16,7 @@ async function destroyExpiredMessages() { try { window.log.info('destroyExpiredMessages: Loading messages...'); - const messages = await window.Signal.Data.getExpiredMessages({ - MessageCollection: window.models.Message.MessageCollection, - }); + const messages = await window.Signal.Data.getExpiredMessages(); await Promise.all( messages.map(async fromDB => { @@ -30,9 +28,7 @@ // We delete after the trigger to allow the conversation time to process // the expiration before the message is removed from the database. - await window.Signal.Data.removeMessage(message.id, { - Message: window.models.Message.MessageModel, - }); + await window.Signal.Data.removeMessage(message.id); Whisper.events.trigger('messageExpired', { conversationKey: message.attributes.conversationId, @@ -59,9 +55,7 @@ let timeout; async function checkExpiringMessages() { // Look up the next expiring message and set a timer to destroy it - const messages = await window.Signal.Data.getNextExpiringMessage({ - MessageCollection: window.models.Message.MessageCollection, - }); + const messages = await window.Signal.Data.getNextExpiringMessage(); const next = messages.at(0); if (!next) { diff --git a/js/modules/attachment_downloads.js b/js/modules/attachment_downloads.js index 9ae463c32..64d66e711 100644 --- a/js/modules/attachment_downloads.js +++ b/js/modules/attachment_downloads.js @@ -142,9 +142,7 @@ async function _runJob(job) { ); } - const found = await getMessageById(messageId, { - Message: models.Message.MessageModel, - }); + const found = await getMessageById(messageId); if (!found) { logger.error('_runJob: Source message not found, deleting job'); await _finishJob(null, id); @@ -226,9 +224,7 @@ async function _runJob(job) { async function _finishJob(message, id) { if (message) { - await saveMessage(message.attributes, { - Message: models.Message.MessageModel, - }); + await saveMessage(message.attributes); const conversation = message.getConversation(); if (conversation) { message.commit(); diff --git a/js/modules/backup.js b/js/modules/backup.js index 66da841fd..c6f26a5f9 100644 --- a/js/modules/backup.js +++ b/js/modules/backup.js @@ -193,9 +193,7 @@ async function importConversationsFromJSON(conversations, options) { } ); // eslint-disable-next-line no-await-in-loop - await window.Signal.Data.saveConversation(migrated, { - Conversation: window.models.Conversation.ConversationModel, - }); + await window.Signal.Data.saveConversation(migrated); } window.log.info( @@ -693,7 +691,6 @@ async function exportConversation(conversation, options = {}) { { limit: CHUNK_SIZE, receivedAt: lastReceivedAt, - MessageCollection: window.models.Message.MessageCollection, } ); const messages = getPlainJS(collection); diff --git a/js/modules/loki_app_dot_net_api.js b/js/modules/loki_app_dot_net_api.js index 7202cbfa1..80b940e4f 100644 --- a/js/modules/loki_app_dot_net_api.js +++ b/js/modules/loki_app_dot_net_api.js @@ -2019,9 +2019,7 @@ class LokiPublicChannelAPI { payload.annotations[0].value.quote = quote; // copied from model/message.js copyFromQuotedMessage - const collection = await Signal.Data.getMessagesBySentAt(quote.id, { - MessageCollection: window.models.Message.MessageCollection, - }); + const collection = await Signal.Data.getMessagesBySentAt(quote.id); const found = collection.find(item => { const messageAuthor = item.getContact(); diff --git a/js/read_receipts.js b/js/read_receipts.js index fe5e8adcb..4c865d17c 100644 --- a/js/read_receipts.js +++ b/js/read_receipts.js @@ -62,10 +62,7 @@ async onReceipt(receipt) { try { const messages = await window.Signal.Data.getMessagesBySentAt( - receipt.get('timestamp'), - { - MessageCollection: window.models.Message.MessageCollection, - } + receipt.get('timestamp') ); const message = await this.getTargetMessage( diff --git a/js/read_syncs.js b/js/read_syncs.js index c1f191c9e..021d86d2d 100644 --- a/js/read_syncs.js +++ b/js/read_syncs.js @@ -28,10 +28,7 @@ async onReceipt(receipt) { try { const messages = await window.Signal.Data.getMessagesBySentAt( - receipt.get('timestamp'), - { - MessageCollection: window.models.Message.MessageCollection, - } + receipt.get('timestamp') ); const found = messages.find( diff --git a/test/backup_test.js b/test/backup_test.js index f9a674856..39b8ec18a 100644 --- a/test/backup_test.js +++ b/test/backup_test.js @@ -495,9 +495,7 @@ describe('Backup', () => { console.log('Backup test: Create models, save to db/disk'); const message = await upgradeMessageSchema(messageWithAttachments); - await window.Signal.Data.saveMessage(message, { - Message: window.models.Message.MessageModel, - }); + await window.Signal.Data.saveMessage(message); const conversation = { active_at: 1524185933350, @@ -518,9 +516,7 @@ describe('Backup', () => { version: 2, }; console.log({ conversation }); - await window.Signal.Data.saveConversation(conversation, { - Conversation: window.models.Conversation.ConversationModel, - }); + await window.Signal.Data.saveConversation(conversation); console.log( 'Backup test: Ensure that all attachments were saved to disk' @@ -579,9 +575,7 @@ describe('Backup', () => { ); console.log('Backup test: Check messages'); - const messageCollection = await window.Signal.Data.getAllMessages({ - MessageCollection: window.models.Message.MessageCollection, - }); + const messageCollection = await window.Signal.Data.getAllMessages(); assert.strictEqual(messageCollection.length, MESSAGE_COUNT); const messageFromDB = removeId(messageCollection.at(0).attributes); const expectedMessage = messageFromDB; diff --git a/test/fixtures.js b/test/fixtures.js index fef03d72e..bd969d847 100644 --- a/test/fixtures.js +++ b/test/fixtures.js @@ -234,9 +234,7 @@ Whisper.Fixtures = () => { conversationCollection.saveAll = function thisNeeded() { Promise.all( this.map(async (convo) => { - await window.Signal.Data.saveConversation(convo.attributes, { - Conversation: window.models.Conversation.ConversationModel, - }); + await window.Signal.Data.saveConversation(convo.attributes); await Promise.all( convo.messageCollection.map(async (message) => { diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index d220a4bbd..151039676 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -560,14 +560,12 @@ function handleMessageChanged( const updatedWithFirstMessageOfSeries = updateFirstMessageOfSeries( sortedMessage ); - console.timeEnd('handleMessageChanged' + payload.id); return { ...state, messages: updatedWithFirstMessageOfSeries, }; } - console.timeEnd('handleMessageChanged' + payload.id); return state; } @@ -577,7 +575,6 @@ function handleMessagesChanged( action: MessagesChangedActionType ) { const { payload } = action; - console.time('handleMessagesChanged' + payload.length); payload.forEach(element => { // tslint:disable-next-line: no-parameter-reassignment @@ -587,8 +584,6 @@ function handleMessagesChanged( }); }); - console.timeEnd('handleMessagesChanged' + payload.length); - return state; }