signal-desktop/ts/util/getQuoteBodyText.ts

31 lines
942 B
TypeScript
Raw Normal View History

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