For ephemeral messages, remove recipient view from shared MRM data if recipient is offline
This commit is contained in:
parent
a0770db179
commit
b95a766888
|
@ -69,6 +69,8 @@ public class MessageSender {
|
||||||
|
|
||||||
if (clientPresent) {
|
if (clientPresent) {
|
||||||
messagesManager.insert(account.getUuid(), device.getId(), message.toBuilder().setEphemeral(true).build());
|
messagesManager.insert(account.getUuid(), device.getId(), message.toBuilder().setEphemeral(true).build());
|
||||||
|
} else {
|
||||||
|
messagesManager.removeRecipientViewFromMrmData(account.getUuid(), device.getId(), message);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
messagesManager.insert(account.getUuid(), device.getId(), message);
|
messagesManager.insert(account.getUuid(), device.getId(), message);
|
||||||
|
|
|
@ -462,7 +462,7 @@ public class MessagesCache extends RedisClusterPubSubAdapter<String, String> imp
|
||||||
/**
|
/**
|
||||||
* Makes a best-effort attempt at asynchronously updating (and removing when empty) the MRM data structure
|
* Makes a best-effort attempt at asynchronously updating (and removing when empty) the MRM data structure
|
||||||
*/
|
*/
|
||||||
private void removeRecipientViewFromMrmData(final List<byte[]> sharedMrmKeys, final UUID accountUuid,
|
void removeRecipientViewFromMrmData(final List<byte[]> sharedMrmKeys, final UUID accountUuid,
|
||||||
final byte deviceId) {
|
final byte deviceId) {
|
||||||
|
|
||||||
final Timer.Sample sample = Timer.start();
|
final Timer.Sample sample = Timer.start();
|
||||||
|
|
|
@ -210,4 +210,15 @@ public class MessagesManager {
|
||||||
SealedSenderMultiRecipientMessage sealedSenderMultiRecipientMessage) {
|
SealedSenderMultiRecipientMessage sealedSenderMultiRecipientMessage) {
|
||||||
return messagesCache.insertSharedMultiRecipientMessagePayload(UUID.randomUUID(), sealedSenderMultiRecipientMessage);
|
return messagesCache.insertSharedMultiRecipientMessagePayload(UUID.randomUUID(), sealedSenderMultiRecipientMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the recipient's view from shared MRM data if necessary
|
||||||
|
*/
|
||||||
|
public void removeRecipientViewFromMrmData(final UUID destinationUuid, final byte destinationDeviceId,
|
||||||
|
final Envelope message) {
|
||||||
|
if (message.hasSharedMrmKey()) {
|
||||||
|
messagesCache.removeRecipientViewFromMrmData(List.of(message.getSharedMrmKey().toByteArray()), destinationUuid,
|
||||||
|
destinationDeviceId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ import java.util.UUID;
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.whispersystems.textsecuregcm.entities.MessageProtos;
|
import org.whispersystems.textsecuregcm.entities.MessageProtos;
|
||||||
import org.whispersystems.textsecuregcm.storage.Account;
|
import org.whispersystems.textsecuregcm.storage.Account;
|
||||||
|
@ -71,20 +73,31 @@ class MessageSenderTest {
|
||||||
MessageProtos.Envelope.class);
|
MessageProtos.Envelope.class);
|
||||||
|
|
||||||
verify(messagesManager).insert(any(), anyByte(), envelopeArgumentCaptor.capture());
|
verify(messagesManager).insert(any(), anyByte(), envelopeArgumentCaptor.capture());
|
||||||
|
verify(messagesManager, never()).removeRecipientViewFromMrmData(any(), anyByte(),
|
||||||
|
any(MessageProtos.Envelope.class));
|
||||||
|
|
||||||
assertTrue(envelopeArgumentCaptor.getValue().getEphemeral());
|
assertTrue(envelopeArgumentCaptor.getValue().getEphemeral());
|
||||||
|
|
||||||
verifyNoInteractions(pushNotificationManager);
|
verifyNoInteractions(pushNotificationManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
void testSendOnlineMessageClientNotPresent() throws Exception {
|
@ValueSource(booleans = {true, false})
|
||||||
|
void testSendOnlineMessageClientNotPresent(final boolean hasSharedMrmKey) throws Exception {
|
||||||
|
|
||||||
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(false);
|
when(clientPresenceManager.isPresent(ACCOUNT_UUID, DEVICE_ID)).thenReturn(false);
|
||||||
when(device.getGcmId()).thenReturn("gcm-id");
|
when(device.getGcmId()).thenReturn("gcm-id");
|
||||||
|
|
||||||
messageSender.sendMessage(account, device, message, true);
|
if (hasSharedMrmKey) {
|
||||||
|
messageSender.sendMessage(account, device,
|
||||||
|
message.toBuilder().setSharedMrmKey(ByteString.copyFromUtf8("sharedMrmKey")).build(), true);
|
||||||
|
} else {
|
||||||
|
messageSender.sendMessage(account, device, message, true);
|
||||||
|
}
|
||||||
|
|
||||||
verify(messagesManager, never()).insert(any(), anyByte(), any());
|
verify(messagesManager, never()).insert(any(), anyByte(), any());
|
||||||
|
verify(messagesManager).removeRecipientViewFromMrmData(any(), anyByte(), any(MessageProtos.Envelope.class));
|
||||||
|
|
||||||
verifyNoInteractions(pushNotificationManager);
|
verifyNoInteractions(pushNotificationManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue