Skip to content

Commit

Permalink
Update sender key flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal authored and alex-signal committed Aug 5, 2021
1 parent 784c373 commit 2b5b664
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class MessageSendLogDatabase constructor(context: Context?, databaseHelper: SQLC

/** @return The ID of the inserted entry, or -1 if none was inserted. Can be used with [addRecipientToExistingEntryIfPossible] */
fun insertIfPossible(recipientId: RecipientId, sentTimestamp: Long, sendMessageResult: SendMessageResult, contentHint: ContentHint, messageId: MessageId): Long {
if (!FeatureFlags.senderKey()) return -1
if (!FeatureFlags.retryReceipts()) return -1

if (sendMessageResult.isSuccess && sendMessageResult.success.content.isPresent) {
val recipientDevice = listOf(RecipientDevice(recipientId, sendMessageResult.success.devices))
Expand All @@ -162,7 +162,7 @@ class MessageSendLogDatabase constructor(context: Context?, databaseHelper: SQLC

/** @return The ID of the inserted entry, or -1 if none was inserted. Can be used with [addRecipientToExistingEntryIfPossible] */
fun insertIfPossible(recipientId: RecipientId, sentTimestamp: Long, sendMessageResult: SendMessageResult, contentHint: ContentHint, messageIds: List<MessageId>): Long {
if (!FeatureFlags.senderKey()) return -1
if (!FeatureFlags.retryReceipts()) return -1

if (sendMessageResult.isSuccess && sendMessageResult.success.content.isPresent) {
val recipientDevice = listOf(RecipientDevice(recipientId, sendMessageResult.success.devices))
Expand All @@ -174,7 +174,7 @@ class MessageSendLogDatabase constructor(context: Context?, databaseHelper: SQLC

/** @return The ID of the inserted entry, or -1 if none was inserted. Can be used with [addRecipientToExistingEntryIfPossible] */
fun insertIfPossible(sentTimestamp: Long, possibleRecipients: List<Recipient>, results: List<SendMessageResult>, contentHint: ContentHint, messageId: MessageId): Long {
if (!FeatureFlags.senderKey()) return -1
if (!FeatureFlags.retryReceipts()) return -1

val accessList = RecipientAccessList(possibleRecipients)

Expand All @@ -195,7 +195,7 @@ class MessageSendLogDatabase constructor(context: Context?, databaseHelper: SQLC
}

fun addRecipientToExistingEntryIfPossible(payloadId: Long, recipientId: RecipientId, sendMessageResult: SendMessageResult) {
if (!FeatureFlags.senderKey()) return
if (!FeatureFlags.retryReceipts()) return

if (sendMessageResult.isSuccess && sendMessageResult.success.content.isPresent) {
val db = databaseHelper.writableDatabase
Expand Down Expand Up @@ -262,7 +262,7 @@ class MessageSendLogDatabase constructor(context: Context?, databaseHelper: SQLC
}

fun getLogEntry(recipientId: RecipientId, device: Int, dateSent: Long): MessageLogEntry? {
if (!FeatureFlags.senderKey()) return null
if (!FeatureFlags.retryReceipts()) return null

trimOldMessages(System.currentTimeMillis(), FeatureFlags.retryRespondMaxAge())

Expand Down Expand Up @@ -302,7 +302,7 @@ class MessageSendLogDatabase constructor(context: Context?, databaseHelper: SQLC
}

fun deleteAllRelatedToMessage(messageId: Long, mms: Boolean) {
if (!FeatureFlags.senderKey()) return
if (!FeatureFlags.retryReceipts()) return

val db = databaseHelper.writableDatabase
val query = "${PayloadTable.ID} IN (SELECT ${MessageTable.PAYLOAD_ID} FROM ${MessageTable.TABLE_NAME} WHERE ${MessageTable.MESSAGE_ID} = ? AND ${MessageTable.IS_MMS} = ?)"
Expand All @@ -312,13 +312,13 @@ class MessageSendLogDatabase constructor(context: Context?, databaseHelper: SQLC
}

fun deleteEntryForRecipient(dateSent: Long, recipientId: RecipientId, device: Int) {
if (!FeatureFlags.senderKey()) return
if (!FeatureFlags.retryReceipts()) return

deleteEntriesForRecipient(listOf(dateSent), recipientId, device)
}

fun deleteEntriesForRecipient(dateSent: List<Long>, recipientId: RecipientId, device: Int) {
if (!FeatureFlags.senderKey()) return
if (!FeatureFlags.retryReceipts()) return

val db = databaseHelper.writableDatabase

Expand Down Expand Up @@ -346,13 +346,13 @@ class MessageSendLogDatabase constructor(context: Context?, databaseHelper: SQLC
}

fun deleteAll() {
if (!FeatureFlags.senderKey()) return
if (!FeatureFlags.retryReceipts()) return

databaseHelper.writableDatabase.delete(PayloadTable.TABLE_NAME, null, null)
}

fun trimOldMessages(currentTime: Long, maxAge: Long) {
if (!FeatureFlags.senderKey()) return
if (!FeatureFlags.retryReceipts()) return

val db = databaseHelper.writableDatabase
val query = "${PayloadTable.DATE_SENT} < ?"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PendingRetryReceiptCache @VisibleForTesting constructor(
private var populated: Boolean = false

fun insert(author: RecipientId, authorDevice: Int, sentTimestamp: Long, receivedTimestamp: Long, threadId: Long) {
if (!FeatureFlags.senderKey()) return
if (!FeatureFlags.retryReceipts()) return
ensurePopulated()

synchronized(pendingRetries) {
Expand All @@ -33,7 +33,7 @@ class PendingRetryReceiptCache @VisibleForTesting constructor(
}

fun get(author: RecipientId, sentTimestamp: Long): PendingRetryReceiptModel? {
if (!FeatureFlags.senderKey()) return null
if (!FeatureFlags.retryReceipts()) return null
ensurePopulated()

synchronized(pendingRetries) {
Expand All @@ -42,7 +42,7 @@ class PendingRetryReceiptCache @VisibleForTesting constructor(
}

fun getOldest(): PendingRetryReceiptModel? {
if (!FeatureFlags.senderKey()) return null
if (!FeatureFlags.retryReceipts()) return null
ensurePopulated()

synchronized(pendingRetries) {
Expand All @@ -51,7 +51,7 @@ class PendingRetryReceiptCache @VisibleForTesting constructor(
}

fun delete(model: PendingRetryReceiptModel) {
if (!FeatureFlags.senderKey()) return
if (!FeatureFlags.retryReceipts()) return
ensurePopulated()

synchronized(pendingRetries) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1787,8 +1787,8 @@ private void handleTypingMessage(@NonNull SignalServiceContent content,
}

private void handleRetryReceipt(@NonNull SignalServiceContent content, @NonNull DecryptionErrorMessage decryptionErrorMessage, @NonNull Recipient senderRecipient) {
if (!FeatureFlags.senderKey()) {
warn(String.valueOf(content.getTimestamp()), "[RetryReceipt] Sender key not enabled, skipping retry receipt.");
if (!FeatureFlags.retryReceipts()) {
warn(String.valueOf(content.getTimestamp()), "[RetryReceipt] Feature flag disabled, skipping retry receipt.");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private MessageDecryptionUtil() {}
Log.w(TAG, String.valueOf(envelope.getTimestamp()), e);
Recipient sender = Recipient.external(context, e.getSender());

if (sender.supportsMessageRetries() && Recipient.self().supportsMessageRetries() && FeatureFlags.senderKey()) {
if (sender.supportsMessageRetries() && Recipient.self().supportsMessageRetries() && FeatureFlags.retryReceipts()) {
jobs.add(handleRetry(context, sender, envelope, e));
postInternalErrorNotification(context);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public final class FeatureFlags {
private static final String MEDIA_QUALITY_LEVELS = "android.mediaQuality.levels";
private static final String RETRY_RECEIPT_LIFESPAN = "android.retryReceiptLifespan";
private static final String RETRY_RESPOND_MAX_AGE = "android.retryRespondMaxAge";
private static final String SENDER_KEY = "android.senderKey.3";
private static final String SENDER_KEY = "android.senderKey.4";
private static final String RETRY_RECEIPTS = "android.retryReceipts";
private static final String SUGGEST_SMS_BLACKLIST = "android.suggestSmsBlacklist";
private static final String ANNOUNCEMENT_GROUPS = "android.announcementGroups";

Expand Down Expand Up @@ -114,6 +115,7 @@ public final class FeatureFlags {
RETRY_RECEIPT_LIFESPAN,
RETRY_RESPOND_MAX_AGE,
SENDER_KEY,
RETRY_RECEIPTS,
SUGGEST_SMS_BLACKLIST,
ANNOUNCEMENT_GROUPS
);
Expand Down Expand Up @@ -162,7 +164,9 @@ public final class FeatureFlags {
MEDIA_QUALITY_LEVELS,
RETRY_RECEIPT_LIFESPAN,
RETRY_RESPOND_MAX_AGE,
SUGGEST_SMS_BLACKLIST
SUGGEST_SMS_BLACKLIST,
RETRY_RECEIPTS,
SENDER_KEY
);

/**
Expand Down Expand Up @@ -349,6 +353,11 @@ public static boolean mp4GifSendSupport() {
return getString(MEDIA_QUALITY_LEVELS, "");
}

/** Whether or not sending or responding to retry receipts is enabled. */
public static boolean retryReceipts() {
return getBoolean(RETRY_RECEIPTS, false);
}

/** How long to wait before considering a retry to be a failure. */
public static long retryReceiptLifespan() {
return getLong(RETRY_RECEIPT_LIFESPAN, TimeUnit.HOURS.toMillis(1));
Expand Down

0 comments on commit 2b5b664

Please sign in to comment.