Search in sources :

Example 1 with TransportOption

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

the class ConversationParentFragment method calculateCharactersRemaining.

private void calculateCharactersRemaining() {
    String messageBody = composeText.getTextTrimmed().toString();
    TransportOption transportOption = sendButton.getSelectedTransport();
    CharacterState characterState = transportOption.calculateCharacters(messageBody);
    if (characterState.charactersRemaining <= 15 || characterState.messagesSpent > 1) {
        charactersLeft.setText(String.format(Locale.getDefault(), "%d/%d (%d)", characterState.charactersRemaining, characterState.maxTotalMessageSize, characterState.messagesSpent));
        charactersLeft.setVisibility(View.VISIBLE);
    } else {
        charactersLeft.setVisibility(View.GONE);
    }
}
Also used : TransportOption(org.thoughtcrime.securesms.TransportOption) SpannableString(android.text.SpannableString) CharacterState(org.thoughtcrime.securesms.util.CharacterCalculator.CharacterState)

Example 2 with TransportOption

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

the class ConversationParentFragment method sendMessage.

private void sendMessage(@Nullable String metricId) {
    if (inputPanel.isRecordingInLockedMode()) {
        inputPanel.releaseRecordingLock();
        return;
    }
    Draft voiceNote = draftViewModel.getVoiceNoteDraft();
    if (voiceNote != null) {
        AudioSlide audioSlide = AudioSlide.createFromVoiceNoteDraft(requireContext(), voiceNote);
        sendVoiceNote(Objects.requireNonNull(audioSlide.getUri()), audioSlide.getFileSize());
        draftViewModel.clearVoiceNoteDraft();
        return;
    }
    try {
        Recipient recipient = getRecipient();
        if (recipient == null) {
            throw new RecipientFormattingException("Badly formatted");
        }
        String message = getMessage();
        TransportOption transport = sendButton.getSelectedTransport();
        boolean forceSms = (recipient.isForceSmsSelection() || sendButton.isManualSelection()) && transport.isSms();
        int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
        long expiresIn = TimeUnit.SECONDS.toMillis(recipient.getExpiresInSeconds());
        boolean initiating = threadId == -1;
        boolean needsSplit = !transport.isSms() && message.length() > transport.calculateCharacters(message).maxPrimaryMessageSize;
        boolean isMediaMessage = attachmentManager.isAttachmentPresent() || recipient.isGroup() || recipient.getEmail().isPresent() || inputPanel.getQuote().isPresent() || composeText.hasMentions() || linkPreviewViewModel.hasLinkPreview() || needsSplit;
        Log.i(TAG, "[sendMessage] recipient: " + recipient.getId() + ", threadId: " + threadId + ",  forceSms: " + forceSms + ", isManual: " + sendButton.isManualSelection());
        if ((recipient.isMmsGroup() || recipient.getEmail().isPresent()) && !isMmsEnabled) {
            handleManualMmsRequired();
        } else if (!forceSms && (identityRecords.isUnverified(true) || identityRecords.isUntrusted(true))) {
            handleRecentSafetyNumberChange();
        } else if (isMediaMessage) {
            sendMediaMessage(forceSms, expiresIn, false, subscriptionId, initiating, metricId);
        } else {
            sendTextMessage(forceSms, expiresIn, subscriptionId, initiating, metricId);
        }
    } catch (RecipientFormattingException ex) {
        Toast.makeText(requireContext(), R.string.ConversationActivity_recipient_is_not_a_valid_sms_or_email_address_exclamation, Toast.LENGTH_LONG).show();
        Log.w(TAG, ex);
    } catch (InvalidMessageException ex) {
        Toast.makeText(requireContext(), R.string.ConversationActivity_message_is_empty_exclamation, Toast.LENGTH_SHORT).show();
        Log.w(TAG, ex);
    }
}
Also used : TransportOption(org.thoughtcrime.securesms.TransportOption) VoiceNoteDraft(org.thoughtcrime.securesms.components.voice.VoiceNoteDraft) Draft(org.thoughtcrime.securesms.database.DraftDatabase.Draft) InvalidMessageException(org.whispersystems.libsignal.InvalidMessageException) AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SpannableString(android.text.SpannableString) RecipientFormattingException(org.thoughtcrime.securesms.recipients.RecipientFormattingException) SuppressLint(android.annotation.SuppressLint)

