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

@ -29,6 +29,8 @@ import { WarnOnlyError } from './Errors';
import { GiftBadgeStates } from '../components/conversation/Message';
import { APPLICATION_OCTET_STREAM, stringToMIMEType } from '../types/MIME';
import { SECOND, DurationInSeconds } from '../util/durations';
import type { AnyPaymentEvent } from '../types/Payment';
import { PaymentEventKind } from '../types/Payment';
const FLAGS = Proto.DataMessage.Flags;
export const ATTACHMENT_MAX = 32;
@ -123,6 +125,38 @@ export function processGroupV2Context(
};
}
export function processPayment(
payment?: Proto.DataMessage.IPayment | null
): AnyPaymentEvent | undefined {
if (!payment) {
return undefined;
}
if (payment.notification != null) {
return {
kind: PaymentEventKind.Notification,
note: payment.notification.note ?? null,
};
}
if (payment.activation != null) {
if (
payment.activation.type ===
Proto.DataMessage.Payment.Activation.Type.REQUEST
) {
return { kind: PaymentEventKind.ActivationRequest };
}
if (
payment.activation.type ===
Proto.DataMessage.Payment.Activation.Type.ACTIVATED
) {
return { kind: PaymentEventKind.Activation };
}
}
return undefined;
}
export function processQuote(
quote?: Proto.DataMessage.IQuote | null
): ProcessedQuote | undefined {
@ -305,6 +339,7 @@ export function processDataMessage(
? Bytes.toBase64(message.profileKey)
: undefined,
timestamp,
payment: processPayment(message.payment),
quote: processQuote(message.quote),
contact: processContact(message.contact),
preview: processPreview(message.preview),