mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-24 21:15:48 +00:00
Add in-chat payment activation requests.
Co-authored-by: Varsha <varsha@mobilecoin.com>
This commit is contained in:
@@ -1028,8 +1028,11 @@ public class SignalServiceMessageSender {
|
||||
.setMobileCoin(mobileCoinPayment);
|
||||
|
||||
builder.setPayment(DataMessage.Payment.newBuilder().setNotification(paymentBuilder));
|
||||
builder.setRequiredProtocolVersion(Math.max(DataMessage.ProtocolVersion.PAYMENTS_VALUE, builder.getRequiredProtocolVersion()));
|
||||
} else if (payment.getPaymentActivation().isPresent()) {
|
||||
DataMessage.Payment.Activation.Builder activationBuilder = DataMessage.Payment.Activation.newBuilder().setType(payment.getPaymentActivation().get().getType());
|
||||
builder.setPayment(DataMessage.Payment.newBuilder().setActivation(activationBuilder));
|
||||
}
|
||||
builder.setRequiredProtocolVersion(Math.max(DataMessage.ProtocolVersion.PAYMENTS_VALUE, builder.getRequiredProtocolVersion()));
|
||||
}
|
||||
|
||||
if (message.getStoryContext().isPresent()) {
|
||||
|
||||
@@ -1240,8 +1240,12 @@ public final class SignalServiceContent {
|
||||
SignalServiceProtos.DataMessage.Payment payment = content.getPayment();
|
||||
|
||||
switch (payment.getItemCase()) {
|
||||
case NOTIFICATION: return new SignalServiceDataMessage.Payment(createPaymentNotification(payment));
|
||||
default : throw new InvalidMessageStructureException("Unknown payment item");
|
||||
case NOTIFICATION:
|
||||
return new SignalServiceDataMessage.Payment(createPaymentNotification(payment), null);
|
||||
case ACTIVATION:
|
||||
return new SignalServiceDataMessage.Payment(null, createPaymentActivation(payment));
|
||||
default:
|
||||
throw new InvalidMessageStructureException("Unknown payment item");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1290,6 +1294,20 @@ public final class SignalServiceContent {
|
||||
return new SignalServiceDataMessage.PaymentNotification(payment.getMobileCoin().getReceipt().toByteArray(), payment.getNote());
|
||||
}
|
||||
|
||||
private static SignalServiceDataMessage.PaymentActivation createPaymentActivation(SignalServiceProtos.DataMessage.Payment content)
|
||||
throws InvalidMessageStructureException
|
||||
{
|
||||
if (!content.hasActivation() ||
|
||||
content.getItemCase() != SignalServiceProtos.DataMessage.Payment.ItemCase.ACTIVATION)
|
||||
{
|
||||
throw new InvalidMessageStructureException("Badly-formatted payment activation!");
|
||||
}
|
||||
|
||||
SignalServiceProtos.DataMessage.Payment.Activation payment = content.getActivation();
|
||||
|
||||
return new SignalServiceDataMessage.PaymentActivation(payment.getType());
|
||||
}
|
||||
|
||||
private static List<SharedContact> createSharedContacts(SignalServiceProtos.DataMessage content) throws InvalidMessageStructureException {
|
||||
if (content.getContactCount() <= 0) return null;
|
||||
|
||||
|
||||
@@ -161,6 +161,18 @@ public class SignalServiceDataMessage {
|
||||
return expirationUpdate;
|
||||
}
|
||||
|
||||
public boolean isActivatePaymentsRequest() {
|
||||
return getPayment().isPresent() &&
|
||||
getPayment().get().getPaymentActivation().isPresent() &&
|
||||
getPayment().get().getPaymentActivation().get().getType().equals(SignalServiceProtos.DataMessage.Payment.Activation.Type.REQUEST);
|
||||
}
|
||||
|
||||
public boolean isPaymentsActivated() {
|
||||
return getPayment().isPresent() &&
|
||||
getPayment().get().getPaymentActivation().isPresent() &&
|
||||
getPayment().get().getPaymentActivation().get().getType().equals(SignalServiceProtos.DataMessage.Payment.Activation.Type.ACTIVATED);
|
||||
}
|
||||
|
||||
public boolean isProfileKeyUpdate() {
|
||||
return profileKeyUpdate;
|
||||
}
|
||||
@@ -655,16 +667,34 @@ public class SignalServiceDataMessage {
|
||||
}
|
||||
}
|
||||
|
||||
public static class PaymentActivation {
|
||||
private final SignalServiceProtos.DataMessage.Payment.Activation.Type type;
|
||||
|
||||
public PaymentActivation(SignalServiceProtos.DataMessage.Payment.Activation.Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public SignalServiceProtos.DataMessage.Payment.Activation.Type getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Payment {
|
||||
private final Optional<PaymentNotification> paymentNotification;
|
||||
private final Optional<PaymentActivation> paymentActivation;
|
||||
|
||||
public Payment(PaymentNotification paymentNotification) {
|
||||
this.paymentNotification = Optional.of(paymentNotification);
|
||||
public Payment(PaymentNotification paymentNotification, PaymentActivation paymentActivation) {
|
||||
this.paymentNotification = Optional.ofNullable(paymentNotification);
|
||||
this.paymentActivation = Optional.ofNullable(paymentActivation);
|
||||
}
|
||||
|
||||
public Optional<PaymentNotification> getPaymentNotification() {
|
||||
return paymentNotification;
|
||||
}
|
||||
|
||||
public Optional<PaymentActivation> getPaymentActivation() {
|
||||
return paymentActivation;
|
||||
}
|
||||
}
|
||||
|
||||
public static class StoryContext {
|
||||
|
||||
@@ -292,8 +292,18 @@ message DataMessage {
|
||||
optional string note = 2;
|
||||
}
|
||||
|
||||
message Activation {
|
||||
enum Type {
|
||||
REQUEST = 0;
|
||||
ACTIVATED = 1;
|
||||
}
|
||||
|
||||
optional Type type = 1;
|
||||
}
|
||||
|
||||
oneof Item {
|
||||
Notification notification = 1;
|
||||
Activation activation = 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user