mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-20 16:49:40 +01:00
Add pre-alpha receive support for remote delete.
This commit is contained in:
@@ -55,6 +55,7 @@ public final class FeatureFlags {
|
||||
private static final String PINS_MEGAPHONE_KILL_SWITCH = "android.pinsMegaphoneKillSwitch";
|
||||
private static final String PROFILE_NAMES_MEGAPHONE = "android.profileNamesMegaphone";
|
||||
private static final String ATTACHMENTS_V3 = "android.attachmentsV3";
|
||||
private static final String REMOTE_DELETE = "android.remoteDelete";
|
||||
|
||||
/**
|
||||
* We will only store remote values for flags in this set. If you want a flag to be controllable
|
||||
@@ -68,7 +69,8 @@ public final class FeatureFlags {
|
||||
PINS_MEGAPHONE_KILL_SWITCH,
|
||||
PROFILE_NAMES_MEGAPHONE,
|
||||
MESSAGE_REQUESTS,
|
||||
ATTACHMENTS_V3
|
||||
ATTACHMENTS_V3,
|
||||
REMOTE_DELETE
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -218,6 +220,11 @@ public final class FeatureFlags {
|
||||
return getValue(ATTACHMENTS_V3, false);
|
||||
}
|
||||
|
||||
/** Send support for remotely deleting a message. */
|
||||
public static boolean remoteDelete() {
|
||||
return getValue(REMOTE_DELETE, false);
|
||||
}
|
||||
|
||||
/** Only for rendering debug info. */
|
||||
public static synchronized @NonNull Map<String, Boolean> getMemoryValues() {
|
||||
return new TreeMap<>(REMOTE_VALUES);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class RemoteDeleteUtil {
|
||||
|
||||
private static final long RECEIVE_THRESHOLD = TimeUnit.DAYS.toMillis(1);
|
||||
private static final long SEND_THRESHOLD = TimeUnit.MINUTES.toMillis(30);
|
||||
|
||||
private RemoteDeleteUtil() {}
|
||||
|
||||
public static boolean isValidReceive(@NonNull MessageRecord targetMessage, @NonNull Recipient deleteSender, long deleteServerTimestamp) {
|
||||
boolean isValidSender = (deleteSender.isLocalNumber() && targetMessage.isOutgoing()) ||
|
||||
(!deleteSender.isLocalNumber() && !targetMessage.isOutgoing());
|
||||
|
||||
return isValidSender &&
|
||||
targetMessage.getIndividualRecipient().equals(deleteSender) &&
|
||||
(deleteServerTimestamp - targetMessage.getServerTimestamp()) < RECEIVE_THRESHOLD;
|
||||
}
|
||||
|
||||
public static boolean isValidSend(@NonNull Collection<MessageRecord> targetMessages, long currentTime) {
|
||||
// TODO [greyson] [remote-delete] Update with server timestamp when available for outgoing messages
|
||||
return Stream.of(targetMessages)
|
||||
.allMatch(message -> message.isOutgoing() &&
|
||||
!message.isRemoteDelete() &&
|
||||
!message.isPending() &&
|
||||
(currentTime - message.getDateSent()) < SEND_THRESHOLD);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user