X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/e61f587bfc8f5557587d8c6cd54efcaf6631fdce..caa4fa0180a84cca10a1b363d25147d03ccb0387:/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java diff --git a/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java b/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java index e9fc3f9c..985e2674 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java @@ -3,6 +3,7 @@ package org.asamk.signal.dbus; import org.asamk.Signal; import org.asamk.signal.DbusConfig; import org.asamk.signal.manager.Manager; +import org.asamk.signal.manager.api.AlreadyReceivingException; import org.asamk.signal.manager.api.AttachmentInvalidException; import org.asamk.signal.manager.api.CaptchaRequiredException; import org.asamk.signal.manager.api.Configuration; @@ -45,10 +46,12 @@ import org.asamk.signal.manager.api.UnregisteredRecipientException; import org.asamk.signal.manager.api.UpdateGroup; import org.asamk.signal.manager.api.UpdateProfile; import org.asamk.signal.manager.api.UserStatus; +import org.asamk.signal.manager.api.UsernameLinkUrl; import org.freedesktop.dbus.DBusMap; import org.freedesktop.dbus.DBusPath; import org.freedesktop.dbus.connections.impl.DBusConnection; import org.freedesktop.dbus.exceptions.DBusException; +import org.freedesktop.dbus.exceptions.DBusExecutionException; import org.freedesktop.dbus.interfaces.DBusInterface; import org.freedesktop.dbus.interfaces.DBusSigHandler; import org.freedesktop.dbus.types.Variant; @@ -162,7 +165,17 @@ public class DbusManagerImpl implements Manager { } @Override - public String setUsername(final String username) throws IOException, InvalidUsernameException { + public String getUsername() { + throw new UnsupportedOperationException(); + } + + @Override + public UsernameLinkUrl getUsernameLink() { + throw new UnsupportedOperationException(); + } + + @Override + public void setUsername(final String username) throws IOException, InvalidUsernameException { throw new UnsupportedOperationException(); } @@ -341,8 +354,13 @@ public class DbusManagerImpl implements Manager { @Override public Pair joinGroup(final GroupInviteLinkUrl inviteLinkUrl) throws IOException, InactiveGroupLinkException { - final var newGroupId = signal.joinGroup(inviteLinkUrl.getUrl()); - return new Pair<>(GroupId.unknownVersion(newGroupId), new SendGroupMessageResults(0, List.of())); + try { + final var newGroupId = signal.joinGroup(inviteLinkUrl.getUrl()); + return new Pair<>(GroupId.unknownVersion(newGroupId), new SendGroupMessageResults(0, List.of())); + } catch (DBusExecutionException e) { + throw new IOException("Failed to join group: " + e.getMessage() + " (" + e.getClass().getSimpleName() + ")", + e); + } } @Override @@ -445,6 +463,10 @@ public class DbusManagerImpl implements Manager { return new SendMessageResults(0, Map.of()); } + public void hideRecipient(final RecipientIdentifier.Single recipient) { + throw new UnsupportedOperationException(); + } + @Override public void deleteRecipient(final RecipientIdentifier.Single recipient) { signal.deleteRecipient(recipient.getIdentifier()); @@ -548,10 +570,17 @@ public class DbusManagerImpl implements Manager { } } + private Thread receiveThread; + @Override public void receiveMessages( Optional timeout, Optional maxMessages, ReceiveMessageHandler handler - ) throws IOException { + ) throws IOException, AlreadyReceivingException { + if (receiveThread != null) { + throw new AlreadyReceivingException("Already receiving message."); + } + receiveThread = Thread.currentThread(); + final var remainingMessages = new AtomicInteger(maxMessages.orElse(-1)); final var lastMessage = new AtomicLong(System.currentTimeMillis()); final var thread = Thread.currentThread(); @@ -577,6 +606,7 @@ public class DbusManagerImpl implements Manager { } Thread.sleep(sleepTimeRemaining); } catch (InterruptedException ignored) { + break; } } } else { @@ -589,6 +619,14 @@ public class DbusManagerImpl implements Manager { } removeReceiveHandler(receiveHandler); + receiveThread = null; + } + + @Override + public void stopReceiveMessages() { + if (receiveThread != null) { + receiveThread.interrupt(); + } } @Override @@ -630,7 +668,7 @@ public class DbusManagerImpl implements Manager { } return Recipient.newBuilder() .withAddress(new RecipientAddress(null, n)) - .withContact(new Contact(contactName, null, null, 0, contactBlocked, false, false)) + .withContact(new Contact(contactName, null, null, 0, contactBlocked, false, false, false)) .build(); }).filter(Objects::nonNull).toList(); }