Throw a `MismatchedDevicesException` for empty message lists to support iOS clients
This commit is contained in:
parent
3af2cc5c70
commit
01258de560
|
@ -13,6 +13,7 @@ import io.micrometer.core.instrument.DistributionSummary;
|
||||||
import io.micrometer.core.instrument.Metrics;
|
import io.micrometer.core.instrument.Metrics;
|
||||||
import io.micrometer.core.instrument.Tag;
|
import io.micrometer.core.instrument.Tag;
|
||||||
import io.micrometer.core.instrument.Tags;
|
import io.micrometer.core.instrument.Tags;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -99,7 +100,11 @@ public class MessageSender {
|
||||||
@Nullable final String userAgent) throws MismatchedDevicesException, MessageTooLargeException {
|
@Nullable final String userAgent) throws MismatchedDevicesException, MessageTooLargeException {
|
||||||
|
|
||||||
if (messagesByDeviceId.isEmpty()) {
|
if (messagesByDeviceId.isEmpty()) {
|
||||||
return;
|
// TODO Simply return and don't throw an exception when iOS clients no longer depend on this behavior
|
||||||
|
throw new MismatchedDevicesException(new MismatchedDevices(
|
||||||
|
destination.getDevices().stream().map(Device::getId).collect(Collectors.toSet()),
|
||||||
|
Collections.emptySet(),
|
||||||
|
Collections.emptySet()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!destination.isIdentifiedBy(destinationIdentifier)) {
|
if (!destination.isIdentifiedBy(destinationIdentifier)) {
|
||||||
|
|
|
@ -344,4 +344,19 @@ class MessageSenderTest {
|
||||||
Optional.of(new MismatchedDevices(Set.of(primaryDeviceId), Set.of(extraDeviceId), Set.of(linkedDeviceId))))
|
Optional.of(new MismatchedDevices(Set.of(primaryDeviceId), Set.of(extraDeviceId), Set.of(linkedDeviceId))))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void sendMessageEmptyMessageList() {
|
||||||
|
final Device device = mock(Device.class);
|
||||||
|
when(device.getId()).thenReturn(Device.PRIMARY_ID);
|
||||||
|
|
||||||
|
final Account account = mock(Account.class);
|
||||||
|
when(account.getDevices()).thenReturn(List.of(device));
|
||||||
|
|
||||||
|
assertThrows(MismatchedDevicesException.class, () -> messageSender.sendMessages(account,
|
||||||
|
new AciServiceIdentifier(UUID.randomUUID()),
|
||||||
|
Collections.emptyMap(),
|
||||||
|
Collections.emptyMap(),
|
||||||
|
null));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue