Search in sources :

Example 1 with SignalServiceStickerManifest

use of org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest in project Signal-Android by WhisperSystems.

the class StickerPackDownloadJob method onRun.

@Override
protected void onRun() throws IOException, InvalidMessageException {
    if (isReferencePack && !SignalDatabase.attachments().containsStickerPackId(packId) && !BlessedPacks.contains(packId)) {
        Log.w(TAG, "There are no attachments with the requested packId present for this reference pack. Skipping.");
        return;
    }
    if (isReferencePack && SignalDatabase.stickers().isPackAvailableAsReference(packId)) {
        Log.i(TAG, "Sticker pack already available for reference. Skipping.");
        return;
    }
    SignalServiceMessageReceiver receiver = ApplicationDependencies.getSignalServiceMessageReceiver();
    JobManager jobManager = ApplicationDependencies.getJobManager();
    StickerDatabase stickerDatabase = SignalDatabase.stickers();
    byte[] packIdBytes = Hex.fromStringCondensed(packId);
    byte[] packKeyBytes = Hex.fromStringCondensed(packKey);
    SignalServiceStickerManifest manifest = receiver.retrieveStickerManifest(packIdBytes, packKeyBytes);
    if (manifest.getStickers().isEmpty()) {
        Log.w(TAG, "No stickers in pack!");
        return;
    }
    if (!isReferencePack && stickerDatabase.isPackAvailableAsReference(packId)) {
        stickerDatabase.markPackAsInstalled(packId, notify);
    }
    StickerInfo cover = manifest.getCover().or(manifest.getStickers().get(0));
    JobManager.Chain chain = jobManager.startChain(new StickerDownloadJob(new IncomingSticker(packId, packKey, manifest.getTitle().or(""), manifest.getAuthor().or(""), cover.getId(), "", cover.getContentType(), true, !isReferencePack), notify));
    if (!isReferencePack) {
        List<Job> jobs = new ArrayList<>(manifest.getStickers().size());
        for (StickerInfo stickerInfo : manifest.getStickers()) {
            jobs.add(new StickerDownloadJob(new IncomingSticker(packId, packKey, manifest.getTitle().or(""), manifest.getAuthor().or(""), stickerInfo.getId(), stickerInfo.getEmoji(), stickerInfo.getContentType(), false, true), notify));
        }
        chain.then(jobs);
    }
    chain.enqueue();
}
Also used : SignalServiceStickerManifest(org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest) SignalServiceMessageReceiver(org.whispersystems.signalservice.api.SignalServiceMessageReceiver) StickerDatabase(org.thoughtcrime.securesms.database.StickerDatabase) ArrayList(java.util.ArrayList) IncomingSticker(org.thoughtcrime.securesms.database.model.IncomingSticker) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) StickerInfo(org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest.StickerInfo) Job(org.thoughtcrime.securesms.jobmanager.Job)

Example 2 with SignalServiceStickerManifest

use of org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest in project Signal-Android by WhisperSystems.

the class StickerPackPreviewRepository method getManifestRemote.

@WorkerThread
private Optional<StickerManifestResult> getManifestRemote(@NonNull String packId, @NonNull String packKey) {
    try {
        byte[] packIdBytes = Hex.fromStringCondensed(packId);
        byte[] packKeyBytes = Hex.fromStringCondensed(packKey);
        SignalServiceStickerManifest remoteManifest = receiver.retrieveStickerManifest(packIdBytes, packKeyBytes);
        StickerManifest localManifest = new StickerManifest(packId, packKey, remoteManifest.getTitle(), remoteManifest.getAuthor(), toOptionalSticker(packId, packKey, remoteManifest.getCover()), Stream.of(remoteManifest.getStickers()).map(s -> toSticker(packId, packKey, s)).toList());
        return Optional.of(new StickerManifestResult(localManifest, false));
    } catch (IOException | InvalidMessageException e) {
        Log.w(TAG, "Failed to retrieve pack manifest.", e);
    }
    return Optional.absent();
}
Also used : SignalServiceStickerManifest(org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) IOException(java.io.IOException) SignalServiceStickerManifest(org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest) WorkerThread(androidx.annotation.WorkerThread)

Example 3 with SignalServiceStickerManifest

use of org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest in project Signal-Android by WhisperSystems.

the class SignalServiceMessageReceiver method retrieveStickerManifest.

/**
 * Retrieves a {@link SignalServiceStickerManifest}.
 *
 * @param packId The 16-byte packId that identifies the sticker pack.
 * @param packKey The 32-byte packKey that decrypts the sticker pack.
 * @return The {@link SignalServiceStickerManifest} representing the sticker pack.
 * @throws IOException
 * @throws InvalidMessageException
 */
