Search in sources :

Example 1 with SlideDeck

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

the class MessageNotifier method constructNotificationState.

private static NotificationState constructNotificationState(@NonNull Context context, @Nullable MasterSecret masterSecret, @NonNull Cursor cursor) {
    NotificationState notificationState = new NotificationState();
    MessageRecord record;
    MmsSmsDatabase.Reader reader;
    if (masterSecret == null)
        reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor);
    else
        reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor, masterSecret);
    while ((record = reader.getNext()) != null) {
        long id = record.getId();
        boolean mms = record.isMms() || record.isMmsNotification();
        Recipient recipient = record.getIndividualRecipient();
        Recipients recipients = record.getRecipients();
        long threadId = record.getThreadId();
        CharSequence body = record.getDisplayBody();
        Recipients threadRecipients = null;
        SlideDeck slideDeck = null;
        long timestamp = record.getTimestamp();
        if (threadId != -1) {
            threadRecipients = DatabaseFactory.getThreadDatabase(context).getRecipientsForThreadId(threadId);
        }
        if (SmsDatabase.Types.isDecryptInProgressType(record.getType()) || !record.getBody().isPlaintext()) {
            body = SpanUtil.italic(context.getString(R.string.MessageNotifier_locked_message));
        } else if (record.isMms() && TextUtils.isEmpty(body)) {
            body = SpanUtil.italic(context.getString(R.string.MessageNotifier_media_message));
            slideDeck = ((MediaMmsMessageRecord) record).getSlideDeck();
        } else if (record.isMms() && !record.isMmsNotification()) {
            String message = context.getString(R.string.MessageNotifier_media_message_with_text, body);
            int italicLength = message.length() - body.length();
            body = SpanUtil.italic(message, italicLength);
            slideDeck = ((MediaMmsMessageRecord) record).getSlideDeck();
        }
        if (threadRecipients == null || !threadRecipients.isMuted()) {
            notificationState.addNotification(new NotificationItem(id, mms, recipient, recipients, threadRecipients, threadId, body, timestamp, slideDeck));
        }
    }
    reader.close();
    return notificationState;
}
Also used : MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) Recipients(org.thoughtcrime.securesms.recipients.Recipients) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) MmsSmsDatabase(org.thoughtcrime.securesms.database.MmsSmsDatabase) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord)

Example 2 with SlideDeck

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

the class QuickResponseService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent, @Nullable MasterSecret masterSecret) {
    if (!TelephonyManager.ACTION_RESPOND_VIA_MESSAGE.equals(intent.getAction())) {
        Log.w(TAG, "Received unknown intent: " + intent.getAction());
        return;
    }
    if (masterSecret == null) {
        Log.w(TAG, "Got quick response request when locked...");
        Toast.makeText(this, R.string.QuickResponseService_quick_response_unavailable_when_Signal_is_locked, Toast.LENGTH_LONG).show();
        return;
    }
    try {
        Rfc5724Uri uri = new Rfc5724Uri(intent.getDataString());
        String content = intent.getStringExtra(Intent.EXTRA_TEXT);
        String numbers = uri.getPath();
        if (numbers.contains("%")) {
            numbers = URLDecoder.decode(numbers);
        }
        Recipients recipients = RecipientFactory.getRecipientsFromString(this, numbers, false);
        Optional<RecipientsPreferences> preferences = DatabaseFactory.getRecipientPreferenceDatabase(this).getRecipientsPreferences(recipients.getIds());
        int subscriptionId = preferences.isPresent() ? preferences.get().getDefaultSubscriptionId().or(-1) : -1;
        long expiresIn = preferences.isPresent() ? preferences.get().getExpireMessages() * 1000 : 0;
        if (!TextUtils.isEmpty(content)) {
            if (recipients.isSingleRecipient()) {
                MessageSender.send(this, masterSecret, new OutgoingTextMessage(recipients, content, expiresIn, subscriptionId), -1, false);
            } else {
                MessageSender.send(this, masterSecret, new OutgoingMediaMessage(recipients, new SlideDeck(), content, System.currentTimeMillis(), subscriptionId, expiresIn, ThreadDatabase.DistributionTypes.DEFAULT), -1, false);
            }
        }
    } catch (URISyntaxException e) {
        Toast.makeText(this, R.string.QuickResponseService_problem_sending_message, Toast.LENGTH_LONG).show();
        Log.w(TAG, e);
    }
}
Also used : OutgoingTextMessage(org.thoughtcrime.securesms.sms.OutgoingTextMessage) Rfc5724Uri(org.thoughtcrime.securesms.util.Rfc5724Uri) Recipients(org.thoughtcrime.securesms.recipients.Recipients) OutgoingMediaMessage(org.thoughtcrime.securesms.mms.OutgoingMediaMessage) RecipientsPreferences(org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.RecipientsPreferences) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) URISyntaxException(java.net.URISyntaxException)

