Search in sources :

Example 16 with SlideDeck

use of org.thoughtcrime.securesms.mms.SlideDeck in project Signal-Android by WhisperSystems.

the class ConversationActivity method onRecorderFinished.

@Override
public void onRecorderFinished() {
    Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(20);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    ListenableFuture<Pair<Uri, Long>> future = audioRecorder.stopRecording();
    future.addListener(new ListenableFuture.Listener<Pair<Uri, Long>>() {

        @Override
        public void onSuccess(@NonNull final Pair<Uri, Long> result) {
            try {
                boolean forceSms = sendButton.isManualSelection() && sendButton.getSelectedTransport().isSms();
                int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
                long expiresIn = recipients.getExpireMessages() * 1000;
                AudioSlide audioSlide = new AudioSlide(ConversationActivity.this, result.first, result.second, ContentType.AUDIO_AAC);
                SlideDeck slideDeck = new SlideDeck();
                slideDeck.addSlide(audioSlide);
                sendMediaMessage(forceSms, "", slideDeck, expiresIn, subscriptionId).addListener(new AssertedSuccessListener<Void>() {

                    @Override
                    public void onSuccess(Void nothing) {
                        new AsyncTask<Void, Void, Void>() {

                            @Override
                            protected Void doInBackground(Void... params) {
                                PersistentBlobProvider.getInstance(ConversationActivity.this).delete(result.first);
                                return null;
                            }
                        }.execute();
                    }
                });
            } catch (InvalidMessageException e) {
                Log.w(TAG, e);
                Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_error_sending_voice_message, Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void onFailure(ExecutionException e) {
            Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_unable_to_record_audio, Toast.LENGTH_LONG).show();
        }
    });
}
Also used : InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) Uri(android.net.Uri) AssertedSuccessListener(org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener) ListenableFuture(org.thoughtcrime.securesms.util.concurrent.ListenableFuture) Vibrator(android.os.Vibrator) ExecutionException(java.util.concurrent.ExecutionException) Pair(android.util.Pair)

Example 17 with SlideDeck

use of org.thoughtcrime.securesms.mms.SlideDeck in project Signal-Android by signalapp.

the class PushDecryptJob method handleSynchronizeSentTextMessage.

private long handleSynchronizeSentTextMessage(@NonNull SentTranscriptMessage message) throws MmsException {
    Recipient recipient = getSyncMessageDestination(message);
    String body = message.getMessage().getBody().or("");
    long expiresInMillis = message.getMessage().getExpiresInSeconds() * 1000L;
    if (recipient.getExpireMessages() != message.getMessage().getExpiresInSeconds()) {
        handleSynchronizeSentExpirationUpdate(message);
    }
    long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipient);
    MessagingDatabase database;
    long messageId;
    if (recipient.getAddress().isGroup()) {
        OutgoingMediaMessage outgoingMediaMessage = new OutgoingMediaMessage(recipient, new SlideDeck(), body, message.getTimestamp(), -1, expiresInMillis, ThreadDatabase.DistributionTypes.DEFAULT);
        outgoingMediaMessage = new OutgoingSecureMediaMessage(outgoingMediaMessage);
        messageId = DatabaseFactory.getMmsDatabase(context).insertMessageOutbox(outgoingMediaMessage, threadId, false, null);
        database = DatabaseFactory.getMmsDatabase(context);
    } else {
        OutgoingTextMessage outgoingTextMessage = new OutgoingEncryptedMessage(recipient, body, expiresInMillis);
        messageId = DatabaseFactory.getSmsDatabase(context).insertMessageOutbox(threadId, outgoingTextMessage, false, message.getTimestamp(), null);
        database = DatabaseFactory.getSmsDatabase(context);
    }
    database.markAsSent(messageId, true);
    if (expiresInMillis > 0) {
        database.markExpireStarted(messageId, message.getExpirationStartTimestamp());
        ApplicationContext.getInstance(context).getExpiringMessageManager().scheduleDeletion(messageId, false, message.getExpirationStartTimestamp(), expiresInMillis);
    }
    return threadId;
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) MessagingDatabase(org.thoughtcrime.securesms.database.MessagingDatabase) OutgoingSecureMediaMessage(org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage) OutgoingEncryptedMessage(org.thoughtcrime.securesms.sms.OutgoingEncryptedMessage) Recipient(org.thoughtcrime.securesms.recipients.Recipient) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck)

