X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/c10910e4660e96c24dce35455c31ec8056d9088c..07972175881d5e749e1e4efff92ac7d0211ff241:/src/main/java/org/asamk/signal/ReceiveMessageHandler.java diff --git a/src/main/java/org/asamk/signal/ReceiveMessageHandler.java b/src/main/java/org/asamk/signal/ReceiveMessageHandler.java index 5925b2b8..07dbfd1d 100644 --- a/src/main/java/org/asamk/signal/ReceiveMessageHandler.java +++ b/src/main/java/org/asamk/signal/ReceiveMessageHandler.java @@ -1,9 +1,9 @@ package org.asamk.signal; -import org.asamk.signal.manager.GroupUtils; import org.asamk.signal.manager.Manager; -import org.asamk.signal.storage.contacts.ContactInfo; -import org.asamk.signal.storage.groups.GroupInfo; +import org.asamk.signal.manager.groups.GroupId; +import org.asamk.signal.manager.groups.GroupUtils; +import org.asamk.signal.manager.storage.groups.GroupInfo; import org.asamk.signal.util.DateUtils; import org.asamk.signal.util.Util; import org.whispersystems.signalservice.api.messages.SignalServiceAttachment; @@ -21,6 +21,7 @@ import org.whispersystems.signalservice.api.messages.calls.BusyMessage; import org.whispersystems.signalservice.api.messages.calls.HangupMessage; import org.whispersystems.signalservice.api.messages.calls.IceUpdateMessage; import org.whispersystems.signalservice.api.messages.calls.OfferMessage; +import org.whispersystems.signalservice.api.messages.calls.OpaqueMessage; import org.whispersystems.signalservice.api.messages.calls.SignalServiceCallMessage; import org.whispersystems.signalservice.api.messages.multidevice.BlockedListMessage; import org.whispersystems.signalservice.api.messages.multidevice.ConfigurationMessage; @@ -35,9 +36,9 @@ import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage import org.whispersystems.signalservice.api.messages.multidevice.ViewOnceOpenMessage; import org.whispersystems.signalservice.api.messages.shared.SharedContact; import org.whispersystems.signalservice.api.push.SignalServiceAddress; -import org.whispersystems.util.Base64; import java.io.File; +import java.util.Base64; import java.util.List; public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { @@ -52,9 +53,9 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { public void handleMessage(SignalServiceEnvelope envelope, SignalServiceContent content, Throwable exception) { if (!envelope.isUnidentifiedSender() && envelope.hasSource()) { SignalServiceAddress source = envelope.getSourceAddress(); - ContactInfo sourceContact = m.getContact(source.getLegacyIdentifier()); + String name = m.getContactOrProfileName(source.getLegacyIdentifier()); System.out.println(String.format("Envelope from: %s (device: %d)", - (sourceContact == null ? "" : "“" + sourceContact.name + "” ") + source.getLegacyIdentifier(), + (name == null ? "" : "“" + name + "” ") + source.getLegacyIdentifier(), envelope.getSourceDevice())); if (source.getRelay().isPresent()) { System.out.println("Relayed by: " + source.getRelay().get()); @@ -97,10 +98,9 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { if (content == null) { System.out.println("Failed to decrypt message."); } else { - ContactInfo sourceContact = m.getContact(content.getSender().getLegacyIdentifier()); + String senderName = m.getContactOrProfileName(content.getSender().getLegacyIdentifier()); System.out.println(String.format("Sender: %s (device: %d)", - (sourceContact == null ? "" : "“" + sourceContact.name + "” ") + content.getSender() - .getLegacyIdentifier(), + (senderName == null ? "" : "“" + senderName + "” ") + content.getSender().getLegacyIdentifier(), content.getSenderDevice())); if (content.getDataMessage().isPresent()) { SignalServiceDataMessage message = content.getDataMessage().get(); @@ -126,10 +126,11 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { if (syncMessage.getRead().isPresent()) { System.out.println("Received sync read messages list"); for (ReadMessage rm : syncMessage.getRead().get()) { - ContactInfo fromContact = m.getContact(rm.getSender().getLegacyIdentifier()); + String name = m.getContactOrProfileName(rm.getSender().getLegacyIdentifier()); System.out.println("From: " - + (fromContact == null ? "" : "“" + fromContact.name + "” ") - + rm.getSender().getLegacyIdentifier() + + (name == null ? "" : "“" + name + "” ") + + rm.getSender() + .getLegacyIdentifier() + " Message timestamp: " + DateUtils.formatTimestamp(rm.getTimestamp())); } @@ -158,13 +159,13 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { String to; if (sentTranscriptMessage.getDestination().isPresent()) { String dest = sentTranscriptMessage.getDestination().get().getLegacyIdentifier(); - ContactInfo destContact = m.getContact(dest); - to = (destContact == null ? "" : "“" + destContact.name + "” ") + dest; + String name = m.getContactOrProfileName(dest); + to = (name == null ? "" : "“" + name + "” ") + dest; } else if (sentTranscriptMessage.getRecipients().size() > 0) { StringBuilder toBuilder = new StringBuilder(); for (SignalServiceAddress dest : sentTranscriptMessage.getRecipients()) { - ContactInfo destContact = m.getContact(dest.getLegacyIdentifier()); - toBuilder.append(destContact == null ? "" : "“" + destContact.name + "” ") + String name = m.getContactOrProfileName(dest.getLegacyIdentifier()); + toBuilder.append(name == null ? "" : "“" + name + "” ") .append(dest.getLegacyIdentifier()) .append(" "); } @@ -243,10 +244,12 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { for (StickerPackOperationMessage m : stickerPackOperationMessages) { System.out.println(" - " + m.getType().toString()); if (m.getPackId().isPresent()) { - System.out.println(" packId: " + Base64.encodeBytes(m.getPackId().get())); + System.out.println(" packId: " + Base64.getEncoder() + .encodeToString(m.getPackId().get())); } if (m.getPackKey().isPresent()) { - System.out.println(" packKey: " + Base64.encodeBytes(m.getPackKey().get())); + System.out.println(" packKey: " + Base64.getEncoder() + .encodeToString(m.getPackKey().get())); } } } @@ -256,8 +259,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { System.out.println("Received message request response:"); System.out.println(" Type: " + requestResponseMessage.getType()); if (requestResponseMessage.getGroupId().isPresent()) { - System.out.println(" Group id: " + Base64.encodeBytes(requestResponseMessage.getGroupId() - .get())); + System.out.println(" Group id: " + Base64.getEncoder() + .encodeToString(requestResponseMessage.getGroupId().get())); } if (requestResponseMessage.getPerson().isPresent()) { System.out.println(" Person: " + requestResponseMessage.getPerson() @@ -280,6 +283,10 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { if (content.getCallMessage().isPresent()) { System.out.println("Received a call message"); SignalServiceCallMessage callMessage = content.getCallMessage().get(); + if (callMessage.getDestinationDeviceId().isPresent()) { + final Integer deviceId = callMessage.getDestinationDeviceId().get(); + System.out.println("Destination device id: " + deviceId); + } if (callMessage.getAnswerMessage().isPresent()) { AnswerMessage answerMessage = callMessage.getAnswerMessage().get(); System.out.println("Answer message: " + answerMessage.getId() + ": " + answerMessage.getSdp()); @@ -305,6 +312,10 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { OfferMessage offerMessage = callMessage.getOfferMessage().get(); System.out.println("Offer message: " + offerMessage.getId() + ": " + offerMessage.getSdp()); } + if (callMessage.getOpaqueMessage().isPresent()) { + final OpaqueMessage opaqueMessage = callMessage.getOpaqueMessage().get(); + System.out.println("Opaque message: size " + opaqueMessage.getOpaque().length); + } } if (content.getReceiptMessage().isPresent()) { System.out.println("Received a receipt message"); @@ -316,6 +327,9 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { if (receiptMessage.isReadReceipt()) { System.out.println(" - Is read receipt"); } + if (receiptMessage.isViewedReceipt()) { + System.out.println(" - Is viewed receipt"); + } System.out.println(" - Timestamps:"); for (long timestamp : receiptMessage.getTimestamps()) { System.out.println(" " + DateUtils.formatTimestamp(timestamp)); @@ -328,8 +342,9 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { System.out.println(" - Timestamp: " + DateUtils.formatTimestamp(typingMessage.getTimestamp())); if (typingMessage.getGroupId().isPresent()) { System.out.println(" - Group Info:"); - System.out.println(" Id: " + Base64.encodeBytes(typingMessage.getGroupId().get())); - GroupInfo group = m.getGroup(typingMessage.getGroupId().get()); + final GroupId groupId = GroupId.unknownVersion(typingMessage.getGroupId().get()); + System.out.println(" Id: " + groupId.toBase64()); + GroupInfo group = m.getGroup(groupId); if (group != null) { System.out.println(" Name: " + group.getTitle()); } else { @@ -356,13 +371,14 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { if (message.getGroupContext().isPresent()) { System.out.println("Group info:"); final SignalServiceGroupContext groupContext = message.getGroupContext().get(); + final GroupId groupId = GroupUtils.getGroupId(groupContext); if (groupContext.getGroupV1().isPresent()) { SignalServiceGroup groupInfo = groupContext.getGroupV1().get(); - System.out.println(" Id: " + Base64.encodeBytes(groupInfo.getGroupId())); + System.out.println(" Id: " + groupId.toBase64()); if (groupInfo.getType() == SignalServiceGroup.Type.UPDATE && groupInfo.getName().isPresent()) { System.out.println(" Name: " + groupInfo.getName().get()); } else { - GroupInfo group = m.getGroup(groupInfo.getGroupId()); + GroupInfo group = m.getGroup(groupId); if (group != null) { System.out.println(" Name: " + group.getTitle()); } else { @@ -381,8 +397,7 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { } } else if (groupContext.getGroupV2().isPresent()) { final SignalServiceGroupV2 groupInfo = groupContext.getGroupV2().get(); - byte[] groupId = GroupUtils.getGroupId(groupInfo.getMasterKey()); - System.out.println(" Id: " + Base64.encodeBytes(groupId)); + System.out.println(" Id: " + groupId.toBase64()); GroupInfo group = m.getGroup(groupId); if (group != null) { System.out.println(" Name: " + group.getTitle()); @@ -394,6 +409,11 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { System.out.println(" Has signed group change: " + groupInfo.hasSignedGroupChange()); } } + if (message.getGroupCallUpdate().isPresent()) { + final SignalServiceDataMessage.GroupCallUpdate groupCallUpdate = message.getGroupCallUpdate().get(); + System.out.println("Group call update:"); + System.out.println(" - Era id: " + groupCallUpdate.getEraId()); + } if (message.getPreviews().isPresent()) { final List previews = message.getPreviews().get(); System.out.println("Previews:"); @@ -416,8 +436,8 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { if (message.getSticker().isPresent()) { final SignalServiceDataMessage.Sticker sticker = message.getSticker().get(); System.out.println("Sticker:"); - System.out.println(" - Pack id: " + Base64.encodeBytes(sticker.getPackId())); - System.out.println(" - Pack key: " + Base64.encodeBytes(sticker.getPackKey())); + System.out.println(" - Pack id: " + Base64.getEncoder().encodeToString(sticker.getPackId())); + System.out.println(" - Pack key: " + Base64.getEncoder().encodeToString(sticker.getPackKey())); System.out.println(" - Sticker id: " + sticker.getStickerId()); // TODO also download sticker image ?? } @@ -447,14 +467,20 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { if (message.getQuote().isPresent()) { SignalServiceDataMessage.Quote quote = message.getQuote().get(); System.out.println("Quote: (" + quote.getId() + ")"); - System.out.println(" Author: " + quote.getAuthor().getLegacyIdentifier()); + System.out.println(" Author: " + m.resolveSignalServiceAddress(quote.getAuthor()).getLegacyIdentifier()); System.out.println(" Text: " + quote.getText()); + if (quote.getMentions() != null && quote.getMentions().size() > 0) { + System.out.println(" Mentions: "); + for (SignalServiceDataMessage.Mention mention : quote.getMentions()) { + printMention(mention, m); + } + } if (quote.getAttachments().size() > 0) { System.out.println(" Attachments: "); for (SignalServiceDataMessage.Quote.QuotedAttachment attachment : quote.getAttachments()) { - System.out.println(" Filename: " + attachment.getFileName()); - System.out.println(" Type: " + attachment.getContentType()); - System.out.println(" Thumbnail:"); + System.out.println(" - Filename: " + attachment.getFileName()); + System.out.println(" Type: " + attachment.getContentType()); + System.out.println(" Thumbnail:"); if (attachment.getThumbnail() != null) { printAttachment(attachment.getThumbnail()); } @@ -467,16 +493,9 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { System.out.println("Remote delete message: timestamp = " + remoteDelete.getTargetSentTimestamp()); } if (message.getMentions().isPresent()) { - final List mentions = message.getMentions().get(); System.out.println("Mentions: "); - for (SignalServiceDataMessage.Mention mention : mentions) { - System.out.println("- " - + mention.getUuid() - + ": " - + mention.getStart() - + " (length: " - + mention.getLength() - + ")"); + for (SignalServiceDataMessage.Mention mention : message.getMentions().get()) { + printMention(mention, m); } } @@ -488,6 +507,11 @@ public class ReceiveMessageHandler implements Manager.ReceiveMessageHandler { } } + private void printMention(SignalServiceDataMessage.Mention mention, Manager m) { + System.out.println("- " + 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" : "") + ( attachment.isStream() ? "Stream" : ""