Example 3 with SlideDeck

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

the class ConversationActivity method onRecorderFinished.

@Override
public void onRecorderFinished() {
    Vibrator vibrator = ServiceUtil.getVibrator(this);
    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) {
            boolean forceSms = sendButton.isManualSelection() && sendButton.getSelectedTransport().isSms();
            int subscriptionId = sendButton.getSelectedTransport().getSimSubscriptionId().or(-1);
            long expiresIn = recipient.getExpireMessages() * 1000L;
            boolean initiating = threadId == -1;
            AudioSlide audioSlide = new AudioSlide(ConversationActivity.this, result.first, result.second, MediaUtil.AUDIO_AAC, true);
            SlideDeck slideDeck = new SlideDeck();
            slideDeck.addSlide(audioSlide);
            sendMediaMessage(forceSms, "", slideDeck, expiresIn, subscriptionId, initiating).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(ConversationActivity.this, result.first);
                            return null;
                        }
                    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                }
            });
        }

        @Override
        public void onFailure(ExecutionException e) {
            Toast.makeText(ConversationActivity.this, R.string.ConversationActivity_unable_to_record_audio, Toast.LENGTH_LONG).show();
        }
    });
}
Also used : 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 4 with SlideDeck

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

the class MessageNotifier method constructNotificationState.

private static NotificationState constructNotificationState(@NonNull Context context, @NonNull Cursor cursor) {
    NotificationState notificationState = new NotificationState();
    MmsSmsDatabase.Reader reader = DatabaseFactory.getMmsSmsDatabase(context).readerFor(cursor);
    MessageRecord record;
    while ((record = reader.getNext()) != null) {
        long id = record.getId();
        boolean mms = record.isMms() || record.isMmsNotification();
        Recipient recipient = record.getIndividualRecipient();
        Recipient conversationRecipient = record.getRecipient();
        long threadId = record.getThreadId();
        CharSequence body = record.getDisplayBody();
        Recipient threadRecipients = null;
        SlideDeck slideDeck = null;
        long timestamp = record.getTimestamp();
        if (threadId != -1) {
            threadRecipients = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadId);
        }
        if (KeyCachingService.isLocked(context)) {
            body = SpanUtil.italic(context.getString(R.string.MessageNotifier_locked_message));
        } else if (record.isMms() && TextUtils.isEmpty(body)) {
            body = SpanUtil.italic(context.getString(R.string.MessageNotifier_media_message));
            slideDeck = ((MediaMmsMessageRecord) record).getSlideDeck();
        } else if (record.isMms() && !record.isMmsNotification()) {
            String message = context.getString(R.string.MessageNotifier_media_message_with_text, body);
            int italicLength = message.length() - body.length();
            body = SpanUtil.italic(message, italicLength);
            slideDeck = ((MediaMmsMessageRecord) record).getSlideDeck();
        }
        if (threadRecipients == null || !threadRecipients.isMuted()) {
            notificationState.addNotification(new NotificationItem(id, mms, recipient, conversationRecipient, threadRecipients, threadId, body, timestamp, slideDeck));
        }
    }
    reader.close();
    return notificationState;
}
Also used : MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) SuppressLint(android.annotation.SuppressLint) MmsSmsDatabase(org.thoughtcrime.securesms.database.MmsSmsDatabase) MessageRecord(org.thoughtcrime.securesms.database.model.MessageRecord) MediaMmsMessageRecord(org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord)

Example 5 with SlideDeck

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

the class MediaMmsMessageRecord method withAttachments.