Example 18 with SlideDeck

use of org.thoughtcrime.securesms.mms.SlideDeck in project Signal-Android by WhisperSystems.

the class MultiShareSender method sendSync.

@WorkerThread
public static MultiShareSendResultCollection sendSync(@NonNull MultiShareArgs multiShareArgs) {
    List<MultiShareSendResult> results = new ArrayList<>(multiShareArgs.getShareContactAndThreads().size());
    Context context = ApplicationDependencies.getApplication();
    boolean isMmsEnabled = Util.isMmsCapable(context);
    String message = multiShareArgs.getDraftText();
    SlideDeck slideDeck;
    try {
        slideDeck = buildSlideDeck(context, multiShareArgs);
    } catch (SlideNotFoundException e) {
        Log.w(TAG, "Could not create slide for media message");
        for (ShareContactAndThread shareContactAndThread : multiShareArgs.getShareContactAndThreads()) {
            results.add(new MultiShareSendResult(shareContactAndThread, MultiShareSendResult.Type.GENERIC_ERROR));
        }
        return new MultiShareSendResultCollection(results);
    }
    for (ShareContactAndThread shareContactAndThread : multiShareArgs.getShareContactAndThreads()) {
        Recipient recipient = Recipient.resolved(shareContactAndThread.getRecipientId());
        List<Mention> mentions = getValidMentionsForRecipient(recipient, multiShareArgs.getMentions());
        TransportOption transport = resolveTransportOption(context, recipient);
        boolean forceSms = recipient.isForceSmsSelection() && transport.isSms();
        int subscriptionId = transport.getSimSubscriptionId().or(-1);
        long expiresIn = TimeUnit.SECONDS.toMillis(recipient.getExpiresInSeconds());
        boolean needsSplit = !transport.isSms() && message != null && message.length() > transport.calculateCharacters(message).maxPrimaryMessageSize;
        boolean isMediaMessage = !multiShareArgs.getMedia().isEmpty() || (multiShareArgs.getDataUri() != null && multiShareArgs.getDataUri() != Uri.EMPTY) || multiShareArgs.getStickerLocator() != null || multiShareArgs.getLinkPreview() != null || recipient.isGroup() || recipient.getEmail().isPresent() || !mentions.isEmpty() || needsSplit;
        if ((recipient.isMmsGroup() || recipient.getEmail().isPresent()) && !isMmsEnabled) {
            results.add(new MultiShareSendResult(shareContactAndThread, MultiShareSendResult.Type.MMS_NOT_ENABLED));
        } else if (isMediaMessage) {
            sendMediaMessage(context, multiShareArgs, recipient, slideDeck, transport, shareContactAndThread.getThreadId(), forceSms, expiresIn, multiShareArgs.isViewOnce(), subscriptionId, mentions);
            results.add(new MultiShareSendResult(shareContactAndThread, MultiShareSendResult.Type.SUCCESS));
        } else {
            sendTextMessage(context, multiShareArgs, recipient, shareContactAndThread.getThreadId(), forceSms, expiresIn, subscriptionId);
            results.add(new MultiShareSendResult(shareContactAndThread, MultiShareSendResult.Type.SUCCESS));
        }
        // XXX We must do this to avoid sending out messages to the same recipient with the same
        // sentTimestamp. If we do this, they'll be considered dupes by the receiver.
        ThreadUtil.sleep(5);
    }
    return new MultiShareSendResultCollection(results);
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) TransportOption(org.thoughtcrime.securesms.TransportOption) Mention(org.thoughtcrime.securesms.database.model.Mention) WorkerThread(androidx.annotation.WorkerThread)

Example 19 with SlideDeck

use of org.thoughtcrime.securesms.mms.SlideDeck in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method sendKeyboardImage.

