X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/e78463ea0a81ef326b6adf85a50887de5192fcf7..7c9fd9d0fb7b303e8194a6de9aed852c488afc25:/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 768f6e89..e975a671 100644 --- a/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java +++ b/src/main/java/org/asamk/signal/dbus/DbusSignalImpl.java @@ -41,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; @@ -73,7 +74,9 @@ public class DbusSignalImpl implements Signal { } 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()); + throw new Error.InvalidUri(e.getClass().getSimpleName() + + " Device link uri has invalid format: " + + e.getMessage()); } } @@ -97,9 +100,7 @@ public class DbusSignalImpl implements Signal { throw new Error.Failure("Failed to get linked devices: " + e.getMessage()); } - return devices.stream() - .map(d -> d.getName() == null ? "" : d.getName()) - .collect(Collectors.toList()); + return devices.stream().map(d -> d.getName() == null ? "" : d.getName()).collect(Collectors.toList()); } @Override @@ -275,7 +276,7 @@ public class DbusSignalImpl implements Signal { ) throws Error.AttachmentInvalid, Error.Failure, Error.UntrustedIdentity { try { final var results = m.sendMessage(new Message(message, attachments), - Set.of(new RecipientIdentifier.NoteToSelf())); + Set.of(RecipientIdentifier.NoteToSelf.INSTANCE)); checkSendMessageResults(results.getTimestamp(), results.getResults()); return results.getTimestamp(); } catch (AttachmentInvalidException e) { @@ -470,6 +471,54 @@ 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 isRegistered(List numbers) { + var results = new ArrayList(); + if (numbers.isEmpty()) { + return results; + } + + Map> 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 givenName, + final String familyName, + final String about, + final String aboutEmoji, + String avatarPath, + final boolean removeAvatar + ) { + try { + if (avatarPath.isEmpty()) { + avatarPath = null; + } + Optional avatarFile = removeAvatar + ? Optional.absent() + : avatarPath == null ? null : Optional.of(new File(avatarPath)); + m.setProfile(givenName, familyName, about, aboutEmoji, avatarFile); + } catch (IOException e) { + throw new Error.Failure(e.getMessage()); + } + } + @Override public void updateProfile( final String name,