Skip to content

Commit

Permalink
Update libsignal-service-java
Browse files Browse the repository at this point in the history
  • Loading branch information
AsamK committed Jan 14, 2024
1 parent 30e8e36 commit be9efb9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,6 @@ public record Call(
Optional<Busy> busy,
List<IceUpdate> iceUpdate,
Optional<Opaque> opaque,
boolean isMultiRing,
boolean isUrgent
) {

Expand All @@ -732,17 +731,13 @@ public static Call from(final SignalServiceCallMessage callMessage) {
.map(m -> m.stream().map(IceUpdate::from).toList())
.orElse(List.of()),
callMessage.getOpaqueMessage().map(Opaque::from),
callMessage.isMultiRing(),
callMessage.isUrgent());
}

public record Offer(long id, String sdp, Type type, byte[] opaque) {
public record Offer(long id, Type type, byte[] opaque) {

static Offer from(OfferMessage offerMessage) {
return new Offer(offerMessage.getId(),
offerMessage.getSdp(),
Type.from(offerMessage.getType()),
offerMessage.getOpaque());
return new Offer(offerMessage.getId(), Type.from(offerMessage.getType()), offerMessage.getOpaque());
}

public enum Type {
Expand All @@ -758,10 +753,10 @@ static Type from(OfferMessage.Type type) {
}
}

public record Answer(long id, String sdp, byte[] opaque) {
public record Answer(long id, byte[] opaque) {

static Answer from(AnswerMessage answerMessage) {
return new Answer(answerMessage.getId(), answerMessage.getSdp(), answerMessage.getOpaque());
return new Answer(answerMessage.getId(), answerMessage.getOpaque());
}
}

Expand Down Expand Up @@ -799,10 +794,10 @@ static Type from(HangupMessage.Type type) {
}
}

public record IceUpdate(long id, String sdp, byte[] opaque) {
public record IceUpdate(long id, byte[] opaque) {

static IceUpdate from(IceUpdateMessage iceUpdateMessage) {
return new IceUpdate(iceUpdateMessage.getId(), iceUpdateMessage.getSdp(), iceUpdateMessage.getOpaque());
return new IceUpdate(iceUpdateMessage.getId(), iceUpdateMessage.getOpaque());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ public void reserveUsername(String nickname) throws IOException, BaseUsernameExc
if (currentUsername != null) {
final var currentNickname = currentUsername.substring(0, currentUsername.indexOf('.'));
if (currentNickname.equals(nickname)) {
refreshCurrentUsername();
try {
refreshCurrentUsername();
} catch (IOException | BaseUsernameException e) {
logger.warn("[reserveUsername] Failed to refresh current username, trying to claim new username");
}
return;
}
}
Expand All @@ -341,11 +345,11 @@ public void reserveUsername(String nickname) throws IOException, BaseUsernameExc
logger.debug("[reserveUsername] Successfully reserved username.");
final var username = candidates.get(hashIndex);

dependencies.getAccountManager().confirmUsername(username.getUsername(), response);
final var linkComponents = dependencies.getAccountManager().confirmUsernameAndCreateNewLink(username);
account.setUsername(username.getUsername());
account.setUsernameLink(linkComponents);
account.getRecipientStore().resolveSelfRecipientTrusted(account.getSelfRecipientAddress());
logger.debug("[confirmUsername] Successfully confirmed username.");
tryToSetUsernameLink(username);
}

public void refreshCurrentUsername() throws IOException, BaseUsernameException {
Expand Down Expand Up @@ -386,12 +390,20 @@ public void refreshCurrentUsername() throws IOException, BaseUsernameException {
}

private void tryReserveConfirmUsername(final Username username) throws IOException {
final var response = dependencies.getAccountManager()
.reserveUsername(List.of(Base64.encodeUrlSafeWithoutPadding(username.getHash())));
logger.debug("[reserveUsername] Successfully reserved existing username.");
dependencies.getAccountManager().confirmUsername(username.getUsername(), response);
logger.debug("[confirmUsername] Successfully confirmed existing username.");
tryToSetUsernameLink(username);
final var usernameLink = account.getUsernameLink();

if (usernameLink == null) {
dependencies.getAccountManager()
.reserveUsername(List.of(Base64.encodeUrlSafeWithoutPadding(username.getHash())));
logger.debug("[reserveUsername] Successfully reserved existing username.");
final var linkComponents = dependencies.getAccountManager().confirmUsernameAndCreateNewLink(username);
account.setUsernameLink(linkComponents);
logger.debug("[confirmUsername] Successfully confirmed existing username.");
} else {
final var linkComponents = dependencies.getAccountManager().reclaimUsernameAndLink(username, usernameLink);
account.setUsernameLink(linkComponents);
logger.debug("[confirmUsername] Successfully reclaimed existing username and link.");
}
}

private void tryToSetUsernameLink(Username username) {
Expand Down
3 changes: 1 addition & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ dependencyResolutionManagement {
library("slf4j.jul", "org.slf4j", "jul-to-slf4j").versionRef("slf4j")
library("logback", "ch.qos.logback", "logback-classic").version("1.4.14")


library("signalservice", "com.github.turasa", "signal-service-java").version("2.15.3_unofficial_91")
library("signalservice", "com.github.turasa", "signal-service-java").version("2.15.3_unofficial_92")
library("sqlite", "org.xerial", "sqlite-jdbc").version("3.44.1.0")
library("hikari", "com.zaxxer", "HikariCP").version("5.1.0")
library("junit.jupiter", "org.junit.jupiter", "junit-jupiter").version("5.10.1")
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/asamk/signal/ReceiveMessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private void printCallMessage(
}
if (callMessage.answer().isPresent()) {
var answerMessage = callMessage.answer().get();
writer.println("Answer message: {}, sdp: {})", answerMessage.id(), answerMessage.sdp());
writer.println("Answer message: {}, opaque length: {})", answerMessage.id(), answerMessage.opaque().length);
}
if (callMessage.busy().isPresent()) {
var busyMessage = callMessage.busy().get();
Expand All @@ -287,12 +287,12 @@ private void printCallMessage(
writer.println("Ice update messages:");
var iceUpdateMessages = callMessage.iceUpdate();
for (var iceUpdateMessage : iceUpdateMessages) {
writer.println("- {}, sdp: {}", iceUpdateMessage.id(), iceUpdateMessage.sdp());
writer.println("- {}, opaque length: {}", iceUpdateMessage.id(), iceUpdateMessage.opaque().length);
}
}
if (callMessage.offer().isPresent()) {
var offerMessage = callMessage.offer().get();
writer.println("Offer message: {}, sdp: {}", offerMessage.id(), offerMessage.sdp());
writer.println("Offer message: {}, opaque length: {}", offerMessage.id(), offerMessage.opaque().length);
}
if (callMessage.opaque().isPresent()) {
final var opaqueMessage = callMessage.opaque().get();
Expand Down
17 changes: 6 additions & 11 deletions src/main/java/org/asamk/signal/json/JsonCallMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,17 @@ static JsonCallMessage from(MessageEnvelope.Call callMessage) {
callMessage.iceUpdate().stream().map(IceUpdate::from).toList());
}

record Offer(long id, String sdp, String type, String opaque) {
record Offer(long id, String type, String opaque) {

public static Offer from(final MessageEnvelope.Call.Offer offer) {
return new Offer(offer.id(),
offer.sdp(),
offer.type().name(),
Base64.getEncoder().encodeToString(offer.opaque()));
return new Offer(offer.id(), offer.type().name(), Base64.getEncoder().encodeToString(offer.opaque()));
}
}

public record Answer(long id, String sdp, String opaque) {
public record Answer(long id, String opaque) {

public static Answer from(final MessageEnvelope.Call.Answer answer) {
return new Answer(answer.id(), answer.sdp(), Base64.getEncoder().encodeToString(answer.opaque()));
return new Answer(answer.id(), Base64.getEncoder().encodeToString(answer.opaque()));
}
}

Expand All @@ -54,12 +51,10 @@ public static Hangup from(final MessageEnvelope.Call.Hangup hangup) {
}
}

public record IceUpdate(long id, String sdp, String opaque) {
public record IceUpdate(long id, String opaque) {

public static IceUpdate from(final MessageEnvelope.Call.IceUpdate iceUpdate) {
return new IceUpdate(iceUpdate.id(),
iceUpdate.sdp(),
Base64.getEncoder().encodeToString(iceUpdate.opaque()));
return new IceUpdate(iceUpdate.id(), Base64.getEncoder().encodeToString(iceUpdate.opaque()));
}
}
}

0 comments on commit be9efb9

Please sign in to comment.