Properly clean up story replies on expiration or delete

This commit is contained in:
Scott Nonnenberg 2023-12-18 08:58:07 -08:00 committed by GitHub
parent 0918b3da7f
commit 8c71ed2590
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 2 deletions

View file

@ -230,7 +230,7 @@ export class MessageCache {
return;
}
return window.Signal.Data.saveMessage(messageAttributes, {
return window.Signal.Data.saveMessage(nextMessageAttributes, {
ourAci: window.textsecure.storage.user.getCheckedAci(),
});
}

View file

@ -8,6 +8,7 @@ import { MessageModel } from '../../models/messages';
import { strictAssert } from '../../util/assert';
import { MessageCache } from '../../services/MessageCache';
import { generateAci } from '../../types/ServiceId';
describe('MessageCache', () => {
describe('filterBySentAt', () => {
@ -343,6 +344,47 @@ describe('MessageCache', () => {
});
});
describe('setAttributes', () => {
it('saves the new attributes to the database', async () => {
const mc = new MessageCache();
const ourAci = generateAci();
const id = uuid();
const messageAttributes: MessageAttributesType = {
conversationId: uuid(),
id,
received_at: 1,
sent_at: Date.now(),
timestamp: Date.now(),
type: 'incoming',
};
await window.Signal.Data.saveMessage(messageAttributes, {
forceSave: true,
ourAci,
});
const changes = {
received_at: 2,
};
const newAttributes = {
...messageAttributes,
...changes,
};
mc.toMessageAttributes(messageAttributes);
await mc.setAttributes({
messageId: id,
messageAttributes: changes,
skipSaveToDatabase: false,
});
const messageFromDatabase = await window.Signal.Data.getMessageById(id);
assert.deepEqual(newAttributes, messageFromDatabase);
});
});
describe('accessAttributesOrThrow', () => {
it('accesses the attributes or throws if they do not exist', () => {
const mc = new MessageCache();

View file

@ -97,7 +97,7 @@ export async function hydrateStoryContext(
strictAssert(isAciString(authorAci), 'Story message from pni');
const newMessageAttributes: Partial<MessageAttributesType> = {
storyReplyContext: {
attachment: omit(attachment, 'screenshotData'),
attachment: attachment ? omit(attachment, 'screenshotData') : undefined,
authorAci,
messageId: storyMessage.id,
},