mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 02:20:39 +00:00
Refactor SendReceiptAction to take type argument
This commit is contained in:
parent
e03c48e0ae
commit
8828b60288
3 changed files with 17 additions and 17 deletions
|
@ -2,6 +2,7 @@ package org.asamk.signal.manager.actions;
|
|||
|
||||
import org.asamk.signal.manager.helper.Context;
|
||||
import org.asamk.signal.manager.storage.recipients.RecipientId;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -10,16 +11,22 @@ import java.util.Objects;
|
|||
public class SendReceiptAction implements HandleAction {
|
||||
|
||||
private final RecipientId recipientId;
|
||||
private final SignalServiceReceiptMessage.Type type;
|
||||
private final List<Long> timestamps = new ArrayList<>();
|
||||
|
||||
public SendReceiptAction(final RecipientId recipientId, final long timestamp) {
|
||||
public SendReceiptAction(
|
||||
final RecipientId recipientId, final SignalServiceReceiptMessage.Type type, final long timestamp
|
||||
) {
|
||||
this.recipientId = recipientId;
|
||||
this.type = type;
|
||||
this.timestamps.add(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Context context) throws Throwable {
|
||||
context.getSendHelper().sendDeliveryReceipt(recipientId, timestamps);
|
||||
final var receiptMessage = new SignalServiceReceiptMessage(type, timestamps, System.currentTimeMillis());
|
||||
|
||||
context.getSendHelper().sendReceiptMessage(receiptMessage, recipientId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -34,13 +41,13 @@ public class SendReceiptAction implements HandleAction {
|
|||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
final SendReceiptAction that = (SendReceiptAction) o;
|
||||
// Using only recipientId here on purpose
|
||||
return recipientId.equals(that.recipientId);
|
||||
// Using only recipientId and type here on purpose
|
||||
return recipientId.equals(that.recipientId) && type == that.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
// Using only recipientId here on purpose
|
||||
return Objects.hash(recipientId);
|
||||
// Using only recipientId and type here on purpose
|
||||
return Objects.hash(recipientId, type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceContent;
|
|||
import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceGroup;
|
||||
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage;
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
|
||||
|
@ -247,7 +248,9 @@ public final class IncomingMessageHandler {
|
|||
var message = content.getDataMessage().get();
|
||||
|
||||
if (content.isNeedsReceipt()) {
|
||||
actions.add(new SendReceiptAction(sender, message.getTimestamp()));
|
||||
actions.add(new SendReceiptAction(sender,
|
||||
SignalServiceReceiptMessage.Type.DELIVERY,
|
||||
message.getTimestamp()));
|
||||
} else {
|
||||
// Message wasn't sent as unidentified sender message
|
||||
final var contact = context.getAccount().getContactStore().getContact(sender);
|
||||
|
|
|
@ -116,16 +116,6 @@ public class SendHelper {
|
|||
return sendGroupMessage(message, recipientIds, distributionId, ContentHint.IMPLICIT);
|
||||
}
|
||||
|
||||
public SendMessageResult sendDeliveryReceipt(
|
||||
RecipientId recipientId, List<Long> messageIds
|
||||
) {
|
||||
var receiptMessage = new SignalServiceReceiptMessage(SignalServiceReceiptMessage.Type.DELIVERY,
|
||||
messageIds,
|
||||
System.currentTimeMillis());
|
||||
|
||||
return sendReceiptMessage(receiptMessage, recipientId);
|
||||
}
|
||||
|
||||
public SendMessageResult sendReceiptMessage(
|
||||
final SignalServiceReceiptMessage receiptMessage, final RecipientId recipientId
|
||||
) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue