mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-02 20:40:38 +00:00
reverted sendMessage, completed isContactBlocked, fixed formatting
This commit is contained in:
parent
4cea401792
commit
6f04361a01
2 changed files with 109 additions and 121 deletions
|
@ -13,7 +13,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public interface Signal extends DBusInterface {
|
public interface Signal extends DBusInterface {
|
||||||
|
|
||||||
long sendMessageSingle(
|
long sendMessage(
|
||||||
String message, List<String> attachments, String recipient
|
String message, List<String> attachments, String recipient
|
||||||
) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.UntrustedIdentity;
|
) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.UntrustedIdentity;
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class DbusSignalImpl implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long sendMessageSingle(final String message, final List<String> attachments, final String recipient) {
|
public long sendMessage(final String message, final List<String> attachments, final String recipient) {
|
||||||
var recipients = new ArrayList<String>(1);
|
var recipients = new ArrayList<String>(1);
|
||||||
recipients.add(recipient);
|
recipients.add(recipient);
|
||||||
return sendMessage(message, attachments, recipients);
|
return sendMessage(message, attachments, recipients);
|
||||||
|
@ -65,9 +65,8 @@ public class DbusSignalImpl implements Signal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkSendMessageResults(
|
private static void checkSendMessageResults(long timestamp, List<SendMessageResult> results)
|
||||||
long timestamp, List<SendMessageResult> results
|
throws DBusExecutionException {
|
||||||
) throws DBusExecutionException {
|
|
||||||
if (results.size() == 1) {
|
if (results.size() == 1) {
|
||||||
checkSendMessageResult(timestamp, results.get(0));
|
checkSendMessageResult(timestamp, results.get(0));
|
||||||
return;
|
return;
|
||||||
|
@ -90,14 +89,6 @@ public class DbusSignalImpl implements Signal {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long sendMessage(final String message, final List<String> attachments, final List<String> recipients) {
|
public long sendMessage(final String message, final List<String> attachments, final List<String> recipients) {
|
||||||
System.out.println("Sending messsage:"+message);
|
|
||||||
System.out.println("Sending rec:"+recipients);
|
|
||||||
for (String r : recipients) {
|
|
||||||
System.out.println("to:"+r);
|
|
||||||
}
|
|
||||||
for (String r : attachments) {
|
|
||||||
System.out.println("at:"+r);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
final var results = m.sendMessage(message, attachments, recipients);
|
final var results = m.sendMessage(message, attachments, recipients);
|
||||||
checkSendMessageResults(results.first(), results.second());
|
checkSendMessageResults(results.first(), results.second());
|
||||||
|
@ -112,9 +103,8 @@ public class DbusSignalImpl implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long sendNoteToSelfMessage(
|
public long sendNoteToSelfMessage(final String message, final List<String> attachments)
|
||||||
final String message, final List<String> attachments
|
throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity {
|
||||||
) throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity {
|
|
||||||
try {
|
try {
|
||||||
final var results = m.sendSelfMessage(message, attachments);
|
final var results = m.sendSelfMessage(message, attachments);
|
||||||
checkSendMessageResult(results.first(), results.second());
|
checkSendMessageResult(results.first(), results.second());
|
||||||
|
@ -153,11 +143,13 @@ public class DbusSignalImpl implements Signal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Since contact names might be empty if not defined, also potentially return the profile name
|
// Since contact names might be empty if not defined, also potentially return
|
||||||
//Profile names separate firstname/lastname by a \0 - replace by space otherwise the interface will hickup
|
// the profile name
|
||||||
|
// Profile names separate firstname/lastname by a \0 - replace by space
|
||||||
|
// otherwise the interface will hickup
|
||||||
@Override
|
@Override
|
||||||
public String getContactName(final String number) {
|
public String getContactName(final String number) {
|
||||||
String name=m.getContactOrProfileName(number).replace("\0", " ");
|
String name = m.getContactOrProfileName(number).replace("\0", " ");
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,11 +206,8 @@ public class DbusSignalImpl implements Signal {
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
return List.of();
|
return List.of();
|
||||||
} else {
|
} else {
|
||||||
return group.getMembers()
|
return group.getMembers().stream().map(m::resolveSignalServiceAddress)
|
||||||
.stream()
|
.map(SignalServiceAddress::getLegacyIdentifier).collect(Collectors.toList());
|
||||||
.map(m::resolveSignalServiceAddress)
|
|
||||||
.map(SignalServiceAddress::getLegacyIdentifier)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,9 +226,7 @@ public class DbusSignalImpl implements Signal {
|
||||||
if (avatar.isEmpty()) {
|
if (avatar.isEmpty()) {
|
||||||
avatar = null;
|
avatar = null;
|
||||||
}
|
}
|
||||||
final var results = m.updateGroup(groupId == null ? null : GroupId.unknownVersion(groupId),
|
final var results = m.updateGroup(groupId == null ? null : GroupId.unknownVersion(groupId), name, members,
|
||||||
name,
|
|
||||||
members,
|
|
||||||
avatar == null ? null : new File(avatar));
|
avatar == null ? null : new File(avatar));
|
||||||
checkSendMessageResults(0, results.second());
|
checkSendMessageResults(0, results.second());
|
||||||
return results.first().serialize();
|
return results.first().serialize();
|
||||||
|
@ -260,133 +247,134 @@ public class DbusSignalImpl implements Signal {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateProfile(
|
public void updateProfile(final String name, final String about, final String aboutEmoji, String avatarPath,
|
||||||
final String name,
|
final boolean removeAvatar) {
|
||||||
final String about,
|
|
||||||
final String aboutEmoji,
|
|
||||||
String avatarPath,
|
|
||||||
final boolean removeAvatar
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
if (avatarPath.isEmpty()) {
|
if (avatarPath.isEmpty()) {
|
||||||
avatarPath = null;
|
avatarPath = null;
|
||||||
}
|
}
|
||||||
Optional<File> avatarFile = removeAvatar
|
Optional<File> avatarFile = removeAvatar ? Optional.absent()
|
||||||
? Optional.absent()
|
|
||||||
: avatarPath == null ? null : Optional.of(new File(avatarPath));
|
: avatarPath == null ? null : Optional.of(new File(avatarPath));
|
||||||
m.setProfile(name, about, aboutEmoji, avatarFile);
|
m.setProfile(name, about, aboutEmoji, avatarFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new Error.Failure(e.getMessage());
|
throw new Error.Failure(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Provide option to query a version string in order to react on potential future interface changes
|
// Provide option to query a version string in order to react on potential
|
||||||
|
// future interface changes
|
||||||
@Override
|
@Override
|
||||||
public String version() {
|
public String version() {
|
||||||
return BaseConfig.PROJECT_VERSION;
|
return BaseConfig.PROJECT_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Create a unique list of Numbers from Identities and Contacts to really get all numbers the system knows
|
|
||||||
@Override
|
|
||||||
public List<String> listNumbers() {
|
|
||||||
List <String> numbers = new ArrayList<>();
|
|
||||||
|
|
||||||
for (IdentityInfo identity : m.getIdentities()) {
|
|
||||||
String number=identity.getAddress().getNumber().orNull();
|
|
||||||
if (number!=null) {
|
|
||||||
if (numbers.indexOf(number)==-1) {
|
|
||||||
numbers.add(number);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var contacts = m.getContacts();
|
// Create a unique list of Numbers from Identities and Contacts to really get
|
||||||
|
// all numbers the system knows
|
||||||
|
@Override
|
||||||
|
public List<String> listNumbers() {
|
||||||
|
List<String> numbers = new ArrayList<>();
|
||||||
|
|
||||||
|
for (IdentityInfo identity : m.getIdentities()) {
|
||||||
|
String number = identity.getAddress().getNumber().orNull();
|
||||||
|
if (number != null) {
|
||||||
|
if (numbers.indexOf(number) == -1) {
|
||||||
|
numbers.add(number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var contacts = m.getContacts();
|
||||||
for (var c : contacts) {
|
for (var c : contacts) {
|
||||||
if (numbers.indexOf(c.number)==-1) {
|
if (numbers.indexOf(c.number) == -1) {
|
||||||
numbers.add(c.number);
|
numbers.add(c.number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return numbers;
|
return numbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getContactNumber(final String name) {
|
public String getContactNumber(final String name) {
|
||||||
//Contact names have precendence.
|
// Contact names have precendence.
|
||||||
var contacts = m.getContacts();
|
var contacts = m.getContacts();
|
||||||
for (var c : contacts) {
|
for (var c : contacts) {
|
||||||
if (!c.name.isEmpty() && c.name.equals(name)) {
|
if (!c.name.isEmpty() && c.name.equals(name)) {
|
||||||
return c.number;
|
return c.number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Try profiles if no contact name was found
|
// Try profiles if no contact name was found
|
||||||
for (IdentityInfo identity : m.getIdentities()) {
|
for (IdentityInfo identity : m.getIdentities()) {
|
||||||
String number=identity.getAddress().getNumber().orNull();
|
String number = identity.getAddress().getNumber().orNull();
|
||||||
if (number!=null) {
|
if (number != null) {
|
||||||
var address = Utils.getSignalServiceAddressFromIdentifier(number);
|
var address = Utils.getSignalServiceAddressFromIdentifier(number);
|
||||||
var profile = m.getRecipientProfile(address);
|
var profile = m.getRecipientProfile(address);
|
||||||
String profileName=profile.getName().replace("\0", " ");
|
String profileName = profile.getName().replace("\0", " ");
|
||||||
if (profileName.equals(name)) {
|
if (profileName.equals(name)) {
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void quitGroup(final byte[] groupId) {
|
public void quitGroup(final byte[] groupId) {
|
||||||
var group = GroupId.unknownVersion(groupId);
|
var group = GroupId.unknownVersion(groupId);
|
||||||
try {
|
try {
|
||||||
m.sendQuitGroupMessage(group);
|
m.sendQuitGroupMessage(group);
|
||||||
} catch (GroupNotFoundException | NotAGroupMemberException e) {
|
} catch (GroupNotFoundException | NotAGroupMemberException e) {
|
||||||
throw new Error.GroupNotFound(e.getMessage());
|
throw new Error.GroupNotFound(e.getMessage());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new Error.Failure(e.getMessage());
|
throw new Error.Failure(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void joinGroup(final String groupLink) {
|
public void joinGroup(final String groupLink) {
|
||||||
final GroupInviteLinkUrl linkUrl;
|
final GroupInviteLinkUrl linkUrl;
|
||||||
try {
|
try {
|
||||||
linkUrl = GroupInviteLinkUrl.fromUri(groupLink);
|
linkUrl = GroupInviteLinkUrl.fromUri(groupLink);
|
||||||
m.joinGroup(linkUrl);
|
m.joinGroup(linkUrl);
|
||||||
} catch (GroupInviteLinkUrl.InvalidGroupLinkException | GroupLinkNotActiveException e) {
|
} catch (GroupInviteLinkUrl.InvalidGroupLinkException | GroupLinkNotActiveException e) {
|
||||||
throw new Error.Failure("Group link is invalid: " + e.getMessage());
|
throw new Error.Failure("Group link is invalid: " + e.getMessage());
|
||||||
} catch (GroupInviteLinkUrl.UnknownGroupLinkVersionException e) {
|
} catch (GroupInviteLinkUrl.UnknownGroupLinkVersionException e) {
|
||||||
throw new Error.Failure("Group link was created with an incompatible version: " + e.getMessage());
|
throw new Error.Failure("Group link was created with an incompatible version: " + e.getMessage());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new Error.Failure(e.getMessage());
|
throw new Error.Failure(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isContactBlocked(final String number) {
|
public boolean isContactBlocked(final String number) {
|
||||||
return false;
|
var contacts = m.getContacts();
|
||||||
}
|
for (var c : contacts) {
|
||||||
|
if (c.number.equals(number)) {
|
||||||
@Override
|
return c.blocked;
|
||||||
public boolean isGroupBlocked(final byte[] groupId) {
|
}
|
||||||
var group = m.getGroup(GroupId.unknownVersion(groupId));
|
}
|
||||||
|
throw new Error.InvalidNumber("Contact not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isGroupBlocked(final byte[] groupId) {
|
||||||
|
var group = m.getGroup(GroupId.unknownVersion(groupId));
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return group.isBlocked();
|
return group.isBlocked();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMember(final byte[] groupId) {
|
public boolean isMember(final byte[] groupId) {
|
||||||
var group = m.getGroup(GroupId.unknownVersion(groupId));
|
var group = m.getGroup(GroupId.unknownVersion(groupId));
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return group.isMember(m.getSelfAddress());
|
return group.isMember(m.getSelfAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue