From 25e03eba357e1d6d4f38caf1ffff9a2f75de28e1 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 19 Feb 2021 15:13:43 +1100 Subject: [PATCH] fix lint --- app/sql.js | 1 - ts/models/messageType.ts | 2 +- ts/receiver/receiver.ts | 2 +- ts/session/sending/MessageSentHandler.ts | 63 ++++++++++--------- .../session/unit/sending/MessageQueue_test.ts | 24 ++++--- 5 files changed, 48 insertions(+), 44 deletions(-) diff --git a/app/sql.js b/app/sql.js index 168b8a447..ccbc57378 100644 --- a/app/sql.js +++ b/app/sql.js @@ -7,7 +7,6 @@ const { redactAll } = require('../js/modules/privacy'); const { remove: removeUserConfig } = require('./user_config'); const pify = require('pify'); -const uuidv4 = require('uuid/v4'); const { map, isString, diff --git a/ts/models/messageType.ts b/ts/models/messageType.ts index e19e937dd..24b458084 100644 --- a/ts/models/messageType.ts +++ b/ts/models/messageType.ts @@ -1,6 +1,6 @@ import { DefaultTheme } from 'styled-components'; import _ from 'underscore'; -import uuidv4 from 'uuid'; +import { v4 as uuidv4 } from 'uuid'; import { QuotedAttachmentType } from '../components/conversation/Quote'; import { AttachmentType } from '../types/Attachment'; import { Contact } from '../types/Contact'; diff --git a/ts/receiver/receiver.ts b/ts/receiver/receiver.ts index 65e553c48..8a6ff7b76 100644 --- a/ts/receiver/receiver.ts +++ b/ts/receiver/receiver.ts @@ -2,7 +2,7 @@ import { EnvelopePlus } from './types'; export { downloadAttachment } from './attachments'; -import uuidv4 from 'uuid'; +import { v4 as uuidv4 } from 'uuid'; import { addToCache, diff --git a/ts/session/sending/MessageSentHandler.ts b/ts/session/sending/MessageSentHandler.ts index dd30f5777..4c7aeb6e2 100644 --- a/ts/session/sending/MessageSentHandler.ts +++ b/ts/session/sending/MessageSentHandler.ts @@ -3,38 +3,8 @@ import { MessageController } from '../messages'; import { OpenGroupMessage } from '../messages/outgoing'; import { RawMessage } from '../types'; +// tslint:disable-next-line no-unnecessary-class export class MessageSentHandler { - /** - * This function tries to find a message by messageId by first looking on the MessageController. - * The MessageController holds all messages being in memory. - * Those are the messages sent recently, recieved recently, or the one shown to the user. - * - * If the app restarted, it's very likely those messages won't be on the memory anymore. - * In this case, this function will look for it in the database and return it. - * If the message is found on the db, it will also register it to the MessageController so our subsequent calls are quicker. - */ - private static async fetchHandleMessageSentData( - m: RawMessage | OpenGroupMessage - ) { - // if a message was sent and this message was created after the last app restart, - // this message is still in memory in the MessageController - const msg = MessageController.getInstance().get(m.identifier); - - if (!msg || !msg.message) { - // otherwise, look for it in the database - // nobody is listening to this freshly fetched message .trigger calls - const dbMessage = await getMessageById(m.identifier); - - if (!dbMessage) { - return null; - } - MessageController.getInstance().register(m.identifier, dbMessage); - return dbMessage; - } - - return msg.message; - } - public static async handlePublicMessageSentSuccess( sentMessage: OpenGroupMessage, result: { serverId: number; serverTimestamp: number } @@ -90,4 +60,35 @@ export class MessageSentHandler { await fetchedMessage.handleMessageSentFailure(sentMessage, error); } + + /** + * This function tries to find a message by messageId by first looking on the MessageController. + * The MessageController holds all messages being in memory. + * Those are the messages sent recently, recieved recently, or the one shown to the user. + * + * If the app restarted, it's very likely those messages won't be on the memory anymore. + * In this case, this function will look for it in the database and return it. + * If the message is found on the db, it will also register it to the MessageController so our subsequent calls are quicker. + */ + private static async fetchHandleMessageSentData( + m: RawMessage | OpenGroupMessage + ) { + // if a message was sent and this message was created after the last app restart, + // this message is still in memory in the MessageController + const msg = MessageController.getInstance().get(m.identifier); + + if (!msg || !msg.message) { + // otherwise, look for it in the database + // nobody is listening to this freshly fetched message .trigger calls + const dbMessage = await getMessageById(m.identifier); + + if (!dbMessage) { + return null; + } + MessageController.getInstance().register(m.identifier, dbMessage); + return dbMessage; + } + + return msg.message; + } } diff --git a/ts/test/session/unit/sending/MessageQueue_test.ts b/ts/test/session/unit/sending/MessageQueue_test.ts index 9ad6102ff..695616f77 100644 --- a/ts/test/session/unit/sending/MessageQueue_test.ts +++ b/ts/test/session/unit/sending/MessageQueue_test.ts @@ -80,14 +80,18 @@ describe('MessageQueue', () => { done(); }); - pendingMessageCache.add( - device, - TestUtils.generateChatMessage(), - waitForMessageSentEvent as any - ); - - messageQueueStub.processPending(device); - expect(waitForMessageSentEvent).to.be.fulfilled; + void pendingMessageCache + .add( + device, + TestUtils.generateChatMessage(), + waitForMessageSentEvent as any + ) + .then(async () => { + return messageQueueStub.processPending(device); + }) + .then(() => { + expect(waitForMessageSentEvent).to.be.fulfilled; + }); }); it('should remove message from cache', async () => { @@ -123,7 +127,7 @@ describe('MessageQueue', () => { done(); }); - pendingMessageCache + void pendingMessageCache .add(device, message, waitForMessageSentEvent as any) .then(() => messageQueueStub.processPending(device)) .then(() => { @@ -144,7 +148,7 @@ describe('MessageQueue', () => { done(); }); - pendingMessageCache + void pendingMessageCache .add(device, message, waitForMessageSentEvent as any) .then(() => messageQueueStub.processPending(device)) .then(() => {