Merge pull request #2437 from Bilb/fix-drop-incoming-empty-messages

fix: make sure we drop empty messages from the main sogs pipeline
pull/2448/head
Audric Ackermann 3 years ago committed by GitHub
commit 95c7e6b152
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -79,35 +79,36 @@ function cleanAttachments(decrypted: SignalService.DataMessage) {
} }
} }
export function isMessageEmpty(message: SignalService.DataMessage) { /**
const { * We separate the isMessageEmpty and the isMessageEmptyExceptReaction, because we
flags, * - sometimes want to drop a message only when it is completely empty,
body, * - and sometimes only when the message is empty but have a reaction
attachments, */
group, function isMessageEmpty(message: SignalService.DataMessage) {
quote, const { reaction } = message;
preview,
openGroupInvitation, return isMessageEmptyExceptReaction(message) && isEmpty(reaction);
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
*/
export function isMessageEmptyExceptReaction(message: SignalService.DataMessage) {
const { flags, body, attachments, group, quote, preview, openGroupInvitation } = message;
return ( return (
!flags && !flags &&
// FIXME remove this hack to drop auto friend requests messages in a few weeks 15/07/2020 isEmpty(body) &&
isBodyEmpty(body) &&
isEmpty(attachments) && isEmpty(attachments) &&
isEmpty(group) && isEmpty(group) &&
isEmpty(quote) && isEmpty(quote) &&
isEmpty(preview) && isEmpty(preview) &&
isEmpty(openGroupInvitation) && isEmpty(openGroupInvitation)
isEmpty(reaction)
); );
} }
function isBodyEmpty(body: string) {
return isEmpty(body);
}
export function cleanIncomingDataMessage( export function cleanIncomingDataMessage(
rawDataMessage: SignalService.DataMessage, rawDataMessage: SignalService.DataMessage,
envelope?: EnvelopePlus envelope?: EnvelopePlus

@ -12,7 +12,7 @@ import { removeMessagePadding } from '../session/crypto/BufferPadding';
import { UserUtils } from '../session/utils'; import { UserUtils } from '../session/utils';
import { perfEnd, perfStart } from '../session/utils/Performance'; import { perfEnd, perfStart } from '../session/utils/Performance';
import { fromBase64ToArray } from '../session/utils/String'; import { fromBase64ToArray } from '../session/utils/String';
import { cleanIncomingDataMessage, isMessageEmpty } from './dataMessage'; import { cleanIncomingDataMessage, isMessageEmptyExceptReaction } from './dataMessage';
import { handleMessageJob, toRegularMessage } from './queuedJob'; import { handleMessageJob, toRegularMessage } from './queuedJob';
export const handleOpenGroupV4Message = async ( export const handleOpenGroupV4Message = async (
@ -63,9 +63,11 @@ const handleOpenGroupMessage = async (
return; return;
} }
if (isMessageEmpty(idataMessage as SignalService.DataMessage)) { if (isMessageEmptyExceptReaction(idataMessage as SignalService.DataMessage)) {
// empty message, drop it // 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; return;
} }

Loading…
Cancel
Save