2021-12-08 19:52:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// 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-08 19:52:46 +00:00
|
|
|
|
|
|
|
import dataInterface from '../../sql/Client';
|
2023-08-10 16:43:33 +00:00
|
|
|
import { generateAci } from '../../types/ServiceId';
|
2021-12-08 19:52:46 +00:00
|
|
|
|
|
|
|
import type { MessageAttributesType } from '../../model-types.d';
|
|
|
|
import { ReadStatus } from '../../messages/MessageReadStatus';
|
|
|
|
|
|
|
|
const {
|
|
|
|
removeAll,
|
|
|
|
_getAllMessages,
|
|
|
|
saveMessages,
|
|
|
|
getMessageMetricsForConversation,
|
|
|
|
getNewerMessagesByConversation,
|
|
|
|
getOlderMessagesByConversation,
|
2023-05-23 21:59:07 +00:00
|
|
|
getTotalUnreadMentionsOfMeForConversation,
|
|
|
|
getOldestUnreadMentionOfMeForConversation,
|
2021-12-08 19:52:46 +00:00
|
|
|
} = dataInterface;
|
|
|
|
|
|
|
|
describe('sql/timelineFetches', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await removeAll();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getOlderMessagesByConversation', () => {
|
|
|
|
it('returns N most recent messages', async () => {
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
|
|
|
const now = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const storyId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
|
2021-12-08 19:52:46 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 1',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now - 20,
|
|
|
|
received_at: now - 20,
|
|
|
|
timestamp: now - 20,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 2',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now - 10,
|
|
|
|
received_at: now - 10,
|
|
|
|
timestamp: now - 10,
|
|
|
|
};
|
|
|
|
const message3: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 3',
|
|
|
|
type: 'outgoing',
|
2023-08-10 16:43:33 +00:00
|
|
|
conversationId: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
sent_at: now,
|
|
|
|
received_at: now,
|
|
|
|
timestamp: now,
|
|
|
|
};
|
|
|
|
const message4: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 4',
|
|
|
|
type: 'story',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now,
|
|
|
|
received_at: now,
|
|
|
|
timestamp: now,
|
|
|
|
storyId,
|
|
|
|
};
|
|
|
|
const message5: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 5',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now,
|
|
|
|
received_at: now,
|
|
|
|
timestamp: now,
|
|
|
|
storyId,
|
|
|
|
};
|
|
|
|
|
|
|
|
await saveMessages([message1, message2, message3, message4, message5], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 5);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2023-03-04 03:03:15 +00:00
|
|
|
const messages = await getOlderMessagesByConversation({
|
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: true,
|
2021-12-08 19:52:46 +00:00
|
|
|
limit: 5,
|
2022-05-11 22:20:47 +00:00
|
|
|
storyId: undefined,
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
2022-03-16 17:30:14 +00:00
|
|
|
assert.lengthOf(messages, 3);
|
2021-12-10 22:51:54 +00:00
|
|
|
|
|
|
|
// Fetched with DESC query, but with reverse() call afterwards
|
|
|
|
assert.strictEqual(messages[0].id, message1.id);
|
|
|
|
assert.strictEqual(messages[1].id, message2.id);
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns N most recent messages for a given story', async () => {
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
|
|
|
const now = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const storyId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
|
2021-12-08 19:52:46 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'story',
|
|
|
|
type: 'story',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now - 20,
|
|
|
|
received_at: now - 20,
|
|
|
|
timestamp: now - 20,
|
|
|
|
storyId,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'story reply 1',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now - 10,
|
|
|
|
received_at: now - 10,
|
|
|
|
timestamp: now - 10,
|
|
|
|
storyId,
|
|
|
|
};
|
|
|
|
const message3: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'normal message',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now,
|
|
|
|
received_at: now,
|
|
|
|
timestamp: now,
|
|
|
|
};
|
|
|
|
|
2021-12-20 21:04:02 +00:00
|
|
|
await saveMessages([message1, message2, message3], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 3);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2023-03-04 03:03:15 +00:00
|
|
|
const messages = await getOlderMessagesByConversation({
|
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2021-12-08 19:52:46 +00:00
|
|
|
limit: 5,
|
|
|
|
storyId,
|
|
|
|
});
|
|
|
|
assert.lengthOf(messages, 1);
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.strictEqual(messages[0].id, message2.id);
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
|
2022-04-20 23:33:38 +00:00
|
|
|
it('returns N most recent messages 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 storyId = 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: 'story',
|
|
|
|
type: 'incoming',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now - 20,
|
|
|
|
received_at: now - 20,
|
|
|
|
timestamp: now - 20,
|
|
|
|
storyId,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2022-04-20 23:33:38 +00:00
|
|
|
body: 'story reply 1',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now - 10,
|
|
|
|
received_at: now - 10,
|
|
|
|
timestamp: now - 10,
|
|
|
|
storyId,
|
|
|
|
};
|
|
|
|
const message3: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2022-04-20 23:33:38 +00:00
|
|
|
body: 'normal message',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now,
|
|
|
|
received_at: now,
|
|
|
|
timestamp: now,
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2023-03-04 03:03:15 +00:00
|
|
|
const messages = await getOlderMessagesByConversation({
|
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2022-04-20 23:33:38 +00:00
|
|
|
limit: 5,
|
2022-05-11 22:20:47 +00:00
|
|
|
storyId: undefined,
|
2022-04-20 23:33:38 +00:00
|
|
|
});
|
|
|
|
assert.lengthOf(messages, 1);
|
|
|
|
assert.strictEqual(messages[0].id, message3.id);
|
|
|
|
});
|
|
|
|
|
2021-12-08 19:52:46 +00:00
|
|
|
it('returns N messages older than provided received_at', async () => {
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
|
|
|
const target = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
|
2021-12-08 19:52:46 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 1',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target - 10,
|
|
|
|
received_at: target - 10,
|
|
|
|
timestamp: target - 10,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 2',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target,
|
|
|
|
received_at: target,
|
|
|
|
timestamp: target,
|
|
|
|
};
|
|
|
|
const message3: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 3',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target + 10,
|
|
|
|
received_at: target + 10,
|
|
|
|
timestamp: target + 10,
|
|
|
|
};
|
|
|
|
|
2021-12-20 21:04:02 +00:00
|
|
|
await saveMessages([message1, message2, message3], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 3);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2023-03-04 03:03:15 +00:00
|
|
|
const messages = await getOlderMessagesByConversation({
|
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2021-12-08 19:52:46 +00:00
|
|
|
limit: 5,
|
|
|
|
receivedAt: target,
|
|
|
|
sentAt: target,
|
2022-05-11 22:20:47 +00:00
|
|
|
storyId: undefined,
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
assert.lengthOf(messages, 1);
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.strictEqual(messages[0].id, message1.id);
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns N older messages with received_at, lesser sent_at', async () => {
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
|
|
|
const target = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
|
2021-12-08 19:52:46 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 1',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target - 20,
|
|
|
|
received_at: target,
|
|
|
|
timestamp: target,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 2',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target - 10,
|
|
|
|
received_at: target,
|
|
|
|
timestamp: target,
|
|
|
|
};
|
|
|
|
const message3: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 3',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target,
|
|
|
|
received_at: target,
|
|
|
|
timestamp: target,
|
|
|
|
};
|
|
|
|
|
2021-12-20 21:04:02 +00:00
|
|
|
await saveMessages([message1, message2, message3], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 3);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2023-03-04 03:03:15 +00:00
|
|
|
const messages = await getOlderMessagesByConversation({
|
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2021-12-08 19:52:46 +00:00
|
|
|
limit: 5,
|
|
|
|
receivedAt: target,
|
|
|
|
sentAt: target,
|
2022-05-11 22:20:47 +00:00
|
|
|
storyId: undefined,
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.lengthOf(messages, 2);
|
2021-12-10 22:51:54 +00:00
|
|
|
|
|
|
|
// Fetched with DESC query, but with reverse() call afterwards
|
|
|
|
assert.strictEqual(messages[0].id, message1.id, 'checking message 1');
|
|
|
|
assert.strictEqual(messages[1].id, message2.id, 'checking message 2');
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns N older messages, same received_at/sent_at but excludes messageId', async () => {
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
|
|
|
const target = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
|
2021-12-08 19:52:46 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 1',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target - 10,
|
|
|
|
received_at: target,
|
|
|
|
timestamp: target,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 2',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target - 10,
|
|
|
|
received_at: target,
|
|
|
|
timestamp: target,
|
|
|
|
};
|
|
|
|
const message3: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 3',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target,
|
|
|
|
received_at: target,
|
|
|
|
timestamp: target,
|
|
|
|
};
|
|
|
|
|
2021-12-20 21:04:02 +00:00
|
|
|
await saveMessages([message1, message2, message3], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 3);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2023-03-04 03:03:15 +00:00
|
|
|
const messages = await getOlderMessagesByConversation({
|
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2021-12-08 19:52:46 +00:00
|
|
|
limit: 5,
|
2022-05-11 22:20:47 +00:00
|
|
|
messageId: message2.id,
|
2021-12-08 19:52:46 +00:00
|
|
|
receivedAt: target,
|
|
|
|
sentAt: target,
|
2022-05-11 22:20:47 +00:00
|
|
|
storyId: undefined,
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.lengthOf(messages, 1);
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.strictEqual(messages[0].id, message1.id);
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getNewerMessagesByConversation', () => {
|
|
|
|
it('returns N oldest messages with no parameters', async () => {
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
|
|
|
const now = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const storyId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
|
2021-12-08 19:52:46 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 1',
|
|
|
|
type: 'outgoing',
|
2023-08-10 16:43:33 +00:00
|
|
|
conversationId: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
sent_at: now,
|
|
|
|
received_at: now,
|
|
|
|
timestamp: now,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 2',
|
|
|
|
type: 'story',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now,
|
|
|
|
received_at: now,
|
|
|
|
timestamp: now,
|
|
|
|
storyId,
|
|
|
|
};
|
|
|
|
const message3: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 3',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now,
|
|
|
|
received_at: now,
|
|
|
|
timestamp: now,
|
|
|
|
storyId,
|
|
|
|
};
|
|
|
|
const message4: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 4',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 10,
|
|
|
|
received_at: now + 10,
|
|
|
|
timestamp: now + 10,
|
|
|
|
};
|
|
|
|
const message5: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 5',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 20,
|
|
|
|
received_at: now + 20,
|
|
|
|
timestamp: now + 20,
|
|
|
|
};
|
|
|
|
|
|
|
|
await saveMessages([message1, message2, message3, message4, message5], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 5);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2023-03-04 03:03:15 +00:00
|
|
|
const messages = await getNewerMessagesByConversation({
|
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: true,
|
2021-12-08 19:52:46 +00:00
|
|
|
limit: 5,
|
2022-05-11 22:20:47 +00:00
|
|
|
storyId: undefined,
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
|
2022-03-16 17:30:14 +00:00
|
|
|
assert.lengthOf(messages, 3);
|
|
|
|
assert.strictEqual(messages[0].id, message3.id, 'checking message 3');
|
|
|
|
assert.strictEqual(messages[1].id, message4.id, 'checking message 4');
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns N oldest messages for a given story with no parameters', async () => {
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
|
|
|
const now = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const storyId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
|
2021-12-08 19:52:46 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 1',
|
|
|
|
type: 'story',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now,
|
|
|
|
received_at: now,
|
|
|
|
timestamp: now,
|
|
|
|
storyId,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 2',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 10,
|
|
|
|
received_at: now + 10,
|
|
|
|
timestamp: now + 10,
|
|
|
|
storyId,
|
|
|
|
};
|
|
|
|
const message3: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 3',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now + 20,
|
|
|
|
received_at: now + 20,
|
|
|
|
timestamp: now + 20,
|
|
|
|
};
|
|
|
|
|
2021-12-20 21:04:02 +00:00
|
|
|
await saveMessages([message1, message2, message3], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 3);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2023-03-04 03:03:15 +00:00
|
|
|
const messages = await getNewerMessagesByConversation({
|
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2021-12-08 19:52:46 +00:00
|
|
|
limit: 5,
|
|
|
|
storyId,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.lengthOf(messages, 1);
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.strictEqual(messages[0].id, message2.id);
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns N messages newer than provided received_at', async () => {
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
|
|
|
const target = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
|
2021-12-08 19:52:46 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 1',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target - 10,
|
|
|
|
received_at: target - 10,
|
|
|
|
timestamp: target - 10,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 2',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target,
|
|
|
|
received_at: target,
|
|
|
|
timestamp: target,
|
|
|
|
};
|
|
|
|
const message3: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 3',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target + 10,
|
|
|
|
received_at: target + 10,
|
|
|
|
timestamp: target + 10,
|
|
|
|
};
|
|
|
|
|
2021-12-20 21:04:02 +00:00
|
|
|
await saveMessages([message1, message2, message3], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 3);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2023-03-04 03:03:15 +00:00
|
|
|
const messages = await getNewerMessagesByConversation({
|
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2021-12-08 19:52:46 +00:00
|
|
|
limit: 5,
|
|
|
|
receivedAt: target,
|
|
|
|
sentAt: target,
|
2022-05-11 22:20:47 +00:00
|
|
|
storyId: undefined,
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
assert.lengthOf(messages, 1);
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.strictEqual(messages[0].id, message3.id);
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
|
2022-04-20 23:33:38 +00:00
|
|
|
it('returns N messages excluding group story replies', async () => {
|
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
|
|
|
|
|
|
|
const target = 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: target - 10,
|
|
|
|
received_at: target - 10,
|
|
|
|
timestamp: target - 10,
|
2023-08-10 16:43:33 +00:00
|
|
|
storyId: generateUuid(),
|
2022-04-20 23:33:38 +00:00
|
|
|
};
|
|
|
|
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: target + 20,
|
|
|
|
received_at: target + 20,
|
|
|
|
timestamp: target + 20,
|
|
|
|
};
|
|
|
|
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: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target + 10,
|
|
|
|
received_at: target + 10,
|
|
|
|
timestamp: target + 10,
|
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);
|
|
|
|
|
2023-03-04 03:03:15 +00:00
|
|
|
const messages = await getNewerMessagesByConversation({
|
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2022-04-20 23:33:38 +00:00
|
|
|
limit: 5,
|
2022-05-11 22:20:47 +00:00
|
|
|
storyId: undefined,
|
2022-04-20 23:33:38 +00:00
|
|
|
receivedAt: target,
|
|
|
|
sentAt: target,
|
|
|
|
});
|
|
|
|
assert.lengthOf(messages, 1);
|
|
|
|
assert.strictEqual(messages[0].id, message2.id);
|
|
|
|
});
|
|
|
|
|
2021-12-08 19:52:46 +00:00
|
|
|
it('returns N newer messages with same received_at, greater sent_at', async () => {
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
|
|
|
const target = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-20 21:04:02 +00:00
|
|
|
|
2021-12-08 19:52:46 +00:00
|
|
|
const message1: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 1',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target,
|
|
|
|
received_at: target,
|
|
|
|
timestamp: target,
|
|
|
|
};
|
|
|
|
const message2: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 2',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target + 10,
|
|
|
|
received_at: target,
|
|
|
|
timestamp: target,
|
|
|
|
};
|
|
|
|
const message3: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'message 3',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target + 20,
|
|
|
|
received_at: target,
|
|
|
|
timestamp: target,
|
|
|
|
};
|
|
|
|
|
2021-12-20 21:04:02 +00:00
|
|
|
await saveMessages([message1, message2, message3], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2021-12-20 21:04:02 +00:00
|
|
|
});
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 3);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2023-03-04 03:03:15 +00:00
|
|
|
const messages = await getNewerMessagesByConversation({
|
|
|
|
conversationId,
|
2022-09-30 00:57:11 +00:00
|
|
|
includeStoryReplies: false,
|
2021-12-08 19:52:46 +00:00
|
|
|
limit: 5,
|
|
|
|
receivedAt: target,
|
|
|
|
sentAt: target,
|
2022-05-11 22:20:47 +00:00
|
|
|
storyId: undefined,
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.lengthOf(messages, 2);
|
|
|
|
// They are not in DESC order because MessageCollection is sorting them
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.strictEqual(messages[0].id, message2.id);
|
|
|
|
assert.strictEqual(messages[1].id, message3.id);
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getMessageMetricsForConversation', () => {
|
|
|
|
it('returns metrics properly for story and non-story timelines', async () => {
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
|
|
|
const target = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const storyId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2021-12-08 19:52:46 +00:00
|
|
|
|
|
|
|
const story: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'story',
|
|
|
|
type: 'story',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target - 10,
|
|
|
|
received_at: target - 10,
|
|
|
|
timestamp: target - 10,
|
|
|
|
};
|
|
|
|
const oldestInStory: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'oldestInStory',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target - 9,
|
|
|
|
received_at: target - 9,
|
|
|
|
timestamp: target - 9,
|
|
|
|
storyId,
|
|
|
|
};
|
|
|
|
const oldest: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'oldest',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target - 8,
|
|
|
|
received_at: target - 8,
|
|
|
|
timestamp: target - 8,
|
|
|
|
};
|
2022-04-22 18:35:14 +00:00
|
|
|
const oldestUnseen: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2022-04-22 18:35:14 +00:00
|
|
|
body: 'oldestUnseen',
|
2021-12-08 19:52:46 +00:00
|
|
|
type: 'incoming',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target - 7,
|
|
|
|
received_at: target - 7,
|
|
|
|
timestamp: target - 7,
|
|
|
|
readStatus: ReadStatus.Unread,
|
|
|
|
};
|
|
|
|
const oldestStoryUnread: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'oldestStoryUnread',
|
|
|
|
type: 'incoming',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target - 6,
|
|
|
|
received_at: target - 6,
|
|
|
|
timestamp: target - 6,
|
|
|
|
readStatus: ReadStatus.Unread,
|
|
|
|
storyId,
|
|
|
|
};
|
|
|
|
const anotherUnread: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'anotherUnread',
|
|
|
|
type: 'incoming',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target - 5,
|
|
|
|
received_at: target - 5,
|
|
|
|
timestamp: target - 5,
|
|
|
|
readStatus: ReadStatus.Unread,
|
|
|
|
};
|
|
|
|
const newestInStory: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'newestStory',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target - 4,
|
|
|
|
received_at: target - 4,
|
|
|
|
timestamp: target - 4,
|
|
|
|
storyId,
|
|
|
|
};
|
|
|
|
const newest: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2021-12-08 19:52:46 +00:00
|
|
|
body: 'newest',
|
|
|
|
type: 'outgoing',
|
|
|
|
conversationId,
|
|
|
|
sent_at: target - 3,
|
|
|
|
received_at: target - 3,
|
|
|
|
timestamp: target - 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
await saveMessages(
|
|
|
|
[
|
|
|
|
story,
|
|
|
|
oldestInStory,
|
|
|
|
oldest,
|
2022-04-22 18:35:14 +00:00
|
|
|
oldestUnseen,
|
2021-12-08 19:52:46 +00:00
|
|
|
oldestStoryUnread,
|
|
|
|
anotherUnread,
|
|
|
|
newestInStory,
|
|
|
|
newest,
|
|
|
|
],
|
2023-08-10 16:43:33 +00:00
|
|
|
{ forceSave: true, ourAci }
|
2021-12-08 19:52:46 +00:00
|
|
|
);
|
|
|
|
|
2021-12-10 22:51:54 +00:00
|
|
|
assert.lengthOf(await _getAllMessages(), 8);
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2023-03-04 03:03:15 +00:00
|
|
|
const metricsInTimeline = await getMessageMetricsForConversation({
|
2022-09-30 00:57:11 +00:00
|
|
|
conversationId,
|
2023-03-04 03:03:15 +00:00
|
|
|
includeStoryReplies: false,
|
|
|
|
});
|
2022-09-30 00:57:11 +00:00
|
|
|
assert.strictEqual(metricsInTimeline?.oldest?.id, oldest.id, 'oldest');
|
2021-12-08 19:52:46 +00:00
|
|
|
assert.strictEqual(metricsInTimeline?.newest?.id, newest.id, 'newest');
|
|
|
|
assert.strictEqual(
|
2022-04-22 18:35:14 +00:00
|
|
|
metricsInTimeline?.oldestUnseen?.id,
|
|
|
|
oldestUnseen.id,
|
|
|
|
'oldestUnseen'
|
2021-12-08 19:52:46 +00:00
|
|
|
);
|
2022-09-30 00:57:11 +00:00
|
|
|
assert.strictEqual(metricsInTimeline?.totalUnseen, 2, 'totalUnseen');
|
2021-12-08 19:52:46 +00:00
|
|
|
|
2023-03-04 03:03:15 +00:00
|
|
|
const metricsInStory = await getMessageMetricsForConversation({
|
2021-12-08 19:52:46 +00:00
|
|
|
conversationId,
|
2023-03-04 03:03:15 +00:00
|
|
|
storyId,
|
|
|
|
includeStoryReplies: true,
|
|
|
|
});
|
2021-12-08 19:52:46 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
metricsInStory?.oldest?.id,
|
|
|
|
oldestInStory.id,
|
|
|
|
'oldestInStory'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
|
|
|
metricsInStory?.newest?.id,
|
|
|
|
newestInStory.id,
|
|
|
|
'newestInStory'
|
|
|
|
);
|
|
|
|
assert.strictEqual(
|
2022-04-22 18:35:14 +00:00
|
|
|
metricsInStory?.oldestUnseen?.id,
|
2021-12-08 19:52:46 +00:00
|
|
|
oldestStoryUnread.id,
|
|
|
|
'oldestStoryUnread'
|
|
|
|
);
|
2022-04-22 18:35:14 +00:00
|
|
|
assert.strictEqual(metricsInStory?.totalUnseen, 1, 'totalUnseen');
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|
|
|
|
});
|
2023-05-23 21:59:07 +00:00
|
|
|
|
|
|
|
describe('mentionsCount & oldestUnreadMention', () => {
|
|
|
|
it('returns unread mentions count and oldest unread mention', async () => {
|
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
|
|
|
|
|
|
|
const target = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2023-05-23 21:59:07 +00:00
|
|
|
|
|
|
|
const readMentionsMe: Partial<MessageAttributesType> = {
|
|
|
|
id: 'readMentionsMe',
|
|
|
|
readStatus: ReadStatus.Read,
|
|
|
|
mentionsMe: true,
|
|
|
|
};
|
|
|
|
const unreadMentionsMe: Partial<MessageAttributesType> = {
|
|
|
|
id: 'unreadMentionsMe',
|
|
|
|
readStatus: ReadStatus.Unread,
|
|
|
|
mentionsMe: true,
|
|
|
|
};
|
|
|
|
const unreadNoMention: Partial<MessageAttributesType> = {
|
|
|
|
id: 'unreadNoMention',
|
|
|
|
readStatus: ReadStatus.Unread,
|
|
|
|
};
|
|
|
|
const unreadMentionsMeAgain: Partial<MessageAttributesType> = {
|
|
|
|
id: 'unreadMentionsMeAgain',
|
|
|
|
readStatus: ReadStatus.Unread,
|
|
|
|
mentionsMe: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
const messages = [
|
|
|
|
readMentionsMe,
|
|
|
|
unreadMentionsMe,
|
|
|
|
unreadNoMention,
|
|
|
|
unreadMentionsMeAgain,
|
|
|
|
];
|
|
|
|
|
|
|
|
const formattedMessages = messages.map<MessageAttributesType>(
|
|
|
|
(message, idx) => {
|
|
|
|
return {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2023-05-23 21:59:07 +00:00
|
|
|
body: 'body',
|
|
|
|
type: 'incoming',
|
|
|
|
sent_at: target - messages.length + idx,
|
|
|
|
received_at: target - messages.length + idx,
|
|
|
|
timestamp: target - messages.length + idx,
|
|
|
|
conversationId,
|
|
|
|
...message,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
await saveMessages(formattedMessages, { forceSave: true, ourAci });
|
2023-05-23 21:59:07 +00:00
|
|
|
|
|
|
|
assert.lengthOf(await _getAllMessages(), 4);
|
|
|
|
|
|
|
|
const unreadMentions = await getTotalUnreadMentionsOfMeForConversation(
|
|
|
|
conversationId,
|
|
|
|
{ includeStoryReplies: false }
|
|
|
|
);
|
|
|
|
const oldestUnreadMention =
|
|
|
|
await getOldestUnreadMentionOfMeForConversation(conversationId, {
|
|
|
|
includeStoryReplies: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(unreadMentions, 2);
|
|
|
|
assert.strictEqual(oldestUnreadMention?.id, 'unreadMentionsMe');
|
|
|
|
});
|
|
|
|
});
|
2021-12-08 19:52:46 +00:00
|
|
|
});
|