Search in sources :

Example 1 with StickerRecord

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

the class StickerPackPreviewRepository method getStickersFromDatabase.

@WorkerThread
private List<StickerManifest.Sticker> getStickersFromDatabase(@NonNull String packId) {
    List<StickerManifest.Sticker> stickers = new ArrayList<>();
    try (Cursor cursor = stickerDatabase.getStickersForPack(packId)) {
        StickerDatabase.StickerRecordReader reader = new StickerDatabase.StickerRecordReader(cursor);
        StickerRecord record;
        while ((record = reader.getNext()) != null) {
            stickers.add(toSticker(record));
        }
    }
    return stickers;
}
Also used : ArrayList(java.util.ArrayList) StickerDatabase(org.thoughtcrime.securesms.database.StickerDatabase) Cursor(android.database.Cursor) StickerRecord(org.thoughtcrime.securesms.database.model.StickerRecord) WorkerThread(androidx.annotation.WorkerThread)

Example 2 with StickerRecord

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

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)

Example 3 with StickerRecord

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

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

the class StickerPackPreviewRepository method getStickersFromDatabase.

@WorkerThread
private List<StickerManifest.Sticker> getStickersFromDatabase(@NonNull String packId) {
    List<StickerManifest.Sticker> stickers = new ArrayList<>();
    try (Cursor cursor = stickerDatabase.getStickersForPack(packId)) {
        StickerDatabase.StickerRecordReader reader = new StickerDatabase.StickerRecordReader(cursor);
        StickerRecord record;
        while ((record = reader.getNext()) != null) {
            stickers.add(toSticker(record));
        }
    }
    return stickers;
}
Also used : ArrayList(java.util.ArrayList) StickerDatabase(org.thoughtcrime.securesms.database.StickerDatabase) Cursor(android.database.Cursor) StickerRecord(org.thoughtcrime.securesms.database.model.StickerRecord) WorkerThread(androidx.annotation.WorkerThread)

Example 5 with StickerRecord

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

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)

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