]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/actions/SendReceiptAction.java
Refactor Context to create helpers lazily
[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
6 import java.util.ArrayList;
7 import java.util.List;
8 import java.util.Objects;
9
10 public class SendReceiptAction implements HandleAction {
11
12 private final RecipientId recipientId;
13 private final List<Long> timestamps = new ArrayList<>();
14
15 public SendReceiptAction(final RecipientId recipientId, final long timestamp) {
16 this.recipientId = recipientId;
17 this.timestamps.add(timestamp);
18 }
19
20 @Override
21 public void execute(Context context) throws Throwable {
22 context.getSendHelper().sendDeliveryReceipt(recipientId, timestamps);
23 }
24
25 @Override
26 public void mergeOther(final HandleAction action) {
27 if (action instanceof SendReceiptAction sendReceiptAction) {
28 this.timestamps.addAll(sendReceiptAction.timestamps);
29 }
30 }
31
32 @Override
33 public boolean equals(final Object o) {
34 if (this == o) return true;
35 if (o == null || getClass() != o.getClass()) return false;
36 final SendReceiptAction that = (SendReceiptAction) o;
37 // Using only recipientId here on purpose
38 return recipientId.equals(that.recipientId);
39 }
40
41 @Override
42 public int hashCode() {
43 // Using only recipientId here on purpose
44 return Objects.hash(recipientId);
45 }
46 }