2023-03-27 23:48:57 +00:00
|
|
|
// Copyright 2023 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2024-07-24 20:14:11 +00:00
|
|
|
import type { ReadonlyMessageAttributesType } from '../model-types.d';
|
2023-03-27 23:48:57 +00:00
|
|
|
import * as EmbeddedContact from '../types/EmbeddedContact';
|
|
|
|
|
|
|
|
export function getQuoteBodyText(
|
2024-07-24 20:14:11 +00:00
|
|
|
messageAttributes: ReadonlyMessageAttributesType,
|
2023-03-27 23:48:57 +00:00
|
|
|
id: number
|
|
|
|
): string | undefined {
|
|
|
|
const storyReactionEmoji = messageAttributes.storyReaction?.emoji;
|
|
|
|
|
|
|
|
const { editHistory } = messageAttributes;
|
|
|
|
const editedMessage =
|
|
|
|
editHistory && editHistory.find(edit => edit.timestamp === id);
|
|
|
|
|
|
|
|
if (editedMessage && editedMessage.body) {
|
|
|
|
return editedMessage.body;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { body, contact: embeddedContact } = messageAttributes;
|
|
|
|
const embeddedContactName =
|
|
|
|
embeddedContact && embeddedContact.length > 0
|
|
|
|
? EmbeddedContact.getName(embeddedContact[0])
|
|
|
|
: '';
|
|
|
|
|
|
|
|
return body || embeddedContactName || storyReactionEmoji;
|
|
|
|
}
|