2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2020-10-26 22:15:28 +00:00
|
|
|
import { assert } from 'chai';
|
|
|
|
import * as sinon from 'sinon';
|
2023-08-10 16:43:33 +00:00
|
|
|
import { v4 as generateUuid } from 'uuid';
|
|
|
|
|
2023-10-04 00:12:57 +00:00
|
|
|
import type { AttachmentType } from '../../types/Attachment';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { CallbackResultType } from '../../textsecure/Types.d';
|
2023-10-04 00:12:57 +00:00
|
|
|
import type { ConversationModel } from '../../models/conversations';
|
|
|
|
import type { MessageAttributesType } from '../../model-types.d';
|
|
|
|
import type { MessageModel } from '../../models/messages';
|
|
|
|
import type { RawBodyRange } from '../../types/BodyRange';
|
2021-07-19 22:44:49 +00:00
|
|
|
import type { StorageAccessType } from '../../types/Storage.d';
|
2023-10-04 00:12:57 +00:00
|
|
|
import type { WebAPIType } from '../../textsecure/WebAPI';
|
|
|
|
import MessageSender from '../../textsecure/SendMessage';
|
|
|
|
import enMessages from '../../../_locales/en/messages.json';
|
|
|
|
import { SendStatus } from '../../messages/MessageSendState';
|
2021-07-09 19:36:10 +00:00
|
|
|
import { SignalService as Proto } from '../../protobuf';
|
2023-10-04 00:12:57 +00:00
|
|
|
import { generateAci } from '../../types/ServiceId';
|
2024-04-29 21:20:20 +00:00
|
|
|
import { getAuthor } from '../../messages/helpers';
|
2023-10-04 00:12:57 +00:00
|
|
|
import { setupI18n } from '../../util/setupI18n';
|
|
|
|
import {
|
|
|
|
APPLICATION_JSON,
|
|
|
|
AUDIO_MP3,
|
|
|
|
IMAGE_GIF,
|
|
|
|
IMAGE_PNG,
|
|
|
|
LONG_MESSAGE,
|
|
|
|
TEXT_ATTACHMENT,
|
|
|
|
VIDEO_MP4,
|
|
|
|
} from '../../types/MIME';
|
2020-09-04 22:51:50 +00:00
|
|
|
|
|
|
|
describe('Message', () => {
|
2021-07-19 22:44:49 +00:00
|
|
|
const STORAGE_KEYS_TO_RESTORE: Array<keyof StorageAccessType> = [
|
|
|
|
'number_id',
|
|
|
|
'uuid_id',
|
|
|
|
];
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
const oldStorageValues = new Map<keyof StorageAccessType, any>();
|
|
|
|
|
2020-10-26 22:15:28 +00:00
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
|
|
|
const attributes = {
|
2023-10-04 00:12:57 +00:00
|
|
|
type: 'outgoing' as const,
|
2020-10-26 22:15:28 +00:00
|
|
|
body: 'hi',
|
|
|
|
conversationId: 'foo',
|
|
|
|
attachments: [],
|
|
|
|
received_at: new Date().getTime(),
|
|
|
|
};
|
|
|
|
|
|
|
|
const source = '+1 415-555-5555';
|
|
|
|
const me = '+14155555556';
|
2023-08-16 20:54:39 +00:00
|
|
|
const ourServiceId = generateAci();
|
2020-10-26 22:15:28 +00:00
|
|
|
|
2023-10-04 00:12:57 +00:00
|
|
|
function createMessage(attrs: Partial<MessageAttributesType>): MessageModel {
|
|
|
|
return new window.Whisper.Message({
|
|
|
|
id: generateUuid(),
|
2021-03-04 21:44:57 +00:00
|
|
|
...attrs,
|
2023-10-04 00:12:57 +00:00
|
|
|
received_at: Date.now(),
|
|
|
|
} as MessageAttributesType);
|
2020-09-04 22:51:50 +00:00
|
|
|
}
|
|
|
|
|
2023-06-09 17:46:59 +00:00
|
|
|
function createMessageAndGetNotificationData(attrs: {
|
|
|
|
[key: string]: unknown;
|
|
|
|
}) {
|
|
|
|
return createMessage(attrs).getNotificationData();
|
|
|
|
}
|
|
|
|
|
2020-10-26 22:15:28 +00:00
|
|
|
before(async () => {
|
|
|
|
window.ConversationController.reset();
|
|
|
|
await window.ConversationController.load();
|
2021-07-19 22:44:49 +00:00
|
|
|
|
|
|
|
STORAGE_KEYS_TO_RESTORE.forEach(key => {
|
|
|
|
oldStorageValues.set(key, window.textsecure.storage.get(key));
|
|
|
|
});
|
2022-12-21 18:41:48 +00:00
|
|
|
await window.textsecure.storage.put('number_id', `${me}.2`);
|
2023-08-16 20:54:39 +00:00
|
|
|
await window.textsecure.storage.put('uuid_id', `${ourServiceId}.2`);
|
2020-10-26 22:15:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
after(async () => {
|
|
|
|
await window.Signal.Data.removeAll();
|
|
|
|
await window.storage.fetch();
|
2021-07-19 22:44:49 +00:00
|
|
|
|
2022-12-21 18:41:48 +00:00
|
|
|
await Promise.all(
|
|
|
|
Array.from(oldStorageValues.entries()).map(([key, oldValue]) => {
|
|
|
|
if (oldValue) {
|
|
|
|
return window.textsecure.storage.put(key, oldValue);
|
|
|
|
}
|
|
|
|
return window.textsecure.storage.remove(key);
|
|
|
|
})
|
|
|
|
);
|
2020-10-26 22:15:28 +00:00
|
|
|
});
|
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
beforeEach(function (this: Mocha.Context) {
|
2020-10-26 22:15:28 +00:00
|
|
|
this.sandbox = sinon.createSandbox();
|
|
|
|
});
|
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
afterEach(function (this: Mocha.Context) {
|
2020-10-26 22:15:28 +00:00
|
|
|
this.sandbox.restore();
|
|
|
|
});
|
|
|
|
|
2020-10-22 17:32:23 +00:00
|
|
|
// NOTE: These tests are incomplete.
|
|
|
|
describe('send', () => {
|
2021-07-19 22:44:49 +00:00
|
|
|
let oldMessageSender: undefined | MessageSender;
|
2021-07-09 21:38:51 +00:00
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
beforeEach(function (this: Mocha.Context) {
|
2021-07-19 22:44:49 +00:00
|
|
|
oldMessageSender = window.textsecure.messaging;
|
2020-10-22 17:32:23 +00:00
|
|
|
|
2021-07-19 22:44:49 +00:00
|
|
|
window.textsecure.messaging =
|
2021-07-23 17:23:50 +00:00
|
|
|
oldMessageSender ?? new MessageSender({} as WebAPIType);
|
2021-07-19 22:44:49 +00:00
|
|
|
this.sandbox
|
|
|
|
.stub(window.textsecure.messaging, 'sendSyncMessage')
|
|
|
|
.resolves({});
|
2020-10-22 17:32:23 +00:00
|
|
|
});
|
|
|
|
|
2021-07-19 22:44:49 +00:00
|
|
|
afterEach(() => {
|
|
|
|
if (oldMessageSender) {
|
|
|
|
window.textsecure.messaging = oldMessageSender;
|
|
|
|
} else {
|
|
|
|
// `window.textsecure.messaging` can be undefined in tests. Instead of updating
|
|
|
|
// the real type, I just ignore it.
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
delete (window.textsecure as any).messaging;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
it('updates `sendStateByConversationId`', async function (this: Mocha.Context) {
|
2021-07-19 22:44:49 +00:00
|
|
|
this.sandbox.useFakeTimers(1234);
|
|
|
|
|
2021-11-11 22:43:05 +00:00
|
|
|
const ourConversationId =
|
|
|
|
window.ConversationController.getOurConversationIdOrThrow();
|
|
|
|
const conversation1 =
|
|
|
|
await window.ConversationController.getOrCreateAndWait(
|
|
|
|
'a072df1d-7cee-43e2-9e6b-109710a2131c',
|
|
|
|
'private'
|
|
|
|
);
|
|
|
|
const conversation2 =
|
|
|
|
await window.ConversationController.getOrCreateAndWait(
|
|
|
|
'62bd8ef1-68da-4cfd-ac1f-3ea85db7473e',
|
|
|
|
'private'
|
|
|
|
);
|
2021-07-19 22:44:49 +00:00
|
|
|
|
|
|
|
const message = createMessage({
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId: (
|
|
|
|
await window.ConversationController.getOrCreateAndWait(
|
|
|
|
'71cc190f-97ba-4c61-9d41-0b9444d721f9',
|
|
|
|
'group'
|
|
|
|
)
|
|
|
|
).id,
|
|
|
|
sendStateByConversationId: {
|
|
|
|
[ourConversationId]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: 123,
|
|
|
|
},
|
|
|
|
[conversation1.id]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: 123,
|
|
|
|
},
|
|
|
|
[conversation2.id]: {
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: 456,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2020-10-22 17:32:23 +00:00
|
|
|
|
2021-09-24 00:49:05 +00:00
|
|
|
const fakeDataMessage = new Uint8Array(0);
|
2023-08-16 20:54:39 +00:00
|
|
|
const conversation1Uuid = conversation1.getServiceId();
|
2023-08-10 16:43:33 +00:00
|
|
|
const ignoredUuid = generateAci();
|
2021-07-19 22:44:49 +00:00
|
|
|
|
|
|
|
if (!conversation1Uuid) {
|
|
|
|
throw new Error('Test setup failed: conversation1 should have a UUID');
|
|
|
|
}
|
|
|
|
|
|
|
|
const promise = Promise.resolve<CallbackResultType>({
|
2023-08-10 16:43:33 +00:00
|
|
|
successfulServiceIds: [conversation1Uuid, ignoredUuid],
|
2021-07-15 23:48:09 +00:00
|
|
|
errors: [
|
|
|
|
Object.assign(new Error('failed'), {
|
2023-08-16 20:54:39 +00:00
|
|
|
serviceId: conversation2.getServiceId(),
|
2021-07-15 23:48:09 +00:00
|
|
|
}),
|
|
|
|
],
|
2021-07-19 22:44:49 +00:00
|
|
|
dataMessage: fakeDataMessage,
|
2023-05-10 01:25:37 +00:00
|
|
|
editMessage: undefined,
|
2021-07-15 23:48:09 +00:00
|
|
|
});
|
|
|
|
|
2023-11-17 18:16:48 +00:00
|
|
|
await message.send({
|
|
|
|
promise,
|
|
|
|
targetTimestamp: message.get('timestamp'),
|
|
|
|
});
|
2020-10-22 17:32:23 +00:00
|
|
|
|
2021-07-19 22:44:49 +00:00
|
|
|
const result = message.get('sendStateByConversationId') || {};
|
|
|
|
assert.hasAllKeys(result, [
|
|
|
|
ourConversationId,
|
|
|
|
conversation1.id,
|
|
|
|
conversation2.id,
|
|
|
|
]);
|
|
|
|
assert.strictEqual(result[ourConversationId]?.status, SendStatus.Sent);
|
|
|
|
assert.strictEqual(result[ourConversationId]?.updatedAt, 1234);
|
|
|
|
assert.strictEqual(result[conversation1.id]?.status, SendStatus.Sent);
|
|
|
|
assert.strictEqual(result[conversation1.id]?.updatedAt, 1234);
|
|
|
|
assert.strictEqual(result[conversation2.id]?.status, SendStatus.Failed);
|
|
|
|
assert.strictEqual(result[conversation2.id]?.updatedAt, 1234);
|
2020-10-22 17:32:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('saves errors from promise rejections with errors', async () => {
|
|
|
|
const message = createMessage({ type: 'outgoing', source });
|
|
|
|
|
|
|
|
const promise = Promise.reject(new Error('foo bar'));
|
2023-11-17 18:16:48 +00:00
|
|
|
await message.send({
|
|
|
|
promise,
|
|
|
|
targetTimestamp: message.get('timestamp'),
|
|
|
|
});
|
2020-10-22 17:32:23 +00:00
|
|
|
|
|
|
|
const errors = message.get('errors') || [];
|
|
|
|
assert.lengthOf(errors, 1);
|
|
|
|
assert.strictEqual(errors[0].message, 'foo bar');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('saves errors from promise rejections with objects', async () => {
|
|
|
|
const message = createMessage({ type: 'outgoing', source });
|
|
|
|
|
|
|
|
const result = {
|
|
|
|
errors: [new Error('baz qux')],
|
|
|
|
};
|
|
|
|
const promise = Promise.reject(result);
|
2023-11-17 18:16:48 +00:00
|
|
|
await message.send({
|
|
|
|
promise,
|
|
|
|
targetTimestamp: message.get('timestamp'),
|
|
|
|
});
|
2020-10-22 17:32:23 +00:00
|
|
|
|
|
|
|
const errors = message.get('errors') || [];
|
|
|
|
assert.lengthOf(errors, 1);
|
|
|
|
assert.strictEqual(errors[0].message, 'baz qux');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
describe('getContact', () => {
|
|
|
|
it('gets outgoing contact', () => {
|
2023-10-04 00:12:57 +00:00
|
|
|
const message = createMessage(attributes);
|
2024-04-29 21:20:20 +00:00
|
|
|
assert.exists(getAuthor(message.attributes));
|
2020-09-04 22:51:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('gets incoming contact', () => {
|
2023-10-04 00:12:57 +00:00
|
|
|
const message = createMessage({
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
});
|
2024-04-29 21:20:20 +00:00
|
|
|
assert.exists(getAuthor(message.attributes));
|
2020-09-04 22:51:50 +00:00
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
});
|
2020-09-04 22:51:50 +00:00
|
|
|
|
|
|
|
// Note that some of this method's behavior is untested:
|
|
|
|
// - Call history
|
|
|
|
// - Contacts
|
|
|
|
// - Expiration timer updates
|
|
|
|
// - Key changes
|
|
|
|
// - Profile changes
|
|
|
|
// - Stickers
|
|
|
|
describe('getNotificationData', () => {
|
2023-06-09 17:46:59 +00:00
|
|
|
let alice: ConversationModel | undefined;
|
|
|
|
let bob: ConversationModel | undefined;
|
|
|
|
let eve: ConversationModel | undefined;
|
|
|
|
before(() => {
|
|
|
|
alice = window.ConversationController.getOrCreate(
|
2023-08-10 16:43:33 +00:00
|
|
|
generateUuid(),
|
2023-06-09 17:46:59 +00:00
|
|
|
'private'
|
|
|
|
);
|
|
|
|
alice.set({ systemGivenName: 'Alice' });
|
|
|
|
|
|
|
|
bob = window.ConversationController.getOrCreate(
|
2023-08-10 16:43:33 +00:00
|
|
|
generateUuid(),
|
2023-06-09 17:46:59 +00:00
|
|
|
'private'
|
|
|
|
);
|
|
|
|
bob.set({ systemGivenName: 'Bob' });
|
|
|
|
|
|
|
|
eve = window.ConversationController.getOrCreate(
|
2023-08-10 16:43:33 +00:00
|
|
|
generateUuid(),
|
2023-06-09 17:46:59 +00:00
|
|
|
'private'
|
|
|
|
);
|
|
|
|
eve.set({ systemGivenName: 'Eve' });
|
|
|
|
});
|
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles unsupported messages', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
supportedVersionAtReceive: 0,
|
|
|
|
requiredProtocolVersion: Infinity,
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2020-09-04 22:51:50 +00:00
|
|
|
{ text: 'Unsupported message' }
|
|
|
|
);
|
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles erased tap-to-view messages', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
isViewOnce: true,
|
|
|
|
isErased: true,
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2020-09-04 22:51:50 +00:00
|
|
|
{ text: 'View-once Media' }
|
|
|
|
);
|
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles tap-to-view photos', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
isViewOnce: true,
|
|
|
|
isErased: false,
|
|
|
|
attachments: [
|
|
|
|
{
|
2023-10-04 00:12:57 +00:00
|
|
|
contentType: IMAGE_PNG,
|
|
|
|
size: 0,
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
|
|
|
],
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2020-09-04 22:51:50 +00:00
|
|
|
{ text: 'View-once Photo', emoji: '📷' }
|
|
|
|
);
|
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles tap-to-view videos', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
isViewOnce: true,
|
|
|
|
isErased: false,
|
|
|
|
attachments: [
|
|
|
|
{
|
2023-10-04 00:12:57 +00:00
|
|
|
contentType: VIDEO_MP4,
|
|
|
|
size: 0,
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
|
|
|
],
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2020-09-04 22:51:50 +00:00
|
|
|
{ text: 'View-once Video', emoji: '🎥' }
|
|
|
|
);
|
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles non-media tap-to-view file types', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
isViewOnce: true,
|
|
|
|
isErased: false,
|
|
|
|
attachments: [
|
|
|
|
{
|
2023-10-04 00:12:57 +00:00
|
|
|
contentType: LONG_MESSAGE,
|
|
|
|
size: 0,
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
|
|
|
],
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2020-09-04 22:51:50 +00:00
|
|
|
{ text: 'Media Message', emoji: '📎' }
|
|
|
|
);
|
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles group updates where you left the group', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
group_update: {
|
|
|
|
left: 'You',
|
|
|
|
},
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2020-09-09 02:25:05 +00:00
|
|
|
{ text: 'You are no longer a member of the group.' }
|
2020-09-04 22:51:50 +00:00
|
|
|
);
|
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles group updates where someone left the group', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
group_update: {
|
2023-08-16 20:54:39 +00:00
|
|
|
left: alice?.getServiceId(),
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2020-09-04 22:51:50 +00:00
|
|
|
{ text: 'Alice left the group.' }
|
|
|
|
);
|
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles empty group updates with a generic message', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
2023-08-16 20:54:39 +00:00
|
|
|
source: alice?.getServiceId(),
|
2020-09-04 22:51:50 +00:00
|
|
|
group_update: {},
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2020-09-04 22:51:50 +00:00
|
|
|
{ text: 'Alice updated the group.' }
|
|
|
|
);
|
|
|
|
});
|
2015-04-08 09:07:14 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles group name updates by you', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source: me,
|
|
|
|
group_update: { name: 'blerg' },
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2020-09-04 22:51:50 +00:00
|
|
|
{
|
|
|
|
text: "You updated the group. Group name is now 'blerg'.",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles group name updates by someone else', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
group_update: { name: 'blerg' },
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2020-09-04 22:51:50 +00:00
|
|
|
{
|
|
|
|
text: "+1 415-555-5555 updated the group. Group name is now 'blerg'.",
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles group avatar updates', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
group_update: { avatarUpdated: true },
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2020-09-04 22:51:50 +00:00
|
|
|
{
|
|
|
|
text: '+1 415-555-5555 updated the group. Group avatar was updated.',
|
|
|
|
}
|
|
|
|
);
|
2020-03-26 21:47:35 +00:00
|
|
|
});
|
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles you joining the group', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
group_update: { joined: [me] },
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2020-09-04 22:51:50 +00:00
|
|
|
{
|
|
|
|
text: '+1 415-555-5555 updated the group. You joined the group.',
|
|
|
|
}
|
|
|
|
);
|
2020-03-26 21:47:35 +00:00
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles someone else joining the group', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
2023-08-16 20:54:39 +00:00
|
|
|
group_update: { joined: [bob?.getServiceId()] },
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2020-09-04 22:51:50 +00:00
|
|
|
{
|
|
|
|
text: '+1 415-555-5555 updated the group. Bob joined the group.',
|
|
|
|
}
|
|
|
|
);
|
2020-03-26 21:47:35 +00:00
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles multiple people joining the group', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
2023-06-09 17:46:59 +00:00
|
|
|
group_update: {
|
2023-08-16 20:54:39 +00:00
|
|
|
joined: [
|
|
|
|
bob?.getServiceId(),
|
|
|
|
alice?.getServiceId(),
|
|
|
|
eve?.getServiceId(),
|
|
|
|
],
|
2023-06-09 17:46:59 +00:00
|
|
|
},
|
|
|
|
}),
|
2020-09-04 22:51:50 +00:00
|
|
|
{
|
2021-11-11 22:43:05 +00:00
|
|
|
text: '+1 415-555-5555 updated the group. Bob, Alice, Eve joined the group.',
|
2020-09-04 22:51:50 +00:00
|
|
|
}
|
|
|
|
);
|
2020-03-26 21:47:35 +00:00
|
|
|
});
|
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles multiple people joining the group, including you', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
2023-06-09 17:46:59 +00:00
|
|
|
group_update: {
|
|
|
|
joined: [
|
2023-08-16 20:54:39 +00:00
|
|
|
bob?.getServiceId(),
|
2023-06-09 17:46:59 +00:00
|
|
|
me,
|
2023-08-16 20:54:39 +00:00
|
|
|
alice?.getServiceId(),
|
|
|
|
eve?.getServiceId(),
|
2023-06-09 17:46:59 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
}),
|
2020-09-04 22:51:50 +00:00
|
|
|
{
|
2021-11-11 22:43:05 +00:00
|
|
|
text: '+1 415-555-5555 updated the group. Bob, Alice, Eve joined the group. You joined the group.',
|
2020-09-04 22:51:50 +00:00
|
|
|
}
|
|
|
|
);
|
2020-03-26 21:47:35 +00:00
|
|
|
});
|
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles multiple changes to group properties', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
2023-08-16 20:54:39 +00:00
|
|
|
group_update: { joined: [bob?.getServiceId()], name: 'blerg' },
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2020-09-04 22:51:50 +00:00
|
|
|
{
|
2021-11-11 22:43:05 +00:00
|
|
|
text: "+1 415-555-5555 updated the group. Bob joined the group. Group name is now 'blerg'.",
|
2020-09-04 22:51:50 +00:00
|
|
|
}
|
|
|
|
);
|
2020-03-26 21:47:35 +00:00
|
|
|
});
|
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles a session ending', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
2023-10-04 00:12:57 +00:00
|
|
|
flags: 1,
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2023-03-30 00:03:25 +00:00
|
|
|
{ text: i18n('icu:sessionEnded') }
|
2020-09-04 22:51:50 +00:00
|
|
|
);
|
2020-03-26 21:47:35 +00:00
|
|
|
});
|
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles incoming message errors', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
2023-10-04 00:12:57 +00:00
|
|
|
errors: [new Error()],
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2023-03-30 00:03:25 +00:00
|
|
|
{ text: i18n('icu:incomingError') }
|
2020-09-04 22:51:50 +00:00
|
|
|
);
|
2020-03-26 21:47:35 +00:00
|
|
|
});
|
2020-09-04 22:51:50 +00:00
|
|
|
|
2023-10-04 00:12:57 +00:00
|
|
|
const attachmentTestCases: Array<{
|
|
|
|
title: string;
|
|
|
|
attachment: AttachmentType;
|
|
|
|
expectedResult: {
|
|
|
|
text: string;
|
|
|
|
emoji: string;
|
|
|
|
bodyRanges?: Array<RawBodyRange>;
|
|
|
|
};
|
|
|
|
}> = [
|
2020-09-04 22:51:50 +00:00
|
|
|
{
|
|
|
|
title: 'GIF',
|
|
|
|
attachment: {
|
2023-10-04 00:12:57 +00:00
|
|
|
contentType: IMAGE_GIF,
|
|
|
|
size: 0,
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
2023-04-10 16:31:45 +00:00
|
|
|
expectedResult: {
|
|
|
|
text: 'GIF',
|
|
|
|
emoji: '🎡',
|
|
|
|
bodyRanges: [],
|
|
|
|
},
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'photo',
|
|
|
|
attachment: {
|
2023-10-04 00:12:57 +00:00
|
|
|
contentType: IMAGE_PNG,
|
|
|
|
size: 0,
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
2023-04-10 16:31:45 +00:00
|
|
|
expectedResult: {
|
|
|
|
text: 'Photo',
|
|
|
|
emoji: '📷',
|
|
|
|
bodyRanges: [],
|
|
|
|
},
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'video',
|
|
|
|
attachment: {
|
2023-10-04 00:12:57 +00:00
|
|
|
contentType: VIDEO_MP4,
|
|
|
|
size: 0,
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
2023-04-10 16:31:45 +00:00
|
|
|
expectedResult: {
|
|
|
|
text: 'Video',
|
|
|
|
emoji: '🎥',
|
|
|
|
bodyRanges: [],
|
|
|
|
},
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'voice message',
|
|
|
|
attachment: {
|
2023-10-04 00:12:57 +00:00
|
|
|
contentType: AUDIO_MP3,
|
2021-07-09 19:36:10 +00:00
|
|
|
flags: Proto.AttachmentPointer.Flags.VOICE_MESSAGE,
|
2023-10-04 00:12:57 +00:00
|
|
|
size: 0,
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
2023-04-10 16:31:45 +00:00
|
|
|
expectedResult: {
|
|
|
|
text: 'Voice Message',
|
|
|
|
emoji: '🎤',
|
|
|
|
bodyRanges: [],
|
|
|
|
},
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'audio message',
|
|
|
|
attachment: {
|
2023-10-04 00:12:57 +00:00
|
|
|
contentType: AUDIO_MP3,
|
|
|
|
fileName: 'audio.mp3',
|
|
|
|
size: 0,
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
2023-04-10 16:31:45 +00:00
|
|
|
expectedResult: {
|
|
|
|
text: 'Audio Message',
|
|
|
|
emoji: '🔈',
|
|
|
|
bodyRanges: [],
|
|
|
|
},
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'plain text',
|
|
|
|
attachment: {
|
2023-10-04 00:12:57 +00:00
|
|
|
contentType: LONG_MESSAGE,
|
|
|
|
size: 0,
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
2023-04-10 16:31:45 +00:00
|
|
|
expectedResult: {
|
|
|
|
text: 'File',
|
|
|
|
emoji: '📎',
|
|
|
|
bodyRanges: [],
|
|
|
|
},
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'unspecified-type',
|
|
|
|
attachment: {
|
2023-10-04 00:12:57 +00:00
|
|
|
contentType: APPLICATION_JSON,
|
|
|
|
size: 0,
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
2023-04-10 16:31:45 +00:00
|
|
|
expectedResult: {
|
|
|
|
text: 'File',
|
|
|
|
emoji: '📎',
|
|
|
|
bodyRanges: [],
|
|
|
|
},
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
|
|
|
];
|
2023-04-10 16:31:45 +00:00
|
|
|
attachmentTestCases.forEach(({ title, attachment, expectedResult }) => {
|
|
|
|
it(`handles single ${title} attachments`, () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2023-04-10 16:31:45 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
attachments: [attachment],
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2023-04-10 16:31:45 +00:00
|
|
|
expectedResult
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`handles multiple attachments where the first is a ${title}`, () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2023-04-10 16:31:45 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
attachments: [
|
|
|
|
attachment,
|
|
|
|
{
|
2023-10-04 00:12:57 +00:00
|
|
|
contentType: TEXT_ATTACHMENT,
|
|
|
|
size: 0,
|
2023-04-10 16:31:45 +00:00
|
|
|
},
|
|
|
|
],
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2023-04-10 16:31:45 +00:00
|
|
|
expectedResult
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it(`respects the caption for ${title} attachments`, () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2023-04-10 16:31:45 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
attachments: [attachment],
|
|
|
|
body: 'hello world',
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2023-04-10 16:31:45 +00:00
|
|
|
{ ...expectedResult, text: 'hello world' }
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
it('handles a "plain" message', () => {
|
|
|
|
assert.deepEqual(
|
2023-06-09 17:46:59 +00:00
|
|
|
createMessageAndGetNotificationData({
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
body: 'hello world',
|
2023-06-09 17:46:59 +00:00
|
|
|
}),
|
2023-04-10 16:31:45 +00:00
|
|
|
{ text: 'hello world', bodyRanges: [] }
|
2020-09-04 22:51:50 +00:00
|
|
|
);
|
2018-11-02 18:02:53 +00:00
|
|
|
});
|
2020-09-04 22:51:50 +00:00
|
|
|
});
|
2018-11-02 18:02:53 +00:00
|
|
|
|
2020-09-04 22:51:50 +00:00
|
|
|
describe('getNotificationText', () => {
|
2023-04-10 22:19:48 +00:00
|
|
|
it("returns a notification's text", async () => {
|
2020-09-04 22:51:50 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
createMessage({
|
2023-04-10 22:19:48 +00:00
|
|
|
conversationId: (
|
|
|
|
await window.ConversationController.getOrCreateAndWait(
|
2023-08-10 16:43:33 +00:00
|
|
|
generateUuid(),
|
2023-04-10 22:19:48 +00:00
|
|
|
'private'
|
|
|
|
)
|
|
|
|
).id,
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
body: 'hello world',
|
|
|
|
}).getNotificationText(),
|
|
|
|
'hello world'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
it("shows a notification's emoji on non-Linux", async function (this: Mocha.Context) {
|
2022-02-11 21:38:52 +00:00
|
|
|
this.sandbox.replace(window.Signal, 'OS', {
|
|
|
|
...window.Signal.OS,
|
|
|
|
isLinux() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
});
|
2020-09-04 22:51:50 +00:00
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
createMessage({
|
2023-04-10 22:19:48 +00:00
|
|
|
conversationId: (
|
|
|
|
await window.ConversationController.getOrCreateAndWait(
|
2023-08-10 16:43:33 +00:00
|
|
|
generateUuid(),
|
2023-04-10 22:19:48 +00:00
|
|
|
'private'
|
|
|
|
)
|
|
|
|
).id,
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
attachments: [
|
|
|
|
{
|
2023-10-04 00:12:57 +00:00
|
|
|
contentType: IMAGE_PNG,
|
|
|
|
size: 0,
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
}).getNotificationText(),
|
|
|
|
'📷 Photo'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
it('hides emoji on Linux', async function (this: Mocha.Context) {
|
2022-02-11 21:38:52 +00:00
|
|
|
this.sandbox.replace(window.Signal, 'OS', {
|
|
|
|
...window.Signal.OS,
|
|
|
|
isLinux() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
});
|
2020-09-04 22:51:50 +00:00
|
|
|
|
|
|
|
assert.strictEqual(
|
|
|
|
createMessage({
|
2023-04-10 22:19:48 +00:00
|
|
|
conversationId: (
|
|
|
|
await window.ConversationController.getOrCreateAndWait(
|
2023-08-10 16:43:33 +00:00
|
|
|
generateUuid(),
|
2023-04-10 22:19:48 +00:00
|
|
|
'private'
|
|
|
|
)
|
|
|
|
).id,
|
2020-09-04 22:51:50 +00:00
|
|
|
type: 'incoming',
|
|
|
|
source,
|
|
|
|
attachments: [
|
|
|
|
{
|
2023-10-04 00:12:57 +00:00
|
|
|
contentType: IMAGE_PNG,
|
|
|
|
size: 0,
|
2020-09-04 22:51:50 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
}).getNotificationText(),
|
|
|
|
'Photo'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|