Removed old comments, simplified if-statement and added a 'leadingSpaces' field to the print attachments/mentions functions

This commit is contained in:
david-harley 2021-02-18 09:43:11 +10:30
parent 7317291d7a
commit 7191e4371b
2 changed files with 44 additions and 28 deletions

View file

@ -1554,16 +1554,17 @@ public class Manager implements Closeable {
} }
} }
} }
if (message.getAttachments().isPresent() && !ignoreAttachments) { if (!ignoreAttachments) {
for (SignalServiceAttachment attachment : message.getAttachments().get()) { if (message.getAttachments().isPresent()) {
downloadAttachment(attachment); for (SignalServiceAttachment attachment : message.getAttachments().get()) {
downloadAttachment(attachment);
}
} }
} if (message.getSharedContacts().isPresent()) {
if (message.getSharedContacts().isPresent() && !ignoreAttachments) { for (SharedContact contact : message.getSharedContacts().get()) {
for (SharedContact contact : message.getSharedContacts().get()) { if (contact.getAvatar().isPresent()) {
if (contact.getAvatar().isPresent()) { downloadAttachment(contact.getAvatar().get().getAttachment());
// TODO probably should save to contacts instead }
downloadAttachment(contact.getAvatar().get().getAttachment());
} }
} }
} }

View file

@ -117,11 +117,11 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
} else { } else {
System.out.println("Received sync contacts"); System.out.println("Received sync contacts");
} }
printAttachment(contactsMessage.getContactsStream()); printAttachment(contactsMessage.getContactsStream(), 0);
} }
if (syncMessage.getGroups().isPresent()) { if (syncMessage.getGroups().isPresent()) {
System.out.println("Received sync groups"); System.out.println("Received sync groups");
printAttachment(syncMessage.getGroups().get()); printAttachment(syncMessage.getGroups().get(), 0);
} }
if (syncMessage.getRead().isPresent()) { if (syncMessage.getRead().isPresent()) {
System.out.println("Received sync read messages list"); System.out.println("Received sync read messages list");
@ -393,7 +393,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
} }
if (groupInfo.getAvatar().isPresent()) { if (groupInfo.getAvatar().isPresent()) {
System.out.println(" Avatar:"); System.out.println(" Avatar:");
printAttachment(groupInfo.getAvatar().get()); printAttachment(groupInfo.getAvatar().get(), 2);
} }
} else if (groupContext.getGroupV2().isPresent()) { } else if (groupContext.getGroupV2().isPresent()) {
final SignalServiceGroupV2 groupInfo = groupContext.getGroupV2().get(); 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(" - Title: " + preview.getTitle());
System.out.println(" - Url: " + preview.getUrl()); System.out.println(" - Url: " + preview.getUrl());
if (preview.getImage().isPresent()) { 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()) { if (contact.getAvatar().isPresent()) {
SharedContact.Avatar avatar = contact.getAvatar().get(); SharedContact.Avatar avatar = contact.getAvatar().get();
System.out.println(" - Avatar:"); System.out.println(" - Avatar:");
printAttachment(avatar.getAttachment()); printAttachment(avatar.getAttachment(), 3);
if (avatar.isProfile()) { if (avatar.isProfile()) {
System.out.println(" - Is profile"); System.out.println(" - Is profile");
} else { } else {
@ -575,7 +575,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
if (quote.getMentions() != null && quote.getMentions().size() > 0) { if (quote.getMentions() != null && quote.getMentions().size() > 0) {
System.out.println(" Mentions: "); System.out.println(" Mentions: ");
for (SignalServiceDataMessage.Mention mention : quote.getMentions()) { for (SignalServiceDataMessage.Mention mention : quote.getMentions()) {
printMention(mention, m); printMention(mention, m, 1);
} }
} }
if (quote.getAttachments().size() > 0) { if (quote.getAttachments().size() > 0) {
@ -585,7 +585,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler {
System.out.println(" Type: " + attachment.getContentType()); System.out.println(" Type: " + attachment.getContentType());
System.out.println(" Thumbnail:"); System.out.println(" Thumbnail:");
if (attachment.getThumbnail() != null) { 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()) { if (message.getMentions().isPresent()) {
System.out.println("Mentions: "); System.out.println("Mentions: ");
for (SignalServiceDataMessage.Mention mention : message.getMentions().get()) { for (SignalServiceDataMessage.Mention mention : message.getMentions().get()) {
printMention(mention, m); printMention(mention, m, 0);
} }
} }
if (message.getAttachments().isPresent()) { if (message.getAttachments().isPresent()) {
System.out.println("Attachments: "); System.out.println("Attachments: ");
for (SignalServiceAttachment attachment : message.getAttachments().get()) { 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() + ")"); .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" : "" attachment.isStream() ? "Stream" : ""
) + ")"); ) + ")");
if (attachment.isPointer()) { if (attachment.isPointer()) {
final SignalServiceAttachmentPointer pointer = attachment.asPointer(); final SignalServiceAttachmentPointer pointer = attachment.asPointer();
System.out.println(" Id: " + pointer.getRemoteId() + " Key length: " + pointer.getKey().length); System.out.println(spaces + " Id: " + pointer.getRemoteId() + " Key length: " + pointer.getKey().length);
System.out.println(" Filename: " + ( System.out.println(spaces + " Filename: " + (
pointer.getFileName().isPresent() ? pointer.getFileName().get() : "-" pointer.getFileName().isPresent() ? pointer.getFileName().get() : "-"
)); ));
System.out.println(" Size: " + ( System.out.println(spaces + " Size: " + (
pointer.getSize().isPresent() ? pointer.getSize().get() + " bytes" : "<unavailable>" pointer.getSize().isPresent() ? pointer.getSize().get() + " bytes" : "<unavailable>"
) + ( ) + (
pointer.getPreview().isPresent() ? " (Preview is available: " pointer.getPreview().isPresent() ? " (Preview is available: "
+ pointer.getPreview().get().length + pointer.getPreview().get().length
+ " bytes)" : "" + " bytes)" : ""
)); ));
System.out.println(" Voice note: " + (pointer.getVoiceNote() ? "yes" : "no")); System.out.println(spaces + " Voice note: " + (pointer.getVoiceNote() ? "yes" : "no"));
System.out.println(" Dimensions: " + pointer.getWidth() + "x" + pointer.getHeight()); System.out.println(spaces + " Dimensions: " + pointer.getWidth() + "x" + pointer.getHeight());
File file = m.getAttachmentFile(pointer.getRemoteId()); File file = m.getAttachmentFile(pointer.getRemoteId());
if (file.exists()) { if (file.exists()) {
System.out.println(" Stored plaintext in: " + file); System.out.println(spaces + " Stored plaintext in: " + file);
} }
} }
} }