MCPcopy
hub / github.com/signalapp/Signal-Desktop / processDataMessage

Function processDataMessage

ts/textsecure/processDataMessage.preload.ts:511–629  ·  view source on GitHub ↗
(
  message: Proto.DataMessage,
  envelopeTimestamp: number,

  // Only for testing
  { _createName: doCreateName = createName } = {}
)

Source from the content-addressed store, hash-verified

509}
510
511export function processDataMessage(
512 message: Proto.DataMessage,
513 envelopeTimestamp: number,
514
515 // Only for testing
516 { _createName: doCreateName = createName } = {}
517): ProcessedDataMessage {
518 // Now that its decrypted, validate the message and clean it up for consumer
519 // processing
520 // Note that messages may (generally) only perform one action and we ignore remaining
521 // fields after the first action.
522
523 if (!message.timestamp) {
524 throw new Error('Missing timestamp on dataMessage');
525 }
526
527 const timestamp = toNumber(message.timestamp);
528
529 if (envelopeTimestamp !== timestamp) {
530 throw new Error(
531 `Timestamp ${timestamp} in DataMessage did not ` +
532 `match envelope timestamp ${envelopeTimestamp}`
533 );
534 }
535
536 const processedAttachments = message.attachments
537 ?.map((attachment: Proto.AttachmentPointer) => ({
538 ...processAttachment(attachment),
539 downloadPath: doCreateName(),
540 }))
541 .filter(isNotNil);
542
543 const { bodyAttachment, attachments } = partitionBodyAndNormalAttachments(
544 { attachments: processedAttachments ?? [] },
545 { logId: `processDataMessage(${timestamp})` }
546 );
547
548 const result: ProcessedDataMessage = {
549 body: message.body ?? '',
550 bodyAttachment,
551 attachments,
552 groupV2: processGroupV2Context(message.groupV2),
553 flags: message.flags ?? 0,
554 expireTimer: DurationInSeconds.fromSeconds(message.expireTimer ?? 0),
555 expireTimerVersion: message.expireTimerVersion ?? 0,
556 profileKey:
557 message.profileKey && message.profileKey.length > 0
558 ? Bytes.toBase64(message.profileKey)
559 : undefined,
560 timestamp,
561 payment: processPayment(message.payment),
562 quote: processQuote(message.quote),
563 contact: processContact(message.contact),
564 preview: processPreview(message.preview),
565 sticker: processSticker(message.sticker),
566 requiredProtocolVersion: message.requiredProtocolVersion ?? 0,
567 isViewOnce: Boolean(message.isViewOnce),
568 reaction: processReaction(message.reaction),

Callers 2

#processDecryptedMethod · 0.90
checkFunction · 0.90

Calls 15

toNumberFunction · 0.90
filterAndCleanFunction · 0.90
dropNullFunction · 0.90
assertDevFunction · 0.90
processGroupV2ContextFunction · 0.85
processPaymentFunction · 0.85
processQuoteFunction · 0.85
processContactFunction · 0.85
processPreviewFunction · 0.85
processReactionFunction · 0.85
processPinMessageFunction · 0.85

Tested by

no test coverage detected