new DBus signal ReceiptReceivedV2

ReceiptReceivedV2 (timestamp<x>, sender<s>, isDeliveryReceipt<b>, isReadReceipt
<b>, isViewedReceipt<b>)::

send three (mutually exclusive) booleans to describe nature of receipt
This commit is contained in:
John Freed 2021-10-07 18:34:15 +02:00
parent a884b7b1d5
commit 24e7c028b9
4 changed files with 82 additions and 4 deletions

View file

@ -303,6 +303,15 @@ ReceiptReceived (timestamp<x>, sender<s>)::
This signal is sent by each recipient (e.g. each group member) after the message was successfully delivered to the device
ReceiptReceivedV2 (timestamp<x>, sender<s>, isDeliveryReceipt<b>, isReadReceipt<b>, isViewedReceipt<b>)::
* timestamp : Integer value that can be used to associate this e.g. with a sendMessage()
* sender : Phone number of the sender
* isDeliveryReceipt : boolean representing whether a delivery receipt was received
* isReadReceipt : boolean representing whether a read receipt was received
* isViewedReceipt : boolean representing whether a viewed receipt was received
This signal is sent by each recipient (e.g. each group member) after the message was successfully delivered to the device
== Examples
Send a text message (without attachment) to a contact::

View file

@ -224,6 +224,51 @@ public interface Signal extends DBusInterface {
}
}
class ReceiptReceivedV2 extends DBusSignal {
private final long timestamp;
private final String sender;
private final boolean isDelivery;
private final boolean isRead;
private final boolean isViewed;
public ReceiptReceivedV2(
String objectpath,
long timestamp,
String sender,
boolean isDelivery,
boolean isRead,
boolean isViewed
) throws DBusException {
super(objectpath, timestamp, sender, isDelivery, isRead, isViewed);
this.timestamp = timestamp;
this.sender = sender;
this.isDelivery = isDelivery;
this.isRead = isRead;
this.isViewed = isViewed;
}
public long getTimestamp() {
return timestamp;
}
public String getSender() {
return sender;
}
public boolean isDelivery() {
return isDelivery;
}
public boolean isRead() {
return isRead;
}
public boolean isViewed() {
return isViewed;
}
}
class SyncMessageReceived extends DBusSignal {
private final long timestamp;

View file

@ -12,6 +12,7 @@ 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.SignalServiceAttachment;
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
import java.util.ArrayList;
import java.util.List;
@ -42,8 +43,18 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
if (envelope.isReceipt()) {
try {
conn.sendMessage(new Signal.ReceiptReceived(objectPath, envelope.getTimestamp(),
// A receipt envelope always has a source address
getLegacyIdentifier(envelope.getSourceAddress())));
if (content.getReceiptMessage().isPresent()) {
SignalServiceReceiptMessage receiptMessage = content.getReceiptMessage().get();
conn.sendMessage(new Signal.ReceiptReceivedV2(objectPath, envelope.getTimestamp(),
// A receipt envelope always has a source address
getLegacyIdentifier(envelope.getSourceAddress()),
receiptMessage.isDeliveryReceipt(),
receiptMessage.isReadReceipt(),
receiptMessage.isViewedReceipt()
));
}
} catch (DBusException e) {
e.printStackTrace();
}
@ -53,12 +64,20 @@ public class JsonDbusReceiveMessageHandler extends JsonReceiveMessageHandler {
: content.getSender();
if (content.getReceiptMessage().isPresent()) {
final var receiptMessage = content.getReceiptMessage().get();
if (receiptMessage.isDeliveryReceipt()) {
if (receiptMessage.isDeliveryReceipt() || receiptMessage.isReadReceipt() || receiptMessage.isViewedReceipt()) {
for (long timestamp : receiptMessage.getTimestamps()) {
try {
//send both signals; only one is relevant
conn.sendMessage(new Signal.ReceiptReceived(objectPath,
timestamp,
getLegacyIdentifier(sender)));
conn.sendMessage(new Signal.ReceiptReceivedV2(objectPath,
timestamp,
getLegacyIdentifier(sender),
receiptMessage.isDeliveryReceipt(),
receiptMessage.isReadReceipt(),
receiptMessage.isViewedReceipt()
));
} catch (DBusException e) {
e.printStackTrace();
}

View file

@ -17,6 +17,9 @@ class JsonReceiptMessage {
@JsonProperty
final boolean isRead;
@JsonProperty
final boolean isViewed;
@JsonProperty
final List<Long> timestamps;
@ -24,19 +27,21 @@ class JsonReceiptMessage {
this.when = receiptMessage.getWhen();
this.isDelivery = receiptMessage.isDeliveryReceipt();
this.isRead = receiptMessage.isReadReceipt();
this.isViewed = receiptMessage.isViewedReceipt();
this.timestamps = receiptMessage.getTimestamps();
}
private JsonReceiptMessage(
final long when, final boolean isDelivery, final boolean isRead, final List<Long> timestamps
final long when, final boolean isDelivery, final boolean isRead, final boolean isViewed, final List<Long> timestamps
) {
this.when = when;
this.isDelivery = isDelivery;
this.isRead = isRead;
this.isViewed = isViewed;
this.timestamps = timestamps;
}
static JsonReceiptMessage deliveryReceipt(final long when, final List<Long> timestamps) {
return new JsonReceiptMessage(when, true, false, timestamps);
return new JsonReceiptMessage(when, true, false, false, timestamps);
}
}