Improve quoted attachment typings

This commit is contained in:
trevor-signal 2024-05-23 17:06:41 -04:00 committed by GitHub
parent 38226115a4
commit 5f0080a7d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 98 additions and 97 deletions

View file

@ -26,9 +26,13 @@ import type { AnyPaymentEvent } from '../../types/Payment';
import { PaymentEventKind } from '../../types/Payment';
import { getPaymentEventNotificationText } from '../../messages/helpers';
import { RenderLocation } from './MessageTextRenderer';
import type { QuotedAttachmentType } from '../../model-types';
const EMPTY_OBJECT = Object.freeze(Object.create(null));
export type QuotedAttachmentForUIType = QuotedAttachmentType &
Pick<AttachmentType, 'isVoiceMessage' | 'fileName' | 'textAttachment'>;
export type Props = {
authorTitle: string;
conversationColor: ConversationColorType;
@ -44,7 +48,7 @@ export type Props = {
onClick?: () => void;
onClose?: () => void;
text: string;
rawAttachment?: QuotedAttachmentType;
rawAttachment?: QuotedAttachmentForUIType;
payment?: AnyPaymentEvent;
isGiftBadge: boolean;
isViewOnce: boolean;
@ -53,11 +57,6 @@ export type Props = {
doubleCheckMissingQuoteReference?: () => unknown;
};
export type QuotedAttachmentType = Pick<
AttachmentType,
'contentType' | 'fileName' | 'isVoiceMessage' | 'thumbnail' | 'textAttachment'
>;
function validateQuote(quote: Props): boolean {
if (
quote.isStoryReply &&
@ -86,9 +85,9 @@ function validateQuote(quote: Props): boolean {
}
// Long message attachments should not be shown.
function getAttachment(
rawAttachment: undefined | QuotedAttachmentType
): undefined | QuotedAttachmentType {
function getAttachment<T extends Pick<QuotedAttachmentType, 'contentType'>>(
rawAttachment: T | undefined
): T | undefined {
return rawAttachment && !MIME.isLongMessage(rawAttachment.contentType)
? rawAttachment
: undefined;