mirror of
https://github.com/AsamK/signal-cli
synced 2025-09-06 22:10:38 +00:00
Merge branch 'AsamK:master' into master
This commit is contained in:
commit
e3e7c87f2a
7 changed files with 361 additions and 7 deletions
|
@ -21,6 +21,14 @@ public interface Signal extends DBusInterface {
|
|||
String message, List<String> attachments, List<String> recipients
|
||||
) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.UntrustedIdentity;
|
||||
|
||||
void sendTyping(
|
||||
String recipient, boolean stop
|
||||
) throws Error.Failure, Error.GroupNotFound, Error.UntrustedIdentity;
|
||||
|
||||
void sendReadReceipt(
|
||||
String recipient, List<Long> targetSentTimestamp
|
||||
) throws Error.Failure, Error.UntrustedIdentity;
|
||||
|
||||
long sendRemoteDeleteMessage(
|
||||
long targetSentTimestamp, String recipient
|
||||
) throws Error.Failure, Error.InvalidNumber;
|
||||
|
@ -41,6 +49,10 @@ public interface Signal extends DBusInterface {
|
|||
String emoji, boolean remove, String targetAuthor, long targetSentTimestamp, List<String> recipients
|
||||
) throws Error.InvalidNumber, Error.Failure;
|
||||
|
||||
void sendContacts() throws Error.Failure;
|
||||
|
||||
void sendSyncRequest() throws Error.Failure;
|
||||
|
||||
long sendNoteToSelfMessage(
|
||||
String message, List<String> attachments
|
||||
) throws Error.AttachmentInvalid, Error.Failure;
|
||||
|
@ -59,6 +71,8 @@ public interface Signal extends DBusInterface {
|
|||
|
||||
void setContactName(String number, String name) throws Error.InvalidNumber;
|
||||
|
||||
void setExpirationTimer(final String number, final int expiration) throws Error.Failure;
|
||||
|
||||
void setContactBlocked(String number, boolean blocked) throws Error.InvalidNumber;
|
||||
|
||||
void setGroupBlocked(byte[] groupId, boolean blocked) throws Error.GroupNotFound, Error.InvalidGroupId;
|
||||
|
@ -73,12 +87,28 @@ public interface Signal extends DBusInterface {
|
|||
byte[] groupId, String name, List<String> members, String avatar
|
||||
) throws Error.AttachmentInvalid, Error.Failure, Error.InvalidNumber, Error.GroupNotFound, Error.InvalidGroupId;
|
||||
|
||||
boolean isRegistered();
|
||||
boolean isRegistered() throws Error.Failure, Error.InvalidNumber;
|
||||
|
||||
boolean isRegistered(String number) throws Error.Failure, Error.InvalidNumber;
|
||||
|
||||
List<Boolean> isRegistered(List<String> numbers) throws Error.Failure, Error.InvalidNumber;
|
||||
|
||||
void addDevice(String uri) throws Error.InvalidUri;
|
||||
|
||||
void removeDevice(int deviceId) throws Error.Failure;
|
||||
|
||||
List<String> listDevices() throws Error.Failure;
|
||||
|
||||
void updateDeviceName(String deviceName) throws Error.Failure;
|
||||
|
||||
void updateProfile(
|
||||
String name, String about, String aboutEmoji, String avatarPath, boolean removeAvatar
|
||||
) throws Error.Failure;
|
||||
|
||||
void removePin();
|
||||
|
||||
void setPin(String registrationLockPin);
|
||||
|
||||
String version();
|
||||
|
||||
List<String> listNumbers();
|
||||
|
@ -97,6 +127,8 @@ public interface Signal extends DBusInterface {
|
|||
|
||||
byte[] joinGroup(final String groupLink) throws Error.Failure;
|
||||
|
||||
String uploadStickerPack(String stickerPackPath) throws Error.Failure;
|
||||
|
||||
class MessageReceived extends DBusSignal {
|
||||
|
||||
private final long timestamp;
|
||||
|
@ -223,6 +255,13 @@ public interface Signal extends DBusInterface {
|
|||
}
|
||||
}
|
||||
|
||||
class InvalidUri extends DBusExecutionException {
|
||||
|
||||
public InvalidUri(final String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
class Failure extends DBusExecutionException {
|
||||
|
||||
public Failure(final String message) {
|
||||
|
|
|
@ -5,8 +5,12 @@ import org.asamk.signal.BaseConfig;
|
|||
import org.asamk.signal.manager.AttachmentInvalidException;
|
||||
import org.asamk.signal.manager.Manager;
|
||||
import org.asamk.signal.manager.NotMasterDeviceException;
|
||||
import org.asamk.signal.manager.StickerPackInvalidException;
|
||||
import org.asamk.signal.manager.UntrustedIdentityException;
|
||||
import org.asamk.signal.manager.api.Device;
|
||||
import org.asamk.signal.manager.api.Message;
|
||||
import org.asamk.signal.manager.api.RecipientIdentifier;
|
||||
import org.asamk.signal.manager.api.TypingAction;
|
||||
import org.asamk.signal.manager.groups.GroupId;
|
||||
import org.asamk.signal.manager.groups.GroupInviteLinkUrl;
|
||||
import org.asamk.signal.manager.groups.GroupNotFoundException;
|
||||
|
@ -17,15 +21,19 @@ import org.asamk.signal.manager.storage.identities.IdentityInfo;
|
|||
import org.asamk.signal.util.ErrorUtils;
|
||||
import org.asamk.signal.util.Util;
|
||||
import org.freedesktop.dbus.exceptions.DBusExecutionException;
|
||||
import org.whispersystems.libsignal.InvalidKeyException;
|
||||
import org.whispersystems.libsignal.util.Pair;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
import org.whispersystems.signalservice.api.groupsv2.GroupLinkNotActiveException;
|
||||
import org.whispersystems.signalservice.api.messages.SendMessageResult;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException;
|
||||
import org.whispersystems.signalservice.api.util.InvalidNumberException;
|
||||
import org.whispersystems.signalservice.internal.contacts.crypto.UnauthenticatedResponseException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
@ -33,6 +41,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -58,6 +67,51 @@ public class DbusSignalImpl implements Signal {
|
|||
return objectPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDevice(String uri) {
|
||||
try {
|
||||
m.addDeviceLink(new URI(uri));
|
||||
} catch (IOException | InvalidKeyException e) {
|
||||
throw new Error.Failure(e.getClass().getSimpleName() + " Add device link failed. " + e.getMessage());
|
||||
} catch (URISyntaxException e) {
|
||||
throw new Error.InvalidUri(e.getClass().getSimpleName()
|
||||
+ " Device link uri has invalid format: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDevice(int deviceId) {
|
||||
try {
|
||||
m.removeLinkedDevices(deviceId);
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getClass().getSimpleName() + ": Error while removing device: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listDevices() {
|
||||
List<Device> devices;
|
||||
List<String> results = new ArrayList<String>();
|
||||
|
||||
try {
|
||||
devices = m.getLinkedDevices();
|
||||
} catch (IOException | Error.Failure e) {
|
||||
throw new Error.Failure("Failed to get linked devices: " + e.getMessage());
|
||||
}
|
||||
|
||||
return devices.stream().map(d -> d.getName() == null ? "" : d.getName()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDeviceName(String deviceName) {
|
||||
try {
|
||||
m.updateAccountAttributes(deviceName);
|
||||
} catch (IOException | Signal.Error.Failure e) {
|
||||
throw new Error.Failure("UpdateAccount error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long sendMessage(final String message, final List<String> attachments, final String recipient) {
|
||||
var recipients = new ArrayList<String>(1);
|
||||
|
@ -165,6 +219,57 @@ public class DbusSignalImpl implements Signal {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTyping(
|
||||
final String recipient, final boolean stop
|
||||
) throws Error.Failure, Error.GroupNotFound, Error.UntrustedIdentity {
|
||||
try {
|
||||
var recipients = new ArrayList<String>(1);
|
||||
recipients.add(recipient);
|
||||
m.sendTypingMessage(stop ? TypingAction.STOP : TypingAction.START,
|
||||
getSingleRecipientIdentifiers(recipients, m.getUsername()).stream()
|
||||
.map(RecipientIdentifier.class::cast)
|
||||
.collect(Collectors.toSet()));
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getMessage());
|
||||
} catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) {
|
||||
throw new Error.GroupNotFound(e.getMessage());
|
||||
} catch (UntrustedIdentityException e) {
|
||||
throw new Error.UntrustedIdentity(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendReadReceipt(
|
||||
final String recipient, final List<Long> timestamps
|
||||
) throws Error.Failure, Error.UntrustedIdentity {
|
||||
try {
|
||||
m.sendReadReceipt(getSingleRecipientIdentifier(recipient, m.getUsername()), timestamps);
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getMessage());
|
||||
} catch (UntrustedIdentityException e) {
|
||||
throw new Error.UntrustedIdentity(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendContacts() {
|
||||
try {
|
||||
m.sendContacts();
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure("SendContacts error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendSyncRequest() {
|
||||
try {
|
||||
m.requestAllSyncData();
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure("Request sync data error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long sendNoteToSelfMessage(
|
||||
final String message, final List<String> attachments
|
||||
|
@ -250,6 +355,15 @@ public class DbusSignalImpl implements Signal {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExpirationTimer(final String number, final int expiration) {
|
||||
try {
|
||||
m.setExpirationTimer(getSingleRecipientIdentifier(number, m.getUsername()), expiration);
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContactBlocked(final String number, final boolean blocked) {
|
||||
try {
|
||||
|
@ -357,6 +471,32 @@ public class DbusSignalImpl implements Signal {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRegistered(String number) {
|
||||
var result = isRegistered(List.of(number));
|
||||
return result.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Boolean> isRegistered(List<String> numbers) {
|
||||
var results = new ArrayList<Boolean>();
|
||||
if (numbers.isEmpty()) {
|
||||
return results;
|
||||
}
|
||||
|
||||
Map<String, Pair<String, UUID>> registered;
|
||||
try {
|
||||
registered = m.areUsersRegistered(new HashSet<>(numbers));
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure(e.getMessage());
|
||||
}
|
||||
|
||||
return numbers.stream().map(number -> {
|
||||
var uuid = registered.get(number).second();
|
||||
return uuid != null;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProfile(
|
||||
final String name,
|
||||
|
@ -378,6 +518,28 @@ public class DbusSignalImpl implements Signal {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePin() {
|
||||
try {
|
||||
m.setRegistrationLockPin(Optional.absent());
|
||||
} catch (UnauthenticatedResponseException e) {
|
||||
throw new Error.Failure("Remove pin failed with unauthenticated response: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure("Remove pin error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPin(String registrationLockPin) {
|
||||
try {
|
||||
m.setRegistrationLockPin(Optional.of(registrationLockPin));
|
||||
} catch (UnauthenticatedResponseException e) {
|
||||
throw new Error.Failure("Set pin error failed with unauthenticated response: " + e.getMessage());
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure("Set pin error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Provide option to query a version string in order to react on potential
|
||||
// future interface changes
|
||||
@Override
|
||||
|
@ -483,6 +645,18 @@ public class DbusSignalImpl implements Signal {
|
|||
return m.getUsername();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadStickerPack(String stickerPackPath) {
|
||||
File path = new File(stickerPackPath);
|
||||
try {
|
||||
return m.uploadStickerPack(path).toString();
|
||||
} catch (IOException e) {
|
||||
throw new Error.Failure("Upload error (maybe image size is too large):" + e.getMessage());
|
||||
} catch (StickerPackInvalidException e) {
|
||||
throw new Error.Failure("Invalid sticker pack: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkSendMessageResult(long timestamp, SendMessageResult result) throws DBusExecutionException {
|
||||
var error = ErrorUtils.getErrorMessageFromSendMessageResult(result);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue