diff --git a/ts/models/conversation.ts b/ts/models/conversation.ts index a2619d3f5..7deeb3717 100644 --- a/ts/models/conversation.ts +++ b/ts/models/conversation.ts @@ -1650,35 +1650,36 @@ export class ConversationModel extends Backbone.Model { public async notify(message: any) { if (!message.isIncoming()) { - return Promise.resolve(); + return; } const conversationId = this.id; - return ConversationController.getInstance() - .getOrCreateAndWait(message.get('source'), 'private') - .then(sender => - sender.getNotificationIcon().then((iconUrl: any) => { - const messageJSON = message.toJSON(); - const messageSentAt = messageJSON.sent_at; - const messageId = message.id; - const isExpiringMessage = this.isExpiringMessage(messageJSON); - - // window.log.info('Add notification', { - // conversationId: this.idForLogging(), - // isExpiringMessage, - // messageSentAt, - // }); - window.Whisper.Notifications.add({ - conversationId, - iconUrl, - isExpiringMessage, - message: message.getNotificationText(), - messageId, - messageSentAt, - title: sender.getTitle(), - }); - }) - ); + const convo = await ConversationController.getInstance().getOrCreateAndWait( + message.get('source'), + 'private' + ); + + const iconUrl = await convo.getNotificationIcon(); + + const messageJSON = message.toJSON(); + const messageSentAt = messageJSON.sent_at; + const messageId = message.id; + const isExpiringMessage = this.isExpiringMessage(messageJSON); + + // window.log.info('Add notification', { + // conversationId: this.idForLogging(), + // isExpiringMessage, + // messageSentAt, + // }); + window.Whisper.Notifications.add({ + conversationId, + iconUrl, + isExpiringMessage, + message: message.getNotificationText(), + messageId, + messageSentAt, + title: convo.getTitle(), + }); } public async notifyTyping({ isTyping, sender }: any) { // We don't do anything with typing messages from our other devices diff --git a/ts/session/instance.ts b/ts/session/instance.ts index 15f35652b..cf7dc55a3 100644 --- a/ts/session/instance.ts +++ b/ts/session/instance.ts @@ -1,8 +1,8 @@ -import { MessageQueue, MessageQueueInterface } from './sending/'; +import { MessageQueue } from './sending/'; let messageQueue: MessageQueue; -function getMessageQueue(): MessageQueueInterface { +function getMessageQueue(): MessageQueue { if (!messageQueue) { messageQueue = new MessageQueue(); } diff --git a/ts/session/sending/MessageQueue.ts b/ts/session/sending/MessageQueue.ts index fb2d8ed4e..d4475426e 100644 --- a/ts/session/sending/MessageQueue.ts +++ b/ts/session/sending/MessageQueue.ts @@ -1,11 +1,7 @@ import { EventEmitter } from 'events'; -import { - GroupMessageType, - MessageQueueInterface, - MessageQueueInterfaceEvents, -} from './MessageQueueInterface'; import { ChatMessage, + ClosedGroupChatMessage, ClosedGroupNewMessage, ContentMessage, DataMessage, @@ -18,8 +14,38 @@ import { PubKey, RawMessage } from '../types'; import { MessageSender } from '.'; import { ClosedGroupMessage } from '../messages/outgoing/content/data/group/ClosedGroupMessage'; import { ConfigurationMessage } from '../messages/outgoing/content/ConfigurationMessage'; +import { ClosedGroupNameChangeMessage } from '../messages/outgoing/content/data/group/ClosedGroupNameChangeMessage'; +import { + ClosedGroupAddedMembersMessage, + ClosedGroupEncryptionPairMessage, + ClosedGroupEncryptionPairRequestMessage, + ClosedGroupRemovedMembersMessage, + ClosedGroupUpdateMessage, +} from '../messages/outgoing/content/data/group'; +import { ClosedGroupMemberLeftMessage } from '../messages/outgoing/content/data/group/ClosedGroupMemberLeftMessage'; + +export type GroupMessageType = + | OpenGroupMessage + | ClosedGroupChatMessage + | ClosedGroupAddedMembersMessage + | ClosedGroupRemovedMembersMessage + | ClosedGroupNameChangeMessage + | ClosedGroupMemberLeftMessage + | ClosedGroupUpdateMessage + | ExpirationTimerUpdateMessage + | ClosedGroupEncryptionPairMessage + | ClosedGroupEncryptionPairRequestMessage; + +// ClosedGroupEncryptionPairReplyMessage must be sent to a user pubkey. Not a group. +export interface MessageQueueInterfaceEvents { + sendSuccess: ( + message: RawMessage | OpenGroupMessage, + wrappedEnvelope?: Uint8Array + ) => void; + sendFail: (message: RawMessage | OpenGroupMessage, error: Error) => void; +} -export class MessageQueue implements MessageQueueInterface { +export class MessageQueue { public readonly events: TypedEventEmitter; private readonly jobQueues: Map = new Map(); private readonly pendingMessageCache: PendingMessageCache; diff --git a/ts/session/sending/MessageQueueInterface.ts b/ts/session/sending/MessageQueueInterface.ts deleted file mode 100644 index 535fc0737..000000000 --- a/ts/session/sending/MessageQueueInterface.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { - ContentMessage, - ExpirationTimerUpdateMessage, - OpenGroupMessage, -} from '../messages/outgoing'; -import { RawMessage } from '../types/RawMessage'; -import { TypedEventEmitter } from '../utils'; -import { PubKey } from '../types'; -import { ClosedGroupChatMessage } from '../messages/outgoing/content/data/group/ClosedGroupChatMessage'; -import { - ClosedGroupAddedMembersMessage, - ClosedGroupEncryptionPairMessage, - ClosedGroupNameChangeMessage, - ClosedGroupRemovedMembersMessage, - ClosedGroupUpdateMessage, -} from '../messages/outgoing/content/data/group'; -import { ClosedGroupMemberLeftMessage } from '../messages/outgoing/content/data/group/ClosedGroupMemberLeftMessage'; -import { ClosedGroupEncryptionPairRequestMessage } from '../messages/outgoing/content/data/group/ClosedGroupEncryptionPairRequestMessage'; - -export type GroupMessageType = - | OpenGroupMessage - | ClosedGroupChatMessage - | ClosedGroupAddedMembersMessage - | ClosedGroupRemovedMembersMessage - | ClosedGroupNameChangeMessage - | ClosedGroupMemberLeftMessage - | ClosedGroupUpdateMessage - | ClosedGroupEncryptionPairMessage - | ClosedGroupEncryptionPairRequestMessage; - -// ClosedGroupEncryptionPairReplyMessage must be sent to a user pubkey. Not a group. -export interface MessageQueueInterfaceEvents { - sendSuccess: ( - message: RawMessage | OpenGroupMessage, - wrappedEnvelope?: Uint8Array - ) => void; - sendFail: (message: RawMessage | OpenGroupMessage, error: Error) => void; -} - -export interface MessageQueueInterface { - events: TypedEventEmitter; - sendToPubKey(user: PubKey, message: ContentMessage): Promise; - send(device: PubKey, message: ContentMessage): Promise; - sendToGroup( - message: GroupMessageType, - sentCb?: (message?: RawMessage) => Promise - ): Promise; - sendSyncMessage( - message: any, - sentCb?: (message?: RawMessage) => Promise - ): Promise; - processPending(device: PubKey): Promise; -} diff --git a/ts/session/sending/index.ts b/ts/session/sending/index.ts index a6de06ca7..251c5d04b 100644 --- a/ts/session/sending/index.ts +++ b/ts/session/sending/index.ts @@ -4,4 +4,3 @@ export { MessageSender }; export * from './PendingMessageCache'; export * from './MessageQueue'; -export * from './MessageQueueInterface'; diff --git a/ts/session/utils/Messages.ts b/ts/session/utils/Messages.ts index f783764f8..61da963b3 100644 --- a/ts/session/utils/Messages.ts +++ b/ts/session/utils/Messages.ts @@ -72,8 +72,8 @@ export const getCurrentConfigurationMessage = async ( const openGroupsIds = convos .filter(c => !!c.get('active_at') && c.isPublic() && !c.get('left')) .map(c => c.id.substring((c.id as string).lastIndexOf('@') + 1)) as Array< - string - >; + string + >; const closedGroupModels = convos.filter( c => !!c.get('active_at') && diff --git a/ts/test/session/unit/receiving/ConfigurationMessage_test.ts b/ts/test/session/unit/receiving/ConfigurationMessage_test.ts index 0589ff1fc..6651697a3 100644 --- a/ts/test/session/unit/receiving/ConfigurationMessage_test.ts +++ b/ts/test/session/unit/receiving/ConfigurationMessage_test.ts @@ -1,3 +1,5 @@ +// tslint:disable: no-implicit-dependencies + import { SignalService } from '../../../../protobuf'; import { handleConfigurationMessage } from '../../../../receiver/contentMessage'; import chai from 'chai'; @@ -11,9 +13,8 @@ import * as cache from '../../../../receiver/cache'; import * as data from '../../../../../js/modules/data'; import { EnvelopePlus } from '../../../../receiver/types'; -// tslint:disable-next-line: no-require-imports no-var-requires -const chaiAsPromised = require('chai-as-promised'); -chai.use(chaiAsPromised); +import chaiAsPromised from 'chai-as-promised'; +chai.use(chaiAsPromised as any); chai.should(); const { expect } = chai; @@ -44,7 +45,7 @@ describe('ConfigurationMessage_receiving', () => { }); it('should not be processed if we do not have a pubkey', async () => { - sandbox.stub(UserUtils, 'getCurrentDevicePubKey').resolves(undefined); + sandbox.stub(UserUtils, 'getOurPubKeyStrFromCache').resolves(undefined); envelope = TestUtils.generateEnvelopePlus(sender); const proto = config.contentProto(); @@ -62,7 +63,7 @@ describe('ConfigurationMessage_receiving', () => { const ourNumber = TestUtils.generateFakePubKey().key; beforeEach(() => { - sandbox.stub(UserUtils, 'getCurrentDevicePubKey').resolves(ourNumber); + sandbox.stub(UserUtils, 'getOurPubKeyStrFromCache').resolves(ourNumber); }); it('should not be processed if the message is not coming from our number', async () => { diff --git a/ts/test/session/unit/receiving/KeyPairRequestManager_test.ts b/ts/test/session/unit/receiving/KeyPairRequestManager_test.ts index bab9f4dc8..4f5d38bb3 100644 --- a/ts/test/session/unit/receiving/KeyPairRequestManager_test.ts +++ b/ts/test/session/unit/receiving/KeyPairRequestManager_test.ts @@ -1,13 +1,14 @@ +// tslint:disable: no-implicit-dependencies + import chai from 'chai'; -// tslint:disable: no-require-imports no-var-requires no-implicit-dependencies import _ from 'lodash'; import { describe } from 'mocha'; import { KeyPairRequestManager } from '../../../../receiver/keyPairRequestManager'; import { TestUtils } from '../../../test-utils'; -const chaiAsPromised = require('chai-as-promised'); -chai.use(chaiAsPromised); +import chaiAsPromised from 'chai-as-promised'; +chai.use(chaiAsPromised as any); chai.should(); const { expect } = chai;