Search in sources :

Example 1 with SendViewedReceiptJob

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

the class VoiceNotePlaybackService method sendViewedReceiptForCurrentWindowIndex.

private void sendViewedReceiptForCurrentWindowIndex() {
    if (player.getPlaybackState() == Player.STATE_READY && player.getPlayWhenReady() && player.getCurrentWindowIndex() != C.INDEX_UNSET) {
        MediaItem currentMediaItem = player.getCurrentMediaItem();
        if (currentMediaItem == null || currentMediaItem.playbackProperties == null) {
            return;
        }
        Uri mediaUri = currentMediaItem.playbackProperties.uri;
        if (!mediaUri.getScheme().equals("content")) {
            return;
        }
        SignalExecutors.BOUNDED.execute(() -> {
            Bundle extras = currentMediaItem.mediaMetadata.extras;
            if (extras == null) {
                return;
            }
            long messageId = extras.getLong(VoiceNoteMediaItemFactory.EXTRA_MESSAGE_ID);
            RecipientId recipientId = RecipientId.from(extras.getString(VoiceNoteMediaItemFactory.EXTRA_INDIVIDUAL_RECIPIENT_ID));
            MessageDatabase messageDatabase = SignalDatabase.mms();
            MessageDatabase.MarkedMessageInfo markedMessageInfo = messageDatabase.setIncomingMessageViewed(messageId);
            if (markedMessageInfo != null) {
                ApplicationDependencies.getJobManager().add(new SendViewedReceiptJob(markedMessageInfo.getThreadId(), recipientId, markedMessageInfo.getSyncMessageId().getTimetamp(), new MessageId(messageId, true)));
                MultiDeviceViewedUpdateJob.enqueue(Collections.singletonList(markedMessageInfo.getSyncMessageId()));
            }
        });
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MediaItem(com.google.android.exoplayer2.MediaItem) Bundle(android.os.Bundle) SendViewedReceiptJob(org.thoughtcrime.securesms.jobs.SendViewedReceiptJob) Uri(android.net.Uri) MessageId(org.thoughtcrime.securesms.database.model.MessageId)

Example 2 with SendViewedReceiptJob

use of org.thoughtcrime.securesms.jobs.SendViewedReceiptJob in project Signal-Android by signalapp.

the class VoiceNotePlaybackService method sendViewedReceiptForCurrentWindowIndex.

private void sendViewedReceiptForCurrentWindowIndex() {
    if (player.getPlaybackState() == Player.STATE_READY && player.getPlayWhenReady() && player.getCurrentWindowIndex() != C.INDEX_UNSET) {
        MediaItem currentMediaItem = player.getCurrentMediaItem();
        if (currentMediaItem == null || currentMediaItem.playbackProperties == null) {
            return;
        }
        Uri mediaUri = currentMediaItem.playbackProperties.uri;
        if (!mediaUri.getScheme().equals("content")) {
            return;
        }
        SignalExecutors.BOUNDED.execute(() -> {
            Bundle extras = currentMediaItem.mediaMetadata.extras;
            if (extras == null) {
                return;
            }
            long messageId = extras.getLong(VoiceNoteMediaItemFactory.EXTRA_MESSAGE_ID);
            RecipientId recipientId = RecipientId.from(extras.getString(VoiceNoteMediaItemFactory.EXTRA_INDIVIDUAL_RECIPIENT_ID));
            MessageDatabase messageDatabase = SignalDatabase.mms();
            MessageDatabase.MarkedMessageInfo markedMessageInfo = messageDatabase.setIncomingMessageViewed(messageId);
            if (markedMessageInfo != null) {
                ApplicationDependencies.getJobManager().add(new SendViewedReceiptJob(markedMessageInfo.getThreadId(), recipientId, markedMessageInfo.getSyncMessageId().getTimetamp(), new MessageId(messageId, true)));
                MultiDeviceViewedUpdateJob.enqueue(Collections.singletonList(markedMessageInfo.getSyncMessageId()));
            }
        });
    }
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) MediaItem(com.google.android.exoplayer2.MediaItem) Bundle(android.os.Bundle) SendViewedReceiptJob(org.thoughtcrime.securesms.jobs.SendViewedReceiptJob) Uri(android.net.Uri) MessageId(org.thoughtcrime.securesms.database.model.MessageId)

Example 3 with SendViewedReceiptJob

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

the class ViewOnceMessageRepository method getMessage.

void getMessage(long messageId, @NonNull Callback<Optional<MmsMessageRecord>> callback) {
    SignalExecutors.BOUNDED.execute(() -> {
        try {
            MmsMessageRecord record = (MmsMessageRecord) mmsDatabase.getMessageRecord(messageId);
            MessageDatabase.MarkedMessageInfo info = mmsDatabase.setIncomingMessageViewed(record.getId());
            if (info != null) {
                ApplicationDependencies.getJobManager().add(new SendViewedReceiptJob(record.getThreadId(), info.getSyncMessageId().getRecipientId(), info.getSyncMessageId().getTimetamp(), info.getMessageId()));
                MultiDeviceViewedUpdateJob.enqueue(Collections.singletonList(info.getSyncMessageId()));
            }
            callback.onComplete(Optional.fromNullable(record));
        } catch (NoSuchMessageException e) {
            callback.onComplete(Optional.absent());
        }
    });
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) NoSuchMessageException(org.thoughtcrime.securesms.database.NoSuchMessageException) SendViewedReceiptJob(org.thoughtcrime.securesms.jobs.SendViewedReceiptJob) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord)

Example 4 with SendViewedReceiptJob

use of org.thoughtcrime.securesms.jobs.SendViewedReceiptJob in project Signal-Android by signalapp.

the class ViewOnceMessageRepository method getMessage.

void getMessage(long messageId, @NonNull Callback<Optional<MmsMessageRecord>> callback) {
    SignalExecutors.BOUNDED.execute(() -> {
        try {
            MmsMessageRecord record = (MmsMessageRecord) mmsDatabase.getMessageRecord(messageId);
            MessageDatabase.MarkedMessageInfo info = mmsDatabase.setIncomingMessageViewed(record.getId());
            if (info != null) {
                ApplicationDependencies.getJobManager().add(new SendViewedReceiptJob(record.getThreadId(), info.getSyncMessageId().getRecipientId(), info.getSyncMessageId().getTimetamp(), info.getMessageId()));
                MultiDeviceViewedUpdateJob.enqueue(Collections.singletonList(info.getSyncMessageId()));
            }
            callback.onComplete(Optional.fromNullable(record));
        } catch (NoSuchMessageException e) {
            callback.onComplete(Optional.absent());
        }
    });
}
Also used : MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) NoSuchMessageException(org.thoughtcrime.securesms.database.NoSuchMessageException) SendViewedReceiptJob(org.thoughtcrime.securesms.jobs.SendViewedReceiptJob) MmsMessageRecord(org.thoughtcrime.securesms.database.model.MmsMessageRecord)

Aggregations

MessageDatabase (org.thoughtcrime.securesms.database.MessageDatabase)4 SendViewedReceiptJob (org.thoughtcrime.securesms.jobs.SendViewedReceiptJob)4 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 MediaItem (com.google.android.exoplayer2.MediaItem)2 NoSuchMessageException (org.thoughtcrime.securesms.database.NoSuchMessageException)2 MessageId (org.thoughtcrime.securesms.database.model.MessageId)2 MmsMessageRecord (org.thoughtcrime.securesms.database.model.MmsMessageRecord)2 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)2