Delivery receipt support for edited messages
This commit is contained in:
parent
43e70720f7
commit
d093b1ab13
7 changed files with 143 additions and 22 deletions
|
@ -182,7 +182,7 @@
|
|||
"@electron/fuses": "1.5.0",
|
||||
"@formatjs/intl": "2.6.7",
|
||||
"@mixer/parallel-prettier": "2.0.3",
|
||||
"@signalapp/mock-server": "2.17.0",
|
||||
"@signalapp/mock-server": "2.18.0",
|
||||
"@storybook/addon-a11y": "6.5.6",
|
||||
"@storybook/addon-actions": "6.5.6",
|
||||
"@storybook/addon-controls": "6.5.6",
|
||||
|
|
|
@ -41,7 +41,7 @@ export async function onEdit(edit: EditAttributesType): Promise<void> {
|
|||
edits.add(edit);
|
||||
|
||||
try {
|
||||
// The conversation the deleted message was in; we have to find it in the database
|
||||
// The conversation the edited message was in; we have to find it in the database
|
||||
// to to figure that out.
|
||||
const targetConversation =
|
||||
await window.ConversationController.getConversationForTargetMessage(
|
||||
|
|
|
@ -62,9 +62,10 @@ export class ViewSyncs extends Collection {
|
|||
|
||||
async onSync(sync: ViewSyncModel): Promise<void> {
|
||||
try {
|
||||
const messages = await window.Signal.Data.getMessagesBySentAt(
|
||||
sync.get('timestamp')
|
||||
);
|
||||
const messages =
|
||||
await window.Signal.Data.getMessagesIncludingEditedBySentAt(
|
||||
sync.get('timestamp')
|
||||
);
|
||||
|
||||
const found = messages.find(item => {
|
||||
const sender = window.ConversationController.lookupOrCreate({
|
||||
|
|
|
@ -4729,7 +4729,11 @@ export function reducer(
|
|||
return state;
|
||||
}
|
||||
|
||||
const toIncrement = data.reactions?.length ? 1 : 0;
|
||||
const toIncrement =
|
||||
data.reactions?.length ||
|
||||
existingMessage.editHistory?.length !== data.editHistory?.length
|
||||
? 1
|
||||
: 0;
|
||||
|
||||
return {
|
||||
...maybeUpdateSelectedMessageForDetails(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2023 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { Proto } from '@signalapp/mock-server';
|
||||
import { Proto } from '@signalapp/mock-server';
|
||||
import { assert } from 'chai';
|
||||
import createDebug from 'debug';
|
||||
import Long from 'long';
|
||||
|
@ -10,6 +10,7 @@ import { strictAssert } from '../../util/assert';
|
|||
import * as durations from '../../util/durations';
|
||||
import type { App } from '../playwright';
|
||||
import { Bootstrap } from '../bootstrap';
|
||||
import { ReceiptType } from '../../types/Receipt';
|
||||
|
||||
export const debug = createDebug('mock:test:edit');
|
||||
|
||||
|
@ -74,17 +75,18 @@ describe('editing', function needsName() {
|
|||
await bootstrap.teardown();
|
||||
});
|
||||
|
||||
it('should edit a message', async () => {
|
||||
it('handles outgoing edited messages phone -> desktop', async () => {
|
||||
const { phone, desktop } = bootstrap;
|
||||
|
||||
const window = await app.getWindow();
|
||||
|
||||
const originalMessage = createMessage();
|
||||
const originalMessageTimestamp = Number(originalMessage.timestamp);
|
||||
|
||||
debug('sending message');
|
||||
{
|
||||
const sendOptions = {
|
||||
timestamp: Number(originalMessage.timestamp),
|
||||
timestamp: originalMessageTimestamp,
|
||||
};
|
||||
await phone.sendRaw(
|
||||
desktop,
|
||||
|
@ -104,11 +106,18 @@ describe('editing', function needsName() {
|
|||
debug('checking for message');
|
||||
await window.locator('.module-message__text >> "hey yhere"').waitFor();
|
||||
|
||||
debug('waiting for receipts for original message');
|
||||
const receipts = await app.waitForReceipts();
|
||||
assert.strictEqual(receipts.type, ReceiptType.Read);
|
||||
assert.strictEqual(receipts.timestamps.length, 1);
|
||||
assert.strictEqual(receipts.timestamps[0], originalMessageTimestamp);
|
||||
|
||||
debug('sending edited message');
|
||||
const editedMessage = createEditedMessage(originalMessage);
|
||||
const editedMessageTimestamp = Number(editedMessage.dataMessage?.timestamp);
|
||||
{
|
||||
const editedMessage = createEditedMessage(originalMessage);
|
||||
const sendOptions = {
|
||||
timestamp: Number(editedMessage.dataMessage?.timestamp),
|
||||
timestamp: editedMessageTimestamp,
|
||||
};
|
||||
await phone.sendRaw(
|
||||
desktop,
|
||||
|
@ -123,4 +132,84 @@ describe('editing', function needsName() {
|
|||
const messages = window.locator('.module-message__text');
|
||||
assert.strictEqual(await messages.count(), 1, 'message count');
|
||||
});
|
||||
|
||||
it('handles incoming edited messages contact -> desktop', async () => {
|
||||
const { contacts, desktop } = bootstrap;
|
||||
|
||||
const window = await app.getWindow();
|
||||
|
||||
const [friend] = contacts;
|
||||
|
||||
const originalMessage = createMessage();
|
||||
const originalMessageTimestamp = Number(originalMessage.timestamp);
|
||||
|
||||
debug('incoming message');
|
||||
{
|
||||
const sendOptions = {
|
||||
timestamp: originalMessageTimestamp,
|
||||
};
|
||||
await friend.sendRaw(
|
||||
desktop,
|
||||
wrap({ dataMessage: originalMessage }),
|
||||
sendOptions
|
||||
);
|
||||
}
|
||||
|
||||
debug('opening conversation');
|
||||
const leftPane = window.locator('.left-pane-wrapper');
|
||||
await leftPane
|
||||
.locator('.module-conversation-list__item--contact-or-conversation')
|
||||
.first()
|
||||
.click();
|
||||
await window.locator('.module-conversation-hero').waitFor();
|
||||
|
||||
debug('checking for message');
|
||||
await window.locator('.module-message__text >> "hey yhere"').waitFor();
|
||||
|
||||
debug('waiting for original receipt');
|
||||
const originalReceipt = await friend.waitForReceipt();
|
||||
{
|
||||
const { receiptMessage } = originalReceipt;
|
||||
strictAssert(receiptMessage.timestamp, 'receipt has a timestamp');
|
||||
assert.strictEqual(receiptMessage.type, Proto.ReceiptMessage.Type.READ);
|
||||
assert.strictEqual(receiptMessage.timestamp.length, 1);
|
||||
assert.strictEqual(
|
||||
Number(receiptMessage.timestamp[0]),
|
||||
originalMessageTimestamp
|
||||
);
|
||||
}
|
||||
|
||||
debug('sending edited message');
|
||||
const editedMessage = createEditedMessage(originalMessage);
|
||||
const editedMessageTimestamp = Number(editedMessage.dataMessage?.timestamp);
|
||||
{
|
||||
const sendOptions = {
|
||||
timestamp: editedMessageTimestamp,
|
||||
};
|
||||
await friend.sendRaw(
|
||||
desktop,
|
||||
wrap({ editMessage: editedMessage }),
|
||||
sendOptions
|
||||
);
|
||||
}
|
||||
|
||||
debug('checking for edited message');
|
||||
await window.locator('.module-message__text >> "hey there"').waitFor();
|
||||
|
||||
const messages = window.locator('.module-message__text');
|
||||
assert.strictEqual(await messages.count(), 1, 'message count');
|
||||
|
||||
debug('waiting for receipt for edited message');
|
||||
const editedReceipt = await friend.waitForReceipt();
|
||||
{
|
||||
const { receiptMessage } = editedReceipt;
|
||||
strictAssert(receiptMessage.timestamp, 'receipt has a timestamp');
|
||||
assert.strictEqual(receiptMessage.type, Proto.ReceiptMessage.Type.READ);
|
||||
assert.strictEqual(receiptMessage.timestamp.length, 1);
|
||||
assert.strictEqual(
|
||||
Number(receiptMessage.timestamp[0]),
|
||||
editedMessageTimestamp
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -15,7 +15,9 @@ import {
|
|||
isVoiceMessage,
|
||||
} from '../types/Attachment';
|
||||
import { getMessageIdForLogging } from './idForLogging';
|
||||
import { isOutgoing } from '../messages/helpers';
|
||||
import { hasErrors } from '../state/selectors/message';
|
||||
import { isIncoming, isOutgoing } from '../messages/helpers';
|
||||
import { isDirectConversation } from './whatTypeOfConversation';
|
||||
import { queueAttachmentDownloads } from './queueAttachmentDownloads';
|
||||
import { shouldReplyNotifyUser } from './shouldReplyNotifyUser';
|
||||
|
||||
|
@ -157,6 +159,33 @@ export async function handleEditMessage(
|
|||
mainMessageModel.set(updatedFields);
|
||||
}
|
||||
|
||||
const conversation = window.ConversationController.get(editAttributes.fromId);
|
||||
|
||||
// Send delivery receipts, but only for non-story sealed sender messages
|
||||
// and not for messages from unaccepted conversations.
|
||||
if (
|
||||
isIncoming(upgradedEditedMessageData) &&
|
||||
upgradedEditedMessageData.unidentifiedDeliveryReceived &&
|
||||
!hasErrors(upgradedEditedMessageData) &&
|
||||
conversation?.getAccepted()
|
||||
) {
|
||||
// Note: We both queue and batch because we want to wait until we are done
|
||||
// processing incoming messages to start sending outgoing delivery receipts.
|
||||
// The queue can be paused easily.
|
||||
drop(
|
||||
window.Whisper.deliveryReceiptQueue.add(() => {
|
||||
window.Whisper.deliveryReceiptBatcher.add({
|
||||
messageId: mainMessage.id,
|
||||
conversationId: editAttributes.fromId,
|
||||
senderE164: editAttributes.message.source,
|
||||
senderUuid: editAttributes.message.sourceUuid,
|
||||
timestamp: editAttributes.message.timestamp,
|
||||
isDirectConversation: isDirectConversation(conversation.attributes),
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// For incoming edits, we mark the message as unread so that we're able to
|
||||
// send a read receipt for the message. In case we had already sent one for
|
||||
// the original message.
|
||||
|
@ -181,11 +210,9 @@ export async function handleEditMessage(
|
|||
drop(mainMessageModel.getConversation()?.updateLastMessage());
|
||||
|
||||
// Update notifications
|
||||
const conversation = mainMessageModel.getConversation();
|
||||
if (!conversation) {
|
||||
return;
|
||||
}
|
||||
if (await shouldReplyNotifyUser(mainMessageModel, conversation)) {
|
||||
await conversation.notify(mainMessageModel);
|
||||
if (conversation) {
|
||||
if (await shouldReplyNotifyUser(mainMessageModel, conversation)) {
|
||||
await conversation.notify(mainMessageModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2252,10 +2252,10 @@
|
|||
node-gyp-build "^4.2.3"
|
||||
uuid "^8.3.0"
|
||||
|
||||
"@signalapp/mock-server@2.17.0":
|
||||
version "2.17.0"
|
||||
resolved "https://registry.yarnpkg.com/@signalapp/mock-server/-/mock-server-2.17.0.tgz#070eb1e0ea33f5947450ac54fe86ade78e589447"
|
||||
integrity sha512-qhvhRvvWAlpR2lCGKLJWUSf5fpx//ZljwxqoQy1FZVnRYy6kEPsEUiO3oNE5Y+7HqFlMgD0Yt2OJbamvbQKngg==
|
||||
"@signalapp/mock-server@2.18.0":
|
||||
version "2.18.0"
|
||||
resolved "https://registry.yarnpkg.com/@signalapp/mock-server/-/mock-server-2.18.0.tgz#fc0d14227c4807ebfb3b701963f1b0746cf6b31f"
|
||||
integrity sha512-/zXdAlw32Fr/vR34w/Loni9UrYNmTKU4kifzJWbZppqYpV6rauFkiOmSmlTU6UDeRS+mNMZ1oY03BmMyi2d67g==
|
||||
dependencies:
|
||||
"@signalapp/libsignal-client" "^0.22.0"
|
||||
debug "^4.3.2"
|
||||
|
|
Loading…
Add table
Reference in a new issue