Drop story replies from group timeline

This commit is contained in:
Josh Perez 2022-04-20 19:33:38 -04:00 committed by GitHub
parent e5ba00b798
commit 774246b6e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 358 additions and 33 deletions

View file

@ -77,6 +77,60 @@ describe('sql/conversationSummary', () => {
assert.isTrue(messages.hasUserInitiatedMessages);
});
it('returns the latest message in current conversation excluding group story replies', async () => {
assert.lengthOf(await _getAllMessages(), 0);
const now = Date.now();
const conversationId = getUuid();
const ourUuid = getUuid();
const message1: MessageAttributesType = {
id: getUuid(),
body: 'message 1',
type: 'outgoing',
conversationId,
sent_at: now + 1,
received_at: now + 1,
timestamp: now + 1,
};
const message2: MessageAttributesType = {
id: getUuid(),
body: 'message 2',
type: 'outgoing',
conversationId,
sent_at: now + 2,
received_at: now + 2,
timestamp: now + 2,
storyId: getUuid(),
};
const message3: MessageAttributesType = {
id: getUuid(),
body: 'message 3',
type: 'incoming',
conversationId,
sent_at: now + 3,
received_at: now + 3,
timestamp: now + 3,
storyId: getUuid(),
};
await saveMessages([message1, message2, message3], {
forceSave: true,
ourUuid,
});
assert.lengthOf(await _getAllMessages(), 3);
const messages = await getConversationMessageStats({
conversationId,
isGroup: true,
ourUuid,
});
assert.strictEqual(messages.activity?.body, message1.body, 'activity');
assert.strictEqual(messages.preview?.body, message1.body, 'preview');
assert.isTrue(messages.hasUserInitiatedMessages);
});
it('preview excludes several message types, allows type = NULL', async () => {
assert.lengthOf(await _getAllMessages(), 0);

View file

@ -719,4 +719,80 @@ describe('sql/markRead', () => {
'should be reaction5'
);
});
it('does not include group story replies', async () => {
assert.lengthOf(await _getAllMessages(), 0);
const start = Date.now();
const readAt = start + 20;
const conversationId = getUuid();
const storyId = getUuid();
const ourUuid = getUuid();
const message1: MessageAttributesType = {
id: getUuid(),
body: 'message 1',
type: 'story',
conversationId,
sent_at: start + 1,
received_at: start + 1,
timestamp: start + 1,
readStatus: ReadStatus.Read,
};
const message2: MessageAttributesType = {
id: getUuid(),
body: 'message 2',
type: 'incoming',
conversationId,
sent_at: start + 2,
received_at: start + 2,
timestamp: start + 2,
readStatus: ReadStatus.Unread,
storyId,
};
const message3: MessageAttributesType = {
id: getUuid(),
body: 'message 3',
type: 'incoming',
conversationId,
sent_at: start + 3,
received_at: start + 3,
timestamp: start + 3,
readStatus: ReadStatus.Unread,
};
const message4: MessageAttributesType = {
id: getUuid(),
body: 'message 4',
type: 'incoming',
conversationId,
sent_at: start + 4,
received_at: start + 4,
timestamp: start + 4,
readStatus: ReadStatus.Unread,
storyId,
};
await saveMessages([message1, message2, message3, message4], {
forceSave: true,
ourUuid,
});
assert.lengthOf(await _getAllMessages(), 4);
const markedRead = await getUnreadByConversationAndMarkRead({
conversationId,
isGroup: true,
newestUnreadAt: message4.received_at,
readAt,
});
assert.lengthOf(markedRead, 1, '1 message marked read');
// Sorted in descending order
assert.strictEqual(
markedRead[0].id,
message3.id,
'first should be message3'
);
});
});

View file

@ -155,6 +155,59 @@ describe('sql/timelineFetches', () => {
assert.strictEqual(messages[0].id, message2.id);
});
it('returns N most recent messages excluding group story replies', async () => {
assert.lengthOf(await _getAllMessages(), 0);
const now = Date.now();
const conversationId = getUuid();
const storyId = getUuid();
const ourUuid = getUuid();
const message1: MessageAttributesType = {
id: getUuid(),
body: 'story',
type: 'incoming',
conversationId,
sent_at: now - 20,
received_at: now - 20,
timestamp: now - 20,
storyId,
};
const message2: MessageAttributesType = {
id: getUuid(),
body: 'story reply 1',
type: 'outgoing',
conversationId,
sent_at: now - 10,
received_at: now - 10,
timestamp: now - 10,
storyId,
};
const message3: MessageAttributesType = {
id: getUuid(),
body: 'normal message',
type: 'outgoing',
conversationId,
sent_at: now,
received_at: now,
timestamp: now,
};
await saveMessages([message1, message2, message3], {
forceSave: true,
ourUuid,
});
assert.lengthOf(await _getAllMessages(), 3);
const messages = await getOlderMessagesByConversation(conversationId, {
isGroup: true,
limit: 5,
});
assert.lengthOf(messages, 1);
assert.strictEqual(messages[0].id, message3.id);
});
it('returns N messages older than provided received_at', async () => {
assert.lengthOf(await _getAllMessages(), 0);
@ -493,6 +546,60 @@ describe('sql/timelineFetches', () => {
assert.strictEqual(messages[0].id, message3.id);
});
it('returns N messages excluding group story replies', async () => {
assert.lengthOf(await _getAllMessages(), 0);
const target = Date.now();
const conversationId = getUuid();
const ourUuid = getUuid();
const message1: MessageAttributesType = {
id: getUuid(),
body: 'message 1',
type: 'outgoing',
conversationId,
sent_at: target - 10,
received_at: target - 10,
timestamp: target - 10,
storyId: getUuid(),
};
const message2: MessageAttributesType = {
id: getUuid(),
body: 'message 2',
type: 'outgoing',
conversationId,
sent_at: target + 20,
received_at: target + 20,
timestamp: target + 20,
};
const message3: MessageAttributesType = {
id: getUuid(),
body: 'message 3',
type: 'outgoing',
conversationId,
sent_at: target + 10,
received_at: target + 10,
timestamp: target + 10,
storyId: getUuid(),
};
await saveMessages([message1, message2, message3], {
forceSave: true,
ourUuid,
});
assert.lengthOf(await _getAllMessages(), 3);
const messages = await getNewerMessagesByConversation(conversationId, {
isGroup: true,
limit: 5,
receivedAt: target,
sentAt: target,
});
assert.lengthOf(messages, 1);
assert.strictEqual(messages[0].id, message2.id);
});
it('returns N newer messages with same received_at, greater sent_at', async () => {
assert.lengthOf(await _getAllMessages(), 0);