Search in sources :

Example 1 with StickerLocator

use of org.thoughtcrime.securesms.stickers.StickerLocator in project Signal-Android by WhisperSystems.

the class AttachmentDatabase method getAttachments.

public List<DatabaseAttachment> getAttachments(@NonNull Cursor cursor) {
    try {
        if (cursor.getColumnIndex(AttachmentDatabase.ATTACHMENT_JSON_ALIAS) != -1) {
            if (cursor.isNull(cursor.getColumnIndexOrThrow(ATTACHMENT_JSON_ALIAS))) {
                return new LinkedList<>();
            }
            List<DatabaseAttachment> result = new LinkedList<>();
            JSONArray array = new JSONArray(cursor.getString(cursor.getColumnIndexOrThrow(ATTACHMENT_JSON_ALIAS)));
            for (int i = 0; i < array.length(); i++) {
                JsonUtils.SaneJSONObject object = new JsonUtils.SaneJSONObject(array.getJSONObject(i));
                if (!object.isNull(ROW_ID)) {
                    String contentType = object.getString(CONTENT_TYPE);
                    result.add(new DatabaseAttachment(new AttachmentId(object.getLong(ROW_ID), object.getLong(UNIQUE_ID)), object.getLong(MMS_ID), !TextUtils.isEmpty(object.getString(DATA)), MediaUtil.isImageType(contentType) || MediaUtil.isVideoType(contentType), contentType, object.getInt(TRANSFER_STATE), object.getLong(SIZE), object.getString(FILE_NAME), object.getInt(CDN_NUMBER), object.getString(CONTENT_LOCATION), object.getString(CONTENT_DISPOSITION), object.getString(NAME), null, object.getString(FAST_PREFLIGHT_ID), object.getInt(VOICE_NOTE) == 1, object.getInt(BORDERLESS) == 1, object.getInt(VIDEO_GIF) == 1, object.getInt(WIDTH), object.getInt(HEIGHT), object.getInt(QUOTE) == 1, object.getString(CAPTION), object.getInt(STICKER_ID) >= 0 ? new StickerLocator(object.getString(STICKER_PACK_ID), object.getString(STICKER_PACK_KEY), object.getInt(STICKER_ID), object.getString(STICKER_EMOJI)) : null, MediaUtil.isAudioType(contentType) ? null : BlurHash.parseOrNull(object.getString(VISUAL_HASH)), MediaUtil.isAudioType(contentType) ? AudioHash.parseOrNull(object.getString(VISUAL_HASH)) : null, TransformProperties.parse(object.getString(TRANSFORM_PROPERTIES)), object.getInt(DISPLAY_ORDER), object.getLong(UPLOAD_TIMESTAMP)));
                }
            }
            return result;
        } else {
            return Collections.singletonList(getAttachment(cursor));
        }
    } catch (JSONException e) {
        throw new AssertionError(e);
    }
}
Also used : DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) JSONArray(org.json.JSONArray) StickerLocator(org.thoughtcrime.securesms.stickers.StickerLocator) JSONException(org.json.JSONException) LinkedList(java.util.LinkedList) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId) JsonUtils(org.thoughtcrime.securesms.util.JsonUtils)

Example 2 with StickerLocator

use of org.thoughtcrime.securesms.stickers.StickerLocator 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 StickerLocator

use of org.thoughtcrime.securesms.stickers.StickerLocator in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method sendSticker.

private void sendSticker(@NonNull StickerRecord stickerRecord, boolean clearCompose) {
    sendSticker(new StickerLocator(stickerRecord.getPackId(), stickerRecord.getPackKey(), stickerRecord.getStickerId(), stickerRecord.getEmoji()), stickerRecord.getContentType(), stickerRecord.getUri(), stickerRecord.getSize(), clearCompose);
    SignalExecutors.BOUNDED.execute(() -> SignalDatabase.stickers().updateStickerLastUsedTime(stickerRecord.getRowId(), System.currentTimeMillis()));
}
Also used : StickerLocator(org.thoughtcrime.securesms.stickers.StickerLocator)

Example 4 with StickerLocator

use of org.thoughtcrime.securesms.stickers.StickerLocator in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method initializeDraft.

// /// Initializers
private ListenableFuture<Boolean> initializeDraft(@NonNull ConversationIntents.Args args) {
    final SettableFuture<Boolean> result = new SettableFuture<>();
    final CharSequence draftText = args.getDraftText();
    final Uri draftMedia = requireActivity().getIntent().getData();
    final String draftContentType = requireActivity().getIntent().getType();
    final MediaType draftMediaType = MediaType.from(draftContentType);
    final List<Media> mediaList = args.getMedia();
    final StickerLocator stickerLocator = args.getStickerLocator();
    final boolean borderless = args.isBorderless();
    if (stickerLocator != null && draftMedia != null) {
        Log.d(TAG, "Handling shared sticker.");
        sendSticker(stickerLocator, Objects.requireNonNull(draftContentType), draftMedia, 0, true);
        return new SettableFuture<>(false);
    }
    if (draftMedia != null && draftContentType != null && borderless) {
        SimpleTask.run(getLifecycle(), () -> getKeyboardImageDetails(draftMedia), details -> sendKeyboardImage(draftMedia, draftContentType, details));
        return new SettableFuture<>(false);
    }
    if (!Util.isEmpty(mediaList)) {
        Log.d(TAG, "Handling shared Media.");
        Intent sendIntent = MediaSelectionActivity.editor(requireContext(), sendButton.getSelectedTransport(), mediaList, recipient.getId(), draftText);
        startActivityForResult(sendIntent, MEDIA_SENDER);
        return new SettableFuture<>(false);
    }
    if (draftText != null) {
        composeText.setText("");
        composeText.append(draftText);
        result.set(true);
    }
    if (draftMedia != null && draftMediaType != null) {
        Log.d(TAG, "Handling shared Data.");
        return setMedia(draftMedia, draftMediaType);
    }
    if (draftText == null && draftMedia == null && draftMediaType == null) {
        return initializeDraftFromDatabase();
    } else {
        updateToggleButtonState();
        result.set(false);
    }
    return result;
}
Also used : SettableFuture(org.thoughtcrime.securesms.util.concurrent.SettableFuture) Media(org.thoughtcrime.securesms.mediasend.Media) StickerLocator(org.thoughtcrime.securesms.stickers.StickerLocator) MediaType(org.thoughtcrime.securesms.mms.SlideFactory.MediaType) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) SpannableString(android.text.SpannableString) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Uri(android.net.Uri)

Aggregations

StickerLocator (org.thoughtcrime.securesms.stickers.StickerLocator)4 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 SpannableString (android.text.SpannableString)1 SecureRandom (java.security.SecureRandom)1 LinkedList (java.util.LinkedList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 AttachmentId (org.thoughtcrime.securesms.attachments.AttachmentId)1 DatabaseAttachment (org.thoughtcrime.securesms.attachments.DatabaseAttachment)1 UriAttachment (org.thoughtcrime.securesms.attachments.UriAttachment)1 StickerDatabase (org.thoughtcrime.securesms.database.StickerDatabase)1 StickerRecord (org.thoughtcrime.securesms.database.model.StickerRecord)1 Media (org.thoughtcrime.securesms.mediasend.Media)1 MediaType (org.thoughtcrime.securesms.mms.SlideFactory.MediaType)1 JsonUtils (org.thoughtcrime.securesms.util.JsonUtils)1 SettableFuture (org.thoughtcrime.securesms.util.concurrent.SettableFuture)1