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.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;
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;
}
}
+ @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
m.setContactName(getSingleRecipientIdentifier(number, m.getUsername()), name);
} catch (NotMasterDeviceException e) {
throw new Error.Failure("This command doesn't work on linked devices.");
+ } catch (UnregisteredUserException e) {
+ throw new Error.Failure("Contact is not registered.");
}
}
m.setContactBlocked(getSingleRecipientIdentifier(number, m.getUsername()), blocked);
} catch (NotMasterDeviceException e) {
throw new Error.Failure("This command doesn't work on linked devices.");
+ } catch (IOException e) {
+ throw new Error.Failure(e.getMessage());
}
}
m.setGroupBlocked(getGroupId(groupId), blocked);
} catch (GroupNotFoundException e) {
throw new Error.GroupNotFound(e.getMessage());
+ } catch (IOException e) {
+ throw new Error.Failure(e.getMessage());
}
}
}
}
+ @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
public void quitGroup(final byte[] groupId) {
var group = getGroupId(groupId);
try {
- m.sendQuitGroupMessage(group, Set.of());
+ m.quitGroup(group, Set.of());
} catch (GroupNotFoundException | NotAGroupMemberException e) {
throw new Error.GroupNotFound(e.getMessage());
} catch (IOException | LastGroupAdminException e) {
}
}
+ @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);