]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/actions/SendReceiptAction.java
Reformat files
[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,
19 final SignalServiceReceiptMessage.Type type,
20 final long timestamp
21 ) {
22 this.recipientId = recipientId;
23 this.type = type;
24 this.timestamps.add(timestamp);
25 }
26
27 @Override
28 public void execute(Context context) throws Throwable {
29 final var receiptMessage = new SignalServiceReceiptMessage(type, timestamps, System.currentTimeMillis());
30
31 context.getSendHelper().sendReceiptMessage(receiptMessage, recipientId);
32 }
33
34 @Override
35 public void mergeOther(final HandleAction action) {
36 if (action instanceof SendReceiptAction sendReceiptAction) {
37 this.timestamps.addAll(sendReceiptAction.timestamps);
38 }
39 }
40
41 @Override
42 public boolean equals(final Object o) {
43 if (this == o) return true;
44 if (o == null || getClass() != o.getClass()) return false;
45 final SendReceiptAction that = (SendReceiptAction) o;
46 // Using only recipientId and type here on purpose
47 return recipientId.equals(that.recipientId) && type == that.type;
48 }
49
50 @Override
51 public int hashCode() {
52 // Using only recipientId and type here on purpose
53 return Objects.hash(recipientId, type);
54 }
55 }