remove MessageQueueInterface

pull/1495/head
Audric Ackermann 4 years ago
parent 2d7515cf0b
commit ebf9714e49
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -1650,35 +1650,36 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public async notify(message: any) { public async notify(message: any) {
if (!message.isIncoming()) { if (!message.isIncoming()) {
return Promise.resolve(); return;
} }
const conversationId = this.id; const conversationId = this.id;
return ConversationController.getInstance() const convo = await ConversationController.getInstance().getOrCreateAndWait(
.getOrCreateAndWait(message.get('source'), 'private') message.get('source'),
.then(sender => 'private'
sender.getNotificationIcon().then((iconUrl: any) => { );
const messageJSON = message.toJSON();
const messageSentAt = messageJSON.sent_at; const iconUrl = await convo.getNotificationIcon();
const messageId = message.id;
const isExpiringMessage = this.isExpiringMessage(messageJSON); const messageJSON = message.toJSON();
const messageSentAt = messageJSON.sent_at;
// window.log.info('Add notification', { const messageId = message.id;
// conversationId: this.idForLogging(), const isExpiringMessage = this.isExpiringMessage(messageJSON);
// isExpiringMessage,
// messageSentAt, // window.log.info('Add notification', {
// }); // conversationId: this.idForLogging(),
window.Whisper.Notifications.add({ // isExpiringMessage,
conversationId, // messageSentAt,
iconUrl, // });
isExpiringMessage, window.Whisper.Notifications.add({
message: message.getNotificationText(), conversationId,
messageId, iconUrl,
messageSentAt, isExpiringMessage,
title: sender.getTitle(), message: message.getNotificationText(),
}); messageId,
}) messageSentAt,
); title: convo.getTitle(),
});
} }
public async notifyTyping({ isTyping, sender }: any) { public async notifyTyping({ isTyping, sender }: any) {
// We don't do anything with typing messages from our other devices // We don't do anything with typing messages from our other devices

@ -1,8 +1,8 @@
import { MessageQueue, MessageQueueInterface } from './sending/'; import { MessageQueue } from './sending/';
let messageQueue: MessageQueue; let messageQueue: MessageQueue;
function getMessageQueue(): MessageQueueInterface { function getMessageQueue(): MessageQueue {
if (!messageQueue) { if (!messageQueue) {
messageQueue = new MessageQueue(); messageQueue = new MessageQueue();
} }

@ -1,11 +1,7 @@
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import {
GroupMessageType,
MessageQueueInterface,
MessageQueueInterfaceEvents,
} from './MessageQueueInterface';
import { import {
ChatMessage, ChatMessage,
ClosedGroupChatMessage,
ClosedGroupNewMessage, ClosedGroupNewMessage,
ContentMessage, ContentMessage,
DataMessage, DataMessage,
@ -18,8 +14,38 @@ import { PubKey, RawMessage } from '../types';
import { MessageSender } from '.'; import { MessageSender } from '.';
import { ClosedGroupMessage } from '../messages/outgoing/content/data/group/ClosedGroupMessage'; import { ClosedGroupMessage } from '../messages/outgoing/content/data/group/ClosedGroupMessage';
import { ConfigurationMessage } from '../messages/outgoing/content/ConfigurationMessage'; 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<MessageQueueInterfaceEvents>; public readonly events: TypedEventEmitter<MessageQueueInterfaceEvents>;
private readonly jobQueues: Map<string, JobQueue> = new Map(); private readonly jobQueues: Map<string, JobQueue> = new Map();
private readonly pendingMessageCache: PendingMessageCache; private readonly pendingMessageCache: PendingMessageCache;

@ -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<MessageQueueInterfaceEvents>;
sendToPubKey(user: PubKey, message: ContentMessage): Promise<void>;
send(device: PubKey, message: ContentMessage): Promise<void>;
sendToGroup(
message: GroupMessageType,
sentCb?: (message?: RawMessage) => Promise<void>
): Promise<void>;
sendSyncMessage(
message: any,
sentCb?: (message?: RawMessage) => Promise<void>
): Promise<void>;
processPending(device: PubKey): Promise<void>;
}

@ -4,4 +4,3 @@ export { MessageSender };
export * from './PendingMessageCache'; export * from './PendingMessageCache';
export * from './MessageQueue'; export * from './MessageQueue';
export * from './MessageQueueInterface';

@ -72,8 +72,8 @@ export const getCurrentConfigurationMessage = async (
const openGroupsIds = convos const openGroupsIds = convos
.filter(c => !!c.get('active_at') && c.isPublic() && !c.get('left')) .filter(c => !!c.get('active_at') && c.isPublic() && !c.get('left'))
.map(c => c.id.substring((c.id as string).lastIndexOf('@') + 1)) as Array< .map(c => c.id.substring((c.id as string).lastIndexOf('@') + 1)) as Array<
string string
>; >;
const closedGroupModels = convos.filter( const closedGroupModels = convos.filter(
c => c =>
!!c.get('active_at') && !!c.get('active_at') &&

@ -1,3 +1,5 @@
// tslint:disable: no-implicit-dependencies
import { SignalService } from '../../../../protobuf'; import { SignalService } from '../../../../protobuf';
import { handleConfigurationMessage } from '../../../../receiver/contentMessage'; import { handleConfigurationMessage } from '../../../../receiver/contentMessage';
import chai from 'chai'; import chai from 'chai';
@ -11,9 +13,8 @@ import * as cache from '../../../../receiver/cache';
import * as data from '../../../../../js/modules/data'; import * as data from '../../../../../js/modules/data';
import { EnvelopePlus } from '../../../../receiver/types'; import { EnvelopePlus } from '../../../../receiver/types';
// tslint:disable-next-line: no-require-imports no-var-requires import chaiAsPromised from 'chai-as-promised';
const chaiAsPromised = require('chai-as-promised'); chai.use(chaiAsPromised as any);
chai.use(chaiAsPromised);
chai.should(); chai.should();
const { expect } = chai; const { expect } = chai;
@ -44,7 +45,7 @@ describe('ConfigurationMessage_receiving', () => {
}); });
it('should not be processed if we do not have a pubkey', async () => { 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); envelope = TestUtils.generateEnvelopePlus(sender);
const proto = config.contentProto(); const proto = config.contentProto();
@ -62,7 +63,7 @@ describe('ConfigurationMessage_receiving', () => {
const ourNumber = TestUtils.generateFakePubKey().key; const ourNumber = TestUtils.generateFakePubKey().key;
beforeEach(() => { 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 () => { it('should not be processed if the message is not coming from our number', async () => {

@ -1,13 +1,14 @@
// tslint:disable: no-implicit-dependencies
import chai from 'chai'; import chai from 'chai';
// tslint:disable: no-require-imports no-var-requires no-implicit-dependencies
import _ from 'lodash'; import _ from 'lodash';
import { describe } from 'mocha'; import { describe } from 'mocha';
import { KeyPairRequestManager } from '../../../../receiver/keyPairRequestManager'; import { KeyPairRequestManager } from '../../../../receiver/keyPairRequestManager';
import { TestUtils } from '../../../test-utils'; import { TestUtils } from '../../../test-utils';
const chaiAsPromised = require('chai-as-promised'); import chaiAsPromised from 'chai-as-promised';
chai.use(chaiAsPromised); chai.use(chaiAsPromised as any);
chai.should(); chai.should();
const { expect } = chai; const { expect } = chai;

Loading…
Cancel
Save