mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-29 10:30:38 +00:00
If contact name is not set, print profile name instead
This commit is contained in:
parent
804ad34a08
commit
f4ed9a01b7
2 changed files with 27 additions and 15 deletions
|
@ -3,7 +3,6 @@ package org.asamk.signal;
|
|||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.groups.GroupId;
|
||||
import org.asamk.signal.manager.groups.GroupUtils;
|
||||
import org.asamk.signal.manager.storage.contacts.ContactInfo;
|
||||
import org.asamk.signal.manager.storage.groups.GroupInfo;
|
||||
import org.asamk.signal.util.DateUtils;
|
||||
import org.asamk.signal.util.Util;
|
||||
|
@ -53,9 +52,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());
|
||||
|
@ -98,10 +97,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();
|
||||
|
@ -127,10 +125,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()));
|
||||
}
|
||||
|
@ -159,13 +158,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(" ");
|
||||
}
|
||||
|
|
|
@ -137,6 +137,7 @@ import org.whispersystems.signalservice.internal.push.SignalServiceProtos;
|
|||
import org.whispersystems.signalservice.internal.push.UnsupportedDataMessageException;
|
||||
import org.whispersystems.signalservice.internal.util.DynamicCredentialsProvider;
|
||||
import org.whispersystems.signalservice.internal.util.Hex;
|
||||
import org.whispersystems.signalservice.internal.util.Util;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
|
@ -2304,8 +2305,20 @@ public class Manager implements Closeable {
|
|||
return account.getContactStore().getContacts();
|
||||
}
|
||||
|
||||
public ContactInfo getContact(String number) {
|
||||
return account.getContactStore().getContact(Utils.getSignalServiceAddressFromIdentifier(number));
|
||||
public String getContactOrProfileName(String number) {
|
||||
final SignalServiceAddress address = Utils.getSignalServiceAddressFromIdentifier(number);
|
||||
|
||||
final ContactInfo contact = account.getContactStore().getContact(address);
|
||||
if (contact != null && !Util.isEmpty(contact.name)) {
|
||||
return contact.name;
|
||||
}
|
||||
|
||||
final SignalProfileEntry profileEntry = account.getProfileStore().getProfileEntry(address);
|
||||
if (profileEntry != null && profileEntry.getProfile() != null) {
|
||||
return profileEntry.getProfile().getName();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public GroupInfo getGroup(GroupId groupId) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue