mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-02 12:30:39 +00:00
Removed old comments, simplified if-statement and added a 'leadingSpaces' field to the print attachments/mentions functions
This commit is contained in:
parent
7317291d7a
commit
7191e4371b
2 changed files with 44 additions and 28 deletions
|
@ -1554,16 +1554,17 @@ public class Manager implements Closeable {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (message.getAttachments().isPresent() && !ignoreAttachments) {
|
||||
for (SignalServiceAttachment attachment : message.getAttachments().get()) {
|
||||
downloadAttachment(attachment);
|
||||
if (!ignoreAttachments) {
|
||||
if (message.getAttachments().isPresent()) {
|
||||
for (SignalServiceAttachment attachment : message.getAttachments().get()) {
|
||||
downloadAttachment(attachment);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (message.getSharedContacts().isPresent() && !ignoreAttachments) {
|
||||
for (SharedContact contact : message.getSharedContacts().get()) {
|
||||
if (contact.getAvatar().isPresent()) {
|
||||
// TODO probably should save to contacts instead
|
||||
downloadAttachment(contact.getAvatar().get().getAttachment());
|
||||
if (message.getSharedContacts().isPresent()) {
|
||||
for (SharedContact contact : message.getSharedContacts().get()) {
|
||||
if (contact.getAvatar().isPresent()) {
|
||||
downloadAttachment(contact.getAvatar().get().getAttachment());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,11 +117,11 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
} else {
|
||||
System.out.println("Received sync contacts");
|
||||
}
|
||||
printAttachment(contactsMessage.getContactsStream());
|
||||
printAttachment(contactsMessage.getContactsStream(), 0);
|
||||
}
|
||||
if (syncMessage.getGroups().isPresent()) {
|
||||
System.out.println("Received sync groups");
|
||||
printAttachment(syncMessage.getGroups().get());
|
||||
printAttachment(syncMessage.getGroups().get(), 0);
|
||||
}
|
||||
if (syncMessage.getRead().isPresent()) {
|
||||
System.out.println("Received sync read messages list");
|
||||
|
@ -393,7 +393,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
}
|
||||
if (groupInfo.getAvatar().isPresent()) {
|
||||
System.out.println(" Avatar:");
|
||||
printAttachment(groupInfo.getAvatar().get());
|
||||
printAttachment(groupInfo.getAvatar().get(), 2);
|
||||
}
|
||||
} else if (groupContext.getGroupV2().isPresent()) {
|
||||
final SignalServiceGroupV2 groupInfo = groupContext.getGroupV2().get();
|
||||
|
@ -421,7 +421,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
System.out.println(" - Title: " + preview.getTitle());
|
||||
System.out.println(" - Url: " + preview.getUrl());
|
||||
if (preview.getImage().isPresent()) {
|
||||
printAttachment(preview.getImage().get());
|
||||
printAttachment(preview.getImage().get(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -453,7 +453,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
if (contact.getAvatar().isPresent()) {
|
||||
SharedContact.Avatar avatar = contact.getAvatar().get();
|
||||
System.out.println(" - Avatar:");
|
||||
printAttachment(avatar.getAttachment());
|
||||
printAttachment(avatar.getAttachment(), 3);
|
||||
if (avatar.isProfile()) {
|
||||
System.out.println(" - Is profile");
|
||||
} else {
|
||||
|
@ -575,7 +575,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
if (quote.getMentions() != null && quote.getMentions().size() > 0) {
|
||||
System.out.println(" Mentions: ");
|
||||
for (SignalServiceDataMessage.Mention mention : quote.getMentions()) {
|
||||
printMention(mention, m);
|
||||
printMention(mention, m, 1);
|
||||
}
|
||||
}
|
||||
if (quote.getAttachments().size() > 0) {
|
||||
|
@ -585,7 +585,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
System.out.println(" Type: " + attachment.getContentType());
|
||||
System.out.println(" Thumbnail:");
|
||||
if (attachment.getThumbnail() != null) {
|
||||
printAttachment(attachment.getThumbnail());
|
||||
printAttachment(attachment.getThumbnail(), 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -598,45 +598,60 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
|
|||
if (message.getMentions().isPresent()) {
|
||||
System.out.println("Mentions: ");
|
||||
for (SignalServiceDataMessage.Mention mention : message.getMentions().get()) {
|
||||
printMention(mention, m);
|
||||
printMention(mention, m, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (message.getAttachments().isPresent()) {
|
||||
System.out.println("Attachments: ");
|
||||
for (SignalServiceAttachment attachment : message.getAttachments().get()) {
|
||||
printAttachment(attachment);
|
||||
printAttachment(attachment, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void printMention(SignalServiceDataMessage.Mention mention, Manager m) {
|
||||
System.out.println("- " + m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid(), null))
|
||||
/**
|
||||
* Prints the Signal mention information
|
||||
*
|
||||
* @param mention is the Signal mention to print
|
||||
* @param m is the Manager. used to resolve UUIDs into phone numbers if possible
|
||||
* @param leadingSpaces is the number of spaces you want the message to be indented by
|
||||
*/
|
||||
private void printMention(SignalServiceDataMessage.Mention mention, Manager m, int leadingSpaces) {
|
||||
String spaces = " ".repeat(leadingSpaces);
|
||||
System.out.println(spaces + "- " + m.resolveSignalServiceAddress(new SignalServiceAddress(mention.getUuid(), null))
|
||||
.getLegacyIdentifier() + ": " + mention.getStart() + " (length: " + mention.getLength() + ")");
|
||||
}
|
||||
|
||||
private void printAttachment(SignalServiceAttachment attachment) {
|
||||
System.out.println("- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (
|
||||
/**
|
||||
* Prints the Signal attachment information
|
||||
*
|
||||
* @param attachment is the Signal attachment to print
|
||||
* @param leadingSpaces is the number of spaces you want the message to be indented by
|
||||
*/
|
||||
private void printAttachment(SignalServiceAttachment attachment, int leadingSpaces) {
|
||||
String spaces = " ".repeat(leadingSpaces);
|
||||
System.out.println(spaces + "- " + attachment.getContentType() + " (" + (attachment.isPointer() ? "Pointer" : "") + (
|
||||
attachment.isStream() ? "Stream" : ""
|
||||
) + ")");
|
||||
if (attachment.isPointer()) {
|
||||
final SignalServiceAttachmentPointer pointer = attachment.asPointer();
|
||||
System.out.println(" Id: " + pointer.getRemoteId() + " Key length: " + pointer.getKey().length);
|
||||
System.out.println(" Filename: " + (
|
||||
System.out.println(spaces + " Id: " + pointer.getRemoteId() + " Key length: " + pointer.getKey().length);
|
||||
System.out.println(spaces + " Filename: " + (
|
||||
pointer.getFileName().isPresent() ? pointer.getFileName().get() : "-"
|
||||
));
|
||||
System.out.println(" Size: " + (
|
||||
System.out.println(spaces + " Size: " + (
|
||||
pointer.getSize().isPresent() ? pointer.getSize().get() + " bytes" : "<unavailable>"
|
||||
) + (
|
||||
pointer.getPreview().isPresent() ? " (Preview is available: "
|
||||
+ pointer.getPreview().get().length
|
||||
+ " bytes)" : ""
|
||||
));
|
||||
System.out.println(" Voice note: " + (pointer.getVoiceNote() ? "yes" : "no"));
|
||||
System.out.println(" Dimensions: " + pointer.getWidth() + "x" + pointer.getHeight());
|
||||
System.out.println(spaces + " Voice note: " + (pointer.getVoiceNote() ? "yes" : "no"));
|
||||
System.out.println(spaces + " Dimensions: " + pointer.getWidth() + "x" + pointer.getHeight());
|
||||
File file = m.getAttachmentFile(pointer.getRemoteId());
|
||||
if (file.exists()) {
|
||||
System.out.println(" Stored plaintext in: " + file);
|
||||
System.out.println(spaces + " Stored plaintext in: " + file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue