1 package org
.asamk
.signal
.manager
.actions
;
3 import org
.asamk
.signal
.manager
.groups
.GroupId
;
4 import org
.asamk
.signal
.manager
.jobs
.Context
;
5 import org
.asamk
.signal
.manager
.storage
.recipients
.RecipientId
;
6 import org
.signal
.libsignal
.metadata
.ProtocolException
;
7 import org
.whispersystems
.libsignal
.protocol
.CiphertextMessage
;
8 import org
.whispersystems
.libsignal
.protocol
.DecryptionErrorMessage
;
9 import org
.whispersystems
.libsignal
.util
.guava
.Optional
;
10 import org
.whispersystems
.signalservice
.api
.messages
.SignalServiceEnvelope
;
11 import org
.whispersystems
.signalservice
.internal
.push
.SignalServiceProtos
;
13 public class SendRetryMessageRequestAction
implements HandleAction
{
15 private final RecipientId recipientId
;
16 private final ProtocolException protocolException
;
17 private final SignalServiceEnvelope envelope
;
19 public SendRetryMessageRequestAction(
20 final RecipientId recipientId
,
21 final ProtocolException protocolException
,
22 final SignalServiceEnvelope envelope
24 this.recipientId
= recipientId
;
25 this.protocolException
= protocolException
;
26 this.envelope
= envelope
;
30 public void execute(Context context
) throws Throwable
{
31 context
.getAccount().getSessionStore().archiveSessions(recipientId
);
33 int senderDevice
= protocolException
.getSenderDevice();
34 Optional
<GroupId
> groupId
= protocolException
.getGroupId().isPresent() ? Optional
.of(GroupId
.unknownVersion(
35 protocolException
.getGroupId().get())) : Optional
.absent();
37 byte[] originalContent
;
39 if (protocolException
.getUnidentifiedSenderMessageContent().isPresent()) {
40 final var messageContent
= protocolException
.getUnidentifiedSenderMessageContent().get();
41 originalContent
= messageContent
.getContent();
42 envelopeType
= messageContent
.getType();
44 originalContent
= envelope
.getContent();
45 envelopeType
= envelopeTypeToCiphertextMessageType(envelope
.getType());
48 DecryptionErrorMessage decryptionErrorMessage
= DecryptionErrorMessage
.forOriginalMessage(originalContent
,
50 envelope
.getTimestamp(),
53 context
.getSendHelper().sendRetryReceipt(decryptionErrorMessage
, recipientId
, groupId
);
56 private static int envelopeTypeToCiphertextMessageType(int envelopeType
) {
57 return switch (envelopeType
) {
58 case SignalServiceProtos
.Envelope
.Type
.PREKEY_BUNDLE_VALUE
-> CiphertextMessage
.PREKEY_TYPE
;
59 case SignalServiceProtos
.Envelope
.Type
.UNIDENTIFIED_SENDER_VALUE
-> CiphertextMessage
.SENDERKEY_TYPE
;
60 case SignalServiceProtos
.Envelope
.Type
.PLAINTEXT_CONTENT_VALUE
-> CiphertextMessage
.PLAINTEXT_CONTENT_TYPE
;
61 default -> CiphertextMessage
.WHISPER_TYPE
;
66 public boolean equals(final Object o
) {
67 if (this == o
) return true;
68 if (o
== null || getClass() != o
.getClass()) return false;
70 final SendRetryMessageRequestAction that
= (SendRetryMessageRequestAction
) o
;
72 if (!recipientId
.equals(that
.recipientId
)) return false;
73 if (!protocolException
.equals(that
.protocolException
)) return false;
74 return envelope
.equals(that
.envelope
);
78 public int hashCode() {
79 int result
= recipientId
.hashCode();
80 result
= 31 * result
+ protocolException
.hashCode();
81 result
= 31 * result
+ envelope
.hashCode();