@NonNull
public MediaMmsMessageRecord withAttachments(@NonNull Context context, @NonNull List<DatabaseAttachment> attachments) {
    Map<AttachmentId, DatabaseAttachment> attachmentIdMap = new HashMap<>();
    for (DatabaseAttachment attachment : attachments) {
        attachmentIdMap.put(attachment.getAttachmentId(), attachment);
    }
    List<Contact> contacts = updateContacts(getSharedContacts(), attachmentIdMap);
    Set<Attachment> contactAttachments = contacts.stream().map(Contact::getAvatarAttachment).filter(Objects::nonNull).collect(Collectors.toSet());
    List<LinkPreview> linkPreviews = updateLinkPreviews(getLinkPreviews(), attachmentIdMap);
    Set<Attachment> linkPreviewAttachments = linkPreviews.stream().map(LinkPreview::getThumbnail).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toSet());
    Quote quote = updateQuote(context, getQuote(), attachments);
    List<DatabaseAttachment> slideAttachments = attachments.stream().filter(a -> !contactAttachments.contains(a)).filter(a -> !linkPreviewAttachments.contains(a)).collect(Collectors.toList());
    SlideDeck slideDeck = MmsDatabase.Reader.buildSlideDeck(context, slideAttachments);
    return new MediaMmsMessageRecord(getId(), getRecipient(), getIndividualRecipient(), getRecipientDeviceId(), getDateSent(), getDateReceived(), getServerTimestamp(), getDeliveryReceiptCount(), getThreadId(), getBody(), slideDeck, getPartCount(), getType(), getIdentityKeyMismatches(), getNetworkFailures(), getSubscriptionId(), getExpiresIn(), getExpireStarted(), isViewOnce(), getReadReceiptCount(), quote, contacts, linkPreviews, isUnidentified(), getReactions(), isRemoteDelete(), mentionsSelf, getNotifiedTimestamp(), getViewedReceiptCount(), getReceiptTimestamp(), getMessageRanges());
}
Also used : Context(android.content.Context) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) NonNull(androidx.annotation.NonNull) WorkerThread(androidx.annotation.WorkerThread) HashMap(java.util.HashMap) R(org.thoughtcrime.securesms.R) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) BodyRangeList(org.thoughtcrime.securesms.database.model.databaseprotos.BodyRangeList) Map(java.util.Map) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Contact(org.thoughtcrime.securesms.contactshare.Contact) Status(org.thoughtcrime.securesms.database.SmsDatabase.Status) IdentityKeyMismatch(org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch) SpannableString(android.text.SpannableString) Set(java.util.Set) Collectors(java.util.stream.Collectors) Optional(org.whispersystems.libsignal.util.guava.Optional) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) List(java.util.List) Nullable(androidx.annotation.Nullable) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId) NetworkFailure(org.thoughtcrime.securesms.database.documents.NetworkFailure) MmsDatabase(org.thoughtcrime.securesms.database.MmsDatabase) Attachment(org.thoughtcrime.securesms.attachments.Attachment) Optional(org.whispersystems.libsignal.util.guava.Optional) HashMap(java.util.HashMap) LinkPreview(org.thoughtcrime.securesms.linkpreview.LinkPreview) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) DatabaseAttachment(org.thoughtcrime.securesms.attachments.DatabaseAttachment) Attachment(org.thoughtcrime.securesms.attachments.Attachment) SlideDeck(org.thoughtcrime.securesms.mms.SlideDeck) AttachmentId(org.thoughtcrime.securesms.attachments.AttachmentId) Contact(org.thoughtcrime.securesms.contactshare.Contact) NonNull(androidx.annotation.NonNull)

Aggregations

SlideDeck (org.thoughtcrime.securesms.mms.SlideDeck)17 Recipient (org.thoughtcrime.securesms.recipients.Recipient)8 SuppressLint (android.annotation.SuppressLint)6 AudioSlide (org.thoughtcrime.securesms.mms.AudioSlide)5 OutgoingMediaMessage (org.thoughtcrime.securesms.mms.OutgoingMediaMessage)5 Context (android.content.Context)4 MediaMmsMessageRecord (org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord)4 MessageRecord (org.thoughtcrime.securesms.database.model.MessageRecord)4 OutgoingSecureMediaMessage (org.thoughtcrime.securesms.mms.OutgoingSecureMediaMessage)4 Slide (org.thoughtcrime.securesms.mms.Slide)4 Uri (android.net.Uri)3 Vibrator (android.os.Vibrator)3 SpannableString (android.text.SpannableString)3 Nullable (androidx.annotation.Nullable)3 WorkerThread (androidx.annotation.WorkerThread)3 ArrayList (java.util.ArrayList)3 ExecutionException (java.util.concurrent.ExecutionException)3 TransportOption (org.thoughtcrime.securesms.TransportOption)3 Attachment (org.thoughtcrime.securesms.attachments.Attachment)3 Contact (org.thoughtcrime.securesms.contactshare.Contact)3