2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-12-20 21:04:02 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
2023-08-10 16:43:33 +00:00
|
|
|
import { v4 as generateUuid } from 'uuid';
|
2021-12-20 21:04:02 +00:00
|
|
|
|
2024-07-22 18:16:33 +00:00
|
|
|
import { DataReader, DataWriter } from '../../sql/Client';
|
2023-08-10 16:43:33 +00:00
|
|
|
import { generateAci } from '../../types/ServiceId';
|
2022-11-16 20:18:02 +00:00
|
|
|
import { DurationInSeconds } from '../../util/durations';
|
2021-12-20 21:04:02 +00:00
|
|
|
|
|
|
|
import type { MessageAttributesType } from '../../model-types.d';
|
|
|
|
|
2024-07-22 18:16:33 +00:00
|
|
|
const { _getAllMessages, getConversationMessageStats } = DataReader;
|
|
|
|
const { removeAll, saveMessages } = DataWriter;
|
2021-12-20 21:04:02 +00:00
|
|
|
|
|
|
|
describe('sql/conversationSummary', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await removeAll();
|
|
|
|
});
|
|
|
|
|
2022-03-16 00:11:28 +00:00
|
|
|
describe('getConversationMessageStats', () => {
|
2021-12-20 21:04:02 +00:00
|
|
|
it('returns the latest message in current conversation', async () => {
|
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
|
|
|
|
|
|
|
const now = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 1',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 1,
|
|
|
|
received_at: now + 1,
|
|
|
|
timestamp: now + 1,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 2',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 2,
|
|
|
|
received_at: now + 2,
|
|
|
|
timestamp: now + 2,
|
|
|
|
};
|
|
|
|
const message3: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 3',
|
|
|
|
type: 'outgoing',
|
2023-08-10 16:43:33 +00:00
|
|
|
conversationId: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
sent_at: now + 3,
|
|
|
|
received_at: now + 3,
|
|
|
|
timestamp: now + 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
await saveMessages([message1, message2, message3], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.lengthOf(await _getAllMessages(), 3);
|
|
|
|
|
2022-03-16 00:11:28 +00:00
|
|
|
const messages = await getConversationMessageStats({
|
2021-12-20 21:04:02 +00:00
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(messages.activity?.body, message2.body, 'activity');
|
|
|
|
assert.strictEqual(messages.preview?.body, message2.body, 'preview');
|
|
|
|
assert.isTrue(messages.hasUserInitiatedMessages);
|
|
|
|
});
|
|
|
|
|
2022-04-20 23:33:38 +00:00
|
|
|
it('returns the latest message in current conversation excluding group story replies', async () => {
|
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
|
|
|
|
|
|
|
const now = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2022-04-20 23:33:38 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2022-04-20 23:33:38 +00:00
|
|
|
body: 'message 1',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 1,
|
|
|
|
received_at: now + 1,
|
|
|
|
timestamp: now + 1,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2022-04-20 23:33:38 +00:00
|
|
|
body: 'message 2',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 2,
|
|
|
|
received_at: now + 2,
|
|
|
|
timestamp: now + 2,
|
2023-08-10 16:43:33 +00:00
|
|
|
storyId: generateUuid(),
|
2022-04-20 23:33:38 +00:00
|
|
|
};
|
|
|
|
const message3: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2022-04-20 23:33:38 +00:00
|
|
|
body: 'message 3',
|
|
|
|
type: 'incoming',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 3,
|
|
|
|
received_at: now + 3,
|
|
|
|
timestamp: now + 3,
|
2023-08-10 16:43:33 +00:00
|
|
|
storyId: generateUuid(),
|
2022-04-20 23:33:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
await saveMessages([message1, message2, message3], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2022-04-20 23:33:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.lengthOf(await _getAllMessages(), 3);
|
|
|
|
|
|
|
|
const messages = await getConversationMessageStats({
|
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2022-04-20 23:33:38 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(messages.activity?.body, message1.body, 'activity');
|
|
|
|
assert.strictEqual(messages.preview?.body, message1.body, 'preview');
|
|
|
|
assert.isTrue(messages.hasUserInitiatedMessages);
|
|
|
|
});
|
|
|
|
|
2021-12-20 21:04:02 +00:00
|
|
|
it('preview excludes several message types, allows type = NULL', async () => {
|
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
|
|
|
|
|
|
|
const now = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 1',
|
|
|
|
// @ts-expect-error We're forcing a null type here for testing
|
|
|
|
type: null,
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 1,
|
|
|
|
received_at: now + 1,
|
|
|
|
timestamp: now + 1,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 2',
|
|
|
|
type: 'change-number-notification',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 2,
|
|
|
|
received_at: now + 2,
|
|
|
|
timestamp: now + 2,
|
|
|
|
};
|
|
|
|
const message3: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 3',
|
|
|
|
type: 'group-v1-migration',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 3,
|
|
|
|
received_at: now + 3,
|
|
|
|
timestamp: now + 3,
|
|
|
|
};
|
|
|
|
const message4: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 5',
|
|
|
|
type: 'profile-change',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 5,
|
|
|
|
received_at: now + 5,
|
|
|
|
timestamp: now + 5,
|
|
|
|
};
|
2022-04-25 21:03:24 +00:00
|
|
|
const message5: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 6',
|
|
|
|
type: 'story',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 6,
|
|
|
|
received_at: now + 6,
|
|
|
|
timestamp: now + 6,
|
|
|
|
};
|
2022-04-25 21:03:24 +00:00
|
|
|
const message6: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 7',
|
|
|
|
type: 'universal-timer-notification',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 7,
|
|
|
|
received_at: now + 7,
|
|
|
|
timestamp: now + 7,
|
|
|
|
};
|
2022-04-25 21:03:24 +00:00
|
|
|
const message7: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 8',
|
|
|
|
type: 'verified-change',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 8,
|
|
|
|
received_at: now + 8,
|
|
|
|
timestamp: now + 8,
|
|
|
|
};
|
|
|
|
|
|
|
|
await saveMessages(
|
2022-04-25 21:03:24 +00:00
|
|
|
[message1, message2, message3, message4, message5, message6, message7],
|
2021-12-20 21:04:02 +00:00
|
|
|
{
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-04-25 21:03:24 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 7);
|
2021-12-20 21:04:02 +00:00
|
|
|
|
2022-03-16 00:11:28 +00:00
|
|
|
const messages = await getConversationMessageStats({
|
2021-12-20 21:04:02 +00:00
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(messages.preview?.body, message1.body);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('activity excludes several message types, allows type = NULL', async () => {
|
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
|
|
|
|
|
|
|
const now = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 1',
|
|
|
|
// @ts-expect-error We're forcing a null type here for testing
|
|
|
|
type: null,
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 1,
|
|
|
|
received_at: now + 1,
|
|
|
|
timestamp: now + 1,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 2',
|
|
|
|
type: 'change-number-notification',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 2,
|
|
|
|
received_at: now + 2,
|
|
|
|
timestamp: now + 2,
|
|
|
|
};
|
|
|
|
const message3: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 3',
|
|
|
|
type: 'group-v1-migration',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 3,
|
|
|
|
received_at: now + 3,
|
|
|
|
timestamp: now + 3,
|
|
|
|
};
|
|
|
|
const message4: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 4',
|
|
|
|
type: 'keychange',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 4,
|
|
|
|
received_at: now + 4,
|
|
|
|
timestamp: now + 4,
|
|
|
|
};
|
|
|
|
const message5: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 6',
|
|
|
|
type: 'profile-change',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 6,
|
|
|
|
received_at: now + 6,
|
|
|
|
timestamp: now + 6,
|
|
|
|
};
|
2022-04-25 21:03:24 +00:00
|
|
|
const message6: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 7',
|
|
|
|
type: 'story',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 7,
|
|
|
|
received_at: now + 7,
|
|
|
|
timestamp: now + 7,
|
|
|
|
};
|
2022-04-25 21:03:24 +00:00
|
|
|
const message7: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 8',
|
|
|
|
type: 'universal-timer-notification',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 8,
|
|
|
|
received_at: now + 8,
|
|
|
|
timestamp: now + 8,
|
|
|
|
};
|
2022-04-25 21:03:24 +00:00
|
|
|
const message8: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 9',
|
|
|
|
type: 'verified-change',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 9,
|
|
|
|
received_at: now + 9,
|
|
|
|
timestamp: now + 9,
|
|
|
|
};
|
|
|
|
|
|
|
|
await saveMessages(
|
|
|
|
[
|
|
|
|
message1,
|
|
|
|
message2,
|
|
|
|
message3,
|
|
|
|
message4,
|
|
|
|
message5,
|
|
|
|
message6,
|
|
|
|
message7,
|
|
|
|
message8,
|
|
|
|
],
|
|
|
|
{
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-04-25 21:03:24 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 8);
|
2021-12-20 21:04:02 +00:00
|
|
|
|
2022-03-16 00:11:28 +00:00
|
|
|
const messages = await getConversationMessageStats({
|
2021-12-20 21:04:02 +00:00
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(messages.activity?.body, message1.body);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('activity excludes expirationTimerUpdates with fromSync = true, includes fromSync = undefined', async () => {
|
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
|
|
|
|
|
|
|
const now = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 1',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
expirationTimerUpdate: {
|
2022-11-16 20:18:02 +00:00
|
|
|
expireTimer: DurationInSeconds.fromSeconds(10),
|
2021-12-20 21:04:02 +00:00
|
|
|
source: 'you',
|
|
|
|
},
|
|
|
|
sent_at: now + 1,
|
|
|
|
received_at: now + 1,
|
|
|
|
timestamp: now + 1,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 2',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
expirationTimerUpdate: {
|
2022-11-16 20:18:02 +00:00
|
|
|
expireTimer: DurationInSeconds.fromSeconds(10),
|
2021-12-20 21:04:02 +00:00
|
|
|
fromSync: true,
|
|
|
|
},
|
|
|
|
sent_at: now + 2,
|
|
|
|
received_at: now + 2,
|
|
|
|
timestamp: now + 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
await saveMessages([message1, message2], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.lengthOf(await _getAllMessages(), 2);
|
|
|
|
|
2022-03-16 00:11:28 +00:00
|
|
|
const messages = await getConversationMessageStats({
|
2021-12-20 21:04:02 +00:00
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(messages.activity?.body, message1.body);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('activity excludes expirationTimerUpdates with fromSync = true, includes fromSync = false', async () => {
|
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
|
|
|
|
|
|
|
const now = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 1',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
expirationTimerUpdate: {
|
2022-11-16 20:18:02 +00:00
|
|
|
expireTimer: DurationInSeconds.fromSeconds(10),
|
2021-12-20 21:04:02 +00:00
|
|
|
source: 'you',
|
|
|
|
fromSync: false,
|
|
|
|
},
|
|
|
|
sent_at: now + 1,
|
|
|
|
received_at: now + 1,
|
|
|
|
timestamp: now + 1,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 2',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
expirationTimerUpdate: {
|
2022-11-16 20:18:02 +00:00
|
|
|
expireTimer: DurationInSeconds.fromSeconds(10),
|
2021-12-20 21:04:02 +00:00
|
|
|
fromSync: true,
|
|
|
|
},
|
|
|
|
sent_at: now + 2,
|
|
|
|
received_at: now + 2,
|
|
|
|
timestamp: now + 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
await saveMessages([message1, message2], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.lengthOf(await _getAllMessages(), 2);
|
|
|
|
|
2022-03-16 00:11:28 +00:00
|
|
|
const messages = await getConversationMessageStats({
|
2021-12-20 21:04:02 +00:00
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(messages.activity?.body, message1.body);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('preview excludes expired message, includes non-disappearing message', async () => {
|
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
|
|
|
|
|
|
|
const now = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 1',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 1,
|
|
|
|
received_at: now + 1,
|
|
|
|
timestamp: now + 1,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 2',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
expirationStartTimestamp: now - 2 * 1000,
|
2022-11-16 20:18:02 +00:00
|
|
|
expireTimer: DurationInSeconds.fromSeconds(1),
|
2021-12-20 21:04:02 +00:00
|
|
|
sent_at: now + 2,
|
|
|
|
received_at: now + 2,
|
|
|
|
timestamp: now + 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
await saveMessages([message1, message2], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.lengthOf(await _getAllMessages(), 2);
|
|
|
|
|
2022-03-16 00:11:28 +00:00
|
|
|
const messages = await getConversationMessageStats({
|
2021-12-20 21:04:02 +00:00
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(messages.preview?.body, message1.body);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('preview excludes expired message, includes non-disappearing message', async () => {
|
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
|
|
|
|
|
|
|
const now = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 1',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
expirationStartTimestamp: now,
|
2022-11-16 20:18:02 +00:00
|
|
|
expireTimer: DurationInSeconds.fromSeconds(30),
|
2021-12-20 21:04:02 +00:00
|
|
|
sent_at: now + 1,
|
|
|
|
received_at: now + 1,
|
|
|
|
timestamp: now + 1,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 2',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
expirationStartTimestamp: now - 2 * 1000,
|
2022-11-16 20:18:02 +00:00
|
|
|
expireTimer: DurationInSeconds.fromSeconds(1),
|
2021-12-20 21:04:02 +00:00
|
|
|
sent_at: now + 2,
|
|
|
|
received_at: now + 2,
|
|
|
|
timestamp: now + 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
await saveMessages([message1, message2], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.lengthOf(await _getAllMessages(), 2);
|
|
|
|
|
2022-03-16 00:11:28 +00:00
|
|
|
const messages = await getConversationMessageStats({
|
2021-12-20 21:04:02 +00:00
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(messages.preview?.body, message1.body);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('excludes group v2 change events where someone else leaves a group', async () => {
|
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
|
|
|
|
|
|
|
const now = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const otherServiceId = generateAci();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 1 - removing ourselves',
|
|
|
|
type: 'group-v2-change',
|
|
|
|
conversationId,
|
|
|
|
groupV2Change: {
|
2023-08-10 16:43:33 +00:00
|
|
|
from: ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
details: [
|
|
|
|
{
|
|
|
|
type: 'member-remove',
|
2023-08-16 20:54:39 +00:00
|
|
|
aci: ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
sent_at: now + 1,
|
|
|
|
received_at: now + 1,
|
|
|
|
timestamp: now + 1,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-20 21:04:02 +00:00
|
|
|
body: 'message 2 - someone else leaving',
|
|
|
|
type: 'group-v2-change',
|
|
|
|
conversationId,
|
|
|
|
groupV2Change: {
|
2023-08-10 16:43:33 +00:00
|
|
|
from: otherServiceId,
|
2021-12-20 21:04:02 +00:00
|
|
|
details: [
|
|
|
|
{
|
|
|
|
type: 'member-remove',
|
2023-08-16 20:54:39 +00:00
|
|
|
aci: otherServiceId,
|
2021-12-20 21:04:02 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
sent_at: now + 2,
|
|
|
|
received_at: now + 2,
|
|
|
|
timestamp: now + 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
await saveMessages([message1, message2], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.lengthOf(await _getAllMessages(), 2);
|
|
|
|
|
2022-03-16 00:11:28 +00:00
|
|
|
const messages = await getConversationMessageStats({
|
2021-12-20 21:04:02 +00:00
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(messages.activity?.body, message1.body, 'activity');
|
|
|
|
assert.strictEqual(messages.preview?.body, message1.body, 'preview');
|
|
|
|
assert.isFalse(messages.hasUserInitiatedMessages);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|