public SignalServiceStickerManifest retrieveStickerManifest(byte[] packId, byte[] packKey) throws IOException, InvalidMessageException {
    byte[] manifestBytes = socket.retrieveStickerManifest(packId);
    InputStream cipherStream = AttachmentCipherInputStream.createForStickerData(manifestBytes, packKey);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    Util.copy(cipherStream, outputStream);
    StickerProtos.Pack pack = StickerProtos.Pack.parseFrom(outputStream.toByteArray());
    List<SignalServiceStickerManifest.StickerInfo> stickers = new ArrayList<>(pack.getStickersCount());
    SignalServiceStickerManifest.StickerInfo cover = pack.hasCover() ? new SignalServiceStickerManifest.StickerInfo(pack.getCover().getId(), pack.getCover().getEmoji(), pack.getCover().getContentType()) : null;
    for (StickerProtos.Pack.Sticker sticker : pack.getStickersList()) {
        stickers.add(new SignalServiceStickerManifest.StickerInfo(sticker.getId(), sticker.getEmoji(), sticker.getContentType()));
    }
    return new SignalServiceStickerManifest(pack.getTitle(), pack.getAuthor(), cover, stickers);
}
Also used : SignalServiceStickerManifest(org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest) ProfileCipherInputStream(org.whispersystems.signalservice.api.crypto.ProfileCipherInputStream) AttachmentCipherInputStream(org.whispersystems.signalservice.api.crypto.AttachmentCipherInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StickerProtos(org.whispersystems.signalservice.internal.sticker.StickerProtos)

Example 4 with SignalServiceStickerManifest

use of org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest in project Signal-Android by WhisperSystems.

the class LinkPreviewRepository method fetchStickerPackLinkPreview.

private static RequestController fetchStickerPackLinkPreview(@NonNull Context context, @NonNull String packUrl, @NonNull Callback callback) {
    SignalExecutors.UNBOUNDED.execute(() -> {
        try {
            Pair<String, String> stickerParams = StickerUrl.parseShareLink(packUrl).or(new Pair<>("", ""));
            String packIdString = stickerParams.first();
            String packKeyString = stickerParams.second();
            byte[] packIdBytes = Hex.fromStringCondensed(packIdString);
            byte[] packKeyBytes = Hex.fromStringCondensed(packKeyString);
            SignalServiceMessageReceiver receiver = ApplicationDependencies.getSignalServiceMessageReceiver();
            SignalServiceStickerManifest manifest = receiver.retrieveStickerManifest(packIdBytes, packKeyBytes);
            String title = manifest.getTitle().or(manifest.getAuthor()).or("");
            Optional<StickerInfo> firstSticker = Optional.fromNullable(manifest.getStickers().size() > 0 ? manifest.getStickers().get(0) : null);
            Optional<StickerInfo> cover = manifest.getCover().or(firstSticker);
            if (cover.isPresent()) {
                Bitmap bitmap = GlideApp.with(context).asBitmap().load(new StickerRemoteUri(packIdString, packKeyString, cover.get().getId())).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).centerInside().submit(512, 512).get();
                Optional<Attachment> thumbnail = bitmapToAttachment(bitmap, Bitmap.CompressFormat.WEBP, MediaUtil.IMAGE_WEBP);
                callback.onSuccess(new LinkPreview(packUrl, title, "", 0, thumbnail));
            } else {
                callback.onError(Error.PREVIEW_NOT_AVAILABLE);
            }
        } catch (IOException | InvalidMessageException | ExecutionException | InterruptedException e) {
            Log.w(TAG, "Failed to fetch sticker pack link preview.");
            callback.onError(Error.PREVIEW_NOT_AVAILABLE);
        }
    });
    return () -> Log.i(TAG, "Cancelled sticker pack link preview fetch -- no effect.");
}
Also used : SignalServiceStickerManifest(org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) StickerRemoteUri(org.thoughtcrime.securesms.stickers.StickerRemoteUri) Attachment(org.thoughtcrime.securesms.attachments.Attachment) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) IOException(java.io.IOException) Bitmap(android.graphics.Bitmap) SignalServiceMessageReceiver(org.whispersystems.signalservice.api.SignalServiceMessageReceiver) StickerInfo(org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest.StickerInfo) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

SignalServiceStickerManifest (org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 InvalidMessageException (org.whispersystems.libsignal.InvalidMessageException)2 SignalServiceMessageReceiver (org.whispersystems.signalservice.api.SignalServiceMessageReceiver)2 StickerInfo (org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest.StickerInfo)2 Bitmap (android.graphics.Bitmap)1 WorkerThread (androidx.annotation.WorkerThread)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ExecutionException (java.util.concurrent.ExecutionException)1 Attachment (org.thoughtcrime.securesms.attachments.Attachment)1 UriAttachment (org.thoughtcrime.securesms.attachments.UriAttachment)1 StickerDatabase (org.thoughtcrime.securesms.database.StickerDatabase)1 IncomingSticker (org.thoughtcrime.securesms.database.model.IncomingSticker)1 Job (org.thoughtcrime.securesms.jobmanager.Job)1 JobManager (org.thoughtcrime.securesms.jobmanager.JobManager)1 StickerRemoteUri (org.thoughtcrime.securesms.stickers.StickerRemoteUri)1 AttachmentCipherInputStream (org.whispersystems.signalservice.api.crypto.AttachmentCipherInputStream)1