+ m.setProfile(name, null, about, aboutEmoji, avatarFile);
+ } catch (IOException e) {
+ throw new Error.Failure(e.getMessage());
+ }
+ }
+
+ // Provide option to query a version string in order to react on potential
+ // future interface changes
+ @Override
+ public String version() {
+ return BaseConfig.PROJECT_VERSION;
+ }
+
+ // Create a unique list of Numbers from Identities and Contacts to really get
+ // all numbers the system knows
+ @Override
+ public List<String> listNumbers() {
+ return Stream.concat(m.getIdentities().stream().map(IdentityInfo::getRecipientId),
+ m.getContacts().stream().map(Pair::first))
+ .map(m::resolveSignalServiceAddress)
+ .map(a -> a.getNumber().orNull())
+ .filter(Objects::nonNull)
+ .distinct()
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public List<String> getContactNumber(final String name) {
+ // Contact names have precedence.
+ var numbers = new ArrayList<String>();
+ var contacts = m.getContacts();
+ for (var c : contacts) {
+ if (name.equals(c.second().getName())) {
+ numbers.add(getLegacyIdentifier(m.resolveSignalServiceAddress(c.first())));
+ }
+ }
+ // Try profiles if no contact name was found
+ for (var identity : m.getIdentities()) {
+ final var recipientId = identity.getRecipientId();
+ final var address = m.resolveSignalServiceAddress(recipientId);
+ var number = address.getNumber().orNull();
+ if (number != null) {
+ var profile = m.getRecipientProfile(recipientId);
+ if (profile != null && profile.getDisplayName().equals(name)) {
+ numbers.add(number);
+ }
+ }
+ }
+ return numbers;
+ }
+
+ @Override
+ public void quitGroup(final byte[] groupId) {
+ var group = GroupId.unknownVersion(groupId);
+ try {
+ m.sendQuitGroupMessage(group, Set.of());
+ } catch (GroupNotFoundException | NotAGroupMemberException e) {
+ throw new Error.GroupNotFound(e.getMessage());
+ } catch (IOException | LastGroupAdminException e) {
+ throw new Error.Failure(e.getMessage());
+ } catch (InvalidNumberException e) {
+ throw new Error.InvalidNumber(e.getMessage());
+ }
+ }
+
+ @Override
+ public void joinGroup(final String groupLink) {
+ try {
+ final var linkUrl = GroupInviteLinkUrl.fromUri(groupLink);
+ if (linkUrl == null) {
+ throw new Error.Failure("Group link is invalid:");
+ }
+ m.joinGroup(linkUrl);
+ } catch (GroupInviteLinkUrl.InvalidGroupLinkException | GroupLinkNotActiveException e) {
+ throw new Error.Failure("Group link is invalid: " + e.getMessage());
+ } catch (GroupInviteLinkUrl.UnknownGroupLinkVersionException e) {
+ throw new Error.Failure("Group link was created with an incompatible version: " + e.getMessage());