1 package org
.asamk
.signal
.manager
.actions
;
3 import org
.asamk
.signal
.manager
.api
.GroupId
;
4 import org
.asamk
.signal
.manager
.helper
.Context
;
5 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientId
;
6 import org
.signal
.libsignal
.metadata
.ProtocolException
;
7 import org
.signal
.libsignal
.protocol
.message
.CiphertextMessage
;
8 import org
.signal
.libsignal
.protocol
.message
.DecryptionErrorMessage
;
9 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceEnvelope
;
10 import org
.whispersystems
.signalservice
.internal
.push
.Envelope
;
12 import java
.util
.Optional
;
14 public class SendRetryMessageRequestAction
implements HandleAction
{
16 private final RecipientId recipientId
;
17 private final ProtocolException protocolException
;
18 private final SignalServiceEnvelope envelope
;
20 public SendRetryMessageRequestAction(
21 final RecipientId recipientId
,
22 final ProtocolException protocolException
,
23 final SignalServiceEnvelope envelope
25 this.recipientId
= recipientId
;
26 this.protocolException
= protocolException
;
27 this.envelope
= envelope
;
31 public void execute(Context context
) throws Throwable
{
32 int senderDevice
= protocolException
.getSenderDevice();
33 Optional
<GroupId
> groupId
= protocolException
.getGroupId().isPresent() ? Optional
.of(GroupId
.unknownVersion(
34 protocolException
.getGroupId().get())) : Optional
.empty();
36 byte[] originalContent
;
38 if (protocolException
.getUnidentifiedSenderMessageContent().isPresent()) {
39 final var messageContent
= protocolException
.getUnidentifiedSenderMessageContent().get();
40 originalContent
= messageContent
.getContent();
41 envelopeType
= messageContent
.getType();
43 originalContent
= envelope
.getContent();
44 envelopeType
= envelope
.getType() == null
45 ? CiphertextMessage
.WHISPER_TYPE
46 : envelopeTypeToCiphertextMessageType(envelope
.getType());
49 DecryptionErrorMessage decryptionErrorMessage
= DecryptionErrorMessage
.forOriginalMessage(originalContent
,
51 envelope
.getTimestamp(),
54 context
.getSendHelper().sendRetryReceipt(decryptionErrorMessage
, recipientId
, groupId
);
57 private static int envelopeTypeToCiphertextMessageType(int envelopeType
) {
58 final var type
= Envelope
.Type
.fromValue(envelopeType
);
60 return CiphertextMessage
.WHISPER_TYPE
;
62 return switch (type
) {
63 case PREKEY_BUNDLE
-> CiphertextMessage
.PREKEY_TYPE
;
64 case UNIDENTIFIED_SENDER
-> CiphertextMessage
.SENDERKEY_TYPE
;
65 case PLAINTEXT_CONTENT
-> CiphertextMessage
.PLAINTEXT_CONTENT_TYPE
;
66 default -> CiphertextMessage
.WHISPER_TYPE
;
71 public boolean equals(final Object o
) {
72 if (this == o
) return true;
73 if (o
== null || getClass() != o
.getClass()) return false;
75 final SendRetryMessageRequestAction that
= (SendRetryMessageRequestAction
) o
;
77 if (!recipientId
.equals(that
.recipientId
)) return false;
78 if (!protocolException
.equals(that
.protocolException
)) return false;
79 return envelope
.equals(that
.envelope
);
83 public int hashCode() {
84 int result
= recipientId
.hashCode();
85 result
= 31 * result
+ protocolException
.hashCode();
86 result
= 31 * result
+ envelope
.hashCode();