Filter incoming bodyRanges, also filter before display

This commit is contained in:
Scott Nonnenberg 2023-04-11 17:16:46 -07:00 committed by GitHub
parent ec1246f60a
commit 4c9baaef80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 84 additions and 126 deletions

View file

@ -125,6 +125,7 @@ import { chunk } from '../util/iterables';
import { isOlderThan } from '../util/timestamp';
import { inspectUnknownFieldTags } from '../util/inspectProtobufs';
import { incrementMessageCounter } from '../util/incrementMessageCounter';
import { filterAndClean } from '../types/BodyRange';
const GROUPV1_ID_LENGTH = 16;
const GROUPV2_ID_LENGTH = 32;
@ -2121,8 +2122,8 @@ export default class MessageReceiver
const message: ProcessedDataMessage = {
attachments,
// We need to remove all of the extra stuff on these objects so serialize properly
bodyRanges: msg.bodyRanges?.map(item => ({ ...item })),
bodyRanges: filterAndClean(msg.bodyRanges),
preview,
canReplyToStory: Boolean(msg.allowsReplies),
expireTimer: DurationInSeconds.DAY,

View file

@ -9,6 +9,7 @@ import type { GiftBadgeStates } from '../components/conversation/Message';
import type { MIMEType } from '../types/MIME';
import type { DurationInSeconds } from '../util/durations';
import type { AnyPaymentEvent } from '../types/Payment';
import type { RawBodyRange } from '../types/BodyRange';
export {
IdentityKeyType,
@ -150,7 +151,7 @@ export type ProcessedQuote = {
authorUuid?: string;
text?: string;
attachments: ReadonlyArray<ProcessedQuoteAttachment>;
bodyRanges: ReadonlyArray<ProcessedBodyRange>;
bodyRanges?: ReadonlyArray<ProcessedBodyRange>;
type: Proto.DataMessage.Quote.Type;
};
@ -190,7 +191,7 @@ export type ProcessedDelete = {
targetSentTimestamp?: number;
};
export type ProcessedBodyRange = Proto.DataMessage.IBodyRange;
export type ProcessedBodyRange = RawBodyRange;
export type ProcessedGroupCallUpdate = Proto.DataMessage.IGroupCallUpdate;

View file

@ -31,6 +31,7 @@ import { APPLICATION_OCTET_STREAM, stringToMIMEType } from '../types/MIME';
import { SECOND, DurationInSeconds } from '../util/durations';
import type { AnyPaymentEvent } from '../types/Payment';
import { PaymentEventKind } from '../types/Payment';
import { filterAndClean } from '../types/BodyRange';
const FLAGS = Proto.DataMessage.Flags;
export const ATTACHMENT_MAX = 32;
@ -175,8 +176,7 @@ export function processQuote(
thumbnail: processAttachment(attachment.thumbnail),
};
}),
// We need to remove all of the extra stuff on these objects so serialize properly
bodyRanges: quote.bodyRanges?.map(item => ({ ...item })) ?? [],
bodyRanges: filterAndClean(quote.bodyRanges),
type: quote.type || Proto.DataMessage.Quote.Type.NORMAL,
};
}
@ -349,8 +349,7 @@ export function processDataMessage(
isViewOnce: Boolean(message.isViewOnce),
reaction: processReaction(message.reaction),
delete: processDelete(message.delete),
// We need to remove all of the extra stuff on these objects so serialize properly
bodyRanges: message.bodyRanges?.map(item => ({ ...item })) ?? [],
bodyRanges: filterAndClean(message.bodyRanges),
groupCallUpdate: dropNull(message.groupCallUpdate),
storyContext: dropNull(message.storyContext),
giftBadge: processGiftBadge(message.giftBadge),