X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/81a11dc9776672e3468ee9a8eed556889fb2e070..06e93b84da2718c31111e820cd35a3354f22bae2:/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 cc346f7a..5421d4ad 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusManagerImpl.java @@ -6,7 +6,6 @@ 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.Configuration; import org.asamk.signal.manager.api.Device; import org.asamk.signal.manager.api.Group; @@ -68,6 +67,7 @@ public class DbusManagerImpl implements Manager { private final Set weakHandlers = new HashSet<>(); private final Set messageHandlers = new HashSet<>(); + private final List closedListeners = new ArrayList<>(); private DBusSigHandler dbusMsgHandler; private DBusSigHandler dbusRcptHandler; private DBusSigHandler dbusSyncHandler; @@ -131,7 +131,7 @@ public class DbusManagerImpl implements Manager { emptyIfNull(about), emptyIfNull(aboutEmoji), avatar == null ? "" : avatar.map(File::getPath).orElse(""), - avatar != null && !avatar.isPresent()); + avatar != null && avatar.isEmpty()); } @Override @@ -297,31 +297,34 @@ public class DbusManagerImpl implements Manager { } @Override - public void sendTypingMessage( + public SendMessageResults sendTypingMessage( final TypingAction action, final Set recipients - ) throws IOException, UntrustedIdentityException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException { - for (final var recipient : recipients) { - if (recipient instanceof RecipientIdentifier.Single) { - signal.sendTyping(((RecipientIdentifier.Single) recipient).getIdentifier(), - action == TypingAction.STOP); - } else if (recipient instanceof RecipientIdentifier.Group) { - throw new UnsupportedOperationException(); - } - } + ) throws IOException, NotAGroupMemberException, GroupNotFoundException, GroupSendingNotAllowedException { + return handleMessage(recipients, numbers -> { + numbers.forEach(n -> signal.sendTyping(n, action == TypingAction.STOP)); + return 0L; + }, () -> { + signal.sendTyping(signal.getSelfNumber(), action == TypingAction.STOP); + return 0L; + }, groupId -> { + throw new UnsupportedOperationException(); + }); } @Override - public void sendReadReceipt( + public SendMessageResults sendReadReceipt( final RecipientIdentifier.Single sender, final List messageIds - ) throws IOException, UntrustedIdentityException { + ) { signal.sendReadReceipt(sender.getIdentifier(), messageIds); + return new SendMessageResults(0, Map.of()); } @Override - public void sendViewedReceipt( + public SendMessageResults sendViewedReceipt( final RecipientIdentifier.Single sender, final List messageIds - ) throws IOException, UntrustedIdentityException { + ) { signal.sendViewedReceipt(sender.getIdentifier(), messageIds); + return new SendMessageResults(0, Map.of()); } @Override @@ -378,6 +381,16 @@ public class DbusManagerImpl implements Manager { return new SendMessageResults(0, Map.of()); } + @Override + public void deleteRecipient(final RecipientIdentifier.Single recipient) throws IOException { + signal.deleteRecipient(recipient.getIdentifier()); + } + + @Override + public void deleteContact(final RecipientIdentifier.Single recipient) throws IOException { + signal.deleteContact(recipient.getIdentifier()); + } + @Override public void setContactName( final RecipientIdentifier.Single recipient, final String name @@ -583,6 +596,13 @@ public class DbusManagerImpl implements Manager { throw new UnsupportedOperationException(); } + @Override + public void addClosedListener(final Runnable listener) { + synchronized (closedListeners) { + closedListeners.add(listener); + } + } + @Override public void close() throws IOException { synchronized (this) { @@ -595,6 +615,10 @@ public class DbusManagerImpl implements Manager { weakHandlers.clear(); messageHandlers.clear(); } + synchronized (closedListeners) { + closedListeners.forEach(Runnable::run); + closedListeners.clear(); + } } private SendMessageResults handleMessage( @@ -666,6 +690,7 @@ public class DbusManagerImpl implements Manager { false, Optional.empty(), Optional.empty(), + Optional.empty(), getAttachments(extras), Optional.empty(), Optional.empty(), @@ -735,6 +760,7 @@ public class DbusManagerImpl implements Manager { false, Optional.empty(), Optional.empty(), + Optional.empty(), getAttachments(extras), Optional.empty(), Optional.empty(), @@ -760,9 +786,8 @@ public class DbusManagerImpl implements Manager { private void notifyMessageHandlers(final MessageEnvelope envelope) { synchronized (messageHandlers) { - Stream.concat(messageHandlers.stream(), weakHandlers.stream()).forEach(h -> { - h.handleMessage(envelope, null); - }); + Stream.concat(messageHandlers.stream(), weakHandlers.stream()) + .forEach(h -> h.handleMessage(envelope, null)); } }