mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 17:29:32 +01:00
Add import and tombstones for mobile coin payments.
This commit is contained in:
@@ -117,6 +117,7 @@ public interface MessageTypes {
|
||||
long SPECIAL_TYPE_REPORTED_SPAM = 0x500000000L;
|
||||
long SPECIAL_TYPE_MESSAGE_REQUEST_ACCEPTED = 0x600000000L;
|
||||
long SPECIAL_TYPE_PAYMENTS_ACTIVATED = 0x800000000L;
|
||||
long SPECIAL_TYPE_PAYMENTS_TOMBSTONE = 0x900000000L;
|
||||
|
||||
long IGNORABLE_TYPESMASK_WHEN_COUNTING = END_SESSION_BIT | KEY_EXCHANGE_IDENTITY_UPDATE_BIT | KEY_EXCHANGE_IDENTITY_VERIFIED_BIT;
|
||||
|
||||
@@ -132,6 +133,10 @@ public interface MessageTypes {
|
||||
return (type & SPECIAL_TYPES_MASK) == SPECIAL_TYPE_PAYMENTS_NOTIFICATION;
|
||||
}
|
||||
|
||||
static boolean isPaymentTombstone(long type) {
|
||||
return (type & SPECIAL_TYPES_MASK) == SPECIAL_TYPE_PAYMENTS_TOMBSTONE;
|
||||
}
|
||||
|
||||
static boolean isPaymentsRequestToActivate(long type) {
|
||||
return (type & SPECIAL_TYPES_MASK) == SPECIAL_TYPE_PAYMENTS_ACTIVATE_REQUEST;
|
||||
}
|
||||
|
||||
@@ -182,6 +182,28 @@ public final class PaymentTable extends DatabaseTable implements RecipientIdData
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public UUID restoreFromBackup(@NonNull RecipientId recipientId,
|
||||
long timestamp,
|
||||
long blockIndex,
|
||||
@NonNull String note,
|
||||
@NonNull Direction direction,
|
||||
@NonNull State state,
|
||||
@NonNull Money amount,
|
||||
@NonNull Money fee,
|
||||
@Nullable byte[] transaction,
|
||||
@Nullable byte[] receipt,
|
||||
@Nullable PaymentMetaData metaData,
|
||||
boolean seen) {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
try {
|
||||
create(uuid, recipientId, null, timestamp, blockIndex, note, direction, state, amount, fee, transaction, receipt, metaData, seen);
|
||||
} catch (SerializationException | PublicKeyConflictException e) {
|
||||
return null;
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
private void create(@NonNull UUID uuid,
|
||||
@Nullable RecipientId recipientId,
|
||||
@@ -439,7 +461,7 @@ public final class PaymentTable extends DatabaseTable implements RecipientIdData
|
||||
if (payment != null && record instanceof MmsMessageRecord) {
|
||||
return ((MmsMessageRecord) record).withPayment(payment);
|
||||
} else {
|
||||
throw new AssertionError("Payment not found for message");
|
||||
Log.w(TAG, "Payment not found for message");
|
||||
}
|
||||
}
|
||||
return record;
|
||||
|
||||
@@ -61,7 +61,7 @@ public final class ThreadBodyUtil {
|
||||
return format(EmojiStrings.GIFT, getGiftSummary(context, record), null);
|
||||
} else if (MessageRecordUtil.isStoryReaction(record)) {
|
||||
return new ThreadBody(getStoryReactionSummary(context, record));
|
||||
} else if (record.isPaymentNotification()) {
|
||||
} else if (record.isPaymentNotification() || record.isPaymentTombstone()) {
|
||||
return format(EmojiStrings.CARD, context.getString(R.string.ThreadRecord_payment), null);
|
||||
} else if (record.isPaymentsRequestToActivate()) {
|
||||
return format(EmojiStrings.CARD, getPaymentActivationRequestSummary(context, record), null);
|
||||
|
||||
@@ -229,6 +229,10 @@ public abstract class DisplayRecord {
|
||||
return MessageTypes.isPaymentsNotification(type);
|
||||
}
|
||||
|
||||
public boolean isPaymentTombstone() {
|
||||
return MessageTypes.isPaymentTombstone(type);
|
||||
}
|
||||
|
||||
public boolean isPaymentsRequestToActivate() {
|
||||
return MessageTypes.isPaymentsRequestToActivate(type);
|
||||
}
|
||||
|
||||
@@ -25,16 +25,20 @@ import org.thoughtcrime.securesms.database.MessageTypes;
|
||||
import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch;
|
||||
import org.thoughtcrime.securesms.database.documents.NetworkFailure;
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.BodyRangeList;
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.CryptoValue;
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.GiftBadge;
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.MessageExtras;
|
||||
import org.thoughtcrime.securesms.linkpreview.LinkPreview;
|
||||
import org.thoughtcrime.securesms.mms.Slide;
|
||||
import org.thoughtcrime.securesms.mms.SlideDeck;
|
||||
import org.thoughtcrime.securesms.payments.CryptoValueUtil;
|
||||
import org.thoughtcrime.securesms.payments.Payment;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.whispersystems.signalservice.api.payments.FormatterOptions;
|
||||
import org.whispersystems.signalservice.api.payments.Money;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -219,6 +223,18 @@ public class MmsMessageRecord extends MessageRecord {
|
||||
return emphasisAdded(context.getString(R.string.MessageRecord_message_encrypted_with_a_legacy_protocol_version_that_is_no_longer_supported));
|
||||
} else if (isPaymentNotification() && payment != null) {
|
||||
return new SpannableString(context.getString(R.string.MessageRecord__payment_s, payment.getAmount().toString(FormatterOptions.defaults())));
|
||||
} else if (isPaymentTombstone() || isPaymentNotification()) {
|
||||
MessageExtras extras = getMessageExtras();
|
||||
|
||||
Money amount = null;
|
||||
if (extras != null && extras.paymentTombstone != null && extras.paymentTombstone.amount != null) {
|
||||
amount = CryptoValueUtil.cryptoValueToMoney(extras.paymentTombstone.amount);
|
||||
}
|
||||
if (amount == null) {
|
||||
return new SpannableString(context.getString(R.string.MessageRecord__payment_tombstone));
|
||||
} else {
|
||||
return new SpannableString(context.getString(R.string.MessageRecord__payment_s, amount.toString(FormatterOptions.defaults())));
|
||||
}
|
||||
}
|
||||
|
||||
return super.getDisplayBody(context);
|
||||
|
||||
Reference in New Issue
Block a user