1 package org
.asamk
.signal
.manager
.actions
;
3 import org
.asamk
.signal
.manager
.groups
.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
.SignalServiceProtos
;
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 context
.getAccount().getSessionStore().archiveSessions(recipientId
);
34 int senderDevice
= protocolException
.getSenderDevice();
35 Optional
<GroupId
> groupId
= protocolException
.getGroupId().isPresent() ? Optional
.of(GroupId
.unknownVersion(
36 protocolException
.getGroupId().get())) : Optional
.empty();
38 byte[] originalContent
;
40 if (protocolException
.getUnidentifiedSenderMessageContent().isPresent()) {
41 final var messageContent
= protocolException
.getUnidentifiedSenderMessageContent().get();
42 originalContent
= messageContent
.getContent();
43 envelopeType
= messageContent
.getType();
45 originalContent
= envelope
.getContent();
46 envelopeType
= 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 return switch (envelopeType
) {
59 case SignalServiceProtos
.Envelope
.Type
.PREKEY_BUNDLE_VALUE
-> CiphertextMessage
.PREKEY_TYPE
;
60 case SignalServiceProtos
.Envelope
.Type
.UNIDENTIFIED_SENDER_VALUE
-> CiphertextMessage
.SENDERKEY_TYPE
;
61 case SignalServiceProtos
.Envelope
.Type
.PLAINTEXT_CONTENT_VALUE
-> CiphertextMessage
.PLAINTEXT_CONTENT_TYPE
;
62 default -> CiphertextMessage
.WHISPER_TYPE
;
67 public boolean equals(final Object o
) {
68 if (this == o
) return true;
69 if (o
== null || getClass() != o
.getClass()) return false;
71 final SendRetryMessageRequestAction that
= (SendRetryMessageRequestAction
) o
;
73 if (!recipientId
.equals(that
.recipientId
)) return false;
74 if (!protocolException
.equals(that
.protocolException
)) return false;
75 return envelope
.equals(that
.envelope
);
79 public int hashCode() {
80 int result
= recipientId
.hashCode();
81 result
= 31 * result
+ protocolException
.hashCode();
82 result
= 31 * result
+ envelope
.hashCode();