X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/c88c92086efcf5c0ad417589db997ef1a034e775..2a20e70aabaad0106774157a78eba60428604ac1:/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java diff --git a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java index f22f08a6..850bcf1d 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java @@ -2,19 +2,20 @@ package org.asamk.signal.dbus; import org.asamk.Signal; 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.api.AttachmentInvalidException; import org.asamk.signal.manager.api.Identity; import org.asamk.signal.manager.api.InactiveGroupLinkException; import org.asamk.signal.manager.api.InvalidDeviceLinkException; import org.asamk.signal.manager.api.InvalidNumberException; +import org.asamk.signal.manager.api.InvalidStickerException; import org.asamk.signal.manager.api.Message; +import org.asamk.signal.manager.api.NotMasterDeviceException; import org.asamk.signal.manager.api.Pair; import org.asamk.signal.manager.api.RecipientIdentifier; import org.asamk.signal.manager.api.SendMessageResult; import org.asamk.signal.manager.api.SendMessageResults; +import org.asamk.signal.manager.api.StickerPackInvalidException; import org.asamk.signal.manager.api.TypingAction; import org.asamk.signal.manager.api.UnregisteredRecipientException; import org.asamk.signal.manager.api.UpdateGroup; @@ -78,12 +79,22 @@ public class DbusSignalImpl implements Signal { this.connection = connection; this.objectPath = objectPath; this.noReceiveOnStart = noReceiveOnStart; + + m.addAddressChangedListener(() -> { + unExportObjects(); + exportObjects(); + }); } public void initObjects() { + exportObjects(); if (!noReceiveOnStart) { subscribeReceive(); } + } + + private void exportObjects() { + exportObject(this); updateDevices(); updateGroups(); @@ -95,9 +106,14 @@ public class DbusSignalImpl implements Signal { m.removeReceiveHandler(dbusMessageHandler); dbusMessageHandler = null; } + unExportObjects(); + } + + private void unExportObjects() { unExportDevices(); unExportGroups(); unExportConfiguration(); + connection.unExportObject(this.objectPath); } @Override @@ -199,7 +215,11 @@ public class DbusSignalImpl implements Signal { @Override public long sendMessage(final String message, final List attachments, final List recipients) { try { - final var results = m.sendMessage(new Message(message, attachments, List.of(), Optional.empty()), + final var results = m.sendMessage(new Message(message, + attachments, + List.of(), + Optional.empty(), + Optional.empty()), getSingleRecipientIdentifiers(recipients, m.getSelfNumber()).stream() .map(RecipientIdentifier.class::cast) .collect(Collectors.toSet())); @@ -208,7 +228,7 @@ public class DbusSignalImpl implements Signal { return results.timestamp(); } catch (AttachmentInvalidException e) { throw new Error.AttachmentInvalid(e.getMessage()); - } catch (IOException e) { + } catch (IOException | InvalidStickerException e) { throw new Error.Failure(e); } catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) { throw new Error.GroupNotFound(e.getMessage()); @@ -346,13 +366,16 @@ public class DbusSignalImpl implements Signal { final String message, final List attachments ) throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity { try { - final var results = m.sendMessage(new Message(message, attachments, List.of(), Optional.empty()), - Set.of(RecipientIdentifier.NoteToSelf.INSTANCE)); + final var results = m.sendMessage(new Message(message, + attachments, + List.of(), + Optional.empty(), + Optional.empty()), Set.of(RecipientIdentifier.NoteToSelf.INSTANCE)); checkSendMessageResults(results); return results.timestamp(); } catch (AttachmentInvalidException e) { throw new Error.AttachmentInvalid(e.getMessage()); - } catch (IOException e) { + } catch (IOException | InvalidStickerException e) { throw new Error.Failure(e.getMessage()); } catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) { throw new Error.GroupNotFound(e.getMessage()); @@ -384,11 +407,14 @@ public class DbusSignalImpl implements Signal { @Override public long sendGroupMessage(final String message, final List attachments, final byte[] groupId) { try { - var results = m.sendMessage(new Message(message, attachments, List.of(), Optional.empty()), - Set.of(getGroupRecipientIdentifier(groupId))); + var results = m.sendMessage(new Message(message, + attachments, + List.of(), + Optional.empty(), + Optional.empty()), Set.of(getGroupRecipientIdentifier(groupId))); checkSendMessageResults(results); return results.timestamp(); - } catch (IOException e) { + } catch (IOException | InvalidStickerException e) { throw new Error.Failure(e.getMessage()); } catch (GroupNotFoundException | NotAGroupMemberException | GroupSendingNotAllowedException e) { throw new Error.GroupNotFound(e.getMessage()); @@ -669,6 +695,8 @@ public class DbusSignalImpl implements Signal { m.setRegistrationLockPin(Optional.empty()); } catch (IOException e) { throw new Error.Failure("Remove pin error: " + e.getMessage()); + } catch (NotMasterDeviceException e) { + throw new Error.Failure("This command doesn't work on linked devices."); } } @@ -678,6 +706,8 @@ public class DbusSignalImpl implements Signal { m.setRegistrationLockPin(Optional.of(registrationLockPin)); } catch (IOException e) { throw new Error.Failure("Set pin error: " + e.getMessage()); + } catch (NotMasterDeviceException e) { + throw new Error.Failure("This command doesn't work on linked devices."); } } @@ -844,7 +874,7 @@ public class DbusSignalImpl implements Signal { } var errors = SendMessageResultUtils.getErrorMessagesFromSendMessageResults(results); - if (errors.size() < results.size()) { + if (errors.size() == 0 || errors.size() < results.size()) { return; } @@ -927,7 +957,7 @@ public class DbusSignalImpl implements Signal { if (d.isThisDevice()) { thisDevice = new DBusPath(deviceObjectPath); } - this.devices.add(new StructDevice(new DBusPath(deviceObjectPath), d.id(), emptyIfNull(d.name()))); + this.devices.add(new StructDevice(new DBusPath(deviceObjectPath), (long) d.id(), emptyIfNull(d.name()))); }); } @@ -1132,6 +1162,8 @@ public class DbusSignalImpl implements Signal { () -> new Variant<>(getRecipientStrings(getGroup().requestingMembers()), "as")), new DbusProperty<>("Admins", () -> new Variant<>(getRecipientStrings(getGroup().adminMembers()), "as")), + new DbusProperty<>("Banned", + () -> new Variant<>(getRecipientStrings(getGroup().bannedMembers()), "as")), new DbusProperty<>("PermissionAddMember", () -> getGroup().permissionAddMember().name(), this::setGroupPermissionAddMember),