Update libsignal-service-java

This commit is contained in:
AsamK 2022-08-02 23:20:26 +02:00
parent 597ac9b504
commit 81e36d4f9b
6 changed files with 47 additions and 22 deletions

View file

@ -14,7 +14,7 @@ repositories {
}
dependencies {
implementation("com.github.turasa", "signal-service-java", "2.15.3_unofficial_52")
implementation("com.github.turasa", "signal-service-java", "2.15.3_unofficial_53")
implementation("com.fasterxml.jackson.core", "jackson-databind", "2.13.3")
implementation("com.google.protobuf", "protobuf-javalite", "3.11.4")
implementation("org.bouncycastle", "bcprov-jdk15on", "1.70")

View file

@ -123,7 +123,7 @@ public class SendHelper {
(messageSender, address, unidentifiedAccess) -> messageSender.sendReceipt(address,
unidentifiedAccess,
receiptMessage));
messageSendLogStore.insertIfPossible(receiptMessage.getWhen(), result, ContentHint.IMPLICIT);
messageSendLogStore.insertIfPossible(receiptMessage.getWhen(), result, ContentHint.IMPLICIT, false);
handleSendMessageResult(result);
return result;
}
@ -140,7 +140,8 @@ public class SendHelper {
unidentifiedAccess,
ContentHint.IMPLICIT,
message,
SignalServiceMessageSender.IndividualSendEvents.EMPTY));
SignalServiceMessageSender.IndividualSendEvents.EMPTY,
false));
}
public SendMessageResult sendRetryReceipt(
@ -237,7 +238,8 @@ public class SendHelper {
timestamp,
messageSendLogEntry.content(),
messageSendLogEntry.contentHint(),
Optional.empty()));
Optional.empty(),
messageSendLogEntry.urgent()));
}
final var groupId = messageSendLogEntry.groupId().get();
@ -266,7 +268,8 @@ public class SendHelper {
timestamp,
contentToSend,
messageSendLogEntry.contentHint(),
Optional.of(group.getGroupId().serialize())));
Optional.of(group.getGroupId().serialize()),
messageSendLogEntry.urgent()));
if (result.isSuccess()) {
final var address = context.getRecipientHelper().resolveSignalServiceAddress(recipientId);
@ -315,6 +318,7 @@ public class SendHelper {
final var messageSendLogStore = account.getMessageSendLogStore();
final AtomicLong entryId = new AtomicLong(-1);
final var urgent = true;
final LegacySenderHandler legacySender = (recipients, unidentifiedAccess, isRecipientUpdate) -> messageSender.sendDataMessage(
recipients,
unidentifiedAccess,
@ -328,14 +332,16 @@ public class SendHelper {
if (entryId.get() == -1) {
final var newId = messageSendLogStore.insertIfPossible(message.getTimestamp(),
sendResult,
contentHint);
contentHint,
urgent);
entryId.set(newId);
} else {
messageSendLogStore.addRecipientToExistingEntryIfPossible(entryId.get(), sendResult);
}
}
},
() -> false);
() -> false,
urgent);
final SenderKeySenderHandler senderKeySender = (distId, recipients, unidentifiedAccess, isRecipientUpdate) -> {
final var res = messageSender.sendGroupDataMessage(distId,
recipients,
@ -343,10 +349,14 @@ public class SendHelper {
isRecipientUpdate,
contentHint,
message,
SignalServiceMessageSender.SenderKeyGroupEvents.EMPTY);
SignalServiceMessageSender.SenderKeyGroupEvents.EMPTY,
urgent);
synchronized (entryId) {
if (entryId.get() == -1) {
final var newId = messageSendLogStore.insertIfPossible(message.getTimestamp(), res, contentHint);
final var newId = messageSendLogStore.insertIfPossible(message.getTimestamp(),
res,
contentHint,
urgent);
entryId.set(newId);
} else {
messageSendLogStore.addRecipientToExistingEntryIfPossible(entryId.get(), res);
@ -582,13 +592,15 @@ public class SendHelper {
SignalServiceDataMessage message, RecipientId recipientId
) {
final var messageSendLogStore = account.getMessageSendLogStore();
final var urgent = true;
final var result = handleSendMessage(recipientId,
(messageSender, address, unidentifiedAccess) -> messageSender.sendDataMessage(address,
unidentifiedAccess,
ContentHint.RESENDABLE,
message,
SignalServiceMessageSender.IndividualSendEvents.EMPTY));
messageSendLogStore.insertIfPossible(message.getTimestamp(), result, ContentHint.RESENDABLE);
SignalServiceMessageSender.IndividualSendEvents.EMPTY,
urgent));
messageSendLogStore.insertIfPossible(message.getTimestamp(), result, ContentHint.RESENDABLE, urgent);
handleSendMessageResult(result);
return result;
}

View file

@ -7,5 +7,5 @@ import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
import java.util.Optional;
public record MessageSendLogEntry(
Optional<GroupId> groupId, SignalServiceProtos.Content content, ContentHint contentHint
Optional<GroupId> groupId, SignalServiceProtos.Content content, ContentHint contentHint, boolean urgent
) {}

View file

@ -117,7 +117,8 @@ public class MessageSendLogStore implements AutoCloseable {
return null;
}
final var contentHint = ContentHint.fromType(resultSet.getInt("content_hint"));
return new MessageSendLogEntry(groupId, content, contentHint);
final var urgent = true; // TODO
return new MessageSendLogEntry(groupId, content, contentHint, urgent);
})) {
return result.filter(Objects::nonNull)
.filter(e -> !isSenderKey || e.groupId().isPresent())
@ -131,7 +132,7 @@ public class MessageSendLogStore implements AutoCloseable {
}
public long insertIfPossible(
long sentTimestamp, SendMessageResult sendMessageResult, ContentHint contentHint
long sentTimestamp, SendMessageResult sendMessageResult, ContentHint contentHint, boolean urgent
) {
final RecipientDevices recipientDevice = getRecipientDevices(sendMessageResult);
if (recipientDevice == null) {
@ -141,11 +142,12 @@ public class MessageSendLogStore implements AutoCloseable {
return insert(List.of(recipientDevice),
sentTimestamp,
sendMessageResult.getSuccess().getContent().get(),
contentHint);
contentHint,
urgent);
}
public long insertIfPossible(
long sentTimestamp, List<SendMessageResult> sendMessageResults, ContentHint contentHint
long sentTimestamp, List<SendMessageResult> sendMessageResults, ContentHint contentHint, boolean urgent
) {
final var recipientDevices = sendMessageResults.stream()
.map(this::getRecipientDevices)
@ -161,7 +163,7 @@ public class MessageSendLogStore implements AutoCloseable {
.findFirst()
.get();
return insert(recipientDevices, sentTimestamp, content, contentHint);
return insert(recipientDevices, sentTimestamp, content, contentHint, urgent);
}
public void addRecipientToExistingEntryIfPossible(final long contentId, final SendMessageResult sendMessageResult) {
@ -272,10 +274,12 @@ public class MessageSendLogStore implements AutoCloseable {
final List<RecipientDevices> recipientDevices,
final long sentTimestamp,
final SignalServiceProtos.Content content,
final ContentHint contentHint
final ContentHint contentHint,
final boolean urgent
) {
byte[] groupId = getGroupId(content);
// TODO store urgent
final var sql = """
INSERT INTO %s (timestamp, group_id, content, content_hint)
VALUES (?,?,?,?)

View file

@ -19,7 +19,8 @@ public class MessageCacheUtils {
try (var f = new FileInputStream(file)) {
var in = new DataInputStream(f);
var version = in.readInt();
if (version > 5) {
if (version > 6) {
// Unsupported envelope version
return null;
}
var type = in.readInt();
@ -63,6 +64,10 @@ public class MessageCacheUtils {
if (version >= 4) {
serverDeliveredTimestamp = in.readLong();
}
boolean isUrgent = true;
if (version >= 6) {
isUrgent = in.readBoolean();
}
Optional<SignalServiceAddress> addressOptional = sourceServiceId == null
? Optional.empty()
: Optional.of(new SignalServiceAddress(sourceServiceId, source));
@ -75,14 +80,15 @@ public class MessageCacheUtils {
serverReceivedTimestamp,
serverDeliveredTimestamp,
uuid,
destinationUuid == null ? UuidUtil.UNKNOWN_UUID.toString() : destinationUuid);
destinationUuid == null ? UuidUtil.UNKNOWN_UUID.toString() : destinationUuid,
isUrgent);
}
}
public static void storeEnvelope(SignalServiceEnvelope envelope, File file) throws IOException {
try (var f = new FileOutputStream(file)) {
try (var out = new DataOutputStream(f)) {
out.writeInt(5); // version
out.writeInt(6); // version
out.writeInt(envelope.getType());
out.writeUTF(envelope.getSourceE164().isPresent() ? envelope.getSourceE164().get() : "");
out.writeUTF(envelope.getSourceUuid().isPresent() ? envelope.getSourceUuid().get() : "");
@ -105,6 +111,7 @@ public class MessageCacheUtils {
var uuid = envelope.getServerGuid();
out.writeUTF(uuid == null ? "" : uuid);
out.writeLong(envelope.getServerDeliveredTimestamp());
out.writeBoolean(envelope.isUrgent());
}
}
}