Send sync message for read/viewed receipt messages

Fixes #1570
This commit is contained in:
AsamK 2024-09-08 08:51:33 +02:00
parent 7cc0ef1c70
commit b51f849fe6
2 changed files with 29 additions and 2 deletions

View file

@ -19,6 +19,7 @@ import org.slf4j.LoggerFactory;
import org.whispersystems.signalservice.api.messages.SendMessageResult;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachment;
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentStream;
import org.whispersystems.signalservice.api.messages.SignalServiceReceiptMessage;
import org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage;
import org.whispersystems.signalservice.api.messages.multidevice.ConfigurationMessage;
import org.whispersystems.signalservice.api.messages.multidevice.ContactsMessage;
@ -30,10 +31,13 @@ import org.whispersystems.signalservice.api.messages.multidevice.DeviceGroupsInp
import org.whispersystems.signalservice.api.messages.multidevice.DeviceGroupsOutputStream;
import org.whispersystems.signalservice.api.messages.multidevice.KeysMessage;
import org.whispersystems.signalservice.api.messages.multidevice.MessageRequestResponseMessage;
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage;
import org.whispersystems.signalservice.api.messages.multidevice.RequestMessage;
import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage;
import org.whispersystems.signalservice.api.messages.multidevice.StickerPackOperationMessage;
import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage;
import org.whispersystems.signalservice.api.messages.multidevice.ViewedMessage;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.push.SignalServiceAddress;
import org.whispersystems.signalservice.internal.push.SyncMessage;
import org.whispersystems.signalservice.internal.push.http.ResumableUploadSpec;
@ -89,6 +93,22 @@ public class SyncHelper {
.sendSyncMessage(SignalServiceSyncMessage.forFetchLatest(SignalServiceSyncMessage.FetchType.STORAGE_MANIFEST));
}
public void sendSyncReceiptMessage(ServiceId sender, SignalServiceReceiptMessage receiptMessage) {
if (receiptMessage.isReadReceipt()) {
final var readMessages = receiptMessage.getTimestamps()
.stream()
.map(t -> new ReadMessage(sender, t))
.toList();
context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forRead(readMessages));
} else if (receiptMessage.isViewedReceipt()) {
final var viewedMessages = receiptMessage.getTimestamps()
.stream()
.map(t -> new ViewedMessage(sender, t))
.toList();
context.getSendHelper().sendSyncMessage(SignalServiceSyncMessage.forViewed(viewedMessages));
}
}
public void sendGroups() throws IOException {
var groupsFile = IOUtils.createTempFile();

View file

@ -704,8 +704,15 @@ public class ManagerImpl implements Manager {
final SignalServiceReceiptMessage receiptMessage
) {
try {
final var result = context.getSendHelper()
.sendReceiptMessage(receiptMessage, context.getRecipientHelper().resolveRecipient(sender));
final var recipientId = context.getRecipientHelper().resolveRecipient(sender);
final var result = context.getSendHelper().sendReceiptMessage(receiptMessage, recipientId);
final var serviceId = account.getRecipientAddressResolver()
.resolveRecipientAddress(recipientId)
.serviceId();
if (serviceId.isPresent()) {
context.getSyncHelper().sendSyncReceiptMessage(serviceId.get(), receiptMessage);
}
return new SendMessageResults(timestamp, Map.of(sender, List.of(toSendMessageResult(result))));
} catch (UnregisteredRecipientException e) {
return new SendMessageResults(timestamp,