Search in sources :

Example 6 with StickerRecord

use of org.thoughtcrime.securesms.database.model.StickerRecord 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)

Example 7 with StickerRecord

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

the class StickerSearchRepository method searchByEmoji.

public void searchByEmoji(@NonNull String emoji, @NonNull Callback<List<StickerRecord>> callback) {
    SignalExecutors.BOUNDED.execute(() -> {
        String searchEmoji = EmojiUtil.getCanonicalRepresentation(emoji);
        List<StickerRecord> out = new ArrayList<>();
        Set<String> possible = EmojiUtil.getAllRepresentations(searchEmoji);
        for (String candidate : possible) {
            try (StickerRecordReader reader = new StickerRecordReader(stickerDatabase.getStickersByEmoji(candidate))) {
                StickerRecord record = null;
                while ((record = reader.getNext()) != null) {
                    out.add(record);
                }
            }
        }
        callback.onResult(out);
    });
}
Also used : ArrayList(java.util.ArrayList) StickerRecord(org.thoughtcrime.securesms.database.model.StickerRecord) StickerRecordReader(org.thoughtcrime.securesms.database.StickerDatabase.StickerRecordReader)

Example 8 with StickerRecord

use of org.thoughtcrime.securesms.database.model.StickerRecord in project Signal-Android by signalapp.

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)

Example 9 with StickerRecord

use of org.thoughtcrime.securesms.database.model.StickerRecord in project Signal-Android by signalapp.

the class StickerSearchRepository method searchByEmoji.

public void searchByEmoji(@NonNull String emoji, @NonNull Callback<List<StickerRecord>> callback) {
    SignalExecutors.BOUNDED.execute(() -> {
        String searchEmoji = EmojiUtil.getCanonicalRepresentation(emoji);
        List<StickerRecord> out = new ArrayList<>();
        Set<String> possible = EmojiUtil.getAllRepresentations(searchEmoji);
        for (String candidate : possible) {
            try (StickerRecordReader reader = new StickerRecordReader(stickerDatabase.getStickersByEmoji(candidate))) {
                StickerRecord record = null;
                while ((record = reader.getNext()) != null) {
                    out.add(record);
                }
            }
        }
        callback.onResult(out);
    });
}
Also used : ArrayList(java.util.ArrayList) StickerRecord(org.thoughtcrime.securesms.database.model.StickerRecord) StickerRecordReader(org.thoughtcrime.securesms.database.StickerDatabase.StickerRecordReader)

Example 10 with StickerRecord

use of org.thoughtcrime.securesms.database.model.StickerRecord in project Signal-Android by signalapp.

the class PushSendJob method getStickerFor.

protected Optional<SignalServiceDataMessage.Sticker> getStickerFor(OutgoingMediaMessage message) {
    Attachment stickerAttachment = Stream.of(message.getAttachments()).filter(Attachment::isSticker).findFirst().orElse(null);
    if (stickerAttachment == null) {
        return Optional.absent();
    }
    try {
        byte[] packId = Hex.fromStringCondensed(stickerAttachment.getSticker().getPackId());
        byte[] packKey = Hex.fromStringCondensed(stickerAttachment.getSticker().getPackKey());
        int stickerId = stickerAttachment.getSticker().getStickerId();
        StickerRecord record = SignalDatabase.stickers().getSticker(stickerAttachment.getSticker().getPackId(), stickerId, false);
        String emoji = record != null ? record.getEmoji() : null;
        SignalServiceAttachment attachment = getAttachmentPointerFor(stickerAttachment);
        return Optional.of(new SignalServiceDataMessage.Sticker(packId, packKey, stickerId, emoji, attachment));
    } catch (IOException e) {
        Log.w(TAG, "Failed to decode sticker id/key", e);
        return Optional.absent();
    }
}
Also used : SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) SignalServiceDataMessage(org.whispersystems.signalservice.api.messages.SignalServiceDataMessage) SignalServiceAttachment(org.whispersystems.signalservice.api.messages.SignalServiceAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) IOException(java.io.IOException) NetworkConstraint(org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint) StickerRecord(org.thoughtcrime.securesms.database.model.StickerRecord)

Aggregations

StickerRecord (org.thoughtcrime.securesms.database.model.StickerRecord)10 StickerDatabase (org.thoughtcrime.securesms.database.StickerDatabase)6 ArrayList (java.util.ArrayList)4 SuppressLint (android.annotation.SuppressLint)2 Cursor (android.database.Cursor)2 WorkerThread (androidx.annotation.WorkerThread)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 SecureRandom (java.security.SecureRandom)2 Attachment (org.thoughtcrime.securesms.attachments.Attachment)2 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)2 UriAttachment (org.thoughtcrime.securesms.attachments.UriAttachment)2 StickerRecordReader (org.thoughtcrime.securesms.database.StickerDatabase.StickerRecordReader)2 NetworkConstraint (org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint)2 StickerLocator (org.thoughtcrime.securesms.stickers.StickerLocator)2 SignalServiceMessageReceiver (org.whispersystems.signalservice.api.SignalServiceMessageReceiver)2 SignalServiceAttachment (org.whispersystems.signalservice.api.messages.SignalServiceAttachment)2 SignalServiceDataMessage (org.whispersystems.signalservice.api.messages.SignalServiceDataMessage)2