fix: add comments to isMessageEmptyExceptReaction and isMessageEmpty

pull/2437/head
Audric Ackermann 3 years ago
parent 4a3d970a35
commit 8649483503

@ -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 (

@ -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;
}

Loading…
Cancel
Save