mirror of
https://github.com/AsamK/signal-cli.git
synced 2026-11-29 08:55:48 +00:00
Reformat files
This commit is contained in:
1 parent
3d7109eb01
commit
926cd256e6
13 files changed
+116
-75
No files matched your search
@@ -33,9 +33,9 @@ public class AttachmentUtils {
|
||||
ResumableUploadSpec resumableUploadSpec
|
||||
) throws ResumeLocationInvalidException, IOException {
|
||||
final var uploadTimestamp = System.currentTimeMillis();
|
||||
final var probedStream = dimensions != null
|
||||
? new ProbedStream(streamDetails.getStream(), dimensions.width(), dimensions.height())
|
||||
: probeImageDimensions(streamDetails);
|
||||
final var probedStream = dimensions != null ? new ProbedStream(streamDetails.getStream(),
|
||||
dimensions.width(),
|
||||
dimensions.height()) : probeImageDimensions(streamDetails);
|
||||
return SignalServiceAttachmentStream.newStreamBuilder()
|
||||
.withStream(probedStream.inputStream())
|
||||
.withContentType(streamDetails.getContentType())
|
||||
|
||||
@@ -39,8 +39,8 @@ class StorageHelperTest {
|
||||
Set.of(pendingId)));
|
||||
assertFalse(StorageHelper.containsOnlyIdentityConflictsPendingRepair(write(List.of()), Set.of(pendingId)));
|
||||
assertFalse(StorageHelper.containsOnlyIdentityConflictsPendingRepair(new WriteOperationResult(null,
|
||||
List.of(pendingRecord),
|
||||
List.of(new byte[]{3})), Set.of(pendingId)));
|
||||
List.of(pendingRecord),
|
||||
List.of(new byte[]{3})), Set.of(pendingId)));
|
||||
}
|
||||
|
||||
private static SignalStorageRecord record(final StorageId id) {
|
||||
|
||||
@@ -50,7 +50,11 @@ class AttachmentUtilsTest {
|
||||
final var blurHash = "LEHV6nWB2yk8pyo0adR*.7kCMdnj";
|
||||
final var details = new StreamDetails(new ByteArrayInputStream(bytes), "video/mp4", bytes.length);
|
||||
final var attachment = AttachmentUtils.createAttachmentStream(details,
|
||||
Optional.of("clip.mp4"), false, new AttachmentDimensions(1080, 1920), blurHash, null);
|
||||
Optional.of("clip.mp4"),
|
||||
false,
|
||||
new AttachmentDimensions(1080, 1920),
|
||||
blurHash,
|
||||
null);
|
||||
|
||||
assertEquals(1080, attachment.getWidth());
|
||||
assertEquals(1920, attachment.getHeight());
|
||||
@@ -64,7 +68,11 @@ class AttachmentUtilsTest {
|
||||
final var stream = new ByteArrayInputStream(imageBytes);
|
||||
final var details = new StreamDetails(stream, "image/png", imageBytes.length);
|
||||
final var attachment = AttachmentUtils.createAttachmentStream(details,
|
||||
Optional.of("meme.png"), false, new AttachmentDimensions(100, 200), null, null);
|
||||
Optional.of("meme.png"),
|
||||
false,
|
||||
new AttachmentDimensions(100, 200),
|
||||
null,
|
||||
null);
|
||||
|
||||
assertEquals(imageBytes.length, stream.available());
|
||||
assertEquals(100, attachment.getWidth());
|
||||
|
||||
@@ -224,9 +224,9 @@ public class App {
|
||||
private OutputWriter getOutputWriter(final Command command) throws UserErrorException {
|
||||
final var outputTypeInput = ns.<OutputType>get("output");
|
||||
final var outputType = outputTypeInput == null ? command.getSupportedOutputTypes()
|
||||
.stream()
|
||||
.findFirst()
|
||||
.orElse(null) : outputTypeInput;
|
||||
.stream()
|
||||
.findFirst()
|
||||
.orElse(null) : outputTypeInput;
|
||||
final var writer = new BufferedWriter(new OutputStreamWriter(System.out, IOUtils.getConsoleCharset()));
|
||||
final var outputWriter = outputType == null
|
||||
? null
|
||||
|
||||
@@ -614,8 +614,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
||||
writer.println("Size: {}{}",
|
||||
attachment.size().isPresent() ? attachment.size().get() + " bytes" : "<unavailable>",
|
||||
attachment.preview().isPresent() ? " (Preview is available: "
|
||||
+ attachment.preview().get().length
|
||||
+ " bytes)" : "");
|
||||
+ attachment.preview().get().length
|
||||
+ " bytes)" : "");
|
||||
}
|
||||
if (attachment.thumbnail().isPresent()) {
|
||||
writer.println("Thumbnail:");
|
||||
|
||||
@@ -109,7 +109,7 @@ public class ListContactsCommand implements JsonRpcLocalCommand {
|
||||
r.getProfile().getPhoneNumberSharingMode() == null
|
||||
? ""
|
||||
: String.valueOf(r.getProfile().getPhoneNumberSharingMode()
|
||||
== PhoneNumberSharingMode.EVERYBODY),
|
||||
== PhoneNumberSharingMode.EVERYBODY),
|
||||
r.getDiscoverable() == null ? "" : String.valueOf(r.getDiscoverable()));
|
||||
}
|
||||
}
|
||||
@@ -121,17 +121,17 @@ public class ListContactsCommand implements JsonRpcLocalCommand {
|
||||
final var jsonInternal = !internal
|
||||
? null
|
||||
: new JsonContact.JsonInternal(r.getProfile()
|
||||
.getCapabilities()
|
||||
.stream()
|
||||
.map(Enum::name)
|
||||
.toList(),
|
||||
.getCapabilities()
|
||||
.stream()
|
||||
.map(Enum::name)
|
||||
.toList(),
|
||||
r.getProfile().getUnidentifiedAccessMode() == Profile.UnidentifiedAccessMode.UNKNOWN
|
||||
? null
|
||||
? null
|
||||
: r.getProfile().getUnidentifiedAccessMode().name(),
|
||||
r.getProfile().getPhoneNumberSharingMode() == null
|
||||
? null
|
||||
? null
|
||||
: r.getProfile().getPhoneNumberSharingMode()
|
||||
== PhoneNumberSharingMode.EVERYBODY,
|
||||
== PhoneNumberSharingMode.EVERYBODY,
|
||||
r.getDiscoverable());
|
||||
return new JsonContact(address.number().orElse(null),
|
||||
address.uuid().map(UUID::toString).orElse(null),
|
||||
@@ -159,9 +159,9 @@ public class ListContactsCommand implements JsonRpcLocalCommand {
|
||||
r.getProfile().getAboutEmoji(),
|
||||
r.getProfile().getAvatarUrlPath() != null,
|
||||
r.getProfile().getMobileCoinAddress() == null
|
||||
? null
|
||||
? null
|
||||
: Base64.getEncoder()
|
||||
.encodeToString(r.getProfile().getMobileCoinAddress())),
|
||||
.encodeToString(r.getProfile().getMobileCoinAddress())),
|
||||
jsonInternal);
|
||||
}).toList();
|
||||
writer.write(jsonContacts);
|
||||
|
||||
@@ -715,7 +715,7 @@ public class DbusSignalImpl implements Signal, AutoCloseable {
|
||||
retryAfterMilliseconds == null
|
||||
? ""
|
||||
: ", retry at " + DateUtils.formatTimestamp(System.currentTimeMillis()
|
||||
+ retryAfterMilliseconds)
|
||||
+ retryAfterMilliseconds)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ record JsonDataMessage(
|
||||
static JsonDataMessage from(MessageEnvelope.Data dataMessage, Manager m) {
|
||||
final var timestamp = dataMessage.timestamp();
|
||||
final var groupInfo = dataMessage.groupContext().isPresent() ? JsonGroupInfo.from(dataMessage.groupContext()
|
||||
.get(), m) : null;
|
||||
.get(), m) : null;
|
||||
final var storyContext = dataMessage.storyContext().isPresent()
|
||||
? JsonStoryContext.from(dataMessage.storyContext().get())
|
||||
: null;
|
||||
@@ -59,32 +59,32 @@ record JsonDataMessage(
|
||||
final var quote = dataMessage.quote().isPresent() ? JsonQuote.from(dataMessage.quote().get()) : null;
|
||||
final var payment = dataMessage.payment().isPresent() ? JsonPayment.from(dataMessage.payment().get()) : null;
|
||||
final var mentions = !dataMessage.mentions().isEmpty() ? dataMessage.mentions()
|
||||
.stream()
|
||||
.map(JsonMention::from)
|
||||
.toList() : null;
|
||||
.stream()
|
||||
.map(JsonMention::from)
|
||||
.toList() : null;
|
||||
final var previews = !dataMessage.previews().isEmpty() ? dataMessage.previews()
|
||||
.stream()
|
||||
.map(JsonPreview::from)
|
||||
.toList() : null;
|
||||
.stream()
|
||||
.map(JsonPreview::from)
|
||||
.toList() : null;
|
||||
final var remoteDelete = dataMessage.remoteDeleteId().isPresent()
|
||||
? new JsonRemoteDelete(dataMessage.remoteDeleteId().get())
|
||||
: null;
|
||||
final var attachments = !dataMessage.attachments().isEmpty() ? dataMessage.attachments()
|
||||
.stream()
|
||||
.map(JsonAttachment::from)
|
||||
.toList() : null;
|
||||
.stream()
|
||||
.map(JsonAttachment::from)
|
||||
.toList() : null;
|
||||
final var sticker = dataMessage.sticker().isPresent() ? JsonSticker.from(dataMessage.sticker().get()) : null;
|
||||
final var contacts = !dataMessage.sharedContacts().isEmpty() ? dataMessage.sharedContacts()
|
||||
.stream()
|
||||
.map(JsonSharedContact::from)
|
||||
.toList() : null;
|
||||
.stream()
|
||||
.map(JsonSharedContact::from)
|
||||
.toList() : null;
|
||||
final var pollCreate = dataMessage.pollCreate().map(JsonPollCreate::from).orElse(null);
|
||||
final var pollVote = dataMessage.pollVote().map(JsonPollVote::from).orElse(null);
|
||||
final var pollTerminate = dataMessage.pollTerminate().map(JsonPollTerminate::from).orElse(null);
|
||||
final var textStyles = !dataMessage.textStyles().isEmpty() ? dataMessage.textStyles()
|
||||
.stream()
|
||||
.map(JsonTextStyle::from)
|
||||
.toList() : null;
|
||||
.stream()
|
||||
.map(JsonTextStyle::from)
|
||||
.toList() : null;
|
||||
final var pinMessage = dataMessage.pinMessage().map(JsonPinMessage::from).orElse(null);
|
||||
final var unpinMessage = dataMessage.unpinMessage().map(JsonUnpinMessage::from).orElse(null);
|
||||
final var adminDelete = dataMessage.adminDelete().map(JsonAdminDelete::from).orElse(null);
|
||||
|
||||
@@ -34,14 +34,14 @@ public record JsonQuote(
|
||||
: null;
|
||||
|
||||
final var attachments = !quote.attachments().isEmpty() ? quote.attachments()
|
||||
.stream()
|
||||
.map(JsonQuotedAttachment::from)
|
||||
.toList() : List.<JsonQuotedAttachment>of();
|
||||
.stream()
|
||||
.map(JsonQuotedAttachment::from)
|
||||
.toList() : List.<JsonQuotedAttachment>of();
|
||||
|
||||
final var textStyles = !quote.textStyles().isEmpty() ? quote.textStyles()
|
||||
.stream()
|
||||
.map(JsonTextStyle::from)
|
||||
.toList() : null;
|
||||
.stream()
|
||||
.map(JsonTextStyle::from)
|
||||
.toList() : null;
|
||||
|
||||
return new JsonQuote(id, author, authorNumber, authorUuid, text, mentions, attachments, textStyles);
|
||||
}
|
||||
|
||||
@@ -27,13 +27,13 @@ public record JsonSendMessageResult(
|
||||
result.isSuccess()
|
||||
? Type.SUCCESS
|
||||
: result.isRateLimitFailure()
|
||||
? Type.RATE_LIMIT_FAILURE
|
||||
? Type.RATE_LIMIT_FAILURE
|
||||
: result.isNetworkFailure()
|
||||
? Type.NETWORK_FAILURE
|
||||
? Type.NETWORK_FAILURE
|
||||
: result.isUnregisteredFailure()
|
||||
? Type.UNREGISTERED_FAILURE
|
||||
? Type.UNREGISTERED_FAILURE
|
||||
: result.isInvalidPreKeyFailure()
|
||||
? Type.INVALID_PRE_KEY_FAILURE
|
||||
? Type.INVALID_PRE_KEY_FAILURE
|
||||
: Type.IDENTITY_FAILURE,
|
||||
result.proofRequiredFailure() != null ? result.proofRequiredFailure().getToken() : null,
|
||||
rateLimitRetryAfterMilliseconds == null ? null : Math.ceilDiv(rateLimitRetryAfterMilliseconds, 1000L));
|
||||
|
||||
@@ -31,9 +31,9 @@ public record JsonSharedContact(
|
||||
: null;
|
||||
|
||||
final var address = !contact.address().isEmpty() ? contact.address()
|
||||
.stream()
|
||||
.map(JsonContactAddress::from)
|
||||
.toList() : null;
|
||||
.stream()
|
||||
.map(JsonContactAddress::from)
|
||||
.toList() : null;
|
||||
|
||||
final var organization = contact.organization().orElse(null);
|
||||
|
||||
|
||||
@@ -50,9 +50,9 @@ record JsonSyncMessage(
|
||||
}
|
||||
|
||||
final var readMessages = !syncMessage.read().isEmpty() ? syncMessage.read()
|
||||
.stream()
|
||||
.map(JsonSyncReadMessage::from)
|
||||
.toList() : null;
|
||||
.stream()
|
||||
.map(JsonSyncReadMessage::from)
|
||||
.toList() : null;
|
||||
|
||||
final JsonSyncMessageType type;
|
||||
if (syncMessage.contacts().isPresent()) {
|
||||
|
||||
@@ -29,42 +29,65 @@ class SendCommandParsingTest {
|
||||
@Test
|
||||
void cliPreservesEmptyAndMissingDimensionPositions() throws Exception {
|
||||
final var parser = ArgumentParsers.newFor("signal-cli", DefaultSettings.VERSION_0_9_0_DEFAULT_SETTINGS)
|
||||
.includeArgumentNamesAsKeysInResult(true).build();
|
||||
.includeArgumentNamesAsKeysInResult(true)
|
||||
.build();
|
||||
new SendCommand().attachToSubparser(parser.addSubparsers().addParser("send"));
|
||||
final var message = send(parser.parseArgs(new String[]{"send", "--note-to-self",
|
||||
"-a", "photo.jpg", "portrait.mp4", "other.mp4", "--attachment-dimensions", "", "1080x1920"}));
|
||||
final var message = send(parser.parseArgs(new String[]{
|
||||
"send",
|
||||
"--note-to-self",
|
||||
"-a",
|
||||
"photo.jpg",
|
||||
"portrait.mp4",
|
||||
"other.mp4",
|
||||
"--attachment-dimensions",
|
||||
"",
|
||||
"1080x1920"
|
||||
}));
|
||||
|
||||
assertEquals(ATTACHMENTS, message.attachments());
|
||||
assertEquals(Arrays.asList(null, new Message.AttachmentDimensions(1080, 1920)),
|
||||
message.attachmentDimensions());
|
||||
assertEquals(Arrays.asList(null, new Message.AttachmentDimensions(1080, 1920)), message.attachmentDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
void jsonRpcPassesDimensionsIntoTheSentMessage() throws Exception {
|
||||
final var message = send(namespace(List.of("", "1920x1080")));
|
||||
assertEquals(ATTACHMENTS, message.attachments());
|
||||
assertEquals(Arrays.asList(null, new Message.AttachmentDimensions(1920, 1080)),
|
||||
message.attachmentDimensions());
|
||||
assertEquals(Arrays.asList(null, new Message.AttachmentDimensions(1920, 1080)), message.attachmentDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
void cliPreservesBlurHashPositions() throws Exception {
|
||||
final var parser = ArgumentParsers.newFor("signal-cli", DefaultSettings.VERSION_0_9_0_DEFAULT_SETTINGS)
|
||||
.includeArgumentNamesAsKeysInResult(true).build();
|
||||
.includeArgumentNamesAsKeysInResult(true)
|
||||
.build();
|
||||
new SendCommand().attachToSubparser(parser.addSubparsers().addParser("send"));
|
||||
final var message = send(parser.parseArgs(new String[]{"send", "--note-to-self",
|
||||
"-a", "photo.jpg", "portrait.mp4", "other.mp4", "--attachment-blurhash", "", BLUR_HASH}));
|
||||
final var message = send(parser.parseArgs(new String[]{
|
||||
"send",
|
||||
"--note-to-self",
|
||||
"-a",
|
||||
"photo.jpg",
|
||||
"portrait.mp4",
|
||||
"other.mp4",
|
||||
"--attachment-blurhash",
|
||||
"",
|
||||
BLUR_HASH
|
||||
}));
|
||||
|
||||
assertEquals(List.of("", BLUR_HASH), message.attachmentBlurHashes());
|
||||
}
|
||||
|
||||
@Test
|
||||
void jsonRpcPassesBlurHashesWithDimensions() throws Exception {
|
||||
final var message = send(new JsonRpcNamespace(Map.of("noteToSelf", true, "attachments", ATTACHMENTS,
|
||||
"attachmentDimensions", List.of("", "1920x1080"), "attachmentBlurhash", List.of("", BLUR_HASH))));
|
||||
final var message = send(new JsonRpcNamespace(Map.of("noteToSelf",
|
||||
true,
|
||||
"attachments",
|
||||
ATTACHMENTS,
|
||||
"attachmentDimensions",
|
||||
List.of("", "1920x1080"),
|
||||
"attachmentBlurhash",
|
||||
List.of("", BLUR_HASH))));
|
||||
|
||||
assertEquals(Arrays.asList(null, new Message.AttachmentDimensions(1920, 1080)),
|
||||
message.attachmentDimensions());
|
||||
assertEquals(Arrays.asList(null, new Message.AttachmentDimensions(1920, 1080)), message.attachmentDimensions());
|
||||
assertEquals(List.of("", BLUR_HASH), message.attachmentBlurHashes());
|
||||
}
|
||||
|
||||
@@ -91,27 +114,37 @@ class SendCommandParsingTest {
|
||||
}
|
||||
|
||||
private JsonRpcNamespace blurHashNamespace(List<String> blurHashes) {
|
||||
return new JsonRpcNamespace(Map.of("noteToSelf", true, "attachments", ATTACHMENTS,
|
||||
"attachmentBlurhash", blurHashes));
|
||||
return new JsonRpcNamespace(Map.of("noteToSelf",
|
||||
true,
|
||||
"attachments",
|
||||
ATTACHMENTS,
|
||||
"attachmentBlurhash",
|
||||
blurHashes));
|
||||
}
|
||||
|
||||
private JsonRpcNamespace namespace(List<String> dimensions) {
|
||||
return new JsonRpcNamespace(Map.of("noteToSelf", true, "attachments", ATTACHMENTS,
|
||||
"attachmentDimensions", dimensions));
|
||||
return new JsonRpcNamespace(Map.of("noteToSelf",
|
||||
true,
|
||||
"attachments",
|
||||
ATTACHMENTS,
|
||||
"attachmentDimensions",
|
||||
dimensions));
|
||||
}
|
||||
|
||||
private Message send(Namespace namespace) throws Exception {
|
||||
final var captured = new AtomicReference<Message>();
|
||||
final var delegate = ManagerMock.create("+15551234567");
|
||||
final var manager = (Manager) Proxy.newProxyInstance(Manager.class.getClassLoader(),
|
||||
new Class<?>[]{Manager.class}, (proxy, method, args) -> {
|
||||
new Class<?>[]{Manager.class},
|
||||
(proxy, method, args) -> {
|
||||
if (method.getName().equals("sendMessage")) {
|
||||
captured.set((Message) args[0]);
|
||||
return new SendMessageResults(1, Map.of());
|
||||
}
|
||||
return method.invoke(delegate, args);
|
||||
});
|
||||
new SendCommand().handleCommand(namespace, manager, (JsonWriter) ignored -> {});
|
||||
new SendCommand().handleCommand(namespace, manager, (JsonWriter) ignored -> {
|
||||
});
|
||||
return captured.get();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user