Init payments message types

This commit is contained in:
Jamie Kyle 2022-11-30 13:47:54 -08:00 committed by GitHub
parent 0c4b52a125
commit 6198b02640
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 741 additions and 185 deletions

View file

@ -9,6 +9,10 @@ import type {
QuotedMessageType,
} from '../model-types.d';
import type { UUIDStringType } from '../types/UUID';
import { PaymentEventKind } from '../types/Payment';
import type { AnyPaymentEvent } from '../types/Payment';
import type { LocalizerType } from '../types/Util';
import { missingCaseError } from '../util/missingCaseError';
export function isIncoming(
message: Pick<MessageAttributesType, 'type'>
@ -26,6 +30,84 @@ export function isStory(message: Pick<MessageAttributesType, 'type'>): boolean {
return message.type === 'story';
}
export type MessageAttributesWithPaymentEvent = MessageAttributesType & {
payment: AnyPaymentEvent;
};
export function messageHasPaymentEvent(
message: MessageAttributesType
): message is MessageAttributesWithPaymentEvent {
return message.payment != null;
}
export function getPaymentEventNotificationText(
payment: AnyPaymentEvent,
senderTitle: string,
conversationTitle: string | null,
senderIsMe: boolean,
i18n: LocalizerType
): string {
if (payment.kind === PaymentEventKind.Notification) {
return i18n('icu:payment-event-notification-label');
}
return getPaymentEventDescription(
payment,
senderTitle,
conversationTitle,
senderIsMe,
i18n
);
}
export function getPaymentEventDescription(
payment: AnyPaymentEvent,
senderTitle: string,
conversationTitle: string | null,
senderIsMe: boolean,
i18n: LocalizerType
): string {
const { kind } = payment;
if (kind === PaymentEventKind.Notification) {
if (senderIsMe) {
if (conversationTitle != null) {
return i18n('icu:payment-event-notification-message-you-label', {
receiver: conversationTitle,
});
}
return i18n(
'icu:payment-event-notification-message-you-label-without-receiver'
);
}
return i18n('icu:payment-event-notification-message-label', {
sender: senderTitle,
});
}
if (kind === PaymentEventKind.ActivationRequest) {
if (senderIsMe) {
if (conversationTitle != null) {
return i18n('icu:payment-event-activation-request-you-label', {
receiver: conversationTitle,
});
}
return i18n(
'icu:payment-event-activation-request-you-label-without-receiver'
);
}
return i18n('icu:payment-event-activation-request-label', {
sender: senderTitle,
});
}
if (kind === PaymentEventKind.Activation) {
if (senderIsMe) {
return i18n('icu:payment-event-activated-you-label');
}
return i18n('icu:payment-event-activated-label', {
sender: senderTitle,
});
}
throw missingCaseError(kind);
}
export function isQuoteAMatch(
message: MessageAttributesType | null | undefined,
conversationId: string,