]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/actions/SendReceiptAction.java
Reset pre key offset if it somehow gets corrupted
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / actions / SendReceiptAction.java
1 package org.asamk.signal.manager.actions;
2
3 import org.asamk.signal.manager.helper.Context;
4 import org.asamk.signal.manager.storage.recipients.RecipientId;
5 import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
6
7 import java.util.ArrayList;
8 import java.util.List;
9 import java.util.Objects;
10
11 public class SendReceiptAction implements HandleAction {
12
13 private final RecipientId recipientId;
14 private final SignalServiceReceiptMessage.Type type;
15 private final List<Long> timestamps = new ArrayList<>();
16
17 public SendReceiptAction(
18 final RecipientId recipientId, final SignalServiceReceiptMessage.Type type, final long timestamp
19 ) {
20 this.recipientId = recipientId;
21 this.type = type;
22 this.timestamps.add(timestamp);
23 }
24
25 @Override
26 public void execute(Context context) throws Throwable {
27 final var receiptMessage = new SignalServiceReceiptMessage(type, timestamps, System.currentTimeMillis());
28
29 context.getSendHelper().sendReceiptMessage(receiptMessage, recipientId);
30 }
31
32 @Override
33 public void mergeOther(final HandleAction action) {
34 if (action instanceof SendReceiptAction sendReceiptAction) {
35 this.timestamps.addAll(sendReceiptAction.timestamps);
36 }
37 }
38
39 @Override
40 public boolean equals(final Object o) {
41 if (this == o) return true;
42 if (o == null || getClass() != o.getClass()) return false;
43 final SendReceiptAction that = (SendReceiptAction) o;
44 // Using only recipientId and type here on purpose
45 return recipientId.equals(that.recipientId) && type == that.type;
46 }
47
48 @Override
49 public int hashCode() {
50 // Using only recipientId and type here on purpose
51 return Objects.hash(recipientId, type);
52 }
53 }