Example 3 with TransportOption

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

the class ConversationParentFragment method sendSticker.

private void sendSticker(@NonNull StickerLocator stickerLocator, @NonNull String contentType, @NonNull Uri uri, long size, boolean clearCompose) {
    if (sendButton.getSelectedTransport().isSms()) {
        Media media = new Media(uri, contentType, System.currentTimeMillis(), StickerSlide.WIDTH, StickerSlide.HEIGHT, size, 0, false, false, Optional.absent(), Optional.absent(), Optional.absent());
        Intent intent = MediaSelectionActivity.editor(requireContext(), sendButton.getSelectedTransport(), Collections.singletonList(media), recipient.getId(), composeText.getTextTrimmed());
        startActivityForResult(intent, MEDIA_SENDER);
        return;
    }
    long expiresIn = TimeUnit.SECONDS.toMillis(recipient.get().getExpiresInSeconds());
    int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
    boolean initiating = threadId == -1;
    TransportOption transport = sendButton.getSelectedTransport();
    SlideDeck slideDeck = new SlideDeck();
    Slide stickerSlide = new StickerSlide(requireContext(), uri, size, stickerLocator, contentType);
    slideDeck.addSlide(stickerSlide);
    sendMediaMessage(recipient.getId(), transport.isSms(), "", slideDeck, null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), expiresIn, false, subscriptionId, initiating, clearCompose, null);
}
Also used : TransportOption(org.thoughtcrime.securesms.TransportOption) LocationSlide(org.thoughtcrime.securesms.mms.LocationSlide) StickerSlide(org.thoughtcrime.securesms.mms.StickerSlide) Slide(org.thoughtcrime.securesms.mms.Slide) GifSlide(org.thoughtcrime.securesms.mms.GifSlide) ImageSlide(org.thoughtcrime.securesms.mms.ImageSlide) AudioSlide(org.thoughtcrime.securesms.mms.AudioSlide) VideoSlide(org.thoughtcrime.securesms.mms.VideoSlide) Media(org.thoughtcrime.securesms.mediasend.Media) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) StickerSlide(org.thoughtcrime.securesms.mms.StickerSlide) SuppressLint(android.annotation.SuppressLint)

Example 4 with TransportOption

use of org.thoughtcrime.securesms.TransportOption 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)

Aggregations

TransportOption (org.thoughtcrime.securesms.TransportOption)4 SuppressLint (android.annotation.SuppressLint)2 SpannableString (android.text.SpannableString)2 AudioSlide (org.thoughtcrime.securesms.mms.AudioSlide)2 SlideDeck (org.thoughtcrime.securesms.mms.SlideDeck)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 Intent (android.content.Intent)1 WorkerThread (androidx.annotation.WorkerThread)1 ArrayList (java.util.ArrayList)1 VoiceNoteDraft (org.thoughtcrime.securesms.components.voice.VoiceNoteDraft)1 Draft (org.thoughtcrime.securesms.database.DraftDatabase.Draft)1 Mention (org.thoughtcrime.securesms.database.model.Mention)1 Media (org.thoughtcrime.securesms.mediasend.Media)1 GifSlide (org.thoughtcrime.securesms.mms.GifSlide)1 ImageSlide (org.thoughtcrime.securesms.mms.ImageSlide)1 LocationSlide (org.thoughtcrime.securesms.mms.LocationSlide)1 Slide (org.thoughtcrime.securesms.mms.Slide)1 StickerSlide (org.thoughtcrime.securesms.mms.StickerSlide)1