From 4a3d970a353ba49c52817ddac4169b5af3e80f7b Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 24 Aug 2022 17:18:28 +1000 Subject: [PATCH 1/2] fix: make sure we drop empty messages from the main sogs pipeline --- ts/receiver/dataMessage.ts | 20 ++++++++++++++++---- ts/receiver/opengroup.ts | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index e2c8d09a4..c08a0df60 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -93,8 +93,7 @@ export function isMessageEmpty(message: SignalService.DataMessage) { return ( !flags && - // FIXME remove this hack to drop auto friend requests messages in a few weeks 15/07/2020 - isBodyEmpty(body) && + isEmpty(body) && isEmpty(attachments) && isEmpty(group) && isEmpty(quote) && @@ -104,8 +103,21 @@ export function isMessageEmpty(message: SignalService.DataMessage) { ); } -function isBodyEmpty(body: string) { - return isEmpty(body); +/** + * Incoming sogs messages without reaction must be dropped when they are empty, so we had to separate this function and `isMessageEmpty` + */ +export function isMessageEmptyNoReaction(message: SignalService.DataMessage) { + const { flags, body, attachments, group, quote, preview, openGroupInvitation } = message; + + return ( + !flags && + isEmpty(body) && + isEmpty(attachments) && + isEmpty(group) && + isEmpty(quote) && + isEmpty(preview) && + isEmpty(openGroupInvitation) + ); } export function cleanIncomingDataMessage( diff --git a/ts/receiver/opengroup.ts b/ts/receiver/opengroup.ts index 2837bb988..524f3e111 100644 --- a/ts/receiver/opengroup.ts +++ b/ts/receiver/opengroup.ts @@ -12,7 +12,7 @@ import { removeMessagePadding } from '../session/crypto/BufferPadding'; import { UserUtils } from '../session/utils'; import { perfEnd, perfStart } from '../session/utils/Performance'; import { fromBase64ToArray } from '../session/utils/String'; -import { cleanIncomingDataMessage, isMessageEmpty } from './dataMessage'; +import { cleanIncomingDataMessage, isMessageEmptyNoReaction } from './dataMessage'; import { handleMessageJob, toRegularMessage } from './queuedJob'; export const handleOpenGroupV4Message = async ( @@ -63,7 +63,7 @@ const handleOpenGroupMessage = async ( return; } - if (isMessageEmpty(idataMessage as SignalService.DataMessage)) { + if (isMessageEmptyNoReaction(idataMessage as SignalService.DataMessage)) { // empty message, drop it window.log.info('received an empty message for sogs'); return; From 864948350379bc10118ee14d15ad1b7b32e8bb2e Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 26 Aug 2022 12:56:36 +1000 Subject: [PATCH 2/2] fix: add comments to isMessageEmptyExceptReaction and isMessageEmpty --- ts/receiver/dataMessage.ts | 35 ++++++++++++----------------------- ts/receiver/opengroup.ts | 8 +++++--- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/ts/receiver/dataMessage.ts b/ts/receiver/dataMessage.ts index c08a0df60..0e23373e8 100644 --- a/ts/receiver/dataMessage.ts +++ b/ts/receiver/dataMessage.ts @@ -79,34 +79,23 @@ function cleanAttachments(decrypted: SignalService.DataMessage) { } } -export function isMessageEmpty(message: SignalService.DataMessage) { - const { - flags, - body, - attachments, - group, - quote, - preview, - openGroupInvitation, - reaction, - } = message; +/** + * We separate the isMessageEmpty and the isMessageEmptyExceptReaction, because we + * - sometimes want to drop a message only when it is completely empty, + * - and sometimes only when the message is empty but have a reaction + */ +function isMessageEmpty(message: SignalService.DataMessage) { + const { reaction } = message; - return ( - !flags && - isEmpty(body) && - isEmpty(attachments) && - isEmpty(group) && - isEmpty(quote) && - isEmpty(preview) && - isEmpty(openGroupInvitation) && - isEmpty(reaction) - ); + return isMessageEmptyExceptReaction(message) && isEmpty(reaction); } /** - * Incoming sogs messages without reaction must be dropped when they are empty, so we had to separate this function and `isMessageEmpty` + * We separate the isMessageEmpty and the isMessageEmptyExceptReaction, because we + * - sometimes want to drop a message only when it is completely empty, + * - and sometimes only when the message is empty but have a reaction */ -export function isMessageEmptyNoReaction(message: SignalService.DataMessage) { +export function isMessageEmptyExceptReaction(message: SignalService.DataMessage) { const { flags, body, attachments, group, quote, preview, openGroupInvitation } = message; return ( diff --git a/ts/receiver/opengroup.ts b/ts/receiver/opengroup.ts index 524f3e111..87aeba6dd 100644 --- a/ts/receiver/opengroup.ts +++ b/ts/receiver/opengroup.ts @@ -12,7 +12,7 @@ import { removeMessagePadding } from '../session/crypto/BufferPadding'; import { UserUtils } from '../session/utils'; import { perfEnd, perfStart } from '../session/utils/Performance'; import { fromBase64ToArray } from '../session/utils/String'; -import { cleanIncomingDataMessage, isMessageEmptyNoReaction } from './dataMessage'; +import { cleanIncomingDataMessage, isMessageEmptyExceptReaction } from './dataMessage'; import { handleMessageJob, toRegularMessage } from './queuedJob'; export const handleOpenGroupV4Message = async ( @@ -63,9 +63,11 @@ const handleOpenGroupMessage = async ( return; } - if (isMessageEmptyNoReaction(idataMessage as SignalService.DataMessage)) { + if (isMessageEmptyExceptReaction(idataMessage as SignalService.DataMessage)) { // empty message, drop it - window.log.info('received an empty message for sogs'); + if (!idataMessage.reaction) { + window.log.info('received an empty message for sogs'); + } return; }