private void sendKeyboardImage(@NonNull Uri uri, @NonNull String contentType, @Nullable KeyboardImageDetails details) {
    if (details == null || !details.hasTransparency) {
        setMedia(uri, Objects.requireNonNull(MediaType.from(contentType)));
        return;
    }
    long expiresIn = TimeUnit.SECONDS.toMillis(recipient.get().getExpiresInSeconds());
    int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
    boolean initiating = threadId == -1;
    SlideDeck slideDeck = new SlideDeck();
    if (MediaUtil.isGif(contentType)) {
        slideDeck.addSlide(new GifSlide(requireContext(), uri, 0, details.width, details.height, details.hasTransparency, null));
    } else if (MediaUtil.isImageType(contentType)) {
        slideDeck.addSlide(new ImageSlide(requireContext(), uri, contentType, 0, details.width, details.height, details.hasTransparency, null, null));
    } else {
        throw new AssertionError("Only images are supported!");
    }
    sendMediaMessage(recipient.getId(), isSmsForced(), "", slideDeck, null, Collections.emptyList(), Collections.emptyList(), composeText.getMentions(), expiresIn, false, subscriptionId, initiating, false, null);
}
Also used : ImageSlide(org.thoughtcrime.securesms.mms.ImageSlide) GifSlide(org.thoughtcrime.securesms.mms.GifSlide) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) SuppressLint(android.annotation.SuppressLint)

Example 20 with SlideDeck

use of org.thoughtcrime.securesms.mms.SlideDeck in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method sendVoiceNote.

private void sendVoiceNote(@NonNull Uri uri, long size) {
    boolean forceSms = sendButton.isManualSelection() && sendButton.getSelectedTransport().isSms();
    boolean initiating = threadId == -1;
    int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
    long expiresIn = TimeUnit.SECONDS.toMillis(recipient.get().getExpiresInSeconds());
    AudioSlide audioSlide = new AudioSlide(requireContext(), uri, size, MediaUtil.AUDIO_AAC, true);
    SlideDeck slideDeck = new SlideDeck();
    slideDeck.addSlide(audioSlide);
    ListenableFuture<Void> sendResult = sendMediaMessage(recipient.getId(), forceSms, "", slideDeck, inputPanel.getQuote().orNull(), Collections.emptyList(), Collections.emptyList(), composeText.getMentions(), expiresIn, false, subscriptionId, initiating, true, null);
    sendResult.addListener(new AssertedSuccessListener<Void>() {

        @Override
        public void onSuccess(Void nothing) {
            draftViewModel.deleteBlob(uri);
        }
    });
}
Also used : AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) SuppressLint(android.annotation.SuppressLint)

Aggregations

SlideDeck (org.thoughtcrime.securesms.mms.SlideDeck)26 Recipient (org.thoughtcrime.securesms.recipients.Recipient)13 SuppressLint (android.annotation.SuppressLint)11 Context (android.content.Context)8 AudioSlide (org.thoughtcrime.securesms.mms.AudioSlide)8 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)8 OutgoingSecureMediaMessage (org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage)7 Nullable (androidx.annotation.Nullable)6 WorkerThread (androidx.annotation.WorkerThread)6 ArrayList (java.util.ArrayList)6 Mention (org.thoughtcrime.securesms.database.model.Mention)6 MmsMessageRecord (org.thoughtcrime.securesms.database.model.MmsMessageRecord)6 GifSlide (org.thoughtcrime.securesms.mms.GifSlide)6 ImageSlide (org.thoughtcrime.securesms.mms.ImageSlide)6 Slide (org.thoughtcrime.securesms.mms.Slide)6 StickerSlide (org.thoughtcrime.securesms.mms.StickerSlide)6 OutgoingTextMessage (org.thoughtcrime.securesms.sms.OutgoingTextMessage)6 SpannableString (android.text.SpannableString)5 Attachment (org.thoughtcrime.securesms.attachments.Attachment)5 Contact (org.thoughtcrime.securesms.contactshare.Contact)5