Put poll receive support behind feature flag.

This commit is contained in:
Michelle Tang
2025-10-09 15:31:07 -04:00
committed by Alex Hart
parent f9ddba5aed
commit 7de9218b80
4 changed files with 38 additions and 0 deletions

View File

@@ -4,6 +4,8 @@ import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import assertk.assertThat import assertk.assertThat
import assertk.assertions.isEqualTo import assertk.assertions.isEqualTo
import io.mockk.every
import io.mockk.mockkStatic
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
@@ -20,6 +22,7 @@ import org.thoughtcrime.securesms.testing.GroupTestingUtils
import org.thoughtcrime.securesms.testing.GroupTestingUtils.asMember import org.thoughtcrime.securesms.testing.GroupTestingUtils.asMember
import org.thoughtcrime.securesms.testing.MessageContentFuzzer import org.thoughtcrime.securesms.testing.MessageContentFuzzer
import org.thoughtcrime.securesms.testing.SignalActivityRule import org.thoughtcrime.securesms.testing.SignalActivityRule
import org.thoughtcrime.securesms.util.RemoteConfig
import org.whispersystems.signalservice.api.crypto.EnvelopeMetadata import org.whispersystems.signalservice.api.crypto.EnvelopeMetadata
import org.whispersystems.signalservice.internal.push.DataMessage import org.whispersystems.signalservice.internal.push.DataMessage
@@ -38,6 +41,10 @@ class DataMessageProcessorTest_polls {
@Before @Before
fun setUp() { fun setUp() {
mockkStatic(RemoteConfig::class)
every { RemoteConfig.receivePolls } returns true
alice = Recipient.resolved(harness.others[0]) alice = Recipient.resolved(harness.others[0])
bob = Recipient.resolved(harness.others[1]) bob = Recipient.resolved(harness.others[1])
charlie = Recipient.resolved(harness.others[2]) charlie = Recipient.resolved(harness.others[2])

View File

@@ -1056,6 +1056,11 @@ object DataMessageProcessor {
groupId: GroupId.V2?, groupId: GroupId.V2?,
receivedTime: Long receivedTime: Long
): InsertResult? { ): InsertResult? {
if (!RemoteConfig.receivePolls) {
log(envelope.timestamp!!, "Poll creation not allowed due to remote config.")
return null
}
log(envelope.timestamp!!, "Handle poll creation") log(envelope.timestamp!!, "Handle poll creation")
val poll: DataMessage.PollCreate = message.pollCreate!! val poll: DataMessage.PollCreate = message.pollCreate!!
@@ -1111,6 +1116,11 @@ object DataMessageProcessor {
groupId: GroupId.V2?, groupId: GroupId.V2?,
receivedTime: Long receivedTime: Long
): InsertResult? { ): InsertResult? {
if (!RemoteConfig.receivePolls) {
log(envelope.timestamp!!, "Poll terminate not allowed due to remote config.")
return null
}
val pollTerminate: DataMessage.PollTerminate = message.pollTerminate!! val pollTerminate: DataMessage.PollTerminate = message.pollTerminate!!
val targetSentTimestamp = pollTerminate.targetSentTimestamp!! val targetSentTimestamp = pollTerminate.targetSentTimestamp!!
@@ -1159,6 +1169,11 @@ object DataMessageProcessor {
senderRecipient: Recipient, senderRecipient: Recipient,
earlyMessageCacheEntry: EarlyMessageCacheEntry? earlyMessageCacheEntry: EarlyMessageCacheEntry?
): MessageId? { ): MessageId? {
if (!RemoteConfig.receivePolls) {
log(envelope.timestamp!!, "Poll vote not allowed due to remote config.")
return null
}
val pollVote: DataMessage.PollVote = message.pollVote!! val pollVote: DataMessage.PollVote = message.pollVote!!
val targetSentTimestamp = pollVote.targetSentTimestamp!! val targetSentTimestamp = pollVote.targetSentTimestamp!!

View File

@@ -102,6 +102,7 @@ import org.thoughtcrime.securesms.util.EarlyMessageCacheEntry
import org.thoughtcrime.securesms.util.IdentityUtil import org.thoughtcrime.securesms.util.IdentityUtil
import org.thoughtcrime.securesms.util.MediaUtil import org.thoughtcrime.securesms.util.MediaUtil
import org.thoughtcrime.securesms.util.MessageConstraintsUtil import org.thoughtcrime.securesms.util.MessageConstraintsUtil
import org.thoughtcrime.securesms.util.RemoteConfig
import org.thoughtcrime.securesms.util.SignalE164Util import org.thoughtcrime.securesms.util.SignalE164Util
import org.thoughtcrime.securesms.util.TextSecurePreferences import org.thoughtcrime.securesms.util.TextSecurePreferences
import org.thoughtcrime.securesms.util.Util import org.thoughtcrime.securesms.util.Util
@@ -1740,6 +1741,10 @@ object SyncMessageProcessor {
sent: Sent, sent: Sent,
senderRecipient: Recipient senderRecipient: Recipient
): Long { ): Long {
if (!RemoteConfig.receivePolls) {
log(envelope.timestamp!!, "Sync poll create not allowed due to remote config.")
}
log(envelope.timestamp!!, "Synchronize sent poll creation message.") log(envelope.timestamp!!, "Synchronize sent poll creation message.")
val recipient = getSyncMessageDestination(sent) val recipient = getSyncMessageDestination(sent)
@@ -1791,6 +1796,10 @@ object SyncMessageProcessor {
senderRecipient: Recipient, senderRecipient: Recipient,
earlyMessageCacheEntry: EarlyMessageCacheEntry? earlyMessageCacheEntry: EarlyMessageCacheEntry?
): Long { ): Long {
if (!RemoteConfig.receivePolls) {
log(envelope.timestamp!!, "Sync poll end not allowed due to remote config.")
}
log(envelope.timestamp!!, "Synchronize sent poll terminate message") log(envelope.timestamp!!, "Synchronize sent poll terminate message")
val recipient = getSyncMessageDestination(sent) val recipient = getSyncMessageDestination(sent)

View File

@@ -1181,5 +1181,12 @@ object RemoteConfig {
hotSwappable = true hotSwappable = true
) )
@JvmStatic
@get:JvmName("receivePolls")
val receivePolls: Boolean by remoteBoolean(
key = "android.receivePolls",
defaultValue = false,
hotSwappable = true
)
// endregion // endregion
} }