mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-22 01:18:35 +01:00
Temporarily support IncomingMessage.online (#404)
iOS versions prior to 5.5.0.7 send `online` on `IncomingMessage`, rather than on the top-level entity. This adds a temporary server-side adaptation, to prevent client-side issues, like persistent typing indicators.
This commit is contained in:
@@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import io.dropwizard.auth.PolymorphicAuthValueFactoryProvider;
|
||||
import io.dropwizard.testing.junit.ResourceTestRule;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -39,11 +40,14 @@ import java.util.concurrent.TimeUnit;
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import junitparams.JUnitParamsRunner;
|
||||
import junitparams.Parameters;
|
||||
import org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.whispersystems.textsecuregcm.auth.AmbiguousIdentifier;
|
||||
@@ -71,6 +75,7 @@ import org.whispersystems.textsecuregcm.storage.MessagesManager;
|
||||
import org.whispersystems.textsecuregcm.tests.util.AuthHelper;
|
||||
import org.whispersystems.textsecuregcm.util.Base64;
|
||||
|
||||
@RunWith(JUnitParamsRunner.class)
|
||||
public class MessageControllerTest {
|
||||
|
||||
private static final String SINGLE_DEVICE_RECIPIENT = "+14151111111";
|
||||
@@ -381,4 +386,34 @@ public class MessageControllerTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@Parameters(method = "argumentsForTestOnlineMessage")
|
||||
public void testOnlineMessage(final String fixture, final boolean expectedOnline) throws Exception {
|
||||
|
||||
final Response response =
|
||||
resources.getJerseyTest()
|
||||
.target(String.format("/v1/messages/%s", SINGLE_DEVICE_RECIPIENT))
|
||||
.request()
|
||||
.header("Authorization", AuthHelper.getAuthHeader(AuthHelper.VALID_NUMBER, AuthHelper.VALID_PASSWORD))
|
||||
.put(Entity.entity(mapper.readValue(jsonFixture(fixture), IncomingMessageList.class),
|
||||
MediaType.APPLICATION_JSON_TYPE));
|
||||
|
||||
assertThat("Good Response", response.getStatus(), is(equalTo(200)));
|
||||
|
||||
verify(messageSender, times(1)).sendMessage(any(Account.class), any(Device.class), any(Envelope.class), eq(expectedOnline));
|
||||
}
|
||||
|
||||
private static Object argumentsForTestOnlineMessage() {
|
||||
return new Object[] {
|
||||
new Object[] { "fixtures/current_message_single_device.json", false }, // default to `false` when absent
|
||||
new Object[] { "fixtures/online_message_true.json", true },
|
||||
new Object[] { "fixtures/online_message_false.json", false },
|
||||
// iOS versions prior to 5.5.0.7 send `online` on IncomingMessageList.message, rather on the top-level entity.
|
||||
// This causes some odd client behaviors, such as persisted typing indicators, so we have a temporary
|
||||
// server-side adaptation.
|
||||
new Object[] { "fixtures/online_message_true_nested_property.json", true },
|
||||
new Object[] { "fixtures/online_message_false_nested_property.json", false },
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user