X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/b178c7c67aea7bf334cbf0d54a4666af0a65b5d9..04fa0468151c78f80197feb6434e39e0fd7e2d9e:/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 b5dcb5e0..6c52d59e 100644 --- a/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java +++ b/lib/src/main/java/org/asamk/signal/manager/ManagerImpl.java @@ -27,11 +27,11 @@ import org.asamk.signal.manager.api.InvalidStickerException; import org.asamk.signal.manager.api.Message; import org.asamk.signal.manager.api.NotPrimaryDeviceException; import org.asamk.signal.manager.api.Pair; +import org.asamk.signal.manager.api.ReceiveConfig; import org.asamk.signal.manager.api.RecipientIdentifier; import org.asamk.signal.manager.api.SendGroupMessageResults; import org.asamk.signal.manager.api.SendMessageResult; import org.asamk.signal.manager.api.SendMessageResults; -import org.asamk.signal.manager.api.StickerPack; import org.asamk.signal.manager.api.StickerPackId; import org.asamk.signal.manager.api.StickerPackInvalidException; import org.asamk.signal.manager.api.StickerPackUrl; @@ -57,7 +57,7 @@ import org.asamk.signal.manager.storage.recipients.Recipient; import org.asamk.signal.manager.storage.recipients.RecipientId; import org.asamk.signal.manager.storage.stickerPacks.JsonStickerPack; import org.asamk.signal.manager.storage.stickerPacks.StickerPackStore; -import org.asamk.signal.manager.storage.stickers.Sticker; +import org.asamk.signal.manager.storage.stickers.StickerPack; import org.asamk.signal.manager.util.AttachmentUtils; import org.asamk.signal.manager.util.KeyUtils; import org.asamk.signal.manager.util.StickerUtils; @@ -167,7 +167,8 @@ class ManagerImpl implements Manager { }); disposable.add(account.getIdentityKeyStore().getIdentityChanges().subscribe(recipientId -> { logger.trace("Archiving old sessions for {}", recipientId); - account.getSessionStore().archiveSessions(recipientId); + account.getAciSessionStore().archiveSessions(recipientId); + account.getPniSessionStore().archiveSessions(recipientId); account.getSenderKeyStore().deleteSharedWith(recipientId); final var profile = account.getProfileStore().getProfile(recipientId); if (profile != null) { @@ -231,6 +232,7 @@ class ManagerImpl implements Manager { context.getAccountHelper().setDeviceName(deviceName); } context.getAccountHelper().updateAccountAttributes(); + context.getAccountHelper().checkWhoAmiI(); } @Override @@ -562,7 +564,8 @@ class ManagerImpl implements Manager { final var quote = message.quote().get(); messageBuilder.withQuote(new SignalServiceDataMessage.Quote(quote.timestamp(), context.getRecipientHelper() - .resolveSignalServiceAddress(context.getRecipientHelper().resolveRecipient(quote.author())), + .resolveSignalServiceAddress(context.getRecipientHelper().resolveRecipient(quote.author())) + .getServiceId(), quote.message(), List.of(), resolveMentions(quote.mentions()), @@ -577,7 +580,7 @@ class ManagerImpl implements Manager { if (stickerPack == null) { throw new InvalidStickerException("Sticker pack not found"); } - final var manifest = context.getStickerHelper().getOrRetrieveStickerPack(packId, stickerPack.getPackKey()); + final var manifest = context.getStickerHelper().getOrRetrieveStickerPack(packId, stickerPack.packKey()); if (manifest.stickers().size() <= stickerId) { throw new InvalidStickerException("Sticker id not part of this pack"); } @@ -587,7 +590,7 @@ class ManagerImpl implements Manager { throw new InvalidStickerException("Missing local sticker file"); } messageBuilder.withSticker(new SignalServiceDataMessage.Sticker(packId.serialize(), - stickerPack.getPackKey(), + stickerPack.packKey(), stickerId, manifestSticker.emoji(), AttachmentUtils.createAttachmentStream(streamDetails, Optional.empty()))); @@ -649,7 +652,7 @@ class ManagerImpl implements Manager { var targetAuthorRecipientId = context.getRecipientHelper().resolveRecipient(targetAuthor); var reaction = new SignalServiceDataMessage.Reaction(emoji, remove, - context.getRecipientHelper().resolveSignalServiceAddress(targetAuthorRecipientId), + context.getRecipientHelper().resolveSignalServiceAddress(targetAuthorRecipientId).getServiceId(), targetSentTimestamp); final var messageBuilder = SignalServiceDataMessage.newBuilder().withReaction(reaction); return sendMessage(messageBuilder, recipients); @@ -686,7 +689,7 @@ class ManagerImpl implements Manager { } catch (UnregisteredRecipientException e) { continue; } - account.getSessionStore().deleteAllSessions(recipientId); + account.getAciSessionStore().deleteAllSessions(recipientId); } } } @@ -704,12 +707,13 @@ class ManagerImpl implements Manager { @Override public void setContactName( - RecipientIdentifier.Single recipient, String name + RecipientIdentifier.Single recipient, String givenName, final String familyName ) throws NotPrimaryDeviceException, UnregisteredRecipientException { if (!account.isPrimaryDevice()) { throw new NotPrimaryDeviceException(); } - context.getContactHelper().setContactName(context.getRecipientHelper().resolveRecipient(recipient), name); + context.getContactHelper() + .setContactName(context.getRecipientHelper().resolveRecipient(recipient), givenName, familyName); } @Override @@ -792,21 +796,21 @@ class ManagerImpl implements Manager { var packIdString = messageSender.uploadStickerManifest(manifest, packKey); var packId = StickerPackId.deserialize(Hex.fromStringCondensed(packIdString)); - var sticker = new Sticker(packId, packKey); - account.getStickerStore().updateSticker(sticker); + var sticker = new StickerPack(packId, packKey); + account.getStickerStore().addStickerPack(sticker); return new StickerPackUrl(packId, packKey); } @Override - public List getStickerPacks() { + public List getStickerPacks() { final var stickerPackStore = context.getStickerPackStore(); return account.getStickerStore().getStickerPacks().stream().map(pack -> { - if (stickerPackStore.existsStickerPack(pack.getPackId())) { + if (stickerPackStore.existsStickerPack(pack.packId())) { try { - final var manifest = stickerPackStore.retrieveManifest(pack.getPackId()); - return new StickerPack(pack.getPackId(), - new StickerPackUrl(pack.getPackId(), pack.getPackKey()), + final var manifest = stickerPackStore.retrieveManifest(pack.packId()); + return new org.asamk.signal.manager.api.StickerPack(pack.packId(), + new StickerPackUrl(pack.packId(), pack.packKey()), pack.isInstalled(), manifest.title(), manifest.author(), @@ -817,7 +821,7 @@ class ManagerImpl implements Manager { } } - return new StickerPack(pack.getPackId(), pack.getPackKey(), pack.isInstalled()); + return new org.asamk.signal.manager.api.StickerPack(pack.packId(), pack.packKey(), pack.isInstalled()); }).toList(); } @@ -828,9 +832,7 @@ class ManagerImpl implements Manager { } void retrieveRemoteStorage() throws IOException { - if (account.getStorageKey() != null) { - context.getStorageHelper().readDataFromStorage(); - } + context.getStorageHelper().readDataFromStorage(); } @Override @@ -858,7 +860,8 @@ class ManagerImpl implements Manager { logger.debug("Starting receiving messages"); context.getReceiveHelper().receiveMessagesContinuously((envelope, e) -> { synchronized (messageHandlers) { - Stream.concat(messageHandlers.stream(), weakHandlers.stream()).forEach(h -> { + final var handlers = Stream.concat(messageHandlers.stream(), weakHandlers.stream()).toList(); + handlers.forEach(h -> { try { h.handleMessage(envelope, e); } catch (Throwable ex) { @@ -947,8 +950,8 @@ class ManagerImpl implements Manager { } @Override - public void setIgnoreAttachments(final boolean ignoreAttachments) { - context.getReceiveHelper().setIgnoreAttachments(ignoreAttachments); + public void setReceiveConfig(final ReceiveConfig receiveConfig) { + context.getReceiveHelper().setReceiveConfig(receiveConfig); } @Override @@ -986,6 +989,9 @@ class ManagerImpl implements Manager { return null; } }).filter(Objects::nonNull).collect(Collectors.toSet()); + if (!recipients.isEmpty() && recipientIds.isEmpty()) { + return List.of(); + } // refresh profiles of explicitly given recipients context.getProfileHelper().refreshRecipientProfiles(recipientIds); return account.getRecipientStore().getRecipients(onlyContacts, blocked, recipientIds, name); @@ -1038,7 +1044,7 @@ class ManagerImpl implements Manager { .computeSafetyNumber(identityInfo.getRecipientId(), identityInfo.getIdentityKey()), scannableFingerprint == null ? null : scannableFingerprint.getSerialized(), identityInfo.getTrustLevel(), - identityInfo.getDateAdded()); + identityInfo.getDateAddedTimestamp()); } @Override @@ -1046,7 +1052,7 @@ class ManagerImpl implements Manager { IdentityInfo identity; try { identity = account.getIdentityKeyStore() - .getIdentity(context.getRecipientHelper().resolveRecipient(recipient)); + .getIdentityInfo(context.getRecipientHelper().resolveRecipient(recipient)); } catch (UnregisteredRecipientException e) { identity = null; }