diff --git a/ts/services/MessageCache.ts b/ts/services/MessageCache.ts index 09d1922a40..29aafdb21d 100644 --- a/ts/services/MessageCache.ts +++ b/ts/services/MessageCache.ts @@ -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(), }); } diff --git a/ts/test-electron/services/MessageCache_test.ts b/ts/test-electron/services/MessageCache_test.ts index 7e313dd7a8..7f8b8f83fd 100644 --- a/ts/test-electron/services/MessageCache_test.ts +++ b/ts/test-electron/services/MessageCache_test.ts @@ -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(); diff --git a/ts/util/hydrateStoryContext.ts b/ts/util/hydrateStoryContext.ts index 6047d1bc89..5f0fc56198 100644 --- a/ts/util/hydrateStoryContext.ts +++ b/ts/util/hydrateStoryContext.ts @@ -97,7 +97,7 @@ export async function hydrateStoryContext( strictAssert(isAciString(authorAci), 'Story message from pni'); const newMessageAttributes: Partial = { storyReplyContext: { - attachment: omit(attachment, 'screenshotData'), + attachment: attachment ? omit(attachment, 'screenshotData') : undefined, authorAci, messageId: storyMessage.id, },