Search in sources :

Example 1 with StickerDatabase

use of org.thoughtcrime.securesms.database.StickerDatabase 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 StickerDatabase

use of org.thoughtcrime.securesms.database.StickerDatabase in project Signal-Android by WhisperSystems.

the class MessageContentProcessor method getStickerAttachment.

private Optional<Attachment> getStickerAttachment(Optional<SignalServiceDataMessage.Sticker> sticker) {
    if (!sticker.isPresent()) {
        return Optional.absent();
    }
    if (sticker.get().getPackId() == null || sticker.get().getPackKey() == null || sticker.get().getAttachment() == null) {
        warn("Malformed sticker!");
        return Optional.absent();
    }
    String packId = Hex.toStringCondensed(sticker.get().getPackId());
    String packKey = Hex.toStringCondensed(sticker.get().getPackKey());
    int stickerId = sticker.get().getStickerId();
    String emoji = sticker.get().getEmoji();
    StickerLocator stickerLocator = new StickerLocator(packId, packKey, stickerId, emoji);
    StickerDatabase stickerDatabase = SignalDatabase.stickers();
    StickerRecord stickerRecord = stickerDatabase.getSticker(stickerLocator.getPackId(), stickerLocator.getStickerId(), false);
    if (stickerRecord != null) {
        return Optional.of(new UriAttachment(stickerRecord.getUri(), stickerRecord.getContentType(), AttachmentDatabase.TRANSFER_PROGRESS_DONE, stickerRecord.getSize(), StickerSlide.WIDTH, StickerSlide.HEIGHT, null, String.valueOf(new SecureRandom().nextLong()), false, false, false, false, null, stickerLocator, null, null, null));
    } else {
        return Optional.of(PointerAttachment.forPointer(Optional.of(sticker.get().getAttachment()), stickerLocator).get());
    }
}
Also used : StickerLocator(org.thoughtcrime.securesms.stickers.StickerLocator) StickerDatabase(org.thoughtcrime.securesms.database.StickerDatabase) SecureRandom(java.security.SecureRandom) UriAttachment(org.thoughtcrime.securesms.attachments.UriAttachment) SuppressLint(android.annotation.SuppressLint) StickerRecord(org.thoughtcrime.securesms.database.model.StickerRecord)

Example 3 with StickerDatabase

use of org.thoughtcrime.securesms.database.StickerDatabase in project Signal-Android by WhisperSystems.

the class StickerLaunchMigrationJob method installPack.

private static void installPack(@NonNull Context context, @NonNull BlessedPacks.Pack pack) {
    JobManager jobManager = ApplicationDependencies.getJobManager();
    StickerDatabase stickerDatabase = SignalDatabase.stickers();
    if (stickerDatabase.isPackAvailableAsReference(pack.getPackId())) {
        stickerDatabase.markPackAsInstalled(pack.getPackId(), false);
    }
    jobManager.add(StickerPackDownloadJob.forInstall(pack.getPackId(), pack.getPackKey(), false));
    if (TextSecurePreferences.isMultiDevice(context)) {
        jobManager.add(new MultiDeviceStickerPackOperationJob(pack.getPackId(), pack.getPackKey(), MultiDeviceStickerPackOperationJob.Type.INSTALL));
    }
}
Also used : MultiDeviceStickerPackOperationJob(org.thoughtcrime.securesms.jobs.MultiDeviceStickerPackOperationJob) StickerDatabase(org.thoughtcrime.securesms.database.StickerDatabase) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager)

Example 4 with StickerDatabase

use of org.thoughtcrime.securesms.database.StickerDatabase in project Signal-Android by WhisperSystems.

the class StickerDownloadJob method onRun.

@Override
protected void onRun() throws Exception {
    StickerDatabase db = SignalDatabase.stickers();
    StickerRecord stickerRecord = db.getSticker(sticker.getPackId(), sticker.getStickerId(), sticker.isCover());
    if (stickerRecord != null) {
        try (InputStream stream = PartAuthority.getAttachmentStream(context, stickerRecord.getUri())) {
            if (stream != null) {
                Log.w(TAG, "Sticker already downloaded.");
                return;
            }
        } catch (FileNotFoundException e) {
            Log.w(TAG, "Sticker file no longer exists, downloading again.");
        }
    }
    if (!db.isPackInstalled(sticker.getPackId()) && !sticker.isCover()) {
        Log.w(TAG, "Pack is no longer installed.");
        return;
    }
    SignalServiceMessageReceiver receiver = ApplicationDependencies.getSignalServiceMessageReceiver();
    byte[] packIdBytes = Hex.fromStringCondensed(sticker.getPackId());
    byte[] packKeyBytes = Hex.fromStringCondensed(sticker.getPackKey());
    InputStream stream = receiver.retrieveSticker(packIdBytes, packKeyBytes, sticker.getStickerId());
    db.insertSticker(sticker, stream, notify);
}
Also used : InputStream(java.io.InputStream) SignalServiceMessageReceiver(org.whispersystems.signalservice.api.SignalServiceMessageReceiver) StickerDatabase(org.thoughtcrime.securesms.database.StickerDatabase) FileNotFoundException(java.io.FileNotFoundException) StickerRecord(org.thoughtcrime.securesms.database.model.StickerRecord)

Aggregations

StickerDatabase (org.thoughtcrime.securesms.database.StickerDatabase)4 StickerRecord (org.thoughtcrime.securesms.database.model.StickerRecord)2 JobManager (org.thoughtcrime.securesms.jobmanager.JobManager)2 SignalServiceMessageReceiver (org.whispersystems.signalservice.api.SignalServiceMessageReceiver)2 SuppressLint (android.annotation.SuppressLint)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 SecureRandom (java.security.SecureRandom)1 ArrayList (java.util.ArrayList)1 UriAttachment (org.thoughtcrime.securesms.attachments.UriAttachment)1 IncomingSticker (org.thoughtcrime.securesms.database.model.IncomingSticker)1 Job (org.thoughtcrime.securesms.jobmanager.Job)1 MultiDeviceStickerPackOperationJob (org.thoughtcrime.securesms.jobs.MultiDeviceStickerPackOperationJob)1 StickerLocator (org.thoughtcrime.securesms.stickers.StickerLocator)1 SignalServiceStickerManifest (org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest)1 StickerInfo (org.whispersystems.signalservice.api.messages.SignalServiceStickerManifest.StickerInfo)1