X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/5771bb858f6894c5eeb52e8614cd1c4132bf6b7f..6106e1878bcb5ad3c28fd74fdf44c6dde971fff6:/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java diff --git a/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java b/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java index 5191e2d9..451adb59 100644 --- a/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java +++ b/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java @@ -25,6 +25,7 @@ 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.InvalidStickerException; +import org.asamk.signal.manager.api.InvalidUsernameException; import org.asamk.signal.manager.api.Message; import org.asamk.signal.manager.api.MessageEnvelope; import org.asamk.signal.manager.api.NotPrimaryDeviceException; @@ -65,6 +66,7 @@ import org.asamk.signal.manager.util.AttachmentUtils; import org.asamk.signal.manager.util.KeyUtils; import org.asamk.signal.manager.util.MimeUtils; import org.asamk.signal.manager.util.StickerUtils; +import org.signal.libsignal.usernames.BaseUsernameException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.whispersystems.signalservice.api.SignalSessionLock; @@ -290,6 +292,20 @@ class ManagerImpl implements Manager { context.getSyncHelper().sendSyncFetchProfileMessage(); } + @Override + public String setUsername(final String username) throws IOException, InvalidUsernameException { + try { + return context.getAccountHelper().reserveUsername(username); + } catch (BaseUsernameException e) { + throw new InvalidUsernameException(e.getMessage() + " (" + e.getClass().getSimpleName() + ")", e); + } + } + + @Override + public void deleteUsername() throws IOException { + context.getAccountHelper().deleteUsername(); + } + @Override public void unregister() throws IOException { context.getAccountHelper().unregister(); @@ -569,7 +585,7 @@ class ManagerImpl implements Manager { final var textAttachment = AttachmentUtils.createAttachmentStream(new StreamDetails(new ByteArrayInputStream( messageBytes), MimeUtils.LONG_TEXT, messageBytes.length), Optional.empty()); messageBuilder.withBody(message.messageText().substring(0, 2000)); - messageBuilder.withAttachment(textAttachment); + messageBuilder.withAttachment(context.getAttachmentHelper().uploadAttachment(textAttachment)); } else { messageBuilder.withBody(message.messageText()); } @@ -588,7 +604,8 @@ class ManagerImpl implements Manager { quote.message(), List.of(), resolveMentions(quote.mentions()), - SignalServiceDataMessage.Quote.Type.NORMAL)); + SignalServiceDataMessage.Quote.Type.NORMAL, + List.of())); } if (message.sticker().isPresent()) { final var sticker = message.sticker().get(); @@ -736,13 +753,18 @@ class ManagerImpl implements Manager { @Override public void deleteRecipient(final RecipientIdentifier.Single recipient) { - account.removeRecipient(account.getRecipientResolver().resolveRecipient(recipient.getIdentifier())); + final var recipientIdOptional = context.getRecipientHelper().resolveRecipientOptional(recipient); + if (recipientIdOptional.isPresent()) { + account.removeRecipient(recipientIdOptional.get()); + } } @Override public void deleteContact(final RecipientIdentifier.Single recipient) { - account.getContactStore() - .deleteContact(account.getRecipientResolver().resolveRecipient(recipient.getIdentifier())); + final var recipientIdOptional = context.getRecipientHelper().resolveRecipientOptional(recipient); + if (recipientIdOptional.isPresent()) { + account.getContactStore().deleteContact(recipientIdOptional.get()); + } } @Override