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) {
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

@ -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();
}

@ -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<MessageQueueInterfaceEvents>;
private readonly jobQueues: Map<string, JobQueue> = new Map();
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 './MessageQueue';
export * from './MessageQueueInterface';

@ -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') &&

@ -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 () => {

@ -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;

Loading…
Cancel
Save