Properly clean up story replies on expiration or delete
This commit is contained in:
parent
0918b3da7f
commit
8c71ed2590
3 changed files with 44 additions and 2 deletions
|
@ -230,7 +230,7 @@ export class MessageCache {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return window.Signal.Data.saveMessage(messageAttributes, {
|
return window.Signal.Data.saveMessage(nextMessageAttributes, {
|
||||||
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
ourAci: window.textsecure.storage.user.getCheckedAci(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { MessageModel } from '../../models/messages';
|
||||||
import { strictAssert } from '../../util/assert';
|
import { strictAssert } from '../../util/assert';
|
||||||
|
|
||||||
import { MessageCache } from '../../services/MessageCache';
|
import { MessageCache } from '../../services/MessageCache';
|
||||||
|
import { generateAci } from '../../types/ServiceId';
|
||||||
|
|
||||||
describe('MessageCache', () => {
|
describe('MessageCache', () => {
|
||||||
describe('filterBySentAt', () => {
|
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', () => {
|
describe('accessAttributesOrThrow', () => {
|
||||||
it('accesses the attributes or throws if they do not exist', () => {
|
it('accesses the attributes or throws if they do not exist', () => {
|
||||||
const mc = new MessageCache();
|
const mc = new MessageCache();
|
||||||
|
|
|
@ -97,7 +97,7 @@ export async function hydrateStoryContext(
|
||||||
strictAssert(isAciString(authorAci), 'Story message from pni');
|
strictAssert(isAciString(authorAci), 'Story message from pni');
|
||||||
const newMessageAttributes: Partial<MessageAttributesType> = {
|
const newMessageAttributes: Partial<MessageAttributesType> = {
|
||||||
storyReplyContext: {
|
storyReplyContext: {
|
||||||
attachment: omit(attachment, 'screenshotData'),
|
attachment: attachment ? omit(attachment, 'screenshotData') : undefined,
|
||||||
authorAci,
|
authorAci,
|
||||||
messageId: storyMessage.id,
|
messageId: storyMessage.id,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue